WE'VE FOUND SAPhelpdesk!!!

***** Read the Reviews / Rate the Solution
We're not quite there yet.But we're getting there!-and we really want you to know when we're ready.
We can send the latest updates to ur email.Just subscribe to the email updates below and confirm the confirmation link in your email

Here's how to stay updated:

Enter ur email:

TO READ LINE IN INTERNAL TABLE

1. To read a single line of an internal table, use the following:
A: LOOP AT itab. _ ENDLOOP.
B: READ itab.
C: SELECT SINGLE * FROM itab.
D: READ TABLE itab.

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 [INTO ] [FROM ] [TO ]

[WHERE ].

.....

ENDLOOP.

You specify the target area using the INTO option. In the case of tables with a header line, you can omit the INTO option. The table work area then becomes the target area.

The internal table is read line by line into or into the table work area . For each line read, the system processes the statement block introduced by LOOP and concluded by ENDLOOP. You can control the flow of the statement block within a LOOP - ENDLOOP block with the control keyword AT (see Loop Processing).

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.

  • By using the FROM option, you can specify with 1 > the index of the first line to be read.
  • By using the TO option, you can specify with 2 > the index of the last line to be read.
  • By using the WHERE option, you can specify any logical expression as (see Programming Logical Expressions). The first operand must be a component of the internal table's line structure. You cannot use the WHERE option if you use the control keyword AT inside the loop.

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

saphelpdesk.co.inYour feedback is always appreciated.I will try to reply Ur queries as soon as time allows.
Regards,
SAPhelpdesk

0 comments:

Post a Comment

Your Ad Here
Write 4 Us ( Support me ) !!!