Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

BAPI_SALESORDER_CREATEFROMDAT2 and Commit-Issue

Hi,

I've a problem with BAPI_TRANSACTION_COMMIT after BAPI_SALESORDER_CREATEFROMDAT2.

BAPI_SALESORDER_CREATEFROMDAT2 is working fine.

In the Return-Vars I've a message "Salesorder create Number 9999999'.

The Salesordernumbers are reserved in the system.

But the BAPI_TRANSACTION_COMMIT gives no result back and the Salesorder is not created.

I've read somewhere that the two BAPIs have to be called in one Process, but I don't know how to do this.

Many many thanks in advance for helping.

CODE:

Dim _ecc = RfcDestinationManager.GetDestination(strSAPSystem)

Dim setOrderAPI As IRfcFunction = _ecc.Repository.CreateFunction("BAPI_SALESORDER_CREATEFROMDAT2")

Dim setCommit As IRfcFunction = _ecc.Repository.CreateFunction("BAPI_TRANSACTION_COMMIT")


Dim SAPStrucOrder_Header_In As SAP.Middleware.Connector.IRfcStructure = setOrderAPI.GetStructure("ORDER_HEADER_IN")


SAPStrucOrder_Header_In.SetValue("DOC_TYPE", "ZEDI")

SAPStrucOrder_Header_In.SetValue("SALES_ORG", "0100")

SAPStrucOrder_Header_In.SetValue("DISTR_CHAN", "10")

SAPStrucOrder_Header_In.SetValue("DIVISION", "10")

Dim datLieferdatum As Date

datLieferdatum = strLieferdatum

SAPStrucOrder_Header_In.SetValue("REQ_DATE_H", datLieferdatum)


Dim SAPTableOrder_Partners As SAP.Middleware.Connector.IRfcTable = setOrderAPI.GetTable("ORDER_PARTNERS")

SAPTableOrder_Partners.Append()

SAPTableOrder_Partners.SetValue("PARTN_ROLE", "AG")

SAPTableOrder_Partners.SetValue("PARTN_NUMB", gstrSAPKDNR)

SAPTableOrder_Partners.Append()

SAPTableOrder_Partners.SetValue("PARTN_ROLE", "WE")

SAPTableOrder_Partners.SetValue("PARTN_NUMB", strSAPKunnrWE)


Dim SAPTableOrder_Items_In As SAP.Middleware.Connector.IRfcTable = setOrderAPI.GetTable("ORDER_ITEMS_IN")

Dim SAPTableOrder_Schedule_In As SAP.Middleware.Connector.IRfcTable = setOrderAPI.GetTable("ORDER_SCHEDULES_IN")


lngTmpPosNr = 0

For z4 As Integer = 0 To PosTabelle.lngPosnr.Length - 1

            lngTmpPosNr = PosTabelle.lngPosnr(z4) * 10

            SAPTableOrder_Items_In.Append()

            SAPTableOrder_Items_In.SetValue("ITM_NUMBER", lngTmpPosNr)

            SAPTableOrder_Items_In.SetValue("MATERIAL", PosTabelle.strSAPArtNr(z4))

            SAPTableOrder_Schedule_In.Append()

            SAPTableOrder_Schedule_In.SetValue("ITM_NUMBER", lngTmpPosNr)

            SAPTableOrder_Schedule_In.SetValue("REQ_QTY", PosTabelle.lngMenge(z4))

            SAPTableOrder_Schedule_In.SetValue("REQ_DATE", datLieferdatum)

Next


setOrderAPI.Invoke(_ecc)
setCommit.Invoke(_ecc)


Dim strVBELN As String

Dim strReturnType As String

Dim strReturnID As String

Dim strReturnNumber As String

Dim strReturnMessage As String

Dim strReturnType2 As String

Dim strReturnID2 As String

Dim strReturnNumber2 As String

Dim strReturnMessage2 As String


Try

            strVBELN = setOrderAPI.GetValue("SALESDOCUMENT").ToString

            strReturnType = setOrderAPI.GetTable("RETURN").GetString("TYPE")

            strReturnID = setOrderAPI.GetTable("RETURN").GetString("ID")

            strReturnNumber = setOrderAPI.GetTable("RETURN").GetString("NUMBER")

            strReturnMessage = setOrderAPI.GetTable("RETURN").GetString("MESSAGE")

            strReturnType2 = setCommit.GetStructure("RETURN").GetString("TYPE")

            strReturnID2 = setCommit.GetStructure("RETURN").GetString("ID")

            strReturnNumber2 = setCommit.GetStructure("RETURN").GetString("NUMBER")

            strReturnMessage2 = setCommit.GetStructure("RETURN").GetString("MESSAGE")

Catch

'nix

End Try

Tags:
replied

I believe this is accomplished by using the following "wrapper" --

RfcSessionManager.BeginContext(_ecc)

setOrderAPI.Invoke(_ecc)
setCommit.Invoke(_ecc)

RfcSessionManager.EndContext(_ecc)

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question