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

looping mechanism

Former Member
0 Likes
988

experts,

if an internal table(ex : itab) contains another internal table (ex : jtab),

which will be the correcct mechanism to loop.

ie first loop jtab then read each row of itab based on criteria

or first loop itab then read each row of jtab.

thanks and regards.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
955

Hi,

First loop itab.

Nested Internal Tables:

Check this links:

http://help.sap.com/saphelp_nw70/helpdata/en/9f/db9eaa35c111d1829f0000e829fbfe/content.htm

Regards

Adil

experts,

if an internal table(ex : itab) contains another internal table (ex : jtab),

which will be the correcct mechanism to loop.

ie first loop jtab then read each row of itab based on criteria

or first loop itab then read each row of jtab.

thanks and regards.

7 REPLIES 7
Read only

Former Member
0 Likes
956

Hi,

First loop itab.

Nested Internal Tables:

Check this links:

http://help.sap.com/saphelp_nw70/helpdata/en/9f/db9eaa35c111d1829f0000e829fbfe/content.htm

Regards

Adil

Read only

Former Member
0 Likes
955

Hi,

Loop at itab.

loop at jtab where field1 = itab-field1.
STATEMENTS.
endloop.

endloop.

Regards,

Shailaja

Read only

Former Member
0 Likes
955

Hi,

first loop Itab then read the row of jtab for each row value of itab.

Mechnism:

The internal table of these kind are called Nested table. The inner table have a set of row for every row in the outer table. so, we need nested loop to access data. The mechanism is similar to any other programming language like C.

for example code , check the link

http://help.sap.com/saphelp_nw70/helpdata/en/9f/db9eaa35c111d1829f0000e829fbfe/content.htm

under the heading

"Formatting Data Using Nested Internal Tables"

Regards,

Anirban

Read only

Former Member
0 Likes
955

hi,

Here you have nested internal tables.

It is always better to LOOP from the top and then LOOP on the inner internal table.

loop at itab.
loop at jtab <condition>.
<program>.
endloop.
endloop

.

Regards

Sumit Agarwal

Read only

Former Member
0 Likes
955

Hi Ramesh,

I will explain with example :

Suppose we have two tables SPFLI and SFLIGHT.

Now if we have to retrieve the fields CARRID, CONNID, CITYFROM & CITYTO from Table SPFLI.

And the fields FLDATE PRICE SEATSMAX & SEATSOCC from SFLIGHT on the condition that SPFLI-CARRID = SFLIGHT-CARRID & SPFLI-CONNID = SFLIGHT-CONNID.

Now the LOOP.....ENDLOOP will be like this :

Loop at t_spfli into fs_spfli.

    write :/ fs_spfli-carrid,
              fs_spfli-connid.

    Loop at t_sflight into fs_sflight where carrid = fs_spfli-carrid
                                                   and connid = fs_spfli-connid.
       write :/ fs_sflight-fldate,
                  fs_sflight-price,
                  fs_sflight-seatsocc,
                  fs_sflight-seatsmax.
     Endloop.

Endloop.

This will fetch all the records from sflight depending upon the condition. This solves the issue.

Regards,

Swapna.

Read only

Former Member
0 Likes
955

Hi Ramesh,

the way will always be...

LOOP AT ITAB.

LOOP AT JTAB.

...........

...........

ENDLOOP.

ENDLOOP.

refer to the link for sample code:

http://sap.ittoolbox.com/groups/technical-functional/sap-dev/call-function-read_text-173330

WIth luck,

Pritam.

Read only

Former Member
0 Likes
955

Hi,

since you are using table within a table.

do like this


LOOP AT itab1.
    LOOP AT itab2 WHERE <cond>.
    ENDLOOP.
ENDLOOP.

Regards

Abhijeet