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

tables

Former Member
0 Likes
513

i want to send the data from database to three internal table.after that then 3 internal table to one internal table tell me the procedure? plz send me having any code?

4 REPLIES 4
Read only

Former Member
0 Likes
490

hi

create a structure which include all the structure of the 3 tables and make a table of it.

read 3 tables and append in the the final table

sort the tables and use binary search to improve the performance.

eg.

type : begin of table4.

include table1. " table structure

include table2.

include table3.

end of table4.

data : table4_tab type table of table4,

wa_tab4 type table4.

sort : table2 by abc,

table3 by xyz.

loop at table1.

read table table2 with key abc = table1-abc

binary search.

if sy-subrc =0.

wa_tab4-table2 = table2.

endif.

read table table3 with key abc = table1-abc

binary search.

if sy-subrc =0.

wa_tab4-table3 = table3.

endif.

wa_tab4-table1 = table1.

append wa_tab4 into table4_tab.

claer wa_tab4.

endloop.

Use this to optimise code & performance

Reward points if helpful

Regards

Nilesh

Read only

Former Member
0 Likes
490

select c1,c2,c3 from db into corresponding fields of table it1.

select c4,c5,c6 from db into corresponding fields of table it2.

select c7,c8,c9 from db into corresponding fields of table it3.

After that you can use the read statement to insert the three table's data into a single internal table.

Best Regards,

Balakrishna.N

Read only

Former Member
0 Likes
490

Hi,

for example take three internal tables..

it_mara -- fields are MATNR, NTGEW

it_marc -- fields are MATNR, WERKS

it_mard -- fields are MATNR, WERKS, LGORT

it_final -- your final internal table --fields are MATNR WERKS LGORT

work area

wa_mara -

wa_marc -

wa_mard -

wa_final --

Query

select matnr ntgew from mara

into table it_mara where matnr = <your selection screen value>.

select matnr werks from MARC

into table it_marc for all entries in it_mara

where matnr = it_mara-matnr

select matnr werks lgort from MARD

into table it_marc for all entries in it_marc

where matnr = it_marc-matnr

werks = it_marc-werks.

you will get data iun all the three tables..

Now Loop at one table and read the othere tables

LOOP AT IT_MARA into wa_mara. " wa_mara is work area for it_mara

wa_final-matnr = wa_mara-matnr

read table it_marc into wa_marc with key matnr = wa_mara-matnr binary search.

if sy-subrc = 0.

wa_final-werks = wa_marc-werks

endif.

read table it_mard into wa_mard with key

matnr = wa_marc-matnr

werks = wa_marc-werks

binary search.

if sy-subrc = 0.

wa_final-lgort = wa_marc-lgort.

endif.

append wa_final to it_final.

endloop.

final internal table contains al the data

rewars if useful.

regards,

nazeer

Read only

Former Member
0 Likes
490

Hi,

Try this sample prog.

REPORT zeasnike_reportpoo .

TABLES : vbap,

vbrp,

lips.

************************************************************************

  • INTERNAL TABLE FOR TABLE VBAP *

************************************************************************

DATA : BEGIN OF itab_vbap OCCURS 0,

vbeln1 LIKE vbap-vbeln,

vrkme LIKE vbap-vrkme,

END OF itab_vbap.

************************************************************************

  • INTERNAL TABLE FOR TABLE VBRP *

************************************************************************

DATA : BEGIN OF itab_vbrp OCCURS 0,

vbeln2 LIKE vbrp-vbeln,

lgort LIKE vbrp-lgort,

posnr LIKE vbrp-posnr,

END OF itab_vbrp.

************************************************************************

  • INTERNAL TABLE FOR TABLE LIPS *

************************************************************************

DATA : BEGIN OF itab_lips OCCURS 0,

vbeln3 LIKE lips-vbeln,

lgort LIKE lips-lgort,

posnr LIKE lips-posnr,

END OF itab_lips.

************************************************************************

  • OUTPUT INTERNAL TABLE *

************************************************************************

DATA : BEGIN OF itab_output OCCURS 0,

vbeln1 LIKE vbap-vbeln,

vrkme LIKE vbap-vrkme,

vbeln2 LIKE vbrp-vbeln,

posnr LIKE vbrp-posnr,

lgort LIKE vbrp-lgort,

vbeln3 LIKE lips-vbeln,

END OF itab_output.

************************************************************************

  • DECLARING CONSTANTS *

************************************************************************

CONSTANTS : c_posnr TYPE i VALUE '000010',

d_posnr TYPE i VALUE '000010'.

************************************************************************

  • SELECT-OPTONS *

************************************************************************

SELECTION-SCREEN : BEGIN OF BLOCK bl1 WITH FRAME TITLE text-001.

SELECT-OPTIONS : vbeln FOR vbap-vbeln.

SELECTION-SCREEN : END OF BLOCK bl1.

************************************************************************

  • SELECTING RECORDS FROM VBAP TABLE TO ITAB_VBAP *

************************************************************************

SELECT vbeln vrkme

FROM vbap INTO TABLE itab_vbap

WHERE vbeln IN vbeln.

MOVE-CORRESPONDING itab_vbap TO itab_output.

************************************************************************

  • SELECTING RECORDS FROM VBRP TABLE TO ITAB_VBRP *

************************************************************************

IF NOT itab_vbap[] IS INITIAL.

SELECT vbeln lgort posnr

FROM vbrp INTO TABLE itab_vbrp FOR ALL ENTRIES IN itab_vbap

WHERE vrkme EQ itab_vbap-vrkme AND

posnr EQ c_posnr.

MOVE-CORRESPONDING itab_vbrp TO itab_output.

************************************************************************

  • SELECTING RECORDS FROM LIPS TABLE TO ITAB_LIPS *

************************************************************************

IF NOT itab_vbrp[] IS INITIAL.

SELECT vbeln lgort posnr

FROM lips INTO TABLE itab_lips FOR ALL ENTRIES IN itab_vbrp

WHERE lgort EQ itab_vbrp-lgort AND

posnr EQ d_posnr.

ENDIF.

ENDIF.

************************************************************************

LOOP AT itab_vbap.

MOVE-CORRESPONDING itab_vbap TO itab_output.

APPEND itab_output.

ENDLOOP.

LOOP AT itab_vbrp.

MOVE-CORRESPONDING itab_vbrp TO itab_output.

APPEND itab_output.

ENDLOOP.

LOOP AT itab_lips.

MOVE-CORRESPONDING itab_lips TO itab_output.

APPEND itab_output.

ENDLOOP.

*************************************************************************

loop at itab_output.

write 😕 itab_output-vbeln1, itab_output-vbeln2, itab_output-vbeln3.

endloop.

**************************************************************************

Reward me if it is useful to you.

Thanks.