Enterprise Resource Planning Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
17,092

Introduction

As we use variant configuration in creative ways, we sometimes want to restrict characteristic values to those maintained in another table (not a variant table). SAP provides a mechanism in CT04 to use a function module to derive the possible values. This requires coding the select statements and output displays. This is a bit cumbersome to maintaine and repeat. With the below solution, you can create a search help with SE10 and then easily adapt this function module to use that search help. Maintenance of the search help is easy, and it is easy to create new ones with very little ABAP.

Implementation

This is an example using company code. The blue fields should be changed for your purposes.

   FUNCTION Z_BUKRS_CHECK_F4.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(CHARACT_NO) LIKE  CABN-ATINN
*"     VALUE(CHARACT) LIKE  CABN-ATNAM
*"     VALUE(DISPLAY) LIKE  RMCLF-KREUZ DEFAULT SPACE
*"     VALUE(ADDITIONAL_VALUES) LIKE  CABN-ATSON DEFAULT SPACE
*"     VALUE(MULTIPLE_VALUES) LIKE  RCTMV-ATLIS DEFAULT SPACE
*"     VALUE(LANGUAGE) LIKE  SY-LANGU DEFAULT SY-LANGU
*"     VALUE(DISPLAY_WITH_LANGUAGE) LIKE  RMCLF-KREUZ DEFAULT SPACE
*"  TABLES
*"      VALUES STRUCTURE  RCTVALUES
*"  EXCEPTIONS
*"      CANCELLED_BY_USER
*"----------------------------------------------------------------------

*This function is used in a characteristic to provide an F4 search using a common search help.
*Fill the first three constants as instructed and as needed for the specific characteristic.
*Note that a function without the '_F4' is created for the check and entered in the characteristic.
*Read the help documentation on the characteristic function field for full explanation.
* data definition ------------------------------------------------------

  CONSTANTSc_SHLPNAME TYPE SHLPNAME VALUE 'PCA_SHLP_BUKRS',
              c_shlpfield TYPE DDSHLPSFLD VALUE 'BUKRS',
               c_conv_routine TYPE RS38L_FNAM VALUE '',
              c_multi TYPE c VALUE 'X', "Set if multivalue characteristic
              del(1) TYPE c VALUE 'D',
              ins(1) TYPE c VALUE 'I'.
  DATAindx TYPE i,
        rc TYPE sy-subrc,
        return_tab TYPE TABLE OF DDSHRETVAL,
        shlp TYPE SHLP_DESCR.
  FIELD-SYMBOLS: <int> TYPE ddshiface,
                 <ret> TYPE DDSHRETVAL.

* Get search help data container.
  CALL FUNCTION 'F4IF_GET_SHLP_DESCR'
    EXPORTING
      SHLPNAME = c_SHLPNAME "Enter the Search help name here
      SHLPTYPE = 'SH'
    IMPORTING
      SHLP     = shlp.

* Mark the relevant field to be returned.
  LOOP AT shlp-interface ASSIGNING <int>
        WHERE shlpfield = c_shlpfield. "Enter the field to be exported.
    <int>-valfield = 'X'.
  ENDLOOP.

* Call the search help dialogue.
  CALL FUNCTION 'F4IF_START_VALUE_REQUEST'
    EXPORTING
      SHLP          = shlp
      MAXRECORDS    = 500
      MULTISEL      = c_multi
    IMPORTING
      RC            = rc
    TABLES
      RETURN_VALUES = return_tab.

** Remove any old selected values
*  LOOP AT values.
*    indx = sy-tabix.
*    READ TABLE return_tab WITH KEY fieldval(30) = values-value ASSIGNING <ret>.
*    IF sy-subrc <> 0.
*      values-status = del.
*      MODIFY values INDEX indx.
*    ENDIF.
*  ENDLOOP.

* Add the new values.
  LOOP AT return_tab ASSIGNING <ret>.
    IF c_conv_routine IS NOT INITIAL.
      CALL FUNCTION c_conv_routine
        EXPORTING
          input     = <ret>-fieldval(30)
        IMPORTING
          OUTPUT    = values-value
        EXCEPTIONS
          NOT_FOUND = 1
          OTHERS    = 2.
    ELSE.
      values-value = <ret>-fieldval(30).
    ENDIF.
    values-status = ins.
    APPEND values.
  ENDLOOP.
ENDFUNCTION.

11 Comments