Category: ABAP

ABAP

  • 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]
  • Projection View in SAP ABAP

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

    Projection View in SAP ABAP

    As the name suggests, Projection View in SAP ABAP Projects few fields of a table. Let us understand it with an example, suppose you have an Employee Details table that contains data regarding employee basic details, Employee Address details and Employee Salary Details. You want Address Verification team to just see the Employee Address details. In this case you will create a Projection View of that table.

     

    Definition

    A Projection View in SAP ABAP is a view that contains exactly one table. It projects only those fields that are assigned to the view.

    *NOTE: The tables can be any transparent, cluster or pool. We don’t define any selection/Join condition for Projection Views.

    For basics of Views Click Here.

    Projection View in SAP ABAP

    Creation of Projection Views:

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

    Step 02: Write an explanatory short text e.g. Views for Employee Details.

    Step 03: Enter your Table name in Basis Table Field.

    Step 04: Select View Fields tab, click Choose Table Fields, select the required fields from Dialog Box and click COPY.

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

    *NOTE: You can further specify Maintenance Status. There are more functions and additional optional of Projection View, we will update it soon.

    Advantages of Projection View in SAP ABAP

    • Selection of Data from View is faster.
    • It helps to display only required & relevant data.
    • It limits full data access to unauthorized users.

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

  • Database View in SAP ABAP

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

    Database View in SAP ABAP

    As the name suggests Database View in SAP ABAP is a view that integrates several distributed database and helps us to view all data at one place. We can access data of Database View using SQL commands (SELECT Statements). It implements inner join for integration. It can even contain a single table without any Join statement. And if there is only table then we can maintain data also otherwise we can just read only.

    Definition

    A Database View in SAP ABAP is a view which combines multiple tables in to a single View and is used only to read the records.

    *NOTE: If only one table is there then it can be maintained too.

    For basics of Views Click Here.

    Database View in SAP ABAP

    Creation of Database View in SAP ABAP:

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

    Step 02: Write an explanatory short text e.g. Views for Admin Dashboard.

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

    Database Table 01
    Step 04:
    Now you need to write Join Conditions or just click  if you have earlier specified the foreign keys in tables; it will automatically write the Join conditions for you based on your foreign key relationship. [To know more about Foreign Keys CLICK HERE]. 

    Example of a JOIN CONDITION.

    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.

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

    *NOTE: You can further go in technical settings of View and specify Buffer. There are more functions and additional optional of Database View, we will update it soon.

    Advantages of Database Views

    • Selection of Data from Views is faster than Selection of Data from individual tables.
    • It helps to select data from logically connected tables.
    [embedyt] https://www.youtube.com/watch?v=IIXCz86eyL0[/embedyt]
  • Inner Join And Outer Join

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

    Inner Join and Outer Join

    Inner Join and Outer Join are the two different ways to join two tables. Both of them produce different result. In this article we will learn both of them.

    Suppose you have two tables with two fields and following data as shown below:

    table 1
    Table 1

    table 2
    Table 2

    Now if you want data that is common in both the table then you will apply Inner Join and get following results:

    Inner Join And Outer Join Example1
    And if you want all data irrespective of its presence in any table, you will apply outer join and get results as shown below:

    Inner Join And Outer Join Example2

    Now let see definition of both of the Joins.

    Definition

    Inner Join

    A join that is utilized by Database views which gives the cross-product of the records present in both table.

    [For basics of Joins click here]

    Outer Join

    A join that shows the cross-product of all the records present in different tables. It is utilized by Help Views, Projection Views and Maintenance Views. [For basics of Views click here]

    It is of two types:

    1. Left Outer Join: It is just like outer join, it includes all the results of Outer Join with all data from the left table.
    2. Right Outer Join: It is also just like outer join, it includes all the results of Outer Join with all data from the right table.

     

  • Joins in SAP ABAP

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

    Joins in SAP ABAP

    In View, we need to join two tables; these two tables can have or cannot have Keys in common. In case of View we give Join Condition (e.g. table1-field1 = table2-field1) on basis of which records are merged. Joins in SAP ABAP can also be applied on two tables without a Join condition and in that case it will just give cross product of the two tables.

    Definition

    Joins in SAP ABAP are cross product of two tables which further uses Join Condition to produce desired output.

    Join Condition: When the cross product of two tables doesn’t give desired result, then a condition is written which tells us how the tables are connected. A statement is written where fields of each table are written with table name and equality operator.

    e.g. table1-field1 = table2-field1

     

    Example:

    If we have two table as shown below and we apply

    1. Join without any Join Condition

    Joins in SAP ABAP without condition

    2. Join with Condition

    Joins in SAP ABAP with condition

    Here the rows who don’t meet the condition are deleted.

     

     

    Joins in SAP ABAP

    Here the column which comes in right hand side of the Join Condition is also deleted.

     

     

    Joins in SAP ABAP

    This is the actual View as output.

    *NOTE:  It is not necessary to compare two fields of different table to form a condition. A condition can also be like Table-Field1 = 1.

    Types of Join

    1. Inner Join
    2. Outer Join

    *Note:

    1. Pooled & Cluster tables cannot be joined via Join statement.
    2. In a single SELECT statement we must define at max 49 JOINS and specifying each table a namespace using AS.
    3. A WHERE condition applied with JOIN statements are actually applied on the results of the JOIN statements.
    4. If same column name appears in multiple tables, then its source is specified using column selector i.e. (~).
    5. JOIN expressions bypass BUFFERING. We can access table buffer by using FOR ALL ENTRIES.
  • Views in ABAP

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

    Views in ABAP

    Have you ever seen the views outside your window? Let’s suppose that a beautiful girl leaves just in front of your house with her parents. Now suppose you have a big window in your room from where you can see windows of both the girl and her parents. If you just want to see the girl, then you can use curtains to hide one part of the window, if you want to check her parents’ activity you can move the curtains again. That is Views in ABAP.

    Views in ABAP helps us to see what we want to see from one table or many.

     

    Definition

    A View is a reusable object which doesn’t stores any data physically but is derived from one or more tables.

    Mandatory steps to make Views in ABAP

     

    Step 01: Open SE11 and choose Views Radio Button. Enter the name and Type of the View

    Step 02: Select the tables for view.

    Step 03: Link tables using Join Conditions.

    Step 04: Select the fields from tables; these will be only visible in the views.

    Step 05: Define the selection conditions which will restrict the records in the view.

     

    Types of Views

     

    VIEWS TYPE JOIN USED Description
    Database Views Inner Join A View that integrate multiple Table into a single View.
    Projection Views N.A A View that shows only few fields of single Table.
    Help Views Outer Join A Search Help can show data from Table or Structure. But if you need data from multiple tables then we create a Help View for Search Help.
    Maintenance Views Outer Join Unlike Database View where you can only View Data, if you want to maintain multiple Table @ a single place using View then we create Maintenance Views.

     

    *NOTE: To know more about Joins click here.

     

    Example

    Requirement: You have three tables of Employee:

    1. ZEMP_DETAILS that have Employee Details like Employee ID, USERNAME, PASSWORD, NAME, and Date of Birth.
    2. ZEMP_ADDRESS that have Employee Details like Employee ID, Employee Address, Town, State, and Country.
    3. ZEMP_SALARY that have Employee Details like Employee ID, Employee Basic Salary, Allowance and Tax.

    Now you want to view all the details of an employee altogether. What will you do?

     

    Proposed Solution:  We will create a view which will be based on Employee ID.

    Views in ABAP

    From above View we can see how we can project multiple tables altogether.

  • ABAP Table Index in SAP

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

    ABAP Table Index

    Suppose you have a million unsorted records and you want to perform search on the basis of non primary key. Then it will take a lot of time to process all the records. In this case you will make something called Secondary Indexes or ABAP Table Index.

    Definition

    An Index is a sorted copy of Database which contains pointer pointing to non-key fields which is used to increase the search speed of a table.

    Types of Indexes

    Primary Index:

    The Primary Index is an Index created by system itself just after the creation of table. It contains only key fields. It has ID 0.

    Secondary Index:

    When your search criteria are not fulfilled by Primary Index, then in this case we can create our own Indexes called Secondary Indexes. Its ID can be of max 3 digit alphanumeric value. The total length of Index Name can be of 13 digit which includes table name and Index ID.

    The naming convention of Secondary Indexes:

    <TABLE_NAME> ~ <INDEX_ID>

    e.g.  ZBARRY_ALLEN ~ A.

     

    Unique Index:

    If we define an Index as Unique Index if we want only unique records or unique combination of field in the table.

    e.g. If you have defined two field combination as Unique. Then only unique values will be inserted. For more visit ABAP Documentation.

    Extension Index:

    A secondary Index is temporary index and needs recreation after every upgrade. If we create Extension Index it is upgrade protected. We don’t have to do anything new, just choose Extension Index in step 02 below.

    How to Create a Secondary ABAP Table Index:

    Step 01: Create a table and in the maintenance screen click on Indexes. [How to Create a table: Click here]

    Step 02: Choose New Icon  and click Create.

    Step 03: Choose Index from Drop Down box. Enter Index ID and click CONTINUE.

    Step 04: Enter an explanatory Short Description.

    Step 05: Choose Table Fields, choose desired fields and choose COPY.

    *NOTE: The order of the field is important.

    Step 06: If the values in the index are always unique then choose Unique radio button else leave it.

    Step 07: According to the use of Index choose one of the radio button:

    Radio Button Description
    For all database systems If it will be used across all database systems
    For selected database systems If only for selected database systems. You can select at max 4.
    Not at all in the database If it is an exclusive Index

     

    Step 08: Save it, Check for Errors and Activate it.

    Disadvantages of Index

    More the number of ABAP Table Index, the more load on the system, as it needs to adjust Indexes every time you Insert, Update or Delete a record. Due to which Table which is written frequently must have less indexes.