12-19-2019 5:26 PM
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
12-19-2019 5:46 PM
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"
12-19-2019 5:46 PM
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"
12-20-2019 7:33 AM
sandra.rossi Thanks a lot !! I had no clue about this CONV functionality. You are a godsend ! 🙂
12-20-2019 12:47 PM
12-19-2019 5:51 PM
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).
12-20-2019 7:34 AM
NO Margaret, my system doesnt support substring. But I got the resolution using CONV functionality.