Search tool ABAP

For the convenience of adding records to the ALV table, you can use the forced call method search tools using the F4IF_FIELD_VALUE_REQUEST Functional Method. Passing the following parameters to the input:

  • tabname - table name or help view, as in our case. Available values for selection will be extracted from this view or table.

  • fieldname - name of the field in the tabname table in which this field is stored.

  • searchhelp - search tool for forced call.

  • multiple_choice - this field is responsible for the possibility of multiple choice of values.

You can also look at other parameters affecting the call of a given search tool by looking at its parameters.

As a result, we get a table of user selection results, in which the fieldval column stores user selected values. Now, if we use this function when adding fields to ALV table, then we can go through this table, move the necessary records, for example, checking on their presence in the target table. Then replenish, if necessary, additional fields. Then update ALV.
The final code of the ABAP program is as follows:

††††DATA:
††††††ls_kunnr†    TYPE†ts_kunnr,
††††††lt_kunnr_ret†TYPE†STANDARD†TABLE†OF†ddshretval,
††††† lr_kunnr†    TYPE†REF†TO†ddshretval.

††††CASE†e_ucomm.
††††††WHEN†'CREATE'.

††††††††CALL†FUNCTION†'F4IF_FIELD_VALUE_REQUEST'
††††††††††EXPORTING
††††††††††††tabname†††††††††=†'ZSD_KUNNR_RS'
††††††††††††fieldname†††††††=†'KUNNR'
††††††††††††searchhelp††††††=†'ZSD_KUNNR'
††††††††††††multiple_choice†=†abap_true
††††††††††TABLES
††††††††††††return_tab††††††=†lt_kunnr_ret
††††††††††EXCEPTIONS
††††††††††††OTHERS††††††††††=†5.

††††††††LOOP†AT†lt_kunnr_ret†REFERENCE†INTO†lr_kunnr_ret.

††††††††††READ†TABLE†mt_kunnr†TRANSPORTING†NO†FIELDS
††††††††††††WITH†KEY†kunnr†=†lr_kunnr_ret->fieldval.
††††††††††IF†sy-subrc†=†0.
††††††††††††CONTINUE.
††††††††††ENDIF.

††††††††††ls_kunnr-kunnr†=†lr_kunnr->fieldval.
††††††††††ls_kunnr-updkz†=†'I'.

††††††††††APPEND†ls_kunnr†TO†mt_kunnr.

††††††††ENDLOOP.
††††††WHEN†OTHERS.
††††††††RETURN.
††††ENDCASE.

††††mcl_alv->refresh(†).