Wednesday, March 18, 2015



badi for infotypes





METHOD if_ex_hrpad00infty~after_input.

  DATA lv_datum               TYPE datum.
  DATA lv_adrs                TYPE text60.
  DATA lv_check(10)           TYPE n VALUE '1234567890'.
  DATA lv_days                TYPE  tfmatage.
  DATA lv_months              TYPE  tfmatage.
  DATA lv_years               TYPE  tfmatage.
  DATA badi_message_handler   TYPE REF TO cl_hrpa_message_list.
  DATA message_handler        TYPE REF TO if_hrpa_message_handler.
  DATA msg                    TYPE symsg.
  DATA is_ok                  TYPE boole_d.
*  CONSTANTS :

  CREATE OBJECT badi_message_handler.
  message_handler = badi_message_handler.
  msg-msgid = 'ZHR'."'YHBN'.
  msg-msgty = 'E'.
  msg-msgno = '030'.
*  msg-msgv1 =  c_ . "'Invalid Plan'(z09).
  DATA : ls_p0591 TYPE p0591.
  IF new_innnn-infty = '0591'.
    CALL METHOD cl_hr_pnnnn_type_cast=>prelp_to_pnnnn
      EXPORTING
        prelp = new_innnn
      IMPORTING
        pnnnn = ls_p0591.

    IF ls_p0591-dat01 IS NOT INITIAL
      AND ls_p0591-dat01 GT 0.
      IF  ls_p0591-gra01 IS INITIAL .
        lv_datum      =  ls_p0591-dat01.
        lv_adrs       =  ls_p0591-gra01.
      ENDIF.
    ENDIF.

    IF ls_p0591-dat02 IS NOT INITIAL
    AND ls_p0591-dat02 GT 0.

      IF  ls_p0591-gra02 IS INITIAL .
        lv_datum      =  ls_p0591-dat02.
        lv_adrs       =  ls_p0591-gra02.
      ENDIF.
    ENDIF.

    IF ls_p0591-dat03 IS NOT INITIAL
      AND ls_p0591-dat03 GT 0.

      IF  ls_p0591-gra03 IS INITIAL .
        lv_datum      =  ls_p0591-dat03.
        lv_adrs       =  ls_p0591-gra03.
      ENDIF.

    ENDIF.
    IF ls_p0591-dat04 IS NOT INITIAL
        AND ls_p0591-dat04 GT 0.

      IF  ls_p0591-gra04 IS INITIAL .
        lv_datum      =  ls_p0591-dat04.
        lv_adrs       =  ls_p0591-gra04.
      ENDIF.

    ENDIF.

    IF ls_p0591-dat05 IS NOT INITIAL
      AND ls_p0591-dat05 GT 0.

      IF  ls_p0591-gra05 IS INITIAL .
        lv_datum      =  ls_p0591-dat05.
        lv_adrs       =  ls_p0591-gra05.
      ENDIF.
    ENDIF.
    IF   lv_datum  IS NOT INITIAL
        AND lv_adrs IS INITIAL .

      CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
        EXPORTING
          i_date_from    = lv_datum
*         I_KEY_DAY_FROM =
          i_date_to      = sy-datum
*         I_KEY_DAY_TO   =
*         I_FLG_SEPARATE = ' '
        IMPORTING
          e_days         = lv_days
          e_months       = lv_months
          e_years        = lv_years.

      IF  lv_years  LT 18 AND lv_adrs IS INITIAL .

        CALL METHOD message_handler->add_message
          EXPORTING
            message = msg
            cause   = message_handler->unknown.
        is_ok   = space.
        badi_message_handler->add_messages( message_handler ).

        RAISE error_with_message.
      ENDIF.
      CLEAR : lv_datum,
              lv_adrs,
              lv_days,
              lv_months,
              lv_years.

    ENDIF.
*BREAK ABAP07.
*     data : lv_name1(30) type c.
***--logic for gratuity nominations
*    if ls_p0591-nam01 is not initial.
*      lv_name1 = ls_p0591-nam01.
*    endif.
*
**set PARAMETER ID 'ABC' FIELD LV_NAME1.
*EXPORT LV_NAME1 FROM LV_NAME1 TO MEMORY ID 'LV_NAME1'.

  ENDIF.

*  IF new_innnn-infty = '0008'.
*
*    DATA:
*        ls_p0008     TYPE p0008.
*
*    CALL METHOD cl_hr_pnnnn_type_cast=>prelp_to_pnnnn
*      EXPORTING
*        prelp = new_innnn
*      IMPORTING
*        pnnnn = ls_p0008.
*
*
*    DATA : lv_char(10)  TYPE c.
*    DATA: lv_chr(10)    TYPE c,
*          lv_num        TYPE p.
*
*    lv_chr =  new_innnn-data1+92(10).
**lv_num
*    CALL FUNCTION 'MOVE_CHAR_TO_NUM'
*      EXPORTING
*        chr             = lv_chr
*      IMPORTING
*        num             = lv_num
*      EXCEPTIONS
*        convt_no_number = 1
*        convt_overflow  = 2
*        OTHERS          = 3.
*    IF sy-subrc <> 0.
** Implement suitable error handling here
*    ENDIF.
*  ENDIF.
ENDMETHOD.







METHOD if_ex_hrpad00infty~after_input .

  CHECK i001p-molga     EQ '21' AND
        new_innnn-infty EQ '2006'.

  DATA:
*    lt_0001 TYPE TABLE OF p0001,
*    lt_0007 TYPE TABLE OF p0007,
*    lt_0008 TYPE TABLE OF p0008,
*    lt_0016 TYPE TABLE OF p0016,
*    lv_quomo TYPE quomo,
    ls_2006 TYPE p2006,
    ls_old_2006 TYPE p2006,
    lv_mandt TYPE sy-mandt,
    lv_ok TYPE c.
  INCLUDE mp326011.

  PERFORM use_3260 IN PROGRAM mp326000
                   USING      new_innnn-begda
                              i001p-molga
                              lv_ok.
  CHECK lv_ok IS NOT INITIAL.
* A 3260 használatban van!

  CLASS cl_hr_pnnnn_type_cast DEFINITION LOAD.

  CALL METHOD cl_hr_pnnnn_type_cast=>prelp_to_pnnnn
    EXPORTING
      prelp = new_innnn
    IMPORTING
      pnnnn = ls_2006.
  PERFORM memory_id IN PROGRAM mp326000
                    USING      gv_memory_id.
  IMPORT gv_from_3260 TO gv_from_3260
         FROM MEMORY ID gv_memory_id.
  IF sy-subrc NE 0.
    CLEAR gv_from_3260.
  ENDIF.
  IF gv_from_3260 NE '3260'.
* { C5066700 2009.12.13 - Nem pontos kulccsal ellenőrizzük
*    CALL FUNCTION 'HR_READ_INFOTYPE'
*      EXPORTING
**       TCLAS                 = 'A'
*        pernr                 = ls_2006-pernr
*        infty                 = '0001'
*        begda                 = ls_2006-begda
*        endda                 = ls_2006-endda
**       BYPASS_BUFFER         = ' '
**       LEGACY_MODE           = ' '
**     IMPORTING
**       SUBRC                 =
*      TABLES
*        infty_tab             = lt_0001
*      EXCEPTIONS
*        infty_not_found       = 1
*        OTHERS                = 2.
*    CALL FUNCTION 'HR_READ_INFOTYPE'
*      EXPORTING
**       TCLAS                 = 'A'
*        pernr                 = ls_2006-pernr
*        infty                 = '0007'
*        begda                 = ls_2006-begda
*        endda                 = ls_2006-endda
**       BYPASS_BUFFER         = ' '
**       LEGACY_MODE           = ' '
**     IMPORTING
**       SUBRC                 =
*      TABLES
*        infty_tab             = lt_0007
*      EXCEPTIONS
*        infty_not_found       = 1
*        OTHERS                = 2.
*    CALL FUNCTION 'HR_READ_INFOTYPE'
*      EXPORTING
**       TCLAS                 = 'A'
*        pernr                 = ls_2006-pernr
*        infty                 = '0008'
*        begda                 = ls_2006-begda
*        endda                 = ls_2006-endda
**       BYPASS_BUFFER         = ' '
**       LEGACY_MODE           = ' '
**     IMPORTING
**       SUBRC                 =
*      TABLES
*        infty_tab             = lt_0008
*      EXCEPTIONS
*        infty_not_found       = 1
*        OTHERS                = 2.
*    CALL FUNCTION 'HR_READ_INFOTYPE'
*      EXPORTING
**       TCLAS                 = 'A'
*        pernr                 = ls_2006-pernr
*        infty                 = '0016'
*        begda                 = ls_2006-begda
*        endda                 = ls_2006-endda
**       BYPASS_BUFFER         = ' '
**       LEGACY_MODE           = ' '
**     IMPORTING
**       SUBRC                 =
*      TABLES
*        infty_tab             = lt_0016
*      EXCEPTIONS
*        infty_not_found       = 1
*        OTHERS                = 2.
*    PERFORM det_quomo IN PROGRAM saplhrlv
*                      TABLES     lt_0001
*                                 lt_0007
*                                 lt_0008
*                                 lt_0016
*                      USING      ls_2006-begda
*                                 ls_2006-pernr
*                      CHANGING   lv_quomo.
*    SELECT SINGLE mandt
*           INTO lv_mandt
*           FROM t5hpbs64
*           WHERE mopgk  EQ i503-konty
*           AND   mozko  EQ i001p-mozko
*           AND   quomo  EQ lv_quomo
*           AND   endda  GE ls_2006-begda
*           AND   begda  LE ls_2006-endda
*           AND   zosker EQ ls_2006-ktart.
    SELECT SINGLE mandt
           INTO lv_mandt
           FROM t5hpbs64
           WHERE endda  GE ls_2006-begda
           AND   begda  LE ls_2006-endda
           AND   zosker EQ ls_2006-ktart.
* } C5066700 2009.12.13 - Nem pontos kulccsal ellenőrizzük
    IF sy-subrc EQ 0.
* { A felhasználás kezdete és vége változhat!
      CALL METHOD cl_hr_pnnnn_type_cast=>prelp_to_pnnnn
        EXPORTING
          prelp = old_innnn
        IMPORTING
          pnnnn = ls_old_2006.
      CLEAR: ls_2006-desta,
             ls_2006-deend,
             ls_2006-aedtm,
             ls_2006-uname,
             ls_old_2006-desta,
             ls_old_2006-deend,
             ls_old_2006-aedtm,
             ls_old_2006-uname.
      IF ls_2006 NE ls_old_2006 OR
         ipsyst-ioper EQ 'DEL'  OR
         ipsyst-ioper EQ 'LIS9' OR
         ipsyst-ioper EQ 'EDQ'  OR
         ipsyst-ioper EQ 'MEDQ' OR
         ipsyst-ioper EQ 'DLIM'.
        MESSAGE e801(hrpbshu).
      ENDIF.
* } A felhasználás kezdete és vége változhat!
    ELSE.
* { C5066700 2009.12.03 - Nem pontos kulccsal ellenőrizzük
*      SELECT SINGLE mandt
*             INTO lv_mandt
*             FROM t5hpbs64
*             WHERE mopgk  EQ i503-konty
*             AND   mozko  EQ i001p-mozko
*             AND   quomo  EQ lv_quomo
*             AND   endda  GE ls_2006-begda
*             AND   begda  LE ls_2006-endda
*             AND   fajta  EQ ls_2006-ktart.
      SELECT SINGLE mandt
             INTO lv_mandt
             FROM t5hpbs64
             WHERE endda  GE ls_2006-begda
             AND   begda  LE ls_2006-endda
             AND   fajta  EQ ls_2006-ktart
             AND   zosker NE space.
* } C5066700 2009.12.03 - Nem pontos kulccsal ellenőrizzük
      IF sy-subrc EQ 0.
        MESSAGE e801(hrpbshu).
      ENDIF.
    ENDIF.
  ENDIF.
ENDMETHOD.

   
                             Enhancement of IT0001







 *----------------------------------------------------------------------*
*   INCLUDE ZP000120                                                   *
*----------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*&      Module  MOD_PBO  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE module_pbo_0001 OUTPUT.

  TABLES:zhrdesignation.

  DATA:
     lwa_desig           TYPE zhrdesignation,
     lwa_disp            TYPE zhr_discipline,
     lt_desig            TYPE TABLE OF zhrdesignation.

  DATA:
     gv_txt              TYPE zhrdetxt,
     gv_discp            TYPE zhr_distxt.

  IF  p0001-zzdesig IS NOT INITIAL.
    SELECT SINGLE * FROM zhrdesignation INTO lwa_desig
                   WHERE spras EQ sy-langu
                     AND desig = p0001-zzdesig.

    IF gv_txt IS INITIAL.
      gv_txt = lwa_desig-detxt.
    ENDIF.
    IF sy-subrc NE 0.
      MESSAGE i000(zhr) WITH p0001-zzdesig.
      CLEAR : p0001-zzdesig, zhrdesignation-detxt.
    ENDIF.
  ENDIF.

  IF p0001-zz_disp IS NOT INITIAL.

    SELECT SINGLE * FROM zhr_discipline INTO lwa_disp WHERE code EQ p0001-zz_disp.

    IF gv_discp IS INITIAL.
      gv_discp = lwa_disp-dis_txt.
    ENDIF.
    IF sy-subrc NE 0.
      MESSAGE i028(zhr) WITH p0001-zz_disp.

    ENDIF.

  ENDIF.

*  SELECT SINGLE detxt FROM zhrdesignation INTO gv_txt WHERE spras EQ sy-langu AND
*                                                      desig EQ p0001-zzdesig.




ENDMODULE.                 " MOD_PBO  OUTPUT


*----------------------------------------------------------------------*
*  MODULE f_getdesignations
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE f_getdesignations.

**  DATA lt_desig TYPE TABLE OF zhrdesignation.
  DATA:
     lt_retval           TYPE TABLE OF ddshretval,
     lwa_retval          TYPE ddshretval.

*  FIELD-SYMBOLS <fs_retval> TYPE ddshretval.
*  FIELD-SYMBOLS <fs_field> TYPE any.
*  DATA loc_field1 TYPE string.
*  DATA loc_field2 TYPE string.
  DATA: lt_fields TYPE TABLE OF dynpread,
      ls_fields  LIKE LINE OF lt_fields.
**
  CLEAR: lt_desig, lt_retval.
**
*--To get the Designation details.
  SELECT * FROM zhrdesignation INTO TABLE lt_desig.

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = 'DESIG'
      value_org       = 'S'
*     DYNPPROG        = SY-REPID
*     DYNPNR          = SY-DYNNR
      dynprofield     = 'P0001-ZZDESIG'
    TABLES
      value_tab       = lt_desig
*     field_tab       = field_tab
      return_tab      = lt_retval
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.
*  IF sy-subrc = 0.
*    READ TABLE lt_retval ASSIGNING <fs_retval> INDEX 1.
*    IF sy-subrc = 0.
*      SPLIT <fs_retval>-retfield AT '-' INTO loc_field1 loc_field2.
*      ASSIGN COMPONENT loc_field2 OF STRUCTURE p0001 TO <fs_field>.
*      <fs_field>  = <fs_retval>-fieldval.
*      CLEAR: loc_field1, loc_field2.
*      UNASSIGN <fs_field>.
*    ENDIF.
*  ENDIF.

  IF sy-subrc EQ 0.
    READ TABLE lt_retval INTO lwa_retval INDEX 1.
    p0001-zzdesig = lwa_retval-fieldval.
  ENDIF.

  READ TABLE lt_desig INTO zhrdesignation WITH KEY desig = p0001-zzdesig ."<fs_retval>-fieldval.
  IF sy-subrc = 0.
***--Setting the Dynpro value back.
    CLEAR: ls_fields, lt_fields.
**
    ls_fields-fieldname = 'P0001-ZZ_CATCODE'.
    ls_fields-fieldvalue = zhrdesignation-cat_code.
    APPEND ls_fields TO lt_fields.
    CLEAR: ls_fields.

    ls_fields-fieldname = 'P0001-ZZ_SCALE'.
    ls_fields-fieldvalue = zhrdesignation-scale.
    APPEND ls_fields TO lt_fields.
    CLEAR: ls_fields.

    ls_fields-fieldname = 'P0001-ZZ_GRADE'.
    ls_fields-fieldvalue = zhrdesignation-grade.
    APPEND ls_fields TO lt_fields.
    CLEAR: ls_fields.
**
    ls_fields-fieldname = 'GV_TXT'."ZHRDESIGNATION-DETXT'.
    ls_fields-fieldvalue = zhrdesignation-detxt.
    APPEND ls_fields TO lt_fields.
    CLEAR: ls_fields.
**
****        ls_fields-fieldname = 'ZHRDESIGNATION-SHTXT'.
****        ls_fields-fieldvalue = zhrdesignation-shtxt.
****        APPEND ls_fields TO lt_fields.
****        CLEAR: ls_fields.
**
    IF lt_fields IS NOT INITIAL.
      CALL FUNCTION 'DYNP_VALUES_UPDATE'
        EXPORTING
          dyname               = sy-cprog
          dynumb               = sy-dynnr
        TABLES
          dynpfields           = lt_fields
        EXCEPTIONS
          invalid_abapworkarea = 1
          invalid_dynprofield  = 2
          invalid_dynproname   = 3
          invalid_dynpronummer = 4
          invalid_request      = 5
          no_fielddescription  = 6
          undefind_error       = 7
          OTHERS               = 8.
      IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDIF.
  ENDIF.
**    ENDIF.
**  ENDIF.


ENDMODULE.                    "f_getdesignations



Creating a Basic SAP Search Help and explanation




The following steps show you how to create a basic SAP search help which allows you to provide the user with a selection help for a specific input field. A search help in its simplest form will just display a list of values from a single database table or view (selection method), which the user can select an option from. The value they select will then be entered into the input field the search help was requested from. 

Step1 - Create Search help 
Execute transaction SE11 and create a new search help called 'ZSHELP'. Please note this can be anything starting with Z that fits in the box but in some older SAP systems must be less than 5 characters long to be used as matchcode) 
 

Select Elementary search help 
 


Step2 - Enter basic details 
Enter a short description and PA0002 into the selection method field, this is basically the table the search help gets it data from 
 


Step3 - Enter search help parameters 
The next step is to add the fields that are going to be used by this search help as parameters i.e. those that appear in the output list or selection screen. To do this click the dropdown option of the first search help parameter 
 

Then select the appropriate field from the list (PERNR) 
 

Repeat this for fields NCHMC and VNAMC 
 
IMP - Import values from the screen/field to the search help 

EXP - Export value back to the input field(s) 

LPOS - Position on the output list the user selects from 

SPOS - Position on the selection screen if your search help to have select options which the user can enter to restrict further the search help value list by. 

Default - Add a default value the field is populated with 


Step4 - Save, activate and test 
Enter LPos values as follows (3,1,2) and tick the EXP column for the pernr field. This is the field who's value you want to be returned when the user selects an option/row. 
 

Save and activate the search help and press the test button, a screen will appear showing how the search help will appear on a pernr field. Press the search help button at the end of the field 
 

The search help output will now look like this with the fields in the order you specified then in the LPOS field 
 


Step5 - Change output order 
Now enter LPos values as follows (1,2,3) 
 

If you save, activate and test the search help again you will see that the output order has changed 
 


Step6 - Add selection options 
Now enter 1 and 2 against parameters NCHMC and VNAME within the SPos column 
 

Now if you save, activate and test the search help again you will see that you have the 2 parameters available on the search help to further restrict the value list. You may need to expand the view using the little arrow to see this additional options. 
 

Enter values in the additional parameters and notice how the hit list is restricted 
 


Step7 - Change Dialog behaviour 
Just to demonstrate what this option does, ensuring you still have values within the SPos column change the dialog behaviour from 'Display values immediately' to 'Dialog with value restriction' 
 

Now when you test it you should notice that the parameter restriction fields are display before you see the value results list. You could also add defaults to these fields using the default column. This option may be usful if the search help returns lots of values as it gives the user an option to restrict further before the data is retrieved and displayed. 
 

Step 8 - Assign matchcode to report parameter 
If you have created your search help to be matchcode compatible (i.e. less than 5 chars long) you can add the following line of ABAP code into your program: 

PARAMETER p_prog LIKE trdir-name MATCHCODE OBJECT zsh. 

alternatively see other methods of adding a search help.


SAP Search helps can be implemented in a variety of ways:
Add to Table fieldAdded via SE11: Place cursor on desired field within database and select menu path  Goto->Search help->for fieldEffect: If field used to create screen field, search help will be called when user executes F4/drop down input help. All fields on screen will be populated if appropriate fields exist in search help and screen.
Add to TableAdded via SE11: Place cursor on desired field within database and select menu path  Goto->Search help->for table
Add to Data elementAdded via SE11: Select desired data element (double click), enter search help name and parameters in appropriate fields on screen. Will be applied to all fields associated with that data element
Add to Screen fieldAdded via screen painter: One of field attributes is search help. Will only populate the one screen field.
Add to Sel. screen parameter (MATCHCODE)Added using 'matchcode' addition for parameters declaration: Search help name must be no more than 5 characters long.

e.g. PARAMETER p_prog LIKE trdir-name MATCHCODE OBJECT zsh.




How to create a Search Help with an Exit

Thanks to this option, it is possible to choose easily an entry without any need for controlling its relevance, since it is automatically supported by the search help functionality.
If you have luck, you would find a standard search help with adequate filters that fulfill your requirement. But, it is not so obvious to find the right search help!
For instance, the standard search help MAT1 contains several tabs with different filters to refine the search for material numbers. Even though, it is not possible to fulfill complex conditions like “Display only materials whose valuation class correspond to a given cost element group”
In such cases, you need to create your own search help and implement the specific conditions on your own, using search help exits.
In this blog, I will explain how to create a search help that fulfills the condition mentioned above:
“Display only materials whose valuation class correspond to a given cost element group”
For those who are not familiar with the concept of valuation classes in MM:
  • Go to transaction MM03 and choose a material number then select the “Accounting 1” view
  • Enter the plant in next popup then confirm.
  • The valuation class could be found under “Current valuation”.
  • The valuation class permits –in combination with other factors- to determine the G/L account on which the stock values have to be posted.
  • G/L accounts are assigned to valuation classes via transaction OBYC.
  • The FI G/L accounts correspond to primary cost elements in CO. Those are categorized into cost element groups that could be visualized using transaction KAH3.
We have now in mind the relationship between valuations classes in MM and cost element groups in CO. Lets create the search help that realizes our requirement.

First step: Create the search help via SE11

In SE11, choose “Search Help” and enter its name, then click on “Create”.
In the next popup, choose the option “Elementary search help” since we will create a single tab in the search help.
Enter a description then fill in the search help parameters:
  • Importing parameters are passed at runtime to the search help. In our example, it concerns information related to a cost element group, i.e. Group name, company code and controlling area.
  • Exporting parameters correspond to the fields displayed in the hit list. These are the material number and description.
  • Further parameters could be added such material type and language. These are filters displayed in the dialog box that enable further restriction of the hit list.
A default value could be assigned to each parameter by filling the column “Default value”. For example, if you want to display only materials with a specific type, you need just to add it as a default value.
Fill in the columns LPOS and SPOS with parameters positions in the hit list and the dialog box respectively.
Keep the dialog type “display values immediately” to display the hit list without going through a dialog box.
The result looks as follows:
It remains only to add the search help exit.
It is a function module with special parameters.
In SE37, create the function module Z_PS_F4_EXIT_MATNR.
It is necessary to add the following parameters. Otherwise the search help could not be activated.
  • Changing parameters
  • Table parameters:
  • Go now back to the search help and activate it

Second step: Implementation of the search help exit.

The search help implementation is structured as follows:
  1. Get importing parameters
  2. Get dialog box parameters
  3. Select material numbers corresponding to a given cost element group
  4. Constitute the result list of the search help
  • Get importing parametersFor this purpose, use parameter SHLP as follows:
  • Get dialog box parameters
    For this purpose, use parameter SHLP-SELOPT as follows:
  • Select material numbers corresponding to the selected cost element group
    This functionality is splitted into several function modules for reusability.
    • Create a function module that builds a range of cost elements belonging to a given group.
    Create a structure…..
    …and table type for the range
    Go to SE37 and create the function module Z_PS_GET_KSTAR_FROM_GROUP with the following parameters:
    Add the following code:
    • Create a function module that returns materials with valuation classes that correspond to a given cost element group.
    Create the following structure which will contain the parameters needed for valuation class selection.
    Create function module Z_PS_GET_RESSOURCE_BY_GRPNAME with following parameters.
Implement now the function module:
  • Call the previously created MF Z_PS_GET_KSTAR_FROM_GROUP to get the range of cost elements belonging to the group in parameter.
  • Use the following tables to find out the relevant material numbers:
    • T030: Get valuation classes corresponding to the previously determined cost elements range
    • MBEW: get materials that have one of the selected valuation classes
The final code looks as follows:
Go back to search help exit Z_PS_F4_EXIT_MATNR and add a call to the function module ‘Z_PS_GET_RESSOURCE_BY_GRPNAME’ :
  • Constitute result list
    Select descriptions of materials found in last step. The dialog box parameters have to be taken into account in the selection.
    Append the result to search help hit list
    To recapitulate, here is the complete code of search help exit Z_PS_F4_EXIT_MATNR

Third step: Test the search help

Create a table with the following zones:
Select zone “MATNR” and click on button “Srch Help”.
Enter the search help name
Mapping between search help parameters and table zones is done automatically. Just confirm the generated proposal.
Generate a maintenance dialog for the table to be able to maintain it via SM30.
Go now to SM30 and add a new entry in the table. Enter group name, company code and controlling area.
Use the search help of zone “Material” to get relevant values. When you execute it, only material numbers corresponding to the group name value are listed.
Change the group name and notice the effect in search help result
You can also display the dialog box to enable more filtering options