2005 Jul 14 8:52 PM
Hi,
I am displaying a table 'ITAB' which has payroll related entries. While calculating, the amount which is one of the entries of the table, comes out to be zero. I dont want to display those entries which have zero amount. For this I have have made another internal table 'ITAB1'.
LOOP AT ITAB.
WA = ITAB.
IF ITAB-BETRG NE 0.
AT NEW PERNR.
MOVE-CORRESPONDING WA TO ITAB1.
APPEND ITAB1.
ENDAT.
ENDIF.
ENDLOOP.
But its not displaying any records. If I run the program without this new table, then it runs fine with all entries including those with zero amount.
Can someone please tell where is the logical error?
Thanks,
Gaurav
2005 Jul 14 9:15 PM
Hi,
If you just want to copy all entries from ITAB which contain field BETRG <> 0 you can use such a code:
LOOP AT ITAB WHERE BETRG <> 0.
MOVE-CORRESPONDING ITAB TO ITAB1.
APPEND ITAB1.
ENDLOOP.
If your table ITAB doesn't have header line you should use variable for working area for example:
LOOP AT ITAB INTO WA WHERE BETRG <> 0.
MOVE-CORRESPONDING WA TO ITAB1.
APPEND ITAB1.
ENDLOOP.
If you dont't have to keep table ITAB content you can just use:
DELETE ITAB WHERE BETRG = 0.
Krzys
Hi,
I am displaying a table 'ITAB' which has payroll related entries. While calculating, the amount which is one of the entries of the table, comes out to be zero. I dont want to display those entries which have zero amount. For this I have have made another internal table 'ITAB1'.
LOOP AT ITAB.
WA = ITAB.
IF ITAB-BETRG NE 0.
AT NEW PERNR.
MOVE-CORRESPONDING WA TO ITAB1.
APPEND ITAB1.
ENDAT.
ENDIF.
ENDLOOP.
But its not displaying any records. If I run the program without this new table, then it runs fine with all entries including those with zero amount.
Can someone please tell where is the logical error?
Thanks,
Gaurav
2005 Jul 14 9:15 PM
Hi,
If you just want to copy all entries from ITAB which contain field BETRG <> 0 you can use such a code:
LOOP AT ITAB WHERE BETRG <> 0.
MOVE-CORRESPONDING ITAB TO ITAB1.
APPEND ITAB1.
ENDLOOP.
If your table ITAB doesn't have header line you should use variable for working area for example:
LOOP AT ITAB INTO WA WHERE BETRG <> 0.
MOVE-CORRESPONDING WA TO ITAB1.
APPEND ITAB1.
ENDLOOP.
If you dont't have to keep table ITAB content you can just use:
DELETE ITAB WHERE BETRG = 0.
Krzys
2005 Jul 14 9:25 PM
2005 Jul 14 9:15 PM
2005 Jul 14 9:31 PM
I think the other answers you got are correct and the way you want to go, but a further point - "AT" is strictly speaking meant for extract datasets, not looping through internal tables. You can use it for internal tables, but whenever I've tried it, I end up getting in trouble (sometimes after the program is signed off and in production). For that reason, I avoid it. This may be the root of your problem.
Rob
2005 Jul 14 10:03 PM
Hi Rob,
Yes I agree with it since the code I wrote earlier was correct. I am using it comfortably in other parts where I have not use loops
Thanks,
Gaurav
2005 Jul 15 1:17 AM
2005 Jul 15 3:54 AM
I dunno Rich - I think I've used it correctly, but I've been bitten a couple of times by programs running in production for a long time only to see them start to misbehave at a loop at itab statement. I don't have access to R/3 right now, but I think the documentation for AT only applies when looping through extract datasets.
Rob