Field symbols

It is equivalent to ABAP pointers and they point to actual address where the data is stored

FIELD-SYMBOLS: <line>     TYPE any,    "generic
               <struct>   TYPE kna1.   "non-generic

Assignment

SELECT * FROM mara INTO TABLE @DATA(lt_mara).
IF lt_mara IS NOT INITIAL.
READ TABLE lt_mara ASSIGNING FIELD-SYMBOL(<line>) INDEX 1.
IF sy-subrc is initial.
  write : | Material = <line>-matnr |
endif.
ENdif.

Field symbols allow you to:

   Assign an alias to a data object

    Adopt or change the type and size of a data object dynamically at runtime

    Set the offset and length for a string variably at runtime

    Set a pointer to a data object that you determine at runtime (dynamic ASSIGN)

    Access components of a structure

    The statement ASSIGN f to <fs> assigns the field f to field symbol <fs>. The field symbol <fs> then “points” to the contents of field f at runtime. This means that all changes to the contents of f are visible in <fs> and vice versa.

Create Data

Dynamic internal Table A Dynamic Internal Table is an internal table with variable number of rows and columns, which can be defined during run time only.

 A dynamic internal table is not declared in the program as static.

 Some of the benefits of Dynamic internal table are:

  • Flexiblilty
  • Extremely useful when the numbers of columns / fields are not known at the design time / compile time.
  • Avoids redundancy
*&---------------------------------------------------------------------*
*& Report YLINKED_LIST
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT YLINKED_LIST.


DATA int TYPE i.
TYPES: BEGIN OF node,
         value TYPE i,
         next  TYPE REF TO data,
       END OF node.
DATA root TYPE REF TO node.
DATA element TYPE REF TO node.
DATA cursor TYPE REF TO node.
SELECT-OPTIONS: input FOR int. "For adding node
PARAMETERS search TYPE i.  "For searching node

CLASS single_linked_list DEFINITION.
  PUBLIC SECTION.
    METHODS add_data IMPORTING val TYPE i.
    METHODS display_data.
    METHODS search_node IMPORTING val TYPE i.
ENDCLASS.

CLASS single_linked_list IMPLEMENTATION.
  METHOD add_data.
    IF ( root IS INITIAL ).
      CREATE DATA root.
      root->value = val.
      cursor = root.
    ELSE.
      CREATE DATA element.
      element->value = val.
      cursor->next = element.
      cursor ?= cursor->next.
    ENDIF.
  ENDMETHOD.
  METHOD search_node.
    DATA(tmp) = root.
    WHILE ( tmp IS NOT INITIAL ).
      IF tmp->value = val.
        WRITE:/ |Found|.
        RETURN.
      ELSE.
        tmp ?= tmp->next.
      ENDIF.
    ENDWHILE.
    WRITE:/ |Not found|.
  ENDMETHOD.
  METHOD display_data.
    DATA(tmp) = root.
    WHILE ( tmp IS NOT INITIAL ).
      WRITE:/ |{ tmp->value }|.
      tmp ?= tmp->next.
    ENDWHILE.
  ENDMETHOD.
ENDCLASS.

* For having only low value(s)
AT SELECTION-SCREEN.
  LOOP AT SCREEN.
    IF screen-name = 'INPUT-HIGH'.
      screen-input = 0.
      MODIFY SCREEN.
      EXIT.
    ENDIF.
  ENDLOOP.

START-OF-SELECTION.

  DATA(ll) = NEW single_linked_list( ).
  IF input IS NOT INITIAL.
    data(k2) = input-high - input-low.
*    LOOP AT input.
    DO k2 TIMES.
      ll->add_data( val = input-low + sy-index - 1 ).
      ENDDO.
*    ENDLOOP.
  ENDIF.
  ll->display_data( ).
  ll->search_node( search ).