Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to fetch object ID from Z table using select query

manish_malakar0316
Active Participant

Hi all,

I am facing a problem while trying to fetch some data from a Z table.

As per my requirement, I have a Z table which has the following fields with (dummy)data :

Process_type Class_type objnr_id proc_id

0006 PI 000456003 123.34

0006 PI 000456003 4395.22

0006 PI 000456004 232.44

0006 PI 000423001 1445.2

Now, in the actual scenario, the objnr_id is the service order number (AUFNR) which is 456 and 423 and the digits 003 , 004 and 001 are the positions (POSNR) concatenated with it.

I have an enhancement in tcode IW33 where I have a button which will pull up all the objnr_id for the AUFNR that is there. So my AUFNR in IW33 is 000456. So I need to pull up the above 3 rows of data from the Z table.

My approach was like this:

select * from Ztable into it_ztable where process_type = '0006' and class_type = 'PI'.

loop at it_ztable into wa.

"remove the last 3 digits from the objnr_id.

"modify the table. So now I have the objnr_id without the concatenated posnr. (i.e. 000456)

endloop

Now I know that the above select query is not correct since I am fetching ALL the objnr_id from the table, which will cause a serious performance issue in production. How can I use the select query properly in this case so that I can only pick out the desired objnr_id and not fetch all the objnr_id ?

I tried using % in select but that only works for hardcoded values.

Regards,

Manish

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor

I guess you want to do something like WHERE ... objnr_id LIKE '<aufnr>%', with <aufnr> being the number of the order, and LIKE combined with % will select all lines with objnr_id starting with <aufnr>.

DATA lv_objnr_id TYPE ztable-objnr_id.

lv_objnr_id = aufnr && '%'.
SELECT ... FROM Ztable WHERE ... AND objnr_id LIKE lv_objnr_id.

More information: ABAP documentation "sql_cond - LIKE"

5 REPLIES 5

Sandra_Rossi
Active Contributor

I guess you want to do something like WHERE ... objnr_id LIKE '<aufnr>%', with <aufnr> being the number of the order, and LIKE combined with % will select all lines with objnr_id starting with <aufnr>.

DATA lv_objnr_id TYPE ztable-objnr_id.

lv_objnr_id = aufnr && '%'.
SELECT ... FROM Ztable WHERE ... AND objnr_id LIKE lv_objnr_id.

More information: ABAP documentation "sql_cond - LIKE"

0 Kudos

sandra.rossi Thanks a lot !! I had no clue about this CONV functionality. You are a godsend ! 🙂

manish.malakar0316 I removed "CONV" from my answer, to demonstrate that the solution is not about CONV, but about using a variable after LIKE, that you initialize by concatenating %. I also added a hyperlink to the documentation of LIKE.

mh97
Contributor
0 Kudos

If you are on NW version that supports SUBSTRING, do like below:

  select knumv, kdatu
  from konv
  where substring( kdatu, 1, 4 ) = '2016'
  into table @data(test_substring).

0 Kudos

NO Margaret, my system doesnt support substring. But I got the resolution using CONV functionality.