Author: Rudramani Pandey

  • Difference between Structure and work area

    Preface – This post is part of the Differences in ABAP for Interviews series.

    Introduction

    We have already discussed Work Area and Structure in SAP ABAP. We already know how they are created and used within the ABAP Report programs. Structure and Work Area in ABAP coding are almost same. It is hard to specify any difference. In this article we will discuss the difference between Structure and work area.

    Structure in SAP ABAP

    A Structure in SAP ABAP is a part of group TYPES in SE11, which consists components that also, refer to a type.

    In simple terms, a structure is a reusable component that contains fields and holds single records at runtime.

    Work Area in SAP ABAP

    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.

     

    Difference between Structure and work area

    Structure Work Area
    A structure is created using SAP Data Dictionary (SE 11) as well as within a ABAP program. A work area is created within a report or Function Module.
    A structure can be a global as well as a local component. A work are is a local component
    A structure is reusable across all the ABAP programming interfaces and data dictionary. A work area is reusable within the report it is created.
    A structure can be nested at multiple levels. A work area cannot be nested.
  • Difference between BAPI and RFC in SAP ABAP

    Preface – This post is part of the Differences in ABAP for Interviews series.

    Before discussing the difference between BAPI and RFC, let’s have a short introduction of the two.

    BAPI

    BAPI stands for Business Application Programming Interface. BAPIs are the specific methods that are stored in BOR (Business Object Repository) of the SAP system to carry out a specific business task. It enables the exchange of business data between SAP components, and between SAP and non-SAP components. It allows integration at the business level rather than technical level. It is stored as RFC enabled function modules in the ABAP Workbench Function Builder. To use a BAPI method to access the data in SAP business objects, an application program only needs to know how to call the method using the name of the BAPI and import/export parameters. Standard BAPIs are easier to use as it prevents the user from having to deal with a large number of different BAPIs. A standard BAPI is preferred over an individual BAPI.

    RFC

    RFC stands for Remote Function Call. It is a protocol for communication between applications of different systems in SAP environment that includes connections between SAP systems and between SAP systems and non-SAP systems.  It is a standard SAP interface for communication between different SAP systems. It describes an external interface to a system function module available in the SAP system. The functionality of R/3 applications can be extended from an external program using RFC interfaces.

    Using only RFC, an SAP system cannot be connected to a non-SAP system to retrieve the data. Only through BAPI, RFC can access the SAP system from a non-SAP system or vice versa.

    Difference between BAPI and RFC in SAP ABAP

    Now, let’s have a look at their difference.

    BAPI RFC
    It is an RFC enabled function module that provides external access to an SAP business application. It is a protocol for communication between applications of different systems in the SAP environment.
    It can be wrapped in Business Objects. It cannot be wrapped in Business objects.
    It can be compared to CGI applications. It can be compared to HTTP
    All BAPIs are RFC. All RFCs are not BAPI.
    Exceptions are not used in BAPI. Exceptions can be defined in the interface of the called function module

     

  • Difference between Exception handler and Event handler

    Preface – This post is part of the Differences in ABAP for Interviews series.

    Before discussing the difference between Exception handler and Event handler, let’s have a short introduction of the two.

    Exception handler

    Exceptions are events that interrupt the flow of executions and make the program to execute further impossible. So, the exceptions need to be handled.

    Exception situations can be detected and raised by either the program or runtime environment. Exceptions in the runtime environment are generally caused by the error situation that cannot be detected by the static program.

    Exceptions can be either handleable or non-handleable. Handleable exceptions are class-based that are predefined in the system or can be custom-defined. They can be raised by the RAISE EXCEPTION or THROW statement and handled by TRY – CATCH – ENDTRY.

    Non-handled exceptions create runtime error and the program terminates with a short dump.

    Event handler

    Events are messages raised by the object when a condition is met. The events are caught by the event handler method that implements the logic to handle the event. These are used by objects or classes that trigger the event handler methods in other objects or classes. Any number of handler methods can be called when the event is triggered. The link between the trigger and the event handler method is decided at run-time.  The event handler decides the event to which it wants to react.

    Using RAISE EVENT statement, the events of a class can be triggered in the methods of the same class. A method of the same or different class is declared as event handler method for the event evt of class class using the addition FOR EVENT evt OF class.

    Difference between Exception handler and Event handler

    Now, let’s have a look at their difference.

    Exception Event Handler
    Exceptions are the error that occurs during the execution of a program that interrupts the normal flow of the control. Events are the messages raised by an object which is raised when a condition is met
    Exception handler is a unit of code that is executed after detection of an exception. Event handler is a unit of code that is executed in response to an event.

     

     

  • SAP Smart Styles

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

    Introduction

    SAP Smart Styles are used to define paragraph and character formats. It can be assigned to texts and fields in the Smart Forms. A Smart Style has to be assigned to each Smart Forms. This is done globally for the entire Smart Forms in the Form Attributes of the Navigation window. It can be applied locally to a node that applies it to the entire subtree, overruling the global settings. A Smart Style can be reused. It can be downloaded locally and uploaded again later.

    SAP Smart Style Feature

    A Smart Style contains the following features:

    • Header data: It contains the default values of the font for the Smart Style. If different values are not assigned to the paragraph and character formats, the system uses these default values.
    • Paragraph format: It contains information on indents, spacing, font settings, text colors, tabs, numbering, and outline. It must have a unique name for each paragraph format.
    • Character format: It is used to assign special output effects such as superscript and subscript, barcode, and font attribute to sections of texts or character strings within a paragraph. Each character format must have a unique name.
    • Colors and underlines can be added to paragraph and character format.
    • Preview option.

    SAP Smart Style Feature

    Each Smart Styles has 3 predetermined nodes in the navigation window, namely, Header data, Paragraph formats, and Character formats.  The Header node contains the standard settings of the font for the Smart Style. It can be seen in the maintenance window. At the bottom, one can see the preview of the selected font.

    Steps to create Smart Style

    1. SMARTSTYLES is the transaction code for Smart Style. Enter SMARTSTYLES in the common field.

    Steps to create Smart Style

    Note:  SMARTFORMS t-code can also be used to create Smart Styles.

    1. Enter the Style name.
    2. Click on
    3. To activate, click on Activate

    Note: To use and transport a Smart Style, it has to be activated first. During activation, if the system finds any error, it displays an error list.

  • Garbage collector in SAP ABAP

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

    Introduction

    As a developer, we need not to explicitly configure memory allocation and deallocation in the system. This process triggers automatically, when the object is created memory is automatically allocated to it and when it is terminated the memory is destroyed by the background process called Garbage Collector to free up the space for new objects.

    The objects using dynamic memory allocation captures some memory and that memory is allocated until there are references to that object. When there is no reference to the object, it is assumed that the object is no longer need. Garbage Collector identifies the unused objects (no more references to the object are there) and scrap it out for other objects to reuse the space. It is called periodically by ABAP runtime environment.

    The programs that do not de-allocate memory at last collapse when there is no more memory left in the system to allocate. This scenario is termed as a memory leak in the program. As garbage collector is an automated process, the number of memory leak errors is minimised.

    Why proper Garbage Collection is important?

    Garbage collection plays an important role in system programming. The unseemly behaviour of the garbage collector can result in critical problems, like:

    • Increased memory requirement
    • Performance degradation

    Benefits

    Garbage collection eventually reduces or eliminates some bugs:

    • Dangling pointer bugs: When there are one or more references to the object is used in the program but the memory is freed.
    • Double free bugs: To free the memory which is already freed.
    • Memory leaks: When memory is not cleared and objects have no reference, this will lead to memory exhaustion.

    Drawback

    Garbage collectors can sometimes bring runtime overhead that can serve as the performance problem for a larger application. Hence, it is critical to implement the right garbage collection method to optimize the application performance.  

  • User-defined types in SAP Classes

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

    Introduction

    User-defined types in SAP Classes are used to define structures and table types in the class. Structure is a data type that defines structures data objects and table type represents the structure and functions of an internal table.

    A TYPE in classes has following fields that are required to be filled:

    • TYPE: Unique name for type.
    • VISIBILITY: This field defines the visibility of type. It has four options: Public, Protected, And Private and Package.
    • TYPING: This field specifies the Reference Type. It has three options: Type, Type Ref To and Like.
    • Associated Type: Any elementary ABAP type or object type can be defined (generic types, classes or interface).
    • DIRECT TYPE ENTRY: The arrow marked button after Associated Type is called Direct Type Entry. It is used to provide further details of the data type.
    • DESCRIPTION: Short description of the field.

    Syntax

    TYPES: Begin of <structure-name>,

    .

    .

    END of <structure-name>.

    TYPES : <tt-name> TYPE TABLE OF <structure-name>.

    How to create User-defined types in SAP Classes?

    Follow the below steps to declare types in global class:

    1. Provide the object name in SE24.
    2. In Class/Interface screen, provide the method name in Method tab.
    3. Go to Types tab to provide user-defined type.
      • Click on Direct Type entry icon to open the editor.
      • Replace the types statement with the user-defined type.

    Example: TYPES : Begin of s_material,                                         “structure

    matnr TYPE MARC-MATNR,

    werks TYPE  MARC-WERKS,

    END OF s_material.

     

     

     

    TYPES : Begin of ty_mara,

    matnr TYPE MARA-MATNR,

    mtart TYPE  MARA-MTART,

    meins TYPE MARA-MEINS,

    matkl TYPE MARA-MATKL,

    END OF ty_mara.

    TYPES: tt_mara TYPE TABLE OF ty_mara.                  “table type

      • Save it.
    1. In the method parameter, add the parameter with associated type name as user-defined type name. And add the required code in method. Save and Activate it.
  • OOPS ALV in SAP ABAP

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

    Introduction

    The OO ALV is ALV using object-oriented ABAP. ALV stands for ABAP List Viewer and provides the standard list format and user interface for all the ABAP programs. The advantage of using OOPS ALV in SAP ABAP is that is flexible and used to build interactive and modern-designing list. SAP has provided a class (class name: CL_GUI_ALV_GRID) which acts as the wrapper class encapsulating ALV GRID functionality.

    The basic components for ALV Grid are:

    • List data: List data are the internal table data’s to be listed.
    • Field Catalog: The field catalog is the internal table that defines the specification on the display of fields. To generate field catalog there are three methods: Automatic generation, semi-automatic generation and manual generation. The internal table must be referred to LVC_T_FCAT.
    • Layout Structure: The layout structure must be of type “LVC_S_LAYO”. This can be used to modify the layout including colour adjustments, grid customization etc.
    • Event Handler: To handle events triggered by ALV, event handler class should be defined and implemented.
    • Additional Data: To stimulate additional data in ALV Grid, additional data should be passed as a parameter.

    Example

    Follow the steps to create an OOPS ALV in SAP ABAP:

    1. Create an object of class CL_GUI_CUSTOM_CONTAINER and class CL_GUI_ALV_GRID.
    2. Populate internal table.
    3. Call screen in which you want to display the list.
    4. Create Custom Container from layout lab
    5. Call method of class CL_GUI_ALV_GRID and pass the required parameters.

    Program

    "SCARR is the SAP Standard table which stores Airlines data
    DATA: t_flight TYPE TABLE OF SCARR.
    DATA: cust_container TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
    cust_grid TYPE REF TO CL_GUI_ALV_GRID.
    Select * from SCARR into table t_flight.
    CALL screen 100.
    MODULE STATUS_0100 OUTPUT.
    SET PF-STATUS 'SCREEN1'.
    SET TITLEBAR 'AIRLINES LIST'.
    ENDMODULE.
    MODULE USER_COMMAND_0100 INPUT.
    CASE SY-UCOMM.
    WHEN 'BACK'.
    LEAVE TO SCREEN 0.
    ENDCASE.
    ENDMODULE.
    MODULE LIST OUTPUT.
    CREATE OBJECT CUST_CONTAINER
    EXPORTING
    CONTAINER_NAME = 'CONTAINER'.
    CREATE OBJECT CUST_GRID
    EXPORTING
    I_PARENT = CUST_CONTAINER.
    CALL METHOD CUST_GRID->SET_TABLE_FOR_FIRST_DISPLAY
    EXPORTING
    i_structure_name = 'SCARR'
    Changing
    it_outtab = t_flight.
    ENDMODULE.

    After you paste the above code, you need to double-click on “CALL screen 100.” so that you can create a Screen. If you try to execute without creating a screen, then you will get an exception mentioning the same, i.e., “No Screen 100 available.”

    After double-clicking the screen, you will see the below view, update info as shown below:

    OO ALV Screen

    Double click on “SET PF-STATUS ‘SCREEN1’. ” and enter these:

    Screen 1 Status

    Add a button by double-clicking on Screen 100 and performing below:

    Add a button

    Back Code

    Update and Activate the screen after changing the below:

    Flow Logic in Screen

    Now change the Layout as shown below:

    1. Click on Layouts

    Layouts

    2. Create a custom container as shown below, choose the button and draw a rectangular shape:

    Screen Painter

    3. It will create something, as shown below. Double-click on it and then enter the name as “CONTAINER”

    CONTAINER

    5. Now Activate the screen, go back to the program, activate the program and run the program, you will see the OO ALV screen as shown below:

    OO ALV Output

    Tutorial Video

    You can watch the video below to learn implementation:

    [embedyt] https://www.youtube.com/watch?v=_duuxLwTq7I[/embedyt]
  • Class Pools and Interface Pools in SAP ABAP

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

    Introduction

    So far we have learnt about the classes and interfaces, their properties, uses and many more things. We can define the class and interface either globally in the repositories or locally in the ABAP program. When the classes and interfaces are defined globally, class pools and interface pools generated by CLASS BUILDER serves as a container and each class pool and interface pool contains a single class or interface. The benefit of defining globally is that they can be accessed by any ABAP program. Whereas when defining locally, they are accessed only by their own program.

    Class Pools

    A class pool acts as the container for classes defined globally and has program type K. It is somewhat similar to module pools or function groups (act as containers) except the fact that the class pools don’t have their own screens or processing blocks than methods. It contains both declarative as well as executable statements. The CREATE OBJECT statement creates the objects to execute the statements in class pools.

    The class pool is introduced by the statement CLASS-POOL in master program. The naming of the master program will contain the global class name and is padded with “=” up to 30th position and ends with “CP”.

    Example, The name of the interface pool for global interface CL_DEMO_GO_CODING is CL_DEMO_GO_CODING=============CP.

    Structure of Class Pool
    Below is the structure of Class Pools:

    Class Pools and Interface Pools in SAP ABAP

    The types defined in the class pool are only visible in the implementation part of the global class.

    Interface Pool

    An interface pool acts as the container for interfaces defined globally and has program type J. Unlike the class pools, interface pools do not have any executable statements. They contain the interface definition which can be implemented by global and local classes.  When interfaces are implemented in global class, the interface definition is also included in the class definition.

    Similar to class pool, the name of the master program of interface pool contains the global interface name and is padded with “=” up to 30th position and ends with “IP”.

    The name of the interface pool for global interface IF_DEMO_GO_CODING is IF_DEMO_GO_CODING=============IP.

  • SAP SmartForms Trace

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

    Introduction

    The SmartForms trace allows us to trace the processing of the Smart Form during printing. It can be analyzed to determine the sequence of the processing of the nodes and the point at which the processing was terminated due to an error.

    SAP SmartForms Trace

    To trace the SAP SmartForms processing, the SFTRACE transaction is used. When a trace is activated using the generated function module, the Smart Form stores the trace for each output in the database.  The degree of the details of the trace can be set. The trace is automatically deactivated after a day; however, the trace files are retained.  The trace output is user-specific which means it is activated only for the user who activated it.

    Trace Settings

    The following settings are available if the trace is active:

    • Level: Determines the degree of the details of the trace.
    • Logical Page (Name): Restricts the trace output to a specific page.
    • Window: Restricts the trace output to a specific window on a page.
    • ABAP Breakpoints: Warning and Error options are used internally.

    Trace Level

    This determines the degree of the details of the trace. Level 5 contains general information while Level 80 contains the most detailed trace.

    The following are the trace levels:

    • Warning or error (Level 5): It contains trace level, trace version, system date and time, and system information.
    • Document information (Level 15): It contains additional information like output channel, form attributes, form structure, and output results.
    • Pages (Level 30): It contains additional information like the name of the processed pages (except the name of the start page).
    • Window (Level 40): It contains additional information like names of the processed windows
    • Output area (Level 45): It also contains information about the table output area.
    • Cell change (table) (Level 47): It also contains the outputs on line types and cells processed in the tables.
    • Text information (Level 50): It also contains attributes values of the processed output nodes like text elements, text modules, etc.
    • Fields (Level 60): It also contains the names and values of the fields in the text outputs,
    • Scanner token (Level 80): It is the maximum trace level and also contains the scanner outputs when analyzing the texts in the text nodes.

    Activating and Configuring the Trace

    The trace is deactivated by default. To trace the form, trace has to be activated and configured. Steps to activate and configure the trace:

    1. Enter SFTRACE in the common field.

    SAP SmartForms Trace

    1. Click on Switch On Once clicked, the status changes from Trace Inactive to Trace Active.

    SAP SmartForms Trace Admin

    1. Set the trace level and other settings.
    2. Press Enter to confirm the entries.

    Once the trace is active for the user, whenever the Smart Form is called, a new trace is created every time. The trace is automatically deactivated after a day; however to manually deactivate the trace click on Switch Off pushbutton.

     

    Analyzing Trace Output

    Traces are stored in the Traces in the database frame of the SFTRACE transaction window. Use the Refresh button to get the updated trace.

    To analyze the trace in the system:

    1. Select the line by pressing the pushbutton on the left side of the table.

    Traces in Database

    1. Click on Display Trace to see the trace screen.

    Analyzing Trace Output

    The traces can be stored locally by selecting the Export   button. To read the locally stored trace, select Read trace from local file button.

    Trace Output

  • Output Types in SAP SmartForms

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

    Introduction

    In classic form printing, the forms are printed using a printer. Smart Forms provides different output types or formats for different use cases. Form Attributes under General Settings node is used to determine the default settings for the form output. The default settings can be overruled using the standard parameters while calling the Smart Forms. In this article we will discuss the Output Types in SAP SmartForms in details.

    Output Types in SAP SmartForms

    Different output types/formats for the SmartForms are:

    • Output Text Format (OTF): It is a standard output format for printing forms in SAP systems. It is the default format in the Form Builder. It can be converted to other formats. It is usually output using spool processing. For this output, in the system, a printer must be set up with a device type that understands OTF.
    • XML for Smart Forms (XSF): It is an XML schema designed for the output of form contents. It does not contain any layout information. It is used to connect to external components of the SAP system to process the contents of the form. To use spool processing for XSF output, at least one printer of type ‘XSF’ must be set in the system.
    • XML Data for Forms (XDF): It is an XML schema that describes the contents of the form. It neither contains the form content nor the layout. To use spool processing, at least one printer of type ‘PLAIN’ must be set in the system. It is stored in the spool in binary format to ensure that no data is lost during conversion.
    • Hypertext Markup Language (HTML): It is a combination of XSF and HTML format that generates the layout information to be able to display into the internet application in order to complete business processes via electronic media rather than using printed mail. The Smart Forms returns a number of structures and tables for HTML outputs.