Category: ABAP

ABAP

  • Collective Search Help in SAP ABAP

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

    Introduction

    As discussed in the earlier article i.e. Search Help in SAP ABAP, a search Help in SAP ABAP are reusable objects that are used to assign input helps (F4 helps) to screen fields. If the data for the search help is bought from combination of many elementary search help, then it will be termed as Collective Search Help.

    Definition

    As the name suggest a collective search help is a collection of multiple elementary search helps. It can even be a combination of elementary search help and another collective search help.

    Below is the example of how it works (data exchange works):

    Collective Search Help in SAP ABAP
    It has an import and export parameter, the data is exchanged between the input screen template and the parameters of the assigned elementary search helps using this interface.

    Steps to Create a Collective Search

    1. Go to SE11
    2. Search help name -> Create -> Choose a type (here, collective)
    3. Maintenance screen of collective search help will open -> Give a short description to find your collective search help
    4. In the definition tab -> Enter a search help parameter (can be elementary help or collective help) -> if it is an import parameter then check it and if it is an export parameter then check it.
    5. Describe the data element to denote the types of elementary search help.
    6. Now go to included Search help tab -> select an elementary search help
    7. Parameter assignment-> Now system automatically maps elementary search help reference parameter to collective search help parameter -> now click on copy -> Activate.
    8. The search help is ready to use.

    Search Help Exit

    1. When you want to use search help beyond normal hits, then we need something called Search Help Exit.
      For example: For current run time data, I want to know the availability of flight seats with the prices enlisted in it. This might not be possible with the normal flow as the data would be fetched in tables containing either no of seats or costs separately.
      In this case we will use Search Help Exit.
    2. It is a well-designed function module with interface same as F4IF_SHLP_EXIT_EXAMPLE. It is called several times by the help processor.
  • Elementary Search Help in SAP ABAP

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

    Introduction

    As discussed in the last article i.e. Search Help in SAP ABAP, a search Help in SAP ABAP are reusable objects that are used to assign input helps (F4 helps) to screen fields. If the data for the search help is bought from a single table, structure or view and is displayed based on a condition, then it will be termed as Elementary Search Help.

    Definition

    As the name suggest an elementary search help reads records from a single element and that can be a table, structure or a view and based on a condition it returns records which are displayed by a dialog box.

    Steps to Create an Elementary Search Help:

    1. Go to SE11-> Choose Search Help-> Give a Name-> Click Create-> Choose types of search help-> Elementary-> (u will be directed to the maintenance screen of search help).
    Elementary Search Help in SAP ABAP
    Elementary Search Help in SAP ABAP
    1. Under the definition, tab give a description (It will help to get your Search Help identified).
    2.  Selection Method
      1. One can choose a SE11 Table,
      2. A View (Database, Projection or Help View)
      3. If you enter a table that has a text table (language specific tables) it will automatically mention its name.
    3. Dialog behavior
      1. Display values immediately -> hit list displayed immediately, best suited for small entries.
      2. Dialog with value restriction -> if the list of possible entries is large, user can limit the data to be processed to prevent system load.
      3. Dialog depends on set of values -> If the hit list contains less than 100 entries, if the hit list contains more than 100 entries the system displays the dialog box for restricted values.
        Dialog behavior
        Dialog behavior
    4. Selection parameters
      Choose and select the fields through drop- down list from the selection method (tables, views) that is to be displayed in the selection screen.

      1. IMP (Importing Parameters)
        The input value/field is passed to the search help.
      2. EXP (Exporting Parameters)
        Export values back to the input help when the user selects an option or a row.
      3. LPOS (List position)
        Position on the output list (hit list) the user selects from.
      4. SPOS (Screen position)
        Position of parameters for value selection in the dialog box.
      5. Default
        To display default values (date, system-fields (values of structure SYST)).
    5. Save -> Activate -> Test.

    Use of an Elementary Search Help

    1. Defines the standard flow of an input help.
    2. Following components can be defined in search help.
      1. Selection Method
        Through this you can choose the data in the hit list where it can come from.
      2. Dialog behavior
        Choose the information displayed in the hit list and in the dialog box.
      3. Selection parameters
        Fields you can choose for hit lists and values to be displayed in the hit list that can be returned in screen fields.

     

  • Transport Request in SAP

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

    Introduction

    Before we start with Transport Request in SAP, let us discuss basic concepts of coding environements/landscapes in SAP. In SAP ERP, we have three landscapes: Development, Quality and Production.

    • Development landscape is where a developer develops his/her codes/programs.
    • Quality landscape is where a developer/tester tests his/her codes/programs.
    • The production is where users actually use the programs made by developer.

    These landscapes give us flexibility to develop, test and run our under-development code before actually giving to the end user. In this way we can find and fix bugs that can actually cause crashes and dumps.

    Now, to make a connection between these landscapes and to transfer our code, SAP provides us something known as Transport Request.

    What is a Transport Request in SAP?

    A transport request is a package where a user can register changes done. It is used in order to transfer data from one installation to the other.

    Whenever we do a small or major change that can be an update an SAP user has to create TR.

    TR holds change tasks that can be understood by a folder that holds files.

    Syntax

    <SID>K<NUMBER>

    SID: System ID

    K: After releasing  TR creates a data file and co-file where data file holds database details and co file contains controlling data.

    NUMBER : Starting with 900001(randomly generated).

    Category of Transport Request

    A TR can hold n number of sub request tasks categorized as:

    Modifiable

    • A task is not released yet.
    • One can add more tasks and complete them before TR is finally released.

    Released

    • Tasks are completed and then it is released by the owner.
    • One cannot do changes and send it to the target system.

    Types of Transport Request

    TR is preferably created in two types, but we will discuss others too.

    Workbench

    • TR created as workbench request is cross-client i.e. changes done for one client reflects in the other client.
    • It is synonymously said that this type of request is created by technical

    Customizing

    • TR created as Customizing request is client specific i.e. changes done for one client won’t reflect the other client.
    • A client copy has to be created using T-CODE SCC1.
    • Client number can be seen next to this type of request
    • It is said that this type of request is created by a functional person

    Process of TR

    ·         Create A Request

    ·         Adding Objects in your Request

    ·         Releasing a Request

  • Debugging in SAP ABAP

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

    Introduction

    Whenever a SAP coder writes a program. At the time of execution, if it gives a dump or runtime error then SAP debugger is a tool to check your lines of codes and examine error during runtime. Debugging in SAP ABAP helps a programmer to check his program flow at runtime.

    We use ABAP debugger by default after the release of SAP 7.0.

    Definition

    In short, we can define as:

    • A tool to analyze ABAP programs.
    • A tool to examine errors in codes during runtime.
    • A tool to display data objects.
    • A tool to understand the flow logic of codes in a program while executing.

    Stepping through a program with the debugger helps you to detect and correct errors in the source code of an ABAP program.

    What is a Breakpoint?

    A signal which tells the runtime processor to interrupt processing and start debugging.

    It gets activated when the program reaches that point.

    How can we debug

    By setting a breakpoint

    Start the debugger by setting and managing the breakpoints and executing the code.

    By running the program debugging mode

    We can enter the debugging mode by using \h from any screen.

    This can be done when we want to check the program from the beginning and are not familiar with the program.

    Types of Breakpoints

    There are two types of breakpoints:

    A. Static Breakpoint

    1. This breakpoint is not specific to a user.
    2. To use a static breakpoint use ABAP Keyword BREAK-POINT.
    3. Place it in the line where you want to use the breakpoint.

    EXAMPLE:

    PROGRAMM Z_USERDATA.

    …..if sy-subrc<>0 .

    BREAK-POINT.

    endif.

    ….

    1. If you want to set a static break-point specific to a user.

    BREAK-POINT username.

    NOTE:

    Kindly delete the static breakpoints manually in development system itself, else it might affect the program in the production system.

    B. DYNAMIC BREAKPOINT

    1. These are breakpoints that are triggered when the program that you are running reaches a particular ABAP statement or exception class.
    2. When debugging session is finished it gets deleted automatically.
    3. U can set a dynamic breakpoint, either in an ABAP editor or directly in the debugger.

    c.1. For setting dynamic breakpoints in ABAP editor.

    c.1.1  Position the cursor on the line of source code where you want to set the break-point.

    c.1.2.  Go to utilities->breakpoint->Set/Stop. The system confirms that breakpoint is set.

    c.2. For setting a dynamic break point in debugging mode:

    c.2.1- Position the cursor on the line where you want to set the breakpoint.

    c.2.2- Select the line by double -clicking it or by choosing Breakpoint-> set/delete.

    NOTE:  A user can set 30 dynamic breakpoints without changing the program code.

    1. Session breakpoint
      Specific to a particular ABAP user session. If the user session is ended (log off sap system) all session breakpoints get deleted.
    2. External breakpoint
      They are applied to the current user session as well as future user sessions.

    e.1. Works in sessions initiated with RFC or HTTP requests or any other external interface.

    e.2. An external breakpoint can apply to:

    e.2.1.A user in the current SAP system

    e.2.2. A user in the current application server of the current SAP system

    e.2.3. User sessions started by a request that has a specific terminal ID.

    NOTE:  Session, External breakpoints can be created at runtime and can be activated/deactivated.

    Special KEYS in Debugging

    Debugging in SAP ABAP - Image Illustration
    Debugging in SAP ABAP – Image Illustration

    F5- Executes a program line by line.

    F6- Executes a function module or a subroutine without entering into it.

    F7- Executes a module or a program in a single step.

    F8 – Executes a program directly. If there is more than one break-point, then can move to one break-point to the other.

  • Exception Class in SAP ABAP

    Preface – This post is part of the Object Oriented ABAP series.

    Introduction

    To understand an exception class, we need to understand what is an exception and when it is raised.

    When we execute any program, some discrepancies can occur due to which a normal flow of execution gets interrupted and the behavior will not be the same as it was expected. That discrepancy is like an event which is occurring due to some reason, which is known as an ‘Exception’.

    It is required to handle such discrepancies in order to prevent the execution flow of any program. In order to achieve that, SAP ABAP has a special class known as an ‘Exception Class’.

    Exception Classes can be defined in a global class as well as in a local class. There are three exception classes exists, which are the subclasses of one root class ‘CX_ROOT’. Those three exception classes are:

    1. CX_STATIC_CHECK – which is being checked by both compiler and runtime system.
    2. CX_DYNAMIC_CHECK – Checked only at runtime system. All System exceptions will come under this exception.
    3. CX_NO_CHECK – This type will be chosen if exceptions are frequent.

    Definition

    An Exception class is used to handle the discrepancies(exception) occurs during the execution a of program.

    Whenever an exception occurs, an object is created (known as an exception object). The attributes of this object would contain information about the error. This exception can be caught by using TRY….CATCH…..ENDTRY block.

    TRY….ENDTRY block contains a protected area, where an exception can be caught using the CATCH statement. One TRY….ENDTRY block can catch more than one exception, but it should get caught in a sequence in which it occurs.

    There are two types of exception handling cases:

    1. One where the exception was raised, deleted before or after handling it.
    2. The other, where an exception which was raised is retained and the program is resumed after the statement that raised an exception.

    Program

    Let’s take an example of a simple arithmetic operation of two numbers. An exception should be raised if one of the two operands is missing.

    NOTE: A local class is used in below sample program.

    REPORT ztest_exception.

    CLASS lcx_missing_operand DEFINITION

    INHERITING FROM CX_STATIC_CHECK.

    ENDCLASS.                                                 “lcx_missing_operand  DEFINITION

     

    CLASS lcl_test_exception DEFINITION.

    PUBLIC SECTION.

    METHODS: add_numbers IMPORTING iv_num1 TYPE i OPTIONAL

    iv_num2 TYPE i OPTIONAL

    RETURNING VALUE(rv_calc) TYPE i

    RAISING   lcx_missing_operand

    PRIVATE SECTION.

    METHODS: do_check RAISING  lcx_missing_operand.

    DATA: lv_num1 TYPE i,

    lv_num2 TYPE i,

    lv_result TYPE i.

    ENDCLASS.                                                      “lcl_test_exception DEFINITION

     

    CLASS lcl_test_exception IMPLEMENTATION.

    METHOD add_numbers.

    v_num1 = iv_num1.

    v_num2 = iv_num2.

    me->do_check( ).

    rv_calc = v_result.

    ENDMETHOD.

     

    METHOD do_check.

    IF v_num1 IS INITIAL.

    RAISE EXCEPTION TYPE lcx_missing_operand.

    ENDIF.

    ENDMETHOD.

     

    ENDCLASS.                                                      “lcl_test_exception IMPLEMENTATION

     

    START-OF-SELECTION.

    DATA: lo_obj TYPE REF TO lcl_test_exception.

    DATA: lo_exc_root TYPE REF TO CX_ROOT.

    DATA: lv_msg TYPE STRING.

    CREATE OBJECT lo_obj.

    TRY .

    lo_obj->add_numbers( iv_num1 = 10 ).

    CATCH lcx_missing_operand.

    WRITE: /  ‘Operand is missing’.

    CATCH CX_ROOT INTO lo_exc_root.

    lv_msg = lo_exc_root->get_text( ).

    WRITE: / lv_msg.

    ENDTRY.

    Advantages

    1. With exception classes, you can track the sequence of called methods. Since in exception class, we have try-end-try block, so we can put the called methods in it, to know if one of them get failed.
    2. An exception class has an advantage that non-OO programmers won’t understand your code, increasing your job security a little.
  • Local Classes in SAP ABAP

    Preface – This post is part of the Object Oriented ABAP series.

    Introduction

    One of the flavors of ABAP classes (Global Classes) we have already discussed in the last article. Another flavor of ABAP class are Local Classes. The only difference between a local class & global class is visibility & accessibility. A local class can be accessed within that program only in which it is being defined & implemented, whereas a global class can be accessed in any other program.

    NOTE: In some of the previous articles, where different types of classes have been described, there the sample programs were the examples of local class only.

    Definition

    A class which is defined and implemented in a program is known as Local Class. Local classes in SAP ABAP can be created through Transaction code SE-38(tool to create a report).

    Program

    Let’s take an example of this class ‘ZCL_MARA’. This class is having one method ‘GET_MATERIAL_TYPE’  to get the material type of a given material.

    NOTE: ‘MARA’ is a table in SAP ABAP for general material data. So, in this sample program, material (iv_matnr – importing parameter of a method) is given by the user, and this method will fetch the material type ( like finished, semi-finished, raw, etc. )

    TYPES: BEGIN OF ty_mara,                                       “USER-DEFINED TYPES

    Matnr TYPE mara-matnr,

    Mtart TYPE mara-mtart,

    END OF ty_mara.

    CLASS zcl_mara DEFINITION.

    PUBLIC SECTION.

    METHODS: get_material_type

    IMPORTING iv_matnr TYPE mara-matnr

    EXPORTING ls_mara type ty_mara.

    ENDCLASS.                                                                    “CLASS DEFINITION

     

    CLASS zcl_mara IMPLEMENTATION.

    METHOD get_material_type.

    SELECT SINGLE matnr, mtart FROM mara INTO ls_mara

    WHERE matnr = iv_matnr

    ENDMETHOD.

    ENDCLASS.                                                                   “CLASS IMPLEMENTATION

     

    Advantages

    1. To restrict the usage of any functionality, we can use it in a local class of any program.
    2. A Local class is very useful while creating an ABAP Unit Test Class, as a local test class has been generated within a global class.
    3. These classes are useful for the enhancements of class methods.
  • Super Class in SAP ABAP

    Preface – This post is part of the Object Oriented ABAP series.

    Introduction

    One of the three pillars of OOABAP uses this concept of Super class to achieve ‘Inheritance’. Super class allows us to extend that class by creating a subclass of it. This subclass will have all the properties of a super class, plus it can have additional properties as well.

    Definition

    A class which is having a derived class from it, is known as a ‘Super Class’.

    To make a class Super Class, the first step is to uncheck the box indicating Final Class while creating a Class through T-Code SE24 (Class Builder). Because if a class is creating as a Final cannot be extended further, and inheritance cannot be achieved in that case.

    If the developer is using this concept of the super class & subclass, then he/she can have all the advantages of ‘Inheritance’.

    Program of Super Class in SAP ABAP:

    Let’s take an example of this employer class ‘ZCL_EMPLOYER’. This employer class is having one method ‘GET_INCOME’ to get income.

     

    CLASS zcl_employer DEFINITION.

    PUBLIC SECTION.

    METHODS: get_income RETURNING VALUE(income) TYPE F.

    PRIVATE SECTION.

    DATA: income TYPE F VALUE 100.

    ENDCLASS.                                                                    “CLASS DEFINITION

    CLASS zcl_employer IMPLEMENTATION.

    METHOD get_income.

    income = me->income * 80.

    ENDMETHOD.

    ENDCLASS.                                                                   “CLASS IMPLEMENTATION

     

    Now, I want to create a subclass of it, where I want to redefine this method ‘GET_INCOME’.

     

    CLASS zcl_manager DEFINITION INHERITING FROM zcl_employer.

    PUBLIC SECTION.

    METHODS: get_income REDEFINITION.

    PRIVATE SECTION.

    DATA: income TYPE F VALUE 100.

    ENDCLASS.                                                                    “CLASS DEFINITION

    CLASS zcl_manager IMPLEMENTATION.

    METHOD get_income.

    income = me->income * 100.

    ENDMETHOD.

    ENDCLASS.                                                                   “CLASS IMPLEMENTATION

     

    Once you derived a class from another class, the new class will be known as ‘SUBCLASS’ or ‘CHILD CLASS’. And the class from which a new class is deriving will be known as ‘SUPER CLASS’ or ‘PARENT CLASS’.

    As discussed earlier, the subclass can have all the properties, & methods of a super class. The developer can redefine the existing methods of the super class and he/she can also add some new functionality into it.

    Advantages:

    Provides reusability of code functionality & fast implementation time. It can have all the advantages of ‘Inheritance’.

  • Global Class in SAP ABAP

    Preface – This post is part of the Object Oriented ABAP series.

    Introduction

    From the reference of an article: SAP ABAP Classes we have discussed the flavors of ABAP Classes & we came to know that ABAP classes are available in two flavors, one of which is Global Class.

    The visibility section of the global class is always public, meaning all the ABAP programs in an R/3 system can access the global class. However, instantiation of that class could be set as either public, protected or private.

    Definition

    A class which is defined in the class builder (Transaction Code – SE24) is known as Global Class.

    While creating a class from Class Builder (T-code: SE24), we get many options that indicate which type of global class we want to create, for example, usual ABAP class, exception class, persistent class or a test class. It also gives an option of whether we want to make it final or not.

    After selecting the type of class and properties ( description & instantiation ), a screen will come where we can see the components of a global class like:

    1. Interfaces – Independent structures which are used in a class to extend the functionality of a class.
    2. Friends – If there is any class, which you want to make a friend of your class, you can define it here.
    3. Attributes – variables or constant declared within the class and can be accessed by all the methods of that class.
    4. Methods – Determines the behavior of an object, it provides some functionality. A method is allowed to access all the attributes of their class.
    5. Events – A mechanism through which one method can raise method of another class.
    6. Types – Table Types can be defined here, that can further be used anywhere in the whole class.
    7. Alias – A concept of providing an alternate method name for an interface method in an implemented class.

     

    While defining an attribute and method, there are two mandatory fields, which we need to provide:

    1. Level: We have 2 level options:
    • Instance – Components declared as instance can only be addressed by the instance(object) of that class only.
    • Static – Components declared as static can be used independently of a class instance.
    1. Visibility: We have 3 Visibility options:
    • Public – Components with this visibility will be available to all.
    • Protected – Components will be visible to that class, where they are defined and to the inherited class.
    • Private – Components will be visible to that class only, where they are defined.

     

    Advantages:

    Provides reusability of code functionality & fast implementation time.

  • Singleton Class in ABAP

    Preface – This post is part of the Object Oriented ABAP series.

    Introduction

    Sometimes there is a need to instantiate an object at a time, that means only one instance is required at one point of time. This is a very common requirement while designing an application. To achieve such a scenario, there is one concept of ‘Singleton Pattern’ or ‘Singleton Class’ in OOABAP.

    This was the theoretical part. Now, a question comes, that how to achieve it in real? So, here the answer is: By declaring the constructor as a ‘Private’ one.  This private constructor can be created after changing the instantiation type to private. This helps us to restrict the further creation of an object of a class.

    Definition of Singleton Class in ABAP

    A class is said to be a singleton class if it can have the utmost one instance only.

    Following is a procedure to create a singleton class :

    1. Visibility of class should be private.
    2. Declare a private attribute with reference to the same class, in which it is being declared.
    3. Create a public static method with returning parameter, having a reference of the same class.
    4. Create an implementation and an object inside the implementation of a public static method.
    5. To create an instance for the singleton class, call this public static method in any program.

    Program:

    For the better understanding of this Singleton Concept, let’s consider this below sample program and here as you can see that object creation of a singleton class is not possible outside the class. So, this is how a singleton pattern works.

    Singleton Class in ABAP
    Singleton Class in ABAP – Image Illustration

    Program Explanation:

    In the above program, we have implemented a local class lcl_singleton_test inside an ABAP Report. In the class definition, we have kept the class as private and have declared a Public section. Under the public section, we have  declared a static attribute lo_singleton which refers to the program itself. Also, we have defined a local variable v of type integer. Then, we have defined the class constructor and a method set_name for the class.

    Later, we have implemented the class where we are creating an object under class constructor. Also, we have assigned a value i.e. “GEETANSHU” to the local variable v.
    Now, in the report code, we are doing a static call to our class via its object r1.

    Advantages of Singleton Class in ABAP:

    1. With the use of Singleton class, testability improves.
    2. Singleton pattern supports the main moto of Object Oriented Design principle by allowing it to open for enhancements and closed for modifications.
    3. The advantage of using a private constructor in Singleton class (as no one create an object of your class).
  • Abstract Class in SAP ABAP

    Preface – This post is part of the Object Oriented ABAP series.

    Introduction

    In simpler words, a class can be called as an abstract class, if it would contain at least one abstract method. Now, the question comes, what is an abstract method? An abstract method is a method which does not have an implementation. Now, a question will come to your mind, if a method is not having any implementation, then what is the use of this abstract method or class.

    So, the answer to your question is: We can implement that abstract method, but not like any other simple class. There is a particular way to implement it.

    To implement an abstract method, a subclass of an abstract class is required. There is no need to instantiate an object of an abstract class. Instantiation is possible only for the subclass. An abstract class can have non-abstract methods as well and It is not necessary to redefine non-abstract methods in each and every inherited class.

    Following points, we need to remember while creating an abstract method:

    1. Abstract methods can never be private.
    2. Only instance methods are allowed to be an abstract method.

    Definition:

    Class with at least one abstract method (which does have implementation) is known as ‘Abstract class’.

    Example: Let’s take a simple real time scenario, where ‘TELEPHONE’ is your class. This class is having four Methods (each method depicts one functionality):

    1. PICKUP_CALL
    2. DROP_CALL
    3. REJECT_CALL
    4. DIAL_NUMBER

    For the first three methods, the functionality would be the same (meaning, you just need to click on one button). But in the fourth method, there could be many possibilities of dialing a number, say in case of an emergency, the dial number would be of three digits. Similarly, there will be different cases like dialing a landline number or a mobile number or some service number or some toll-free number etc.

    So, here ‘DIAL_NUMBER’ method will be declared as an abstract method. Here, the functionality of this method is same, that is dialing a number. But the implementation could be different in different scenarios.

    Program:

    CLASS ZCL_TELEPHONE DEFINITION ABSTRACT.                                            “Abstract Class”

    PUBLIC SECTION.

    METHODS: DIAL_NUMBER ABSTRACT.                                                       “Abstract Method”

    METHODS: PICKUP_CALL.

    METHODS: DROP_CALL.                                                                                “Non-Abstract Methods”

    METHODS: REJECT_CALL

    ENDCLASS.

     

    CLASS ZCL_SUBCLASS_TELEPHONE DEFINITION INHERITING FROM ZCL_TELEPHONE.        ‘
    PUBLIC SECTION.
    METHODS DIAL_NUMBER REDEFINITION.
    ENDCLASS.

    CLASS ZCL_SUBCLASS_TELEPHONE IMPLEMENTATION.
    METHOD DIAL_NUMBER.

    ENDMETHOD.
    ENDCLASS.

    Advantages:

    1. Provide flexibility to add default operations with multiple flavors.
    2. Abstract classes allow us to partially implement the class.
    3. We can achieve Polymorphism by using an abstract class.
    4. We can achieve Dynamic Binding also. The object of an abstract class can be used as a reference, which further could be replaced by the concrete object at runtime, this is known as dynamic binding.