Skip to main content

Command Palette

Search for a command to run...

DAY 13 – Internal Table Operations, Transactions & Memory Handling in ABAP

Published
β€’4 min read
DAY 13 – Internal Table Operations, Transactions & Memory Handling in ABAP
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’s session is one of the most important practical topics in ABAP development.

You will understand:

  • Internal Table Operations (READ, APPEND, INSERT, DELETE, MODIFY, SORT)

  • Memory Handling (CLEAR, FREE)

  • CALL TRANSACTION

  • HOTSPOT & Interactive Output

  • SAP Memory vs ABAP Memory

  • EXPORT / IMPORT

  • SUBMIT

  • Parameter ID Handling

This is core report programming knowledge used in real SAP projects.


🧠 PART 1 – Internal Table Operations

Before databases, before UI β€” ABAP developers work heavily with internal tables.

Think of an internal table as:

A temporary Excel sheet stored in program memory.


πŸ”Ή 1. TYPE & DATA Declaration

TYPES: BEGIN OF ty_student,
         id     TYPE i,
         name   TYPE string,
         marks  TYPE i,
       END OF ty_student.

DATA: gt_student TYPE STANDARD TABLE OF ty_student,
      gs_student TYPE ty_student.

What happens here?

  • ty_student β†’ Structure (like one row)

  • gt_student β†’ Internal table (multiple rows)

  • gs_student β†’ Work area (one row at a time)


πŸ”Ή 2. APPEND – Add Record at End

gs_student-id = 1.
gs_student-name = 'HARISH'.
gs_student-marks = 85.
APPEND gs_student TO gt_student.

πŸ“Œ Meaning:

Adds a new row at the end of internal table.


πŸ”Ή 3. INSERT – Insert at Specific Position

INSERT gs_student INTO gt_student INDEX 2.

πŸ“Œ Inserts record at position 2.

If index does not exist β†’ Runtime error.


πŸ”Ή 4. READ TABLE – Fetch Specific Record

READ TABLE gt_student INTO gs_student WITH KEY id = 2.
IF sy-subrc = 0.
  WRITE: / 'Read Success:', gs_student-name.
ENDIF.

Important:

sy-subrc = 0 β†’ Success
sy-subrc β‰  0 β†’ Record not found


πŸ”Ή 5. MODIFY – Update Existing Row

gs_student-marks = 95.
MODIFY gt_student FROM gs_student INDEX sy-tabix.

Updates existing record at given index.


πŸ”Ή 6. DELETE – Remove Record

DELETE gt_student WHERE id = 3.

Deletes record matching condition.


πŸ”Ή 7. SORT – Arrange Records

SORT gt_student BY marks DESCENDING.

Sorts table by marks from highest to lowest.


πŸ”Ή 8. LOOP & SUM – Process Table

DATA gv_total TYPE i.

LOOP AT gt_student INTO gs_student.
  gv_total = gv_total + gs_student-marks.
ENDLOOP.

WRITE: / 'Total Marks:', gv_total.

πŸ–± PART 2 – HOTSPOT & CALL TRANSACTION

πŸ”Ή HOTSPOT – Clickable Text

FORMAT HOTSPOT ON.
WRITE: / 'Click Here to Open SE11'.
FORMAT HOTSPOT OFF.

When user clicks β†’ You can trigger AT LINE-SELECTION.


πŸ”Ή CALL TRANSACTION

CALL TRANSACTION 'SE11'.

Opens transaction programmatically.


πŸ” PART 3 – SAP Memory vs ABAP Memory

Here is the conceptual difference:

πŸ”· SAP Memory (SPA/GPA)

Used for:

Passing small values across transactions.

Example:

SET PARAMETER ID 'DTB' FIELD 'SFLIGHT'.
CALL TRANSACTION 'SE11'.
  • 'DTB' = Parameter ID for table name

  • Opens SE11 with SFLIGHT automatically filled

Lifetime:

Until user logs off.


πŸ”· ABAP Memory

Used within same internal session.

EXPORT Example:

EXPORT gv_total TO MEMORY ID 'ZTOTAL'.

IMPORT Example:

IMPORT gv_total FROM MEMORY ID 'ZTOTAL'.

πŸ’‘ Real Life Analogy

  • SAP Memory β†’ Locker assigned to you in office.

  • ABAP Memory β†’ Notebook used inside meeting room.


πŸ” PART 4 – SUBMIT

Used to call another report program.

SUBMIT z_other_program AND RETURN.

If you want to pass values:

SUBMIT z_other_program
  WITH p_carr = 'LH'
  AND RETURN.

🧹 PART 5 – CLEAR vs FREE

πŸ”Ή CLEAR

Resets value but memory remains allocated.

CLEAR gs_student.

πŸ”Ή FREE

Releases memory completely.

FREE gt_student.

πŸ”„ PART 6 – Full Combined Working Example

REPORT z_day13_demo.

TYPES: BEGIN OF ty_data,
         id TYPE i,
         name TYPE string,
       END OF ty_data.

DATA: gt_data TYPE STANDARD TABLE OF ty_data,
      gs_data TYPE ty_data.

DATA gv_count TYPE i.

* Append
gs_data-id = 1.
gs_data-name = 'ABAP'.
APPEND gs_data TO gt_data.

* Read
READ TABLE gt_data INTO gs_data INDEX 1.
IF sy-subrc = 0.
  WRITE: / 'Record Found:', gs_data-name.
ENDIF.

* Export to memory
EXPORT gv_count TO MEMORY ID 'ZCNT'.

* Call Transaction
SET PARAMETER ID 'DTB' FIELD 'SFLIGHT'.
CALL TRANSACTION 'SE11'.

* Free memory
FREE gt_data.

πŸ“Š Complete Keyword Summary

KeywordPurpose
APPENDAdd row at end
INSERTAdd row at specific position
READ TABLEFetch row
MODIFYUpdate row
DELETERemove row
SORTArrange rows
CLEARReset value
FREERelease memory
SET PARAMETERStore SAP memory
EXPORTStore ABAP memory
IMPORTRetrieve ABAP memory
CALL TRANSACTIONOpen transaction
SUBMITCall program

🎯 Final Understanding

Today you learned:

  • How internal tables behave like temporary databases

  • How to manipulate records dynamically

  • How SAP Memory differs from ABAP Memory

  • How to open transactions programmatically

  • How to pass data between programs

  • How to properly manage memory

More from this blog