06-03-2010 10:10 AM
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 ?
06-03-2010 10:48 AM
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
06-03-2010 11:55 AM
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.
06-22-2010 11:46 AM
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.
06-03-2010 12:17 PM
Note that current SAP best practice is to COLLECT into a sorted table with declared keys.
06-22-2010 11:54 AM
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