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 tables looping.

Former Member
0 Likes
869

Hi all.

I have one internal table which passed to one exit.

Based on the key combinations of the records in this table,

I will get records for 3 more tables.

Now, I have to make a final table which contains for each record

the key of first table, values in first internal table if any for this key,

values in 2nd internal table for this key if any,

values in the third internal table if any.

If 2 or more records exists for one key I have to append all the values one by one to this key.

Please help me out.

Regards,

Veeranji Reddy P.

8 REPLIES 8
Read only

rejish_balakrishnan
Contributor
0 Likes
826

Hi,

Achieve this using a nested loop statement giving IF condition on subsequent level of loop.

eg:

Loop at t_itan into fs_itab.

if field1 = field2 .

w_flag = 1.

.

.

statements

.

.

endif.

loop at t_itab2 into fs_itab2.

if w_flag = 1.

if field3 = field 4.

w_flag_2 = 1.

.

.

statements

.

endif.

loop at t_itab3 into fs_itab3.

.

.

.

like this .

Read only

0 Likes
826

use nested loops.

loop at itab1.

. . . . . . . . .

loop at itab2 where col1 = itab1-col1.

. . . . . . . . .

loop at itab3 where col1 = itab2-col1.

. . . . . . . . .

  • Do summation of fields here.

endloop.

  • Do summation of fields here too if required ( dat is if more than two records are present in itab2 for one record of itab1 ).

endloop.

endloop.

Read only

0 Likes
826

Internal Table 1

Internal Table 2

Internal Table 3

From your Example Internal table 1 is the main table.

Loop at internal table 1.

Read table internal table 2 into work area internal table 2 with key field1 = field1 of itab 1.

if sy-subrc = 0.

Flag1 = 'X'.

endif.

Read table internal table 3 into work area internal table 3 with key field1 = field1 of itab 1.

if sy-subrc = 0.

Flag2 = 'X'.

endif.

if flag1 = 'X' and Flag2 = 'X'.

Append the record from 3 above work areas of internal table.

endif.

clear : flag1, flag2.

endloop.

If you use nested loop it will affect the performance use Binary search in internal table by sorting the key field on internal table.

Cheers,

Naveen

Read only

Former Member
0 Likes
826

Hi,

Hope this logic might help you.

LOOP AT git_header INTO gwa_header.

  • Your Code

LOOP AT git_item INTO gwa_item FROM indx.

indx = indx + 1.

  • Your Code.

  • Delivery Schedule.

LOOP AT git_delv_sch INTO gwa_delv_sch WHERE legpo EQ gwa_item-legpo AND

legit EQ gwa_item-legit.

  • Your code

ENDLOOP. " Item Delivery Schedule

AT END OF legpo.

CLEAR: gwa_poitem, gwa_poitemx,

gwa_poaccount, gwa_poaccountx,

gwa_poaddrdelivery,

gwa_poschedule, gwa_poschedulex.

EXIT.

ENDAT.

ENDLOOP. " PO Item

ENDLOOP. "PO Header

Thanks,

Prashanth

Read only

Former Member
0 Likes
826

Hi,

As per my understanding, you need to get data from all the three tables, and if 2 or more records are fteched, then u need to move them into a final table.

Please find the algorithm below, if this is the scenario

Loop at <tab1>

select * from <tab1> where <key1> = <tab1>-<key> into table <tmp>

if sy-dbcnt > 1.

copy the contents of <tmp> to <final>

endif.

select * from <tab2> where <key2> = <tab1>-<key> into table <tmp>

if sy-dbcnt > 1.

copy the contents of <tmp> to <final>

endif

select * from <tab3> where <key3> = <tab1>-<key> into table <tmp>

if sy-dbcnt > 1.

copy the contents of <tmp> to <final>

endif

Regards,

Shiny

Read only

Former Member
0 Likes
826

Hi,

Simply you need to use the

Loop at <internal table>

For all enetries <sec internal table>

Pooja

Read only

Former Member
0 Likes
826

Hi,

Please try the code below...

data : count1 type i,

count2 type i,

count3 type i.

loop at itab1 into wa1.

count1 = 0.

move-corresponding wa1 to wa_final.

loop at itab2 into wa2 where key = wa1-key.

add 1 to count1.

count2 = 0.

move-corresponding wa2 to wa_final.

loop at itab3 into wa3 where key = wa2-key.

add 1 to count.

move-corresponding wa3 to wa_final.

append wa_final to itab_final.

endloop.

if count2 = 0.

append wa_final to itab_final.

endif.

endloop.

if count1 = 0.

append wa_final to itab_final.

endif.

endloop.

Regards,

Siddarth

Read only

0 Likes
826

Hi all....

Sorry for delayed reply...

I missed main requirement to specify...

Time is to be considered.

If for one interval of first table I have 2 values for 2nd table,

I have to split the period to give 2 values of 2nd table.

Please suggest...

Regards,

Veeranji Reddy P.