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

Removing a row entry from a internal table

Former Member
0 Likes
1,211

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

1 ACCEPTED SOLUTION
Read only

krzysztof_konitz4
Contributor
0 Likes
1,023

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

7 REPLIES 7
Read only

krzysztof_konitz4
Contributor
0 Likes
1,024

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

Read only

0 Likes
1,023

Thanks everyone. The problem is solved.

Gaurav

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,023

There are a few ways of doing this. You can bypass the records that have a zero by.......


loop at itab where betrg ne 0.
***
endloop.


loop at itab 
if betrg = 0.
continue.
endif.
***
endloop.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,023

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

Read only

0 Likes
1,023

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

Read only

0 Likes
1,023

The AT statement works pretty good in LOOPs when using it for control breaks, like when writing reports and doing subtotals and stuff. But, I agree, you do have to be careful to make sure that you are using it correctly.

Regards,

Rich Heilmanm

Read only

0 Likes
1,023

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