Why is inline-declared itab not initialized in AT SELECTION SCREEN OUTPUT?

Viewed 167

I have the following piece of code.

REPORT YYY.

TYPES: BEGIN OF t_test,
    test TYPE c LENGTH 4,
  END OF t_test,
  tth_test TYPE HASHED TABLE OF t_test WITH UNIQUE KEY test.

DATA(g_tab_test) = VALUE tth_test( ( test = 'AAAA' ) ( test = 'BBBB' )
  ( test = 'CCCC' ) ( test = 'DDDD' ) ).

PARAMETERS:
  p_x1 TYPE abap_bool,
  p_x2 TYPE abap_bool,
  p_x3 TYPE abap_bool.

CLASS lcl_main DEFINITION FINAL CREATE PRIVATE.
  PUBLIC SECTION.
    CLASS-METHODS:
      main.
ENDCLASS.

CLASS lcl_main IMPLEMENTATION.
  METHOD main.
  ENDMETHOD.
ENDCLASS.

AT SELECTION-SCREEN OUTPUT.
  LOOP AT screen.
    MODIFY SCREEN.
  ENDLOOP.
  BREAK-POINT. "<-- why is the table g_tab_test not initialsed here yet?

AT SELECTION-SCREEN ON p_x1.
  ASSERT 1 = 1.

Despite its definition, the table at the point of break in AT SELECTION-SCREEN OUTPUT is empty. Why is it so and is it a documented behaviour?

1 Answers

I believe it is a documented behaviour.

https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abapstart-of-selection.htm

In an executable program, the following statements are assigned to an implicit START-OF-SELECTION event block, which is inserted by an explicit START-OF-SELECTION event block if one exists:

All statements that are not declaration and are listed before the first explicit processing block.

All functional statements in the program if it does not contain any explicit processing blocks,

The code is "in the air", not explicitly under an exact event, this means the initialization of the internal table will run only with the implicit START-OF-SELECTION.

The code piece needs to be under INITIALIZATION (or LOAD-OF-PROGRAM depending on the exact need)

Related