System divides the module pool program into several include program. These are global field, PBO modules, and PAI modules. It is entirely user’s decision whether to use these modules or write directly into main program.
Creation of Module Pool Program
You can create module pool program either through
Object browser
System automatically creates the module pool program and for these program which are created through object browser, system creates the include modules.
Or
ABAP/4 editor
It is similar to normal program creation. Type of program should be given ‘M’ and is not created by system.
Communication between Dynpro and Module Program
For each screen, the system executes the flow logic, which contains corresponding events. The control is passed to Module Pool Program. Module Pool Program handles the code for these events and again passes back control to the flow logic and finally to screen. Unlike on line program, in this case, the control remains with flow logic. The switching of control between flow logic and module pool program and back is common process when user executes transaction.
Creation of a Complete Transaction
Steps involved to create a complete transaction
• Create module pool program.
• From screen painter create screens.
• Write flow logic for each screen.
• Write code for all the events in module pool program.
• Check for any error in screen and flow logic.
• Generate each and every component of screen i.e. flow logic and screen.
• Single screen can be tested using Screen Painter.
• Create transaction code through object browser.
• Generate the transaction code.
• User can execute the transaction by entering the transaction code in the command field.
Handling Function Code
The function code or OKCODE is the last field of Field list. Function code can be handled as follows:
During the Designing of the screen, a function code is assigned to pushbutton.
• In field list, developer needs to specify OKCODE as last field.
• In module program it is a global field and can be evaluated in the PAI event.
• A function code is treated in the same way, regardless it comes from pushbutton, menu item or any other GUI element.
A complete example for transaction is shown below:
If you have a screen like the one below:
When the user clicks on the Display button, you want to display details of sflight, with corresponding carrid and connid (which is entered by the user).
Module pool program to handle this particular screen is as follows:
Program YVTEST7.
TABLES: SFLIGHT.
DATA: OKCODE (4).
MODULE INPUT1 INPUT,
CASE OKCODE.
WHEN ‘DISP’.
SELECT * FROM SFLIGHT
WHERE CARRID = SFLIGHT – CARRID AND
CONNID = SFLIGHT – CONNID.
ENDSELECT.
LEAVE TO SCREEN 200.
WHEN ‘EXIT’. LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. “INPUT1 INPUT
MODULE USER_COMMAND_0200 INPUT.
CASE OKCODE.
WHEN ‘BACK’. LEAVE TO SCREEN 100.
ENDCASE.
ENDMODULE. “USER_COMMAND_0200 INPUT
When the user clicks on display, control is transferred to screen no. 200 on which you display sflight details & on the same screen, when user clicks on BACK button, he comes back to main screen.
Flow logic for screen 100 is as follows:
PROCESS AFTER INPUT.
MODULE INPUT.
Flow logic for screen 200
PROCESS AFTER INPUT.
USER_COMMAND_0200.
MODULES: Modules are handled in module pool program.
You need to write flow logic for screen 200 and design screen 200.
In case of transaction transfer of data from program to screen is automatic i.e. you need not transfer the data from program to screen explicitly. The fields, which you define in the screen receives the data from program and displays the same.
The Field Checks
As already mentioned Transaction is the only method, which SAP recommends to update the database tables. Data entered in the database table should be valid and correct. Data entered is validated at each and every point. ABAP/4 offers various methods to validate data and those are as follows:
• Automatic field checks
• Checks performed in the flow logic
• Checks performed in the ABAP/4 module pool program
Automatic Field Checks
These checks are based on the field information stored in the dictionary. These checks are performed by the system automatically when the user enters the data for the screen field. System performs these checks before PAI event is triggered. Types of field checks performed by system are as follows:
• Required input
While designing the screen, for particular screen field if you click the Req. Entry checkbox, the field becomes mandatory. When the transaction is executed if user leaves this particular field blank, the system displays error message. User cannot proceed until the user enters some data.
• Proper Data Format
Each field has its own data format whether it is table field or screen field. Whenever data is entered, system checks for the proper format of the data. For example date. Each user has its own format for date, which is defined in the user master record. If the date defined in the user master record is in the format DD/MM/YYYY, if the user enters the date, say, in YY/DD/MM, the user displays the error message. System also checks for the value of month or days. For example if month entered is greater than twelve then the error message is displayed.
• Valid Value for the Field
In data dictionary two tables are related by Primary key-Foreign key relationship. Whenever the user enters the data, the system checks for the check table values. Also in Domain, if you have fixed values, then the system checks for these values.
Automatic field checks are repeated each time the user enters the data.
About at Exit – Command
Automatic field checks can be avoided by AT EXIT-COMMAND, which works exactly the same way as Cancel works on application tools bar. In the R/3 screen, if you want to quit the processing of that particular screen without entering the mandatory fields, user can click the Cancel button. Same functionality can be incorporated in the user-defined transaction by using AT EXIT-COMMAND. This module can be called before the system executes the automatic field checks and it goes without saying that before PAI event. Code for AT EXIT-COMMAND in flow logic and in module pool program can be written as follows:
In Flow Logic
Process After Input.
Module exit AT EXIT-COMMAND.
In module pool program.
Module exit.
Case okcode.
When ‘Exit’.
Leave to screen 0.
To achieve this kind of functionality a pushbutton or menu item should be assigned a function type ‘E’. It tells the system to process this particular module before carrying out any field checks.
Flow Logic Validations
Consider the case where you want user to enter only ‘LH’ and ‘SQ’ for sflight-carrid. In this case, you are restricting value of a screen field. This cannot be achieved by automatic field check. Hence there is a need of additional validation. It can be done in flow logic by using following statement:
Field --------------- Values
Syntax
PAI.
Field sflight-carrid values (‘LH’).
For multiple values
PAI.
Field sflight-carrid values (‘LH’ ‘SQ’).
Field sflight-price values (between 1000 and 2000).
In this case when the user enters the value, PAI is triggered and field is checked for that particular value. If the value entered happens to be wrong, that field is enabled for user to enter. If you have multiple Field statements in your flow logic, it is sequential execution.
Consider the following case:
PAI.
Module assign.
Field sflight-carrid values (‘LH’ ‘SQ’).
In ABAP/4
Module assign.
Data: carrid1 like sflight-carrid.
Carrid1 = sflight-carrid.
Endmodule.
In this case, Sflight-carrid is used in the flow logic before the field statement. The system will give invalid value or some previous value as the field sflight-carrid is used in module before it is checked i.e., field statement is after the module in which sflight-carrid is being used. The field is not available to the system unless it executes the field statement. Field statement transfers the values to the program and is done only once. If you don’t have Field statement in your flow logic, transfer of values takes place in PAI event.
Consider one more case where you have multiple field statement.
PAI.
Field Sflight-carrid values (‘LH’).
Field Sflight-connid values (‘0400’ ‘0500’).
In this case if the user enters only carrid wrong, then this particular field is enabled and rest of the fields are disabled for user to input. Many times if the user enters wrong value for one field, then you might want to give option to user to enter all the fields, which is not possible by using Field statement only. This functionality can be achieved by CHAIN – ENDCHAIN.
Syntax
Chain.
Field sflight-carrid value (‘LH’).
Field sflight-connid values (between ‘200’ and ‘500’).
Endchain.
Field sflight-price values (‘100’ ‘1000’).
In this case, if the user enters wrong value only for carrid, both the fields i.e. carrid and connid are enabled as they are grouped together in the Chain statement. The field price will be disabled for input. Usually, logically related fields are grouped together with Chain-Endchain statement.
Module Pool Program Validations
Checking fields ABAP/4 program includes
• Field statement in flow logic.
• Module statement in ABAP/4 module pool Program.
Syntax
PAI.
Field sflight-carrid module
This module can be handled in the main program i.e. module pool program.
In ABAP/4 program
Module Check.
Select single * from sflight where carrid = sflight-carrid.
If sy-subrc ne 0.
Message e001.
Endif.
In this case, field sflight-carrid is checked in the table for its existence.
Dynamically Calling the Screens
No comments:
Post a Comment