Enhancing User Interaction: Creating Dropdown Lists in SAP Module Pool Programming
In SAP module pool programming, you can create drop-down lists using Input/Output fields or the List Box UI element. With Input/Output fields, you define parameters with the addition "AS LISTBOX" and provide values using the VALUES statement. In the List Box UI element method, you add a list box to the screen via the Screen Painter and populate it with values in the PBO event. In the PAI event, you handle the selected value. Both methods enable users to select options from a predefined list, enhancing user interaction in SAP applications.
Requirement :-
-
We are required to create two drop down list.
-
And the Customer wants that based on one drop down list, the value of other drop down list will change.
Hint :
- Create a table which consists of two columns State and Region , we will maintain the data into the table , then we will create a module pool program which will help us to achieve this particular requirement.
Solution :-
-
Step 1 :- Create a table which consists of two columns State and Region and provide a value range for state column.
-
Step 2 :- Create a TMG for the table.
-
Step 3 :- Provide few entries into the table through SM30.
-
Step 4 :- Create a Module Pool Program through ABAP Editor and navigate it to SE80.
-
Step 5 :- Create a screen 100 in the program.
-
Step 6 :- Open the layout on screen 100.
-
Create a label state
-
Create a input/output field and in the description mark it as List box.
-
Again follow the above steps for column Region.
-
-
Step 7 :- Create the type structure and corresponding internal table and work area for our table.
-
Step 7 :- Uncomment the PAI logic of screen 100 and select master program and write the logic into it.
-
Step 8 :- Open the PBO of screen 100 since we have to perform layout specific changes.
- We will use function module VRM_SET_VALUES to find the data with out screen field Region.
-
step 9 :- create a transaction code for the program
Code :-
*&---------------------------------------------------------------------*
*& Modulpool ZAR_MODULE_DROP_DOWN
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
PROGRAM ZAR_MODULE_DROP_DOWN.
*&-------------------------------
*Creating type structure
tables : ZAR_STATE_REGION.
types: begin of ty_local,
STATE type ZAR_STATE,
ZREGION type ZAR_REGION,
end of ty_local.
data : lt_local type table of ty_local,
ls_local type ty_local.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
Select STATE ZREGION
from ZAR_STATE_REGION
into table lt_local
where STATE = ZAR_STATE_REGION-STATE.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.
DATA : lt_values type VRM_VALUES,
ls_values type VRM_VALUE.
if ZAR_STATE_REGION-STATE is not INITIAL.
clear lt_values.
LOOP at lt_local into ls_local.
ls_values-text = ls_local-ZREGION.
append ls_values to lt_values.
clear ls_values.
endloop.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'ZAR_STATE_REGION-ZREGION'
values = lt_values
EXCEPTIONS
ID_ILLEGAL_NAME = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
endif.
ENDMODULE.
Execute the Program :-
- Press enter
- So, this is how we can use drop down list in module pool programming.
Comments
Post a Comment