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: 

select endselect collect

Former Member
0 Kudos

 data: wa_lqua like line of t_lqua.
if t_main[] is not initial.
  SELECT matnr charg lgnum verme einme ausme FROM lqua INTO wa_lqua
  FOR ALL ENTRIES IN t_main
  WHERE matnr = t_main-idnrk AND
        charg = t_main-charg AND
        lgnum = p_lgnum
        AND lgtyp = 'PMI'.
  collect wa_lqua into t_lqua.
  endselect.
endif.

Will this code function correctly ?.I am asking because i cant test in DEV as i have no case.

verme,einme,ausme are quantities will they be added for every unique matnr,charg,lgnum ?

5 REPLIES 5

MarcinPciak
Active Contributor
0 Kudos

As long as you typed t_lqua like this, then it should


types: begin of type_t_lqua,
               matnr type ...
               charg type ...
               lgnum type ...
              verme type ...
              einme type ...
              ausme type ...
         end of type_t_lqua.

types: table_type_t_lqua type table of type_t_lqua with key matnr charg lqnum.   "you can also use WITH UNIQUE KEY

data: wa_lqua type type_t_lqua,
         t_lqua type table_type_t_lqua.
....  "here all numbers will be collected under given key of the table 

Regards

Marcin

Former Member
0 Kudos

Hi Aaditya,

Instead of the above code, use the below code and also this improves the performance .

Declare an internal table for eg. t_lqua.

and select all the values in this table.

data: wa_lqua like line of t_lqua.

if t_main[] is not initial.

SELECT matnr charg lgnum verme einme ausme FROM lqua INTO table t_lqua

FOR ALL ENTRIES IN t_main

WHERE matnr = t_main-idnrk AND

charg = t_main-charg AND

lgnum = p_lgnum

AND lgtyp = 'PMI'.

if sy-subrc eq 0.

sort t_lqua.

loop at t_lqua into wa_lqua.

collect wa_lqua into t_lqua.

endloop.

endif.

Regards,

Md ZIauddin.

0 Kudos

Sorry !.All of you are wrong.Reason is we cannot use for all entries here it will skip one quantity incase it finds a duplicate.

Former Member
0 Kudos

Note that current SAP best practice is to COLLECT into a sorted table with declared keys.

Former Member
0 Kudos

Hi Aditya ,

Very first thing ,

If you dont have data for testing thern simply what you can do is , run the program in debigging and populate some entries in the tables manually and go ahead with the tetsing. Hop eit wil help you in future for tetsing when data is not present in datbase.

Now as far as your code is concerned

if t_main[] is not initial.

SELECT matnr charg lgnum verme einme ausme FROM lqua INTO wa_lqua

FOR ALL ENTRIES IN t_main

WHERE matnr = t_main-idnrk AND

charg = t_main-charg AND

lgnum = p_lgnum

AND lgtyp = 'PMI'.

collect wa_lqua into t_lqua.

endselect.

endif.

1.First do not use select end-select

2.Select data into table instead of work area.

3.Rest all will work

Regards,

Uma Dave