Thursday, January 8, 2009

Dialog Prorgramming

Module Pool Programming
(Also called Screen or Dialog Programming)

Events in module pool programming:
Process Before Output (PBO)
Process After Input (PAI)
Process on Help-request (POH) – F1
Process on Value Request (POV) – F4

PBO: In this event, we write the logic to display the screen layout. Data will transfer from program fields to screen fields with identical names.

PAI: Whenever we do any operation in the screen which is associated with function code, this event will be triggered. Data will pass from screen fields to program fields.
SY-UCOMM is the only we can use PAI.

SE80 : Select PROGRAM from dropdown – enter program name – press enter
– asks for creation – press YES – make sure TOP INCLUDE check is enabled.
Delete * and enter prog name TOP.

IN SE80:
- double click on program – goto change mode – uncomment 001 and I01 include programs.
- Double click on the include programs, create and back.
- Right click on program name – create screen.
- Enter the short description
- Click on element list
- Enter ok_code - we can give any variable name but ok_code is standard.
- Click on layout.
- Click on Textbox – drag it on screen – double click textbox.
- Enter the name and text – give quick info an icon name.
- Similarly make 2 more text boxes. One for second number and one for result.
- Click on input , output box and drag it on screen.
Enter name and format.
- Click on push button, drag it on screen.
Enter name
Enter text.
- enter function code – eg- ADD
- another button for EXIT.
-Design screen. Goto flow logic.
- Uncomment the module after PAI.
Double click on the module - asks for creation - click YES.
- Select I-1 include program.

Module USER_COMMENT_I011 input
Case ok_code.
WHEN ‘ADD’.
R = A + B.
WHEN ‘EXIT’.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.

-Double click on main program.
Two types of fields:
- Screen Fields
- Program Fields
Double click on program, double click on TOP INCLUDE.

NOTE: generally in TOP INCLUDE, we declare all the global variables.
TOP INCLUDE is include at the top.
In TOP INCLUDE write:

DATA: a type I,
B TYPE I,
R TYPE I,
OK_CODE TYPE SY-UCOMM.

- Right click on main program.
- Executing module pool type of program.
- Except report programs, we cant execute any program directly by F8.
- For module pool programs, we execute by creating a TCODE: SE93.
Or
Right click on program – create – transaction.
- Enter transaction code name and short description.
- Select program and screen.
- Enter program name and screen number.
- Click on all the GUI options and SAVE.
- Click on cursor position under attributes.
- Hitting Enter will pass empty function code.
- to avoid this problem: goto screen – goto flow logic, after process before output, create a module.
MODULE CLEAR_OK_CODE.
- Double click on module, it will ask for creation.
- Select 001 include.
- In module we will write:
CLEAR OK_CODE.

Static Screen Changes.
Requirement: Make the result field as display only and the field number as mandatory.

- Double click on the screem – click on layout.
- Goto change mode.
- Double click on the first field.
- Select program tab in attributes under input dropdon – select required.
- Double click on result field, goto program tab – select output only.

OR
- Click on element list tab and change the attributes.

To create a cancel button.
- Double click on screen – click on layout.
- Click on pushbutton – drag it on screen.
- Enter the name, text and function code.
- Select function type as E.
- Click on flowlogic.
- In PAI, create a module of type:
‘at exit_command’.
- MODULE LEAVE AT EXIT_COMMAND.
Double click on module
Select I01(PAI)
-IF OK_CODE = ‘CANCEL’.
LEAVE TO SCREEN 0.
ENDIF.
- SCREEN 0 breaks the screen sequence.

In AT EXIT-COMMAND, field validation is not triggered, so it doesn’t check for fields and comes out.
In report, we do validation in ‘at selection screen’.
Display error message if user enter value A > 10.
- Double click on screen.
In PAI:
FIELD A MODULE VALIDATE_A.
Inside the module write:
MODULE VALIDATE_A INPUT.
IF A .= 10.
MESSAGE “ENTER VALUE LESS THAN 10” TYPE ‘E’.

Field statement:
We use it for single field validation, i.e. if any error occurs in the module, then the field will be enabled, other fields will be disabled

To validate a group of fields:
In this case, double click on screen.

CHAIN.
FIELD A.
FIELD B.
MODULE VALIDATE_A.
ENDCHAIN.

- DYNAMIC SCREEN MODIFICATIONS:
When user click on add, display only result field.
Double click on screen.
Uncomment module after PBO or write a module,
Double click on module.
Select o01.

CASE ‘OK_CODE’.
WHEN : ‘ADD’.
LOOP AT SCREEN.
IF SCREEN-NAME = ‘A’.
SCREEN-ACTIVE = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDCASE.
ENDMODULE.

SCREEN is an internal table defined by the system which contains the field attributes or the screen attributes.

To disable a group of fields, double click on screen, goto layout – double click on fields whose attributes we want to change.
Enter a group name in first input box of groups.
Eg – GR1.
In LOOP AT SCREEN.
Instead of screen-name , can write screen-group1 – ‘GR1’.

TABSTRIP Control.
- Create a module pool type of program.
2 includes will be added automatically PBO and PAI.
- Create a screen.
Enter screen number, short secription.
Goto element list – enter OK_CODE.
- Click on layout
- Click on Tabstrip control – drag it on screen.
- Double click on tabstrip control.
- Enter the name.
- If more than two tabs are required, change the tabtitle
( by default two is the value)
- Double click on tab1.
Enter the name, text and function code.
Color is red for fields i.e. the information is mandatory to be filled.
- Click on Subscreen Area – Drag it on screen.
- Double click on other tab and do the same.
- Click on flow logic:
- Now we need to design subscreens ( that are assigned to tabs).
- Right click on program – Create screen
OR
Goto screen – other object – enter screen number and enter create.
- Short description , Add subscreen.
- Select Subscreen radio button
We will see OK_CODE is not enabled. By default for subscreen.

- After designing the subscreen layouyt, goto flow logic. Uncomment module of PAI.
- Double click on TOP INCLUDE and write following in TOP INCLUDE.
DATA : A TYPE I,
B TYPE I,
R TYPE I.
CONTROLS TAB TYPE TABSTRIP.

Double click on main screen.
Flowlogic:
PBO: Process Before Output.
CALL SUBSCREEN ADD_REF1 INCLUDING ‘ZTABSTRIP’ ‘1011’.
CALL SUBSCREEN MUL_REF1 INCLUDING ‘ZTABSTRIP’ ‘1012’.

PAI : Process After Input.
CALL SUBSCREEN ADD_REF1.
CALL SUBSCREEN MUL_REF1.

Double click on module command.
In main program:
MODULE USER_COMMAND_1010 INPUT.
CASE OK_CODE.
WHEN ‘ADD’.
TAB-ACTIVE TAB = ‘ADD’.
WHEN ‘MUL’.
TBA-ACTIVE TAB – ‘MUL’.
EBDCASE.
ENDMODULE.


TABLE CONTROL:
Create a module pool program.
We will try including screen in report program.
So create a report program:
REPORT ZTEST_TABLECONTROL.
START-OF-SELECTION.
CALL SUBSCREN 1010.
- double click on screen.
- click on element list – enter OK_CODE.
- goto layout – click and drop table control.
- double click on table control.
- check vertical and horizontal separators.
- click on dictionary / program fields ( red button at top) or press F6.
- Enter the table name – select fields and click OK.
- Again F6. Select fields that we want.
- Put it on fields.(drag n drop at the header area of table control.
- Click and drag Push button : make two of them – DISPLAY and EXIT.
- Click on Flow Logic. Write following:
PROCESS BEFORE OUTPUT.
LOOP AT IT_VBAP WITH CONTROL TABLE.
MODULE TRANSPORT.
ENDLOOP.

PROCESS AFTER INPUT.
LOOP AT IT_VBAP.
….
ENDLOOP.

MODULE USER_COMMAND 1010.
CASE ….

ENDCASE.

- Double click on MODULE TRANSPORT – include main program.
Main program:
REPORT ZTEST_TABLECONTROL.
TABLES VBAP.
DATA: OK_CODE TYPE SY-UCOMM.
CONTROLS TABLE TYPE TABLEVIEW USING SCREEN 1010.
TYPES: BEGIN OF TY_VBAP,
POSNR TYPE VBAP-POSNR,
MATNR TYPE VBAP-MATNR,
ARKTX TYPE VBAP-ARKTCX,
NETWR TPE VBAP-NETWR,
KWMENG TYPE VBAP-KWMENG,
END OF TY_VBAP,
TY_T_VBAP TYPE TABLE OF TY_VBAP.
DATA: IT_VBAP TYPE TY_T_VBAP,
X_VBAP TYPE TY_VBAP.
START-OF-SELECTION.
CALL SCREEN 1010.
PROCESS BEFORE OUTPUT.
LOOP AT IT_VBAP INTO X_VBAP WITH CONTROL TABLE.
MODULE TRANSPORT.
ENDLOOP.

PROCESS AFTER INPUT.
LOOP AT IT_VBAP.
ENDLOOP.
MODULE USER_COMMAND_1010.
MODULE TRANSPORT OUTPUT.
MOVE-CORRESPONDING X_VBAP TO VBAP.
ENDMODULE.

MODULE SELECT_DATA OUTPUT.
IF VBAK-SEL = ‘X’. “We can add desired logic
ENDMODULE.

MODULE USER_COMMAND_1010_INPUT.
CASE OK_CODE.
WHEN ‘DISPLAY’/
DATA FILL TYPE SY-TABIX.
SELECT POSNR MATNR ARKTX NETWR KWMENG
INTO TABLE IT_VBAP FROM IT_VBAP
WHERE VBELN = VBAP-VBELN.
DESCBRIBE TABLE IT_VBAP LINES FILL.
TABLE-LINES = FILL “ to make table control scrollable.
WHEN ‘EXIT’.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.

No comments: