‎2011 Jun 13 10:55 PM
Hi Friends,
I have created a remote-enabled function module which simulates the MFBF transaction as follows.
Import Parameters:
I_WERKS type WERKS
I_MATNR type MATNR
I_QTY type ERFMG
I_UOM type SA_ERFME
I_VERID type VERID
I_BUDAT type BUDAT
I_HDRTXT type BKTXTExport Parameters:
CONFIRMATION type PRTNR
MATERIAL_DOC type MBLNR
RETURN type BAPIRET2Source code:
TABLES: ZWS_ERR.
DATA: WA_ZWS_ERR TYPE ZWS_ERR.
DATA: L_FLAGS TYPE BAPI_RM_FLG,
L_GENDATA TYPE BAPI_RM_DATGEN,
L_SPCDATA TYPE BAPI_RM_DATSTOCK.
DATA: BEGIN OF GM OCCURS 0.
INCLUDE STRUCTURE BAPI2017_GM_ITEM_CREATE.
DATA: END OF GM.
DATA: L_TMSTMP(11) TYPE p DECIMALS 7.
DATA: L_LOW TYPE TVARV_VAL.
*Make to Stock Scenario:
*check to see if we need to capture successful calls:
select SINGLE low INTO L_LOW
FROM tvarvc
where name = 'ZWS_MTS_GD'
AND LOW = 'X'.
IF I_WERKS IS INITIAL.
I_WERKS = '0010'.
ENDIF.
L_FLAGS = '01'.
L_GENDATA-MATERIALNR = I_MATNR.
L_GENDATA-PRODPLANT = I_WERKS.
L_GENDATA-PRODVERSION = I_VERID.
L_GENDATA-BACKFLQUANT = I_QTY.
L_GENDATA-UNITOFMEASURE = I_UOM.
L_GENDATA-DOCHEADERTXT = I_HDRTXT.
L_GENDATA-POSTDATE = I_BUDAT.
L_GENDATA-DOCDATE = SY-DATUM.
CALL FUNCTION 'BAPI_REPMANCONF1_CREATE_MTS'
EXPORTING
BFLUSHFLAGS = L_FLAGS
BFLUSHDATAGEN = L_GENDATA
BFLUSHDATAMTS = L_SPCDATA
IMPORTING
CONFIRMATION = CONFIRMATION
RETURN = RETURN
* TABLES
* SERIALNR =
GOODSMOVEMENTS = GM.
* Commit or rollback the bapi
if CONFIRMATION ne '0000000000'.
call function 'BAPI_TRANSACTION_COMMIT'.
*Capture "successful" calls in table to track usage
*for initial deploymnet (testing, monitoring, etc.)
*To turn off - Set TVARVC variable ZWS_MTS_GD to initial
IF L_LOW EQ 'X'.
get time stamp field L_TMSTMP.
WA_ZWS_ERR-MANDT = SY-MANDT.
WA_ZWS_ERR-TIMESTAMP = L_TMSTMP.
WA_ZWS_ERR-WERKS = I_WERKS.
WA_ZWS_ERR-MATNR = I_MATNR.
WA_ZWS_ERR-BACKFLQUANT = I_QTY.
WA_ZWS_ERR-UOM = I_UOM.
WA_ZWS_ERR-VERID = I_VERID.
WA_ZWS_ERR-BUDAT = I_BUDAT.
WA_ZWS_ERR-HDRTXT = I_HDRTXT.
WA_ZWS_ERR-TYPE = RETURN-TYPE.
WA_ZWS_ERR-ID = RETURN-ID.
WA_ZWS_ERR-MSGNO = RETURN-NUMBER.
WA_ZWS_ERR-MESSAGE = CONFIRMATION.
WA_ZWS_ERR-ERNAM = SY-UNAME.
WA_ZWS_ERR-ERDAT = SY-DATUM.
WA_ZWS_ERR-ERZET = SY-UZEIT.
INSERT ZWS_ERR FROM WA_ZWS_ERR.
endif.
else .
*Do not send application errors back to calling application!!
*Application Errors will be handled in SAP, so store the errors in table ZWS_ERR
*And then clear RETURN
call function 'BAPI_TRANSACTION_ROLLBACK' .
get time stamp field L_TMSTMP.
WA_ZWS_ERR-MANDT = SY-MANDT.
WA_ZWS_ERR-TIMESTAMP = L_TMSTMP.
WA_ZWS_ERR-WERKS = I_WERKS.
WA_ZWS_ERR-MATNR = I_MATNR.
WA_ZWS_ERR-BACKFLQUANT = I_QTY.
WA_ZWS_ERR-UOM = I_UOM.
WA_ZWS_ERR-VERID = I_VERID.
WA_ZWS_ERR-BUDAT = I_BUDAT.
WA_ZWS_ERR-HDRTXT = I_HDRTXT.
WA_ZWS_ERR-TYPE = RETURN-TYPE.
WA_ZWS_ERR-ID = RETURN-ID.
WA_ZWS_ERR-MSGNO = RETURN-NUMBER.
WA_ZWS_ERR-MESSAGE = RETURN-MESSAGE.
WA_ZWS_ERR-ERNAM = SY-UNAME.
WA_ZWS_ERR-ERDAT = SY-DATUM.
WA_ZWS_ERR-ERZET = SY-UZEIT.
INSERT ZWS_ERR FROM WA_ZWS_ERR.
CLEAR RETURN.
endif.When I test my FM, I am getting confirmation number(It is working fine till here) But I don't see any material document number.
Have I done anything wrong? Please suggest me in such a way that I need my material document number also get populated.
Thanks in Advance.
‎2011 Jun 14 7:41 AM
Hi,
Your getting the confirmation number using this bapi
CALL FUNCTION 'BAPI_REPMANCONF1_CREATE_MTS'
EXPORTING
BFLUSHFLAGS = L_FLAGS
BFLUSHDATAGEN = L_GENDATA
BFLUSHDATAMTS = L_SPCDATA
IMPORTING
CONFIRMATION = CONFIRMATION " Here ur getting Confirmation Number
RETURN = RETURN
* TABLES
* SERIALNR =
GOODSMOVEMENTS = GM.
Where your getting material Document Number?
Where your passing MATERIAL_DOC = material Document number?
I search Your code MATERIAL_DOC is not present. Your passing the confirmation number only Not a material Docu Number.
Once you got the Document Number Pass the value like
MATERIAL_DOC = ."Here you have to pass the value
regards,
Dhina..
‎2011 Jun 14 7:41 AM
Hi,
Your getting the confirmation number using this bapi
CALL FUNCTION 'BAPI_REPMANCONF1_CREATE_MTS'
EXPORTING
BFLUSHFLAGS = L_FLAGS
BFLUSHDATAGEN = L_GENDATA
BFLUSHDATAMTS = L_SPCDATA
IMPORTING
CONFIRMATION = CONFIRMATION " Here ur getting Confirmation Number
RETURN = RETURN
* TABLES
* SERIALNR =
GOODSMOVEMENTS = GM.
Where your getting material Document Number?
Where your passing MATERIAL_DOC = material Document number?
I search Your code MATERIAL_DOC is not present. Your passing the confirmation number only Not a material Docu Number.
Once you got the Document Number Pass the value like
MATERIAL_DOC = ."Here you have to pass the value
regards,
Dhina..
‎2011 Jun 14 2:31 PM
Hi Dhina,
Thank you so much for the response. The bapi ('BAPI_REPMANCONF1_CREATE_MTS'
)from which I am getting the confirmation number doesn't have a material document field.
In my program I have retrieved the value of material_doc value.
CLEAR: GV_MATERIAL_DOCUMENT.
SELECT MBLNR INTO GV_MATERIAL_DOCUMENT FROM MKPF
WHERE BUDAT EQ I_BUDAT
AND BLDAT EQ SY-DATUM.
ENDSELECT.
IF SY-SUBRC = 0.
WA_ZWS_ERR-MBLNR = GV_MATERIAL_DOCUMENT.
ENDIF.But still when I test my FM I get the confirmation number and the material_doc field is not populated. That is where I am confused.
Please suggest.
Thanks.
‎2011 Jun 15 5:19 AM
Hi Nani,
Your getting the material Document number using this field GV_MATERIAL_DOCUMENT right. Just pass the field value to
MATERIAL_DOC like.
CLEAR: GV_MATERIAL_DOCUMENT.
SELECT MBLNR INTO GV_MATERIAL_DOCUMENT FROM MKPF
WHERE BUDAT EQ I_BUDAT
AND BLDAT EQ SY-DATUM.
ENDSELECT.
IF SY-SUBRC = 0.
* WA_ZWS_ERR-MBLNR = GV_MATERIAL_DOCUMENT."instead of this
MATERIAL_DOC = GV_MATERIAL_DOCUMENT."use this st. to get the material docu num
ENDIF.
Please check the sy-subrc it will return 0 or not.
Regards,
Dhina..
‎2011 Jun 15 5:20 AM
Hi Nani,
Your getting the material Document number using this field GV_MATERIAL_DOCUMENT right. Just pass the field value to
MATERIAL_DOC like.
CLEAR: GV_MATERIAL_DOCUMENT.
SELECT MBLNR INTO GV_MATERIAL_DOCUMENT FROM MKPF
WHERE BUDAT EQ I_BUDAT
AND BLDAT EQ SY-DATUM.
ENDSELECT.
IF SY-SUBRC = 0.
* WA_ZWS_ERR-MBLNR = GV_MATERIAL_DOCUMENT."instead of this
MATERIAL_DOC = GV_MATERIAL_DOCUMENT."use this st. to get the material docu num
ENDIF.
Please check the sy-subrc it will return 0 or not.
Regards,
Dhina..
‎2011 Jun 15 2:55 PM
Hi Dhina,
Thanks a lot. I got the required output. I am closing this thread. Points assigned.
Thanks Again.