‎2006 Jun 24 7:41 PM
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
‎2006 Jun 25 6:50 AM
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!
‎2006 Jun 24 7:57 PM
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
‎2006 Jun 24 8:09 PM
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
‎2006 Jun 24 10:38 PM
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
‎2006 Jun 25 5:52 AM
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
‎2006 Jun 25 6:50 AM
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!