2009 Feb 11 10:34 AM
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
2009 Feb 11 10:40 AM
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
2009 Feb 11 10:40 AM
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
2009 Feb 11 10:41 AM
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.
2009 Feb 11 10:41 AM
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
2009 Feb 11 10:46 AM
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
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |