Friday, October 18, 2013

SAP ABAP how to pass search help parameters in F4IF_FIELD_VALUE_REQUEST via callback form



Hi folks,
i am not a search help expert, but i think this little finding can be interesting for many of you.

You call a search help ( or the f4 of a table field that has a search help) and somehow you dont get the set parameter to work in order to pass the parameters to the search help.

I found out you can specify a callback routine where you can individually set each value for the parameters of the search help.
You have to use parameters callback_program and callback_form.
 The interface of the form is the following
FORM CALLB_value_request  TABLES   record_tab STRUCTURE seahlpres
                 CHANGING shlp TYPE shlp_descr_t   callcontrol LIKE ddshf4ctrl.

You find the sample report below. In particular here i am trying to use the standard IT0021 FAMSA search help.
This search help (H_PAD_T591A_SUBTY) has the pernr as a parameter. From the pernr it determines the molga and via a really weird table (T591A) with really ugly customizing it is determined if a subtype of IT0021 is valid for this pernr.
I do not want to program this whole thing from scratch so i want to use the search help. Here is the right way to call it.
Enjoy!



REPORT zzz.
START-OF-SELECTION.

  DATA lt_ret TYPE TABLE OF ddshretval.

  CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
    EXPORTING
      tabname             = 'P0021'
      fieldname           = 'FAMSA'
*     SEARCHHELP          = ' '
*     SHLPPARAM           = ' '
*     DYNPPROG            = ' '
*     DYNPNR              = ' '
*     DYNPROFIELD         = ' '
*     STEPL               = 0
*     VALUE               = ' '
*     MULTIPLE_CHOICE     = ' '
*     DISPLAY             = ' '
*     SUPPRESS_RECORDLIST = ' '
      callback_program    = sy-repid
      callback_form       = 'CALLB_VALUE_REQUEST'
*   CALLBACK_METHOD           =
*   SELECTION_SCREEN          = ' '
* IMPORTING
*   USER_RESET                =
  TABLES
    return_tab                = lt_ret
  EXCEPTIONS
*   FIELD_NOT_FOUND           = 1
*   NO_HELP_FOR_FIELD         = 2
*   INCONSISTENT_HELP         = 3
*   NO_VALUES_FOUND           = 4
    OTHERS                    = 5     .
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.


*&---------------------------------------------------------------------*
*&      Form
*&---------------------------------------------------------------------*
FORM CALLB_value_request  TABLES   record_tab STRUCTURE seahlpres
                 CHANGING shlp TYPE shlp_descr_t   callcontrol LIKE ddshf4ctrl.

  DATA: ls_interface TYPE ddshiface.

  LOOP AT shlp-interface INTO ls_interface.

    IF ls_interface-shlpfield = 'PERNR'.

      ls_interface-value = '00373737.

      MODIFY shlp-interface FROM ls_interface.

    ENDIF.

  ENDLOOP.
ENDFORM.