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

Former Member
0 Likes
678

hi,

i have internal table records with three fields. only two columns are filled already. how to fill third column records.

the condition is

matnr mtart maktx

-


ab100 xyz

ab110 xyz

how to fill third column.

can we use

select single * stamtement inside loop and endloop.

how can it be solved . please solve the problem with detail explanation with example.

thank u in advance.

regards

sri

1 ACCEPTED SOLUTION
Read only

aris_hidalgo
Contributor
0 Likes
651

Hi,

You could use select single inside a loop or for all entries(outside a loop). using for all entries is faster than using select single inside a loop. About you question, you could do it this way:

loop at itab1.

select single from dbtable

into itab2-field3.

endselect.

if sy-subrc = 0.

move itab2-field3 to itab1-field3.

endif.

modify itab1.

endloop.

In the example above, the structure of itab1 and itab2 are the same. Also, you can use field-symbols so the modify statement will be eliminated giving you more performance in your loop statement.

Regards!

5 REPLIES 5
Read only

Clemenss
Active Contributor
0 Likes
651

Hi Sri,

you could but should not select single in the loop.

Better sort your interal table.

Then

select ...

read table itab with key ... binary search.

  • put value in column 3 if found

endselect.

Regards,

Clemens

Read only

Former Member
0 Likes
651

Hi

U can use a JOIN to insert all data at the same moment:

SELECT AMATNR AMTART B~MAKTX

FROM MARA AS A INNER JOIN MAKT AS B

ON AMATNR = BMATNR

INTO TABLE ITAB

WHERE A~MATNR IN

..............

AND B~SPRAS = SY-LANGU

But if you can't use a JOIN, you have to read the MAKT table in the loop as just you have done:

LOOP AT ITAB.

SELECT SINGLE MAKTX FROM MAKT INTO ITAB-MAKTX

WHERE MATNR = ITAB-MATNR

AND SPRAS = SY-LANGU.

MODIFY ITAB.

ENDLOOP.

Max

Read only

Manohar2u
Active Contributor
0 Likes
651

You can use select single if you don't have many records. Else you need to select them into new internal table to READ in a loop and to modify itab.

Regds

Manohar

Read only

Former Member
0 Likes
651

hi

declare a new internal table and select ur req content of third field using for all entries in clause and then loop at first table and read this new tab with key binay search and move the content to the first table and say modify firsttab.

Regards

Gunjan

Read only

aris_hidalgo
Contributor
0 Likes
652

Hi,

You could use select single inside a loop or for all entries(outside a loop). using for all entries is faster than using select single inside a loop. About you question, you could do it this way:

loop at itab1.

select single from dbtable

into itab2-field3.

endselect.

if sy-subrc = 0.

move itab2-field3 to itab1-field3.

endif.

modify itab1.

endloop.

In the example above, the structure of itab1 and itab2 are the same. Also, you can use field-symbols so the modify statement will be eliminated giving you more performance in your loop statement.

Regards!