*&---------------------------------------------------------------------*
*& Report ZTEST_PROGRAM_2
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ztest_program_2.
TYPES : BEGIN OF lty_student,
name TYPE string,
id TYPE zstudent_id_01,
departid TYPE zdep_id,
departmentname TYPE string,
END OF lty_student.
" internal table
DATA lt_student TYPE TABLE OF lty_student.
" work area.
DATA ls_student TYPE lty_student.
DATA ls_department TYPE zdepartment_1.
" assign -->
" unassig --> directly access the place where the data is stored.
START-OF-SELECTION.
SELECT studentname studentid departmentid FROM zstudent_2
INTO TABLE lt_student.
"using workarea.
clear: ls_Student.
ls_student-id = '2'.
ls_student-name = 'RAM'.
ls_student-departid = '4'.
ls_student-departmentname = 'CSE'.
" append
append ls_Student to lt_Student.
"using workarea.
clear: ls_Student.
ls_student-id = '3'.
ls_student-name = 'RAM'.
ls_student-departid = '5'.
ls_student-departmentname = 'CSE'.
" append
insert ls_Student into lt_Student.
LOOP AT lt_student INTO ls_student.
WRITE: / ls_student-name, ls_student-id, ls_student-departid, ls_Student-departmentname.
ENDLOOP.
This ABAP report ZTEST_PROGRAM_2
is a beginner-friendly example that demonstrates how to work with internal tables, work areas, and database records. It starts by defining a custom structure lty_student
to hold student details such as ID, name, department ID, and department name. An internal table lt_student
and a work area ls_student
are then declared to store and process this data. The program first fetches existing records from the custom database table zstudent_2
into the internal table using a SELECT ... INTO TABLE
statement. After that, new student entries are created manually by filling values into the work area and adding them to the internal table using both APPEND
and INSERT
. Finally, the program loops through the internal table and displays each student’s details on the output screen. Overall, the code provides a simple but practical illustration of how internal tables can combine database data with additional records and then be processed for reporting in ABAP.
