Friday, May 3, 2019

Field Symbol as a Variable


Field symbol is like a pointer which we use in C language. Field symbol doesn’t hold any memory. It only points to that memory location. We can assign a value to a field symbol. After assigning the value that field symbol only hold that value with a dynamic memory allocation. Normal variable always holds memory allocation. The variable can be empty with value or full with value but memory allocation is always there. Field symbol is dynamic memory allocation. It holds value when it is assigned.

In the following program we are assigning (Inline declaration) a field symbol. It means <v_maktx> doesn’t hold any memory allocation but it points the value of MAKTX from MAKT table. Using field symbol always increases the performance of program since we are working with dynamic memory.

PARAMETERSp_matnr TYPE matnr.

DATA dref TYPE REF TO data.
CREATE DATA dref TYPE makt-maktx.
ASSIGN dref->TO FIELD-SYMBOL(<v_maktx>).

SELECT SINGLE maktx FROM makt INTO <v_maktx>
  WHERE matnr p_matnr
    AND spras sy-langu.

IF sy-subrc 0.
  WRITE'Description-'<v_maktx>.
ENDIF.

No comments: