Skip to main content

Command Palette

Search for a command to run...

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

Published
β€’4 min read
πŸ“˜ Day-9: Type Groups, Class Types & Implementing Views Using Abap Code
R

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:

  1. Type Groups (Type Pools)

  2. Class Types (OO ABAP)

  3. 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: SE11

  • Object 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?

StepMeaning
TYPESDefines custom structure
Internal TableStores multiple DB records
SELECTFetches data
LOOPProcesses records
WRITEDisplays 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?

PartExplanation
SELECT-OPTIONSCreates dynamic filter
INNER JOINCombines header + item
INTO TABLEStores result in memory
LOOPDisplays records

πŸ”Ή Important Difference

View (SE11)ABAP JOIN
Defined in DictionaryWritten in Program
Reusable globallyUsed locally
No coding requiredRequires 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

ConceptPurpose
TYPE GROUPGlobal reusable types
TYPESLocal structure
CLASSModern OOP container
INNER JOINCombine multiple tables
SELECT-OPTIONSDynamic filter
LOOPRow 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

More from this blog

A

ABAP Essentials for Beginners

13 posts