‎2007 Oct 01 9:02 AM
I need to loop my internal table. Need to perform if else statement in the loop.
What is the coding for looping internal table? I also need to check if i have successfully loop all the rows.
Will reward points immidiately if my question is solved. Thanks.
‎2007 Oct 01 9:52 AM
DATA: BEGIN OF itab OCCURS 10,
qty type I,
END OF itab.
DO 25 TIMES. itab-qty = sy-index. APPEND itab.
ENDDO.
LOOP AT itab.
if itab-qty ne 0.
WRITE: /1 itab-qty.
endif.
ENDLOOP.
‎2007 Oct 01 9:04 AM
Loop at itab into watab.
if watab-qty < 100.
watab-count = watab-count + 1.
elseif watab-qty > 100 and watab-qty < 200.
watab-range = watab-range + 1.
endif.
modify itab from watab.
endloop.
‎2007 Oct 01 9:05 AM
Hi,
Try this.
loop at itab.
if itab-field1 > 1.
processing...
else.
processing.
endif.
endloop.
Or in the ABAP editor, place your cursor in the loop word and press F1 so you can see the documentation for LOOP statement. The same for the IF statement. You can learn a lot from their docs.
‎2007 Oct 01 9:06 AM
Hi,
do like this
Loop at itab.
if itab-field1 eq <some value>.
do this
else.
do this.
exit.
endloop.
U can get number of lines in an internal table
describe table itab lines v_lines.
Regards,
Nagaraj
‎2007 Oct 01 9:07 AM
Hi,
LOOP AT itab result [cond].
if result [cond]
write :
else
write :
...
ENDLOOP
u can check the sy-tabix whether u have looped at all the records.
Regards,
Sai
‎2007 Oct 01 9:14 AM
Hi,
data line_count type i, row_count type i.
describe itab lines line_count.
Loop at itab.
if condition
row_count = row_count + 1,
else.
row_count = row_count + 1,
endif.
endloop.
if line_count = row_count.
all rows processed.
endif.
Reward if useful!
‎2007 Oct 01 9:33 AM
Can i have the declaration and all the fields input?
I'm new to ABAP. I need sample code to guide me through.
I need a working code so i can understand how it works.
‎2007 Oct 01 9:51 AM
Hi,
Same i have given,
data line_count type i, row_count type i.
data: itab type table of mara.
data: wa_itab like line of itab.
start-of-selection.
select * from mara into table itab.
describe itab lines line_count.
Loop at itab into wa_itab.
if wa_itab-matnr = 'A'
row_count = row_count + 1,
else.
row_count = row_count + 1,
endif.
endloop.
if line_count = row_count.
all rows processed.
endif.
Reward if useful!
‎2007 Oct 01 9:52 AM
DATA: BEGIN OF itab OCCURS 10,
qty type I,
END OF itab.
DO 25 TIMES. itab-qty = sy-index. APPEND itab.
ENDDO.
LOOP AT itab.
if itab-qty ne 0.
WRITE: /1 itab-qty.
endif.
ENDLOOP.
‎2007 Oct 01 10:25 AM
I have a database table name ZSTUD04.
This is my code. Is there something wrong?
The write statement does not appear.
Actually i'm doing validation methods. If the data in the database table
does not telly with the validation rules(stored in OS), it will highlight the cell that has something wrong. So my supervisor ask me to do a loop on all rows first den check according to the OS table.
Validate if the fields are mandatory, data type, unique check... etc.
Simply has no idea on how to do it.
TABLES ZSTUD04.
data: itab TYPE TABLE OF ZSTUD04,
watab TYPE ZSTUD04.
loop at itab into watab.
if watab-eyear > 2005.
processing...
WRITE 'Above 2005'.
else.
processing.
WRITE 'Below 2005'.
endif.
endloop.
‎2007 Oct 01 10:33 AM
hi jocelyn,
is this code complete .. i mean where r u moving the data into the internal table specified.
‎2007 Oct 01 10:35 AM
Hi,
ur code seems to be ok..only thing u have to check whether u have data in the internal table iatb..Also put a brak point at "LOOP AT ITAB INTO WATAB" and see whether ur write statement is triggering or not.
Regards,
Nagaraj
‎2007 Oct 01 10:37 AM
hi
to move dat to the corresponding internal table use select statement.
‎2007 Oct 01 10:38 AM
Ermmm... i'm trying to create an internal table for my ZSTUD04 database table.
data: itab TYPE TABLE OF ZSTUD04,
watab TYPE ZSTUD04.
Is this the way to declare an internal table? Is watab my internal table?
Sorry I'm new to ABAP language.
Get very confuse with the overwhelming infomation in the forum.
‎2007 Oct 01 10:42 AM
hi,
the internal table declaration is fine.. only thing is you have to copy data from zstud04 to itab.
you can use :
select * from zstud04 into corresonding fields of itab.
after that you can proceed with your if-else conditions.
hope this helps..
‎2007 Oct 01 10:43 AM
hi,
Yes its an internal table.
<b>data: itab TYPE TABLE OF ZSTUD04,
watab TYPE ZSTUD04</b>.
to make watab an work area, the declaration should be
<b>data: itab TYPE TABLE OF ZSTUD04, "internal table
data: watab LIKE line of itab.</b> " work area
‎2007 Oct 01 10:53 AM
I have added. But still nothing appear. This is my code.
Any suggestion to do it another way?
TABLES ZSTUD03.
data: itab TYPE TABLE OF ZSTUD03,
watab TYPE ZSTUD03.
loop at itab into watab.
select * from ZSTUD03 into corresponding fields of watab.
ENDSELECT.
if watab-eyear > 2005.
processing...
WRITE 'Above 2005'.
else.
processing.
WRITE 'Below 2005'.
endif.
endloop.
‎2007 Oct 01 11:08 AM
TABLES ZSTUD03.
data: itab TYPE TABLE OF ZSTUD03,
watab TYPE ZSTUD03.
select * from ZSTUD03 into table itab.
loop at itab into watab.
if watab-eyear > 2005.
* processing...
WRITE 'Above 2005'.
else.
* processing.
WRITE 'Below 2005'.
endif.
endloop.
reward if useful.
‎2007 Oct 01 11:12 AM
TABLES ZSTUD03.
data: itab TYPE TABLE OF ZSTUD03.
data: watab like line of itab.
select * from ZSTUD03 into corresponding fields of table itab.
loop at itab into watab.
if watab-eyear > 2005.
* processing...
WRITE 'Above 2005'.
else.
* processing.
WRITE 'Below 2005'.
endif.
endloop.
<b>Hope this works.</b>
Message was edited by:
Runal Singh
‎2007 Oct 01 11:14 AM
try this..
TABLES ZSTUD03.
data: itab TYPE TABLE OF ZSTUD03,
watab like line of ZSTUD03.
select * from ZSTUD03 into corresponding fields of itab.
endselect.
loop at itab into watab.
if watab-eyear > 2005.
processing...
WRITE 'Above 2005'.
else.
processing.
WRITE 'Below 2005'.
endif.
endloop.
Message was edited by:
ritika malhotra
‎2007 Oct 02 3:27 AM
Thanks everyone for the response.
I can understand now how to do a basic loop.