Module Pool

Module Pool is basically used for the Data entry programming. Basic steps of module pool is define as follows:-
1. Module Pool Steps
2. Program Example
3. Code For Copy & Delete Buttons

1. Module Pool Steps:
1. Create program using transaction code SE80.
2. Now Create Screen by right clicking program name and create screen.
3. Now open screen painter by clicking Layout.
4. Design screen as per requirement.
Note:
1. Define data CONTROLS : tc type tableview using screen '0200'.
For use of table control where tc is the name of table of screen painter.
2. Define data data : ok_code type sy-ucomm.
For use of buttons in screen painter.
3. This ok_code must be included in element List (i.e. all screen fields must be included in the Element List).




And now use code like this –
case ok_code.
when 'BACK'.
call SCREEN '100'.
endcase.
Where BACK is Function Code of button’s property in screen painter.


PBO Module:
PROCESS BEFORE OUTPUT.
MODULE status_0200.
LOOP AT izqmrr WITH CONTROL tc.
ENDLOOP.

PBI Module:
PROCESS AFTER INPUT.
LOOP.
ENDLOOP.
MODULE user_command_0200.

GUI Title:
set TITLEBAR 'Y_DURGESH321_TITLE'.
Where Y_DURGESH321_TITLE is the name of the GUI Title.

GUI Status:
set pf-status 'STATUS' excluding 'CANCEL'.
Where 'STATUS' is name of the GUI Status. If we add excluding 'CANCEL'.
Then Cancel button will not be added.
If we have to exclude multiple icon then following procedure will be added.
1. Create an internal table.
DATA : BEGIN OF i_stat OCCURS 10,
fcode(6) TYPE c.
DATA : END OF i_stat.
2. Add name of icon in table.
i_stat-fcode = 'SAVE'.
APPEND i_stat.
i_stat-fcode = 'CANCEL'.
APPEND i_stat.
3. Now set PF-status excluding i_stat.
SET PF-STATUS 'STATUS' EXCLUDING i_stat.
Now Bothe SAVE and CANCEL icon will be disabled simultaneously.

Automatically Increase Lines of Table In Entry Screen :
data : l_ilines type i.
CONTROLS : tc type tableview using screen '0200'.
describe table lt_results lines l_ilines.
tc-lines = l_ilines + 18.

Saving Data in Table:
Steps for saving data are as follows –

This is the flow logic of data entry screen i.e. of the screen from which we have to save the data.
1. At PROCESS AFTER INPUT writes following lines –
A.
LOOP AT i_emp.
MODULE crtrecord.
ENDLOOP.
Where MODULE crtrecord is created manually for transferring data from screen field to program field i.e. data entry form to internal table.
There are following code of line written in MODULE crtrecord for data transfer.
MODULE crtrecord INPUT.
MODIFY i_emp INDEX tc-current_line.
IF sy-subrc NE 0.
APPEND i_emp.
ENDIF.
ENDMODULE.

B. MODULE user_command_0100
MODULE user_command_0100 INPUT.

CASE ok_code.
WHEN 'SAVE'.
MODIFY ymod FROM TABLE i_emp.
IF sy-subrc = 0.
MESSAGE 'Record Has Been Updated' TYPE 'S'.
ENDIF.
ENDCASE.
ENDMODULE.
This is the code written basically for the saving the data in the table.

2. At PROCESS BEFORE OUTPUT writes following lines –
LOOP AT i_emp WITH CONTROL tc.
ENDLOOP.

2. Program Example:

PROCESS BEFORE OUTPUT.
LOOP AT i_emp WITH CONTROL tc.
ENDLOOP.
MODULE STATUS_0100.

PROCESS AFTER INPUT.
LOOP at i_emp.
CHAIN.
FIELD : i_emp-empid,
i_emp-empname.
MODULE validate ON CHAIN-REQUEST.
ENDCHAIN.
MODULE crtrec.
ENDLOOP.
MODULE user_command_0100.

a. MODULE STATUS_0100.


b. MODULE validate ON CHAIN-REQUEST
IF i_emp-empid IS INITIAL.
MESSAGE 'Enter EMP_ID' TYPE 'E'.
EXIT.
ELSEIF i_emp-empname IS INITIAL.
MESSAGE 'Enter EMP_Name' TYPE 'E'.
EXIT.
ENDIF.
SELECT SINGLE empid FROM ymod INTO i_emp-empid
WHERE empid = i_emp-empid.
IF sy-subrc IS INITIAL.
MESSAGE 'EMP_ID Already Exist' TYPE 'E'.
EXIT.
ENDIF
c. MODULE crtrec..
MODIFY i_emp INDEX tc-current_line.
IF sy-subrc NE 0.
APPEND i_emp.
ENDIF.
d. MODULE user_command_0100.
MODIFY ymod FROM TABLE i_emp.

3. Code For Copy & Delete Buttons:

a.Decalre field MARK in internal table of type character.
DATA: BEGIN OF i_emp OCCURS 0.
INCLUDE STRUCTURE ymod.
DATA: mark.====Filed For delition
DATA: END OF i_emp.
b.Cearte button in form painter for copy and delete records.
c.Add FIELD i_emp-mark MODULE modify ON REQUEST. in PAI as given below –
PROCESS AFTER INPUT.
MODULE exit AT EXIT-COMMAND.
LOOP AT i_emp.
CHAIN.
FIELD : i_emp-empid,
i_emp-empname.
MODULE validation ON CHAIN-REQUEST.
MODULE itablefill.
ENDCHAIN.
FIELD i_emp-mark MODULE modify ON REQUEST.
ENDLOOP.
MODULE user_command_0100.
d.Now Create MODULE modify as follows –
MODULE modify INPUT.
MODIFY i_emp INDEX tc-current_line TRANSPORTING mark.
ENDMODULE.
e. Add following lines in MODULE user_command_0100 of PAI Module as follows –
IF ok_code = 'SAVE'.
MODIFY ymod FROM TABLE i_emp.
DELETE i_emp WHERE mark = ''.
ELSEIF ok_code = 'DEL'.
DELETE i_emp WHERE mark = 'X'.
ELSEIF ok_code = 'COPY'.
READ TABLE i_emp WITH KEY mark = 'X' INTO wa_results.
IF sy-subrc = 0.
APPEND wa_results to i_emp.
ENDIF.
ENDIF.
Note:
wa_results is workarea like internal table
data: wa_results LIKE LINE OF i_emp.