Google Search - Blog...........


Let's say the selection screen has two input fields. One is plant i.e., PA_WERKS and other one is object(PA_OBJ). While executing the report, User will first enter the plant name in the WERKS field. Then, he will press F4 at the PA_OBJ field. It should dynamically take the value from PA_WERKS and display the possible values on F4 dialog box by searching in the table ZAIS_MMG.
Solution is written below and all the comments were provided at necessary places. Table need not be necessarily ZAIS_MMG. This logic is used for any table where you just need to change the table name.
Below is the subroutine that needs to be called at seelction screenAT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_obj.
*& Form object_f4help
* Provides the possible values for pa_obj
* --> p1 text
* <-- p2 text *----------------------------------------------------------------------* FORM object_f4help. * Refresh the internal table. This helps in reusing these tables and variables in * other subroutines. CLEAR: tb_dynpfields, tb_object_range. REFRESH: tb_dynpfields, tb_object_range. * Define Internal tables. DATA: tb_dynpfields LIKE dynpread OCCURS 0 WITH HEADER LINE. * Define constants. CONSTANTS: co_retfield TYPE dfies-fieldname VALUE 'OBJECT', co_dynprog LIKE sy-repid VALUE '/DCSEA/Z_AIS_NUM_RESET_PAJERO', co_s TYPE c VALUE 'S', co_field(27) TYPE c VALUE 'PA_OBJ'. * Assigning the values of program name and screen to the variables. wf_dyname = sy-repid. " PROGRAM NAME wf_dynumb = sy-dynnr. " SCREEN NUMBER wf_dynpro = co_field. * Move the field name to tb_dynpfields. MOVE 'PA_WERKS' TO tb_dynpfields-fieldname. APPEND tb_dynpfields. * Read screen field values before PAI field transport. This FM is used for dynamically * reading a value from the selection screen field . CALL FUNCTION 'DYNP_VALUES_READ' EXPORTING dyname = wf_dyname dynumb = wf_dynumb TABLES dynpfields = tb_dynpfields EXCEPTIONS invalid_abapworkarea = 1 invalid_dynprofield = 2 invalid_dynproname = 3 invalid_dynpronummer = 4 invalid_request = 5 no_fielddescription = 6 invalid_parameter = 7 undefind_error = 8 double_conversion = 9 stepl_not_found = 10 OTHERS = 11. IF sy-subrc <> 0.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
* Read the tbale tb_dynpfields to read the dynamic value of pa_werks
READ TABLE tb_dynpfields INDEX 1.
IF sy-subrc = 0.
wf_werks = tb_dynpfields-fieldvalue.
* Populate the table tb_object_range. Make sure that we filter out null values as it * might appear on the screen.
SELECT werks object
INTO TABLE tb_object_range
FROM zais_mmg
WHERE werks EQ wf_werks
and object NE ' '.
* Sorting is always done before dlete adjacent duplicate.
sort tb_object_range.
* This will delete all duplicate entries. Or else when you press F4, it will display * the duplicates also.
delete adjacent duplicates from tb_object_range comparing object.
* F4 help also returning the value to be displayed in internal table. If the internal table is empty, it will display the message saying 'Values are not found'.
retfield = co_retfield
dynpprog = co_dynprog
dynpnr = sy-dynnr
dynprofield = wf_dynpro
value_org = co_s
value_tab = tb_object_range
parameter_error = 1
no_values_found = 2
IF sy-subrc <> 0.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDFORM. " object_f4help

No comments:

Post a Comment