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

do while condition

anupam_srivastava2
Participant
0 Likes
34,367

Hi all

I want to write a do while loop, where the condition for while will be end of internal table.

how can I wrtie this..any idea

11 REPLIES 11
Read only

Former Member
0 Likes
12,068

Find the number of entries in the table using the describe statment and do ...enddo for as many entries in itab.


describe table itab lines l_lines.

do l_lines times.
enddo.

regards,

Advait

Read only

0 Likes
12,068

Hi

the internal table size will vary . I want to write something like this.

do

while (end of internal table)

Read only

0 Likes
12,068

Hi C,

Since the internal table size may vary, you can use the

DESCRIBE

statement....This will give the current size of the internal table.

Once you capture the size, then you can use the below given code..

DO...While sy-tabix <= v_index

Here v_index will hold the maximum lines in the internal table....so this loop will be executed until the end of the internal table.

Best Regards,

Ram.

Read only

0 Likes
12,068

the internal table size will vary . I want to write something like this.

That is the reason i recommended you to use the describe statement so that you get the number of lines in the internal table at runtime in a variable.

Anyways, I don't know why you want to do this. As Matt explained LOOP AT ... ENDLOOP should also be sufficient.

regards,

Advait

Read only

Former Member
0 Likes
12,068

Hi,

You can DESCRIBE the internal table and find out the number of records in the internal table.

The you can use that number as your index in the do while statement.

DO... WHILE SY-TABIX <= TableIndex.

Best Regards,

Ram.

Read only

Former Member
0 Likes
12,068

Hi,

Find the number or records in the table using describe statement.


describe table itab lines lin.

do lin times.
write your code....
enddo.

Read only

matt
Active Contributor
0 Likes
12,068

Doesn't LOOP AT... ENDLOOP. exactly meet your needs????

Read only

0 Likes
12,068

>

> Doesn't LOOP AT... ENDLOOP. exactly meet your needs????

Exactly, from what I can judge from reading the first post. I do not understand why anyone would want to make work for themselves by avoiding the simple solution and making things more complicated.

Read only

Former Member
0 Likes
12,068

Hi,

First count the number of lines in internal tables using

describe table it_table lines lv_value.

now the variable lv_value will holds the number of lines in internal table ..

Then do the required do and while conditions based in this count.

Thanks,

ThiruKumaran. R

Read only

Former Member
0 Likes
12,068

Hi,

Describe table tablename lines v_line.

Data count type i value 0.

while count < v_line.

perform code_to_write.

endwhile.

Form code_to_write.

count = count + 1.

endform.

This work exactly as u want.

Thnaks & Regards

Ruchi Tiwari

Read only

anupam_srivastava2
Participant
0 Likes
12,068

thanks for ur replies