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) 

No comments:

Post a Comment