Showing posts with label Field Symbol. Show all posts
Showing posts with label Field Symbol. Show all posts

Thursday, September 10, 2020

Differences between Work Area and Field Symbol in SAP ABAP.

What are the differences between Work Area and Field Symbol?


Differences between Work Area and Field Symbol in SAP ABAP.

Work Area

Field Symbol

-----------

1. It is the data variable.

1. It is a Pointer.

--------------

2. The ABAP statement is DATA is used to declare

or define work areas.

2. The ABAP statement FIELD-SYMBOLS is used to declare Field symbols.

------------------

3. The ABAP statement INTO is used to process record by record through work area .

3. The ABAP statement ASSIGNING is used to assign the FIELD-SYMBOLS .

------------------

4. The ABAP statement MODIFY must be used to

modify the internal table .

4.No need to use MODIFY , Since it is a pointer .

---------------------

5. No need to specify within the Angular brackets (< >).

5. It Must be specify within the Angular brackets (< >) .

Friday, December 28, 2018

Field Symbol - Dynamic Programming in ABAP.


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.
DATAlt_ 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.

  
DATAgd_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.
********--------------------------------------