Using INITIALIZATION event to set default Values

Set default values on selection-screen using INITIALIZATION event in SAP ABAP programming

+ -
Most of the times in real-time business requirements we need to set default values on selection-screen elements like input fields, check boxes, select-options, radio buttons etc. We use the initialization event to set default values on selection screen.
REPORT ZSAPN_INITIALIZATION.
TABLES : MARA. "tables decleration for select-options
PARAMETERS : P_INPUT TYPE CHAR20. "Input fied with 20 character length.

SELECT-OPTIONS: S_SO FOR MARA-MATNR. "select-options

PARAMETERS P_CHK AS CHECKBOX. "check box

PARAMETERS P_RAD1 RADIOBUTTON GROUP RB1.
PARAMETERS P_RAD2 RADIOBUTTON GROUP RB1.
By using the above code we can display the below screen.

Using INITIALIZATION in SAP ABAP

But we need to set default values to the input field, select-options(High, low), check box(default select), select radio button default.

Set Default values for parameters using INITIALIZATION

The below example explains you how to set default values using INITIALIZATION event to set default values on selection screen.
INITIALIZATION. "This event will trigger first
P_INPUT = 'SAPNuts'.

Set default values for Select-Options using  initialization event

Technically select-options are nothing but internal tables with four fields, the four fields are SIGN(Stores I - Inclusive of Defined Values/Range and E - Exclusive of Defined Values/Range, OPTION(Stores EQ - Equal, NE- Not Equal, LT - Lower Than, LE - Lower Equal, GT - Greater Than, GE - Greater Equal, BT - Between, CP - Covers Pattern and NP - Does Not Cover Pattern,LOW(Stores low value), HIGH(Stores high value), the below code is used to set default values for select-options.
INITIALIZATION.
  S_SO-LOW = '1'.
  S_SO-OPTION = 'BT'.
  S_SO-SIGN = 'I'.
  S_SO-HIGH = '100'.
  APPEND S_SO. " append select-options to screen

Set Default values for check box and radio buttons group

Check box and radio buttons store either X or space, X means selected, space means not selected, use the below code to default check box and radio buttons.
INITIALIZATION.
  P_CHK = 'X'.
  P_RAD2 = 'X'.

The final code will be

REPORT ZSAPN_INITIALIZATION.
TABLES : MARA. "tables decleration for select-options
PARAMETERS : P_INPUT TYPE CHAR20. "Input fied with 20 character length.

SELECT-OPTIONS: S_SO FOR MARA-MATNR. "select-options

PARAMETERS P_CHK AS CHECKBOX. "check box

PARAMETERS P_RAD1 RADIOBUTTON GROUP RB1.
PARAMETERS P_RAD2 RADIOBUTTON GROUP RB1.

INITIALIZATION.

  P_INPUT = 'SAPNuts'.
  S_SO-LOW = '1'.
  S_SO-OPTION = 'BT'.
  S_SO-SIGN = 'I'.
  S_SO-HIGH = '100'.
  APPEND S_SO.
  P_CHK = 'X'.

Using INITIALIZATION in SAP ABAP

Learner Questions


No Questions by learners, be first one to ask ..!!

    Please Sign in to ask a question

    Was this lesson helpful to you? Yes No 47 People out of 51 think this lesson helpful


    Lesson Navigation

    ←Previous Chapter
    Next Lesson → Interactive Reporting in SAP ABAP