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

Regarding Internal table

Former Member
0 Likes
701

Hi All,

Im having one final internal table which contain fields. from vbak , vbap & vbep.

TYPES : BEGIN OF tp_final,

vbeln TYPE vbak-vbeln,

erdat TYPE erdat,

ernam TYPE ernam,

auart LIKE vbak-auart,

posnr type posnr,

matnr type matnr,

kwmeng type kwmeng,

etenr type etenr,

ettyp type ettyp,

END OF tp_final

TYPES : BEGIN OF tp_vbak,

vbeln TYPE vbak-vbeln,

erdat TYPE erdat,

ernam TYPE ernam,

auart LIKE vbak-auart,

END OF tp_vbak.

TYPES : BEGIN OF tp_vbap,

vbeln TYPE vbak-vbeln,

posnr type posnr,

matnr type matnr,

kwmeng type kwmeng,

END OF tp_vbap.

TYPES : BEGIN OF tp_vbep,

vbeln TYPE vbak-vbeln,

posnr type posnr,

etenr type etenr,

ettyp type ettyp,

END OF tp_vbap.

i have written a 3 select query for this using for all entries .

My question is how to append all the three internal tables data to final internal table i.e tp_final....

Regs ,

Murthy

5 REPLIES 5
Read only

former_member156446
Active Contributor
0 Likes
678

hi

I am assuming all the table have header line.. if not use woek areas of these tables.


loop at tp_vbak.
move-corresponding tp_vbak to tp_final.
append tp_final.
endloop.

loop at tp_vbap.
move-corresponding tp_vbap to tp_final.
append tp_final.
endloop.

loop at tp_vbep.
move-corresponding tp_vbep to tp_final.
append tp_final.
endloop.

Read only

Former Member
0 Likes
678

narayana,

LOOP AT tp_vbak.

MOVE : require values of tp_vbak ti i_final.

APPEND i_final.

LOOP AT tp_vbap where vbeln EQ tp_vbak.

MOVE : require values of tp_vbap ti i_final.

APPEND i_final.

ENDLOOP.

LOOP AT tp_vbep where vbeln eq tp_vbak-vbeln.

MOVE : require values of tp_vbek ti i_final.

APPEND i_final.

ENDLOOP.

ENDLOOP.

FREE :tp_vbak,ty_vbap,ty_vbek.

Don't forget to reward if useful...

Read only

Former Member
0 Likes
678

As per my understanding, you can use a single select statement to derive the data in the final internal table.

Something like...


TYPES : BEGIN OF tp_final,
          vbeln TYPE vbak-vbeln,
          erdat TYPE erdat,
          ernam TYPE ernam,
          auart LIKE vbak-auart,
          posnr TYPE posnr,
          matnr TYPE matnr,
          kwmeng TYPE kwmeng,
          etenr TYPE etenr,
          ettyp TYPE ettyp,
        END OF tp_final.

DATA: i_final TYPE STANDARD TABLE OF tp_final.

SELECT a~vbeln a~erdat a~ernam a~auart
       b~posnr b~matnr b~kwmeng c~etenr c~ettyp
       INTO TABLE i_final
       FROM vbak AS a
       INNER JOIN vbap AS b
       ON b~vbeln = a~vbeln
       INNER JOIN vbep AS c
       ON c~vbeln = a~vbeln
       AND c~posnr = b~posnr
       WHERE <cond>.

Regards

Eswar

Read only

Former Member
0 Likes
678

HI Murthy,

this is the procedure to add the data from 3 or more tables into to the final table by taking the common field into consideration.

loop at tp_vbak.

tp_final-vbeln = tp_vbak-vbeln.

tp_final-erdat = tp_vbak-erdat.

tp_final-ernam = tp_vbak-ernam.

tp_final-auart = tp_vbak-auart.

read table tp_vbap with key vbeln = tp_vbak-vbeln.

if sy-subrc eq 0.

tp_vbap

tp_final-posnr = tp_vbap-posnr.

tp_final-matnr = tp_vbap-matnr.

tp_final-kwmeng = tp_vbap-kwmeng.

endif.

read table tp_vbep with key vbeln = tp_vbak-vbeln.

if sy-subrc eq 0.

tp_final-etenr = tp_vbep-etenr.

tp_final-ettyp = tp_vbep-ettyp.

endif.

append tp_final.

endloop.

Reward points if this is useful.

thanks,

satheesh.

Read only

Former Member
0 Likes
678

Hi,

try this......

loop at tp_vbep.
 move-corresponding tp_vbep to tp_final.
 read table tp_vbap with key vbeln = tp_vbep-vbeln posnr = tp_vbep-posnr.
 if sy-subrc is initial.
   move : tp_vbap-matnr  to tp_final-matnr,
          tp_vbap-kwmeng to tp_final-kwmeng.   
   endif.
  read table tp_vbak with key vbeln = tp_vbep-vbeln.
   if sy-subrc is initial.
   move : tp_vbak-erdat to tp_final-erdat,
          tp_vbak-ernam to tp_final-ernam,
          tp_vbak-auart to tp_final-auart.   
   endif. 
  append tp_final.
  clear  tp_final.
  endloop.

Cheers,

Will.