Category: SAP

  • ABAP Field Symbols

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

    ABAP Field Symbols

    In ABAP reports, very often you will be having a situation where you need to store single record of a table or take input from user and append that record to table, both at run-time. In this situation you 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, you will have to update your structure. So, instead of using structure you can use something called workarea and field symbols that are the replica of single row of that table with same fields.

    Introduction

    In programming language C/C++, there is a concept of pointers. Let us understand pointers first, before understanding Field Symbols.

    Pointers in C/C++:

    A pointer is also a variable that hold an address which is the location of another variable in memory. Since a pointer is also a variable, therefore its value is also stored in the memory in another location. In given image, we have assigned the address of a variable “A” to a pointer variable “P”. The link between the variables “P” and the variable “A” can be visualized as shown in the figure.

    ABAP Field Symbols
    ABAP Field Symbols – Pointer Illustration

    The address of A is 07xff0a767cc4. We can see that the value of variable “P” is the address of the variable “A”. Thus, we may access the value of “A” by using the value of “P” [how to access is explained later]. Therefore, we say that the variable “P” points to the variable “A”, hence “P” got the name ‘pointer’.

    Referencing and Dereferencing Pointer:

    Referencing Pointer: As the name suggest, Referencing is used for reference. A referencing pointer is the one that uses & operator (ampersand character) to set a pointer variable i.e. Address assignment of a variable to a pointer.

    int a;
    int* p1;
    a = 11;
    p1 = &a; //p1 references c1

    Dereferencing Pointer: As the name suggests, Dereferencing is used to get values out of a reference. A dereferencing pointer is the one that uses * operator (asterisk character) to get the value stored at a pointer.

    int b;
    b = *p1; //value of b will be then 11. Since we have assigned address of a to p1 in above example

    Why to use a pointer:

    A pointer is used to reduce the length and complexity of a program and hence increase the execution speed.

    What is a Field Symbol?

    Just like a pointer discussed above, SAP also introduced something called Field-Symbols. It refers either a table, a field or even anything. When I say anything, I mean that the structure of field symbol will be determined dynamically. In simple words, a field symbol is just a pointer that is used to point a specific line of internal table.

    Definition

    A field symbol in ABAP is a dereferencing pointer that is mainly used to point specific lines of Internal table. It can be used to point either a table, a field or a dynamic structure. It is used as an alternative to work area to reduce the memory consumption and increase the performance of a program.

    Syntax

    FIELD-SYMBOLS <fs> { typing | obsolete_typing }.

    The ABAP keyword FIELD-SYMBOLS is used to declare a field symbol <fs>. Fs is the part of naming convention and the mandatory angle brackets distinguish them from the other data objects.

    Syntax for declaring a field symbol using different data types:

    FIELD-SYMBOLS: <fs_example1> TYPE field name.
    FIELD-SYMBOLS: < fs_example2> TYPE table.
    FIELD-SYMBOLS: < fs_example3> TYPE REF TO DATA. "here DATA is a reference type

    The keywords which are used to assign a value to the field symbol are ASSIGNING and ASSIGN.

    ASSIGN <itab> [ KEY primary_key (‘…’) = ‘…’] TO <fs_example>.

    It is done because, a pointer must have an address to refer, here we assign an address to the field symbol.

    It is very important to check if a field symbol is assigned or not else, we will get a run-time error.

    IF <FS_EXAMPLE> IS ASSIGNED.
    **Your code
    ENDIF.

    Dynamic Field Symbol or Field-Symbols Inline-Declaration

    With the introduction of inline declaration of field symbols, we don’t have to check whether it is assigned or not. Also, we don’t have to declare a field symbol directly.

    Syntax:

    …. FIELD-SYMBOL(<fs>) ….

    Example

    LOOP AT <itab> ASSIGNING FIELD-SYMBOL(<fs_line>). 
    *** Your Code 
    ENDLOOP.

     

  • Modularization Techniques in ABAP

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

    Modularization Techniques in ABAP is a way to write codes in different processing blocks like subroutine, Function Modules and ABAP objects. In this article, we will learn what is a Modularization, its types and advantages.

    Introduction

    The literal meaning of Modularization is “design or production of something in a separate section”. All the ABAP programs are modular in structure. This can be easily understood from ABAP Events. All these events are different blocks and are part of general execution of ABAP programs.

    Apart from this internal modularization, ABAP also provides external Modularization techniques. In this external modularization technique, ABAP codes are written in different processing blocks like subroutine, Function Modules and ABAP objects, and are called from ABAP report.

    These processing blocks that we call from ABAP programs are called procedures.

    Modularization Techniques in ABAP
    Modularization Techniques in ABAP – Image Illustration

    Definition:

    Modularization Techniques in ABAP is a way to incorporate reusability in ABAP programs. It improves the readability and maintainability of ABAP programs, prevents redundancies, incorporates reusability of functions, and the encapsulation of data.

    Type of Modularization in ABAP

    • Following are the processing blocks that can be called from ABAP programs:
      1.     Subroutines
      2.    Function modules
      3.    Methods (see ABAP Objects)

     

    • Following are the modularization technique ABAP allows you to modularize source code by placing ABAP statements:
      1.     Local Macros
      2.    Global Include Programs

    Advantages of Modularization in ABAP

    Modularization Technique in ABAP brings following advantages to ABAP programs:

    • Improves the readability and maintainability of ABAP programs
    • Prevents redundancies
    • Incorporates reusability of functions
    • Encapsulation of data
  • 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.