Sunday 1 October 2017

ABAP: Structures

Structure is a user defined complex data type in ABAP. By using structure, we can group relevant fields.

For example, we can group the student details like student_id, first_name, last_name, email and phone_num in one structure.

How can we define a structure?
You can define a structure using built in types, data elements, table type, structures etc.,

Can a structure be defined using other structure?
Yes, you can define a structure using other structure.

For example, Address structure has following fields.
         a. Street
         b. City
         c. Country
         d. PIN   
You can define student structure with below fields.
         a. student_id : char(30)
         b. first_name : char(30)
         c. last_name : char(30)
         d. email : char(30)
         e. phone_num : char(20)
         f. address (of type Address structure)

Where can I define structures?
Structures can be defined locally or globally in ABAP Dictionary.

Creating structures
I am going to show, how to create the structure ZSTUDENT_STR using the existing data elements.

COMPONENT
TYPE
STUDENT_ID
ZSTUDENT_ID
FIRST_NAME
ZSTUDENT_FIRST_NAME
LAST_NAME
ZSTUDENT_LAST_NAME
PRIMARY_EMAIL
ZSTUDENT_PRIMARY_EMAIL
SECONDARY_EMAIL
ZSTUDENT_SECONDARY_EMAIL
PHONE_NUMBER
ZPHONE_NUM
DATE_OF_JOIN
ZSTUDENT_DATE_OF_JOIN


Types like ZSTUDENT_ID, ZSTUDENT_FIRST_NAME, ZSTUDENT_LAST_NAME, ZSTUDENT_PRIMARY_EMAIL, ZSTUDENT_SECONDARY_EMAIL, ZPHONE_NUM, ZSTUDENT_DATE_OF_JOIN are the data elements that we created in my previous post.

Open ABAP Dictionary by using the transaction ‘SE11’.

Give the technical name as ‘ZSTUDENT_STR’ in the Data type field, and press Create button.

Select the type as structure.

Press Ok. It opens below screen.
Give the short description as ‘Student structure’.


Update the component and their component types.

Press enter, ABAP system automatically update the semantic information.
Save the structure.

Set the enhancement category.

Go to Extras -> Enhancement Category…
It opens below window, press OK.
Select the option ‘Can Be Enhanced (Deep)’. By selecting the option 'Can be Enhanced (Deep)', I am telling to the ABAP system that the structure can be enhanced in future.
Press copy.
Activate the structure.

You can try creating below structures.

ZPARENT_STR
Component
Component Type
PARENT_ID
ZPARENT_ID
FIRST_NAME
ZPARENT_FIRST_NAME
LAST_NAME
ZPARENT_LAST_NAME
PRIMARY_EMAIL
ZPARENT_PRIMARY_EMAIL
SECONDARY_EMAIL
ZPARENT_SECONDARY_EMAIL
PHONE_NUMBER
ZPHONE_NUM


ZTEACHING_FACULTY_STR
COMPONENT
COMPONENT TYPE
FACULTY_ID
ZFACULTY_ID
FIRST_NAME
ZFACULTY_FIRST_NAME
LAST_NAME
ZFACULTY_LAST_NAME
PRIMARY_EMAIL
ZFACULTY_PRIMARY_EMAIL
WORK_EMAIL
ZFACULTY_WORK_EMAIL
PHONE_NUMBER
Z_PHONE_NUM
DATE_OF_JOIN
ZFACULTY_DATE_OF_JOIN
SALARY
ZSALARY


ZNON_TECHING_FACULTY_STR
COMPONENT
COMPONENT TYPE
NON_TEACHING_FACULTY_ID
ZNON_FACULTY_ID
FIRST_NAME
ZFACULTY_FIRST_NAME
LAST_NAME
ZFACULTY_LAST_NAME
PRIMARY_EMAIL
ZFACULTY_PRIMARY_EMAIL
WORK_EMAIL
ZFACULTY_WORK_EMAIL
PHONE_NUMBER
Z_PHONE_NUM
DATE_OF_JOIN
ZFACULTY_DATE_OF_JOIN
SALARY
ZSALARY

ZFACULTY_STUDENT_STR
COMPONENT
COMPONENT TYPE
FACULTY_ID
ZFACULTY_ID
STUDENT_ID
ZSTUDENT_ID
YEAR_OF_TEACHING
ZYEAR_OF_TEACHING

ZSTUDENT_PARENT_STR
COMPONENT
COMPONENT TYPE
STUDENT_ID
ZSTUDENT_ID
PARENT_ID
ZPARENT_ID

ZFACULTY_RATING_STR
COMPONENT
COMPONENT TYPE
FACULTY_ID
ZFACULTY_ID
STUDENT_ID
ZSTUDENT_ID
FACULTY_RATING
ZFACULTY_RATING
        
ZSTUDENT_RATING_STR
COMPONENT
COMPONENT TYPE
STUDENT_ID
ZSTUDENT_ID
FACULTY_ID
ZFACULTY_ID
STUDENT_RATING
ZSTUDENT_RATING

In this post we created below structures.
ZSTUDENT_STR, ZPARENT_STR, ZTEACHING_FACULTY_STR, ZNON_TECHING_FACULTY_STR, ZFACULTY_STUDENT_STR, ZSTUDENT_PARENT_STR, ZFACULTY_RATING_STR, ZSTUDENT_RATING_STR



Previous                                                 Next                                                 Home

No comments:

Post a Comment