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

internal table problem

Former Member
0 Likes
1,408

Dear Experts,

i am using five internal tables, to fill the different data,

Now i need to display it in ouput,

how to fill this in one internal table,

i created one internal table with all the fileds of all above five internal tables.

how to get it in one internal table.

Thanks and regards.

Thirukumaran. R

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,375

Hi,

use this simple code to solve your issue...


DO.
  CLEAR : FS_ITAB1, FS_ITAB2, FS_ITAB3, FS_ITAB4, FS_ITAB5.

  READ TABLE T_ITAB1 INTO FS_ITAB1 INDEX SY-INDEX.
  READ TABLE T_ITAB2 INTO FS_ITAB2 INDEX SY-INDEX.
  READ TABLE T_ITAB3 INTO FS_ITAB3 INDEX SY-INDEX.
  READ TABLE T_ITAB4 INTO FS_ITAB4 INDEX SY-INDEX.
  READ TABLE T_ITAB5 INTO FS_ITAB5 INDEX SY-INDEX.

  IF FS_ITAB1 IS INITIAL AND
      FS_ITAB2 IS INITIAL AND
      FS_ITAB3 IS INITIAL AND
      FS_ITAB4 IS INITIAL AND
      FS_ITAB5 IS INITIAL.
               EXIT.
  ELSE.
     MOVE-CORRESPONDING FS_ITAB1 TO FS_FINAL_ITAB.
     MOVE-CORRESPONDING FS_ITAB1 TO FS_FINAL_ITAB. 
     MOVE-CORRESPONDING FS_ITAB1 TO FS_FINAL_ITAB.
     MOVE-CORRESPONDING FS_ITAB1 TO FS_FINAL_ITAB.
     MOVE-CORRESPONDING FS_ITAB1 TO FS_FINAL_ITAB.
    APPEND FS_FINAL_ITAB TO T_FINAL_ITAB.
  ENDIF.
ENDDO.

Regards,

Siddarth

12 REPLIES 12
Read only

former_member386202
Active Contributor
0 Likes
1,375

Hi,

Use Read statement, refer following code

IF NOT it_bsis[] IS INITIAL.

LOOP AT it_bsis INTO wa_bsis.

wa_final-blart = wa_bsis-blart.

wa_final-belnr = wa_bsis-belnr.

wa_final-bldat = wa_bsis-bldat.

wa_final-budat = wa_bsis-budat.

wa_final-xref3 = wa_bsis-xref3.

wa_final-zuonr = wa_bsis-zuonr.

wa_final-ebeln = wa_bsis-ebeln.

wa_final-txz01 = wa_bsis-txz01.

wa_final-lifnr = wa_bsis-lifnr.

IF wa_bsis-shkzg EQ 'H'.

wa_final-dmbtr = wa_bsis-dmbtr * ( -1 ).

ELSE.

wa_final-dmbtr = wa_bsis-dmbtr.

ENDIF.

IF wa_bsis-blart EQ 'RE'.

wa_final-menge = wa_bsis-menge.

ENDIF.

CLEAR : wa_mseg.

READ TABLE it_mseg INTO wa_mseg WITH KEY mblnr = wa_bsis-mblnr

mjahr = wa_bsis-mjahr

ebeln = wa_bsis-ebeln

ebelp = wa_bsis-ebelp

BINARY SEARCH.

IF sy-subrc EQ 0.

wa_final-lifnr = wa_mseg-lifnr.

wa_final-txz01 = wa_mseg-txz01.

IF wa_bsis-blart EQ 'WE'.

wa_final-erfmg = wa_mseg-erfmg.

ENDIF.

IF wa_bsis-ebeln IS INITIAL.

wa_final-ebeln = wa_mseg-ebeln.

ENDIF.

ENDIF.

IF wa_bsis-blart EQ 'WE'.

wa_final-mblnr = wa_bsis-mblnr.

ENDIF.

APPEND wa_final TO it_final.

CLEAR : wa_bsis,

wa_final,

wa_mseg,

wa_mkpf.

ENDLOOP.

ENDIF.

Regards,

Prashant

Read only

former_member386202
Active Contributor
0 Likes
1,375

Hi,

Use Read statement, refer following code

IF NOT it_bsis[] IS INITIAL.

LOOP AT it_bsis INTO wa_bsis.

wa_final-blart = wa_bsis-blart.

wa_final-belnr = wa_bsis-belnr.

wa_final-bldat = wa_bsis-bldat.

wa_final-budat = wa_bsis-budat.

wa_final-xref3 = wa_bsis-xref3.

wa_final-zuonr = wa_bsis-zuonr.

wa_final-ebeln = wa_bsis-ebeln.

wa_final-txz01 = wa_bsis-txz01.

wa_final-lifnr = wa_bsis-lifnr.

IF wa_bsis-shkzg EQ 'H'.

wa_final-dmbtr = wa_bsis-dmbtr * ( -1 ).

ELSE.

wa_final-dmbtr = wa_bsis-dmbtr.

ENDIF.

IF wa_bsis-blart EQ 'RE'.

wa_final-menge = wa_bsis-menge.

ENDIF.

CLEAR : wa_mseg.

READ TABLE it_mseg INTO wa_mseg WITH KEY mblnr = wa_bsis-mblnr

mjahr = wa_bsis-mjahr

ebeln = wa_bsis-ebeln

ebelp = wa_bsis-ebelp

BINARY SEARCH.

IF sy-subrc EQ 0.

wa_final-lifnr = wa_mseg-lifnr.

wa_final-txz01 = wa_mseg-txz01.

IF wa_bsis-blart EQ 'WE'.

wa_final-erfmg = wa_mseg-erfmg.

ENDIF.

IF wa_bsis-ebeln IS INITIAL.

wa_final-ebeln = wa_mseg-ebeln.

ENDIF.

ENDIF.

IF wa_bsis-blart EQ 'WE'.

wa_final-mblnr = wa_bsis-mblnr.

ENDIF.

APPEND wa_final TO it_final.

CLEAR : wa_bsis,

wa_final,

wa_mseg,

wa_mkpf.

ENDLOOP.

ENDIF.

Regards,

Prashant

Read only

former_member386202
Active Contributor
0 Likes
1,375

Hi,

Use Read statement, refer following code

IF NOT it_bsis[] IS INITIAL.

LOOP AT it_bsis INTO wa_bsis.

wa_final-blart = wa_bsis-blart.

wa_final-belnr = wa_bsis-belnr.

wa_final-bldat = wa_bsis-bldat.

wa_final-budat = wa_bsis-budat.

wa_final-xref3 = wa_bsis-xref3.

wa_final-zuonr = wa_bsis-zuonr.

wa_final-ebeln = wa_bsis-ebeln.

wa_final-txz01 = wa_bsis-txz01.

wa_final-lifnr = wa_bsis-lifnr.

IF wa_bsis-shkzg EQ 'H'.

wa_final-dmbtr = wa_bsis-dmbtr * ( -1 ).

ELSE.

wa_final-dmbtr = wa_bsis-dmbtr.

ENDIF.

IF wa_bsis-blart EQ 'RE'.

wa_final-menge = wa_bsis-menge.

ENDIF.

CLEAR : wa_mseg.

READ TABLE it_mseg INTO wa_mseg WITH KEY mblnr = wa_bsis-mblnr

mjahr = wa_bsis-mjahr

ebeln = wa_bsis-ebeln

ebelp = wa_bsis-ebelp

BINARY SEARCH.

IF sy-subrc EQ 0.

wa_final-lifnr = wa_mseg-lifnr.

wa_final-txz01 = wa_mseg-txz01.

IF wa_bsis-blart EQ 'WE'.

wa_final-erfmg = wa_mseg-erfmg.

ENDIF.

IF wa_bsis-ebeln IS INITIAL.

wa_final-ebeln = wa_mseg-ebeln.

ENDIF.

ENDIF.

IF wa_bsis-blart EQ 'WE'.

wa_final-mblnr = wa_bsis-mblnr.

ENDIF.

APPEND wa_final TO it_final.

CLEAR : wa_bsis,

wa_final,

wa_mseg,

wa_mkpf.

ENDLOOP.

ENDIF.

Regards,

Prashant

Read only

sridhar_meesala
Active Contributor
0 Likes
1,375

Hi,

Try using MOVE-CORRESPONDING.

MOVE-CORRESPONDING itab1 TO final_itab.
MOVE-CORRESPONDING itab2 TO final_itab.
MOVE-CORRESPONDING itab3 TO final_itab.
MOVE-CORRESPONDING itab4 TO final_itab.
MOVE-CORRESPONDING itab5 TO final_itab.

Thanks,

Sri.

Read only

former_member404244
Active Contributor
0 Likes
1,375

Hi,

I donno if i understood correctly, but this is what u can do Loop one internal table haviing more data and then read rest of them...and finally append the values...

Regards,

Nagaraj

Read only

former_member842213
Participant
0 Likes
1,375

Hi

There should be some link between all the five internaltables,using that loop the main internal table and read the other

internal tables with relation ascondition and append in your fifth internal table

Example

LOOP AT ibagmast INTO wabagmastf.

READ TABLE imailcenter INTO wamailcenter

WITH KEY shipping_point = wabagmastf-shipping_point.

IF sy-subrc = 0.

wafinal-werkt = wamailcenter-shipping_point_d.

ENDIF.

READ TABLE ibagdocs INTO wabagdocs

WITH KEY guid = wabagmastf-guid.

IF sy-subrc EQ 0.

wafinal-vbeln = wabagdocs-document_number.

wafinal-inspection_lot = wabagdocs-inspection_lot.

ENDIF.

  • Filling bagmast data to final internal table

wafinal-werk = wabagmastf-shipping_point.

wafinal-budat = wabagmastf-posting_date.

wafinal-bgid = wabagmastf-bag_id.

wafinal-matnr = wabagmastf-product.

wafinal-ocid = wabagmastf-originating_cust.

wafinal-kunnr = wabagmastf-customer_account.

wafinal-canum = wabagmastf-ship_to_account.

wafinal-matnr = wabagmastf-product.

wafinal-guid = wabagmastf-guid.

wafinal-bag_status = wabagmastf-bag_status.

wafinal-service_type = wabagmastf-service_type.

APPEND wafinal TO ifinal.

CLEAR wafinal.

ENDLOOP.

Read only

Former Member
0 Likes
1,376

Hi,

use this simple code to solve your issue...


DO.
  CLEAR : FS_ITAB1, FS_ITAB2, FS_ITAB3, FS_ITAB4, FS_ITAB5.

  READ TABLE T_ITAB1 INTO FS_ITAB1 INDEX SY-INDEX.
  READ TABLE T_ITAB2 INTO FS_ITAB2 INDEX SY-INDEX.
  READ TABLE T_ITAB3 INTO FS_ITAB3 INDEX SY-INDEX.
  READ TABLE T_ITAB4 INTO FS_ITAB4 INDEX SY-INDEX.
  READ TABLE T_ITAB5 INTO FS_ITAB5 INDEX SY-INDEX.

  IF FS_ITAB1 IS INITIAL AND
      FS_ITAB2 IS INITIAL AND
      FS_ITAB3 IS INITIAL AND
      FS_ITAB4 IS INITIAL AND
      FS_ITAB5 IS INITIAL.
               EXIT.
  ELSE.
     MOVE-CORRESPONDING FS_ITAB1 TO FS_FINAL_ITAB.
     MOVE-CORRESPONDING FS_ITAB1 TO FS_FINAL_ITAB. 
     MOVE-CORRESPONDING FS_ITAB1 TO FS_FINAL_ITAB.
     MOVE-CORRESPONDING FS_ITAB1 TO FS_FINAL_ITAB.
     MOVE-CORRESPONDING FS_ITAB1 TO FS_FINAL_ITAB.
    APPEND FS_FINAL_ITAB TO T_FINAL_ITAB.
  ENDIF.
ENDDO.

Regards,

Siddarth

Read only

Former Member
0 Likes
1,375

Hi,

You mean that you have 5 internal tables with different fields and want to combine them into one internal table. In that case, I'm sure there must be some common fields in all the itabs and using these, you can relate one table with the other. Using this relationship, loop at the table which you think is the primary table and inner loop on tables having 1 to many or 1..1 relationship and keep appending records to the final itab.

If all the fields are same in all the tables and you want to combine this into 1. Then use the statement APPEND LINES OF ITAB_source to ITAB_target.

BR,

Advait

Read only

Former Member
0 Likes
1,375

Loop one internal table and read rest tables according to the key of looping table and append the data into final internal table

For example

if you have tow internal table itab1 and itab2 as follows

ITAB1--- MATNR and SPART

ITAB2 MATNR and LGORT

ITAB_FINAL -- MATNR,SPART and LGORT

Example

loop at itab1 into wa_itab1.

move wa_itab1-matnr to itab_final-matnr.

move wa_itab1-spart to itab_final-spart.

read table ITAB2 into wa_itab2 with key matnr = itab1-matnr.

if sy-aubrc = 0.

move wa_itab2-lgort to itab_final-lgort.

endif.

append itab_final.

endloop.

Now in the same manner you can move data of five internal tables into a final internal table.

Hope this will help you.

Read only

Former Member
0 Likes
1,375

to do this you must have some key in common in itabs

so loop at one table

read the 2nd with key fields in the 1st and 2nd in common

read the 3rd with key common in 3rd and (1st or 2nd)

read the 4th eith key common in 4th and (1st or 2nd or 3rd)

read the 5th with key common in 5th and (1st or 2nd or 3rd or 4th)

now move-corrosponding fields to final itab

append.

Read only

Former Member
0 Likes
1,375

Hi Rajendran,

Try the following way.....



Move corresponding itab1[] to itab_final.
loop at itab2 into wa_itab2.
w_idx = sy-tabix.      
read table itab_final into wa_itab_final index w_idx.

move corresponding wa_itab2 into wa_itab_final.
modify table itab_final index w_idx from wa_itab_final.
 
Read itab3 into wa_itab3 index w_idx.
move corresponding wa_itab3 into wa_itab_final.
modify table itab_final index w_idx from wa_itab_final.
 
 
Read itab4 into wa_itab4 index w_idx.
move corresponding wa_itab4 into wa_itab_final.
modify table itab_final index w_idx from wa_itab_final.
 
Read itab5 into wa_itab5 index w_idx.
move corresponding wa_itab5 into wa_itab_final.
modify table itab_final index w_idx from wa_itab_final.
 
endloop.

Regards,

Mdi.Deeba

Read only

Former Member
0 Likes
1,375

Hi,

you should make loop in each idividual internal table and appending the corresponding into your new Super internal table.

LOOP AT ITAB1.

move-correspondign itab1 to itab.

APPEND ITAB.

CLEAR itab1.

ENDLOOP.

LOOP AT ITAB2.

move-correspondign itab2 to itab.

APPEND ITAB.

CLEAR itab2.

ENDLOOP.

At the end of this opperation the table itab will have all the context of the tables itab1, itab2. You can use the command COLLECT instead of APPEND, if you want to merge the lines (sum all the numeric fields, not the alphanumarecic).

With Regards

George