Saturday, June 28, 2025

🏷 FIELD SYMBOLS

 

1. Introduction

  • Field Symbols are placeholders for the data objects (Variable, Work Area etc.).
  • Field Symbols do not reserve any physical memory space, but they point to the content of the data objects.
  • After declaring a field symbol, we can assign the data object to the field symbol.
  • After successful assignment, whenever we address a field symbol, ultimately we are addressing the data object that is assigned to that field symbol.

Syntax :

FIELD-SYMBOLS <FS>


In the above syntax, FIELD-SYMBOLS = keyword, where fs is the name of the field symbol.
The name of the field symbol is always enclosed between <>.

2. Types of Field Symbols

Field symbols are of two types:

  1. Typed Field Symbol
  2. Generic Field Symbol

 

1. FIELD-SYMBOLS : <FS_STR> TYPE ANY.

2. FIELD-SYMBOLS : <FT_TAB> TYPE ANY TABLE.

In the above syntax, the field symbol is of elementary data type integer (I).

  • When we provide the generic data types like ANY and ANY TABLE to the field symbol, then it is called a generic field symbol.
  • Generic field symbols are used for dynamic programming.
  • When we provide the data element like elementary, complex etc. to the field symbol then it is called a typed field symbol.

If we specify a type to the field symbol, the system checks the compatibility of the field symbol and the data object assigned to that field symbol.


3. Typed Field Symbol Implementation

Example –

FIELD-SYMBOLS : <fs> TYPE i.

DATA lv_name(30) TYPE c VALUE 'SRK'.

 

*& Defining field symbol

FIELD-SYMBOLS  <fs_name> TYPE c.

 

*& Assigning variable to field symbol

ASSIGN lv_name TO <fs_name>.

IF <fs_name> IS ASSIGNED.

  <fs_name> = 'Akshay Kumar'.

  WRITE / lv_name.

ENDIF.

Output:
Akshay Kumar


4. Field Symbol as a Replacement of Work Area

Requirement –
We will fetch out the records from the employee table and this time we will use field symbols to display those records on the output screen.

As soon as we change the value of a field symbol, by default the value of the data object will change.

  • We can replace work area by field symbol while performing internal table operations.
  • This is because work area stores a copy of the internal table row, whereas field symbol directly references the internal table row.

Hence, processing of internal table with field symbol is faster than with work area.

Example –

TYPES BEGIN OF ty_employee,

  emp_id TYPE ZSD_emp_id,

  emp_name TYPE ZSD_emp_name,

  department TYPE ZSD_department,

  manager TYPE ZSD_manager,

END OF ty_employee.

 

DATA lt_employee TYPE TABLE OF ty_employee,

     ls_employee TYPE ty_employee.

 

FIELD SYMBOLS <fs_employee> TYPE ty_employee.

 

DATA lv_Emp_id TYPE zsd_emp_id.

SELECT OPTIONS s_emp_id FOR lv_emp_id.

 

SELECT emp_id emp_name department manager

  FROM zsd_emp_tab

  INTO TABLE lt_employee

  WHERE emp_id IN s_emp_id.

 

LOOP AT lt_employee ASSIGNING <fs_employee>.

  IF <fs_employee> IS ASSIGNED.

    WRITE: / <fs_employee>-emp_id,

             <fs_employee>-emp_name.

  ENDIF.

ENDLOOP.

 

Output:

1001 John Paul

1002 Meera Jain

 

No comments:

Post a Comment