There are many situations where it is usefull to force a user command programatically. One of such cases is when we want to update the selection screen after a screen field has changed.
To do so one only has to call the following Function module: SAPGUI_SET_FUNCTIONCODE .
In the exemple above, we are forcing an ENTER.
Here is a practical example on filling two display fields on the selection screen, after the user changes the plant.
Code:
To do so one only has to call the following Function module: SAPGUI_SET_FUNCTIONCODE .
CALL FUNCTION 'SAPGUI_SET_FUNCTIONCODE' EXPORTING functioncode = '=ENT' EXCEPTIONS function_not_supported = 1 OTHERS = 2.
Here is a practical example on filling two display fields on the selection screen, after the user changes the plant.
When the User changes the Plant the List of Warehouses and Storage Locations Changes Automatically |
Code:
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_werks . PERFORM get_plants USING p_werks. AT SELECTION-SCREEN OUTPUT. PERFORM fill_screen_texts USING p_werks CHANGING p_lgort p_lgnum. LOOP AT SCREEN. CASE screen-group1. WHEN 'DIS'. screen-input = '0'. ENDCASE. MODIFY SCREEN. ENDLOOP.
*&---------------------------------------------------------------------* *& Form GET_PLANTS *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_P_WERKS text *----------------------------------------------------------------------* FORM get_plants USING p_p_werks. TYPES: BEGIN OF ty_s_werks, werks TYPE werks_d, name1 TYPE name1, END OF ty_s_werks. DATA: lt_werks TYPE TABLE OF ty_s_werks. SELECT DISTINCT werks name1 FROM t001w INTO TABLE lt_werks WHERE werks IN ( SELECT DISTINCT werks FROM zmdm_crwh ). CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST' EXPORTING retfield = 'WERKS' dynpprog = sy-repid dynpnr = sy-dynnr dynprofield = 'P_WERKS' value_org = 'S' TABLES value_tab = lt_werks EXCEPTIONS parameter_error = 1 no_values_found = 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. " Simulate an user enter after he has " changed the plant, so that we can force a " AT SELECTION-SCREEN OUTPUT event " and thus populate fields " p_lgort and p_lgnum with the list of the " corresponding storage locations and " warehouses for the selected plant CALL FUNCTION 'SAPGUI_SET_FUNCTIONCODE' EXPORTING functioncode = '=ENT' EXCEPTIONS function_not_supported = 1 OTHERS = 2. ENDFORM. " GET_PLANTS *&---------------------------------------------------------------------* *& Form FILL_SCREEN_TEXTS *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_P_WERKS text * <--P_P_LGORT text * <--P_P_LGNUM text *----------------------------------------------------------------------* FORM fill_screen_texts USING value(p_werks) TYPE werks_d CHANGING value(p_lgort) TYPE string value(p_lgnum) TYPE string. DATA: lt_zmdm_crstl TYPE TABLE OF zmdm_crstl, lt_zmdm_crwh TYPE TABLE OF zmdm_crwh. FIELD-SYMBOLS: <fs_zmdm_crstl> TYPE zmdm_crstl, <fs_zmdm_crwh> TYPE zmdm_crwh. CLEAR: p_lgort, p_lgnum. CHECK p_werks IS NOT INITIAL. SELECT * FROM zmdm_crstl INTO TABLE lt_zmdm_crstl WHERE werks = p_werks. SELECT * FROM zmdm_crwh INTO TABLE lt_zmdm_crwh WHERE werks = p_werks. " Fill the list of Storage Locations for the selected plant ( P_WERKS ) " to be displayed on the selection screen field ( P_LGORT ) LOOP AT lt_zmdm_crstl ASSIGNING <fs_zmdm_crstl>. IF p_lgort IS INITIAL. p_lgort = <fs_zmdm_crstl>-lgort. ELSE. CONCATENATE p_lgort <fs_zmdm_crstl>-lgort INTO p_lgort SEPARATED BY space. ENDIF. ENDLOOP. " Fill the list of Warehouses for the selected plant ( P_WERKS ) " to be displayed on the selection screen field ( P_LGNUM ) LOOP AT lt_zmdm_crwh ASSIGNING <fs_zmdm_crwh>. IF p_lgnum IS INITIAL. p_lgnum = <fs_zmdm_crwh>-lgnum. ELSE. CONCATENATE p_lgnum <fs_zmdm_crwh>-lgnum INTO p_lgnum SEPARATED BY space. ENDIF. ENDLOOP. ENDFORM. " FILL_SCREEN_TEXTS
This comment has been removed by the author.
ReplyDelete