Local Structure in ABAP Report

Suppose in an ABAP Report, we have multiple data for a person. This data is name, address, contact number and salary. Now, again we have same data for another person. Will you create those variables again for the second person or would you like to reuse the above variables. In this case, you will need a group of these variables under a single component. This component is known as structure  or local structure in ABAP report .
***Note: If you want to learn about ABAP SE11 (Data Dictionary) Structure, visit here.

Definition

A Local Structure in ABAP reports is a reusable component which acts as a collection of different variables of different data types under a single name. It holds only single data at runtime.

Syntax

A local structure in ABAP is defined within BEGIN OF…. END OF. And it starts either with TYPES or DATA.

BEGIN OF <Your_Structure_name>,

NAME TYPE c LENGTH 20,

SALARY TYPE i,

END OF <Your_Structure_name>.

Local Structure in ABAP Report
Local Structure in ABAP Report – Image Illustration

NOTE: A local structure can also be created at runtime. We will show this in below example.

Examples

Case 1:

DATA: BEGIN OF LS_EMPLOYEE,

NAME TYPE c LENGTH 20,

SALARY TYPE i,

END OF LS_EMPLOYEE.

In this case, we directly fetch one data into this structure.

Select Single * from ZEMPLOYEE into corresponding fields of @LS_EMPLOYEE.

Case 2:

TYPES: BEGIN OF LS_EMPLOYEE,

NAME TYPE c LENGTH 20,

SALARY TYPE i,

END OF LS_EMPLOYEE.

Since it is a TYPE, hence it cannot hold data at runtime. Hence we will need to define a workarea first and then fetch data into that.

DATA: WA_ EMPLOYEE   TYPE   LS_EMPLOYEE.

Select Single * from ZEMPLOYEE into corresponding fields of WA_ EMPLOYEE.

CASE 3:

In latest update of ABAP, we can create a structure/workarea at runtime in given way:

SELECT Single * from ZEMPLOYEE into corresponding fields of DATA(WA_ EMPLOYEE).

In this way, we will not have to define a structure anymore and we can use this structure again in the program too.

Types of Structures

In real world development, we simply create a structure the way it is mentioned in above examples. But some time, as per scenario, we need to create structures in a different manner. SAP provides 4 types of structures:

Structure Type Description Use Case
Flat structures The structure which contains only elementary data types. A structure of employee basic data e.g. Name, age, salary, etc
Flat character-like structures The structure which contains only character like elementary data types. Character like data types are text field (char), numeric text field (n), text string (string). A structure which will be used only to read and no calculation will be made. In this case all data can be string type.
Nested structures A structure inside a structure is called a nested structure. A structure of school containing another structure of student details and teacher details.
Deep structures A structure which has at least one deep component (string, internal table or reference variables). A structure which saves mail content. Mail content can have unknown length, in this case data type of that field will be string.

 

 

Leave a comment

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