Skip to Content
avatar image
Former Member

F4 Search Help

Dear all,

I'm having a a requirement where I need to populate next parameter on the selections screen based on the input from first search help field.

If you look at below upon selecting P_KUNNR value from search help , P_VKORG needs to be defaulted. Remember that KUNNR value may be assigned to multiple Sales Organizations .

I have written below code but it is always reading first record from internal table because I'm reading by KUNNR - Not sure how to retrieve the index of the selected row on the search help screen so that I can read the correct row from internal table.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_kunnr.

PERFORM provide_search_help_kunnr.

FORM provide_search_help_kunnr.

* Declaration for Transactional Data
TYPES: BEGIN OF ty_acct,
vkorg TYPE vkorg,
kunnr TYPE zkunnr_sis,
znicknm TYPE znicknm,
END OF ty_acct.

DATA: lt_acct TYPE TABLE OFty_acct,
ls_acct TYPE ty_acct,
lv_kunnr TYPE kunnr,
l_repid TYPE sy-repid,
l_dynnr TYPE sy-dynnr..

* Search Help related declarations.

DATA : lt_fmap TYPE STANDARD TABLE OF dselc ,
lt_returntab TYPE STANDARD TABLE OF ddshretval,
lt_dynpread TYPE STANDARD TABLE OF dynpread.
DATA:
ls_dynpread TYPE dynpread,
ls_fmap TYPE dselc.

FIELD-SYMBOLS: <rwa> LIKE LINE OF lt_returntab.
CLEAR:lv_kunnr,lt_acct,ls_acct.
l_repid = sy-repid.
l_dynnr = sy-dynnr.
SELECT DISTINCT vkorg kunnr znicknm
FROM ztsis_accounts
INTO TABLE lt_acct.
ls_fmap-dyfldname = ls_fmap-fldname = 'VKORG'. APPEND ls_fmap TO lt_fmap.
ls_fmap-dyfldname = ls_fmap-fldname = 'KUNNR'. APPEND ls_fmap TO lt_fmap.
ls_fmap-dyfldname = ls_fmap-fldname = 'ZNICKNM'. APPEND ls_fmap TO lt_fmap.

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'KUNNR'
dynpprog = l_repid
dynpnr = l_dynnr
dynprofield = 'KUNNR'
value_org = 'S'
TABLES
value_tab = lt_acct
return_tab = lt_returntab
dynpfld_mapping = lt_fmap
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF sy-subrc = 0.
READ TABLE lt_returntab ASSIGNING <rwa> INDEX 1.
CHECK sy-subrc EQ 0.
p_kunnr = <rwa>-fieldval.


CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = p_kunnr
IMPORTING
output = lv_kunnr.


SORT lt_acct BY kunnr.


READ TABLE lt_acct INTO ls_acct WITH KEY kunnr = lv_kunnr BINARY SEARCH.

ls_dynpread-fieldname = 'P_VKORG'.
ls_dynpread-fieldvalue = ls_acct-vkorg.
APPEND ls_dynpread TO lt_dynpread.
CALL FUNCTION 'DYNP_VALUES_UPDATE'
EXPORTING
dyname = sy-cprog
dynumb = sy-dynnr
TABLES
dynpfields = lt_dynpread.
ENDIF.

ENDFORM.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Oct 14, 2016 at 07:15 PM

    Hi

    You can define a your own form in order to change a parameter of the search help and so all fields of selected line will be return

    Of course I haven't your z-object, so I use KNVV table instead of ztsis_accounts, but it's the same

    Selection-screen:

    PARAMETERS: P_KUNNR LIKE KNA1-KUNNR.
    PARAMETERS: P_VKORG LIKE KNVV-VKORG.
    

    Event for F4:

    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_KUNNR.
      PERFORM PROVIDE_SEARCH_HELP_KUNNR.

    The form

    FORM PROVIDE_SEARCH_HELP_KUNNR.
    
    * Declaration for Transactional Data
      TYPES: BEGIN OF TY_ACCT,
              VKORG TYPE VKORG,
              KUNNR TYPE KUNNR,
    *         ZNICKNM TYPE ZNICKNM,
      END OF TY_ACCT.
    
      DATA: LT_ACCT  TYPE TABLE OF TY_ACCT,
            LS_ACCT  TYPE TY_ACCT,
            LV_KUNNR TYPE KUNNR,
            L_REPID  TYPE SY-REPID,
            L_DYNNR  TYPE SY-DYNNR..
    
    * Search Help related declarations.
      DATA : LT_RETURNTAB TYPE STANDARD TABLE OF DDSHRETVAL,
             LT_DYNPREAD  TYPE STANDARD TABLE OF DYNPREAD.
      DATA:  LS_DYNPREAD  TYPE DYNPREAD.
    
      FIELD-SYMBOLS: <RWA> LIKE LINE OF LT_RETURNTAB.
    
      L_REPID = SY-REPID.
      L_DYNNR = SY-DYNNR.
    
      SELECT VKORG KUNNR UP TO 20 ROWS
         FROM KNVV
             INTO TABLE LT_ACCT.
    
      CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
        EXPORTING
          RETFIELD         = 'KUNNR'
          DYNPPROG         = L_REPID
          DYNPNR           = L_DYNNR
          CALLBACK_PROGRAM = L_REPID
          CALLBACK_FORM    = 'F4_FORM'                "<--------The form where change help parameter
          VALUE_ORG        = 'S'
        TABLES
          VALUE_TAB        = LT_ACCT
          RETURN_TAB       = LT_RETURNTAB
        EXCEPTIONS
          PARAMETER_ERROR  = 1
          NO_VALUES_FOUND  = 2
          OTHERS           = 3.
    
    
    
      IF SY-SUBRC = 0.
    * Now LT_RETURNTAB have both fields of your internal table LT_ACCT with values of selected lines
        LOOP AT LT_RETURNTAB ASSIGNING <RWA>.    
          CASE <RWA>-FIELDNAME.
            WHEN 'F0001'.
              LS_DYNPREAD-FIELDNAME  = 'P_VKORG'.
              LS_DYNPREAD-FIELDVALUE = <RWA>-FIELDVAL.
              APPEND LS_DYNPREAD TO LT_DYNPREAD.
    
              CALL FUNCTION 'DYNP_VALUES_UPDATE'
                EXPORTING
                  DYNAME     = SY-CPROG
                  DYNUMB     = SY-DYNNR
                TABLES
                  DYNPFIELDS = LT_DYNPREAD.
            WHEN 'F0002'.
              P_KUNNR = <RWA>-FIELDVAL.
          ENDCASE.
        ENDLOOP.
      ENDIF.
    ENDFORM. 

    Form to be called by F4IF_INT_TABLE_VALUE_REQUEST

    FORM F4_FORM TABLES RECORD_TAB    STRUCTURE SEAHLPRES
                 CHANGING SHLP_TOP    TYPE SHLP_DESCR
                          CALLCONTROL TYPE DDSHF4CTRL.
      CALLCONTROL-RETALLFLDS = 'X'.                  "If you set this field the fm F4IF_INT_TABLE_VALUE_REQUEST returns all                                                     fields
    ENDFORM.    
    Add comment
    10|10000 characters needed characters exceeded

  • Oct 14, 2016 at 06:53 PM

    Whatever the line selected by the user, the parameter RETURN_TAB will contain only the selected line. So, I don't understand your question.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 15, 2016 at 07:48 PM

    Sundra - Max solution really worked .

    Add comment
    10|10000 characters needed characters exceeded