But what about a bit more complicated case, imagine, you would need to fill more dynpro fields based on search help result. Here you are out of standard techniques. Below example solves exactly this case.
It triggers manually standard SAP search help - in this case USER_COMP. This search help offers various selection methods how to pick a desired person, in the end it returns username.
Below F4 module gets username, reads user full name and fills both values on dynpro. Comments should be self explanatory enough ;-)
Dynpro coding:
PROCESS ON VALUE-REQUEST. " F4 actionFIELD gs_task_pool-responsible_pers MODULE f4_responsible.
Source code:
*&---------------------------------------------------------------------*
*& Module F4_RESPONSIBLE INPUT
*&---------------------------------------------------------------------*
* Transport values to dynpro/screen
*----------------------------------------------------------------------*
MODULE f4_responsible INPUT.
DATA: lt_dynpfields TYPE STANDARD TABLE OF dynpread,
ls_dynpfields LIKE LINE OF lt_dynpfields,
ls_shlp_descr TYPE shlp_descr,
lt_shlp_return_values TYPE STANDARD TABLE OF ddshretval,
lv_username TYPE xubname.
" Get search help description
CALL FUNCTION 'F4IF_GET_SHLP_DESCR'
EXPORTING
shlpname = 'USER_COMP' " Standard SAP search help name
shlptype = 'SH'
IMPORTING
shlp = ls_shlp_descr.
" Ask FM F4IF_START_VALUE_REQUEST for return values - set the sign
FIELD-SYMBOLS: <fs_interface> LIKE LINE OF ls_shlp_descr-interface.
LOOP AT ls_shlp_descr-interface ASSIGNING <fs_interface>.
<fs_interface>-valfield = 'X'.
ENDLOOP.
" Trigger search help popup screen
CALL FUNCTION 'F4IF_START_VALUE_REQUEST'
EXPORTING
shlp = ls_shlp_descr
TABLES
return_values = lt_shlp_return_values.
CLEAR lt_dynpfields.
CLEAR ls_dynpfields.
CLEAR lv_username.
CLEAR gs_user_address.
FIELD-SYMBOLS: <fs_return_value> LIKE LINE OF lt_shlp_return_values.
LOOP AT lt_shlp_return_values ASSIGNING <fs_return_value>.
" Fill 1th screen field
ls_dynpfields-fieldname = 'GS_TASK_POOL-RESPONSIBLE_USR'.
ls_dynpfields-fieldvalue = <fs_return_value>-fieldval.
APPEND ls_dynpfields TO lt_dynpfields.
" Fill 2nd screen field
lv_username = <fs_return_value>-fieldval.
gs_user_address = lcl_main=>self->get_user_detail( iv_username = lv_username ).
ls_dynpfields-fieldname = 'GS_TASK_POOL-RESPONSIBLE_PERS'.
ls_dynpfields-fieldvalue = gs_user_address-fullname.
CONDENSE ls_dynpfields-fieldvalue.
APPEND ls_dynpfields TO lt_dynpfields.
EXIT. " process just one item/person
ENDLOOP.
" Update screen fields
CALL FUNCTION 'DYNP_VALUES_UPDATE'
EXPORTING
dyname = '/FDSEU/HCPC' "Program name
dynumb = '0220' "Screen number
TABLES
dynpfields = lt_dynpfields
EXCEPTIONS
OTHERS = 0.
ENDMODULE. " F4_RESPONSIBLE INPUT
Sources on net:
- https://wiki.scn.sap.com/wiki/display/Snippets/F4+help+functionality+for+a+dynpro+screen+field+using+the+PROCESS+ON+VALUE-REQUEST+statement
- https://keremkoseoglu.wordpress.com/2009/03/25/how-to-call-a-sap-search-help-manually/
- https://stackoverflow.com/questions/17143057/can-i-call-a-search-help-programatically-with-some-parameters-already-filled-in