GoCoding.org

Structure in SAP ABAP

by | Apr 24, 2018 | ABAP Beginner

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:

FieldsValueDescription
ComponentIt can be 16 digit Alphanumeric word starting with a letter and can contain underscoreIt is the column name of your table
KeyTick all the fields whose value will be unique and can define the relationship with other tablesA structure must contain at least one key field, else it can’t be Activated
Initial Value IndicatorTick if the field must have an initial valueAll key fields must always be given initial values. By default all fields are assigned initial values irrespective of indicator.
Typing MethodChoose from the available types: TYPE,LIKE,REF TOIt gives you an option to specify whether you are creating a type field, like field or reference field.
Component TypeSelect your Data Element or create oneIf 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 TypeAny Data type like CHAR,INTAccording to requirement specify the data type
LengthGive max length of your fieldLength will be dependent upon Data Type
Decimal PlacesNumber of places after decimal pointMainly for Float variables
Short DescriptionExplanatory statement for your fieldWhat 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]

FIELDSValueDescription
FieldSame as aboveSame as above
Data ElementSame as aboveSame as above
Data TypeSame as aboveSame as above
Foreign KeysForeign Keys for that fieldIt will be reflected after you maintain Foreign Key relationships
Check TableCheck Table for FieldIt will be reflected once you have check table relationship for the field
Origin of input helpInput help with fixed values, with check table, search helps, Static Input HelpIt reflects the way your input will be made to the given field
Srch HelpYour Search Help nameTo attach Search Helps to field
DefaultsAny Value depending upon the type of fieldTo assign Default value for the field
DomainDomain of specified Data ElementIf 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]

FIELDSValueDescription
FieldSame as aboveSame as above
Data ElementSame as aboveSame as above
Data TypeSame as aboveSame as above
Reference TableReference Table nameIf your data element refers to a table
Reference FieldField of Reference table being ReferredIt is actually the field being referred by the data element
Short DescriptionSame as aboveSame 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.

 

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.