‎2008 Jun 10 1:08 PM
Hi,
how 2 loop the internal table in oops program
Does loop and read work normally or are they any alternatives?
Thank U
Rohith
‎2008 Jun 10 1:12 PM
Hello,
The loop looks like any loop, the only difference is that the internal table cannot have an work area.
Notes
Within classes, you cannot change table itab in the statement block of the LOOP using statements that access the entire table. Statements such as CLEAR, FREE, LOCAL, REFRESH, SORT and all types of assignments to itab are not allowed.
If you specify the internal table itab through a Reference variable, then the loop is processed completely at the table referenced at entry. Possible changes of the reference variable do not have an effect on the loop. The respective object cannot be deleted from the Garbage Collector, as long as the loop is not completed.
Example
Nested LOOP-loops. The contents of the current row for the outer loop are analyzed in the WHERE-condition for the inner loop.
PARAMETERS p_name TYPE scarr-carrname DEFAULT '*'.
DATA: scarr_tab TYPE SORTED TABLE OF scarr
WITH UNIQUE KEY carrname,
spfli_tab TYPE SORTED TABLE OF spfli
WITH NON-UNIQUE KEY carrid.
FIELD-SYMBOLS <fs> LIKE LINE OF scarr_tab.
DATA spfli_line LIKE LINE OF spfli_tab.
SELECT *
FROM scarr
INTO TABLE scarr_tab.
SELECT *
FROM spfli
INTO TABLE spfli_tab.
LOOP AT scarr_tab ASSIGNING <fs>
WHERE carrname CP p_name.
LOOP AT spfli_tab INTO spfli_line
WHERE carrid = <fs>-carrid.
WRITE: / spfli_line-carrid,
spfli_line-connid.
ENDLOOP.
ENDLOOP.
Example
The following loop deletes all lines of an internal table since - through the short form of the DELETE statement - the current first line is always deleted.
DATA itab TYPE TABLE OF i.
DATA wa LIKE LINE OF itab.
LOOP AT itab INTO wa TO 6.
DELETE itab.
ENDLOOP.
Regards.
‎2008 Jun 10 1:13 PM
Hi,
Looping is the same in OOPS
Check this -
If there is more than one record with the condition VNAM = 'ZVAR1'. Then LOOP AT I_T_VA_RANGE will process all the records that matches the condition..
LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE
WHERE VNAM = 'ZVAR1'.
< logic x>
ENDLOOPThe READ TABLE will get the first occurence of that condition...If there are more than one record..It will get the first record...
READ I_T_VAR_RANGE INTO LOC_VAR_RANGE
with Key VNAM = 'ZVAR1'.
IF sy-subrc = 0
< logic x>
endifReward Points if useful.
‎2008 Jun 10 1:19 PM
hi,
Do we have any difference in oops abap from 6.0 ECC
thanks,
Rohith.
‎2008 Dec 24 11:38 AM