To read an internal table into a work area line by line, you can program a loop using the LOOP statement. The syntax is as follows: Syntax LOOP AT [WHERE ..... ENDLOOP. You specify the target area The internal table Within the statement block, the system field SY-TABIX contains the index of the current line. The loop ends as soon as all lines of the table have been processed. After the ENDLOOP statement, the system field SY-SUBRC is set to 0 if at least one line was read. Otherwise it is set to 4. You can restrict the number of lines to be processed in the loop by using the FROM, TO, or WHERE options. The FROM and TO options restrict the number of lines which the system has to read. The WHERE option only prevents unnecessary filling of the work area. With the WHERE option, the system must read all lines. To improve performance, you should use the FROM and TO options as much as possible. It can be also beneficial under certain conditions to leave the loop with the EXIT statement (see Terminating a Loop Entirely) instead of using the WHERE option. DATA: BEGIN OF LINE, COL1 TYPE I, COL2 TYPE I, END OF LINE. DATA ITAB LIKE LINE OCCURS 10. DO 30 TIMES. LINE-COL1 = SY-INDEX. LINE-COL2 = SY-INDEX * SY-INDEX. APPEND LINE TO ITAB. ENDDO. LOOP AT ITAB INTO LINE FROM 10 TO 25 WHERE COL2 > 400. WRITE: / SY-TABIX, LINE-COL2. ENDLOOP. The produces the following output: 21 441 22 484 23 529 24 576 25 625 Here, an internal table ITAB based on the field string LINE is created. The table is filled in a DO loop with the numbers between 1 and 30 and the squares of these numbers. The DO loop reads the table line by line. The index of the lines to be read is restricted to the numbers between 10 and 25, and the contents of the second component of each line is restricted to numbers greater than 400.
Confused? Feel free to ask
Your feedback is always appreciated.I will try to reply Ur queries as soon as time allows.
Regards,
SAPhelpdesk
0 comments:
Post a Comment