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

At first - Work area initialized

Former Member
0 Likes
2,235

Hi,

I am quite new to ABAP. Forgive me if this is really a stupid question. But I tried to search and could not find any solution for the same. So here is the problem.

I have an inner loop and I want to use the At first statement here. My code is some thing like

loop at itab_1 into wa_1.

loop at itab_2 into wa_2 where matnr = wa_1-matnr.

at first.

wa_1-netpr = wa_2-netpr

modify itab_1 from wa_1.

continue.

endat.

wa_1-lifnr = wa_2-lifnr.

append wa_1 to itab_3.

endloop.

endloop.

The problem is the work area wa_2 values are initialized when the control gets into at first. Why does this happen? Is this the expected behaviour? If so, how can I modify my code to achieve the same result?

Thanks

Jai

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,296

Hi

loop at itab_1 into wa_1.
*  loop at itab_2 into wa_2 where matnr = wa_1-matnr.
  loop at itab_2 where matnr = wa_1-matnr.
    wa_2 = itab2.
    at first.
       wa_1-netpr = wa_2-netpr
       modify itab_1 from wa_1.
        continue.
    endat.
    wa_1-lifnr = wa_2-lifnr.
    append wa_1 to itab_3.
  endloop.
endloop.

U shouldn't use AT FIRST event in a LOOP with the WHERE condition.

Max

Hi

loop at itab_1 into wa_1.
*  loop at itab_2 into wa_2 where matnr = wa_1-matnr.
  loop at itab_2 where matnr = wa_1-matnr.
    wa_2 = itab2.
    at first.
       wa_1-netpr = wa_2-netpr
       modify itab_1 from wa_1.
        continue.
    endat.
    wa_1-lifnr = wa_2-lifnr.
    append wa_1 to itab_3.
  endloop.
endloop.

U shouldn't use AT FIRST event in a LOOP with the WHERE condition.

Max

4 REPLIES 4
Read only

Former Member
0 Likes
1,297

Hi

loop at itab_1 into wa_1.
*  loop at itab_2 into wa_2 where matnr = wa_1-matnr.
  loop at itab_2 where matnr = wa_1-matnr.
    wa_2 = itab2.
    at first.
       wa_1-netpr = wa_2-netpr
       modify itab_1 from wa_1.
        continue.
    endat.
    wa_1-lifnr = wa_2-lifnr.
    append wa_1 to itab_3.
  endloop.
endloop.

U shouldn't use AT FIRST event in a LOOP with the WHERE condition.

Max

Read only

Former Member
0 Likes
1,296

this problems happens somethimes..i dont know why...

define wa_temp type wa_2

do this:

loop at itab_1 into wa_1.

loop at itab_2 into wa_2 where matnr = wa_1-matnr.

wa_temp = wa_2.

'then use wa_temp'

at first.

wa_1-netpr = wa_temp-netpr

modify itab_1 from wa_1.

continue.

endat.

wa_1-lifnr = wa_temp-lifnr.

append wa_1 to itab_3.

endloop.

endloop.

Read only

Former Member
0 Likes
1,296

Hi,

The main pre-requisite to use AT FIRST stmt is to sort the internal table before the looping....

Ex:

Changes made in u code:

sort itan by netpr.

loop at itab_1 into wa_1.

loop at itab_2 into wa_2 where matnr = wa_1-matnr.

at first.

wa_1-netpr = wa_2-netpr

modify itab_1 from wa_1.

continue.

endat.

wa_1-lifnr = wa_2-lifnr.

append wa_1 to itab_3.

endloop.

endloop.

AT FIRST means prints whatever the data in this, at the beging of the loop before displaying the data or populationg the data.Generaly we u use this stmt to print the headers means labels of that table.....

Regards

Kiran

Read only

Former Member
0 Likes
1,296

hi,

In your code, the used AT FIRST will be executed only for the first loop pass, hence use At New <field-name>.

This block is executed for every new value of <field-name>.

Thanks and regards

Sharath