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

Control loop statements

Former Member
0 Likes
537

Hello Gurus,

I always have the confusion while I am using the control loops statment with respective to fields I want to use control loops on.

data: begin of sample_tab occurs 0,

field1 like mara-matnr,

field2 like vbrp-vbeln,

field3 like maktx-maktl,

end of sample_tab.

Let's think that FIELD1 is the desired field that I want to apply the control loops statment logic on always. Please also let me know that what care that I have to take before the use of Control loop statement. Please explain following scenarios.

AT end of - field1 is first field in sample_tab?

- field2 is second field in sample_tab?

- field1 is first field in sample_tab and not

a key field of any db table.

- field1 is second field in sample_tab and not

a key field of any db table.

AT frist - field1 is first field in sample_tab?

- field2 is second field in sample_tab?

- field1 is first field in sample_tab and not

a key field of any db table?

- field1 is second field in sample_tab and not

a key field of any db table?

AT last - field1 is first field in sample_tab?

- field2 is second field in sample_tab?

- field1 is first field in sample_tab and not

a key field of any db table?

- field1 is second field in sample_tab and not

a key field of any db table?

on change of - field1 is first field in sample_tab?

- field2 is second field in sample_tab?

- field1 is first field in sample_tab and not

a key field of any db table?

- field1 is second field in sample_tab and not

a key field of any db table?

Thanks in advance.

SDN

1 ACCEPTED SOLUTION
Read only

abdul_hakim
Active Contributor
0 Likes
504

hi

before using the control loop statements you should sort the internal table by control break.

In your case you should sort your itab as <b>SORT SAMPLE_TAB BY FIELD1.</b>

Cheers,

Abdul Hakim

4 REPLIES 4
Read only

Former Member
0 Likes
504
Read only

abdul_hakim
Active Contributor
0 Likes
505

hi

before using the control loop statements you should sort the internal table by control break.

In your case you should sort your itab as <b>SORT SAMPLE_TAB BY FIELD1.</b>

Cheers,

Abdul Hakim

Read only

aris_hidalgo
Contributor
0 Likes
504

Hi,

In order to properly use those statements, you should first sort your itab by field1. For example:

sort sample_tab by field1.

loop at sample_tab.

at end of field1.

write: / 'END'.

endat.

at first.

write: / 'This is the first record'.

endat.

at last.

write: / 'This is the last record'.

endat.

endloop.

Hope this helps...

P.S. Please award points for useful answers.

Read only

former_member186741
Active Contributor
0 Likes
504

AT end of field1

- field1 is first field in sample_tab?

<b> will be processed whenever field1 changes </b>

AT end of field2

- field2 is second field in sample_tab?

<b> will be processed whenever field1 or field2 changes </b>

- field1 is first field in sample_tab and not

a key field of any db table.

<b> will be processed whenever field1 changes </b>

<b> being a key field is not relevant </b>

- field1 is second field in sample_tab and not

a key field of any db table.

<b> will be processed whenever field1 OR the first field changes </b>

<b> being a key field is not relevant </b>

AT frist - field1 is first field in sample_tab?

- field2 is second field in sample_tab?

- field1 is first field in sample_tab and not

a key field of any db table?

- field1 is second field in sample_tab and not

a key field of any db table?

<b> regardless of field values this code will be exected on the very FIRST pass of the loop</b>

AT last - field1 is first field in sample_tab?

- field2 is second field in sample_tab?

- field1 is first field in sample_tab and not

a key field of any db table?

- field1 is second field in sample_tab and not

a key field of any db table?

<b> regardless of field values this code will be exected on the very LAST pass of the loop</b>

on change of - field1 is first field in sample_tab?

- field2 is second field in sample_tab?

- field1 is first field in sample_tab and not

a key field of any db table?

- field1 is second field in sample_tab and not

a key field of any db table?

<b> do not use 'on change' this it is intended for 'selects' not loops. Instead use 'at new ..'. </b>

at new field1.

<b>This will be executed whenever the field1 value differs from the previous pass (or on the first pass).</b>

at new field2.

<b>This will be executed whenever the field1 OR field2 values differ from the previous pass (or on the first pass).</b>