Author: Rudramani Pandey

  • Parallel Cursor in ABAP

    Preface – This post is part of the ABAP Beginner series.

    Parallel Cursor in ABAP is a way to modify the conventional nested loop in such a way that the overall performance of the ABAP program gets improved.

    Introduction

    Suppose we have two tables, one table has Employee basic details and another table has Employee monthly salary details. And the requirement is to print Employee Basic details with all his salaries. What a programmer will do, he will write two Loops. The first loop will get the employee basic details one by one and the other loop will get employee salary details. You can check this thing in below ABAP code:

    LOOP AT zemployee_basic INTO wa_employee_basic.
    LOOP AT zemployee_salary INTO wa_employee_salary where employee_id = wa_employee_basic-employee_id.
    Write: wa_employee_basic-employee_id, wa_employee_salary-month, wa_employee_salary-amount.
    ENDLOOP.
    ENDLOOP.

    The above code will work fine and will print Employee ID, Month of the Salary and Amount of the salary of each and every employee.

    Parallel Cursor: Loop in Loop Image Illustration
    Parallel Cursor: Loop in Loop Image Illustration

    What if you want to find Salary Amount of one person for a particular month? You will again write the same loops to find the required details.

    Also, for every new Employee ID, the second Loop still goes through the whole data.

    What we conclude with this process is that, this process is neither good for printing data nor good for search operation as it wastes ample amount of time.

    Parallel Cursor Concept

    To curb this problem, a concept called Parallel Cursor was introduced by SAP ABAP.

    According to Parallel cursor concept, we need to follow following steps:

    Step 01: Sort both the tables

    Step 02: Write the first loop, like the previous way itself.

    Step 03: Read the second table with the key that was required to search the data. This would give the first value regarding the key and also its position in the table [SY-TABIX].

    Step 04: If the above step executed successfully, it means data is there in the second table associated with the key. Hence the SY-SUBRC will be set to zero. In this step we will check the value of SY-SUBRC. If it is zero, than we will proceed.

    Step 05: Assign the SY-TABIX value into a local variable. We do this step to preserve the SY-TABIX value as it changes with the loop.’

    Step 06: Now it’s the time to write the second loop. This time we don’t write the WHERE condition. This time we will write FROM condition with the local variable we initialized above.

    Step 07: In this step we check if the key of first table is equal to the key of second table or not. If not, then exit the loop. This stops the loop from reading non required data.

    Step 08: In this step we write our actual logic or print statements. And then close both the loops.

    Parallel Cursor Example

    Let us implement parallel cursor algorithm in the last example we discussed.

    SORT: zemployee_basic, zemployee_salary. [Step 01]

    LOOP AT zemployee_basic INTO wa_employee_basic. [Step 02]

    READ TABLE zemployee_salary INTO wa_temp WITH KEY employee_id = wa_employee_basic-employee_id BINARY SEARCH. [Step 03]

    IF SY-SUBRC = 0. [Step 04]

    lv_index = SY-TABIX. (you need to declare this variable earlier only) [Step 05]

    LOOP AT zemployee_salary INTO wa_employee_salary FROM lv_index . [Step 06]

    IF wa_employee_basic-employee_id <> wa_employee_salary-employee_id. [Step 07]

    EXIT.

    ENDIF.

    Write: wa_employee_basic-employee_id, wa_employee_salary-month, wa_employee_salary-amount. [Step 08]

    ENDLOOP.

    ENDLOOP.

    From above steps and example, it is clear that Parallel cursor is better than conventional nested loops. Actually nested loops take O(n1*n2) time to execute both the loops while parallel cursor takes O(n1+n2) time to execute the same.

  • SAP Message

    Preface – This post is part of the ABAP Beginner series.

    While using mobile phone and websites, you might have seen several messages popping up like security message in Mobile phones regarding photo access or antivirus message in PC regarding virus detection. All these messages can be a success, information or error message. In similar way we can showcase SAP message in ABAP programs too.

    Definition

    A Message in ABAP is used to display a text message either stored in table T100 or any text [can be in a message class] where type of the message can be a status, warning, error and etc. A message in ABAP can also be used to raise an exception.

    SAP Message Class

    Message class is a class which holds a list of messages with message id. It is created using transaction code SE91. This helps to maintain all messages related to a project/program all together.

    Syntax

    MESSAGE { msg | text

    | tn

    | tn(id)

    | { ID mid TYPE mtype NUMBER num }

    | {oref TYPE mtype}

    | {text TYPE mtype} }

    { { [DISPLAY LIKE dtype] [RAISING exception] }

    | [INTO text] }

    [WITH dobj1 … dobj4].

    Syntax Explanation

    The above syntax is explained below:

    Syntax Explanation Example
    msg | text
    or, {text TYPE mtype}
    Here msg is taken from class T100 while text is a string. MESSAGE ‘Success Message’ TYPE ‘I’.
    tn It needs a message class. Here t is a single character and n is three digit number; both are written together. These particular tn will represent a text that is stored in message class. Here message class name is written at the starting of report. REPORT ztest MESSAGE-ID zmessageclass.

    MESSAGE s001.

     

    –>  Here s001 is a message having its text stored in zmessageclass.

    tn(id) Like above t and n means same. Here id is the message class name and it is written just after the message REPORT ztest.

    MESSAGE s001 (zmessageclass).

    { ID mid TYPE mtype NUMBER num } Here mid means message class, mtype means type of message (explained later) and num is a message number (a number of length three) DATA: m_id   TYPE sy-msgid VALUE ‘ zmessageclass ‘,

    m_type TYPE sy-msgty VALUE ‘I’, m_num   TYPE sy-msgno VALUE ‘001’.

     

    MESSAGE ID m_id TYPE m_type NUMBER m_num.

    {oref TYPE mtype} Here oref is object reference variable which points to an object whose class implements the system interface IF_T100_MESSAGE. These are mainly used when we deal with local classes inside a report. Check out the example at given link.
    [DISPLAY LIKE dtype] When Display like is used, then instead of type of message the icon will be as per Display Like MESSAGE ‘Success Message’ TYPE ‘I’ DISPLAY LIKE ‘E’.

    *** Note: Above message is informative message but will be displayed as error message.

    [RAISING exception] It raises a non class based exception and only sends a message if the exception was not handled. It can be handled via sy-subrc. CLASS-METHODS msg1 EXCEPTIONS excp1.

    METHOD msg1.

    MESSAGE ‘Exception msg in a Method’ TYPE ‘I’ RAISING excp1.

    ENDMETHOD.

    [INTO text] This type of message does not impact on program flow and it does not matter what is the type of message. It just assigns the value of Message into a user defined field [here text]. MESSAGE i001 INTO DATA(newText).

     

    ***Note: Here newText is created dynamically and holds the value of i001 in it. This value can be used later in the same program.

    [WITH dobj1 … dobj4] This is used to add static text in place of ‘&’.

    Suppose, we are bring text from table T100 and the text is “I am a &&”.

    Then we can put our values in place of & & according to the situation.

    MESSAGE i001 WITH ‘Good’ ‘Player’.

    –>  The above will return “I am a good player”.

    ***Note: We can even give index to ‘&’ in the table. Suppose the text was “I am a 2& 1&”.

    Then the above Message will give output : “I am a player good”.

     

    Types of SAP Message

    Value Type Explanation
    A Termination It is displayed in a dialog box and the program is terminated.
    E Error It displays an error message in status bar and all the input fields are cleared.
    I Information It is displayed in a dialog box.
    S Status It is displayed in status bar of next screen.
    W Warning It displays a warning message in status bar and all the input fields are cleared.
    X Exit Exit messages cancels the running program and returns a dump.

     

    Information Message in SAP
    Information Message in SAP – Image Illustration
    Error Message in SAP
    Error Message in SAP – Image Illustration
    Status Message in SAP
    Status Message in SAP – Image Illustration
  • Open SQL Statements in SAP ABAP

    Preface – This post is part of the ABAP Beginner series.

    When we talk about Open SQL in ABAP, then it means only Data Manipulation Language (DML) part of SQL. It means we can only manipulate the table created in ABAP Dictionary using open SQL and not create a new table using SQL. The SQL statements of ABAP Reports directly communicate with a database as shown below:

    Open SQL in SAP
    Open SQL in SAP – Image Illustration

    Open SQL Keywords in ABAP

    SAP ABAP provides many SQL keywords that can be used as DML. These are as follow:

    Keyword Function
    SELECT It is used to fetch/ read data from database table.
    INSERT It is used to insert data into a database table.
    UPDATE Changes content of a row of database table based upon condition.
    MODIFY Same as above, Changes content of a row of database table based upon condition. But if the data is not present as per condition, then it creates/ inserts a new data in the database table.
    DELETE It deletes a row or all data based upon condition.
    OPEN CURSOR,

    FETCH,

    CLOSE CURSOR

    To read lines of database tables using cursor. In these statements we don’t fetch data from table into something but assign it to the cursor.

     

    Examples

    *** We will update it soon

  • Control Break statements in SAP ABAP

    Preface – This post is part of the ABAP Beginner series.

    Control Break statements in SAP ABAP are the are statements enclosed between  AT and ENDAT. These statements help us to control a loop according to our requirement. In this article we will discuss about the four control break statements provided by SAP ABAP.

    Introduction

    In ABAP, there are times where we need to perform some group level processing operations only upon certain set of data. For that purpose, we can take all data from a table to an internal table and push that data into a loop [LOOP … END LOOP]. In that loop we will need something called control break statements which are enclosed between statements AT and ENDAT.

    To utilize these control break statements in ABAP, we will also need some mathematical statements such as SUM, which can be used to total the numeric components of a table.

    ***Note: If inside a Loop you are using INTO wa, then it cannot be modified as it is overwritten with the old one when the AT-ENDAT control structure is entered. In this case use another work area to save your changes.

    Types of Control Break statements in SAP ABAP

    Statement Description
    AT FIRST …. ENDAT ·         This is triggered for the first row of internal table or the first iteration of loop (both are same).

    ·         As soon it is hit (AT FIRST), the value of work area are filled by ‘*’. And as soon as it hit –ENDAT, the work area is restored.

    AT NEW <field_name>   …. ENDAT ·         This is triggered for First row of a group with the same content of internal table based on a field (here <field_name>).
    AT END OF <field_name>   …. ENDAT ·         This is triggered for Last row of a group with the same content of internal table based on a field (here <field_name>).
    AT LAST …. ENDAT ·         This is triggered for the last row of internal table or the last iteration of loop (both are same).

    Image Illustration

    Control Break statements in SAP ABAP: At First
    Control Break statements in SAP ABAP: At First
    Control Break statements in SAP ABAP: At New
    At New
    Control Break statements in SAP ABAP: At End
    At End
    Control Break statements in SAP ABAP: At Last
    At Last

    Example

    *** We will update it soon

  • ABAP Work Area

    Preface – This post is part of the ABAP Beginner series.

    In ABAP reports, very often we will be having a situation where we need to store single record of a table or take input from user and append that record to table, both at runtime. In this situation we will need a structure which has all the fields of that particular table with the same namespace. Every time the content of the table changes, we will have to update our structure. So, instead of using structure we can use something called work area that is the replica of single row of that table with same fields.

    Definition

    A work area in ABAP represents single row of an internal table and it is used to process internal table line by line. It holds only single data at runtime.

    ABAP Work Area
    ABAP Work Area- Image Illustration

    Syntax

    A workarea can be defined in a report in two ways.

    Case 1: Predefining the type of work area and allocating memory to it.

    DATA: <YOUR_WORK_AREA_NAME> TYPE <Structure, Table, Line Type, View>.

    Case 2: Using Open SQL to allocate memory and type to work area at runtime.

    SELECT SINGLE * FROM <YOUR_TABLE_NAME> INTO DATA (<YOUR_WORK_AREA_NAME>).

    *** Exclude the parenthesis <> from above while using them in your programs.

    Examples

    Case 1:

    DATA: wa_emp TYPE zemployee.
    SELECT SINGLE * FROM zemployee INTO wa_emp.

    Note: If your work area does not match the structure of the table from which data is being pulled, you can write following:

    SELECT SINGLE * FROM zemployee INTO CORRESPONDING FIELDS OF wa_emp.

    Case 2:

    SELECT SINGLE * FROM zemployee INTO DATA (wa_emp).
  • ABAP Internal Table

    Preface – This post is part of the ABAP Beginner series.

    Very often, there is a situation in ABAP where we need to store multiple data of a definite structure at runtime and perform some operations upon them. For runtime operations we cannot hit database every time. In that situation, we fetch required data from database table, store it in something called ABAP Internal Table and perform operations upon them.

    Definition

    An Internal table in ABAP is a runtime copy of a table or structure. It is a reusable object. Each line of an internal table has same structure. In SAP, Internal table is an alternative to Arrays.

    ABAP Internal Table
    ABAP Internal Table – Illustration Image

    Syntax

    DATA:  <YOUR_INTERNAL_TABLE_NAME> TYPE TABLE OF <Structure, Table, Data type, Table Type>.

    Note: An Internal table can also be defined at runtime. It is explained in one of the example below.

    Examples

    Case 1:

    DATA:  itab_emp TYPE TABLE OF   zemployee. // Declaration of Internal table
    SELECT * FROM zemployee INTO TABLE itab_emp. // feeding data in internal table

    Case 2:

    SELECT * FROM zemployee INTO TABLE @DATA (itab_emp). // Declaration of Internal table at runtime and feeding data there itself

    Types of ABAP Internal Tables

    According to the frequency of use, internal tables are of following types:

    Type Description Example
    Standard tables A standard Internal table is the one which is accessed by its index. In this table we APPEND data one by one and later access data (Read, Modify and Delete) using INDEX statement. DATA:  itab_emp TYPE TABLE OF   zemployee.
    Sorted tables A sorted internal table is just like a standard internal table except data is inserted not appended. It is sorted as we fill it. We fill sorted table using INSERT statement. DATA:  itab_emp TYPE SORTED TABLE OF zemployee WITH UNIQUE KEY empid.
    Hashed tables A hashed internal table is the one in which data is filled using UNIQUE KEY. To access data we need this key. DATA:  itab_emp TYPE HASHED TABLE OF zemployee

    WITH UNIQUE KEY empid empname.

    Operations on ABAP Internal Tables

    Operations on Entire Internal Tables

    Assigning Internal Tables MOVE itab1 TO itab2.

    OR

    itab2 = itab1.

    Initialize Internal Tables CLEAR itab => To clear the header of the table

    CLEAR itab [] => To initialize the table but the initial memory remains reserved.

    REFRESH itab => Clears data of table but the initial memory remains reserved. It is same as CLEAR itab [].

    FREE itab =>It clears data as well as the initial memory allocated to the table.

    Compare Internal Tables Suppose we have two Internal tables ITAB1 and ITAB2 with same data type but different number of data, let us say 2 and 3 Lines of data respectively. The statement returns Boolean result.

    ITAB1 GT ITAB2 (Greater than) => False

     

    ITAB1 EQ ITAB2 (Equal to) => False

     

    ITAB1 LE ITAB2 ( Less than or equal to) => True

     

    ITAB1 NE ITAB2 (Not Equal to) => True

     

    ITAB1 LT ITAB2 (Less than) => True

    Sort Internal Tables SORT itab [ASCENDING|DESCENDING] [AS text] [STABLE]. The default is ascending order.
    Internal Tables as Interface Parameters We can use Internal table as a parameter in Forms and Interfaces. In forms Internal Table is written in addition to USING and CHANGING.
    Determining the Attributes of Internal Tables DESCRIBE TABLE itab [LINES lv_lin] [OCCURS lv_n] [KIND lv_knd].

    If you use LINES, it gives number of rows in Internal table.

    If you use OCCURS, it gives initial size of Internal table.

    If you use KIND, it gives type of Internal table.

     

     

    Operations on Individual Lines

     
    Access Methods for Individual Table Entries 1. Using Work Area

    READ TABLE <itable> [INTO <wa>] INDEX <idx>.

    2. Field Symbol

    READ TABLE <itable> ASSINGING FIELD SYMBOL(<fs_tab>)

    Filling Internal Tables Line by Line APPEND [<wa> TO / INITIAL LINE TO] <itab>.
    Reading Table Lines READ TABLE itab FROM wa result.

     

    or using a key

     

    READ TABLE itab WITH TABLE KEY k1 = f1 … kn = fn result.

     

    Both the above statements set sy-subrc value to 0 & 4 for success and failure search cases respectively.

    Processing Table Lines in Loops LOOP AT itab result condition.

    statement block

    ENDLOOP.

    The result part can be work area or field symbol.

    Changing Table Lines MODIFY TABLE itab FROM wa [TRANSPORTING f1 f2 …] [WHERE condition].

    The given statement modifies single record based on condition.

    In Transporting we can give specific column/field we want to modify.

    Deleting Table Lines DELETE TABLE itab FROM wa.

     

    or using a key

     

    DELETE TABLE itab WITH TABLE KEY k1 = f1 … kn = fn.

    Searching Through Internal Tables Line by Line 1.  FIND IN TABLE

    FIND [{FIRST OCCURRENCE}|{ALL OCCURRENCES} OF] pattern IN TABLE itab [IN {BYTE|CHARACTER} MODE]

    ·         [{FIRST OCCURRENCE}|{ALL OCCURRENCES} tells if search is only for first findings or for all

    ·         “pattern” is the string being searched for

    ·         [IN {BYTE|CHARACTER} MODE] tells if the search will be character wise or byte wise

     

    2.  REPLACE IN TABLE

    REPLACE [{FIRST OCCURRENCE}|{ALL OCCURRENCES} OF] pattern   IN TABLE itab … WITH new [IN {BYTE|CHARACTER} MODE]

    ·         The way FIND works in same way, it also finds and replaces the pattern with new

    *** We will discuss all these operations in a separate post for better clarification.

    Open SQL in ABAP Internal Table

    The way we access and manipulate data in tables of SAP ABAP, in the same way we can use open SQL to manipulate data of internal tables

  • Local Structure in ABAP Report

    Preface – This post is part of the ABAP Beginner series.

    Suppose in an ABAP Report, we have multiple data for a person. This data is name, address, contact number and salary. Now, again we have same data for another person. Will you create those variables again for the second person or would you like to reuse the above variables. In this case, you will need a group of these variables under a single component. This component is known as structure  or local structure in ABAP report .
    ***Note: If you want to learn about ABAP SE11 (Data Dictionary) Structure, visit here.

    Definition

    A Local Structure in ABAP reports is a reusable component which acts as a collection of different variables of different data types under a single name. It holds only single data at runtime.

    Syntax

    A local structure in ABAP is defined within BEGIN OF…. END OF. And it starts either with TYPES or DATA.

    BEGIN OF <Your_Structure_name>,

    NAME TYPE c LENGTH 20,

    SALARY TYPE i,

    END OF <Your_Structure_name>.

    Local Structure in ABAP Report
    Local Structure in ABAP Report – Image Illustration

    NOTE: A local structure can also be created at runtime. We will show this in below example.

    Examples

    Case 1:

    DATA: BEGIN OF LS_EMPLOYEE,

    NAME TYPE c LENGTH 20,

    SALARY TYPE i,

    END OF LS_EMPLOYEE.

    In this case, we directly fetch one data into this structure.

    Select Single * from ZEMPLOYEE into corresponding fields of @LS_EMPLOYEE.

    Case 2:

    TYPES: BEGIN OF LS_EMPLOYEE,

    NAME TYPE c LENGTH 20,

    SALARY TYPE i,

    END OF LS_EMPLOYEE.

    Since it is a TYPE, hence it cannot hold data at runtime. Hence we will need to define a workarea first and then fetch data into that.

    DATA: WA_ EMPLOYEE   TYPE   LS_EMPLOYEE.

    Select Single * from ZEMPLOYEE into corresponding fields of WA_ EMPLOYEE.

    CASE 3:

    In latest update of ABAP, we can create a structure/workarea at runtime in given way:

    SELECT Single * from ZEMPLOYEE into corresponding fields of DATA(WA_ EMPLOYEE).

    In this way, we will not have to define a structure anymore and we can use this structure again in the program too.

    Types of Structures

    In real world development, we simply create a structure the way it is mentioned in above examples. But some time, as per scenario, we need to create structures in a different manner. SAP provides 4 types of structures:

    Structure Type Description Use Case
    Flat structures The structure which contains only elementary data types. A structure of employee basic data e.g. Name, age, salary, etc
    Flat character-like structures The structure which contains only character like elementary data types. Character like data types are text field (char), numeric text field (n), text string (string). A structure which will be used only to read and no calculation will be made. In this case all data can be string type.
    Nested structures A structure inside a structure is called a nested structure. A structure of school containing another structure of student details and teacher details.
    Deep structures A structure which has at least one deep component (string, internal table or reference variables). A structure which saves mail content. Mail content can have unknown length, in this case data type of that field will be string.

     

     

  • ABAP Report Events: Selection Screen Events

    Preface – This post is part of the ABAP Beginner series.

    In this article, we have discussed a type of ABAP Report Events i.e. Selection Screen Events. To learn all about ABAP Report Events click here.

    Introduction

    In ABAP Report Events after ABAP Reporting Events of ABAP, we have Selection Screen Events which occur in a predefined manner. These events are called in similar a way of Dynpro sequence (PBO and PAI). These events are processed during selection screen processing.

    In simple words, selection screen events are the events that are called after a selection screen block is opened and it is used to manipulate the selection screen block based on user interaction at runtime.

    Basic Dynpro Events

    Before we discuss Selection screen events, let us learn basic Dynpro events first:

    PBO: Process Before Output

    This event is triggered before a screen is sent to presentation layer (output screen).

    PAI: Process After Input

    This event is triggered by a user action on ABAP GUI.

    POH: Process On Help Request

    This event is triggered when F1 (Field Help) of an input field on the screen is requested.

    POV: Process On Value Request

    This event is triggered when F4 (Input Help) of an input field on the screen is requested.

    Types of Selection Screen Events

    Following are the types of Selection Screen Events:

    Event

    Description

    ·         AT SELECTION-SCREEN OUTPUT ·         It is raised by PBO event. Thus anything that needs to be changed dynamically on screen uses this event.

    ·         This event is also useful in case we need to initialize something every time the selection screen code of a program is called because INITIALIZATION is loaded only once but AT SELECTION-SCREEN OUTPUT is loaded every time.

    ·         MODIFY SCREEN can be used to manipulate screens during AT SELECTION-SCREEN OUTPUT event.

    ·         AT SELECTION-SCREEN ON { Parameter | Selection Criteria } ·         It is raised by PAI event. This event is triggered if content of Parameter or Selection Criteria is passed to ABAP program.

    ·         A selection criterion (selection table) is generated using SELECT-OPTIONS. And for each line of selection table, different calls are made to AT SELECTION-SCREEN ON {Parameter | Selection Criteria} is made.

    ·         If a warning or an error message is raised, the input parameters of this event blocks become ready for input again.

    AT SELECTION-SCREEN ON END OF selcrit ·         Unlike above event, call to this event is made with entire selection table.

    ·         It is mainly used to mark the end of Selection Screen event calls.

    AT SELECTION-SCREEN ON BLOCK block ·         It is raised by PAI event. This event is triggered when all the inputs of a block is passed to the ABAP program.

    ·         If a warning or an error message is raised, the input parameters of this event blocks become ready for input again.

    AT SELECTION-SCREEN ON RADIOBUTTON GROUP group ·         It is raised by PAI event. This event is triggered when all the inputs of a block is passed to the ABAP program.

    ·         If a warning or an error message is raised, the input parameters of this event blocks become ready for input again.

    AT SELECTION-SCREEN ·         This is the last event raised in selection screen processing

    ·         All input values are passed to this event; hence we can perform all types of validations here.

    ·         If a warning or an error message is raised, the input parameters of this event blocks become ready for input again.

    AT SELECTION-SCREEN ON HELP-REQUEST|VALUE-REQUEST FOR {para|selcrit-low|selcrit-high} } ·         This event is triggered on F1 or F4 Help request from screen.

    ·         It is raised by POH and POV event.

    AT SELECTION-SCREEN ON EXIT-COMMAND ·         This event is triggered if any of the following actions are called on the screen: Back, Exit, or Cancel.

    ·         Any cleanup activities can be taken care here.

     

    Examples

    AT SELECTION-SCREEN OUTPUT

    In given example, if in Parameter ‘EXIT’ is passed, then the whole screen is hidden.

    PARAMETERS: EXIT (10) TYPE c.

    AT SELECTION-SCREEN OUTPUT.

    LOOP AT SCREEN INTO DATA (wa_screen).

    IF wa_screen -name = ‘ EXIT ‘.

    wa-invisible = ‘1’.

    MODIFY screen FROM wa_screen.

    ENDIF.

    ENDLOOP.

    *** Note: We will update examples for other events very soon.

  • ABAP Report Events: Reporting Events

    Preface – This post is part of the ABAP Beginner series.

    In this article, we have discussed a type of ABAP Report Events i.e. Reporting Events. To learn all about ABAP Report Events click here.

    Introduction

    In ABAP Report Events after Program Constructor Event of ABAP, we have ABAP Reporting Events which occur in a predefined manner. These events are called in a predefined sequence (as mentioned later in this post). These events are only called in Executable reports.

    Types of Reporting Events

    Following are the types of Reporting Events:

    Event Description Status
    INITIALIZATION This event is called just after LOAD-OF-PROGRAM and used to fix default values and initialize fields
    START-OF-SELECTION This event is called after the Standard Screens are once processed and is used to write all the functional statements
    GET node These are used in reports associated with only logical database and are used to read events of logical database Obsolete
    END-OF-SELECTION These are used in reports associated with only logical database and is raised when:

    • When logical database has completed its work

    • Just after START-OF-SELECTION

    Obsolete

     

    INITIALIZATION

    As discussed above, this event is called just after LOAD-OF-PROGRAM and before any selection screen events; and it is used to fix default values and initialize fields.

    Example

    PARAMETERS:  p_lan TYPE string.

    INITIALIZATION.

    p_lan = sy-langu.

    ***Note: In case a standard selection screen is there, multiple calls are made to the same program based upon user input and interaction. INITIALIZATION is ignored after the first call to the program and in this case to initialize the selection screen explicitly for each call we will have to use the event AT SELECTION-SCREEN OUTPUT.

    START-OF-SELECTION

    As discussed above, this event is called after the Standard Screens are once processed and it is used to write all the functional statements. By functional statements we mean the actual code/ business logic.

    Example

    REPORT ztest_report.

    DATA:  text TYPE string.

    START-OF-SELECTION.

    text = ‘Hello World!’.

    Write: text.

    *** Note: If I will not write START-OF-SELECTION in above program, still the program will construct a block of START-OF-SELECTION implicitly just before the actual code. Thus we can skip writing START-OF-SELECTION, but it is a good practise to use it as it

  • ABAP Report Events: List events

    Preface – This post is part of the ABAP Beginner series.

    In this article, we have discussed a type of ABAP Report Events i.e. List events. To learn all about ABAP Report Events click here.

    Introduction

    In ABAP Report List means ABAP table. Using List events we can manipulate or perform actions on a list. Interactive report uses list events to interact with a table output.

    Types of List events

    Following are the types of List events:

    Event

    Description

    TOP-OF-PAGE

    [DURING LINE-SELECTION]
    It is used to write constants in the header of a page. The header remains fixed against scrolling.

    If used without [DURING LINE-SELECTION], TOP-OF-PAGE is triggered as soon the list is created else it loads during particular line selection.

    END-OF-PAGE It is used to write constants in the header of a page. It appears at the end of a page and is generally used to print page number.

    It only works in case of LINE-COUNT is defined (will be explained via example).

    AT LINE-SELECTION It is triggered whenever a line of a list is double clicked. The main purpose of this event is in Interactive report where on click of a line item creates details lists.
    AT USER-COMMAND It is triggered whenever a custom button is clicked on UI.
    AT PF It is triggered whenever a function key is pressed on a keyboard.
    SET USER-COMMAND It can be used to auto trigger a button key by setting an fcode to the USER-COMMAND. These fcodes are predefined and you can find them here.

     

    Examples

    *** Note: We will update examples for all the events very soon.