简体   繁体   中英

New record for custom F4

I created a Search Help which has 2 fields: id and description

I want to add new row into the results which don't come from the source table. I heard that we can do it via a Search Help Exit, but I don't know how to do that.

I want to add this row:

ID       Description
00004    "For all users"

Context: my Search Help was created in the BackEnd and I appended it to an assignment block on my CRM WEBUI component and it works good. But, now I need to add new value into my F4, only one new row.

By default, a Search Help displays the contents of a database table or view ("selection method"), all columns or only specific columns defined in the search help.

If you wish to display different data either by building it from scratch (empty "selection method") or by adapting the data read from that "selection method", you need to use a Search Help Exit .

A search help exit is a function module to be assigned to the search help, called at different moments (called "steps") during the execution of the search help, which can modify the behavior and contents of the search help. The most important steps are:

  • "SELECT": it's called before SAP extracts the data from the database (if any), after the selection dialog was eventually displayed to enter values to filter the data. If the "selection method" was left empty, you may initialize the data yourself at this moment.
  • "DISP": it's called after SAP extracts the data from the database (if there's a "selection method"), just before it's displayed. At this time, you may change the data.

Steps to create a Search Help Exit :

  1. Create the function module with the following signature (you may copy the template function module F4IF_SHLP_EXIT_EXAMPLE ) :
     CHANGING VALUE(SHLP) TYPE SHLP_DESCR VALUE(CALLCONTROL) LIKE DDSHF4CTRL TABLES SHLP_TAB TYPE SHLP_DESCT RECORD_TAB LIKE SEAHLPRES.
  2. Add the ABAP code in your function module to build or filter the data:
    • The step name is the parameter callcontrol-step .
    • The records are in the parameter RECORD_TAB ; to change them, use an intermeidate internal table that you manually type to match the columns selected for the "hit list output" in the search help (order of columns is not important, because the logic of F4UT_* function modules hereafter is based on column names). To transfer RECORD_TAB to your internal table you call the function module F4UT_PARAMETER_VALUE_GET (one column at a time, call it repeatedly for several columns), and to transfer your internal table to RECORD_TAB you call the function module F4UT_RESULTS_MAP .
    • If you need them, the eventual data selections are in the parameter SHLP-SELOPT .
  3. Edit the Search Help (transaction code SE11), and enter the name of your function module in the screen field "Search help exit".

For more information, read the SAP Library about Search Help Exits , the F4UT_* function modules are provided with some documentation in your system, and there are demos in your system like the search help SFLIGHT.

In your very specific case, I advise you to not define a "selection method" and use a search help exit with this code:

DATA source_tab TYPE TABLE OF zyourtable.
IF callcontrol-step = 'SELECT'.
  SELECT * FROM zyourtable INTO TABLE source_tab.
  APPEND value ty_source( ID = '00004' Description = 'For all users' ) TO source_tab.
  CALL FUNCTION 'F4UT_RESULTS_MAP' " transfer of source_tab to record_tab
    TABLES
      SHLP_TAB    = shlp_tab
      RECORD_TAB  = record_tab
      SOURCE_TAB  = source_tab
    CHANGING
      SHLP        = shlp
      CALLCONTROL = callcontrol.
ENDIF.

Here's my final solution based on Sandra answer:

IF callcontrol-step = 'SELECT'.
DATA: BEGIN OF ls_res_tab,
        id          TYPE zdt_favorite_retail_store,
        description TYPE zdt_favorite_retail_store_decr,
      END OF ls_res_tab.

DATA: res_tab LIKE TABLE OF ls_res_tab.

SELECT id description FROM ztx_fav_store INTO TABLE res_tab.

ls_res_tab-id = '00004'.
ls_res_tab-description = 'For all  users'.
APPEND ls_res_tab TO res_tab.

"* Prepare for output
CALL FUNCTION 'F4UT_RESULTS_MAP'
  TABLES
    shlp_tab          = shlp_tab
    record_tab        = record_tab
    source_tab        = res_tab
  CHANGING
    shlp              = shlp
    callcontrol       = callcontrol
  EXCEPTIONS
    illegal_structure = 1
    OTHERS            = 2.

EXIT. "Don't process STEP DISP additionally in this call.
ENDIF.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM