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 tables...

Former Member
0 Likes
1,082

Hi all,

I have 3 internal tables with different strcutures, now i need to populate a final internal with all these three internal tables data,...how..

thanks

10 REPLIES 10
Read only

former_member386202
Active Contributor
0 Likes
1,060

Hi,

Use READ table to do that

refer below 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

matt
Active Contributor
0 Likes
1,060

Loop through one, read the other two, build the fourth.

LOOP AT itab1 ASSIGNING <wa1>.
  MOVE-CORRESPONDING <wa1> INTO ls_wa4.
  READ TABLE itab2 ASSIGNING <wa2> WITH TABLE KEY key1 = <wa1>-key1...
  IF sy-subrc IS INITIAL.
      MOVE-CORRESPONDING <wa2> INTO ls_wa4.
  ENDIF.
  READ TABLE itab3 ASSIGNING <wa3> WITH TABLE KEY key2 = <wa1>-key2...
  IF sy-subrc IS INITIAL.
      MOVE-CORRESPONDING <wa3> INTO ls_wa4.
  ENDIF.
  INSERT ls_wa4 INTO TABLE itab4.
ENDLOOP.

If you make the itab2 and itab3 HASHED with the correct keys, then you'll get optimium performance. If they don't have a unique key, define them as SORTED.

Read only

Former Member
0 Likes
1,060

use read statements

Read only

Former Member
0 Likes
1,060

are the three internal tables having some common fields ....if not then i have to say you are working on a very tough and unreliable requirement.

if they are...you need to identify these fields and then poopulate the table.

suppose itab4 is your target table and itab1 , itab2 and itab3 are the two tables with data

loop at itab1 into wa1.

move-corresponding wa1 to wa4.

append wa4 to itab4.

endloop.

loop at itab4 into wa4.

lv_tabix = sy-tabix.

loop at itab2 into wa2 where <field> = wa4-field "compare the common fields here.

wa4_1-<field> = wa2-<field>.

modify itab4 from wa4 index lv_tabix.

endloop.

do the same thing by looping on the other tables...

endloop.

the code above is not checked and is just to give you a hint....you can adjust it as per your requirement

Read only

Former Member
0 Likes
1,060

try it this way, assuming you have a comman field in all the three tables.

Loop at table1 into wa1.
  read table table2 into wa2 where field eq wa1-field.
  read table table3 into wa3 where field eq wa1-field.
   waf-field1 = wa1-field.   
   waf-field2 = wa1-field1.
   waf-field3 = wa2-field1.
   waf-field4 = wa3-field1.
append waf into tablef.
Endloop.

With luck,

Pritam.

Read only

matt
Active Contributor
0 Likes
1,060

>

> try it this way, assuming you have a comman field in all the three tables.

>

>

Loop at table1 into wa1.
>   read table table2 into wa2 where field eq wa1-field.
>   read table table3 into wa3 where field eq wa1-field.
>    waf-field1 = wa1-field.   
>    waf-field2 = wa1-field1.
>    waf-field3 = wa2-field1.
>    waf-field4 = wa3-field1.
> append waf into tablef.
> Endloop.

>

>

> With luck,

> Pritam.

Since when has READ... WHERE been a valid ABAP statement

bad luck.

Read only

0 Likes
1,060

Pritam....

i just hope you wrote a pseudocode and not the abap code...

READ and WHERE don't go together...

Read only

Former Member
0 Likes
1,060

Hi,

There should be a common field among in internal tables.

Then

loop itab1

LOOP itab2.

LOOP itab3.

MOve records to final internal table.

END loop.

END loop.

END loop.

IF there are no line items(single record) then

loop itab1

READ table itab2 with key .....

READ table itab3 with key .....

MOve records to final internal table.

END loop.

Regards,

Murali krishna

Read only

Former Member
0 Likes
1,060

This message was moderated.

Read only

Former Member
0 Likes
1,060

hi gurus..

  • select shipping details from vbkd

SELECT inco1

inco2

INTO CORRESPONDING FIELDS OF TABLE it_sales

FROM vbkd

FOR ALL ENTRIES IN it_sales

WHERE vbeln EQ it_sales-vbeln

AND posnr EQ it_sales-posnr.

  • get description of shipping point

SELECT vtext

INTO CORRESPONDING FIELDS OF TABLE it_sales

FROM tvstt

FOR ALL ENTRIES IN it_sales

WHERE spras = 'en'

AND vstel = it_sales-vstel.

  • get description of incoterms

SELECT bezei

INTO CORRESPONDING FIELDS OF TABLE it_sales

FROM tinct

FOR ALL ENTRIES IN it_sales

WHERE inco1 = it_sales-inco1.

  • AND

  • inco1 = it_sales-inco2.

  • SELECT bezei

  • INTO CORRESPONDING FIELDS OF TABLE it_sales

  • FROM tinct.

  • WHERE inco1 = it_sales-inco2

  • get description route

SELECT bezei

INTO CORRESPONDING FIELDS OF TABLE it_sales

FROM tvrot

FOR ALL ENTRIES IN it_sales

WHERE route = it_sales-route.

  • Get customer details

SELECT kunnr

name1

name2

ort01

pstlz

regio

pfach

INTO CORRESPONDING FIELDS OF TABLE it_sales

FROM kna1

FOR ALL ENTRIES IN it_sales

WHERE kunnr EQ it_sales-kunnr.

how can i store all the data that i extracted into a final internal table (it_details)???

tnx!!