0% found this document useful (0 votes)
3 views13 pages

SAP ABAP ModulePool SalesOrder ProjectNotes

The document outlines the development of a Sales Order Creation screen using SAP ABAP Module Pool Programming, detailing objectives, scope, program architecture, and screen design. It includes specifications for user input fields, validation logic, and transaction codes necessary for implementation. Additionally, it provides guidelines for testing and common pitfalls to avoid during development.

Uploaded by

kolluraghavendra
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views13 pages

SAP ABAP ModulePool SalesOrder ProjectNotes

The document outlines the development of a Sales Order Creation screen using SAP ABAP Module Pool Programming, detailing objectives, scope, program architecture, and screen design. It includes specifications for user input fields, validation logic, and transaction codes necessary for implementation. Additionally, it provides guidelines for testing and common pitfalls to avoid during development.

Uploaded by

kolluraghavendra
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

SAP ABAP Module Pool Programming | Sales Order Creation Screen | Project Notes

SAP ABAP
Module Pool Programming
Sales Order Creation Screen — Project Notes

Project Overview Document


Prepared for: SAP ABAP Development Team
Document Version: 1.0 | Date: April 2026

1. Project Overview

1.1 Objective
To develop a fully functional Sales Order Creation screen using SAP ABAP Module Pool (Dialog)
Programming. The screen allows end-users to enter sales order details — customer, material, quantity,
price, and delivery date — and persist the data to the SAP database with full validation, error handling,
and GUI controls.

1.2 Scope
• Design and implement a module pool program of type M (SAPMZSALES_ORDER)
• Create and configure Screen 0100 in the Screen Painter (SE51)
• Build GUI Status and Title in the Menu Painter (SE41)
• Implement PBO and PAI event modules with full business logic
• Add field-level validations with meaningful error messages
• Enable F4 value help for key fields (Customer, Material)
• Save validated data to SAP database tables (VBAK, VBAP)
• Assign a transaction code (ZSO_CREATE) via SE93

1.3 Key Transactions Used

Transaction Code Purpose

SE38 / SE80 ABAP Editor / Object Navigator — write and manage the module pool
program
SAP ABAP Module Pool Programming | Sales Order Creation Screen | Project Notes

Transaction Code Purpose

SE51 Screen Painter — design screen layout and write flow logic

SE41 Menu Painter — define GUI Status, toolbar buttons, and window title

SE93 Transaction Maintenance — assign ZSO_CREATE to


SAPMZSALES_ORDER, screen 0100

SE11 ABAP Dictionary — inspect VBAK, VBAP, and KNA1 table structures

SM30 Table Maintenance — verify saved sales order records

SE37 Function Module Browser — locate F4 and number range FMs

/nZSO_CREATE Execute the Sales Order Creation transaction (end-user entry point)
SAP ABAP Module Pool Programming | Sales Order Creation Screen | Project Notes

2. Program Architecture

2.1 Program Type and Includes


Module pool programs use TYPE M and cannot be executed directly — they are always invoked via a
transaction code. The main program acts as a container; all functional code lives in INCLUDE programs
to keep the codebase maintainable.

PROGRAM sapmzsales_order.

INCLUDE mzsales_order_top. " Global data declarations


INCLUDE mzsales_order_o01. " PBO modules (OUTPUT)
INCLUDE mzsales_order_i01. " PAI modules (INPUT)
INCLUDE mzsales_order_f01. " FORM subroutines

2.2 Global Data (TOP Include)


All variables shared across screens and modules are declared in the TOP include. The TABLES
statement is mandatory — it creates a screen-compatible structure that SAP uses to automatically
transport data between the screen fields and program memory by name matching.

TABLES: vbak, vbap, kna1.

DATA: gv_vbeln TYPE vbak-vbeln,


gv_kunnr TYPE vbak-kunnr,
gv_matnr TYPE vbap-matnr,
gv_kwmeng TYPE vbap-kwmeng,
gv_netpr TYPE vbap-netpr,
gv_edatu TYPE vbap-edatu,
gv_ok_code TYPE sy-ucomm,
gv_save_flag TYPE c.

DATA: gt_items TYPE TABLE OF vbap,


gs_item TYPE vbap.

Field names on the screen (defined in SE51) must EXACTLY match the ABAP variable or
KEY RULE structure field names. SAP uses this name-match to automatically move data between the
screen and program memory — a mismatch means the field simply will not transport.

3. Screen Design (SE51)

3.1 Screen Attributes — Screen 0100


SAP ABAP Module Pool Programming | Sales Order Creation Screen | Project Notes

Attribute Value / Explanation

Screen Number 0100 (main data entry screen)

Short Description Sales Order Creation

Screen Type Normal (full-screen dialog)

Next Screen 0 (return to caller when flow logic completes)

Hold Data Checked (field values persist if user navigates away and returns)

Lines / Columns Set according to SAP system defaults (typically 25 lines)

3.2 Screen Fields Layout


The following fields are placed on screen 0100 using the Screen Painter's graphical layout editor. Field
names must map directly to the global ABAP variable names.

Screen Field Name Type / Length Description

GV_KUNNR CHAR 10 / Input Customer number — links to


KNA1

VBAK-AUDAT DATS 8 / Input Sales order date

GV_MATNR CHAR 18 / Input Material number — links to MARA

GV_KWMENG QUAN 13 / Input Order quantity

GV_NETPR CURR 11 / Input Net price per unit

GV_EDATU DATS 8 / Input Requested delivery date

GV_VBELN CHAR 10 / Output only Generated sales order number


(display after save)

3.3 Screen Field Attributes


• Required (Mandatory): GV_KUNNR, GV_MATNR, GV_KWMENG — these fields must be filled
before PAI proceeds
• Output Only: GV_VBELN — set screen-input = 0 in PBO so the user cannot edit the generated
number
• F4 Help: Assign search help objects to GV_KUNNR (SH_KUNNR) and GV_MATNR
(SH_MATNR) in SE11
• Display-only labels: Created using Text elements (type T) in the layout editor
SAP ABAP Module Pool Programming | Sales Order Creation Screen | Project Notes

4. Screen Flow Logic (SE51 Flow Logic Editor)

4.1 Complete Flow Logic — Screen 0100


Flow logic is pseudo-ABAP written in the Screen Painter's Flow Logic tab. It is NOT standard ABAP — it
uses special screen-only keywords. The FIELD … MODULE construct is the key performance
optimization: it triggers the named module only when that specific field was changed by the user.

PROCESS BEFORE OUTPUT.


MODULE status_0100.
MODULE populate_defaults.
MODULE modify_screen_fields.

PROCESS AFTER INPUT.


MODULE exit_command AT EXIT-COMMAND.
FIELD gv_kunnr MODULE validate_customer.
FIELD gv_matnr MODULE validate_material.
FIELD gv_kwmeng MODULE validate_quantity.
FIELD gv_netpr MODULE validate_price.
FIELD gv_edatu MODULE validate_delivery_date.
MODULE user_command_0100.

PROCESS ON VALUE-REQUEST.
FIELD gv_kunnr MODULE f4_customer.
FIELD gv_matnr MODULE f4_material.

The MODULE exit_command AT EXIT-COMMAND clause is critical. Without it, pressing


AT EXIT- BACK or CANCEL triggers all field-level validations first. AT EXIT-COMMAND fires
COMMAND BEFORE all validations, allowing the user to leave the screen cleanly even if mandatory
fields are empty.

5. PBO Modules (Process Before Output)

5.1 Overview
PBO fires every time the screen is about to be displayed to the user — on initial load and after every PAI
cycle that does not leave the screen. PBO's job is to set up the GUI environment and populate or refresh
field values.

5.2 Module: status_0100


Sets the active GUI Status and screen title. Both must be pre-created in SE41.

MODULE status_0100 OUTPUT.


SET PF-STATUS 'STATUS_0100'.
SET TITLEBAR 'TITLE_0100'.
ENDMODULE.
SAP ABAP Module Pool Programming | Sales Order Creation Screen | Project Notes

STATUS_0100 is defined in SE41 with the following function codes active:

Function Code Button / Key

SAVE Save button (F11) — triggers save logic in PAI

BACK Back button (F3) — returns to previous screen

EXIT Exit button (Shift+F3) — exits to SAP Easy Access

CANCEL Cancel button (F12) — discards changes and exits

CUST_F4 Custom F4 search (optional explicit trigger)

5.3 Module: populate_defaults


MODULE populate_defaults OUTPUT.
IF gv_edatu IS INITIAL.
gv_edatu = sy-datum. " Default: today's date
ENDIF.
IF gv_vbeln IS INITIAL.
CLEAR gv_vbeln. " No order number yet
ENDIF.
ENDMODULE.

5.4 Module: modify_screen_fields


Controls field visibility, input mode, and mandatory status at runtime using the SCREEN system structure.

MODULE modify_screen_fields OUTPUT.


LOOP AT SCREEN.
CASE screen-name.
WHEN 'GV_VBELN'.
screen-input = 0. " Always read-only
screen-required = 0.
WHEN 'GV_KUNNR' OR 'GV_MATNR' OR 'GV_KWMENG'.
screen-required = 1. " Mandatory fields
ENDCASE.
MODIFY SCREEN.
ENDLOOP.
ENDMODULE.
SAP ABAP Module Pool Programming | Sales Order Creation Screen | Project Notes

6. PAI Modules (Process After Input)

6.1 Exit Command Handler


This must be the very first module in PAI to ensure clean exit without triggering validations.

MODULE exit_command INPUT.


CASE sy-ucomm.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'CANCEL'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.

6.2 Field Validation Modules

MODULE validate_customer INPUT.


IF gv_kunnr IS INITIAL.
MESSAGE 'Customer number is mandatory' TYPE 'E'.
ELSE.
SELECT SINGLE kunnr FROM kna1
INTO gv_kunnr WHERE kunnr = gv_kunnr.
IF sy-subrc <> 0.
MESSAGE e001(zmsg) WITH gv_kunnr.
" 'Customer & does not exist in the system'
ENDIF.
ENDIF.
ENDMODULE.

MODULE validate_material INPUT.


IF gv_matnr IS INITIAL.
MESSAGE 'Material number is mandatory' TYPE 'E'.
ELSE.
SELECT SINGLE matnr FROM mara
INTO gv_matnr WHERE matnr = gv_matnr.
IF sy-subrc <> 0.
MESSAGE e002(zmsg) WITH gv_matnr.
ENDIF.
ENDIF.
ENDMODULE.

MODULE validate_quantity INPUT.


IF gv_kwmeng <= 0.
MESSAGE 'Quantity must be greater than zero' TYPE 'E'.
ENDIF.
ENDMODULE.

MODULE validate_price INPUT.


SAP ABAP Module Pool Programming | Sales Order Creation Screen | Project Notes

IF gv_netpr < 0.
MESSAGE 'Net price cannot be negative' TYPE 'E'.
ENDIF.
ENDMODULE.

MODULE validate_delivery_date INPUT.


IF gv_edatu < sy-datum.
MESSAGE 'Delivery date cannot be in the past' TYPE 'W'.
" TYPE W = warning, allows user to continue
ENDIF.
ENDMODULE.

E (Error): Stops PAI processing. Cursor returns to the offending field with red highlight.
User must correct before proceeding.
MESSAGE W (Warning): Displays warning but allows the user to press Enter once more to proceed.
TYPES I (Information): Shows a modal popup — user must click OK.
S (Success): Displays a non-blocking green status bar message — program continues
normally.

6.3 Central Command Handler


MODULE user_command_0100 INPUT.
gv_ok_code = sy-ucomm.
CLEAR sy-ucomm. " ALWAYS clear to prevent re-trigger

CASE gv_ok_code.
WHEN 'SAVE'.
PERFORM save_sales_order.
WHEN OTHERS.
" Other function codes handled by exit_command module
ENDCASE.
ENDMODULE.

7. F4 Value Help

7.1 Customer F4 Module


F4 modules fire from the PROCESS ON VALUE-REQUEST event and display a search popup so users
can find valid values without memorizing keys.

MODULE f4_customer INPUT.


DATA: lt_customers TYPE TABLE OF kna1,
ls_customer TYPE kna1.

SELECT kunnr name1 FROM kna1


INTO TABLE lt_customers
UP TO 500 ROWS.

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'


EXPORTING
SAP ABAP Module Pool Programming | Sales Order Creation Screen | Project Notes

retfield = 'KUNNR'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'GV_KUNNR'
value_org = 'S'
TABLES
value_tab = lt_customers
EXCEPTIONS
parameter_error = 1
OTHERS = 2.
ENDMODULE.
SAP ABAP Module Pool Programming | Sales Order Creation Screen | Project Notes

8. Save Logic (FORM Subroutine)

8.1 Complete Save Routine


FORM save_sales_order.
DATA: lv_vbeln TYPE vbak-vbeln.

" Step 1: Generate sales order number


CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
nr_range_nr = '01'
object = 'VBELN_VA'
IMPORTING
number = lv_vbeln
EXCEPTIONS
interval_not_found = 1
OTHERS = 2.

IF sy-subrc <> 0.
MESSAGE 'Could not generate order number' TYPE 'E'.
RETURN.
ENDIF.

" Step 2: Populate and INSERT header record


CLEAR vbak.
vbak-mandt = sy-mandt.
vbak-vbeln = lv_vbeln.
vbak-kunnr = gv_kunnr.
vbak-audat = sy-datum.
vbak-erdat = sy-datum.
vbak-erzet = sy-uzeit.
vbak-ernam = sy-uname.
INSERT vbak.

IF sy-subrc <> 0.
MESSAGE 'Header insert failed — order already exists' TYPE 'E'.
ROLLBACK WORK.
RETURN.
ENDIF.

" Step 3: Populate and INSERT item record


CLEAR vbap.
vbap-mandt = sy-mandt.
vbap-vbeln = lv_vbeln.
vbap-posnr = '000010'.
vbap-matnr = gv_matnr.
vbap-kwmeng = gv_kwmeng.
vbap-netpr = gv_netpr.
vbap-edatu = gv_edatu.
INSERT vbap.

IF sy-subrc <> 0.
MESSAGE 'Item insert failed' TYPE 'E'.
ROLLBACK WORK.
SAP ABAP Module Pool Programming | Sales Order Creation Screen | Project Notes

RETURN.
ENDIF.

" Step 4: Commit and confirm


COMMIT WORK AND WAIT.
gv_vbeln = lv_vbeln.
MESSAGE s003(zmsg) WITH lv_vbeln.
" 'Sales order & created successfully'
ENDFORM.

9. Common Pitfalls and Best Practices

Pitfall Symptom Fix

Not clearing sy-ucomm Last function code re-fires after each PAI Always: gv_ok_code = sy-ucomm.
cycle CLEAR sy-ucomm.

MESSAGE 'E' in PBO Screen loops infinitely on load Error messages only in PAI —
never in PBO

Screen field name Data not transported between screen and Field name must exactly match
mismatch program ABAP variable name

Missing AT EXIT- BACK/CANCEL triggers all validations Add MODULE exit_command AT


COMMAND before exit EXIT-COMMAND as first PAI
module

No ROLLBACK on Partial data committed (header with no item) Always ROLLBACK WORK on
failed INSERT any INSERT failure before
RETURN

COMMIT WORK Async commit — data may not be available Use COMMIT WORK AND WAIT
without AND WAIT immediately after for synchronous commit

Using MESSAGE 'E' in F4 popup broken or screen locked Use MESSAGE 'I' or handle errors
F4 module silently in F4 modules

Wrong Next Screen in Screen does not exit after SAVE Set Next Screen = 0 in SE51
attributes screen attributes, or use SET
SCREEN / LEAVE TO SCREEN
dynamically
SAP ABAP Module Pool Programming | Sales Order Creation Screen | Project Notes

10. Testing Checklist

Unit Test Scenarios

Test Case Input / Action Expected Result

Happy path save Fill all fields correctly, click Save (F11) Order created. Success message
with order number. GV_VBELN
populated.

Invalid customer Enter non-existent customer number, press Error E: 'Customer & does not
Enter exist'. Cursor on KUNNR field.

Invalid material Enter non-existent material number Error E: 'Material & does not exist'.
Cursor on MATNR field.

Zero quantity Enter 0 in quantity field Error E: 'Quantity must be greater


than zero'.

Past delivery date Enter a date before today Warning W: 'Delivery date cannot
be in the past'. User can proceed.

F4 customer help Press F4 on Customer field Search popup appears listing


KNA1 records. Value populated
on selection.

Cancel with empty Leave all fields empty, press Cancel (F12) Screen exits cleanly without
fields validation errors (AT EXIT-
COMMAND fires).

Back navigation Fill partial data, press Back (F3) Returns to previous screen
without saving. No error
messages.

Duplicate save Save successfully, then press Save again New order number generated —
each save creates a distinct
record.

11. Quick Reference Card

Item Value

Program Name SAPMZSALES_ORDER (type M)

Transaction Code ZSO_CREATE

Main Screen 0100 — Sales Order Entry

GUI Status STATUS_0100 (defined in SE41)

GUI Title TITLE_0100

DB Tables Written VBAK (header), VBAP (item)


SAP ABAP Module Pool Programming | Sales Order Creation Screen | Project Notes

Item Value

DB Tables Read (validation) KNA1 (customer), MARA (material)

Number Range Object VBELN_VA — external number range for order numbers

Message Class ZMSG — custom messages E001, E002, E003, S003

Key System Variables sy-ucomm (function code), sy-subrc (return code), sy-datum (date),
sy-uname (user)

SAP ABAP Module Pool Programming — Sales Order Creation Screen | Internal Project Notes | v1.0

You might also like