Category: SAP

  • How to make ABAP Calculator Program

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

    Introduction

    ABAP calculator program is just like any simple calculator which performs operation like addition, subtraction, multiplication and division.

    A Calculator in ABAP is just like any simple calculator which performs operation like addition, subtraction, multiplication and division. To perform these operation we will take two inputs from user using PARAMETERS keyword and the operation in form of Push Button/RADIO Button.

    Here in given program we have used Push Button to get the operation from user.

    PARAMETERS : p_inp1 TYPE int2,
                 p_inp2 TYPE int2.
    DATA: lv_out  TYPE int2,
          lv_sign TYPE c,
          flag    TYPE int1 VALUE 0.
    SELECTION-SCREEN :BEGIN OF SCREEN 500 TITLE TEXT-001,  "Where we create a screen with number 500
                      PUSHBUTTON /10(10) add  USER-COMMAND add,
                      PUSHBUTTON 25(10) sub USER-COMMAND sub,
                      PUSHBUTTON 40(10) mul USER-COMMAND multiply,
                      PUSHBUTTON 55(10) div USER-COMMAND divide,
    END OF SCREEN 500.
    INITIALIZATION. " Where we Initialize the value of our buttons we created above
      add = 'Add'.
      sub = 'Subtract'.
      mul = 'Multiply'.
      div = 'Division'.
    AT SELECTION-SCREEN. "Where we do calculation
      CASE sy-ucomm.
        WHEN 'ADD'.
          flag = 1.
          lv_out = p_inp1 + p_inp2.
        WHEN 'SUB'.
          flag = 1.
          lv_out = p_inp1 - p_inp2.
        WHEN 'DIVIDE'.
          IF ( p_inp2 <> 0 ).
            flag = 1.
            lv_out = p_inp1 / p_inp2.
          ELSE.
            flag = 2.
          ENDIF.
        WHEN 'MULTIPLY'.
          flag = 1.
          lv_out = p_inp1 * p_inp2.
      ENDCASE.
    START-OF-SELECTION. " Where we show output
      IF p_inp1 IS NOT INITIAL OR p_inp2 IS NOT INITIAL.
        CALL SELECTION-SCREEN '500' STARTING AT 10 10. "Where we call the Screen 500 we created earlier.
        IF flag = 1.
          WRITE: lv_out.
        ELSEIF flag = 2.
          WRITE: 'Cannot Divide a number by 0'.
        ELSEIF flag = 0.
          MESSAGE 'Press any Button to perform any operation!' TYPE 'I'.
        ENDIF.
      ELSE.
        MESSAGE 'Please give both Input to proceed!' TYPE 'I'.
      ENDIF.
    

    Line by Line Explanation of Code

    Line 1: Parameter declaration of type integer

    Line 2: Parameter declaration of type integer

    Line 3: Data declaration of type integer

    Line 4: Data declaration of type character

    Line 5: Data Declaration for Flag of type integer and value 0

    Line 6: Selection Screen Statement and creation of Screen 500

    Line 7: Creation of Push Button ‘add’ with User Command ‘create’ [User Command is used to call the button]

    Line 8: Creation of Push Button ‘sub’ with User Command ‘sub’ [User Command is used to call the button]

    Line 9: Creation of Push Button ‘mul’ with User Command ‘multiply’ [User Command is used to call the button]

    Line 10: Creation of Push Button ‘div’ with User Command ‘divide’ [User Command is used to call the button]

    Line 11: End of Selection Screen made at Line 6

    Line 12: INITIALIZATION Event [It is a predefined event of ABAP Reports]

    Line 13:  Naming the button add as ‘Add’

    Line 14: Naming the button sub as ‘Subtract’

    Line 15: Naming the button mul as ‘Multiply’

    Line 16: Naming the button div as ‘Division’

    Line 17: AT SELECTION-SCREEN Event [It is a predefined event of ABAP Reports]

    Line 18: Create of Case statement where the user input will be taken via System Variable sy-ucomm and will be the condition for further statement.

    Line 19: When user clicked button ‘ADD’ that we created in Line 7, then proceed to next statement else jump to next When condition.

    Line 22: When user clicked button ‘SUB’ that we created in Line 8, then proceed to next statement else jump to next When condition.

    Line 25: When user clicked button ‘DIVIDE’ that we created in Line 9, then proceed to next statement else jump to next When condition.

    Line 32: When user clicked button ‘MULTIPLY’ that we created in Line 10, then proceed to next statement else jump to next When condition.

    In above condition, we have then written simple mathematical statements to perform respective operations.

    That’s it, we have successfully written code for ABAP Calculator Program.

    Tutorial Video

    You can watch the below video to learn implementation:

    [embedyt] https://www.youtube.com/watch?v=mrb3SFhhWj4[/embedyt]
  • Check Prime Number or Not in ABAP Program

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

    In this program you need to take input from user using PARAMETERS and find whether it is Prime or not. The number which is divisible only by 1 or by itself is called Prime number while the number which is divisible by any other number also apart from 1 and itself is not a Prime number.
    In the program(Prime Number Program in ABAP) given below we will find whether the number entered is Prime or not.

    PARAMETERS p_num TYPE int2.
    DATA: lv_check  TYPE int2 VALUE 2,
          lv_flag   TYPE int1 VALUE 0,
          lv_length TYPE c.
    IF p_num EQ 1.
      MESSAGE '1 is neither Prime nor Composite' TYPE 'I'.
    ELSEIF p_num IS INITIAL.
      MESSAGE 'Input cannot be empty or 0' TYPE 'I'.
    ELSE.
      WHILE lv_check <= p_num / 2 .
        IF ( p_num MOD lv_check ) EQ 0.
          lv_flag = 1.
          EXIT.
        ENDIF.
        lv_check = lv_check + 1.
      ENDWHILE.
      IF lv_flag EQ 0.
        WRITE 'Prime'.
      ELSE.
        WRITE 'Not Prime : Composite'.
      ENDIF.
    ENDIF.
    

    Explanation:

    Line 01: Here, we define a parameter to take an input from user, the input will be always a number.

    Line 02: Here we will define some fields that will be utilized in the program later. lv_check will be used to check if the number is divisible by any number which is less than or equal to its half or not, lv_flag will be used to set flag 0 or 1. Flag = 0 will mean, number is prime and 1 will mean, number is not prime. lv_length will be used to check the length of the number.

    Line 03: Here we will check if the number is one or not.

    Line 04: If the number was one in above step, we will give informative message popup “1 is neither Prime nor Composite”.

    Line 05: Here we will check if the number is initial or not.

    Line 06: If the number was initial in above step, we will give informative message popup “Input cannot be empty or 0”.

    Line 07: If all the above condition will fail, then we will execute the later lines.

    Line 08: Here we have added a while condition which will run until lv_check is less than or equal to the half of the entered number. It is checked, because a prime number must not be divisible to any number apart of itself and 1. To check that we divide it by all the number that is equal to or less than its half. And why half, it is because no number is divisible by a number greater than its half. E.g. 10 can never be divided by 6 i.e. greater than its half i.e. 5.

    Line 09: Here we check if the number is divisible by lv_check or not. For every number, we divide it from 2 to its half with the help of lv_check. If it divides the number, then we set the flag 1 else the flag remains 0. After every check we increment the value of lv_check until it is equal to half of the entered number.

    Line 10 and later: We have later checked if the flag is 0 or 1. And, if the flag remained 0, we show in output ‘Prime’ else ‘Not Prime : Composite’.

    That’s it, in this way we have written successfully Prime Number Program in ABAP,

  • Check Even or Odd in ABAP Program

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

    To check even or odd in ABAP Program, you need to take input from user using PARAMETERS and divide it by 2. The number which when divided by 2 gives remainder zero is called Even number while the number which gives remainder one is called odd number.
    To get remainder in ABAP we use mod keyword. In the program given below we will find whether the number entered is Odd or Even .

    PARAMETERS: p_num TYPE int2.
    IF p_num IS INITIAL.
      MESSAGE 'Input cannot be empty' TYPE 'I'.
    ELSEIF p_num MOD 2 EQ 0.
      WRITE 'EVEN'.
    ELSEIF  p_num MOD 2 <> 0.
      WRITE 'ODD'.
    ENDIF.
    

    Explanation:

    Line 01: Here we have defined a parameter p_num to take input. The type of input will always be a number.

    Line 02: If the input provided by user is initial, then in Line 03 we will pop up an information message saying “Input cannot be empty”.

    Line 04: If the number provided by user is not initial and is divisible by 2, then we will give output as “Even” in Line 05.

    Line 06: If the number provided by user is not initial and is not divisible by 2, then we will give output as “Odd” in Line 07.

    That’s it, we have successfully written code to check if a given number is even or odd in ABAP Program.

  • Search Help in SAP ABAP

    Search Help in SAP ABAP

    Before we learn Search Help in SAP ABAP, let us see a daily life example first.

    In Windows PC, when you click Search Help in SAP ABAP windows_logo_image, a set of fixed options appear in front of you.

    This is something that is created to help you and you can search for the apps that you want to open. These apps are limited and are predefined and you can select only the one that is visible to you. In this way windows restrict you to select only valid apps. SAP provides similar scenario of data/record selection from a predefined fixed value. These values are created using Search Help in SE11.

    Definition

    Search Help in SAP ABAP are reusable objects that are used to assign input helps (F4 helps) to screen fields.

    This becomes mandatory when input is a formal key (In case data depends upon data of another table e.g. Registration of Employees in an event on basis of his employee ID).

    How a Search Help Works?

    We will update it soon.

    Types of Search Help in SAP ABAP

    These are the following two types of Search Helps:

    Type Description
    Elementary search helps It reads records from table, structure or view on the basis of a condition and returns those records which are displayed by a dialog box.
    Collective search helps It combines multiple Elementary search helps to provide records.

     

    Advantages of Search Helps

    • Search Help is a reusable component
    • It helps to avoid wrong input to the dependent table. It means a table whose records are dependent upon data of another table; any record added in that table which is not present in dependent table will not be legit.
  • PARAMETERS in SAP ABAP: Types, Syntax & Examples

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

    Parameters in SAP ABAP Report

    Have you ever worked on HTML tags where we use <INPUT> tag to get single input OR C/C++ tag where we use SCANF/CIN statement to take single input. Just like that, in ABAP PARAMETERS are used to take single input.

    Definition

    PARAMETERS are ABAP statements which are used to declare input ABAP variables in ABAP Programs/Report, variables are just like DATA statements. For every PARAMETER variable declared, an input box becomes visible on selection screen.

    Syntax

    PARAMETERS   <NAME OF YOUR PARAMETER>  [ TYPE/LIKE ]   <DATA ELEMENT/ABAP PREDEFINED DATA TYPE/REFERENCE to ABAP Table, Structure or View Field>

    Examples

    Case 01: TYPE/LIKE to DATA ELEMENT.

    PARAMETERS   P_BARRY TYPE ZBARRY_NAME.      //Here P_BARRY is a Parameter with property same as ZBARRY_NAME which is a Data Element.
    
    PARAMETERS   P_ALLEN LIKE P_BARRY.      //Here P_ALLEN is a Parameter with Property same as Parameter P_BARRY i.e. ZBARRY_NAME.

     

     

    Case 02: TYPE/LIKE to ABAP PREDEFINED DATA TYPE.

    PARAMETERS   P_BARRY(10)    TYPE C.     //Here P_BARRY is a Parameter with property of a character and length 10.
    
    PARAMETERS   P_ALLEN LIKE P_BARRY.      //Here P_ALLEN is a Parameter with Property same as Parameter P_BARRY i.e. character and length 10.

     

     

    Case 03:  REFERENCE to ABAP Table, Structure or View Field.

    DATA    CARR_ID(40) TYPE c.
    
    CARR_ID =  ‘SFLIGHT-CARRID’.
    
    PARAMETERS  P_BARRY LIKE (CARR_ID).

     

     

    *NOTE: In the above statement, the PARAMETER is just like field CARRID of table SFLIGHT. It will have all the properties (length, data type, decimal places, etc) and search help of that field.

    DEFAULT Values of a PARAMETER

    Syntax:

    PARAMETERS    <NAME OF YOUR PARAMETER>    [TYPE/LIKE]   <DATA ELEMENT/ ABAP DATA TYPES/ DDIC Field>    DEFAULT  <YOUR DEFAULT VALUE>.

     

    Example:

    PARAMETERS   P_NAME(20)    TYPE    C     DEFAULT    ‘BARRY ALLEN’.

     

    Setting PARAMETER value from Memory

    We can store values in SAP Memory. To learn more about Memories click here.

    From these memories we can get the values and set it as default in PARAMETER.

    Have you ever wondered that after viewing your table name when you come back again to SE11, its name still appears? This is possible because every time we open anything in SE11, the value of Parameter is set into memory and when we revisit the DDIC/SE11, it get the Parameter value back from memory. Let us see how we can do it too in our program.

     

    To Set PARAMETER value in SAP Memory:

    SET PARAMETER ID <NAME OF YOUR Memory ID>  FIELD  <Name of the field whose value will be saved>.

     

    Example:

    SET PARAMETER ID  pid_barry   FIELD  lv_barry.

     

     

    To Get PARAMETER value from SAP Memory:

    GET PARAMETER ID <NAME OF YOUR Memory ID>  FIELD  <Name of the field which will get the value>.

     

    Example:

    GET PARAMETER ID  pid_barry   FIELD  lv_barry.

     

     

    To Give Default value to Parameter from SAP Memory:

    PARAMETERS    <Name of your parameter>  [TYPE/LIKE]   <DATA TYPE/DATA ELEMENT/DDIC REFERENCE>  MEMORY ID <NAME OF YOUR Memory ID>  .

     

    Example:

    PARAMETER   P_NAME(20)   TYPE    C    MEMORY ID   pid_barry  .

     

    *NOTE: IF any of the above operation fails, SY-SUBRC becomes 4.

    Allow PARAMETER to Accept LOWER and Upper Case

    The default value of Parameter is upper case that means all input changes to upper case. You can allow lower cases using given syntax.

    Syntax:  PARAMETERS    <Name of your parameter>  [TYPE/LIKE]   <DATA TYPE/DATA ELEMENT/DDIC REFERENCE>  LOWER CASE.

    Example:

    PARAMETER   P_NAME(20)   TYPE    C    LOWER CASE  .

     

     

    Reduce Visible Length

    You can allow as many lengths of Parameter you want and also restrict the length visible to the end user using given syntax.

    Syntax:  PARAMETERS    <Name of your parameter>  [TYPE/LIKE]   <DATA TYPE/DATA ELEMENT/DDIC REFERENCE>  VISIBLE LENGTH <Your Length>.

    Example:

    PARAMETER   P_NAME(20)   TYPE    C    VISIBLE LENGTH 5  .

     

     

    Define Required/Mandatory/Obligatory Field

    Suppose you want an input the will be saved in the table as a Primary key, it means it is a required field and it cannot be left blank. To tell user that it is mandatory to fill some values in this field you will use given syntax.

    Syntax:  PARAMETERS    <Name of your parameter>  [TYPE/LIKE]   <DATA TYPE/DATA ELEMENT/DDIC REFERENCE>  OBLIGATORY.

    Example:

    PARAMETER   P_NAME(20)   TYPE    C    OBLIGATORY.

     

     

    Attach Search Help to Parameters

    Search Help were earlier called Match Code Objects in SAP ABAP. To know more about Search Help Click Here.

    A search help provides the possible values for a given parameter. To attach a search help to a parameter use the syntax given below:

    Syntax:  PARAMETERS    <Name of your parameter>  [TYPE/LIKE]   <DATA TYPE/DATA ELEMENT/DDIC REFERENCE>  MATCHCODE OBJECT <Name of your Search Help>.

    Example:

    PARAMETER   P_NAME(20)   TYPE    C     MATCHCODE OBJECT     ZBARRY_SHELP.

     

     

    Check Parameter Input against Check Table or Fixed Value

    If you want a Parameter to have input only that value that is present in the Check Table. Then you need to do three things:

    1. Make the Parameter Obligatory: The Empty value will not be in check table and hence it will be a required field.
    2. DATA TYPE will be a field from table having Check-Value Relationship.
    3. Attach a Check: A Check will ensure the presence of valid value.

    Syntax:  PARAMETERS    <Name of your parameter>  [TYPE/LIKE]   < DDIC REFERENCE>  OBLIGATORY VALUE CHECK.

    Example:

    PARAMETER   P_CARRID     TYPE    SFLIGHT-CARRID     OBLIGATORY VALUE CHECK.

     

    The check will compare data with check table; if not present will throw an error.

     

    Define Checkbox

    A Parameter can be a simple field as well as a checkbox with given syntax.

    Syntax:

    PARAMETERS    <Name of your parameter>  AS   CHECKBOX.

    Example:

     PARAMETER:   P_CHECK1     AS   CHECKBOX   .
    
    P_CHECK2     AS   CHECKBOX    DEFAULT   ‘X’  .

     

    Here P_CHECK2 has default value ‘X’ which means it is checked.

     

    Define Radio Button

    A Parameter can be a simple field, a checkbox and even a radio button.

    Syntax:  PARAMETERS    <Name of your parameter>    RADIOBUTTON GROUP     <Name of Radio button Group> .

    Example:

    PARAMETER:   P_rad1     RADIOBUTTON GROUP      rad1       DEFAULT   ‘X’  ,
    
    P_rad2     RADIOBUTTON GROUP    rad1 ,
    
    P_rad3     RADIOBUTTON GROUP    rad1 .

     

    The radio buttons comes under a group with one of them as a default value. A radio button group here can have maximum length four. If you do not assign the default value, the first radio button is assigned automatically. Here ‘X’ means radio button is pressed.

     

    Modify Input Fields

    To modify appearance of a field or a Parameter, we assign it a MODIF ID whose length can be maximum 3 characters. Now these fields will behave as a single group. And using Modify Screen statements we can modify their appearance on screen.

    SYNTAX: PARAMETERS   <Name of your parameter>    [TYPE/LIKE]    <DATA TYPE/DATA ELEMENT/DDIC REFERENCE>    MODIF ID    <Name of your MODIF ID>.

    Example:

    PARAMETERS:   P_First_name(20)    TYPE    C   MODIF ID    md1,
    
    P_Last_name(20)    TYPE    C   MODIF ID    md1.

     

     

    Hide a Parameter

    Sometimes you need a parameter but you don’t need to display it. In such case you can pass default value, or a value via INITIALIZATION, or via another Program.

    SYNTAX: PARAMETERS   <Name of your parameter>  [TYPE/LIKE]    <DATA TYPE/DATA ELEMENT/DDIC REFERENCE>  NO-DISPLAY.

  • Lock Objects in SAP ABAP

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

    Lock Objects in SAP ABAP

    Let us understand Lock Objects in SAP ABAP from a real life scenario. Have you ever booked a seat in a bus or a seat for movie online? If yes, you might have faced a situation where you were doing the booking and the seat got locked, it means the seat will be locked permanently on your name if you pay for it or will be unlocked after certain time period if you denied payment. This is an example of table lock, where the same seat cannot be booked by two different people. This feature in SAP ABAP is called Lock Objects.

    Below is the online portal of Movie tickets seat selection page.

    Lock Objects in SAP ABAP-Movie Hall Lock Seat

    Here the red seats are the permanently locked seat; green seats are the one which is locked temporarily. Lock objects locks a table temporarily till the operation is performed on the table.

    Definition

    Lock Objects in SAP ABAP are global reusable component which generates function modules that are used to set and release locks on data record. This lock mechanism is important to synchronize access of same data record by multiple programs/users.

    Function Modules Generated by Lock Objects

    1. ENQUEUE_<lock object name>: It sets the lock.
    2. (DEQUEUE_<lock object name>: It releases the lock.

    *NOTE: These FMs are automatically assigned to a Function Group; these FMs are generated every time, when you activate the locks. While transporting these locks, do not transfer either FMs or Function Group, just transfer the lock object.

    Creation of Lock Objects in SAP ABAP:

    Step 01: Open SE11.

    Step 02: Click Lock Objects Radio Button from the given radio buttons.  Give your Lock Objects name starting with EZ or EY e.g. “EZBarry_lock”.

    Note: The name of your lock object must begin with E. Here E defines Enqueue.

    Step 03: Click Create, Enter explanatory description for Lock Objects in Short Description e.g. “Lock Objects for Test”.

    Step 04: In the Attributes section, you can maintain the following:

    Field Value Description
    Package Your Package name Enter your package name, in this way all the FMs and FG will be also transferred here.
    Allow RFC Checked/ Unchecked If you Allow RFC, the generated FMs can be called from another system with Remote Function Call.

     

    *Note: If you enable the RFC for an existing Lock, before activating the lock object, you must ensure that the generated FMs that were called by your ABAP Programs are having the appropriate Parameters.

    Step 05: In the Tables section, you can maintain the following:

    Field Value Description
    Primary Table: The table that will be Primarily have the lock.
    Name Name of the table It is the Primary table or the main table which is being locked
    Lock Mode Select one of the option from Drop Down It controls how the lock affects table and how it is passed to the reports/user
    Secondary Table: The table that is linked with Primary table via Foreign keys relationship.
    Name Name of the table It is the table which is linked to Primary table via Foreign relationship.
    Lock Mode Select one of the option from Drop Down It controls how the lock affects table and how it is passed to the reports/user

    Lock Mode: On a single table, multiple users can set their own lock by creating their own Lock Objects, the given lock mode enables one or all of them access over the table at the same time.

    Type of Lock Lock Mode Description
    Shared Lock S ( S hared) It means several users/transactions can access locked data at the same time in display mode : Read lock
    Exclusive Lock E ( E xclusive) It means the user who has locked data, only he can unlock it  : Write lock
    Exclusive but not cumulative lock X (e X clusive non-cumulative) Two or more different lock objects can lock a table simultaneously. Once the Lock is freed by first lock object, it will be locked by second Lock object. In this case, one lock object cannot lock a table more than once simultaneously.
    Optimistic Lock O ( O ptimistic) In case more than one user is using lock for same table, but not all are changing data, it’s not good to leave table locked. An Optimistic Lock changes in to E(Exclusive) mode as soon as the user tries to save the data.

     

    Step 06: In the Lock Parameter section, you can maintain the following:

    Field Value Description
     W Checkbox W stands for Want, you check the parameter you want to be locked
    Lock Parameter  Field Name The field name of the table that appears as Lock Parameter name which is locked, you can change it but not recommended
    Table Table Name The table that is associated with the field name
    Field Field Name The field name of the table that is locked

     

    Step 07: Save it, check for Error and activate your Lock Object.

     

    Advantages of Lock Objects:

    1. It prevents collision of data in same record.
    2. Lock Object prevents multiple editions of same data at same time.
    3. It tells other programs/user that the table is being currently edited.

    *NOTE: There are more topics left in Lock Objects in SAP ABAP like Function Modules of Lock Objects, _SCOPE Parameters, etc that will be discussed in upcoming articles.

    [embedyt] https://www.youtube.com/watch?v=H7R7VycSqF4[/embedyt]
  • Table Type in SAP ABAP

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

    Table Type in SAP ABAP

    Before discussing Table Type in SAP ABAP, it will be good to understand Internal Tables first.

    An Internal table is a runtime object which holds runtime data in form of table. Its data type is specified by its line type, key and table type. Line type tells the data type of an internal table which can be a structure, a table, an internal table or any data type. Keys are the one which helps to identify each row. Table type specifies how ABAP will access these internal tables i.e. standard table, sorted table & hashed table.

     

    In ABAP Program you can also define Internal Table of type “TABLE TYPE”:

    DATA: ITAB TYPE TTYP.

    Here TTYP stands for Table Type.

    In this particular case you don’t need to take care of any other properties of internal table, it will be taken care by Table Type.

    Definition

    A Table Type in SAP ABAP is a global reusable object which is used to define structure and functional attributes of an internal table in ABAP.

    A table type is defined by:

    • Line Type: It defines the structure and data type
    • Access Mode: kind of internal table e.g. Sorted, Hashed, Indexed
    • Keys: Primary & Secondary keys of the table

    Creation of Table Type in SAP ABAP:

    #Using ABAP Dictionary

    Step 01: Open SE11.

    Step 02: Click Data Type Radio Button and select Table Type radio button from the given radio buttons.  Give your Table Type name starting with Z or Y e.g. “ZBarry_ttype”.

    Step 03: Click Create, Enter explanatory description for table type in Short Description e.g. “Table Type for Test”.

    Step 04:  On Line Type tab, maintain one of the following:

     

    Fields Value Description
    Line Type Enter name of any of the following:

    A data element, a structure, a table, a view or even a table type

    Table Type will create a structure similar to this line type.
    Predefined Type Enter Data Type, Field Length & decimal places Length Type can be any predefined data types with any length of field and decimal places. It is similar to the creation of Data Elements.
    Reference Type Enter either name of a class, an interface, a generic reference to ANY, OBJECT, or DATA or a reference to a type defined in the Dictionary. Reference type creates a pointer to data object

     

     

    Step 05: On the Initialization and Access tab, maintain the following:

    Fields Value Description
    Initial Line Number Enter any numeric value if you know the number of records

    Note: You can leave it empty.

    Just Like OCCURS statement in ABAP Internal Table, here too we can specify the number of Initial lines occupied by the internal table.
    Access: It defines the way Internal table data is accessed while performing the SQL operations on the internal table. Choose one of the following given below:

     

    Access Mode Description
    Standard table It uses linear search to access key.
    Sorted table It is sorted internally on basis of key. It uses binary search to access key.
    Hashed table It is sorted internally on basis of hashed key. The hash key is generated for each key and this key is used to access data irrespective of index. Hashed keys are generated using Hash Algorithm internally.
    Index table In this case the table can be Standard or Sorted. It allows Index access for such table. Index tables are used to define generic parameters of a Subroutine Form & Function Module.
    Not Specified It means table can be any among Standard, Sorted or Hashed. The access of Index is not allowed here.

     

    Step 06: On the Key tab, maintain the following:

    Fields Value Description
    Key Definition: It specifies the Primary key of the table. Select one of the following:
    Standard key It defines the key of Table Type on basis of Line type. The Key contains all the character fields of the table line in case of structure, table or view and It is the entire table line in case of Data Element or Reference type.
    Line type It defines the entire fields of line type as Primary key.
    Key components We can select Primary key from the structure specified by us in Line Type tab earlier. In this case, we need to select the Primary keys.
    Key not specified In this case key is Generic. And the table type is called Generic Table Types.
    Key Category: It tells whether our table type will make an internal table that can store only Unique keys or can have duplicates also.
    Unique It means internal table can have only unique records.
    Non-Unique It means internal table can have duplicate records too.
    Not specified It can be any Unique or Non-Unique. It defines Generic Table Types.
    Key Components If you have chosen Key components in Key Definition tab, than you must click on the button Choose components and choose the required fields.

     

    Note: Here table line means structure of line type.

    Combination of Access Mode and Key category that is allowed:

    Access Mode Key category Description
    Not Specified Not specified It means that if the access mode is the one as mention here, than the key categories must be chosen from this table only.
    Index Table Not specified
    Standard Table Non-Unique
    Sorted Table Unique, Non-Unique or Not specified
    Hashed Table Unique

     

    Step 07: Once all the above fields are maintained, save, check for errors and activate your table type.

     

    Advantages of Table Type in SAP ABAP:

    1. For an Internal table, you might need to create a local structure using types, state its type, and state its other properties. By using table types, we need to just declare the internal table of type Table Types, rest will be taken care by the table types.
    2. Being a global object, it can be reused.

     

    Note: Table Types is a vast topic and it needs one more article to explain the rest of the concepts like Ranges Table Types, etc. We will cover them in next article.

    [embedyt] https://www.youtube.com/watch?v=pTimu6kTgbg[/embedyt]
  • Structure in SAP ABAP

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

    Structure in SAP ABAP

    When you read this word “STRUCTURE”, what is the first thing that comes into your mind?  Is it a structure of a building, a structure of a bridge or a structure of a compound or Structure in SAP ABAP?

    These are what I found in Microsoft Word Clip Arts. From these images it is clear that structure is something that is not the final product or final output but it is something that helps us to get the final output.

    In SAP ABAP or in any other languages, structure is a group of fields grouped under one name. These fields can have different data types and different lengths. These structures can be reused.  These structures can even have a structure as a field called as Nested structure.

     

     

    Definition

    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.

    Structure in SAP ABAP

    Features:

    • A structure is an array of fields.
    • A work area is also a structure which holds single data at runtime and has pre allocated memory in database.
    • When we create a structure using TYPES statement in ABAP report, no memory is allocated in database. It is allocated when we define a work area of type Structure.
    • A Global structure is the one we create using SE11 ABAP Dictionary and a Local Structure is the one we declare in ABAP report using keyword
      TYPES: BEGIN OF XYZ,
      Field1 TYPE c,
      Field2 TYPE c,
      END OF XYZ. 
    • The main purpose of Structure is to define the data at screen interface [e.g. ODATA Interface, ABAP GUI Interface & ABAP Module Pool Interface] and type for Interface Parameters of Classes and Function Modules.
    • A structure can also be included in a table.[only Flat Structures]

     

    Types of Structure in SAP ABAP

    On the basis of type of fields/components of structure, there are three types of Structure:

    1. Flat Structure in SAP ABAP:

    As the name suggests, flat structure are the one that contains fields simply pointing to a Data Element or a predefined data type.

    For example, we have four simple fields as shown below:

    ABAP flat structure

    1.  Nested Structure in SAP ABAP:

    As the name suggests, nested structure are the one that contains at least one field pointing to another structure.

    *NOTE: A structure can be nested to any depths.

    ABAP Nested Structure

    Here we have structure with four fields and the third field is pointing to another structure consisting two fields.

    1. Deep Structure in SAP ABAP:

    Deep structures are the one that contains at least one field pointing to table type. Table Type itself points to a structure or a table. That’s why these are called deep structures.

    ABAP Deep Structure

    In above example we can see that Deep structure has a field pointing to a Table Type and the table type itself is pointing to a structure.

     

    *NOTE: We can include only Flat structures in table.

    Creation of Structure in SAP ABAP:

    #Using ABAP Dictionary

    Step 01: Open SE11.

    Step 02: Click Data Type Radio Button and select Structure radio button from the given radio buttons.  Give your Structure name starting with Z or Y e.g. “ZBarry_struct”.

    Step 03: Click Create, Enter explanatory description for structure in Short Description e.g. “Structure for Test”.

    Step 04: In the components tab, maintain the following:

    Fields Value Description
    Component It can be 16 digit Alphanumeric word starting with a letter and can contain underscore It is the column name of your table
    Key Tick all the fields whose value will be unique and can define the relationship with other tables A structure must contain at least one key field, else it can’t be Activated
    Initial Value Indicator Tick if the field must have an initial value All key fields must always be given initial values. By default all fields are assigned initial values irrespective of indicator.
    Typing Method Choose from the available types: TYPE,LIKE,REF TO It gives you an option to specify whether you are creating a type field, like field or reference field.
    Component Type Select your Data Element or create one If you are not using Predefined Type, you need to provide a Data Element
    Predefined Type : If you are not using Data Element, click the Predefined Type tab & enter following:
    Data Type Any Data type like CHAR,INT According to requirement specify the data type
    Length Give max length of your field Length will be dependent upon Data Type
    Decimal Places Number of places after decimal point Mainly for Float variables
    Short Description Explanatory statement for your field What your field means/doing

     

    Step 05: Under Entry help/check tab maintain the following: It will be maintained automatically after step 04. [You can skip this step]

    FIELDS Value Description
    Field Same as above Same as above
    Data Element Same as above Same as above
    Data Type Same as above Same as above
    Foreign Keys Foreign Keys for that field It will be reflected after you maintain Foreign Key relationships
    Check Table Check Table for Field It will be reflected once you have check table relationship for the field
    Origin of input help Input help with fixed values, with check table, search helps, Static Input Help It reflects the way your input will be made to the given field
    Srch Help Your Search Help name To attach Search Helps to field
    Defaults Any Value depending upon the type of field To assign Default value for the field
    Domain Domain of specified Data Element If your Data Element has a Domain, it will reflect here

     

    Step 06: Under Currency/ Quantity Fields tab maintain the following: [You can skip this step]

    FIELDS Value Description
    Field Same as above Same as above
    Data Element Same as above Same as above
    Data Type Same as above Same as above
    Reference Table Reference Table name If your data element refers to a table
    Reference Field Field of Reference table being Referred It is actually the field being referred by the data element
    Short Description Same as above Same as above

     

    Step 07:  Append Structure from respective tab. [You can skip this step]

    Step 08: Once all the above fields are maintained, save, check for errors and activate your Structure.

     

    [embedyt] https://www.youtube.com/watch?v=xQDp3YjxdXc[/embedyt]
  • Maintenance View in SAP ABAP

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

    Maintenance View in SAP ABAP

    As the name suggest, a Maintenance View in SAP ABAP is a view that is used to maintain data of multiple tables, altogether. The view automatically distributes data to the respective tables connected to it.

    Like Database & Help view, here too we can see data altogether added we can maintain data here.

    If you want a read only view just with inner joins, go with Database View and if you want a view from single table, go with Projection View and if you want a read only view with outer joins, go with Help View. And if you want a view with outer join which you can view as well as edit, then go with Maintenance View.

    Definition

    A Maintenance View in SAP ABAP is a view that combines multiple tables into a single view using outer join and is mainly used to maintain multiple tables altogether.

    *NOTE: The Join Conditions can be only chosen via tab.  Relationship Tab Image

    It means you need to create foreign key relationship in advance. To know how to create a Foreign Key Relationship click here.

    For basics of Views Click Here.

    Maintenance View in SAP ABAP

    Creation of Maintenance View in SAP ABAP:

    Step 01: Open SE11, select Views radio button, and enter a name for your view e.g. ZBARRY_MAINTAIN_VIEWS and click CREATE. Choose Maintenance Views from radio buttons.

    Step 02: Write an explanatory short text e.g. Help View for Employee ID.

    Step 03: Write all your primary table names you want in your view in column Tables.

    *NOTE: Only tables linked with Primary table (via Foreign Key Relationship) can be included in the view.

    Table 01 Image
    Step 04: Now you need to provide Join Conditions. Select your Primary Table and click Relationship Tab Image; it will fetch the foreign key relationship. Choose and copy the Relationship. The Join Condition derived from the relationship will be displayed as shown below. [To know more about Foreign Keys CLICK HERE].

    *NOTE: Only the Relationship made with N:1 cardinality will be available. To know more about  View Restrictions CLICK HERE.

    Table View
    Step 05:
    Click View Fields and then click Table fields, Select the fields from each table that you want to be visible in your View.To know more about Joins CLICK HERE.

    *NOTE: By default all the fields of Primary Table that you have provided in Step 03 will be chosen (as it is an outer join).

    Step 06: Save it, check for Errors and click Activate.

    Step 07: Initiate Table Maintenance Generator as we did for tables and maintain data via SM30.

     *NOTE: There are more functions and additional options of Maintenance View, we will update it soon.

    Advantages of Maintenance Views

    1. Maintenance View fetches required data from Multiple Tables and hence faster than selecting data from these tables individually.
    2. It maintains (Create/Update/Delete) Multiple Tables at once and hence faster than maintaining multiple tables individually.
    3. We can maintain Delivery Class of View separately.

    *NOTE: Under Maintenance Status tab, select Page and then select Delivery Class.

    1. It utilizes Outer Join and hence all data from Primary table is displayed irrespective of their presence in other secondary tables.

    This feature can be understood via an example that we have a view that displays an employee name with First name and Last name that are being fetched from two different tables on basis of Employee ID.

    Table 1:

    Emp ID First Name
    001 John
    002 Ron

     

    Table 2:

    Emp ID Last Name
    001 Cena

     

    Inner Join Output:

    Emp ID First Name Last Name
    001 John Cena

     

    Outer Join Output:

    Emp ID First Name Last Name
    001 John Cena
    002 Ron

     

    [embedyt] https://www.youtube.com/watch?v=XgB2dAr3Mj0[/embedyt]

     

  • Help View in SAP ABAP

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

    Help View in SAP ABAP

    As the name suggest, A Help View in SAP ABAP is a view that is used as a selection method in Search Help. A search help takes either tables or views as input. The views can be Database View, Projection View or Help Views, based upon requirement.
    A Database view uses inner join and hence provides only those data that has relational entries in all table. In case you need all data, irrespective of any condition from given tables, you need to use outer join i.e. a view that uses outer join i.e. Help View.

    Definition

    A Help View in SAP ABAP is a view that combines multiple tables into a single view using outer join and is mainly used as an input to Search Help.

    *NOTE: The Join Conditions can be only chosen via tab. Relationship Tab Image  It means you need to create foreign key relationship in advance. To know how to create a Foreign Key Relationship click here.

    For basics of Views Click Here.

    Help View in SAP ABAP

    Creation of Help View in SAP ABAP:

    Step 01: Open SE11, select Views radio button, and enter a name for your view e.g. ZBARRY_HELP_VIEWS and click CREATE. Choose Help Views from radio buttons.

    Step 02: Write an explanatory short text e.g. Help View for Employee ID.

    Step 03: Write all your primary table names you want in your view in column Tables.

    *NOTE: Only tables linked with Primary table (via Foreign Key Relationship) can be included in the view.

    Table 01 Image
    *NOTE:
    Only the Relationship made with N:1 cardinality will be available. To know more about Help View Restrictions CLICK HERE.

    Step 04: Now you need to provide Join Conditions. Select your Primary Table and click Relationship Tab Image; it will fetch the foreign key relationship. Choose and copy the Relationship. The Join Condition derived from the relationship will be displayed as shown below. [To know more about Foreign Keys CLICK HERE].

    Table View
    Step 05:
    Click View Fields and then click Table fields, Select the fields from each table that you want to be visible in your View.To know more about Joins CLICK HERE.

    *NOTE: By default all the fields of Primary Table that you have provided in Step 03 will be chosen (as it is an outer join).

    Step 06: Save it, check for Errors and click Activate.

     *NOTE: There are more functions and additional options of Help View, we will update it soon.

    Advantages of Help Views

    1. Help View fetches required data from Multiple Tables and hence faster than selecting data from these tables individually.
    2. Help Views utilizes Outer Join and hence all data from Primary table is displayed irrespective of their presence in other secondary tables.

    This feature can be understood via an example that we have a view that displays an employee name with First name and Last name that are being fetched from two different tables on basis of Employee ID.

    Table 1:

    Emp ID First Name
    001 John
    002 Ron

     

    Table 2:

    Emp ID Last Name
    001 Cena

     

    Inner Join Output:

    Emp ID First Name Last Name
    001 John Cena

     

    Outer Join Output:

    Emp ID First Name Last Name
    001 John Cena
    002 Ron

     

    [embedyt] https://www.youtube.com/watch?v=GCptsAlkhBY[/embedyt]