Video:
Code:
*&———————————————————————*
*& Report ZPR_FS_DEMO1
*&
*&———————————————————————*
*&
*&
*&———————————————————————*
REPORT ZPR_FS_DEMO1.
*******************************************Declare Field Symbols – begin
*DATA IT_MARAV TYPE STANDARD TABLE OF MARAV.
*DATA WA_MARAV LIKE LINE OF IT_MARAV.
** Declare Field Symbols with type
*FIELD-SYMBOLS <FS_MARAV> LIKE LINE OF IT_MARAV.
** Declare Field Symbols without type
*FIELD-SYMBOLS <FS_ANY_TAB> TYPE ANY TABLE.
*FIELD-SYMBOLS <FS_ANY> TYPE ANY.
*******************************************Declare Field Symbols – end
*
*******************************************APPEND and INSERT using Field Symbols – begin
*WRITE: / ‘******************************************APPEND and INSERT using Field Symbols – begin’.
** APPEND lines
*WRITE: / ‘APPEND lines’.
*APPEND INITIAL LINE TO IT_MARAV ASSIGNING <FS_MARAV>.
*<FS_MARAV>-MATNR = ‘000000001’.
*<FS_MARAV>-MAKTX = ‘Test 1’.
*LOOP AT IT_MARAV ASSIGNING <FS_MARAV>.
* WRITE: / <FS_MARAV>-MATNR, ‘ – ‘, <FS_MARAV>-MAKTX.
*ENDLOOP.
** INSERT lines
*WRITE: / ‘INSERT lines’.
*INSERT INITIAL LINE INTO IT_MARAV ASSIGNING <FS_MARAV> INDEX 2.
*<FS_MARAV>-MATNR = ‘000000002’.
*<FS_MARAV>-MAKTX = ‘Test 2’.
*LOOP AT IT_MARAV ASSIGNING <FS_MARAV>.
* WRITE: / <FS_MARAV>-MATNR, ‘ – ‘, <FS_MARAV>-MAKTX.
*ENDLOOP.
*WRITE: / ‘******************************************APPEND and INSERT using Field Symbols – end’.
*******************************************APPEND and INSERT using Field Symbols – end
*
*******************************************Access Internal Table records using Field Symbols – begin
*WRITE: / ‘******************************************Access Internal Table records using Field Symbols – begin’.
** Via READ TABLE
*WRITE: / ‘Via READ TABLE’.
*READ TABLE IT_MARAV ASSIGNING <FS_MARAV> INDEX 1.
*IF SY-SUBRC = 0.
* WRITE: / <FS_MARAV>-MATNR, ‘ – ‘, <FS_MARAV>-MAKTX.
*ELSE.
*ENDIF.
*READ TABLE IT_MARAV ASSIGNING <FS_MARAV> WITH KEY MATNR = ‘000000002’.
*IF SY-SUBRC = 0.
* WRITE: / <FS_MARAV>-MATNR, ‘ – ‘, <FS_MARAV>-MAKTX.
*ELSE.
*ENDIF.
** Via LOOP
*WRITE: / ‘Via LOOP’.
*LOOP AT IT_MARAV ASSIGNING <FS_MARAV>.
* WRITE: / <FS_MARAV>-MATNR, ‘ – ‘, <FS_MARAV>-MAKTX.
*ENDLOOP.
*WRITE: / ‘******************************************Access Internal Table records using Field Symbols – end’.
*******************************************Access Internal Table records using Field Symbols – end
*
*******************************************Modify an entry using Field Symbol – begin
*WRITE: / ‘******************************************Modify an entry using Field Symbols – begin’.
** READ and MODIFY
*WRITE: / ‘READ and MODIFY’.
*READ TABLE IT_MARAV ASSIGNING <FS_MARAV> WITH KEY MATNR = ‘000000002’.
*IF SY-SUBRC = 0.
* <FS_MARAV>-MAKTX = ‘Test 2 – updated’.
*ELSE.
*ENDIF.
*LOOP AT IT_MARAV ASSIGNING <FS_MARAV>.
* WRITE: / <FS_MARAV>-MATNR, ‘ – ‘, <FS_MARAV>-MAKTX.
*ENDLOOP.
** LOOP and MODIFY
*WRITE: / ‘LOOP and MODIFY’.
*LOOP AT IT_MARAV ASSIGNING <FS_MARAV>.
* <FS_MARAV>-ERSDA = SY-DATUM + SY-TABIX.
* WRITE: / <FS_MARAV>-MATNR, ‘ – ‘, <FS_MARAV>-MAKTX, ‘ – ‘, <FS_MARAV>-ERSDA.
*ENDLOOP.
*WRITE: / ‘******************************************Modify an entry using Field Symbols – end’.
*******************************************Modify an entry using Field Symbol – end
*
*******************************************Check Field Symbols using IS ASSIGNED – begin
*WRITE: / ‘******************************************Check Field Symbols using IS ASSIGNED – begin’.
*IF <FS_MARAV> IS ASSIGNED.
* WRITE: / ‘Assigned’.
*ELSE.
* WRITE: / ‘Unassigned’.
*ENDIF.
*WRITE: / ‘******************************************Check Field Symbols using IS ASSIGNED – end’.
*******************************************Check Field Symbols using IS ASSIGNED – end
*
*******************************************Remove the Reference of Field Symbols – begin
*WRITE: / ‘******************************************Remove the Reference of Field Symbols – begin’.
*UNASSIGN <FS_MARAV>.
*IF <FS_MARAV> IS ASSIGNED.
* WRITE: / ‘Assigned’.
*ELSE.
* WRITE: / ‘Unassigned’.
*ENDIF.
*WRITE: / ‘******************************************Remove the Reference of Field Symbols – end’.
*******************************************Remove the Reference of Field Symbols – end
*
*******************************************Copy Internal Tables using Fields Symbols – begin
*WRITE: / ‘******************************************Copy Internal Tables using Fields Symbols – begin’.
*DATA IT_MARAV1 TYPE STANDARD TABLE OF MARAV.
*DATA IT_MARAV2 TYPE STANDARD TABLE OF MARAV.
*FIELD-SYMBOLS <FS_ANY_TAB_1> TYPE ANY TABLE.
*FIELD-SYMBOLS <FS_ANY_TAB_2> TYPE ANY TABLE.
*FIELD-SYMBOLS <FS> TYPE ANY.
*FIELD-SYMBOLS <F> TYPE ANY.
**
*ASSIGN IT_MARAV1 TO <FS_ANY_TAB_1>.
**
*SELECT
* *
*FROM MARAV
*INTO TABLE <FS_ANY_TAB_1>
*UP TO 10 ROWS.
**
*ASSIGN IT_MARAV2 TO <FS_ANY_TAB_2>.
**
*<FS_ANY_TAB_2> = <FS_ANY_TAB_1>.
**
**WRITE: / ‘records of IT_MARAV1’.
**LOOP AT IT_MARAV1 ASSIGNING <FS>.
** ASSIGN COMPONENT ‘MATNR’ OF STRUCTURE <FS> TO <F>.
** WRITE: / <F>.
**ENDLOOP.
***
**WRITE: / ‘records of IT_MARAV2’.
**LOOP AT IT_MARAV2 ASSIGNING <FS>.
** ASSIGN COMPONENT ‘MATNR’ OF STRUCTURE <FS> TO <F>.
** WRITE: / <F>.
**ENDLOOP.
*WRITE: / ‘records of IT_MARAV1’.
*LOOP AT <FS_ANY_TAB_1> ASSIGNING <FS>.
* ASSIGN COMPONENT ‘MATNR’ OF STRUCTURE <FS> TO <F>.
* WRITE: / <F>.
*ENDLOOP.
**
*WRITE: / ‘records of IT_MARAV2’.
*LOOP AT <FS_ANY_TAB_2> ASSIGNING <FS>.
* ASSIGN COMPONENT ‘MATNR’ OF STRUCTURE <FS> TO <F>.
* WRITE: / <F>.
*ENDLOOP.
*WRITE: / ‘******************************************Copy Internal Tables using Fields Symbols – end’.
*******************************************Copy Internal Tables using Fields Symbols – end
********************************************Assign data using Field Symbols – begin
*WRITE: / ‘*******************************************Assign data using Field Symbols – begin’.
*DATA IT_MARAV1 TYPE STANDARD TABLE OF MARAV.
*DATA IT_MARAV2 TYPE STANDARD TABLE OF MARAV.
*FIELD-SYMBOLS <FS_1> LIKE LINE OF IT_MARAV1.
*FIELD-SYMBOLS <FS_2> LIKE LINE OF IT_MARAV2.
*SELECT
* *
*FROM MARAV
*INTO TABLE IT_MARAV1
*UP TO 10 ROWS.
**
*LOOP AT IT_MARAV1 ASSIGNING <FS_1>.
* APPEND INITIAL LINE TO IT_MARAV2 ASSIGNING <FS_2>.
* <FS_2> = <FS_1>.
*ENDLOOP.
*WRITE: / ‘records of IT_MARAV1’.
*LOOP AT IT_MARAV1 ASSIGNING <FS_1>.
* WRITE: / <FS_1>-MATNR.
*ENDLOOP.
*WRITE: / ‘records of IT_MARAV2’.
*LOOP AT IT_MARAV2 ASSIGNING <FS_2>.
* WRITE: / <FS_2>-MATNR.
*ENDLOOP.
*WRITE: / ‘*******************************************Assign data using Field Symbols – end’.
********************************************Assign data using Field Symbols – end
********************************************Field Symbols to access Components by Name – begin
*WRITE: / ‘*******************************************Field Symbols to access Components by Name – begin’.
*DATA IT_MARAV1 TYPE STANDARD TABLE OF MARAV.
*FIELD-SYMBOLS <FS_1> LIKE LINE OF IT_MARAV1.
*FIELD-SYMBOLS <FS> TYPE ANY.
*SELECT
* *
*FROM MARAV
*INTO TABLE IT_MARAV1
*UP TO 10 ROWS.
**
*LOOP AT IT_MARAV1 ASSIGNING <FS_1>.
* WRITE: / ‘///////////////////////////////’.
* ASSIGN COMPONENT ‘MATNR’ OF STRUCTURE <FS_1> TO <FS>.
* WRITE: / <FS>.
* WRITE: / ‘///////////////////////////////’.
* ASSIGN COMPONENT ‘MAKTX’ OF STRUCTURE <FS_1> TO <FS>.
* WRITE: / <FS>.
*ENDLOOP.
*WRITE: / ‘*******************************************Field Symbols to access Components by Name – end’.
********************************************Field Symbols to access Components by Name – end
*******************************************Field Symbols to access Components by Number – begin
WRITE: / ‘*******************************************Field Symbols to access Components by Number – begin’.
DATA IT_MARAV1 TYPE STANDARD TABLE OF MARAV.
FIELD-SYMBOLS <FS_1> LIKE LINE OF IT_MARAV1.
FIELD-SYMBOLS <FS> TYPE ANY.
SELECT
*
FROM MARAV
INTO TABLE IT_MARAV1
UP TO 10 ROWS.
*
LOOP AT IT_MARAV1 ASSIGNING <FS_1>.
WRITE: / ‘///////////////////////////////’.
ASSIGN COMPONENT 2 OF STRUCTURE <FS_1> TO <FS>.
WRITE: / <FS>.
WRITE: / ‘///////////////////////////////’.
ASSIGN COMPONENT 4 OF STRUCTURE <FS_1> TO <FS>.
WRITE: / <FS>.
ENDLOOP.
WRITE: / ‘*******************************************Field Symbols to access Components by Number – end’.
*******************************************Field Symbols to access Components by Number – end