Monday, June 30, 2025

πŸ’» Module Pool Programming

ABAP Transactions:

  • It is also known as Module Pool Programming
  • It is also known as Dialog Programming

Transaction:
A transaction is a series of Dialog Steps in which application will accept data from user which is finally updated to Database.

Note:
Flow Logic (Events) acts as interface between *Screen Painter & Dialog Programming

Events in Dialog Programming:

  1. PAI (Process After Input)
  2. PBO (Process Before Output)
  3. POH (Process on Help Request)
  4. POV (Process on Value Request)


PAI:

  • It triggers after processing input values in a screen
  • This event triggers whenever user interacts with a screen

PBO:

  • It triggers before screen display

Note:

  1. PAI will bring the data from Screen → Program Variables
  2. PBO will bring the data from Program Variables → Screen


POH:

  • It triggers whenever user selects F1 Function Key.
  • It is used for help

POV:

  • It triggers whenever user selects F4 Function Key.
  • It is used for search help


Flow of Data in Module Pool Programming:

  • Transfer data from Screen to Program variables
  • Transfer data from Program Variables to Screen


Function Control Codes:

  • It is also known as FCT codes
  • Using FCT codes, Function Codes can be controlled or identified in Module Pool Programming

 

SY-UCOMM:
SY-UCOMM returns FCT value for a function key (button) in Dialog programming selected by user.


Steps:

  1. Work with SE38 (create a Dialog Programming)
  2. Work with SE51 (create a Screen)
  3. Work with SE93 (create a T code)
  4. Run the T code


Requirement:

Solution:

Step-1
  Go to SE38 

Program: ZSD_CUSTOMER_DETAILS 

Create 

Title: Customer Details 

Type: Module Pool 

Enter 

Package: ZABAP 

Save 

Create Request 

Short Description: SD/ABAP: Customer Details   

Enter 

Enter 

Step-2:

Go to SE51 

Program: ZSD_CUSTOMER_DETAILS 

Screen Number: 100 

Create 

Short Description: Screen 100 

Layout button 

Place a box (last from 6th option) on the screen 

Double click on Frame of the box 

Provide Text: Customer Details 

Select Dictionary Program Fields (F6) 

Table Name: KNA1 

Select: Kunnr, Land1, Name1, Ort01, Pstlz, Stras 

Place 3 Push buttons (starting from 6th option) on Tool bar 

    - Button 1 → Text: Display, FCT Code: Display 

    - Button 2 → Text: Clear, FCT Code: Clear 

    - Button 3 → Text: Exit, FCT Code: Exit 

Flow Logic button (F9) 

Remove comment for MODULE USER_COMMAND_100 

Double click on USER_COMMAND_100 → Create → Main Program 

Code Section:

TABLES: KNA1.

 

DATA: BEGIN OF wa_kna1,

  Land1 TYPE land1,

  Name1 TYPE name1,

  Ort01 TYPE ort01,

  Pstlz TYPE pstlz,

  Stras TYPE stras,

END OF wa_kna1.

 

CASE SY-UCOMM.

  WHEN ‘Display’.

    SELECT SINGLE land1 name1 ort01 pstlz stras INTO wa_kna1 FROM KNA1

    WHERE kunnr EQ KNA1-kunnr.

  WHEN ‘Clear’.

    CLEAR: wa_kna1, KNA1-kunnr.

  WHEN ‘Exit’.

    LEAVE PROGRAM.

ENDCASE.

Continue in STATUS_100:

KNA1-land1 = wa_kna1-land1.

KNA1-name1 = wa_kna1-name1.

KNA1-ort01 = wa_kna1-ort01.

KNA1-pstlz = wa_kna1-pstlz.

KNA1-stras = wa_kna1-stras.

 

Step-3:

Go to SE93 

Transaction Code: ZCUSTOMER 

Create 

Title: T code for Customer Details 

Program: ZSD_CUSTOMER_DETAILS 

Screen Number: 100 

Save 

Run the T code (ZCUSTOMER) 

 

Brief Flow:

  1. PBO (Screen is called)
  2. PAI (Triggers when a Button is selected)
  3. PBO (Carries data from Program to Screen)


Debugging a Module Pool Program:

Go to SE38 → Program: ZSD_CUSTOMER_DETAILS → Change 

Place cursor at WHEN ‘DISPLAY’ → Select Stop 

Place cursor between MODULE...ENDMODULE of STATUS_100 → Select Stop 

Run T code (ZCUSTOMER) 


Sub Screen Area:

  • It is a location where sub screens can be called in Main screen

Note:
In SAP, you can create only 1 Normal Screen in an application; remaining all are Sub screens


Requirement:

Syntax for Calling Sub Screen:

CALL SUBSCREEN <sub screen area name> INCLUDING <program name> <sub screen number>.

Example:

CALL SUBSCREEN SUB INCLUDING ‘ZMM_MATERIAL_SUB’ ‘110’.

Solution:
Step-1:

Go to SE38 

Program: ZMM_MATERIAL_SUB 

Create 

Title: Materials Details with Sub Screen 

Type: Module Pool 

Save 

Package: ZABAP 

Create Request 

Short Description: MM/ABAP: Materials Details with Sub Screen

Step-2:

Go to SE51 

Program: ZMM_MATERIAL_SUB 

Screen: 100 → Create → Layout 

Add Field: matnr (from MARA) 

Place Sub Screen Area: SUB 

Add Buttons: Display, Clear, Exit 

Flow Logic → MODULE USER_COMMAND_100 → Main Program 

Code:

TABLES: MARA, MAKT.

 

CASE SY-UCOMM.

  WHEN ‘DISPLAY’.

    SELECT SINGLE mtart matkl brgew ntgew spart FROM MARA

    INTO (MARA-mtart, MARA-matkl, MARA-brgew, MARA-ntgew, MARA-spart)

    WHERE matnr = MARA-matnr.

 

    SELECT SINGLE maktx FROM MAKT INTO MAKT-maktx

    WHERE matnr = MARA-matnr AND spras = ‘EN’.

  WHEN ‘CLEAR’.

    CLEAR: MARA, MAKT.

  WHEN ‘EXIT’.

    LEAVE PROGRAM.

ENDCASE.

Flow Logic in PBO:

CALL SUBSCREEN SUB INCLUDING ‘ZMM_MATERIAL_SUB’ ‘110’.

Create Sub Screen 110:

Screen Type: Sub Screen 

Layout → Place box → Title: Material Details 

Add Fields: matnr, matkl, brgew, ntgew, spart (from MARA) 

Add Field: maktx (from MAKT) 

Flow Logic → Activate screen 

Step-3:

Go to SE93 

T-Code: ZMATERIAL 

Title: T code for Materials Details 

Program: ZMM_MATERIAL_SUB 

Screen: 100 

Save 

Run T code (ZMATERIAL) 

🧩 Sub Objects in ABAP Editor

 

Sub Objects in ABAP Editor:
1. Source Code
2. Variants
3. Attributes
4. Documentation
5. Text Elements

πŸ”Ή 1. Source Code

  • It is nothing but the source code of a program.

πŸ”Ή 2. Attributes

  • It specifies attributes of a program such as: Title, Type, Date of creation & change...and more

πŸ”Ή 3. Documentation

  • Using this option, you can provide documentation for a program.

πŸ”Έ Example:

Go to SE38 Program: ZDEMO Documentation Change Provide Purpose: The report is displaying segment wise materials details Provide Integration: No Provide Prerequisites: s_matnr s_werks Save

πŸ”Ή 4. Text Elements

  • Using Text Elements, you can maintain Labels or Selection Screen Fields.

πŸ”Έ Example:

Go to SE38Program: ZDEMOText ElementsChangeSelection Text Name Text s_matnr Material Code s_werks PlantActivate

πŸ”Ή 5. Variants

  • Using Variants, you can provide default input values for a Selection Screen.
  • In background scheduling reports, the reports are executed automatically by the system in the background. For such reports, input values are supplied using Variants.

πŸ”Έ Example:

➤ Go to SE38 ➤ Program: ZDEMO ➤ Variants ➤ Change ➤ Variant: ZVAR ➤ Create ➤ Enter input values i.e. 100-100 to 100-500Select Attribute option (F6) ➤ Meaning: Variant Creation ➤ Save ➤ Run the report ➤ Select Get Variant optionDouble click on variant name (ZVAR)

πŸ“„ Version Management in SAP ABAP

 

Using Version Management, you can get the history of a program with:

  • Request Numbers
  • User Name
  • Date of creation & change

  • It is highly useful to the programmer if required to retrieve an old version instead of the current version

πŸ”Έ Example:

➤ Go to SE38 ➤ Program: ZDEMO ➤ Select Utilities → Versions → Version Management


❓ Ques: How can you store an object from Local Object to existing Package?

➤ Go to SE38 ➤ Program: name which is stored in Local objectSelect Goto → Object Directory Entry ➤ Select Change option ➤ Package: ZABAP ➤ Save


❓ Ques: How can you delete an object from an existing Request Number?

➤ Go to SE11 ➤ Database Table: E071 ➤ Display ➤ Contents optionObject Name: program name (ZDEMO) ➤ Execute (F8) ➤ Go to SE10 ➤ Select Display ➤ Expand Main Request Number ➤ Expand Sub Request Number ➤ Expand Program optionSelect your program ➤ Select Delete option ➤ You will find a message, Enter ➤ Yes

Sunday, June 29, 2025

πŸ•’Background Job in SAP ABAP

What Is Background Job?

• It is a non-interactive process that runs behind normal interactive operations.

• They run in parallel and do not disturb interactive (Foreground jobs) processes and operations.

• Background jobs are also known as batch jobs in the SAP system that run in the background without affecting the normal operations in the system. Background jobs are used to reduce manual effort and automate the process.

• They can run in the background without any user input and can be scheduled to run when the system load is low.

• It is scheduled by using SM36. Also, can be analyzed using Tcode SM37.

Advantages of Background Jobs:

• It reduces manual effort & automates the task.

• It can be scheduled as per the user's choice.

• It reduces user interaction and can run seamlessly in the background without user input.

• By defining the variant for the background job, the user no longer needs to be concerned about inputting a value in the field. As a result, confusion among users is also minimized.

• Suitable for programs that are time-consuming or require significant resources, which can be scheduled to run during low system load periods, typically at night (when the system load is low).

Classification of Background Jobs:

The categorization of background jobs is divided into 3 classes:

Class A comprises critical or high-priority jobs, Class B includes medium-priority jobs, and Class C encompasses low-priority jobs.

1. CLASS A:

• Some urgent or critical tasks must be scheduled with class A priority job.

• Class A priority reserves one or more background work processes.

• User has to check how many background work processes are free.

• Suppose a user chooses 2 background work processes for class B and class C = (Total Number of work processes set in operation modes RZ03) - (Background work processes allowed to Class A category).

2. Class B:

• Once Class A jobs are completed, Class B jobs will start executing in the background before Class C jobs.

3. Class C:

• It runs after both class A and class B jobs are completed.

Status of Background Jobs:

We can check the status of the jobs using Tcode SM37

1. Scheduled:

If you have created a job with the program name and variant, but haven't specified the start conditions such as start date/time, end date/time, frequency, etc., the job status will be set to 'Scheduled'.

2. Released:

The job must meet all the necessary criteria before it can be considered for release status. A start condition is essential for the job to enter the release phase.

3. Ready:

The job has satisfied all necessary conditions and is currently in the queue, awaiting the availability of a free background work process.

4. Active:

This status indicates that the job has running in the background. We cannot change the job's status once it is active.

5. Finished:

The job is executed successfully without any error/interruption. And the task is completed.

6. Cancelled:

It indicates the job has been terminated abnormally. The reason could be: ▪ An administrator intentionally terminates a job. ▪ One of the programs in the job step contains an error like an exception or error message.

Scheduling Methods

Note: We can schedule background jobs in three ways:

  1. By Tcode SM37
  2. By Tcode SE38
  3. Using the Function module

πŸš€ Transport Requests (TR)

 
What is Transport Request (TR) in SAP?

Transport Request is container of changes which is made in SAP Development system as per Customer requirement.

Using TR we can transport or move all changes/ Customize setting from DEV to QA to Production System.

TR Naming Convention

Format: SID<K>90003

  • SID - System Name
  • K - Co file created in Data base
  • 90003 - Number can be anything from starting with 9xxx

Example: If TR DEVK90003 generated in development system then as per naming convention Here SID is DEV

Types of Transport Request

1. Workbench Request

Workbench requests are cross-client. Changes done in one client are automatically reflected in all other clients. If we use ABAP Logic during changes then use Workbench Request.

2. Customizing Request

Customizing requests are client specific. The changes will not be reflected in other clients. for Example if we made changes in DEV-100 system then this will not reflected in DEV-200 system we need to do copy client by TR (T code ; SCC1)

we use this customizing request if not using ABAP Logic during changes in system.

How to Release TR

T-code: SE01

If you know TR number then go to Display tab -> Put TR No. -> Click on Display Push Button.


Steps to Release Transport Request:

  1. Select Sub TR EH7K900456 --> Click on truck Icon Button so that Sub TR will be release.

  2. Again Select Main EH7K900455 --> TR Click on Truck Icon Button so that Main TR will be release

Note: System not allow you release first MAIN TR before release Sub TR.

Status Confirmation

Once you Release TR then Right Check mark will be visible next to TR

How To Revert SAP Released Transport Request To Unreleased Status

If You want change Status of TR from Released to Unreleased then follow below Process.

Step-by-Step Process:

  1. Run T-code SE38 /SA38

  2. Enter Program RDDIT076 in SE38/SA38 & Execute

  3. In the Selection screen Enter Main TR number which you want to change status.

  4. Select TR and Click on binoculars

  5. Click on Pencil Button for Change Mode.

  6. System Allow you change status From "R to D'" & SAVE it

Now TR status Changed as D- Modifiable

For Information Purpose

Types of TR Status Request

Status Description
D Modifiable
R Released

Saturday, June 28, 2025

πŸ”„ Practicals Basics Programs - Imperative Logic 3

✅ Write an executable program that does NOT have a routine.The program should include a work area with 5 fields of different types or more. Then, it must be populated and its fields should be printed one per line, separated by one horizontal line. After testing your program, change the output separating each field by two lines. During this process, refactor your code to include a routine which handles the separation between each line.

πŸ”Έ Solution:

REPORT z_abap101_056. TYPES: BEGIN OF work_area, str TYPE string, date TYPE d, time TYPE t, integer TYPE i, hex TYPE x LENGTH 8, END OF work_area. START-OF-SELECTION. work_area-str = 'This is a string'. work_area-date = '20141225'. " Christmas work_area-time = '134059'. work_area-integer = 101. work_area-hex = '0123456789ABCDEF'. * Before refactoring * WRITE work_area-str. * ULINE. * WRITE work_area-date DD/MM/YY. * ULINE. * WRITE work_area-time. * ULINE. * WRITE work_area-integer. * ULINE. * WRITE work_area-hex. * ULINE. * After refactoring WRITE work_area-str. PERFORM separe_line. WRITE work_area-date DD/MM/YY. PERFORM separe_line. WRITE work_area-time. PERFORM separe_line. WRITE work_area-integer. PERFORM separe_line. WRITE work_area-hex. PERFORM separe_line. *&---------------------------------------------------------------------* *& Form separe_line *&---------------------------------------------------------------------* * Separe each output line *----------------------------------------------------------------------* FORM separe_line. DO 2 TIMES. ULINE. ENDDO. ENDFORM. "separe_line

✅ Write an executable program with a routine that receives a work area containing five different data types and count how many components are not filled. Finally, print result.

πŸ”Έ Solution:

REPORT z_abap101_057. TYPES: BEGIN OF ty_work_area, str TYPE string, date TYPE d, time TYPE t, integer TYPE i, hex TYPE x LENGTH 8, END OF ty_work_area. DATA work_area TYPE ty_work_area. *&---------------------------------------------------------------------* *& Form count_initial_components *&---------------------------------------------------------------------* * Gets a work area, counts how many components are initial and write * the result *----------------------------------------------------------------------* * -->US_WORK_AREA work area *----------------------------------------------------------------------* FORM count_initial_components USING us_work_area TYPE ty_work_area. DATA lv_initial_components_counter TYPE i. IF us_work_area-str IS INITIAL. lv_initial_components_counter = lv_initial_components_counter + 1. ENDIF. IF us_work_area-date IS INITIAL. lv_initial_components_counter = lv_initial_components_counter + 1. ENDIF. IF us_work_area-time IS INITIAL. lv_initial_components_counter = lv_initial_components_counter + 1. ENDIF. IF us_work_area-integer IS INITIAL. lv_initial_components_counter = lv_initial_components_counter + 1. ENDIF. IF us_work_area-hex IS INITIAL. lv_initial_components_counter = lv_initial_components_counter + 1. ENDIF. WRITE: 'Initial components: ', lv_initial_components_counter. NEW-LINE. ENDFORM. "count_initial_components START-OF-SELECTION. PERFORM count_initial_components USING work_area. work_area-str = 'This is a string'. PERFORM count_initial_components USING work_area. work_area-date = '20141225'. " Christmas PERFORM count_initial_components USING work_area. work_area-time = '134059'. PERFORM count_initial_components USING work_area. work_area-integer = 101. PERFORM count_initial_components USING work_area. work_area-hex = '0123456789ABCDEF'. PERFORM count_initial_components USING work_area.

✅ Write an executable program with a routine that receives a work area with at least 4 components.All components can only be declared using numeric and different primitive types. Your routine should sum the values from all components and print the result.

πŸ”Έ Solution:

REPORT z_abap101_058. TYPES: BEGIN OF ty_work_area, integer TYPE i, float TYPE f, pack TYPE p LENGTH 8 DECIMALS 3, decfloat34 TYPE decfloat34, END OF ty_work_area. *&---------------------------------------------------------------------* *& Form sum_numeric_components *&---------------------------------------------------------------------* * Receives a work area with numeric components and sum them. *----------------------------------------------------------------------* * -->US_WA Work area with numeric components *----------------------------------------------------------------------* FORM sum_numeric_components USING us_wa TYPE ty_work_area. DATA lv_sum_result TYPE decfloat34. lv_sum_result = us_wa-integer + us_wa-float + us_wa-pack + us_wa-decfloat34. WRITE lv_sum_result. NEW-LINE. ENDFORM. "sum_numeric_components START-OF-SELECTION. DATA work_area TYPE ty_work_area. DATA work_area_doubled TYPE ty_work_area. work_area-integer = 2. work_area-float = '2.5'. work_area-pack = '2.12345'. work_area-decfloat34 = 1000000000000000000000000000000. PERFORM sum_numeric_components USING work_area. work_area_doubled-integer = work_area-integer * 2. work_area_doubled-float = work_area-float * 2. work_area_doubled-pack = work_area-pack * 2. work_area_doubled-decfloat34 = work_area-decfloat34 * 2. PERFORM sum_numeric_components USING work_area_doubled.

✅ Write an executable program with a routine that receives a work area with 3 char components and 3 numeric components. The routine should clear some component values according to the following rules:
1. Clear char components only if the sum of the numeric components is odd (ignoring possible decimal places)
2. Clear numeric components only if the sum of vowels in the three char components is even (ignoring lower/upper case)

πŸ”Έ Solution:

REPORT z_abap101_059. TYPES: BEGIN OF ty_char_and_numeric, char_comp1 TYPE string, char_comp2 TYPE c LENGTH 3, char_comp3 TYPE n LENGTH 10, num_comp1 TYPE i, num_comp2 TYPE f, num_comp3 TYPE decfloat16, END OF ty_char_and_numeric. *&---------------------------------------------------------------------* *& Form clear_char_or_numeric *&---------------------------------------------------------------------* * This routine clears some component values according to the following rules: * a. Clear char components only if the sum of the numeric components is odd * (ignoring possible decimal places) * b. Clear numeric components only if the sum of vowels in the three char * components is even (ignoring lower/upper case) *----------------------------------------------------------------------* * -->US_WA_CHAR_AND_NUMERIC text *----------------------------------------------------------------------* FORM clear_char_or_numeric USING us_wa_char_and_numeric TYPE ty_char_and_numeric. DATA lv_mod_result TYPE i. DATA lv_sum_numeric TYPE i. lv_sum_numeric = us_wa_char_and_numeric-num_comp1 + us_wa_char_and_numeric-num_comp2 + us_wa_char_and_numeric-num_comp3. lv_mod_result = lv_sum_numeric MOD 2. IF lv_mod_result <> 0. CLEAR: us_wa_char_and_numeric-char_comp1, us_wa_char_and_numeric-char_comp2, us_wa_char_and_numeric-char_comp3. RETURN. ENDIF. DATA lv_vowel_count TYPE i. DATA lv_current_vowel_count TYPE i. FIND ALL OCCURRENCES OF REGEX 'a|e|i|o|u|A|E|I|O|U' IN us_wa_char_and_numeric-char_comp1 MATCH COUNT lv_current_vowel_count. lv_vowel_count = lv_vowel_count + lv_current_vowel_count. FIND ALL OCCURRENCES OF REGEX 'a|e|i|o|u|A|E|I|O|U' IN us_wa_char_and_numeric-char_comp2 MATCH COUNT lv_current_vowel_count. lv_vowel_count = lv_vowel_count + lv_current_vowel_count. FIND ALL OCCURRENCES OF REGEX 'a|e|i|o|u|A|E|I|O|U' IN us_wa_char_and_numeric-char_comp3 MATCH COUNT lv_current_vowel_count. lv_vowel_count = lv_vowel_count + lv_current_vowel_count. lv_mod_result = lv_vowel_count MOD 2. IF lv_mod_result = 0. CLEAR: us_wa_char_and_numeric-num_comp1, us_wa_char_and_numeric-num_comp2, us_wa_char_and_numeric-num_comp3. RETURN. ENDIF. ENDFORM. "clear_char_or_numeric START-OF-SELECTION. DATA wa_char_cleared TYPE ty_char_and_numeric. DATA wa_numeric_cleared TYPE ty_char_and_numeric. wa_char_cleared-char_comp1 = 'This should be clea'. wa_char_cleared-char_comp2 = 'red'. wa_char_cleared-char_comp3 = '0123456789'. wa_char_cleared-num_comp1 = 1. wa_char_cleared-num_comp2 = 10. wa_char_cleared-num_comp3 = 100. WRITE: wa_char_cleared-char_comp1, wa_char_cleared-char_comp2, wa_char_cleared-char_comp3, wa_char_cleared-num_comp1, wa_char_cleared-num_comp2, wa_char_cleared-num_comp3. NEW-LINE. PERFORM clear_char_or_numeric USING wa_char_cleared. WRITE: wa_char_cleared-char_comp1, wa_char_cleared-char_comp2, wa_char_cleared-char_comp3, wa_char_cleared-num_comp1, wa_char_cleared-num_comp2, wa_char_cleared-num_comp3. NEW-LINE. ULINE. wa_numeric_cleared-char_comp1 = 'aeiouAEIOU'. wa_numeric_cleared-char_comp2 = 'BCD'. wa_numeric_cleared-char_comp3 = '0123456789'. wa_numeric_cleared-num_comp1 = 2. " even wa_numeric_cleared-num_comp2 = 10. wa_numeric_cleared-num_comp3 = 100. WRITE: wa_numeric_cleared-char_comp1, wa_numeric_cleared-char_comp2, wa_numeric_cleared-char_comp3, wa_numeric_cleared-num_comp1, wa_numeric_cleared-num_comp2, wa_numeric_cleared-num_comp3. NEW-LINE. PERFORM clear_char_or_numeric USING wa_numeric_cleared. WRITE: wa_numeric_cleared-char_comp1, wa_numeric_cleared-char_comp2, wa_numeric_cleared-char_comp3, wa_numeric_cleared-num_comp1, wa_numeric_cleared-num_comp2, wa_numeric_cleared-num_comp3. NEW-LINE.

✅ Write an executable program which contains three internal tables (their type must contain at least three components of different data types). Each table will have a different type (standard, sorted and hashed). Add 3 identical values in each table and view the contents of each table in the debugger.

πŸ”Έ Solution:

REPORT z_abap101_060. TYPES: BEGIN OF ty_line, id TYPE c LENGTH 10, name TYPE string, value TYPE i, END OF ty_line. DATA it_standard TYPE STANDARD TABLE OF ty_line. DATA it_sorted TYPE SORTED TABLE OF ty_line WITH UNIQUE KEY id. DATA it_hashed TYPE HASHED TABLE OF ty_line WITH UNIQUE KEY id. START-OF-SELECTION. DATA wa TYPE ty_line. wa-id = '3'. wa-name = 'John'. wa-value = 50. APPEND wa TO it_standard. INSERT wa INTO TABLE it_sorted. INSERT wa INTO TABLE it_hashed. wa-id = '2'. wa-name = 'Mary'. wa-value = 60. APPEND wa TO it_standard. INSERT wa INTO TABLE it_sorted. INSERT wa INTO TABLE it_hashed. wa-id = '1'. wa-name = 'Max'. wa-value = 30. APPEND wa TO it_standard. INSERT wa INTO TABLE it_sorted. INSERT wa INTO TABLE it_hashed. BREAK-POINT.

πŸ“š SAP ABAP Data Dictionary

The transaction of the database dictionary is SE11. It is a central repository to create objects and to store the data. An advantage of a data dictionary is reusability - once an object is developed in a data dictionary it can be used in any program throughout the SAP.

Creating Database Tables

Radio Button 1: Database Table Overview

Database table is a combination of structure and table data (table structure consists of field name and table data will store the business data like master and transaction data) in which we can display, Create, and Update the changes in the table.

Step-by-Step Table Creation Process

Let's create a table zcustomer_tabl table.

Step 1: Table Name Creation

Write the name of the table that you want to create in the box. If that name is already taken by another table write another name, and click on create button.

Step 2: Short Description

We need to write a short description first (any meaningful description regarding tables like customer information).

Step 3: Delivery Class Configuration

Then we need to provide a delivery class in the delivery and maintenance tab. It is a tick mark field which means it is a mandatory field we need to provide value here otherwise it will throw an error (compulsory otherwise we cannot proceed further).

Select the search help near the box or press F4. It will display the search help bar. We have 7 types of delivery classes:

  • A - Application table (master and transaction table - 99% we will work with master and transaction data)
  • C - Customizing table (we can make direct changes only in customizing server only not in the production server)
  • L - Used by application programmers
  • G, E, S, W - Used by SAP only

 
Understanding Data Types

Master Data - It is only created once in the database (e.g., Bank Master).

Transaction Data - Which is created frequently or changes frequently (e.g., deposit, withdraw).

Delivery Class - It is used to control the Transport of the table data. It is used to specify the type of the table.

  • In Real time we mostly use the delivery class 'A'
  • In the case of delivery class 'A' the table can maintained in any system (development, quality, production systems) using SM30

Data Browser/Table View Maintenance

This property is used to specify whether the table can be maintained or not. In real time we mostly use "Display/maintenance allowed" option.

It is of 3 types:

  1. Display/Maintenance allowed with Restrictions - We can only Display the data. Create, or change is not possible
  2. Display/Maintenance allowed - We can Display, Create, Change directly
  3. Display/Maintenance not allowed - We cannot create, display, or change the data directly

Step 4: MANDT Field Configuration

In the fields tab while creating a table in SAP, the first field always be MANDT and it is always the primary key, it is a non-transportation object.

MANDT - Using mandt we can restrict the data across the client (dev and unit test system). Whatever data we have entered in the development server should not be there in another system like a unit test server, that is why we have to use the mandt field.

Step 5: Primary Key Definition

Then write your all fields in a single table. Min. 1 primary key is mandatory and max. 16 primary keys allowed, tick key button, and initial checkbox.

  • The key checkbox will tell us that the field is a primary key
  • An initial checkbox will tell us that the column cannot be NULL

Step 6: Field Definition

Then write the field name that you want to insert into the table. We can give the data type and field description directly but we will lose the features like search help and value range which are given through data element and domain level only.

Step 7: Technical Settings

After defining the data type with their corresponding fields we need to give a technical setting that consists of data class and size category.

Data Class - Is used to specify the type of the data to be maintained in the table. Data class provides what type of table it is:

  • APPL0 (master data class) - The data which is not changing frequently (e.g., DATE OF BIRTH)
  • APPL1 (transaction data class) - The data which is changing frequently (e.g., SALARY)
  • APPL2 (organizational data class) - The data which is changing rarely (e.g., COMPANY CODE)

In Real time we mostly use APPL0 or APPL1.

Size Category - Size category ranges from 0 to 8. It determines the space required for the table.

  • It is used to specify the initial space required for the table in the database
  • In real time we mostly use '0' category (0 – 8) -> [0 – 2700]
  • 0 means e.g., 8kb it will reserve 8kb of space in the main memory

Step 8: Currency and Weight Fields

If you want to add any currency or weight field you need to define the reference table and reference field. Because every Country has different measuring units that is why SAP has made it mandatory.

Activate it.

Enhancement Category

EXTRAS -> ENHANCEMENT CATEGORY

Enhancement category is used to enhance the particular fields of the table. In Real time we mostly use Can be enhanced (DEEP).

  • If we want to add any fields in the future we have to choose can be enhanced
  • If we don't want to add any fields then cannot be enhanced
  • If not sure then select not classified

Foreign Key Relationships

FOREIGN KEY - Select the row in which you want to add a foreign key with the parent table click on the key icon. It will ask for a check table which will be the parent table that gives the name of a parent table.

Click on the proposal it will give you the field name in which the foreign key can be maintained. Select on that field click on ok. That field will be added as the foreign key. Parent table is called check table and we can maintain foreign key with its primary key and child table column but data element must be same to apply foreign key in the child table.

It gives data element level field validation.

Cardinality Ratio = Single record of a header table corresponds to multiple records of a Secondary table.

Text Tables

Text Table – These are Tables That hold the Description of the Parent Table.

Creating Text Tables

Step 1: Create A Parent Table

Step 2: Create a text table

2nd key always be langu in the text table.

Step 3: Create a foreign key relationship

  • Mark 1st row and select foreign key button
  • Mark 2nd row which is langu and select foreign key button
  • Mark the 3rd row select the foreign key button and give the parent table name in the check table field
  • Mark the radio button Key fields of a text table
  • Cardinality 1:N
  • Create a proposal and click on copy

Text table is now created.

Step 4: Check the text table in the parent table

It will show text table was created or not.

Index Tables

INDEX TABLE - To improve the performance of select queries. Suppose, your query is taking too much time to execute then to resolve that issue we need to create an index table. E.g., bseg, mseg, lips etc.

We create index tables in very rare cases, especially in the ECC system. Not necessarily in the Hana system because the Hana system is very fast.

Advantages

  • It gives high performance
  • It stores the data always in sorted order

Disadvantages

  • It occupies space from the table in which the index table is being created which will reduce the performance of the database table, which is why it is recommended to create an index table very rarely

Types of Index

Primary Index

Primary Key will act as Primary Index. We can create Primary Key for custom Table only. SAP automatically creates a primary key index implicitly, when we activate our database tables.

When we search the record in any tables based on the primary key it always gives high performance.

Secondary Index

These are created and maintained by the Technical Consultants/ABAPer. Based upon our requirement, we will create a secondary Index. Maximum 9 Secondary Index we can create in a table. Secondary Index is possible for both Standard and Custom Tables.

Creating Index Tables

  1. STEP 1: CLICK IN INDEX TAB
  2. Step 2: Click on create button then create index
  3. Step 3: Give 3 digit Index Name Starting with Z and click Continue
  4. Step 4: Give a Short Description and field Names that you want to use in your program
  5. Step 5: Give Field Names and Activate your index table

Buffering

Overview

Buffering is a temporary storage on the application layer. There are 3 layers in SAP:

  1. Presentation Layer – In which we interact with SAP system
  2. Application layer – In which we write our programs
  3. Database layer – In which tables data are residing there (it is a permanent storage)

It improves the performance when accessing the data records contained in the table. Sometimes, we need to access a particular set of records more frequently than others. Accessing Records Directly from a database table can be very time-consuming.

Buffering Options

  1. Buffering not allowed – Table buffering Is not performed for the table
  2. Buffering Switched on – Table Buffering is Performed for the table
  3. Buffering allowed, but switched off - Buffer is allowed but It is switched off and can be switched on anytime according to the requirement of the customer

Types of Buffering

1. Single Record Buffering

In the case of single record buffering single record load in the buffer at a time.

When to use: Single record Buffering should be used for tables where single records are accessed by specifying the complete Key.

Advantages:

  • This type of Buffering requires less memory on the application layer

Disadvantages:

  • There is no Significant reduction in the number of database access

2. Full Record Buffering

In the case of Full Record Buffering, The Full Records of a table load in the buffer.

When to use: Tables that are best suited for full record buffering are frequently accessed and rarely changed. Tables that contain transaction data should not go for full record buffering.

Advantages:

  • There is a Significant reduction in no. of database access

Disadvantages:

  • This type of buffering requires more space on the application layer

3. Generic Area Buffering

The records that match the generic key are loaded in the buffer. The best example of generic area buffering is language-dependent tables.

In the case of Generic Area Buffering we need to pass the number of key fields. The number of key fields for a generic area buffering is less than the primary key of a table.

Important Points in Buffering

  1. If we don't need buffering select checkbox buffering allowed but switched off
  2. If we want to reset the buffer of a particular table never use t-code /$TAB. This t-code will reset the buffer of all tables not a single table
  3. We can pass the table in t-code AL12 to reset the buffer of a particular table

Table Maintenance Generator (TMG)

Table Maintenance Generator - It is used to maintain multiple entries & validate the table data using the T-code SM30.

In real-time users cannot access SE11 code. Using a tool called TMG users can perform data entry (DML operation - insert, update, delete). In TMG, Users can perform operations to a particular table plus they will be restricted to a particular table only.

Steps for Working with TMG

  1. Execute SE11
  2. Select the Radio button DB Table
  3. Provide the Table name & click on change
  4. Click on utilities
  5. Click on TMG
  6. Select the auth. group as &NC& and Provide the function group as your table name
  7. Select the one-step radio button
  8. Enter the overview screen number (could be any). [4 digit only]
  9. Click on the create icon(F6) and click on save
  10. Press the enter button & Click on Local Object or TR and click on Back
  11. Test TMG through SM30
  12. Create t-code in SE93 (same name as table name)

Maintenance Types

  • One-step - Data entry (multiple records) if our table has fewer fields then select one step
  • Two-step - Data entry (record by record) if our table has more fields then select two steps

Recording Routine

  • Standard recording routine - It will ask for transport requests
  • No, or user, recording routine - It will not ask for transport requests

Events in TMG

Validation can be done by Table events using SM30. Totally 38 events are there in TMG.

Mostly we use these 5 events in real life:

  1. Before saving the data in the database
  2. After saving the data in the database
  3. Before deleting the data display
  4. After deleting the data display
  5. Creating a new entry

Important Points in TMG

  1. To generate the TMG, data browser/table view maintenance options need to be - display/maintenance allowed
  2. Whenever we add new columns/fields to the table after the generation of TMG, the newly added fields do not appear automatically while maintaining data with the help of SM30. We need to delete the TMG and generate it again
  3. To delete the TMG, open the table in change mode, otherwise delete button does not appear

Database Utility

Database Utility acts as an Interface between the ABAP dictionary and the database.

We can call the database utility from the initial screen of the ABAP dictionary with utilities -> Database utility (T-Code: SE14).

Purpose of Database Utility

  1. To check the default value of table fields
  2. To adjust the table data

Important point: Do not perform any database operation on the table while performing the database utility. If you do that it will delete the data from the table.

Data Browser

The t-code for data browser is SE16. Through data browser we can view the data of a table. From SE11 we can navigate SE16 data browser. The t-code for new data browser is SE16N.

Types of Database Tables

There are 3 types of database tables:

1. Transparent Table

In case of transparent table, there is a relationship between the ABAP dictionary and the database.

2. Pooled Table

In the case of a pooled table, there is an N:1(many to one) relationship between the ABAP dictionary and the database. For pooled tables, a primary-foreign key relationship is not required.

Table pool structure: Tabname Varkey Dataln Vardata

3. Cluster Table

In case of cluster table, there is N:1(many to one) relationship between the ABAP dictionary and the database. For cluster tables, primary-foreign key relationship is mandatory.

Table cluster structure: Key Pageno Vardata

Views

Views - Views is a virtual table. View does not have any data. It is bringing the data from a table. View is a logical database because it has no data while table is a physical database it has its own data.

The View is a virtual table that gets the field and data from other tables.

Table vs View Comparison

Table:

  • Having fields and we can store data
  • A table has a technical setting
  • In a table, we can store 1 kind of data either master or transaction
  • Additional resources are required to maintain tables like technical setting, data class, size category that is why they have poor performance compared to views

View:

  • In view, we get the field and data from other table
  • Views don't have technical settings
  • In views we can view both master and transaction data simultaneously
  • No additional Resources are required (Good Performance)

Types of Views

1. Database View

It is created based on 1 or more than 1 table using join condition. Tables Should have relationship between to create Database View.

In the database view, the maintenance status is read-only which means we can not change the data we can see only in the database we can put selection conditions.

2. Projection View

Projection view only creates with a single table called a basis table. Suppose if a table has 200 columns and we want to show only 5 columns then we will use projection view.

Maintenance status is always in change and display mode.

3. Maintenance View

It is also known as a Table maintenance generator. Its purpose is to maintain multiple table. The tables must have relationship between them. Take mandt field in the maintenance view.

4. Help View

It is also called search help. The tables must have relationship between them.

Important Points: Not more than 1 record should exist in the dependent/Secondary table.