Dynamic Screen Field Modification in SAP ABAP Module Pool Programming: A Comprehensive Guide
In module pool programming in SAP ABAP, changing the screen fields involves dynamically modifying the attributes or values of screen elements like input fields, output fields, pushbuttons, etc., based on certain conditions or user actions. Here's a general guide on how to change screen fields in module pool programming:
- Identify the Screen Field: Determine which screen field you want to change. This could be a field for user input, display, or action.
- Accessing Screen Fields: In your ABAP code, you typically access screen fields using their names (defined in the screen painter) or by referencing their corresponding data elements or variables.
- Field Attributes: To change the properties of a screen field (such as its visibility, editability, color, etc.), you modify its attributes. This is typically done using statements like
SET PARAMETER
orSET SCREEN
. - Modifying Field Values: If you need to change the value displayed in a field dynamically (e.g., based on database values, user input, or system conditions), you assign a new value to the corresponding data element or variable associated with that field.
- Event Handling: Determine when the field needs to be changed. This could be during initialization, when a certain user action occurs (like clicking a button or selecting an item from a list), or based on some program logic or external input.
- Control Structures: Use control structures like
IF
,CASE
, orLOOP
to conditionally change field properties or values based on your program logic or user input. - Screen Flow Logic: Ensure that the changes to screen fields are reflected appropriately within the flow of your program. This involves coordinating the changes with other actions or processes happening within the module pool.
- Testing: Thoroughly test your program to ensure that the changes to screen fields are behaving as expected under different scenarios and conditions.
By following these steps, you can effectively change screen fields in module pool programming to create dynamic and interactive user interfaces within your SAP applications.
For Example :-
- In the below example, we set the Input property at zero.
-
LOOP at Screen.
IF ( condition ).
SCREEN-INPUT = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
-
Requirement :-
-
Suppose, I execute the one of the previous programs that we used in Modal dialog box.
-
Now, customer wants some dynamic changes on the screen
-
Customer wants that all the fields except the Order number should become non editable.
Solution :-
-
Step 1 :- Open the PBO of the screen 200 and write the below logic.
Code :-
*&---------------------------------------------------------------------*
*& Modulpool ZAR_MODULE_POOL_PROGRAM
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
PROGRAM zar_module_pool_program.
TABLES: zar_header.
TYPES : BEGIN OF ty_header,
order_number TYPE zar_order_number,
order_date TYPE zar_order_date,
payment_mode TYPE zar_payment_mode,
total_amount TYPE zar_total_amount,
currency TYPE zar_curency,
END OF ty_header.
DATA : lt_header TYPE TABLE OF ty_header,
ls_header TYPE ty_header.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'HEADER'.
SET TITLEBAR 'HDR'.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
IF sy-ucomm EQ 'SUBMIT'.
SELECT SINGLE order_number order_date
payment_mode total_amount currency
FROM zar_header INTO ls_header
WHERE order_number = zar_header-order_number.
zar_header-order_number = ls_header-order_number.
zar_header-order_date = ls_header-order_date.
zar_header-payment_mode = ls_header-payment_mode.
zar_header-total_amount = ls_header-total_amount.
zar_header-currency = ls_header-currency.
CALL SCREEN '0200' STARTING AT 10 20 "Top Left Corner Coordinates
ENDING AT 80 60. "Bottom Right Corner Coordinates
ENDIF.
IF sy-ucomm EQ 'BACK'.
LEAVE TO SCREEN 0.
ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_0200 OUTPUT.
LOOP AT SCREEN.
IF screen-name = 'ZAR_HEADER-ORDER_DATE'
OR screen-name = 'ZAR_HEADER-PAYMENT_MODE'
OR screen-name = 'ZAR_HEADER-TOTAL_AMOUNT'
OR screen-name = 'ZAR_HEADER-CURRENCY'.
screen-input = '0'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
SET PF-STATUS 'HEADER'.
SET TITLEBAR 'DET'.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0200 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0200 INPUT.
IF sy-ucomm EQ 'OK'.
LEAVE TO SCREEN 0.
ENDIF.
ENDMODULE.
Execute the Code :-
- click on submit button.
- We can see all fields other than order number has become non editable.
Comments
Post a Comment