Application Development and Automation 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: 
Read only

suggest me code

Former Member
0 Likes
752

I have one internal table itab1 with field VBELN KUNNR which contain the sales orders and the customer numbers based on some selection criteria..

I have another internal table itab2 with fields VBELN POSNR and MATNR (line items) for the above sales orders

I want to display a report with VBELN and KUNNR from itab1 and POSNR MATNR from itab2 for all the orders in itab1..

6 REPLIES 6
Read only

Former Member
0 Likes
732
Loop at itab1 into wa1.
   loop at itab2 into wa2
                      where vbeln = wa1-vbeln. 
        write: / wa1-vbeln, wa1-kunnr, wa2-posnr, wa2-matnr.
        clear: wa2.
   endloop.
   clear: wa1.
endloop.

suppose wa1 in the workarea for itab1 and wa2 is workarea for itab2.

Read only

former_member873340
Active Participant
0 Likes
732

Hi suresh,

here is the code which suits ur requirement.

You include matnr in the itab1 table.

sort itab1 by vbeln kunnr.

sort itab2 by vbeln posnr matnr.

loop at itab1.

read table itab2 with key vbeln = itab1-vbeln

binary search.

if sy-subrc = 0.

itab1-matnr = itab2-matnr.

modify itab1.

clear itab1.

endif.

endloop.

Award points for all helpful answers and close the question if u hav got ur required answer.

Regards

Gowri

Read only

Former Member
0 Likes
732

Hi Suresh,

Refer following code :

loop at itab1.

loop at itab2 where vbeln = itab1-vbeln.

write:/10 itab1-vbeln, itab2-posnr.

endloop.

endloop.

Regards,

Hemant

Read only

Former Member
0 Likes
732

Hi

You can either move the data to one internal table and use that internal table for display purpose in ALV.Or you can define fieldcatalog seperately where you can mention the table name and field name.If your creating ordinary report you can use write statement.

Loop at itab1

loop at itab2 where vbeln = itab1-vbeln.

write:itab1,itab2.

endloop.

endloop.

Reward if useful.

Regards

Shibin

Read only

Former Member
0 Likes
732

sort it_vbak by vbeln.

sort it_vbap by vbeln.

data : l_tabix like sy-tabix.

loop at it_vbak.

clear l_tabix.

read table it_vbap with key vbeln = it_vbak-vbeln binary serach.

if sy-subrc eq 0.

l_tabix = sy-tabix.

endif.

loop at it_vbap from index l_tabix.

if it_vbak-vbeln eq it_vbap-vbeln.

-->>popualte it_final with it_vbap and it_vbak.

else.

exit.

endif.

endloop.

endloop.

Reward the points if it is helpful..

Message was edited by:

Sasidhar Indukuru

Read only

Former Member
0 Likes
732

Hi,

From my understanding, your internal table 1 contain of field VBELN KUNNR, the data inside this table should be unique. What I mean by unique is there are no duplicate entries for the same VBELN.

Internal table 2 contain of fields VBELN POSNR and MATNR which is line items data which will consists of more than 1 line item with the same VBELN.

Below is my suggestion on the coding.

SORT INTERNAL TABLE 1 BY VBELN. (sort the table first before read table with binary search can be used)

LOOP at <INTERNAL TABLE 2>.

READ TABLE <INTERNAL TABLE 1> WITH KEY VBELN = <INTERNAL TABLE 2>-VBELN BINARY SEARCH.

IF SY-SUBRC = 0.

WRITE: <INTERNAL TABLE 1>-VBELN, <INTERNAL TABLE 1>-KUNNR, <INTERNAL TABLE 2>-POSNR, <INTERNAL TABLE 1>-MATNR.

ENDIF.

ENDLOOP.

Hope this help.

Cheers....