Category: ABAP

ABAP

  • Difference between Procedural Programming and Object-oriented Programming

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

    Introduction

    Before jumping to the difference between a Procedural Programming and Object-oriented Programming, let’s have a short introduction of the two.

    Programs are the instructions that tell the computer what to do to come up with the solution to a particular problem. There are several approaches to building solutions to specific types of problems with programming. Two of the most important approaches are procedural programming and Object-Oriented Programming.

     

    Procedural Programming

    Procedural Programming is a structured programming approach, based upon the concept of calling procedures which consists of a series of computational steps to be carried out. It follows Top Down approach to solve any problem. There is no accessing mode required to access the attributes or functions of a particular program. There is no proper way of hiding data, hence it is less secure.

    Object-oriented Programming

    Object-Oriented Programming is based upon the concept of Objects and Classes. It follows Bottom Up approach to solve the problem. The OOP paradigm focuses on the data rather than the algorithm to create the modules by dividing into the data and functions. An object contains the data in the form of attributes and codes in the form of methods. It provides data abstraction; hence it is more secure than procedural programming.

    Procedural Programming and Object-oriented Programming

    Procedural programming is simple and straight forward as it allows good isolation and containment for variables when properly scoped with functions and control loops. But it becomes more prohibitive to maintain the larger codes.  Here comes the Object-oriented Programming which makes it easy to maintain the codes as new objects can be created which control their data. SAP provides us option to implement of them altogether.

    Difference between Procedural Programming and Object-oriented Programming

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

    Procedural OOPs
    It is process-oriented. It is result-oriented.
    Follows Top down approach. Follows Bottom up approach.
    Each function contains different data. Each object controls its data.
    There is no access specifier They have access specifiers such as Private, Public, Protected etc.
    Adding new data and function is not easy. Adding new data and functions is easy.
    Overloading is not possible. Overloading is possible.
    It is less secure. It is more secure.
    No concept of inheritance. Inheritance is allowed.

     

  • Difference between SAP Memory and ABAP Memory

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

    Introduction

    Before jumping to the differences between SAP memory and ABAP Memory, let’s have a short introduction.

    ABAP programs utilize two types of memory: SAP memory and ABAP memory. The main difference between the two memories is their scope.

    SAP Memory and ABAP Memory

    ABAP memory is very limited as it can only accessible within one internal session and programs running outside the session are not able to read or write this memory. Whereas, SAP Memory is a global memory and is accessible to all the programs running under that session as well as across different main sessions. SAP memory can be used to pass data from one program to another either within a session or to another session.

    In terms of usage, the main use of ABAP memory is to make data accessible to multiple programs within the same session. Whereas, SAP memory also makes data available across multiple sessions.

    When dealing with SAP memory, GET/SET parameters are used to exchange data. To set these parameters for a user or a program, SET PARAMETER is used and other programs can then retrieve the parameter using the GET PARAMETER command. On the other hand, ABAP memory can be accessed by the ABAP programs within the same internal session using IMPORT and EXPORT commands. Data within this memory remains intact during a sequence of program calls.

    It is important to they are used appropriately to enhance the speed and efficiency of the application as well as resource usage.

    Difference between SAP Memory and ABAP Memory

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

    SAP Memory ABAP Memory
    It is a Global Memory. It is a local Memory.
    All SAP GUI sessions have access to it. All programs within a session can have access.
    It makes data available across main session It makes data available multiple session within same session.
    Data can be exchanged using GET/SET. Data can be exchanged using EXPORT/IMPORT.

     

  • Data Class vs Delivery Class in SAP ABAP: Differences

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

    Introduction

    The most common question of an ABAP Interview is the difference between Data Class and Delivery class of an ABAP Table. In our previous articles, we have discussed both in detail and now we will discuss their differences.

    Before jumping to the difference between a Data Class and Delivery class, let’s have a short introduction of the two.

     

    Data Class

    A Data Class represents a physical area in the database where all the data of the table assigned to this Data Class are stored.

    Data Class in ABAP can be assigned to a table using its Technical Settings. SAP was smart while creating properties for tables. With the help of Data Class, SAP divides and organize the Tables according to their type of Data. It keeps all Master Data together, all Transaction Data together, all User Data together and all Organizational Data together. This increases system performance as well as increases system availability.

    Types of Data Class are:

    • APPL0 (Master Data): Data which is rarely changed.
    • APPL1 (Transactional Data): Data which is changed frequently.
    • APPL2 (Organizational Data): Data defined when the system is installed and seldom
    • USER and USER1 are provided for the customer.

     

    As Data Class determines the type of data the table contains, the Delivery class determines the behaviour of the table.

     

    Delivery Class

    A delivery class defines:

    • Transport control of Data within Landscapes and customer systems
    • Transport control of Data for an installation and upgrade
    • Transport control of Data of client copy
    • If data can be maintained in Extended Table Maintenance [SM30] using TMG or not.

     

    In short, we can say a delivery class determines whether data of the table can be maintained & transported or not.

    Types of Delivery Class are:

    • A: Application table (master and transaction data).
    • C: Customer table, data maintained by the customer only.
    • L: Table for storing temporary data

     

    Difference between Data Class and Delivery class

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

    Data Class Delivery Class
    It determines the actual physical area of database where table is created It controls the degree to which SAP or customer is responsible for table maintenance
    It is set in Technical settings for the table It is set in Delivery & Maintenance
    It determines the type of data the table contains. It determines the table type.
    They are of 5 types:

    APPL0 à Master Data

    APPL1 à Transactional Data

    APPL2 à Organizational Data

    USER, USER1

    Following are the delivery classes:

    Aà Application table

    Cà Customer table

    L,G,E,S,W

     

     

  • Difference between Domain and Data Element

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

    Introduction

    Before jumping to the difference between a Domain and Data Element, let’s have a short introduction of the two. We need to use data in ABAP reports and it needs to be define in ABAP Dictionary and for that we need to define Domain, Data Element and, Tables.

     

    Domain

    A domain is a reusable object which describes the technical characteristics of an attribute. It defines a value range, which sets the permissible data values for the fields, data types, conversion routine, etc. A single domain can be used for any number of fields of identical structure.

    With the help of domain, lowercase letters can be entered into the table fields.

     

    Data Element

    A domain cannot be directly used in a Report/Program or as a table field, it is assigned to a data element that adds some semantic information to the field i.e. Field Label, heading, etc.

    Data Element is the smallest individual component of the complex types and is used to provide field labels, documentation, parameter ID, and search help for the table field.

     

    At Domain level, Search Help fetches data either from defined fixed value or Value Table while Search help assigned to Data Element fetches data from Global Search help created via SE11.

     

    Difference between Domain and Data Element

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

    Domain Data Element
    It is used to describe the technical characteristics of an attribute. It is used to describe the semantic definition of the table field.
    It describes the value range, data types, and conversion routine. It provides field labels, documentation, parameter ID, and search help for the table field.
    Search help assigned to it fetches data from either fixed value or Value Help Table. Search help assigned to it fetches data from Global Search help created via SE11.
    It is assigned to a data element. It is assigned to a table field or structure.
    It cannot be referenced in ABAP programs. It can be referenced in ABAP programs with TYPE.
    It is stored in Standard Table DD01L and Domain texts are stored in DD01T. It is stored in standard Table DD04L and Data Element texts are stored in DD04T.

     

  • Subroutine in SAP ABAP

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

    Introduction

    A good coder always tries to reduce repetitive codes and implements codes in such way that it can be reused. Subroutine in SAP ABAP provides us the same functionality. In this article we will learn what it is and how to implement it in SAP ABAP.

    What are Sub Routine

    A Subroutine in SAP ABAP is a well-defined reusable procedures used for code modularisation. Subroutines can be used locally in a program.

    It is written between FORM and ENDFORM.

    PERFORM subroutine is used to invoke subroutine.

    Passing values with Subroutines

    There are 2 ways to pass values with subroutines:

    Pass By Value

    • In this the actual and formal parameter refers to different memory.
    • IF the value of formal parameter is changed then the value of actual parameter won’t change.
    • Keyword VALUE identifies that the parameter is passed by value.

    Pass by Reference

    • In this the actual and formal parameters refer to same memory.
    • If the formal parameter is changed, actual parameter also changes.

    Types of Subroutines

    Internal Subroutines

    Subroutines that are defined in the same program and called within the same program.

    External Subroutines

    Subroutines that are defined in a program and are called in a different program are called as external subroutines.

    How to create a are Sub Routine Module in SAP

    1. Go to SE80
    2. Select your program for which you want to create a subroutine -> select -> create a subroutine (name it).
    3. Write a code in FORM and ENFORM and if u want to call it as an internal subroutine then PERFORM has to be included.

    Calling a Subroutine

    Internal Subroutines

    REPORT PROGRAM NAME.

    PERFORM SUBROUTINE NAME.

    FORM SUBROUTINE NAME.

    P1 TEXT

    FORM SUBROUTINE NAME.

    Write:  ‘This is internal subroutine’.

    ENDFORM.

    External Subroutines

    FORM FORMNAME.

    Select *from MARA into table it_mara where matnr is s_matnr.

    ENDFORM.

    To call this form in a program.

    PERFORM subroutine_name IN PROGRAM program_name.

    Advantages of Sub Routine

    • Pass by value allocates new memory location for use in subroutines
    • Pass by reference passes a pointer to a memory location.

     

  • Message Class in SAP ABAP (SE91): Create & Use Examples

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

    Introduction

    To issue a message or warning or error or any kind of information in ABAP, either we have to hard code that message or maintain it in text symbols. What if the same message is required somewhere else like in any other program or class, again hard coding it or maintaining in text symbol would be recurring and inefficient procedure.

    Instead of doing this, we can collect all the messages at one place and use it multiple times and at multiple places, that one place is nothing but a message class. Any message can be identified with a unique number assigned to it. To use a message from message class in any ABAP program or in any class, we only need to specify the message class, message number and message type.

    Definition

    Message Class is like a container which contains all messages in it. All the messages from different message classes are stored in database table T100.

    Message Class Creation

    A message class can be created in two ways:

    1. Through transaction code SE91.

     

    Message class creation through T-Code SE91
    Message class creation through T-Code SE91

     

    Message class Maintenance Screen
    Message class Maintenance Screen
    • Syntax of calling these messages from message class in ABAP Programs:

            MESSAGE <type of message><message number>(message class name) WITH <parameter>.

    Example 1 : MESSAGE I000(ZTEST_CLASS).                                                     “Information Message

    Example 2 : MESSAGE E0001(ZTEST_CLASS) WITH 0001.                                     “Error Message

    Note: In figure 2, message text at 001 position is having ‘&’. With this operator we can pass text/literals whatever we want to display. So, for example 2 message will get displayed as:

     ‘The value 0001 is invalid’.

    1. Through report.

    Syntax : REPORT <Report Name> message-id <Message Class>

    “Double click on message class name to create a message class.

    Advantages

    A single message can be used multiple times at multiple places, we don’t need to hard code same message or maintain the same text symbols in different programs.

  • What is SAP OData

    Preface – This post is part of the SAP ABAP OData Tutorial series.

    Introduction

    If you plan to expose your SAP Data (Table or Query Data) to external environment like UI5/Fiori or HANA, then you need to push your data in a form of API. By API we mean, using OData we will generate a service link that can be accessed via internet and can be used to perform CRUD operations. SAP OData in SAP ABAP environment is just like another ABAP Class. We can access the methods of this class using SEGW transaction. We can write our required code here for the data manipulation and once we activate the class, the service link that we generate will act accordingly.

    Definition

    SAP OData is a standard Web protocol used for querying and updating data present in SAP using ABAP, applying and building on Web technologies such as HTTP to provide access to information from a variety of external applications, platforms and devices.

    In SAP, we use SEGW transaction code to create an OData Service. SEGW stands for Service Gateway.

    Architecture of SAP OData

    Here, we will discuss about the High level architecture of SAP OData.

    SAP OData High Level Architecture
    SAP OData High Level Architecture

    Why we need ODATA

    SAP OData comes with multiple advantages. It not only helps us to expose data but also helps a customer to access data from anywhere and any device. If there will be no OData services, then the data will remain on premise and in case a user needs to access their data, they might have to visit the data location, which is uncomfortable for the digital world.

    Advantages of an ODATA

    Using SAP OData provides us following advantages:

    • It helps to obtain human readable results i.e. you can use your browser to see the output data
    • It is very easy and relatively fast to access data
    • It uses all the standards of web protocols i.e. GET, PUT, POST, DELETE, and QUERY
    • It uses Stateless Applications: It means Server does not save any data of Client (e.g. UI5 Application) and treats every OData call as a new call
    • It receives data in form of related pieces of information, one leading to another: It is an interaction pattern known as “alert-analyse-act”, “view-inspect-act”, or “explore & act”. According to this pattern not all data are loaded together, and a user analyses a data and reaches its required information after navigation. In this way the data loads quickly and correctly.

    SAP OData V2 (Version 2)

    OData v2 is a set of new standards which are add-ons to SAP OData V1, and these are as follows:

    • Client-side sorting and filtering
    • All requests can be batched
    • All data is cached in the model
    • Automatic Message handling

    You can read more about SAP OData v2 vs OData v1 here.

    SAP OData V4 (Version 4)

    OData v4 is the latest upgradation to the SAP OData services which comes with some addition and some reduction of features, such as:

    • The new version brings simplification in terms of data binding. The new OData V4 model simplifies the data binding parameter structure.
    • OData v4 requires only asynchronous data retrieval.
    • The Batch groups are solely defined via binding parameters in the new OData v4 calls with the corresponding parameters on the model as default.
    • It supports use of an operation binding. And now it is much easier to bind operation execution results to controls.
    • Create, Read, Update and Delete (Remove) operations are available implicitly via the bindings
    • In OData v4, the Metadata is only accessed via ODataMetaModel

    You can read more about SAP OData v4 vs OData v2 here.

  • SAP Package

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

    INTRODUCTION

    A development class (container) to store different development objects together that are developed by a developer. Earlier anyone could use any developed object because everything was stored in a flat structure. In order to set up protection for developers’ development object package concept was introduced. In order to address technical modularization in large scales for developed objects SAP Package concept was introduced.

    SAP PACKAGE BUILDER CONCEPT

    • Packages are a further development of the current development classes with added semantics.
    • They are designed to help developers encapsulate, modularize, decouple units in the SAP System.
    • They extend the concept of development classes with added attributes as nesting, interfaces, visibility and use accesses.

    SAP PACKAGE BUILDER

    1. It helps to implement the concept of packages in ABAP Workbench.
    2. It can be called using transaction SE21 or SPACKAGE.

    Features of SAP PACKAGE BUILDER

    1. It helps to create packages and sub packages.
    2. It can specify a package hierarchy.
    3. Define package interface for users.

    HOW TO CREATE A PACKAGE IN SAP.

    1. Enter the package name -> create.

    SAP Package Builder

    2. Package is either created or you can display a created one.

    SAP Package Creation

    3. It has certain attributes.

    1. Package Interfaces:
    • In order to make package content visible.
    • Only those package element that are added in the interface are visible.
    • Package make their services available to other package using the package interface.

    SAP Package Interface

         2. Sub Packages

    • It holds an attribute of packages ‘Nesting’.
    • A package can be created /or an existing package can be added.

    SAP Sub Package

         3. Package Hierarchy

    • The main focus is to provide a structure for packages.
    • Sub packages can be inserted inside main package.
    • This shows the depth to which they are nested.

    HOW TO MOVE OBJECTS FROM ONE PACKAGE TO ANOTHER.

    Go to SE80 -> Give the program name -> Right click-> Additional functions -> Change package assignment.

    SAP Package Assignment

    After giving the new package name -> ok.

    Assign Object to a Package

    SAP PACKAGE TABLES

    TDEVC

    SAP PACKAGE TABLES

  • Table Maintenance Generator in SAP ABAP

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

    Introduction

    In SAP ABAP Tables, it is sometime required to maintain a table (Create, update, edit or delete a record) manually. In this case, Table Maintenance Generator helps us to achieve the same. In this article, we will explore Table Maintenance Generator and will also learn the events associated with it.

    Definition

    • A tool used to tailor the tables created by end users.
    • End user do not have access to SE11 or SE11 T-Codes in production system so by using the generator they can customize the tables.
    • The end users can create, delete and modify entries.
    • After every changes done, user must go to SM30 T-code and by passing view/table name, select the maintain button to get the changes reflected.

    Prerequisite

    When we create a table in SE11 ABAP Dictionary, some features need to be activated.

    1. Delivery class
    • Delivery class are used for controlling data transport of tables for installation, upgrade, and client copy, and for transporting between customer systems.
    • The delivery class is also used in extended table maintenance.

    TMG Delivery Class

     

    • It helps in filling seven entries.

     Delivery Class Entries

     

    1. Data Browser/Table View Maint.
      This tab states whether data can be displayed or maintain a database table or view using the tools Data Browser T-code SE16 and Table View Maintenance T-codes SM30 and SM31.

    It has 3 features:-

    • Display/Maintenance allowed – A user can view in data browser as well as make changes in the data browser and also maintain and display in SM30 and generate table maintenance dialog in SE54.
    • Display/Maintenance allowed with restrictions – A user can view and make changes but with some restrictions.
    • Display/Maintenance not allowed – A user can neither view in data browser (SE16) nor maintain.

    Table View Maint

    How to Create a Table Maintenance Generator

    • Go to SE11 (ABAP Dictionary) => pass the table name => change => utilities => table maintenance generator => Generate table maintenance dialog: Generation Environment.

    Generate table maintenance dialog

    • Pass the Authorization Group name, if there is no specific group of people then assign it to &NC& (without authorization group). In total 759 groups can be assigned.
    • Authorization object – Element of the authorization system. Authorization objects allow complex checks linked to several conditions of an authorization which allows a user to carry out an action.
    • Function Group – Pass the name where generated maintenance modules can be stored. It can be same as the table name.
    • Maintenance Screens
      • Maintenance type
        • Select the maintenance type and click on find screen numbers on the tool bar=> propose screen numbers => Screen number gets populated => Create a button on the application toolbar => Assign TMG and function group to the proper package and click OK.
        • A pop up appears (Request completed without errors).
        • Table maintenance generator is created with this message in the status bar.
    • Description of maintenance types
      • One step maintenance, one screen that is overview screen is displayed in which the entries are displayed in the form of lists.
      • It is processed at run time.
      • Entries should be displayed in one line of the screen.
      • Two step maintenance, an additional screen (single screen) is processed at run time.
      • The single screen can be called from the overview screen by function key for every entry.

    How to Use a Table Maintenance Generator

    Follow the given steps to use a Table Maintenance Generator:

    1. Go to SM30

    Table Maintenance Generator

    1. Pass the name of the table => Maintain (click) => the overview screen appears.

    TMG New Entries

    1. Click on NEW entries => add new entries and save (this is a part of another screen).

    As mentioned, only one record at a time is allowed to enter, since it is user friendly.

    1. If we do any changes in the table, then we need to re -adjust, re-create TMG.

    Events of a Table Maintenance Generator

    Follow given steps to create Events in ABAP TMG

    1. SE11 => Change => TMG => Environment => Events

    TMG Events

    1. After selection of type of event => Editor => Write the code between FORM/ENDFORM.

    TMG Event Form

    1. List of available events:

    TMG Event List 1 TMG Event List 2

     

  • What are Restful Web Services

    Preface – This post is part of the SAP ABAP OData Tutorial series.

    Introduction

    In our previous article we have discussed what is an API. There are different types of API calls e.g. Simple Object Access Protocol (SOAP), Remote Procedure Call (RPC) and Representational State Transfer (REST). All these API calls have same purpose i.e. to transfer data securely among two or more systems. In this article we will only explore the Restful Web Services.

    What is REST

    As stated earlier, REST stands for Representational State Transfer. It is a simple way of sending and receiving data between client and server. It doesn’t require any software or standards to transfer data. It has a predefined structure to do the API call. Developers just need to use the predefined way and pass their data as JSON payload.

    Restful Web Services

    Attributes of Restful Web Services

    A RESTful web service has following six constraints/attributes:

    1. Client-Server: It is a very important aspect of REST APIs. A REST API follows client-server architecture and these both should be separate. It means both the server and client can not be same server. In case it is same, you will receive CORS error.
    2. Stateless: In REST, all calls are treated as a new call and any previous call state will not give any advantage to the new call. Hence during each call, it is required to maintain all the necessary authentication and other information.
    3. Cache: A REST API encourages the browser and server caching process to enhance its processing speed.
    4. Uniform Interface: The interface between the Client and Server remains uniform, hence any changes in either side will not affect the API functionality. This help in development of Client and Server system independently.
    5. Layered System: REST allows usage of layered structure in server side i.e. you can have data on different server, authentication on different server while the API on different server. The client will never come to know that it is getting the data from which server.
    6. Code on Demand: It is an optional feature of REST API where server can even send executable code to the client that can run directly during run time.

    Methods in Restful Web Services

    Using Restful web services, we can perform these basic four operations:

    1. GET: This method is used to get a list of data from server.
    2. POST: This method is used to post/create a new record in server.
    3. PUT: This method is used to update an existing record of server.
    4. DELETE: This method is used to perform deletion of a record at server side.

    Note: Just calling the above method doesn’t guarantee that the operations will be performed until these operations are implemented at the server side too.

    Advantages of Restful Web Services

    Following are the major advantages of a RESTful API:

    • They are simpler and flexible to implement
    • It supports greater variety of data formats e.g. JSON, XML, YAML, etc.
    • It is faster and provides better performance

    Disadvantages of Restful Web Services

    Although REST services tend to provide multiple benefits, still it has given demerits:

    • To implement state related query the REST Headers are required which is a clumsy work
    • The PUT and DELETE operations are not usable through firewalls or in some browsers.