Field Symbol - Dynamic
Programming in ABAP.
A. How to declare field symbol in sap abap.
DATA :new_val TYPE i VALUE 4.
FIELD-SYMBOLS:<lv_var> TYPE i.
ASSIGN new_val to <lv_var>.
WRITE: / <lv_var>.
<lv_var> = 8.
WRITE: / new_val.
***End how to declare field symbol
B. Field symbol as a replacement of Work area in sap abap:
DATA:IT_SPFLI TYPE STANDARD TABLE OF SPFLI.
FIELD-SYMBOLS:<FS_SPFLI> TYPE SPFLI.
START-OF-SELECTION.
SELECT *
FROM SPFLI
INTO TABLE IT_SPFLI
UP TO 10 ROWS.
END-OF-SELECTION.
****Loop declare
LOOP AT IT_SPFLI ASSIGNING <FS_SPFLI>.
<FS_SPFLI>-COUNTRYFR = 'COUNTRYFR'.
ENDLOOP.
****End field symbol as a replacement of Work area:
***************************************************
* 3 *
***************************************************
C. Appending to internal table in sap abap:
DATA:IT_SPFLI1 TYPE STANDARD TABLE OF SPFLI.
FIELD-SYMBOLS:<FS_SPFLI1> TYPE SPFLI.
APPEND INITIAL LINE TO IT_SPFLI1 ASSIGNING <FS_SPFLI1>.
IF <FS_SPFLI1> is ASSIGNED.
<Fs_spfLi1>-COUNTRYFR = 'TEST'.
<Fs_spfli1>-CITYFROM = 'TEST'.
UNASSIGN <FS_SPFLI1>.
ENDIF.
APPEND INITIAL LINE TO IT_SPFLI1 ASSIGNING <FS_SPFLI1>.
IF <FS_SPFLI1> is ASSIGNED.
<Fs_spfLi1>-COUNTRYFR = 'TEST1'.
<Fs_spfli1>-CITYFROM = 'TEST1'.
UNASSIGN <FS_SPFLI1>.
ENDIF.
*******************End appending to internal table:
**************************************************
* 5 *
***************************************************
D. Reading internal table using generic field symbol in sap abap:
FIELD-SYMBOLS: <fs_tab> TYPE SPFLI.
FIELD-SYMBOLS: <fs_str> TYPE SPFLI.
DATA: lt_ SPFLI TYPE STANDARD TABLE OF SPFLI.
ASSIGN lt_SPFLI TO <fs_tab>.
SELECT * FROM SPFLI INTO TABLE lt_SPFLI UP TO 10 ROWS.
READ TABLE <fs_tab> ASSIGNING <fs_str> WITH KEY ('CARRID') = 'TESTDATA'.
**************************************************
* 6 *
***************************************************
E. Simple Object In fields symbols
*REPORT ZSW_FIELD_SYMBOLS.
***Type declare
TYPES:BEGIN OF TY_SPFLI,
CARRID TYPE S_CARR_ID,
CONNID TYPE S_CONN_ID,
END OF TY_SPFLI.
**Internal Table Declare.
DATA:it_SPFLI_1 TYPE STANDARD TABLE OF TY_SPFLI.
DATA: gd_index TYPE string,
gd_rfp0 TYPE string.
**field Symbol Declare
FIELD-SYMBOLS :<fs_SPFLI_1> TYPE TY_SPFLI.
** Start selection screen
START-OF-SELECTION.
**** Select query for fetch data
SELECT CARRID
CONNID
FROM SPFLI
INTO TABLE it_SPFLI_1
UP TO 50 ROWS.
END-OF-SELECTION.
** End selection screen
*** Loop With field Symbol
LOOP AT it_SPFLI1 ASSIGNING <fs_SPFLI>.
IF <fs_SPFLI_1> is ASSIGNED.
WRITE: <fs_SPFLI_1>-CARRID,<fs_SPFLI_1>-CONNID.
ENDIF.
ENDLOOP.
********--------------------------------------
No comments:
Post a Comment