Application Development 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: 

joining of to internal tables

Former Member
0 Kudos

Hi,

I am having to internal tables it_itab and it_jtab of diffrent structure in my program.

my requirement is to add all the fields it_jtab into it_itab and write the write the write statement so that I can see all the fields.

How is this possible.

5 REPLIES 5

Former Member
0 Kudos

Try this solution.

Make another Internal Table i_ztab that contains all fields of i_itab and i_jtab.

Copy i_itab into corresponding fields of i_ztab.

Looping at i_jtab modify i_ztab corresponding fields.

Award POints if useful

Bhupal

ThomasZloch
Active Contributor
0 Kudos

that only makes sense if itab and jtab have a key relationship.

if so, loop at itab and read the corresponding entry in jtab inside that loop using the key fields. Then you can write entries of both tables in one line.

Cheers

Thomas

Former Member
0 Kudos

Hi Shilpa,

The key point here is to have atleast one field which is common to both the internal tables i.e a primary key.

I will provide a small prog here, hope this will help you to achieve what you desire.

TABLE : LFA1,LFB1.

DATA : BEGIN OF ITAB_FINAL OCCURS 0,

LIFNR LIKE LFA1-LIFNR,

NAME1 LIKE LFA1-NAME1,

ZWELS LIKE LFB1-ZWELS,

ZTERM LIKE LFB1-ZTERM,

END OF ITAB_FINAL.

DATA : BEGIN OF ITAB OCCURS 0,

LIFNR LIKE LFA1-LIFNR,

NAME1 LIKE LFA1-NAME1,

END OF ITAB.

DATA : BEGIN OF JTAB OCCURS 0,

LIFNR LIKE LFB1-LIFNR,

ZWELS LIKE LFB1-ZWELS,

ZTERM LIKE LFB1-ZTERM,

END OF JTAB.

SELECT LIFNR NAME1 INTO TABLE ITAB FROM LFA1.

SELECT LIFNR ZWELS ZTERM INTO TABLE JTAB FROM LFB1.

LOOP AT ITAB.

MOVE-CORRESPONDING ITAB TO ITAB_FINAL.

APPEND ITAB_FINAL.

ENDLOOP.

LOOP AT ITAB_FINAL.

READ TABLE JTAB WITH KEY LIFNR = ITAB_FINAL-LIFNR.

IF SY-SUBRC = 0.

ITAB_FINAL-ZWELS = JTAB-ZWELS.

ITAB_FINAL-ZTERM = JTAB-ZTERM.

MODIFY ITAB_FINAL.

ENDLOOP.

WRITE : / 'VENDOR NO' , 'VENDOR NAME', 'PAYMENT METHOD','PAYMENT TERMS'.

LOOP AT ITAB_FINAL.

WRITE : / ITAB_FINAL-LIFNR, ITAB_FINAL-NAME1,ITAB_FINAL-ZWELS,ITAB_FINAL-ZTERM.

ENDLOOP.

This program prints total of 4 columns 2 each from 2 different internal tables.

Reward Points,if useful,

-Bhavin P Shah

Former Member
0 Kudos

Hi,

if both the tables are having same structure then use the below syntax.

APPEND LINES OF itab1 [FROM idx1] [TO idx2] TO itab2.

if both are different, decide what is the main table among those two, loop through the another internal table, pass the individual fields to main internal table header or workarea, and then append.

Reward if useful.

Thanks,

Sreeram.

Edited by: Sreeram Prasad on Dec 21, 2007 10:11 AM

Former Member
0 Kudos

Hi,

Just copy the below code and execute.

-


REPORT zstemp_qty2_ LINE-SIZE 255 .

DATA:it_vbak LIKE vbak OCCURS 0 WITH HEADER LINE.

DATA:it_vbap LIKE vbap OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF it_sales OCCURS 0 ,

vbeln LIKE vbak-vbeln,

kunnr LIKE vbak-kunnr,

posnr LIKE vbap-posnr,

matnr LIKE vbap-matnr,

END OF it_sales.

START-OF-SELECTION.

SELECT * FROM vbak INTO TABLE it_vbak UP TO 50 ROWS.

IF NOT it_vbak[] IS INITIAL.

SELECT * FROM vbap INTO TABLE it_vbap

FOR ALL ENTRIES IN it_vbak

WHERE vbeln = it_vbak-vbeln.

ENDIF.

LOOP AT it_vbak.

READ TABLE it_vbap WITH KEY vbeln = it_vbak-vbeln.

IF sy-subrc = 0.

it_sales-vbeln = it_vbak-vbeln.

it_sales-posnr = it_vbap-posnr.

it_sales-kunnr = it_vbak-kunnr.

it_sales-matnr = it_vbap-matnr.

APPEND it_sales.

CLEAR it_sales.

ENDIF.

ENDLOOP.

-


If you want to write in it_vbak table only means it_vba we shoud have fields that correspond to another table

-


REPORT zstemp_qty2_ LINE-SIZE 255 .

DATA:it_vbak LIKE vbak OCCURS 0 WITH HEADER LINE.

*DATA:it_vbap LIKE vbap OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF it_sales OCCURS 0 ,

vbeln LIKE vbak-vbeln,

kunnr LIKE vbak-kunnr,

posnr LIKE vbap-posnr,

matnr LIKE vbap-matnr,

matkl like vbap-matkl,

arktx like vbap-arktx,

erdat like vbak-erdat,

END OF it_sales.

START-OF-SELECTION.

SELECT * FROM vbak INTO TABLE it_vbak UP TO 50 ROWS.

IF NOT it_vbak[] IS INITIAL.

SELECT * FROM vbap INTO corresponding fields of TABLE it_sales

FOR ALL ENTRIES IN it_vbak

WHERE vbeln = it_vbak-vbeln.

ENDIF.

loop at it_sales.

read table it_vbak with key vbeln = it_sales-vbeln.

if sy-subrc = 0.

it_sales-kunnr = it_vbak-kunnr.

it_sales-erdat = it_vbak-erdat.

modify it_sales transporting kunnr erdat.

clear it_sales.

endif.

endloop.

LOOP AT it_sales.

WRITE:/ it_sales-vbeln,it_sales-posnr,it_sales-kunnr,

it_sales-matnr,it_sales-matkl,it_sales-arktx,it_sales-erdat.

ENDLOOP.

-


Regds

Sivaparvathi

Please dont forget to reward points if helpful......