In SAP ABAP, pass by value and pass by reference are two methods of passing data to methods, function modules, or forms. They determine how the data is handed over and whether changes to the data affect the original variable.
SAP EWM Help Latest Questions
A subroutine is a block of reusable code defined using FORM and called using PERFORM. It is a procedural method of modularization mainly used in classical ABAP programming. When to use: In classic procedural ABAP programs. For logic reuse in the same or ...
An include is a code fragment stored separately and inserted into a program using the INCLUDE statement. It’s mainly used to split a large program into manageable blocks. When to use: To split large programs into smaller reusable blocks. Often used for reusable ...
A function module (FM) is a globally reusable procedure created in transaction SE37 or inside a Function Group. It can be called from anywhere in the system. When to use: · When you want reusable logic across different programs. · Supports exception handling ...
A macro is a text replacement technique defined using DEFINE … END-OF-DEFINITION. It’s similar to a preprocessor directive and is expanded at runtime. When to use: · For short code blocks with similar patterns (e.g., logging or repetitive output). · Used mainly in ...
REDUCE is used to aggregate values like totals, counts, etc., in a clean, functional style. *&---------------------------------------------------------------------* *& Report ZREP_LCLCLASS *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT zrep_lclclass. TYPES: BEGIN OF ty_order, id TYPE i, amount TYPE i, END OF ty_order. DATA: lt_orders TYPE STANDARD TABLE OF ty_order WITH EMPTY KEY, lv_total TYPE i. lt_orders = VALUE #( ( id = 1 amount = 100 ) ( id = 2 amount = 250 ) ( id = 3 amount = 150 ) ). lv_total = REDUCE i( INIT sum = 0 FOR order IN lt_orders NEXT sum = sum + order-amount ). WRITE: / 'Total Amount:', lv_total. Output: Total Amount: 500
When we create a variable in the public section of a class, we can use it within the methods of that class. Let’s say we assign it an initial value. Later, if we create another variable with the same name ...
This replaces the need for LOOP AT, IF, and APPEND all in one line—powerful and readable. *&---------------------------------------------------------------------* *& Report ZREP_LCLCLASS *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT zrep_lclclass. TYPES: BEGIN OF ty_user, name TYPE string, status TYPE string, END OF ty_user. DATA: lt_users TYPE STANDARD TABLE OF ty_user WITH EMPTY KEY, lt_names TYPE STANDARD TABLE OF string WITH EMPTY KEY. lt_users = VALUE #( ( name = 'Alice' status = 'ACTIVE' ) ( name = 'Bob' status = 'INACTIVE' ) ( name = 'Charlie' status = 'ACTIVE' ) ). lt_names = VALUE string_table( FOR user IN lt_users WHERE ( status = 'ACTIVE' ) ( user-name ) ). LOOP AT lt_names INTO DATA(name). WRITE: / name. ENDLOOP. Output: Alice Charlie
You can build a new internal table with only selected entries and fields like this: *&---------------------------------------------------------------------* *& Report ZREP_LCLCLASS *&---------------------------------------------------------------------* *& Demonstrates modern ABAP syntax: REDUCE, FILTER, FOR expressions *&---------------------------------------------------------------------* REPORT zrep_lclclass. *---------------------------- * Example 1: REDUCE Operator *---------------------------- TYPES: BEGIN OF ty_order, id TYPE i, amount TYPE i, END OF ty_order. DATA: lt_orders TYPE STANDARD TABLE OF ty_order WITH EMPTY KEY, lv_total TYPE i. lt_orders = VALUE #( ( id = 1 amount = 100 ) ( id = 2 amount = 250 ) ( id = 3 amount = 150 ) ). lv_total = REDUCE i( INIT sum = 0 FOR order IN lt_orders NEXT sum = sum + order-amount ). WRITE: / '--- REDUCE Example ---', / 'Total Amount:', lv_total. *---------------------------- * Example 2: FILTER Operator *---------------------------- TYPES: BEGIN OF ty_user, name TYPE string, status TYPE string, END OF ty_user. DATA: lt_users TYPE STANDARD TABLE OF ty_user WITH EMPTY KEY, lt_active_users TYPE STANDARD TABLE OF ty_user WITH EMPTY KEY. lt_users = VALUE #( ( name = 'Alice' status = 'ACTIVE' ) ( name = 'Bob' status = 'INACTIVE' ) ( name = 'Charlie' status = 'ACTIVE' ) ). lt_active_users = FILTER #( lt_users WHERE status = 'ACTIVE' ). WRITE: / '--- FILTER Example ---'. LOOP AT lt_active_users INTO DATA(user). WRITE: / user-name, user-status. ENDLOOP. *------------------------------------------------------ * Example 3: FOR Expression - Extract Specific Fields *------------------------------------------------------ DATA: lt_names TYPE STANDARD TABLE OF string WITH EMPTY KEY. lt_names = VALUE string_table( FOR user IN lt_users WHERE ( status = 'ACTIVE' ) ( user-name ) ). WRITE: / '--- FOR Expression Example ---'. LOOP AT lt_names INTO DATA(name). WRITE: / name. ENDLOOP. This creates a new string table containing only the names of users whose status = 'ACTIVE'—short, clean, and readable. Output: — ...
In SAP, pooled tables are a type of database table used to store data from multiple internal tables (called logical tables) within a single physical table in the database. Pooled tables help in reducing the number of database objects and ...