‎2007 Dec 30 12:23 PM
‎2007 Dec 30 12:30 PM
Hi Srinath,
Loop at Statement is used for process records in your internal table by using loop at statement we found records by sequence.
Ex:-
Loop at itab.
write itab-field1.
endloop.
Plzz Reward if it is useful,
Mahi.
‎2007 Dec 30 8:24 PM
if you want to process the data in itab... u need to hit the exact record/records to make the chagnes .. loop at will help you accomplish that.
‎2007 Dec 30 9:17 PM
Hi srinath,
please read carefully to prepare the next question:
[ABAP Statements an Overview |http://help.sap.com/saphelp_erp2005vp/helpdata/en/fc/eb2d4d358411d1829f0000e829fbfe/frameset.htm]
Thank you for your cooperation.
Regards,
Clemens
‎2007 Dec 31 4:12 AM
Hi Srinath
I am writing some details for you,
Please reward pts also.
Regards
Deepanker.
Loops
In a loop, a statement block is executed several times in succession. There are four kinds of loops in ABAP:
· Unconditional loops using the DO statement.
· Conditional loops using the WHILE statement.
· Loops through internal tables and extract datasets using the LOOP statement.
· Loops through datasets from database tables using the SELECT statement.
This section deals with DO and WHILE loops. SELECT is an Open SQL statement, and is described in the Open SQLsection. The LOOP statement is described in the sections on internal tables and extract datasets.
Unconditional Loops
To process a statement block several times unconditionally, use the following control structure:
ENDDO.
Use the TIMES addition to restrict the number of loop passes to n.
If you do not specify any additions, the statement block is repeated until it reaches a termination statement such as EXIT or STOP (see below). The system field sy-index contains the number of loop passes, including the current loop pass.
You can nest DO loops and combine them with other loop forms.
Simple example of a DO loop:
DO.
WRITE sy-index.
IF sy-index = 3.
EXIT.
ENDIF.
ENDDO.
The list output is:
1 2 3
The loop is processed three times. Here, the processing passes through the loop three times and then leaves it after the EXIT statement.
Example of two nested loops with the TIMES addition:
DO 2 TIMES.
WRITE sy-index.
SKIP.
DO 3 TIMES.
WRITE sy-index.
ENDDO.
SKIP.
ENDDO.
The list output is:
1
1 2 3
2
1 2 3
The outer loop is processed twice. Each time the outer loop is processed, the inner loop is processed three times. Note that the system field sy-index contains the number of loop passes for each loop individually.
Conditional Loops
To repeat a statement block for as long as a certain condition is true, use the following control structure:
WHILE log_exp
ENDWHILE.
log_exp can be any logical expression. The statement block between WHILE and ENDWHILE is repeated as long as the condition is true or until a termination statement such as EXIT or STOP occurs. The system field sy-index contains the number of loop passes, including the current loop pass.
You can nest WHILE loops to any depth, and combine them with other loop forms.
REPORT demo_flow_control_while.
DATA: length TYPE i VALUE 0,
strl TYPE i VALUE 0,
string(30) TYPE c VALUE 'Test String'.
strl = strlen( string ).
WHILE string NE space.
WRITE string(1).
length = sy-index.
SHIFT string.
ENDWHILE.
WRITE: / 'STRLEN: ', strl.
WRITE: / 'Length of string:', length.
The output appears as follows:
T e s t S t r i n g
STRLEN: 11
Length of String: 11
Here, a WHILE loop is used to determine the length of a character string. This is done by shifting the string one position to the left each time the loop is processed until it contains only blanks. This example has been chosen to demonstrate the WHILE statement. Of course, you can determine the length of the string far more easily and efficiently using the strlen function.
Terminating Loops
ABAP contains termination statements that allow you to terminate a loop prematurely. There are two categories of termination statement - those that only apply to the loop, and those that apply to the entire processing block in which the loop occurs. The STOPand REJECT statements belong to the latter group (see Exiting Eventblocks).
The termination statements that apply only to the loop in which they occur are CONTINUE, CHECKand EXIT. You can only use the CONTINUE statement in a loop. CHECK and EXIT, on the other hand, are context-sensitive. Within a loop, they only apply to the execution of the loop itself. Outside of a loop, they terminate the entire processing block in which they occur (subroutine, dialog module, event block, and so on).
CONTINUE, CHECK and EXITcan be used in all four loop types in ABAP (DO, WHILE, LOOP and SELECT).
Terminating a Loop Pass Unconditionally
To terminate a single loop pass immediately and unconditionally, use the CONTINUE statement in the statement block of the loop.
CONTINUE.
After the statement, the system ignores any remaining statements in the current statement block, and starts the next loop pass.
DO 4 TIMES.
IF sy-index = 2.
CONTINUE.
ENDIF.
WRITE sy-index.
ENDDO.
The list output is:
1 3 4
The second loop pass is terminated without the WRITE statement being processed.
Terminating a Loop Pass Conditionally
To terminate a single loop pass conditionally, use the CHECK condition statement in the statement block of the loop.
CHECK condition.
If the condition is not true, any remaining statements in the current statement block after the CHECK statement are ignored, and the next loop pass starts. condition can be any logical expression.
DO 4 TIMES.
CHECK sy-index BETWEEN 2 and 3.
WRITE sy-index.
ENDDO.
The list output is:
2 3
The first and fourth loop passes are terminated without the WRITE statement being processed, because sy-index is not between 2 and 3.
Exiting a Loop
To terminate an entire loop immediately and unconditionally, use the EXIT statement in the statement block of the loop.
EXIT.
After this statement, the loop is terminated, and processing resumes after the closing statement of the loop structure (ENDDO, ENDWHILE, ENDLOOP, ENDSELECT). In nested loops, only the current loop is terminated.
DO 4 TIMES.
IF sy-index = 3.
EXIT.
ENDIF.
WRITE sy-index.
ENDDO.
The list output is:
1 2
In the third loop pass, the loop is terminated before the WRITE statement is processed.
‎2007 Dec 31 4:10 PM
Hi Deepanker
> I am writing some details for you,
Everybody has his/her own truth. Thank you for copying SAP online help and then asking for points
[Loops (SAP Library - ABAP Programming (BC-ABA)):|http://help.sap.com/saphelp_erp2005vp/helpdata/en/fc/eb3564358411d1829f0000e829fbfe/content.htm]
What about your personal New Year's pledge ?
Regards,
Clemens
‎2007 Dec 31 4:20 AM
Dear Srinath,
LOOP AT ITAB.
ENDLOOP.
Actually the LOOP...ENDLOOP statement is an iterative statement. That means the statements written between LOOP...ENDLOOP will run until the corresponding object reaches/satisfies the EOF/Condition.
In the above example, itab means that internal table....
Some times the loop statement will look like...
loop at itab into wa.
endloop.
here, wa means workarea which is having same type of itab.
If the internal table is having header line then no need of specific work area...so it was mentioned that
loop at itab.
endloop.
This loop will execute iteratively (continuously/repetedly) the statements in the block (loop...endloop) until or unless all the records from the internal table is read/processed.
once the control reached the end of itab...then loop will stop and continue the execution with the next statement which is coming after endloop..