Using this information, specification workbench can be enhanced with customer own search functionality.
With standard SAP, specification can be searched for only one material. This shows how can we provide customer own search option to search specifications for multiple materialsn Range of materials.
ABAP developments:
Create three functiona modules
Create FM ZEHS_OCC_SUB_FIND_BY_MAT_PARA with code pasted in the bottom of the document.
This FM will be called to enter different materials(Selection )
Create FM ZEHS_OCC_SUB_FIND_BY_MAT with code in the bottom of the document
To get specification for the materials provided in the selection.
Create FM ZEHS_OCC_SUB_FIND_BY_MAT_CMD with code in attached
This FM will be used to to add selected specifications to search results
Configuration:
Maintain configuration as stated below to add custom extended search option.
Configuration Path:
SPRO->EHS->Basic Data and Tools->Basic Settings->Manage User exits
Create new entry with following details:
User Exit Cat SUB_QUERY
User Exit SUB_BY_MAT(Any name)
Specification SUBSTANCE
FM ZEHS_OCC_SUB_FIND_BY_MAT(Created above)
Sort sequence: (Enter any number based on your current
sequence)
Description: Substance by Material Number
After above steps go to CG02 and check search functionality:
Substance by Material Number will be shown like below and search for specifications.
GLOBAL DATA:
Global Data for FMs
TYPE-POOLS: ESP1, ESP12.
INCLUDE CBUI01.
INCLUDE CBUI03.
INCLUDE CBUI09.
TABLES: RLGRAP.
DATA: LG_FLG_CANCEL TYPE BOOLEAN VALUE FALSE.
DATA: LG_VALDAT LIKE ESTRH-VALFR.
DATA: LG_CUASTATUS LIKE TC01.
DATA: LG_PROVID LIKE ESTOCC-PROVID.
DATA: BEGIN OF LG_SUB_TAB OCCURS 0,
PROVSUBID LIKE ESTOCC-PROVSUBID,
PROVTIMESTAMP LIKE ESTOCC-PROVTIMESTAMP,
END OF LG_SUB_TAB.
DATA: LG_IOTAB LIKE RCGRHIOT OCCURS 0 WITH HEADER LINE.
RANGES:
R_MATNR FOR ESTMJ-MATNR, " Material Number
* global data for 'substance find by Material Number'
DATA: BEGIN OF LG_FIND_BY_MAT_DATA,
CALLERID LIKE TCGSGP-CALLERID
VALUE 'ZEHS_OCC_SUB_FIND_BY_MAT',
FLG_PARA_EXIST TYPE BOOLEAN VALUE FALSE,
END OF LG_FIND_BY_MAT_DATA.
FUNCTION ZEHS_OCC_SUB_FIND_BY_MAT_CMD.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_COMMAND) TYPE ESP12_EXTSEA_CMDFUNC_CMD_TYPE
*" VALUE(I_OBJTYPE) LIKE TCGOBJ-OBJTYPE OPTIONAL
*" EXPORTING
*" VALUE(E_FLG_PARA_EXIST) TYPE ESP1_BOOLEAN
*" TABLES
*" X_PARAMETER_TAB STRUCTURE TCGSGP
*" CHANGING
*" REFERENCE(X_ADDITIONAL_PARAMS) TYPE ESP12_EXTSEA_CMDFUNC_TYPE
*" OPTIONAL
*" EXCEPTIONS
*" UNKNOWN_COMMAND
*"----------------------------------------------------------------------
CASE I_COMMAND.
* clear parameter
WHEN ESP12_EXTSEA_CMDFUNC_CMD-CLEAR_PARA.
LG_FIND_BY_MAT_DATA-FLG_PARA_EXIST = FALSE.
* get parameter => fill x_parameter_tab from global data
WHEN ESP12_EXTSEA_CMDFUNC_CMD-GET_PARA.
IF LG_FIND_BY_MAT_DATA-FLG_PARA_EXIST = TRUE.
CLFRSH: X_PARAMETER_TAB.
X_PARAMETER_TAB-CALLERID = 'ZEHS_OCC_SUB_FIND_BY_MAT'.
APPEND X_PARAMETER_TAB.
ENDIF.
* set parameter => fill global data from x_parameter_tab
WHEN ESP12_EXTSEA_CMDFUNC_CMD-SET_PARA.
IF ( NOT X_PARAMETER_TAB[] IS INITIAL ).
READ TABLE X_PARAMETER_TAB WITH KEY
CALLERID = 'ZEHS_OCC_SUB_FIND_BY_MAT'.
IF SY-SUBRC = 0.
LG_FIND_BY_MAT_DATA-FLG_PARA_EXIST = FALSE.
ENDIF.
ENDIF.
* other command => raise exception
WHEN OTHERS.
RAISE UNKNOWN_COMMAND.
ENDCASE.
* fill export parameter
E_FLG_PARA_EXIST = LG_FIND_BY_MAT_DATA-FLG_PARA_EXIST.
ENDFUNCTION.
FUNCTION zehs_occ_sub_find_by_mat.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_VALDAT) TYPE ESTRH-VALFR DEFAULT SY-DATUM
*" TABLES
*" I_SUBSTANCE_TAB STRUCTURE RCGSTDRECN
*" I_ENVIRONMENT_TAB STRUCTURE TCGENV
*" E_SUBSTANCE_TAB STRUCTURE RCGSTDRECN
*" E_HITINFO_TAB STRUCTURE RCGHITINFO OPTIONAL
*" CHANGING
*" REFERENCE(X_ADDITIONAL_PARAMS) TYPE ESP12_EXTSEA_FUNC_TYPE
*" OPTIONAL
*" EXCEPTIONS
*" INTERNAL_ERROR
*"----------------------------------------------------------------------
IF NOT r_matnr[] IS INITIAL.
DATA: li_erecn LIKE rcgstdrecn OCCURS 0 WITH HEADER LINE.
DATA: l_restrictions LIKE sy-dbcnt.
REFRESH: e_substance_tab.
CLEAR: d_cnt, e_substance_tab.
SELECT recnroot " Sequence number
FROM estmj
INTO TABLE li_erecn
WHERE matnr IN r_matnr
AND delflg EQ space
AND valfr LE i_valdat
AND valto GE i_valdat.
DESCRIBE TABLE i_substance_tab LINES l_restrictions.
SORT i_substance_tab BY recn.
IF l_restrictions > 0.
LOOP AT li_erecn.
READ TABLE i_substance_tab WITH KEY recn = li_erecn-recn BINARY
SEARCH.
CHECK sy-subrc NE 0.
DELETE li_erecn.
ENDLOOP. " LOOP AT LI_ERECN.
ENDIF. " IF L_RESTRICTIONS > 0
e_substance_tab[] = li_erecn[].
FREE li_erecn.
ENDIF. " IF NOT R_SUBID[] IS INITIAL.
ENDFUNCTION.
FUNCTION ZEHS_OCC_SUB_FIND_BY_MAT_PARA.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_VALDAT) TYPE ESTRH-VALFR DEFAULT SY-DATUM
*" VALUE(I_FLG_SHOW_ONLY) TYPE ESP1_BOOLEAN
*" EXPORTING
*" VALUE(E_FLG_PARA_EXIST) TYPE ESP1_BOOLEAN
*" VALUE(E_FLG_CANCEL) TYPE ESP1_BOOLEAN
*" CHANGING
*" REFERENCE(X_ADDITIONAL_PARAMS) TYPE ESP12_EXTSEA_PARAFUNC_TYPE
*" OPTIONAL
*"----------------------------------------------------------------------
* initialize export parameter
E_FLG_PARA_EXIST = LG_FIND_BY_MAT_DATA-FLG_PARA_EXIST.
CALL FUNCTION 'COMPLEX_SELECTIONS_DIALOG'
EXPORTING
TITLE = 'Find by Material Number '
TABLES
RANGE = R_MATNR
EXCEPTIONS
NO_RANGE_TAB = 1
CANCELLED = 2
INTERNAL_ERROR = 3
INVALID_FIELDNAME = 4
OTHERS = 5
.
IF SY-SUBRC <> 0.
ENDIF. " IF SY-SUBRC <> 0.
IF NOT R_MATNR[] IS INITIAL.
LG_FIND_BY_MAT_DATA-FLG_PARA_EXIST = TRUE.
ELSE.
LG_FIND_BY_MAT_DATA-FLG_PARA_EXIST = FALSE.
ENDIF. " IF NOT R_MATNR[] IS INITIAL.
* Fill export parameter
E_FLG_CANCEL = LG_FLG_CANCEL.
CLEAR LG_FLG_CANCEL.
E_FLG_PARA_EXIST = LG_FIND_BY_MAT_DATA-FLG_PARA_EXIST.
ENDFUNCTION.