Wednesday, October 12, 2011

Search Helps with Search Help Exit

Create a search help either with view or DB table depending on requirement.
then assith the Table/View in search help(my requirement was satisfied by Elementary, same approach )

Delcare Changing & Tables in the Search help exit

Then customize the following code according to the requirements


FUNCTION zirm_prdclass_brand.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  TABLES
*"      SHLP_TAB TYPE  SHLP_DESCT
*"      RECORD_TAB STRUCTURE  SEAHLPRES
*"  CHANGING
*"     REFERENCE(SHLP) TYPE  SHLP_DESCR
*"     REFERENCE(CALLCONTROL) LIKE  DDSHF4CTRL STRUCTURE  DDSHF4CTRL
*"----------------------------------------------------------------------

  TYPESBEGIN OF ty_mara,
          matnr TYPE matnr,
           vkorg TYPE vkorg,
           vtweg  TYPE vtweg,
          prodh TYPE prodh_d,
         END OF ty_mara,

         BEGIN OF ty_final,
           matnr TYPE matnr,
           vkorg TYPE vkorg,
           vtweg  TYPE vtweg,
           zzprodh4  TYPE zzprodh4,
           zzprodh5  TYPE zzprodh5,
           zzprodh6  TYPE zzprodh6,
           END OF ty_final.

  DATA: lt_mara TYPE STANDARD TABLE OF ty_mara,
        lt_final TYPE STANDARD TABLE OF ty_final,
        ls_mara TYPE ty_mara,
        ls_final TYPE ty_final.
  DATA: it_mara TYPE STANDARD TABLE OF mvke,
        w_mara TYPE mvke,
        w_selopt LIKE LINE OF shlp-selopt,
        w_fielddrop LIKE LINE OF shlp-fieldprop.

  DATA: l_vkorg(1).

  IF callcontrol-step = 'SELECT'.
    READ TABLE shlp_tab INDEX 1.
    CLEAR: l_vkorg.
    LOOP AT shlp-selopt INTO w_selopt.
      IF w_selopt-shlpfield = 'MATNR'.
        w_mara-matnr = w_selopt-low.
      ELSEIF w_selopt-shlpfield = 'VKORG'.
        w_mara-vkorg = w_selopt-low.
        l_vkorg = 'X'.
      ELSEIF w_selopt-shlpfield = 'VTWEG'.
        w_mara-vtweg = w_selopt-low.
      ENDIF.
    ENDLOOP.
    IF w_mara IS NOT INITIAL.
      APPEND w_mara  TO it_mara .
    ENDIF.


    LOOP AT shlp-fieldprop INTO w_fielddrop
    WHERE fieldname CS 'ZZPROD'.
      w_fielddrop-shlpoutput = 'X'.
      MODIFY shlp-fieldprop FROM w_fielddrop.
    ENDLOOP.
    CLEAR: w_fielddrop.
    IF NOT it_mara IS INITIAL AND l_vkorg = 'X'.
      SELECT matnr vkorg vtweg prodh FROM mvke
        INTO TABLE lt_mara
        FOR ALL ENTRIES IN it_mara
        WHERE matnr = it_mara-matnr
          AND vkorg = it_mara-vkorg.
    ELSEIF NOT it_mara IS INITIAL .
      SELECT matnr vkorg vtweg prodh FROM mvke
        INTO TABLE lt_mara
        FOR ALL ENTRIES IN it_mara
        WHERE matnr = it_mara-matnr.
    ELSE.
      SELECT matnr vkorg vtweg prodh FROM mvke
        INTO TABLE lt_mara.
    ENDIF.
    IF NOT lt_mara IS INITIAL.
      LOOP AT lt_mara INTO ls_mara.
        ls_final-matnr = ls_mara-matnr.
        ls_final-vkorg = ls_mara-vkorg.
        ls_final-vtweg = ls_mara-vtweg.
        IF shlp_tab-shlpname = 'ZIRM_BRAND'.
          ls_final-zzprodh4 = ls_mara-prodh+6(3).
        ELSEIF shlp_tab-shlpname = 'ZIRM_PRD_CLASS'.
          ls_final-zzprodh5 = ls_mara-prodh+9(3).
        ELSE.
          ls_final-zzprodh6 = ls_mara-prodh+12(3).
        ENDIF.
        APPEND ls_final TO lt_final.
      ENDLOOP.

    ENDIF.


    CALL FUNCTION 'F4UT_RESULTS_MAP'
      TABLES
        shlp_tab          = shlp_tab
        record_tab        = record_tab
        source_tab        = lt_final
      CHANGING
        shlp              = shlp
        callcontrol       = callcontrol
      EXCEPTIONS
        illegal_structure = 1
        OTHERS            = 2.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.

    callcontrol-step = 'DISP'.

  ENDIF.

  REFRESH: it_mara,
           lt_mara,
           lt_final.
ENDFUNCTION.