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 related question

Former Member
0 Likes
1,429

I am dealing with variables internal table. There are 4 entries in it. I want to transfer those 4 entries into another internal table. one way is to write 4 loop statements but i want to know if there is a better way of looping through the same records 4 times. can some body please give me the syntax please?

Thanks.

I am dealing with variables internal table. There are 4 entries in it. I want to transfer those 4 entries into another internal table. one way is to write 4 loop statements but i want to know if there is a better way of looping through the same records 4 times. can some body please give me the syntax please?

Thanks.

6 REPLIES 6
Read only

KodandaPani_KV
Active Contributor
0 Likes
1,367

HI,

can you try the below syntax.

IT_FINAL[ ]= IT_FINAL2[]

we are moving all objects form IT_FINAL to IT_FINAL2.

-Phani.

Read only

Former Member
0 Likes
1,367

itab1[] = itab2[].

Read only

sander_vanwilligen
Active Contributor
0 Likes
1,367

Hi,

If the other internal table already contains records, then you should use:

APPEND LINES OF itab1 TO itab2.

Otherwise you can use (as suggested by the others):

itab2 = itab1[].

Best regards,

Sander

Read only

Former Member
0 Likes
1,367

Firstly, thank you every one for their answers. Every one got the points.

See what i want to do is this:

Currently i have my data in Internal table 1 and look like this:

Internal Table 1:

field1     field2     OPTION

12          ZXX          EQ

13          ZNN         EQ

Now, what i want to do is to take these 2 values in another internal table but i also want to manipulate the values. one way is to do this:

Loop at internal table1 into internal table 2

IF INTERNAL TABLE 1 - Field2 = 'ZXX'

INTERNAL TABLE 1 - Field2 = 'ZYY'

ENDIF.

APPEND to another table.

ENDLOOP.

Loop at internal table1 into internal table 2

IF INTERNAL TABLE 1 - Field2 = 'ZXX'

INTERNAL TABLE 1 - Field2 = 'ZGG'

ENDIF.

APPEND to another table.

ENDLOOP.

Because in my second internal table, I want to insert ZYY, ZGG and ZNN (total of three records). This way will work but i think there must be a better way to do this and not call 2 loop statements. so i am trying to find out the best practice.

Thanks.

Read only

0 Likes
1,367

Do you know ABAP? Please learn the ABAP basics or take help from an ABAPper. Looping at one itab into another itab isn't possible.

Here's the code that could help you - there's no need to have two loops.


LOOP AT itab1 into wa1.      "wa1 is a work area of the same struct as itab1

     IF wa1-field2 = 'ZXX'.

          wa1-field2 = 'ZYY'. append wa1 to another_itab.

          wa1-field2 = 'ZGG'. append wa1 to another_itab.

          wa1-field2 = 'ZNN'. append wa1 to another_itab.

     ENDIF.

ENDLOOP.

Read only

Former Member
0 Likes
1,367

Hi,

If both table is having same structure then you need not to put loop for filling records.

Please make two internal tables with similar structure like this as an example.

TYPES : Begin of ty_matnr,

matnr TYPE matnr,

END of ty_matnr.

DATA it_matnr TYPE TABLE of ty_matnr.

DATA  it_matnr1 TYPE TABLE of ty_matnr.

SELECT matnr

FROM mara

INTO TABLE it_matnr

UPTO 4 ROWS.

IF sy-subrc EQ 0.

it_matnr1[] = it_matnr[].

ENDIF.

I hope this clarifies your query.

BR,

Praveen