Transcript
Page 1: Dialaog - 2.Doc for Module Pool Programming - By Perumal

Input Screen – Selection screen

1. The module pool program execution sequence is PBO -> Getting the input from user -> PAI -> PBO

2. For sub screen we have to specify as the sub screen in the attribute of sub screen

3. Sub screen can not have the OK_CODE4. For list box we need to select as list box in the drop down option of the

filed attribute5. We have to call the sub screen in the main screen of both PBO and PAI6. We need to loop the internal table which belongs to table control in the

PBO as well as in the PAI of the particular screen 7. A function code can be assigned to list box also so that it will trigger when

we select the value from that (ie As we have used in this program)8. We can assign value for the particular list box from fixed range value of

particular domain or using VRM_SET_VALUES in PBO and VRM_GET_VALUES in PAI

9. If we use VRM function then we need to declare TYPE-POOLS : VRM in the program

10. We can validate the sub screen in the PAI of main screen by checking the ok_code since we can’t have the ok_code in the sub screen

11. To place ICON and Check box we need to declare the fields in the internal table which we are referring in the table control so that it will display.

12. When we add new lines we need to increase the table control current line by 1 TABL_CTRL-CURRENT_LINE = TABL_CTRL-CURRENT_LINE1 + 1 in PAI

Page 2: Dialaog - 2.Doc for Module Pool Programming - By Perumal

13. In the same way when we delete line from table control we need to decrease by 1 in PAI.

14. Cursor position can only be set in PBO module not in PAI.Output Screen – For multi record table control

Output Screen – For single record

Drop down list in table ctrlIcon

Page 3: Dialaog - 2.Doc for Module Pool Programming - By Perumal

In design mode – Main screen

Flow logic for main screen

Sub Screen Area1. SUBSCR1 for multi 2. SUBSCR2 for single

Tab Button1. F-Code MULTI2. F-Code SINGLE

Drop down list

F4 – Help with popup window

No of tab title in the tab strip ctrl

Page 4: Dialaog - 2.Doc for Module Pool Programming - By Perumal

PROCESS BEFORE OUTPUT.

*To set PF status and title(PF Status can not be in subscreen) MODULE STATUS_2000.

call subscreen SUBSCR1 including 'ZTABLE_CONTROL' '0100'. call subscreen SUBSCR2 including 'ZTABLE_CONTROL' '0200'.

PROCESS AFTER INPUT.

MODULE stop_process AT EXIT-COMMAND.

call subscreen SUBSCR1. call subscreen SUBSCR2.

* For user user command event MODULE USER_COMMAND_2000.

Sub screen 100(Table control)

Page 5: Dialaog - 2.Doc for Module Pool Programming - By Perumal

Designing Table Control

Input box for Icon

Input Box

Text Box

Text box for table ctrl titleColumn

selection field IT_INV-PICK

Page 6: Dialaog - 2.Doc for Module Pool Programming - By Perumal

Flow Logic for sub screen 100*------------------------------- PBO---------------------------------*PROCESS BEFORE OUTPUT.

*To get data and table control lines MODULE get_tab_ctrl_lines.

*To modify the screen attribute MODULE set_screen_fields.

*To assign value into table control from internal table LOOP AT it_inv WITH CONTROL tab_ctrl. "CURSOR tab_ctrl-current_line.

**To modify the screen attribute* MODULE set_screen_fields. module enable_disable_rows.

ENDLOOP. module set_to_last.*------------------------------- PAI---------------------------------*PROCESS AFTER INPUT.

LOOP AT it_inv.

*To do the manipulation of rec like delete , modify, append FIELD it_inv-pick MODULE pick.

* MODULE pick.

* CHAIN.

Dictionary or Program fields

Select what ever field u want and click on ok button so that we can drag and place it in the table control

Itab Name from prg

List box for drop down list

Page 7: Dialaog - 2.Doc for Module Pool Programming - By Perumal

* FIELD : IT_INV-VBELN,* IT_INV-KUNAG,* IT_INV-FKDAT,* IT_INV-NETWR.** MODULE check_input_data.* ENDCHAIN.*

ENDLOOP.

MODULE insert_newrecord.

Sub screen 200(Single Record)

Flow logic for screen 200

PROCESS BEFORE OUTPUT. MODULE screen_filed.

PROCESS AFTER INPUT. MODULE USER_COMMAND_0200.

PROCESS ON VALUE-REQUEST. FIELD WA_SINGLE-STATUS MODULE HELP_LIST.*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::** Program ID : ZTABLE_CONTROL

Function code to trigger the event when we select the value in the list box

Page 8: Dialaog - 2.Doc for Module Pool Programming - By Perumal

* Transaction Code : ** Author : Perumal* Description : ** Project : ** Version : 1.0*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*

*------------------------------------------------------------------** Change History*------------------------------------------------------------------** Date | Programmer | Corr. # | Description* | | |******************************************************************** REPORT ZTABLE_CONTROL LINE-SIZE 351 NO STANDARD PAGE HEADING LINE-COUNT 65 MESSAGE-ID zmsg.

*********************************************************************TABLES******************************************************************** Tables: vbrk, vbrp, zinv.

TYPE-POOLS: vrm.

*********************************************************************INTERNAL TABLES AND STRUCTURES******************************************************************** Data : begin of it_inv occurs 0. include structure zinv. Data : pick type c, icon(200), end of it_inv.

Data : it_inv_temp like table of it_inv with header line.

Data : wa_inv like zinv, wa_inv1 like zinv, wa_single like zinv.

* For dropdown list box Data : status_help type vrm_values, vbeln_help type vrm_values, v_status(01) value 'X'.

* For F4 help in the selection screen DATA: BEGIN OF i_tabf OCCURS 10. INCLUDE STRUCTURE help_value. DATA: END OF i_tabf.

DATA: BEGIN OF i_values OCCURS 10, lines(256) TYPE c, END OF i_values.

********************************************************************

Page 9: Dialaog - 2.Doc for Module Pool Programming - By Perumal

*VARIABLES******************************************************************** Data : v_ln type i, v_ln1 type i, v_line type i, v_change type c, v_change1 type c, v_answer, v_select, v_add, v_single_flag, v_help_flag value 'X', v_back type c.

Data : v_pre_vbeln like vbrk-vbeln, v_next_vbeln like vbrk-vbeln, v_okcode like sy-ucomm, v_dochlp value 'X'.

*********************************************************************TABLE CONTROL******************************************************************** CONTROLS: tab_ctrl TYPE TABLEVIEW USING SCREEN '100', tab_strip TYPE TABSTRIP.. data wa_tab like line of tab_ctrl-cols.

*********************************************************************INITIALIZATION******************************************************************** INITIALIZATION.

********************************************************************SELECTION SCREEN DEFINITIONS******************************************************************* SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-000.

SELECT-OPTIONS: so_fkdat for vbrk-fkdat obligatory, so_vbeln for vbrk-vbeln.

SELECTION-SCREEN END OF BLOCK b.

********************************************************************SELECTION SCREEN EVENT******************************************************************* AT SELECTION-SCREEN ON VALUE-REQUEST FOR so_vbeln-low. PERFORM pro_help CHANGING so_vbeln-low.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR so_vbeln-high. PERFORM pro_help CHANGING so_vbeln-high.

*********************************************************************START-OF-SELECTION******************************************************************** START-OF-SELECTION.

PERFORM get_data.

CALL SCREEN 2000.

Page 10: Dialaog - 2.Doc for Module Pool Programming - By Perumal

*********************************************************************MODULE SET_STATUS OUTPUT(PBO-MAIN SCREEN 2000)******************************************************************** MODULE STATUS_2000 OUTPUT.

SET PF-STATUS 'ZSTATUS'. SET TITLEBAR 'ZTITLE'.

ENDMODULE. " SET_STATUS OUTPUT

*********************************************************************MODULE GET TABLE CONTROL LINES(PBO-SUBSCREEN 100)******************************************************************** MODULE GET_TAB_CTRL_LINES OUTPUT.

DESCRIBE TABLE it_inv LINES v_ln.

* Enabling table control vertical line when user command is not ADD.* DESCRIBE TABLE it_inv LINES TAB_CTRL-LINES. IF SY-UCOMM <> 'ADD'.

TAB_CTRL-LINES = v_ln.

ENDIF.

IF sy-ucomm = 'CHANGE' and v_single_flag <> 'X'.

set cursor field 'IT_INV-FKDAT' line 1.

ENDIF.

ENDMODULE. " GET_TAB_CTRL_LINES OUTPUT

*********************************************************************MODULE SET SCREEN FIELDS(PBO-SUBSCREEN 100)******************************************************************** MODULE SET_SCREEN_FIELDS OUTPUT.

IF v_status = 'X'.

append 'Open' to status_help. append 'Closed' to status_help.

* Assigning drop down values for table control CALL FUNCTION 'VRM_SET_VALUES' EXPORTING id = 'IT_INV-STATUS' values = status_help.

ENDIF.

IF not it_inv[] is initial. "Checking for change after the clear

loop at tab_ctrl-cols into wa_tab.

wa_tab-screen-input = '0'.

* Making the screen field as editable for change mode except key field IF wa_tab-screen-name <> 'IT_INV-VBELN' AND wa_tab-screen-name <> 'IT_INV-ICON' AND

Page 11: Dialaog - 2.Doc for Module Pool Programming - By Perumal

v_okcode = 'CHANGE'. wa_tab-screen-input = '1'.

ENDIF..

modify tab_ctrl-cols from wa_tab.

endloop.

ENDIF.

ENDMODULE. " SET_SCREEN_FIELDS OUTPUT

*********************************************************************MODULE TO ENABLE NEW ROWS(PBO-SUBSCREEN 100)******************************************************************** MODULE enable_disable_rows OUTPUT.

IF v_okcode = 'ADD'.

* if it_inv-netwr > 2000.* IF sy-stepl = 5.* endif.

IF tab_ctrl-current_line > v_ln.

loop at screen.

IF screen-name <> 'IT_INV-ICON'.

screen-input = '1'. modify screen.

ENDIF.

endloop.

ENDIF.

ENDIF.

IF v_okcode <> 'CLEAR' and it_inv-vbeln <> ' '.

* Green icon for fully due* **Assigning ICON based on the status of the receivable IF it_inv-total is initial.

call function 'ICON_CREATE' exporting name = '@08@'* TEXT = ' '* INFO = ' '* ADD_STDINF = 'X' IMPORTING RESULT = IT_INV-ICON* EXCEPTIONS* ICON_NOT_FOUND = 1* OUTPUTFIELD_TOO_SHORT = 2* OTHERS = 3 . if sy-subrc <> 0.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

Page 12: Dialaog - 2.Doc for Module Pool Programming - By Perumal

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. endif.* Yellow icon for partially received amount ELSEIF it_inv-recamt < it_inv-netwr and not it_inv-recamt is initial.

call function 'ICON_CREATE' exporting name = '@09@'* TEXT = ' '* INFO = ' '* ADD_STDINF = 'X' IMPORTING RESULT = IT_INV-ICON* EXCEPTIONS* ICON_NOT_FOUND = 1* OUTPUTFIELD_TOO_SHORT = 2* OTHERS = 3 . if sy-subrc <> 0.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. endif.

* Red icon for fully received amount ELSEIF it_inv-netwr = it_inv-total.

call function 'ICON_CREATE' exporting name = '@0A@'* TEXT = ' '* INFO = ' '* ADD_STDINF = 'X' IMPORTING RESULT = IT_INV-ICON* EXCEPTIONS* ICON_NOT_FOUND = 1* OUTPUTFIELD_TOO_SHORT = 2* OTHERS = 3 . if sy-subrc <> 0.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. endif.

ENDIF.

ENDIF.

ENDMODULE. " ENABLE_DISABLE_ROWS OUTPUT********************************************************************MODULE SET_TO_LAST OUTPUT(PBO - FOR SCREEN 100)******************************************************************* MODULE set_to_last output.

IF sy-ucomm = 'ADD'.

* tab_ctrl-top_line = v_ln + 1. set cursor field 'IT_INV-VBELN' line v_ln.

ENDIF.

Page 13: Dialaog - 2.Doc for Module Pool Programming - By Perumal

ENDMODULE. " SET_TO_LAST OUTPUT

*********************************************************************MODULE SCREEN_FILED OUTPUT(PBO-SUBSCREEN 200)******************************************************************** MODULE screen_filed OUTPUT.

if v_dochlp = 'X'.

select vbeln from zinv into corresponding fields of table it_inv_temp where fkdat in so_fkdat and vbeln in so_vbeln.

loop at it_inv_temp.

append it_inv_temp-vbeln to vbeln_help.

endloop.

CALL FUNCTION 'VRM_SET_VALUES' EXPORTING id = 'WA_SINGLE-VBELN' values = vbeln_help.

clear v_dochlp.

endif.

IF v_single_flag = 'X'.

loop at screen.

IF v_change <> 'Y'.

screen-input = '0'.

ELSE.

screen-input = '1'.

ENDIF.

modify screen.

endloop.

ELSE.

clear v_change. " Clearing when the multi screen is active

ENDIF.

ENDMODULE. " SCREEN_FILED OUTPUT

*********************************************************************MODULE STOP_PROCESS INPUT(FOR AT EXIT-COMMAND PAI-MAINSCREEN 2000)******************************************************************** MODULE stop_process INPUT.

Page 14: Dialaog - 2.Doc for Module Pool Programming - By Perumal

SET SCREEN 0.

ENDMODULE. " STOP_PROCESS INPUT

*********************************************************************MODULE USER COMMAND FOR MAIN SCREEN INPUT(PAI-MAINSCREEN 2000)******************************************************************** MODULE USER_COMMAND_2000 INPUT.

IF v_status = 'X'.

CALL FUNCTION 'VRM_GET_VALUES' EXPORTING id = 'IT_INV-STATUS' values = status_help.

clear v_status.

ENDIF.

clear v_okcode.

v_okcode = sy-ucomm.

CASE v_okcode.

WHEN 'MULTI'.

TAB_STRIP-ACTIVETAB = 'MULTI'. CLEAR v_single_flag.

WHEN 'SINGLE'.

TAB_STRIP-ACTIVETAB = 'SINGLE'. v_single_flag = 'X'.

* WHEN 'EXIT'.* * SET SCREEN 0.

WHEN 'BACK'.

* Modification of the changes in database after confirmation when back IF v_change1 = 'Y'.

CALL FUNCTION 'POPUP_TO_CONFIRM' EXPORTING TITLEBAR = 'Confirm' text_question = 'Do u want save the changes?' TEXT_BUTTON_1 = 'Yes'(001) TEXT_BUTTON_2 = 'No'(002) IMPORTING ANSWER = v_answer.

IF v_answer eq '1'.

MODIFY zinv FROM it_inv.

ENDIF.

ENDIF.

SET SCREEN 0.

Page 15: Dialaog - 2.Doc for Module Pool Programming - By Perumal

WHEN 'CHANGE'.

v_change = 'Y'. v_change1 = 'Y'. WHEN 'SAVE'.

IF v_single_flag <> 'X'.* Updating the database table from the internal table UPDATE zinv FROM TABLE it_inv. ENDIF.

WHEN 'DELETE'.

IF v_single_flag <> 'X'.

READ TABLE it_inv WITH KEY pick = 'X'.

IF sy-subrc = 0.

CALL FUNCTION 'POPUP_TO_CONFIRM' EXPORTING TITLEBAR = 'Confirm' text_question = 'Are you sure to delete?' TEXT_BUTTON_1 = 'Yes'(001) TEXT_BUTTON_2 = 'No'(002) IMPORTING ANSWER = v_answer.

IF v_answer eq '1'.

loop at it_inv.

IF it_inv-pick = 'X'.* Deleting the selected row from the database table DELETE FROM zinv WHERE vbeln = it_inv-vbeln.

* Deleting the selected row from the internal table DELETE it_inv. CONTINUE.

ENDIF.

endloop.

ENDIF.

* Updating the database table from the internal table(With Pick = X) UPDATE zinv FROM TABLE it_inv.

ELSE.

MESSAGE I000(ZMSG1).

ENDIF.

ENDIF.

WHEN 'ADD'.

Page 16: Dialaog - 2.Doc for Module Pool Programming - By Perumal

* To handle the sceen attributes* v_change = 'Y'. v_add = 'Y'.

* Adding new line in the tale control TAB_CTRL-LINES = v_ln + 1.* Clear the table control WHEN 'CLEAR'.

IF v_single_flag <> 'X'.

FREE it_inv[].

ENDIF.

ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

*********************************************************************MODULE PICK INPUT(PAI-SUBSCREEN 100)******************************************************************** MODULE pick INPUT. CLEAR wa_inv. MOVE-CORRESPONDING it_inv TO wa_inv.

IF not wa_inv is initial.

* Calculation for the total amount* IF NOT wa_inv-recamt IS INITIAL.

it_inv-total = wa_inv-netwr - wa_inv-recamt.

* ELSE.

* Modify the internal based on the table ctrl input MODIFY it_inv INDEX tab_ctrl-current_line.

* Checking for new record IF tab_ctrl-current_line > v_ln.

* Checking for existing entry READ TABLE it_inv WITH KEY vbeln = wa_inv-vbeln. IF sy-subrc <> 0.

* Appending new record into internal table APPEND it_inv.

ELSE.

MESSAGE I001(ZMSG1).

ENDIF.

ENDIF.

ENDIF.

ENDMODULE. " CHECK INPUT

*******************************************************************

Page 17: Dialaog - 2.Doc for Module Pool Programming - By Perumal

*MODULE FOR INSERT NEW RECORD IN THE DATABASE TABLE(SCREEN 100)******************************************************************* MODULE insert_newrecord INPUT.

read table it_inv index tab_ctrl-lines.

* Inserting new record into database table after confirmation IF not it_inv-vbeln is initial.

IF v_add = 'Y' and sy-ucomm = 'BACK'.

CALL FUNCTION 'POPUP_TO_CONFIRM' EXPORTING TITLEBAR = 'Confirm' text_question = 'Do u want save?' TEXT_BUTTON_1 = 'Yes'(001) TEXT_BUTTON_2 = 'No'(002) IMPORTING ANSWER = v_answer.

IF v_answer eq '1'.

MODIFY zinv FROM table it_inv.

ENDIF.

ENDIF.

ENDIF.

ENDMODULE. " UPDATE_NEWRECORD INPUT********************************************************************MODULE FOR CHECK INPUT DATA IN TABLE CONTROL******************************************************************* MODULE check_input_data INPUT.

IF tab_ctrl-current_line = v_ln.

CLEAR wa_inv1. MOVE-CORRESPONDING it_inv TO wa_inv1.

IF sy-ucomm = 'SAVE'.

IF WA_INV1-VBELN IS INITIAL OR WA_INV1-KUNAG IS INITIAL OR WA_INV1-FKDAT IS INITIAL OR WA_INV1-NETWR IS INITIAL.

MESSAGE I005(ZMSG1).

ENDIF.

ENDIF.

ENDIF.

ENDMODULE. " CHECK_INPUT_DATA INPUT*********************************************************************MODULE USER COMMAND FOR SUB SCREEN INPUT(PAI-SUBSCREEN 200)********************************************************************MODULE user_command_0200 INPUT.

Page 18: Dialaog - 2.Doc for Module Pool Programming - By Perumal

IF v_dochlp = 'X'.

CALL FUNCTION 'VRM_GET_VALUES' EXPORTING id = 'WA_SINGLE-VBELN' values = vbeln_help.

ENDIF.*Calculation for the total amount wa_single-total = wa_single-netwr - wa_single-recamt.

clear v_okcode.

v_okcode = sy-ucomm.

CASE v_okcode.

WHEN 'VBELN'.

v_pre_vbeln = wa_single-vbeln.

IF v_pre_vbeln <> v_next_vbeln.

select single * from zinv into corresponding fields of wa_single where vbeln = wa_single-vbeln.

v_next_vbeln = v_pre_vbeln. clear v_pre_vbeln.

ENDIF.

WHEN 'SAVE'.

IF v_single_flag = 'X'.

UPDATE zinv from wa_single.

ENDIF.

WHEN 'DELETE'.

IF v_single_flag = 'X'.

CALL FUNCTION 'POPUP_TO_CONFIRM' EXPORTING TITLEBAR = 'Confirm' text_question = 'Are you sure to delete?' TEXT_BUTTON_1 = 'Yes'(001) TEXT_BUTTON_2 = 'No'(002) IMPORTING ANSWER = v_answer.

IF v_answer eq '1'.

DELETE zinv from wa_single. CLEAR wa_single.

ENDIF.

ENDIF.

Page 19: Dialaog - 2.Doc for Module Pool Programming - By Perumal

WHEN 'CLEAR'. IF v_single_flag = 'X'.

CLEAR wa_single.

ENDIF. ENDCASE.ENDMODULE. " USER_COMMAND_0200 INPUT*********************************************************************MODULE HELPLIST INPUT FOR SUB SCREEN (PAI-SUBSCREEN 200)********************************************************************MODULE help_list INPUT.

DATA : BEGIN OF value_tab2 OCCURS 1, status LIKE zinv-status, END OF value_tab2.

IF v_help_flag = 'X'.

append 'Open' to value_tab2. append 'Closed' to value_tab2. CLEAR v_help_flag.

ENDIF.

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST' EXPORTING retfield = 'STATUS' dynpprog = 'ZTABLE_CONTROL' dynpnr = '0200' dynprofield = 'WA-SINGLE-STATUS'* STEPL = 0 window_title = 'Order List'* VALUE = ' ' value_org = 'S'* MULTIPLE_CHOICE = ' '* DISPLAY = ' '* CALLBACK_PROGRAM = ' '* CALLBACK_FORM = ' ' TABLES value_tab = value_tab2* FIELD_TAB =* RETURN_TAB =* DYNPFLD_MAPPING = EXCEPTIONS parameter_error = 1 no_values_found = 2 OTHERS = 3.

ENDMODULE. " HELP_LIST INPUT*********************************************************************FORM TO GET F4 HELP VALES FOR DOCUMENT NUMBERS IN THE SELECTION SCREEN******************************************************************** FORM pro_help CHANGING l_value.

FREE : i_tabf,i_values.

select vbeln into table i_values from vbrk where fkdat in so_fkdat.

Page 20: Dialaog - 2.Doc for Module Pool Programming - By Perumal

i_tabf-tabname = 'VBRK'. i_tabf-fieldname = 'VBELN'. i_tabf-selectflag = 'X'. APPEND i_tabf.

CALL FUNCTION 'HELP_VALUES_GET_WITH_TABLE' EXPORTING titel = 'Doc' IMPORTING select_value = l_value TABLES fields = i_tabf valuetab = i_values EXCEPTIONS OTHERS = 4.

IF sy-subrc <> 0.

ENDIF.

ENDFORM.********************************************************************FORM FOR GET DATA******************************************************************* FORM get_data.

select * from vbrk into corresponding fields of table it_inv where fkdat in so_fkdat and vbeln in so_vbeln.

loop at it_inv.

* Delete the record from internal table if it exist already select single * from zinv where vbeln = it_inv-vbeln. if sy-subrc = 0. delete it_inv. continue. endif.

endloop.

* Insert the record which is not exist already. insert zinv from table it_inv.

* Get the values from the customized table FREE it_inv[].

select * from zinv into corresponding fields of table it_inv where fkdat in so_fkdat and vbeln in so_vbeln.

SORT it_inv by vbeln.

ENDFORM.

Page 21: Dialaog - 2.Doc for Module Pool Programming - By Perumal

Recommended