For this,
Create the structure YCPS_BOM_STR same as STPO_API02.
Copy the function group RSAX and use the function module structure RSAX_GET_DATA_SIMPLE .
Algorithm of the Function module:
•Selections to be included are Plant, Alternative BOM, BOM Usage and material.
•Among these selections Plant needs to be entered. If there is no specific value enter (0001 to 9999).
•Select all the relevant materials from MAST table into internal table for the selections given above.
•Call the FM CSAP_MAT_BOM_ITEM_SELECT for each material.
•This FM will give all the Components, its Qty, Its UOM, Valid From and Valid to Date for each material passed.
•Include the logic for conversions to different data types like DATE and QUAN.
FUNCTION FUNCTION-MODULE NAME.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(I_REQUNR) TYPE
SRSC_S_IF_SIMPLE-REQUNR
*" REFERENCE(I_DSOURCE) TYPE
SRSC_S_IF_SIMPLE-DSOURCE OPTIONAL
*" REFERENCE(I_MAXSIZE) TYPE
SRSC_S_IF_SIMPLE-MAXSIZE OPTIONAL
*" REFERENCE(I_INITFLAG) TYPE
SRSC_S_IF_SIMPLE-INITFLAG OPTIONAL
*" REFERENCE(I_READ_ONLY) TYPE
SRSC_S_IF_SIMPLE-READONLY OPTIONAL
*" TABLES
*" I_T_SELECT TYPE SRSC_S_IF_SIMPLE-T_SELECT
OPTIONAL
*" I_T_FIELDS TYPE SRSC_S_IF_SIMPLE-T_FIELDS
OPTIONAL
*" E_T_DATA STRUCTURE YCPS_BOM_STR OPTIONAL
*" EXCEPTIONS
*" NO_MORE_DATA
*" ERROR_PASSED_TO_MESS_HANDLER
*"----------------------------------------------------------------------
* Auxiliary Selection criteria structure
DATA: L_S_SELECT TYPE SRSC_S_SELECT,
LT_DATE LIKE STKO-DATUV,
I_QTY TYPE STPO-MENGE,
L_TABIX LIKE SY-TABIX.
DATA: L_COMP_QTY(18).
DATA: BEGIN OF I_MAST OCCURS 0,
MATNR LIKE MAST-MATNR, "MATERIAL
WERKS LIKE MAST-WERKS, "PLANT
STLAN LIKE MAST-STLAN, "BOM USAGE
STLNR LIKE MAST-STLNR, "BOM
STLAL LIKE MAST-STLAL, "ALTERNATIVE BOM
END OF I_MAST.
DATA: I_STPO LIKE STPO_API02 OCCURS 0 WITH HEADER
LINE,
YCPS_BOM_TAB LIKE YCPS_BOM_STR OCCURS 0 WITH HEADER
LINE.
TABLES: MAST.
RANGES: R_MATNR FOR MAST-MATNR,
R_WERKS FOR MAST-WERKS,
R_STLAN FOR MAST-STLAN,
R_STLAL FOR MAST-STLAL.
* Maximum number of lines for DB table
STATICS: S_S_IF TYPE SRSC_S_IF_SIMPLE,
S_COUNTER_DATAPAKID LIKE SY-TABIX.
* Initialization mode (first call by SAPI) or data
transfer mode
* (following calls) ?
IF I_INITFLAG = SBIWA_C_FLAG_ON.
************************************************************************
* Initialization: check input parameters
* buffer input parameters
* prepare data selection
************************************************************************
* Check DataSource validity
CASE I_DSOURCE.
WHEN 'DATA-SOURCE NAME'.
WHEN OTHERS.
IF 1 = 2. MESSAGE E009(R3). ENDIF.
* this is a typical log call. Please write every
error message like this
LOG_WRITE 'E' "message type
'R3'" message
class
'009' "message number
I_DSOURCE "message variable 1
' '. "message variable 2
RAISE ERROR_PASSED_TO_MESS_HANDLER.
ENDCASE.
APPEND LINES OF I_T_SELECT TO S_S_IF-T_SELECT.
* Fill parameter buffer for data extraction calls
S_S_IF-REQUNR = I_REQUNR.
S_S_IF-DSOURCE = I_DSOURCE.
S_S_IF-MAXSIZE = I_MAXSIZE.
* Fill field list table for an optimized select
statement
* (in case that there is no 1:1 relation between
InfoSource fields
* and database table fields this may be far from
beeing trivial)
APPEND LINES OF I_T_FIELDS TO S_S_IF-T_FIELDS.
ELSE. "Initialization mode or data extraction ?
************************************************************************
* Data transfer: First Call OPEN CURSOR + FETCH
* Following Calls FETCH only
************************************************************************
* First data package -> OPEN CURSOR
IF S_COUNTER_DATAPAKID = 0.
CLEAR: R_MATNR,
R_WERKS,
R_STLAN,
R_STLAL.
REFRESH: R_MATNR,
R_WERKS,
R_STLAN,
R_STLAL.
*-- Material Number
LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE
FIELDNM = 'MATNR'.
MOVE-CORRESPONDING L_S_SELECT TO R_MATNR.
APPEND R_MATNR.
ENDLOOP.
*-- Plant
LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE
FIELDNM = 'WERKS'.
MOVE-CORRESPONDING L_S_SELECT TO R_WERKS.
APPEND R_WERKS.
ENDLOOP.
*-- Item Category
LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE
FIELDNM = 'STLAN'.
MOVE-CORRESPONDING L_S_SELECT TO R_STLAN.
APPEND R_STLAN.
ENDLOOP.
*-- Alternative BOM
LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE
FIELDNM = 'BOM_ALT'.
MOVE-CORRESPONDING L_S_SELECT TO R_STLAL.
APPEND R_STLAL.
ENDLOOP.
SELECT * INTO CORRESPONDING FIELDS OF TABLE I_MAST
FROM MAST
WHERE WERKS IN R_WERKS
AND MATNR IN R_MATNR
AND STLAN IN R_STLAN
AND STLAL IN R_STLAL.
IF SY-SUBRC EQ 0.
SORT I_MAST BY WERKS MATNR STLNR.
DELETE I_MAST WHERE WERKS = ''.
ENDIF.
LOOP AT I_MAST.
CALL FUNCTION 'CSAP_MAT_BOM_ITEM_SELECT'
EXPORTING
* I_STPO =
MATERIAL = i_mast-matnr
PLANT = i_mast-werks
BOM_USAGE = i_mast-stlan
ALTERNATIVE = i_mast-stlal
* VALID_FROM = p_datuv
* VALID_TO = p_datub
FL_MATERIAL_CHECK = 'X'
FL_FOREIGN_KEY_CHECK = 'X'
* IMPORTING
* FL_WARNING =
TABLES
T_STPO = i_stpo
EXCEPTIONS
ERROR = 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.
LOOP AT I_STPO.
L_COMP_QTY = I_STPO-COMP_QTY.
REPLACE ALL OCCURRENCES OF ',' IN L_COMP_QTY WITH
SPACE.
CONDENSE L_COMP_QTY.
I_QTY = L_COMP_QTY.
MOVE-CORRESPONDING I_MAST TO YCPS_BOM_TAB.
*Individual mapping is done as the valid to and from
date is not in BW format
YCPS_BOM_TAB-BOM_ALT = I_STPO-BOM_ALT.
YCPS_BOM_TAB-ITEM_CATEG = I_STPO-ITEM_CATEG.
YCPS_BOM_TAB-BOM_NO = I_STPO-BOM_NO.
YCPS_BOM_TAB-ITEM_NO = I_STPO-ITEM_NO.
YCPS_BOM_TAB-ITEM_NODE = I_STPO-ITEM_NODE.
YCPS_BOM_TAB-ITEM_COUNT = I_STPO-ITEM_COUNT.
YCPS_BOM_TAB-COMPONENT = I_STPO-COMPONENT.
YCPS_BOM_TAB-COMP_QTY = I_QTY.
YCPS_BOM_TAB-COMP_UNIT = I_STPO-COMP_UNIT.
YCPS_BOM_TAB-VALID_FROM+0(4) =
I_STPO-VALID_FROM+6(4).
YCPS_BOM_TAB-VALID_FROM+4(2) =
I_STPO-VALID_FROM+0(2).
YCPS_BOM_TAB-VALID_FROM+6(2) =
I_STPO-VALID_FROM+3(2).
YCPS_BOM_TAB-VALID_TO+0(4) = I_STPO-VALID_TO+6(4).
YCPS_BOM_TAB-VALID_TO+4(2) = I_STPO-VALID_TO+0(2).
YCPS_BOM_TAB-VALID_TO+6(2) = I_STPO-VALID_TO+3(2).
YCPS_BOM_TAB-RECURSIVE = I_STPO-RECURSIVE.
YCPS_BOM_TAB-DEP_LINK = I_STPO-DEP_LINK.
YCPS_BOM_TAB-ALE_IND = I_STPO-ALE_IND.
YCPS_BOM_TAB-CHG_NO_TO = I_STPO-CHG_NO_TO.
YCPS_BOM_TAB-CREATED_ON = I_STPO-CREATED_ON.
YCPS_BOM_TAB-CREATED_BY = I_STPO-CREATED_BY.
YCPS_BOM_TAB-CHANGED_ON = I_STPO-CHANGED_ON.
YCPS_BOM_TAB-CHANGED_BY = I_STPO-CHANGED_BY.
YCPS_BOM_TAB-FLDELETE = I_STPO-FLDELETE.
APPEND YCPS_BOM_TAB.
ENDLOOP.
REFRESH I_STPO.
ENDLOOP.
ENDIF. "First data package ?
IF I_STPO IS INITIAL.
RAISE NO_MORE_DATA.
ENDIF.
APPEND LINES OF YCPS_BOM_TAB TO E_T_DATA.
S_COUNTER_DATAPAKID = S_COUNTER_DATAPAKID + 1.
REFRESH YCPS_BOM_TAB.
ENDIF.
ENDFUNCTION.