cancel
Showing results for 
Search instead for 
Did you mean: 

Using ALV, Can I display multiple sales document that is related to a material?

walkerist
Participant
0 Kudos

Hi, currently I was able to display the 1 sales document to related to my material. But there were multiple sales document related to my material.

This is my current logic:

it_output - this contains the material number. Sales document will be mapped on the loop.

MaterialSales Document
1800 
7107 

it_salesdoc - this contains the sales document which will be used for mapping.

MaterialSales Document
1800123456
1800789010
1800111213
7107571234
7107888123
71077741312

LOOP AT it_output INTO ls_output

DATA(lv_so) = VALUE #( it_salesdoc [ matnr = ls_output-matnr ]-vbeln ).

ls_output-vbeln = lv_so.

MODIFY it_output FROM ls_output TRANSPORTING vbeln WHERE matnr = ls_output-matnr.

ENDLOOP.

Current display is this:

MaterialSales Document
1800123456
7107571234

Can I display it something like this? 

MaterialSales Document
1800123456
1800789010
1800111213
7107571234
7107888123
71077741312
Sandra_Rossi
Active Contributor
0 Kudos
If the internal table IT_OUTPUT is used for both storing materials and ALV output, then use one more internal table for only materials, and use IT_OUTPUT for only the ALV output. Simple as that.
View Entire Topic
Yasin
Active Participant
0 Kudos

 

Yes it is possible, you need use conditional loop to search all sales orders related to the material number,  use append statement to add all related records once finished use Modify statement otherwise your internal tale it will keep one record only (your current scenario) 

example logic using 2 loops: 

Loop AT it_output INTO WA_it_output
LOOP AT it_salesdoc WHERE (  matnr =  WA_it_output-matnr  ) INTO  wa_it_salesdoc_final

APPEND wa_it_salesdoc to it_salesdoc_final.

ENDLOOP.
ENDLOOP.
MODIFY it_salesdoc_final.

You may achieve the same result with different approach you are not limited to the above. 

Please reward if it was helpful.

Thanks

walkerist
Participant
0 Kudos
Thanks for this. I'm checking on option wherein I can avoid using nested loops.
Sandra_Rossi
Active Contributor
0 Kudos
@walkerist if the logic needs nested loops with internal tables, it's never been a problem. You are confusing with nested SELECT which must be avoided.