04-28-2006 6:23 AM
how can i use "loop at itab assigning <wa>" on a internal table with header line .thanks!
04-28-2006 6:35 AM
Hi Mao,
Using a Field Symbol
To assign the contents of the current loop line to a field symbol, specify <result> as follows:
LOOP AT <itab> ASSIGNING <FS> <conditions>.
In each loop pass, the field symbol <FS> points to the table entry read in that pass. If the line type is structured, you should specify the same type for the field symbol when you declare it. This allows you to address the components of the field symbol. If you cannot specify the type statically, you must use further field symbols and the technique of assigning components of structures to address the components of the structure.
The end of the loop does not affect the field symbol, that is, after ENDLOOP it is still assigned to the same line as in the final loop pass. If no table entries are processed in the loop, because the table is entry, or no line meets the condition <condition>, the field symbol is not changed.
e.g.
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.
FIELD-SYMBOLS <FS> LIKE LINE OF ITAB.
DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
ENDDO.
READ TABLE ITAB WITH TABLE KEY COL1 = 2 ASSIGNING <FS>.
<FS>-COL2 = 100.
READ TABLE ITAB WITH TABLE KEY COL1 = 3 ASSIGNING <FS>.
DELETE ITAB INDEX 3.
IF <FS> IS ASSIGNED.
WRITE '<FS> is assigned!'.
ENDIF.
LOOP AT ITAB ASSIGNING <FS>.
WRITE: / <FS>-COL1, <FS>-COL2.
ENDLOOP.
The output is:
1 1
2 100
4 16
The example fills a sorted table ITAB with 4 lines. The second line is assigned to the field symbol <FS> (which has the same type), and modified using it. The third line is assigned to <FS> and then deleted. Consequently, the logical expression in the IF statement is untrue. <FS> is used to display the table lines in the LOOP. Afterwards, it points to the third line of the table.
Regards,
Sameena
04-28-2006 6:26 AM
create a field symbol, and use that instead of the header.
eg,
field-symbols <th>.
loop at i_t assigning <th>.
*write:/ <th>-mandt, etc
endloop.
04-28-2006 6:30 AM
Hi,
A small change, the field symbols will have to be declared like the work area of the table
FIELD-SYMBOLS : <fs_MARA> TYPE MARA
OR
FIELD-SYMBOLS : <fs_MARA> LIKE LINE OF ITAB.
Then Loop at itab assigning <fs_mara>
endloop.
Regards,
Ravi
04-28-2006 6:34 AM
hi here is the answer,
data itab like table of mara with header line.
field-symbols <fs> like mara.
loop at itab assigning <fs>.
endloop.
Cheers,
Abdul Hakim
04-28-2006 6:35 AM
Hi Mao,
Using a Field Symbol
To assign the contents of the current loop line to a field symbol, specify <result> as follows:
LOOP AT <itab> ASSIGNING <FS> <conditions>.
In each loop pass, the field symbol <FS> points to the table entry read in that pass. If the line type is structured, you should specify the same type for the field symbol when you declare it. This allows you to address the components of the field symbol. If you cannot specify the type statically, you must use further field symbols and the technique of assigning components of structures to address the components of the structure.
The end of the loop does not affect the field symbol, that is, after ENDLOOP it is still assigned to the same line as in the final loop pass. If no table entries are processed in the loop, because the table is entry, or no line meets the condition <condition>, the field symbol is not changed.
e.g.
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.
FIELD-SYMBOLS <FS> LIKE LINE OF ITAB.
DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
ENDDO.
READ TABLE ITAB WITH TABLE KEY COL1 = 2 ASSIGNING <FS>.
<FS>-COL2 = 100.
READ TABLE ITAB WITH TABLE KEY COL1 = 3 ASSIGNING <FS>.
DELETE ITAB INDEX 3.
IF <FS> IS ASSIGNED.
WRITE '<FS> is assigned!'.
ENDIF.
LOOP AT ITAB ASSIGNING <FS>.
WRITE: / <FS>-COL1, <FS>-COL2.
ENDLOOP.
The output is:
1 1
2 100
4 16
The example fills a sorted table ITAB with 4 lines. The second line is assigned to the field symbol <FS> (which has the same type), and modified using it. The third line is assigned to <FS> and then deleted. Consequently, the logical expression in the IF statement is untrue. <FS> is used to display the table lines in the LOOP. Afterwards, it points to the third line of the table.
Regards,
Sameena
04-28-2006 6:48 AM
DATA : BEGIN OF GT_ZCO001 OCCURS 0.
INCLUDE STRUCTURE ZCO001.
DATA: END OF GT_ZCO001.
DATA: BEGIN OF GT_FILE OCCURS 0,
ZCNTRY TYPE LAND1,
ZOLOC TYPE ZOLOC,
ZOLOC20 TYPE ZOLOC20,
ZOLOC40 TYPE ZOLOC40,
ZAWSYS TYPE LOGSYSTEM,
END OF GT_FILE.
FIELD-SYMBOLS: <FS_ZCO001> TYPE ZCO001,
<FS_FILE> LIKE GT_FILE.
LOOP AT GT_FILE ASSIGNING <FS_FILE>.
<FS_ZCO001>-ZCNTRY = <FS_FILE>-ZCNTRY.
<FS_ZCO001>-ZOLOC20 = <FS_FILE>-ZOLOC20.
<FS_ZCO001>-ZOLOC40 = <FS_FILE>-ZOLOC40.
<FS_ZCO001>-ZAWSYS = <FS_FILE>-ZAWSYS.
APPEND GT_ZCO001.
CLEAR GT_ZCO001.
ENDLOOP.
04-28-2006 7:04 AM
Haha, Sameena's answer is what i wanted, but thank you all all the same,experts.