Preface – This post is part of the ABAP Beginner series.
Table of Contents
Program Constructor Event
A Program Constructor event in SAP ABAP is used to load global constant value or data of a program. It consist only one Event: LOAD-OF-PROGRAM
Load of Program is Just like a Class Constructor or Static Constructor of a Class.
Now if you don’t know class constructor, then simply understand this thing, A Load of Program loads default values for a session e.g. Language.
Now you may say, we can load default values using INITIALIZATION, yes you can but it will be executed for every run, while Load of Program is executed once for a session.
LOAD OF PROGRAM is useful only in case of a report called using SUBMIT or the one that run using a transaction code else it will perform same as INITIALIZATION.
Example of LOAD-OF-PROGRAM:
LOAD-OF-PROGRAM. DATA global_langu TYPE sy-langu. global_langu = COND #( WHEN sy-langu = 'D' THEN 'German' ELSE 'English' ).
The above program have two statements.
- The first statement is declaring a variable g_langu (A global variable for language) of type sy-langu (it fetches system language that is based on the system location).
- The second statement is checking a condition, if the system language is D (i.e. German) then assign g_langu as ‘German’ and assign ‘English’ for any other system language.
- It is the first even executed by SAP ABAP
- It is used to initialize global default values
- If in a program, LOAD-OF-PROGRAM is only used for initialization and there is no executable lines after that, then LOAD-OF-PROGRAM event is not raised
Flow of an Executable Program
The statement SUBMIT is used to load the program in a separate internal session and based upon the following sequence calls different events as mention below:
- AT SELECTION-SCREEN OUTPUT