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

moving 2 itabs data into Final table

Former Member
0 Likes
1,263

Hi all,

I have ITAB1 with fields LIFNR, KTOKK, NAME1, LAND1.

ITAB2 WITH FIELDS LIFNR, AKONT, ZTERM.

I WANT TO MOVE ALL THE FIELDS INTO ONE FINAL TABLE.

i.e ITAB will have LIFNR, KTOKK, NMAE1, LAND, AKONT, ZTERM.

HOW TO DO THIS ?

Thanks

Krupali

1 ACCEPTED SOLUTION
Read only

JozsefSzikszai
Active Contributor
0 Likes
1,241

hi KR,

roughly:

LOOP AT itab1.
==> move fields of itab1 into itab_final
READ TABLE itab2 INTO ... WITH KEY lifnr = itab1-lifnr.
==> move fields of itab2 into itab_final.
APPEND itab_final.
ENDLOOP.

hope this helps

ec

13 REPLIES 13
Read only

bpawanchand
Active Contributor
0 Likes
1,241

HI

Use MOVE-CORRESPONDING staement

regards

Pavan

Read only

Former Member
0 Likes
1,241

Can you not even try. Is it to difficult.

This sort of question has been asked before. Try searching for answers before asking such a simple question.

Read only

JozsefSzikszai
Active Contributor
0 Likes
1,242

hi KR,

roughly:

LOOP AT itab1.
==> move fields of itab1 into itab_final
READ TABLE itab2 INTO ... WITH KEY lifnr = itab1-lifnr.
==> move fields of itab2 into itab_final.
APPEND itab_final.
ENDLOOP.

hope this helps

ec

Read only

Former Member
0 Likes
1,241

Hi ...

ITAB[] = ITAB1[]

Loop at ITAB2.

Read table ITAB with key field lifnr transport ......

IF subrc = 0.

move fields of ITAB2 to Itab.

Modify ITAB transport ......

ENDif.

ENDLOOP.

Thanks,

Gaurav.

Read only

former_member386202
Active Contributor
0 Likes
1,241

Hi,

Refer Below code.

LOOP AT it_bsis INTO wa_bsis.

lv_index = sy-tabix.

CLEAR : wa_ekpo.

READ TABLE it_ekpo INTO wa_ekpo WITH KEY ebeln = wa_bsis-ebeln

ebelp = wa_bsis-ebelp

BINARY SEARCH.

IF sy-subrc EQ 0.

wa_bsis-txz01 = wa_ekpo-txz01.

ENDIF.

CLEAR : wa_ekbe.

READ TABLE it_ekbe INTO wa_ekbe WITH KEY ebeln = wa_bsis-ebeln

ebelp = wa_bsis-ebelp

belnr = wa_bsis-mblnr1

BINARY SEARCH.

IF sy-subrc EQ 0.

wa_bsis-menge = wa_ekbe-menge.

ENDIF.

MODIFY it_bsis FROM wa_bsis INDEX lv_index

TRANSPORTING txz01 menge.

CLEAR : wa_bsis,

wa_ekpo.

ENDLOOP.

ENDIF.

Regards,

Prashant

Read only

Former Member
0 Likes
1,241

hiii

you can do it if same structure is there in your final internal table use like below first line then if you want to take data based on condition then use with READ statement.

i_output = i_marc.

  IF i_marc[] IS NOT INITIAL.

    SELECT matnr                       " Material Number
           werks                       " Plants
           lgort                       " Storage Location
      FROM mard
      INTO TABLE i_mard
       FOR ALL ENTRIES IN i_marc
     WHERE matnr EQ i_marc-matnr
       AND werks EQ i_marc-werks
       AND lgort IN s_lgort.

  ENDIF.                               " IF i_mara[] IS NOT INITIAL


  IF sy-subrc EQ 0.
    LOOP AT i_output INTO wa_output.
      READ TABLE i_mard INTO wa_mard WITH KEY matnr = wa_output-matnr.
      wa_output-lgort = wa_mard-lgort.
      MODIFY i_output FROM wa_output.
      CLEAR wa_output.
    ENDLOOP.                           " LOOP AT i_output
  ENDIF.                               " IF sy-subrc EQ 0

regards

twinkal

Read only

Former Member
0 Likes
1,241

Hi,

Sort both the internal tables by lifnr.

1. For moving matching records only.

loop at itab1.

loop at itab2 with key lifnr eq itab1-lifnr.

endloop.

endloop.

2. To move all records irrespective of the LIFNR value.

i_final[] = itab1[].

append i_final.

loop at itab2.

<use Move statements..>

append i_final.

endloop.

Thanks,

Anita

Read only

Former Member
0 Likes
1,241

sort itab1 by lifnr.

sort itab2 by lifnr.

loop at itab1.

read table itab2 with key lifnr = itab1-lifnr binarysearch.

if sy-subrc = 0.

move-correponding itab to itab.

endif.

move-corresponding itab1 to itab.

append itab.

endloop.

Regards

Murali Papana

Read only

Former Member
0 Likes
1,241

Hi,

loop at itab1.

read table itab2 with key lifnr = itab1-lifnr.

itab-LIFNR = itab1-lifnr.

itab- KTOKK = itab1-ktokk.

itab-NMAE1 = itab1-name1.

itab-LAND = itab1-land1.

itab-AKONT = itab2-akont.

itab-ZTERM = itab2-zterm.

append itab.

endloop.

if itab2 contains one record for multiple records in itab1 do above else loop it on either way

Regaurds,

sree.

Read only

Former Member
0 Likes
1,241

Hi,

loop at itab1.

read table itab2 with key lifnr = itab1-lifnr.

itab-LIFNR = itab1-lifnr.

itab- KTOKK = itab1-ktokk.

itab-NMAE1 = itab1-name1.

itab-LAND = itab1-land1.

itab-AKONT = itab2-akont.

itab-ZTERM = itab2-zterm.

append itab.

endloop.

if itab2 contains one record for multiple records in itab1 do above else loop it on either way

Regaurds,

sree.

Read only

Former Member
0 Likes
1,241

Hello,

you have a common field LIFNR in both the table itab1 and itab2 based on the join get the data in a structure and use move corresponding in the main itab table.

Thanks and Regards,

Gunjan

Read only

Former Member
0 Likes
1,241

Try it like this:

Loop at ITAB1 into WA1.
  Loop at ITAB2 into WA2 where LIFNR EQ WA1-LIFNR.

     WA3-LIFNR   = WA1-LIFNR.
     WA3-KTOKK = WA1-KTOKK. 
     WA3-NMAE1 = WA1-NMAE1.
     WA3-LAND1  = WA1-LAND1.
     WA3-AKONT = WA2-AKONT.
     WA3-ZTERM = WA2-ZTERM.

   Append WA3 to ITAB3.

  Endloop.
Endloop.

With luck,

Pritam.

Read only

Subhankar
Active Contributor
0 Likes
1,241

Hi...

Please try in this way

Loop at i_TAB1 into wa_ITAB1.

read table i_tab2 into wa_ITAB2 with key lifnr = wa_itab1-lifnr.

if sy-subrc = 0.

populate final work area using wa_itab1 and wa_itab2.

append it to final table.

endif.

endloop.