Author: Rudramani Pandey

  • SAP SmartForms Flow Control

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

    Introduction

    The flow of the processing of the Smart Form can be controlled using the tree hierarchy defined in the navigation window. In this article we will explain the flow control in SAP SmartForms.

    Conditions affecting Flow Control

    There are multiple options that affect the sequence of the processing of the form.

    Output Conditions:

    This is used to suppress the processing of individual nodes or entire subtrees in the tree structure.

    • To enter the output condition, select the node and go to the Condition tab in the maintenance window.
    • In this tab, a condition can be entered with two operands in each line. An operand can be a value or a field. To select a comparison operator, press on the pushbutton between the two columns. The most important operators are AND and OR. By default, the conditions are evaluated using AND
    • Perform local check to validate output conditions.
    • The output conditions can be linked to output events of pages and windows. Using AND condition in Additional event box is used to link them.

    When the conditions are met, the system processes the nodes/sub-nodes according to the condition value. If not, the system ignores the current node and its sub-nodes.

     

    Alternative Execution:

    It is used to process one of two inferior nodes. To do so,

    • Create a Alternative node in the navigation tree.
    • On the General Attributes tab, define an unstructured condition in the Node Conditions
    • This node has two directly inferior nodes: TRUE and FALSE. Insert the inferior nodes here.
    • Perform local check to validate output conditions.

    If the condition is met, the system processes the directly inferior node TRUE, if not, FALSE.

    Repeated Output:

    To process the output repeatedly, loop nodes are used which reads the data from the internal table line by line. To do so,

    • Create a Loop node in the navigation tree.
    • Enter a unique name and description for the node.
    • Read the data from an internal table to a work area and create inferior nodes that display the fields of the read table lines.

     

    Dynamic Processing:

    This is done by page sequence and numbering. This is determined by

    • The Next page attribute
    • The volume of the data and space available in the main window
    • As soon as a page is full, the Smart Form triggers a page break, known as a dynamic page break.

    During the processing of the form, the system maintains internal counters, which can be used to display the current page number.

  • Node Types in SAP SmartForms

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

    Introduction

    When a Smart Form is created, the form builder already has two nodes in the Navigation window. “Global Settings” and “Pages and Windows” are the two roots that are created by default for every Smart Form.  In this article we will explore more about Node Types in SAP SmartForms.

    Nodes in SAP SmartForms

    The inferior nodes of the Global Settings are used to maintain Form Attributes, Form Interface, and Global Settings.

    The inferior nodes of the Pages and Windows are used to create pages of the form, position elements on the pages, and determine the flow of the process of the elements.

    Each sub-node of the two root nodes has attributes. These attributes are maintained in the Maintenance Window. The attributes that can be maintained are General Attributes, Output Options and Conditions are the same for almost every type of the nodes.

    • General Attributes shows the general description of the node.
    • Output Options contain properties such as Positions, Style, Box and Shading. It may have additional options depending on the position of the node.
    • Conditions allow the processing of the node only if the conditions are true.

    Node Types in SAP SmartForms

    Let’s discuss the types of nodes:

    1. Output Areas:

    Output Areas

    1. Elementary Nodes:

    Elementary Nodes

    1. Table Outputs:

    Table Outputs

     

    1. Flow Control:

    Flow Control

  • SAP SmartForms Form Logic

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

    Introduction

    As we have discussed already in the previous tutorial about the Form Builder, let’s see about the Form Logic in SAP SmartForms.

    In SAP SmartForms, the form logic defines the data to be read from the database, the conditions, and controls the flow of the form output. The form logic is described by the form structure on the left pane of the Smart Forms interface.

    SAP SmartForms Form Logic
    SAP SmartForms Form Logic

    Nodes in SmartForms

    When a new Smart form is created, there are default nodes on the left side.  Global Settings and Pages and Windows are the two roots that are created by default for every Smart Form.

    The Global Settings node has 3 sub-folders, namely Form Attributes, Form Interface, and Global definitions. The Form Interface contains the data which will be passed to the Smart Form from the calling ABAP program and the Global Definitions contain the data that are available throughout the Smart Form.

    Defining Form Logic in SAP SmartForms

    To define the form logic, a hierarchical structure has to be defined under Pages and Windows in Navigation Window. This hierarchy determines the rules for processing the Smart Form.

    The form logic is used to control the flow of the form output. The following rules for form logic should be remembered:

    • In the tree structure, a tab is defined in the Maintenance Window for every node to link the node to a condition. If the condition is fulfilled, the node is processed and if not, then the node is skipped as well as all its sub-nodes.
    • The nodes are processed from top to bottom.
    • The page break on each page depends on how much space is left on the current page.
    • A next page should be defined for each page and flow control is defined for each page. However, one can go to other pages dynamically.
  • Events in ABAP Class

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

    Introduction

    Events in ABAP Class are the functions in a class which triggers the event handlers of other class based on the outcomes. With the use of events, any number of event handler methods can be called. The link between the triggering event and event handler is decided at run-time.

    Definition

    An event is the mechanism by which a method of one class can invoke the method of other class without instantiating that class.

    Steps to add Events in ABAP Class

    • Define an event
    • Define a method
    • Link event and method
    • Create a triggering method to raise the event
    • Define SET HANDLER statement at an instance in the program

    Points to consider

    • Event handler method is defined by FOR EVENT <event-name> OF <class-name>.
    • It has only output parameters.
    • To pass output parameters to the event handler method, RAISE EVENT statement is used.
    • SET HANDLER method is used to link the event to its handler methods in a program.

    Types of Events

    Events are of two types:

    • Instance events: Instance events can only get triggered in instance methods. It is declared using EVENTS statement.

    EVENTS <event-name>….

    • Static events: Static events are triggered by both instance and static methods. And also static methods can only trigger static events. It is declared using CLASS-EVENTS.

    CLASS-EVENTS <event-name>….

    Syntax

    FOR EVENT <event-name> OF <class-name>.

    Example

    Lets’ pin down an example:

    **** main class definition****

    CLASS zcl_demo DEFINITION.

    PUBLIC SECTION.

    DATA : num1 TYPE I.

    METHODS: compare IMPORTING num2 TYPE I.

    EVENTS: event_compare.

    ENDCLASS.

    ****event handler definition****

    CLASS zcl_eventhandler DEFINITION.

    PUBLIC SECTION.

    METHODS: handling_compare FOR EVENT event_compare OF zcl_demo.

    ENDCLASS.

    ****class implementation ****

    CLASS zcl_demo IMPLEMENTATION.

    METHOD compare.

    num1 = num2.

    If num1 > 10.

    RAISE EVENT event_compare.                                                              “Raise an event

    ENDIF.

    ENDMETHOD.

    ENDCLASS.

     

    ****event handler implementation ****

    CLASS zcl_eventhandler IMPLEMENTATION.

    METHOD handling_compare.

    WRITE: “Event triggered… Num1 is greater than 10..”

     

    ENDMETHOD.

    ENDCLASS.

    START-OF-SELECTION.

    ****creating class object****

    DATA : object_demo TYPE REF TO zcl_demo,

    ****creating event handleobject****

    object_eventhandler TYPE REF To zcl_eventhandler.

    CREATE OBJECT object_demo.

    CREATE OBJECT object_eventhandler.

    SET HANDLER object_eventhandler-> handling_compare FOR zcl_demo.        “Setting up handler

    object_demo-> compare(2).

    Events in ABAP Class

  • Interface in ABAP

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

    Introduction

    As we know that the principles of Object-Oriented Programming are Encapsulation, Abstraction, Inheritance and Polymorphism. Polymorphism is implemented through Interfaces. It defines the ability of a message to be displayed in many forms. It allows an interface to have multiple implementations.  In this article we will discuss Interface in ABAP OOPs in detail.

    Consider a real-life example; a person at the same time has many roles. A woman at the same time can have many features, she can be a mother, wife, daughter or an employee but actions are as per the situation and conditions. Similarly, an interface is an independent entity which can have many implementations to extend the scope of the classes.

    Properties of Interface

    • Interfaces only have method definitions. Method implementation is done in implemented classes.
    • Interfaces can be used by any no of classes to extend the scope of the class.
    • Each class can have its own implementation of interface methods depending upon the class functionalities.
    • The declaration of interface does not include the visibility section. But in the declaration part of a class, they must be listed under Public Section.

    You can create an interface in SE24. Provide the interface name, methods and its parameters and implement the interface in classes.

    Definition of Interface in ABAP

    Interface is an independent structure which is used in classes to enhance its functionality.

    Example

    Let’s pin down an example.

    ****interface definition****

    INTERFACE zif_demo.

    METHOD display.

    ENDINTERFACE.

    ****class definition ****

    CLASS zcl_demo DEFINITION.

    PUBLIC SECTION.

    INTERFACES zif_demo.

    END CLASS.

    CLASS zcl_demo1 DEFINITION.

    PUBLIC SECTION.

    INTERFACES zif_demo.

    END CLASS.

     

    ****class implementation****

    CLASS zcl_demo IMPLEMENTATION.

    METHOD zif_demo~display.                                                              “Interface Method implementation

    WRITE : “This is the interface method in class 1..”

    END METHOD.

    END CLASS.

    CLASS zcl_demo1 IMPLEMENTATION.

    METHOD zif_demo~display.                                                              “Interface Method implementation

    WRITE : “This is the interface method in class 2..”

    END METHOD.

    END CLASS.

     

    ****creating class object****

    START-OF-SELECTION

    DATA : object_demo TYPE REF TO zcl_demo.

    CREATE OBJECT object_demo.

    CALL METHOD : object_demo-> zif_demo~display.

     

    DATA : object_demo1 TYPE REF TO zcl_demo1.

    CREATE OBJECT object_demo1.

    CALL METHOD : object_demo1-> zif_demo1~display.

     

    Interface in ABAP

    In the above example, there is one interface zif_demo defined which has only the definition part. And we have two classes zcl_demo and zcl_demo1 implementing the interface. This is how we can achieve Polymorphism through interfaces.

  • Alias in SAP Classes

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

    Introduction

    An alias in general term is used to indicate the alternate name for a given person, or thing. Similarly, in OOPs ABAP, an alias is an alternate name given to the interface methods implemented in the class. Whenever we implement the interface in a class, the interface method is copied with naming convention <Interface-Name>~<Method-Name>. Instead of using the default interface method name in the class, we can provide an alternate name to it (called alias) and can use alias name in the program. In this article we will learn more about Alias in SAP Classes.

    Definition

    An alias is an alternate name for interface methods that are implemented in the class.

    How to give alias name to interface methods in the SAP Classes?

    In transaction SE24, provide the class name and open it in editable mode. There will be one Alias tab. Provide the alias name corresponding to the interface methods.

    Calling interface methods in the class will be easy by the use of an alias.

    CALL METHOD <object-name> -> <alias-interface-method>

    Syntax

    The below syntax is used to give alias in the program:

    ALIASES  <alias-name> FOR <interface-method>.

    Example

    Let us suppose an interface is implemented in the class and we have provided alias name to the interface method.

    For example,

    ZIF_MATERIAL~GET_MATERIAL_DETAILS (Interface Method)    –       DETAILS (Alias Name)

    DATA : object_name TYPE REF TO zcl_demo.

    DATA: wa_mara TYPE MARA.                                                                      “MARA Declaration

    PARAMETERS p_matnr TYPE MARA-MATNR.                                       “User Input

    CREATE OBJECT object_name.                                                                   “Object creation

    START-OF-SELECTION.

    ** CALL METHOD object_name -> ZIF_MATERIAL~GET_MATERIAL_DETAILS.**

     

    CALL METHOD object_name -> details.                                                   “Method call with alias name

    EXPORTING

    IM_MATNR = p_matnr

    IMPORTING

    EX_MATNR = wa_mara.

    The above code retrieves the material details based on the input material number (MATNR) from interface ZIF_MATERIAL. Here we have used the alias name DETAILS as method name for the simplicity of understanding the code. Instead of DETAILS, we can also use ZIF_MATERIAL~GET_MATERIAL_DETAILS, but using this more than once in tricky code will make the code much more complex.

  • Class Method in SAP OOABAP

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

    Introduction

    A method defines the behaviour of an object. It can access all the attributes and hence can change the status of the object. In this article we will discuss Class Method in SAP OOABAP.

    There are a few points to consider while declaring the method:

    • The method definition is defined in the class definition and implemented in class implementation.
    • It can be declared using Method and End method statement.
    • Methods have parameter interface to pass the values when they are called and return the value to the caller.

    Syntax

    The method must be declared between the statements METHOD and END METHOD.

    METHOD <method-name>.

    .

    .

    END METHOD.

    Types

    There are three types of methods:

    • Instance method

      These methods are declared using METHOD statements. They can access all the attributes of the class and can trigger all the events.

    • Static methods

      These types of method are declared using CLASS-METHOD statements. They can access the static attributes and can trigger static events only.

    • Special methods

      There are two special methods : constructor and class_constructor, which are called automatically whenever the class is accessed for the first time.

    ME Operator in Class Method

    In the implementation part of the instance method in a class, an implicitly created local reference variable ME is available. It points to the currently executed instance. The me variable is reserved and cannot be used for naming attributes and parameter.

    Example

    ****class definition****
    
    CLASS zdemo DEFINITION.
    
           PUBLIC SECTION.
    
                 DATA var(50) TYPE C VALUE “Displaying me variable”.
    
                    METHOD instance_method.                                                        “Instance Method definition
    
                    CLASS-METHODS static_method.                                              “Static Method definition
    
    END CLASS.
    
    ****class implementation****
    
    CLASS zdemo IMPLEMENTATION.
    
           METHOD instance_method.                                                                “Instance Method implementation
    
                    WRITE : ME->var.                                                                             “ Displaying ME Variable
    
                    WRITE : “This is instance method”
    
           END METHOD.
    
           METHOD static_method.                                                                      “Static Method implementation
    
                    WRITE : “This is static method”
    
           END METHOD.
    
    END CLASS.
    
    ****creating class object****
    
    START-OF-SELECTION
    
    DATA : object_demo TYPE REF TO zdemo.
    
    CREATE OBJECT object_demo.
    
    CALL METHOD : object_demo-> instance_method ,
    
                                    object_demo->static_method.

    Class Method

  • Objects in ABAP

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

    Introduction

    Objects in ABAP are special variables that have distinct characteristics and behaviors in general terms known as attributes and methods. The attributes define the state of an object and a method defines the behavior or actions performed by the object.

    An object has three main characteristics-

    • State – State defines the set of attributes and its values.
    • Identity – Each object has a unique identity.
    • Behaviour – Behaviour defines the actions performed.

    The two objects may have the same state or behaviour but their identity is always unique. The identity of object sustains till its lifetime.

    For example, a student has attributes like student name (first name, last name), student id, date of birth, address and behaviour would be the change in its attributes. The two students may have the same attributes and behaviour but they are not identical. Their identity is unique and will never change throughout their lifetime.

    Objects interact with each other by sending messages.

    Definition

    An object is the instance of the class. It is a special variable that has distinct characteristics and behaviours.

    ABAP Objects creation

    Object creation includes two steps. They are as follows:

    • Creating reference variable to class.

    DATA : <object_name> TYPE REF TO <class_name>.

    • Creating an object from the reference variable.

    CREATE OBJECT : <object_name>.

    Example

    Let’s jot down an example.

    ****class definition****
    
    CLASS zdemo DEFINITION.
    
                    PUBLIC SECTION.
    
                                     METHOD : zdemo_method.
    
    END CLASS.
    
    ****class implementation****
    
    CLASS zdemo IMPLEMENTATION.
    
                    METHOD zdemo_method.
    
                                    WRITE : “ABAP Object”
    
                    END METHOD.
    
    END CLASS.
    
    ****creating class object****
    
    START-OF-SELECTION.
    
    DATA : object_demo TYPE REF TO zdemo.                                             “Creating reference variable”
    
    CREATE OBJECT object_demo.                                                                   “Creating object”
    
    CALL METHOD : object_demo->zdemo.

    Objects in ABAP

    In the example, zdemo_method is the method defined in the public section of definition part of the class zdemo. The implementation part of the method is provided in the class implementation. Firstly, we have created the reference variable object_demo to the class and then created an object object_demo from the reference variable. The object_demo->zdemo calls of the method zdemo_method and executes the code inside the method.

  • Migration from SAPscript to Smart Forms

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

    Introduction

    SAP Smart Forms is a tool to create and maintain forms for mass printing and sending documents for important business processes. If an existing SAPscript form is available in the system, it can be migrated to SAP Smart Forms.  The SAPscript can be migrated individually or any number of SAPscript can be migrated in one go. In this article we will discuss the steps involved in the Migration from SAPscript to Smart Forms.

    Migration of a SAPscript

    Step 1: Enter SMARTFORMS in the common field. Enter the Smart Forms name in the form name.

    Open Smart Forms Transaction
    Open Smart Forms Transaction

    Step 2: From menu bar, choose Utilities -> Migration ->Import SAPscript  Form.

    Migration from SAPscript to Smart Forms

    Step 3: A popup will appear. Enter the name of the SAPscript which has to be migrated. Also, provide language in the language field.

    Import Smart Scripts
    Import Smart Scripts

    Note: If the SAPscript is not available in the selected language, a popup will appear with a list of all languages that are available on the form. Select one of the existing languages.

    Select a Language
    Select a Language

    Step 4: Press Enter. It opens the SAP Form Builder screen in change mode.

    Step 5: Now, change the layout and logic of the form. And Click on the Activate button to activate the Smart Forms.

    Mass migration of the SAPscript

    Step 1: Enter SE38 in the common field and execute the SF_MIGRATE report.

    Step 2: Enter the names and language of the SAPscript form and Execute. The system creates the corresponding Smart Forms with the name of the SAPscript with an extension  _SF.

    Step 3: To modify the Smart Forms, go to transaction SMARTFORMS and enter the name of the Smart Forms. Modify and click on the Activate button to activate it.

  • SAP Smart Forms Builder

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

    In the previous tutorial, we have learned about the basics of SAP Smart Forms. Let’s learn about the screen and windows in SAP Smart Forms Builder.

    Introduction

    SAP Smart Forms provides a graphical user interface that allows us to create and maintain the layout and the form logic of the form. The graphical user interface is known as the SAP Form Builder.

    The SAP Form Builder is divided into three sections:

    SAP Smart Forms Builder
    SAP Smart Forms Builder
    1. Navigation Window: It consists of nodes and sub-nodes, which contain all the elements like windows, texts, etc. It shows the hierarchical structure of the Smart Forms and maintains the form logic. It has 2 root nodes by default for every Smart Forms:
    • General setting’s node to maintain Form Attributes, Form Interface, and Global Definitions. The Global Definitions contain the data that are available throughout the Smart Forms and the Form Interface contains the data which will be passed to the Smart Forms from the calling ABAP program.
    • Pages and Windows to create pages of the form, position elements on the pages, and determine the flow of the process of the elements.

     

    1. Maintenance Window: It is used to maintain the attributes of all the elements in the navigation tree nodes. In this window, depending on the node type, additional graphical tools are integrated.
    • PC Editor for the text nodes.
    • Table Painter for tables and template nodes.

     

    1. Form Painter: It is used to design the layout of the page of the Smart Forms. It allows us to add Windows and graphics, determine their position and size. It can be displayed or suppressed by selecting Form Painter on/off.

     

    Features

    1.      Navigation

    If a node is selected in the Navigation Window, the system displays the corresponding maintenance screen and highlights the corresponding window in the Form Painter.

    Also, on selecting a window in Form Painter, the system highlights the corresponding node in the tree and displays the corresponding maintenance screen for the selected window.

    2.      Updating the form

    Some settings such as height, width, etc. that are done graphically in the Form Painter are automatically copied to the maintenance screen. However, if the attributes are changed in the maintenance screen, it reflects the Navigation screen and Form Painter only after RETURN is pressed.

    3.      Service function

    The Form Builder provides the following service functions:

    • It has a field list that contains all fields of the Smart Forms.
    • It has an error list.
    • It allows us to undo/redo the changes to the form description.
    • It allows uploading and downloading the form locally.
    • It allows returning to the last active version of the form.