Summary -
In this topic, we described about the below sections -
ABAP supports the structured variable declared as a structured data type. Structured variable can be defined by using BEGIN OF and END OF keywords.
A structure variable can be declared by using another structure variable with LIKE. Each individual field in the structure can be accessed using hyphen (-).
Syntax -
DATA: BEGIN OF {structure-name}
{local variables declaration}
END OF {structure-name}.
Example -
Write a simple program to display student details using structure.
Code -
*&---------------------------------------------------------------------*
*& Report Z_STRUCTURE_VARIABLE
*&---------------------------------------------------------------------*
*& Program Written by TUTORIALSCAMPUS
*&---------------------------------------------------------------------*
REPORT Z_STRUCTURE_VARIABLE.
* Declaring student structure with student no, student name and
* student class
DATA: BEGIN OF student,
no TYPE n,
name(25) TYPE c,
class(10) TYPE c,
END OF student.
* Assigning value to student no
MOVE 1 TO student-no.
* Assigning value to student name
MOVE 'pawan' TO student-name.
* Assigning value to student class
MOVE '1st class' TO student-class.
* Displaying student structure details by using stucture appending
WRITE : 'student-no :', student-no,
/ 'student-name :', student-name,
/ 'student-class:', student-class.
Output -
Explaining Example -
In the above example, each and every statement is preceeded with a comment to explain about the statement. Go through them to get clear picture of example code.
student is a structure variable. no, name and class are elementary variables in student structure variable.
The structure variables are referring like - no as student-no, name as student-name and class as student-class.
These references student-no, student-name and student-class are used in programming process to manuplate the data.