π Day-9: Type Groups, Class Types & Implementing Views Using Abap Code

On a journey of continuous learning π I share the concepts I learn daily through blogs. Learn concepts with me β one topic at a time.
#LearningInPublic #ContinuousLearning
Today we delve into advanced ABAP structuring concepts.
We will clearly understand:
Type Groups (Type Pools)
Class Types (OO ABAP)
Implementing Views using ABAP JOIN code
This topic is crucial for clean coding, reusable design, and real-time development projects.
πΉ PART 1: TYPE GROUP (TYPE POOL)
What is a Type Group?
A Type Group (also called Type Pool) is a container that holds globally reusable type definitions and constants.
Think of it like:
π¦ A shared toolbox that stores structures, table types, and constants under one common name.
Why Use a Type Group?
To define global reusable types
To maintain centralized type definitions
To improve readability
To standardize structures across programs
Where is a Type Group Created?
T-Code:
SE11Object Type: Type Group
How to Use a Type Group in a Program?
To use a Type Group, include it in your program with the TYPE-POOLS statement. This makes all types defined inside the Type Group available for use.
Example:
TYPE-POOLS: ZSD_TYPES.
Now all types defined inside ZSD_TYPES can be used.
Naming Convention
All types inside a Type Group must start with the type group name.
Example:
If Type Group = ZSD_TYPES
Then type should be:
TYPES: BEGIN OF ZSD_TYPES_STRUCTURE,
field1 TYPE c LENGTH 10,
field2 TYPE i,
END OF ZSD_TYPES_STRUCTURE.
Advantages
β Reusable across multiple programs
β Clean structured development
β Centralized control
Disadvantages
β Entire type group loads into memory
β In modern ABAP, Global Classes are preferred
πΉ Practical Example: Custom Types in Program
Below is a clean structured version of your example:
TYPES: BEGIN OF ty_student,
id TYPE i,
name TYPE c LENGTH 50,
END OF ty_student.
DATA: lt_students TYPE TABLE OF ty_student,
ls_student TYPE ty_student.
SELECT id name FROM zdt_student INTO TABLE lt_students.
LOOP AT lt_students INTO ls_student.
WRITE: / ls_student-id, ls_student-name.
ENDLOOP.
What is Happening Here?
| Step | Meaning |
| TYPES | Defines custom structure |
| Internal Table | Stores multiple DB records |
| SELECT | Fetches data |
| LOOP | Processes records |
| WRITE | Displays output |
πΉ PART 2: CLASS TYPES (Object-Oriented ABAP)
Now we move to modern ABAP β Object-Oriented Programming (OOP).
In real projects, Classes are preferred over Type Groups.
What is a Class in ABAP?
A Class is:
A blueprint that contains data and methods (logic) together.
Created using:
- T-Code:
SE24
Basic Class Template
CLASS lcl_example DEFINITION.
PUBLIC SECTION.
METHODS: display.
ENDCLASS.
CLASS lcl_example IMPLEMENTATION.
METHOD display.
WRITE: 'Hello, ABAP OOP!'.
ENDMETHOD.
ENDCLASS.
Calling a Class in a Program
DATA: lo_example TYPE REF TO lcl_example.
CREATE OBJECT lo_example.
CALL METHOD lo_example->display.
πΉ PART 3: IMPLEMENTING VIEW LOGIC USING ABAP JOIN
Now we will simulate what a Database View does using ABAP JOIN.
Scenario:
We have two tables:
ZDT_STUDENT_HDR (Header)
ZDT_STUDENT_ITEM (Item)
We want combined data.
Clean Production-Style ABAP JOIN Code
SELECT-OPTIONS: s_id FOR zdt_student_hdr-id.
SELECT a~id a~name b~subject
INTO TABLE @DATA(lt_combined)
FROM zdt_student_hdr AS a
INNER JOIN zdt_student_item AS b
ON a~id = b~student_id
WHERE a~id IN @s_id.
LOOP AT lt_combined INTO DATA(ls_combined).
WRITE: / ls_combined-id, ls_combined-name, ls_combined-subject.
ENDLOOP.
What is Happening Here?
| Part | Explanation |
| SELECT-OPTIONS | Creates dynamic filter |
| INNER JOIN | Combines header + item |
| INTO TABLE | Stores result in memory |
| LOOP | Displays records |
πΉ Important Difference
| View (SE11) | ABAP JOIN |
| Defined in Dictionary | Written in Program |
| Reusable globally | Used locally |
| No coding required | Requires ABAP coding |
πΉ Modern Better Version (New ABAP Syntax)
SELECT a~id, a~name, b~subject
FROM zdt_student_hdr AS a
INNER JOIN zdt_student_item AS b
ON a~id = b~student_id
INTO TABLE @DATA(lt_combined)
WHERE a~id IN @s_id.
Modern ABAP:
Uses
@Inline declarations
Cleaner and safer
πΉ Quick Memory Chart
| Concept | Purpose |
| TYPE GROUP | Global reusable types |
| TYPES | Local structure |
| CLASS | Modern OOP container |
| INNER JOIN | Combine multiple tables |
| SELECT-OPTIONS | Dynamic filter |
| LOOP | Row processing |
π₯ Final Understanding
Type Group = Old structured reusable types
Classes = Modern reusable logic container
Views = Dictionary-level logical join
JOIN in ABAP = Program-level logical join



