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 loop in oops

rohit_kaikala
Participant
0 Likes
1,098

Hi,

how 2 loop the internal table in oops program

Does loop and read work normally or are they any alternatives?

Thank U

Rohith

4 REPLIES 4
Read only

Former Member
0 Likes
592

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.

Read only

Former Member
0 Likes
592

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>
ENDLOOP

The 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>
endif

Reward Points if useful.

Read only

rohit_kaikala
Participant
0 Likes
592

hi,

Do we have any difference in oops abap from 6.0 ECC

thanks,

Rohith.

Read only

rohit_kaikala
Participant
0 Likes
592

thank u