%3CLINGO-SUB%20id%3D%22lingo-sub-1786613%22%20slang%3D%22en-US%22%3EDebatching%20SAP%20BAPI%20Transaction%20Requests%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1786613%22%20slang%3D%22en-US%22%3E%3CH3%20id%3D%22toc-hId-1261641078%22%20id%3D%22toc-hId-1261641078%22%3E%3CFONT%20color%3D%22%230000FF%22%3E%3CSTRONG%3E%3CFONT%20size%3D%224%22%3EIntroduction%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3EThis%20article%20is%20the%20second%20installment%20of%20a%20series%20on%20the%20scenario%20used%20in%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fbiztalk-server-team-blog%2Fbg-p%2FBizTalkServerTeamBlog%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3ESAP%20BAPI%20Transactions%20Walkthrough%3C%2FA%3E%2C%20which%20should%20be%20read%20before%20this%20blog%20post.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3EHere%2C%20instead%20of%20receiving%20a%20pre-determined%20number%20of%20BAPI%20transaction%20requests%20one%20at%20a%20time%2C%20the%20orchestration%20expects%20a%20single%20document%20containing%20a%20batch%20of%20requests%2C%20as%20well%20as%20the%20desired%20outcome%20(commit%20or%20rollback).%20Debatching%20of%20XML%20messages%20into%20single%20BAPI%20transaction%20requests%20is%20done%20inside%20the%20orchestration%20by%20calling%20the%20default%20XMLReceive%20pipeline.%20General%20documentation%20regarding%20this%20orchestration%20feature%20may%20be%20found%20at%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fbiztalk%2Fcore%2Fhow-to-use-expressions-to-execute-pipelines%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EHow%20to%20Use%20Expressions%20to%20Execute%20Pipelines%3C%2FA%3E.%26nbsp%3B%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3EThe%20choice%20of%20in-orchestration%20pipeline%20processing%20over%20direct%20processing%20in%20the%20receive%20port%20is%20mostly%20arbitrary.%20It%20allows%20us%20to%20keep%20this%20presentation%20focused%20on%20a%20single%20place%20where%20the%20different%20stages%20are%20integrated.%20The%20orchestration%20is%20well-suited%20for%20a%20workflow%20of%20multiple%20actions%20and%20custom%20error%20handling.%20There%20are%20pros%20and%20cons%20mentioned%20in%20the%20literature%20regarding%20both%20options%20and%20it%20would%20take%20another%20post%20to%20cover%20them%20in%20detail.%20%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3EIt%20is%20worth%20mentioning%20that%20w%3C%2FFONT%3E%3CFONT%20size%3D%224%22%3Eith%20in-orchestration%20pipelines%3A%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E-%20Transforms%20can%20happen%20before%20debatching%2C%20which%20in%20some%20cases%20could%20be%20a%20hard%20requirement%3B%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E-%20It%20is%20possible%20to%20enumerate%20over%20messages%20of%20different%20types%3B%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E-%20Failures%20result%20in%20exceptions%20being%20thrown%20rather%20than%20messages%20being%20suspended%20by%20the%20pipeline%20(see%20for%20instance%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fbiztalk%2Fcore%2Ferror-handling%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EError%20Handling%3C%2FA%3E%20for%20failure%20behavior%20in%20the%20pipeline%20stage).%20The%20thrown%20exceptions%20can%20be%20handled%20in%20a%20catch%20block%20within%20the%20calling%20orchestration%2C%20which%20could%20allow%20for%20graceful%20error%20handling%20with%20BAPI_TRANSACTION_ROLLBACK.%3C%2FFONT%3E%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--545813385%22%20id%3D%22toc-hId--545813385%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22toc-hId-1941699448%22%20id%3D%22toc-hId-1941699448%22%3E%3CSTRONG%3E%3CFONT%20size%3D%224%22%20color%3D%22%230000FF%22%3EDebatching%20with%20Receive%20Pipeline%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3EPipeline%20processing%20of%20messages%20containing%20batches%20of%20orders%20can%20summarized%20as%20%3A%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Article2PipelineMessageProcessing.PNG%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F227195iF8ADC561585E3F28%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Article2PipelineMessageProcessing.PNG%22%20alt%3D%22Article2PipelineMessageProcessing.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CFONT%20size%3D%224%22%3EEnvelope%20Schema%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3EThe%20first%20step%20for%20using%20a%20debatching%20pipeline%20is%20to%20define%20an%20envelope%20schema%20to%20represent%20multiple%20orders.%20This%20is%20done%20according%20to%20the%20following%20process%2C%20initially%20documented%20in%20%3CA%20href%3D%22https%3A%2F%2Fsocial.technet.microsoft.com%2Fwiki%2Fcontents%2Farticles%2F31367.biztalk-de-batching-options.aspx%23Calling_a_pipeline_inside_an_orchestration%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3ECalling%20a%20pipeline%20inside%20an%20orchestration%3C%2FA%3E.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CFONT%20size%3D%224%22%3EAdd%20a%20new%20schema%20file%20to%20the%20project.%3C%2FFONT%3E%3C%2FLI%3E%0A%3CLI%3E%3CFONT%20size%3D%224%22%3EChange%20the%20root%20node%20name%20to%20%22Orders%22.%3C%2FFONT%3E%3C%2FLI%3E%0A%3CLI%3E%3CFONT%20size%3D%224%22%3EIn%20the%20properties%20window%20for%20the%20%3CSCHEMA%3E%20treeview%20node%3A%20(a)%20change%20the%20Envelope%20property%20to%20Yes%2C%20and%20(b)%20import%20the%20Order%20schema.%3C%2FSCHEMA%3E%3C%2FFONT%3E%3C%2FLI%3E%0A%3CLI%3E%3CFONT%20size%3D%224%22%3EIn%20the%20properties%20window%20for%20the%20%22Orders%22%20root%20node%2C%20set%20the%20Body%20XPath%20property%20to%20%2F*%5Blocal-name()%3D'Orders'%20and%20namespace-uri()%3D'%3CNAMESPACE%20of%3D%22%22%20the%3D%22%22%20schema%3D%22%22%20here%3D%22%22%3E%3C%2FNAMESPACE%3E%3C%2FFONT%3E%3C%2FLI%3E%0A%3CLI%3E%3CFONT%20size%3D%224%22%3EInsert%20a%20child%20record%20under%20the%20root%20node.%3C%2FFONT%3E%3C%2FLI%3E%0A%3CLI%3E%3CFONT%20size%3D%224%22%3EIn%20the%20child%20record%20properties%2C%20set%20the%20data%20structure%20type%20field%20to%20Order.%20As%20a%20result%2C%20the%20Order%20definition%20will%20appear%20under%20Orders.%3C%2FFONT%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%20style%3D%22margin%3A%200in%3B%20font-family%3A%20Calibri%3B%20font-size%3A%2011.0pt%3B%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22CreateEnvelopeSchemaREDUX.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F227081i9020C1678C77679E%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22CreateEnvelopeSchemaREDUX.png%22%20alt%3D%22CreateEnvelopeSchemaREDUX.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3EMessages%20initially%20received%20by%20the%20orchestration%20contain%20BAPI%20transaction%20requests%2C%20which%20contain%20an%20IsCommit%20field%20in%20addition%20to%20the%20envelope%20schema.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Emmanuel_Abram-Profeta_0-1603731225412.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F229299i2C240D08AD52410D%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Emmanuel_Abram-Profeta_0-1603731225412.png%22%20alt%3D%22Emmanuel_Abram-Profeta_0-1603731225412.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E%3CEM%3EIsCommit%20%3C%2FEM%3Eis%20a%20promoted%20property%20which%20is%20used%20later%20on%20for%20deciding%20whether%20to%20commit%20or%20rollback%20the%20transaction%20batch.%20Orders%20corresponds%20to%20the%20envelope%20schema%20imported%20into%20%3CEM%3ERequestsInfo%3C%2FEM%3E.%20The%20Orders%20element%20is%20extracted%20by%20a%20transform%20shape%20into%20a%20message%20called%20%3CEM%3ESalesOrders%3C%2FEM%3E.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E%3CSTRONG%3ENote%3C%2FSTRONG%3E%3A%20the%20%3CEM%3ERequestsInfo%20%3C%2FEM%3Eschema%20could%20also%20be%20an%20envelope%20schema%20for%20Order%2C%20instead%20of%20the%20Orders%20schema.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CFONT%20size%3D%224%22%3EImplementing%20the%20Pipeline%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3EBefore%20using%20the%20pipeline%2C%20the%20following%20dependencies%20must%20be%20added%20to%20the%20BizTalk%20project%3A%3C%2FFONT%3E%3C%2FP%3E%0A%3CUL%20type%3D%22disc%22%3E%0A%3CLI%3E%3CFONT%20size%3D%224%22%3EMicrosoft.XLANGs.Pipeline.dll%3C%2FFONT%3E%3C%2FLI%3E%0A%3CLI%3E%3CFONT%20size%3D%224%22%3EMicrosoft.BizTalk.Pipeline.dll%3C%2FFONT%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3EThe%20pipeline%20must%20be%20inside%20a%20scope%20of%20type%20Atomic%20because%20it%20is%20of%20non-serializable%20type.%20As%20a%20result%2C%20the%20orchestration%20has%20to%20be%20of%20type%20%22Long%20running%22.%20Inside%20the%20atomic%20scope%2C%20the%20first%20expression%20starts%20the%20pipeline%20execution%3A%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3EPipelineOutputMessageVar%20%3D%20Microsoft.XLANGs.Pipeline.XLANGPipelineManager.ExecuteReceivePipeline(typeof(Microsoft.BizTalk.DefaultPipelines.XMLReceive)%2C%20SalesOrders)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3Ewhere%20%3CEM%3EPipelineOutputMessageVar%20%3C%2FEM%3Eis%20a%20variable%20of%20type%20Microsoft.XLANGs.Pipeline.ReceivePipelineOutputMessages%20and%20is%20used%20to%20iterate%20in%20a%20loop%20shape%20with%20the%20expression%3A%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3EPipelineOutputMessageVar.MoveNext()%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3EInside%20the%20loop%20shape%2C%20a%20message%20of%20type%20%3CEM%3EOrder%3C%2FEM%3E%2C%20%3CEM%3ECurrentOrder%3C%2FEM%3E%2C%20is%20assigned%20as%20follows%3A%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3ECurrentOrder%20%3D%20null%3B%0APipelineOutputMessageVar.GetCurrent(CurrentOrder)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E%3CEM%3ECurrentOrder%20%3C%2FEM%3Eis%20then%20mapped%20to%20a%20message%20(%3CEM%3EBAPIMessage%3C%2FEM%3E)%20of%20type%20BUS2032.CREATEFROMDAT2.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3EThe%20figure%20below%20shows%20the%20entire%20pipeline%20stage%3A%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%20style%3D%22margin%3A%200in%3B%20font-family%3A%20Calibri%3B%20font-size%3A%2011.0pt%3B%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22AnnotatedPipelineREDUX.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F227082i666D5A1CA02D3B5A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22AnnotatedPipelineREDUX.png%22%20alt%3D%22AnnotatedPipelineREDUX.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-134244985%22%20id%3D%22toc-hId-134244985%22%3E%3CFONT%20color%3D%22%230000FF%22%3E%3CSTRONG%3ECaching%20BAPIMessages%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3EIdeally%2C%20the%20%3CEM%3EBAPIMessages%20%3C%2FEM%3Eshould%20be%20sent%20to%20the%20SAP%20server%20from%20within%20the%20pipeline%2C%20by%20using%20the%20%3CEM%3Esend-receive%3C%2FEM%3E%20port%20connected%20to%20SAP.%20However%2C%20an%20atomic%20scope%20may%20not%20contain%20both%20the%20send%20and%20the%20corresponding%20receive%20(see%20a%20detailed%20explanation%20%3CA%20href%3D%22https%3A%2F%2Fsocial.msdn.microsoft.com%2FForums%2Fen-US%2Fa63fc9ed-3391-404b-a55b-42946bcda170%2Fan-atomic-scope-may-not-contain-or-call-a-service-or-scope-that-contains-both-the-send-and-the%3Fforum%3Dbiztalkgeneral%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E)%3B%20in%20our%20case%2C%20the%20SAP%20adapter%20port%20needs%20to%20be%20bidirectional%20because%20the%20orchestration%20needs%20the%20document%20id%20contained%20in%20the%20response%20and%20which%20is%20used%20later%20on%20to%20query%20the%20transactions%20status.%20Note%20that%20this%20is%20specific%20to%20our%20scenario%20because%20we%20need%20a%20bi-directional%20port%20rather%20than%20just%20sending%20BAPI%20transactions%2C%20which%20could%20be%20a%20perfectly%20valid%20and%20simpler%20scenario.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3ETo%20work%20around%20the%20scope%20constraint%2C%20%3CEM%3EBAPIMessages%20%3C%2FEM%3Eare%20saved%20in%20a%20list%20object%20to%20be%20used%20outside%20the%20pipeline%20scope%3A%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3ETempXmlData%20%3D%20BAPIMessage%3B%0ABAPIOrders.AddFromXMLString(TempXmlData)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3Ewhere%20%3CEM%3ETempXmlData%20%3C%2FEM%3Eis%20a%20variable%20of%20type%20%3CEM%3EXmlDocument%3C%2FEM%3E%2C%20and%20%3CEM%3EBAPIOrders%20%3C%2FEM%3Eis%20of%20custom%20type%20%3CEM%3EBAPIOrderList%20%3C%2FEM%3Eadded%20in%20a%20helper%20library.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3Enamespace%20SapBAPITxClientDebatching%0A%7B%0A%20%20%20%20%5BSerializable%5D%0A%20%20%20%20public%20class%20BAPIOrdersList%20%3A%20List%3CCREATEFROMDAT2%3E%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20public%20BAPIOrdersList()%20%7B%20%7D%0A%0A%20%20%20%20%20%20%20%20public%20void%20AddFromXMLString(XmlDocument%20document)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20MemoryStream%20stream%20%3D%20new%20MemoryStream()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20document.Save(stream)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20stream.Flush()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20stream.Position%20%3D%200%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20XmlSerializer%20reader%20%3D%20new%20System.Xml.Serialization.XmlSerializer(typeof(CREATEFROMDAT2))%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20StreamReader%20st%20%3D%20new%20StreamReader(stream)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20this.Add((CREATEFROMDAT2)reader.Deserialize(st))%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20st.Close()%3B%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20public%20CREATEFROMDAT2%20Get(int%20index)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20this%5Bindex%5D%3B%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20public%20int%20OrdersCount()%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20this.Count%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D%3C%2FCREATEFROMDAT2%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3EThe%20helper%20library%20also%20contains%20C%23%20classes%20corresponding%20to%20the%20BAPI%20transactions%20schemas%20generated%20by%20running%20the%20xsd.exe%20utility%20on%20the%20BAPI%20schemas%20generated%20in%20Visual%20Studio.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--1673209478%22%20id%3D%22toc-hId--1673209478%22%3E%3CFONT%20color%3D%22%230000FF%22%3E%3CSTRONG%3E%3CFONT%20size%3D%224%22%3EProcessing%20the%20debatched%20BAPI%20Transactions%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3EOnce%20all%20%3CEM%3EOrder%20%3C%2FEM%3Eelements%20have%20been%20debatched%2C%20the%20orchestration%20exits%20the%20pipeline%20atomic%20scope%20and%20iterates%20over%20the%20list%20of%20BAPI%20transaction%20messages%20to%20serialize%20and%20send%20to%20the%20send-receive%20port%20(%3CEM%3ELOBPort%3C%2FEM%3E)%20connected%20to%20the%20SAP%20server.%20This%20stage%20is%20identical%20to%20Stage%202%20in%20%3CA%20href%3D%22onenote%3A%23SAP%2520BAPI%2520Transactions%2520Tutorial%26amp%3Bsection-id%3D%7B1A38D629-68E4-4460-8618-62BFA6199F5D%7D%26amp%3Bpage-id%3D%7B7CE139D2-AB44-4168-95F1-E2FFB0546857%7D%26amp%3Bend%26amp%3Bbase-path%3Dhttps%3A%2F%2Fmicrosoft.sharepoint.com%2Fteams%2FBizTalk_Server%2FShared%2520Documents%2FBizTalk2016%2FProjectExecution%2FBlog%2520Articles.one%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3ESAP%20BAPI%20Transactions%20Tutorial%3C%2FA%3E%20except%20that%20here%2C%20BAPI%20transaction%20requests%20are%20provided%20by%20the%20orchestration%20variable%20%3CEM%3EBAPIOrders%3C%2FEM%3E.%20%3CBR%20%2F%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DebatchingStage2AnnotatedREDUX.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F227083i66B5E7D1A7DF7F2E%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22DebatchingStage2AnnotatedREDUX.png%22%20alt%3D%22DebatchingStage2AnnotatedREDUX.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-814303355%22%20id%3D%22toc-hId-814303355%22%3E%3CSTRONG%3E%3CFONT%20size%3D%224%22%20color%3D%22%230000FF%22%3EThe%20Global%20Picture%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3ESubsequent%20stages%20of%20the%20orchestration%20are%20presented%20in%20detail%20in%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fbiztalk-server-team-blog%2Fbg-p%2FBizTalkServerTeamBlog%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3ESAP%20BAPI%20Transactions%20Tutorial%3C%2FA%3E.%20In%20Stage%203%2C%20the%20action%20to%20take%20(Commit%2FRollback)%20is%20determined%20by%20the%20%3CEM%3EIsCommit%3C%2FEM%3E%20promoted%20property%20mentioned%20earlier.%20%3CBR%20%2F%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%20style%3D%22margin%3A%200in%3B%20font-family%3A%20Calibri%3B%20font-size%3A%2011.0pt%3B%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DebatchingOrchestrationREDUXS1.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F227084i73889126F42549CD%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22DebatchingOrchestrationREDUXS1.png%22%20alt%3D%22DebatchingOrchestrationREDUXS1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DebatchingOrchestrationREDUXS2.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F227086iAD6145F7424471A3%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22DebatchingOrchestrationREDUXS2.png%22%20alt%3D%22DebatchingOrchestrationREDUXS2.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DebatchingOrchestrationREDUXS3.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F227087i0362BAA0FD71585A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22DebatchingOrchestrationREDUXS3.png%22%20alt%3D%22DebatchingOrchestrationREDUXS3.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DebatchingOrchestrationREDUXS4.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F227089iDBA78E2F179700C2%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22DebatchingOrchestrationREDUXS4.png%22%20alt%3D%22DebatchingOrchestrationREDUXS4.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--993151108%22%20id%3D%22toc-hId--993151108%22%3E%3CFONT%20color%3D%22%230000FF%22%3E%3CSTRONG%3E%3CFONT%20size%3D%224%22%3EConcluding%20Remarks%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3EThe%20aim%20of%20this%20post%20was%20to%20extend%20the%20BAPI%20tutorial%20scenario%20by%20showing%20BAPI%20transactions%20working%20with%20known%20BizTalk%20patterns%20such%20as%20debatching.%20Another%20pattern%20to%20consider%20is%20Scatter-Gather%2C%20of%20which%20debatching%20is%20the%20first%20step.%20This%20will%20be%20the%20topic%20of%20another%20blog%20post.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3EAll%20code%20used%20in%20this%20article%20is%20attached.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-1494361725%22%20id%3D%22toc-hId-1494361725%22%3E%3CFONT%20color%3D%22%230000FF%22%3E%3CSTRONG%3E%3CFONT%20size%3D%224%22%3EReferences%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fbiztalk-server-team-blog%2Fsap-bapi-transactions-walkthrough%2Fba-p%2F1772148%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3ESAP%20BAPI%20Transactions%20Walkthrough%3C%2FA%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E%3CA%20href%3D%22https%3A%2F%2Fsocial.technet.microsoft.com%2Fwiki%2Fcontents%2Farticles%2F31367.biztalk-de-batching-options.aspx%23Calling_a_pipeline_inside_an_orchestration%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3ECalling%20a%20pipeline%20inside%20an%20orchestration%3C%2FA%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E%3CA%20href%3D%22https%3A%2F%2Fsocial.technet.microsoft.com%2FForums%2Fen-US%2Fcc7e43de-9fab-4cee-9103-06bcf3a2ebf1%2Fdebatching-in-orchestration-using-receive-pipeline-in-biztalk%3Fforum%3Dbiztalkgeneral%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EDebatching%20in%20orchestration%3C%2FA%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E%3CA%20href%3D%22https%3A%2F%2Fwww.connected-pawns.com%2F2010%2F10%2F12%2Fde-batching-within-an-orchestration-using-xpath-or-calling-a-pipeline%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EPerformance%20study%20of%20debatching%20within%20an%20orchestration%3C%2FA%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E%3CA%20href%3D%22https%3A%2F%2Fsocial.msdn.microsoft.com%2FForums%2FLync%2Fen-US%2F243e728f-619a-40be-adeb-7af39b846f56%2Fdifferent-techniques-of-debatching-in-orchestration%3Fforum%3Dbiztalkgeneral%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EDifferent%20techniques%20of%20debatching%20in%20orchestration%3C%2FA%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fbiztalk%2Fcore%2Fhow-to-use-expressions-to-execute-pipelines%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EHow%20to%20Use%20Expressions%20to%20Execute%20Pipelines%3C%2FA%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fbiztalk%2Fcore%2Ferror-handling%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EError%20Handling%20in%20Pipelines%3C%2FA%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3EFor%20more%20general%20info%20on%20the%20SAP%20Adapter%3A%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fbiztalk%2Fadapters-and-accelerators%2Fadapter-sap%2Foperations-on-bapis-in-sap%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EOperations%20on%20BAPIs%20in%20SAP%3C%2FA%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fbiztalk%2Fadapters-and-accelerators%2Fadapter-sap%2Frun-bapi-transactions-in-sap-using-biztalk-server%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3ERun%20BAPI%20Transactions%20in%20SAP%20using%20BizTalk%20Server%3C%2FA%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fbiztalk%2Fadapters-and-accelerators%2Fadapter-sap%2Fmessage-schemas-for-bapi-operations%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EMessage%20Schemas%20for%20BAPI%20Operations%3C%2FA%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fbiztalk%2Fadapters-and-accelerators%2Fadapter-sap%2Fbrowse-search-and-get-metadata-for-bapi-operations-in-sap%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3ESAP%20Adapter%20documentation%3C%2FA%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E%3CA%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Fhelp%2F4491648%2Ffix-bapi-transactions-are-not-committed-when-you-use-wcf-sap-nco-conne%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3ERegistry%20setting%20to%20enable%20BAPI%20transactions%3C%2FA%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fbiztalk%2Fadapters-and-accelerators%2Fadapter-sap%2Fget-metadata-for-sap-operations-in-visual-studio%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EGet%20Metadata%20for%20SAP%20Operations%20in%20Visual%20Studio%3C%2FA%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fbiztalk%2Fadapters-and-accelerators%2Fadapter-sap%2Fbrowse-search-and-get-metadata-for-bapi-operations-in-sap%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EBrowse%2C%20search%2C%20and%20retrieve%20metadata%20from%20SAP%20for%20BAPI%20operations%3C%2FA%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%20style%3D%22margin%3A%200in%3B%20font-family%3A%20Calibri%3B%20font-size%3A%2011.0pt%3B%22%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1786613%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20continue%20from%20where%20%3CA%20href%3D%22onenote%3A%23SAP%2520BAPI%2520Transactions%2520Tutorial%26amp%3Bsection-id%3D%7B1A38D629-68E4-4460-8618-62BFA6199F5D%7D%26amp%3Bpage-id%3D%7B7CE139D2-AB44-4168-95F1-E2FFB0546857%7D%26amp%3Bend%26amp%3Bbase-path%3Dhttps%3A%2F%2Fmicrosoft.sharepoint.com%2Fteams%2FBizTalk_Server%2FShared%2520Documents%2FBizTalk2016%2FProjectExecution%2FBlog%2520Articles.one%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3ESAP%20BAPI%20Transactions%20Walkthrough%3C%2FA%3E%20left%20off%20by%20presenting%2C%20step-by-step%2C%20batch%20processing%20of%20BAPI%20transaction%20requests%20with%20a%20receive%20pipeline%20called%20from%20the%20orchestration.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1786613%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EBizTalk%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E

Introduction

 

This article is the second installment of a series on the scenario used in SAP BAPI Transactions Walkthrough, which should be read before this blog post.

 

Here, instead of receiving a pre-determined number of BAPI transaction requests one at a time, the orchestration expects a single document containing a batch of requests, as well as the desired outcome (commit or rollback). Debatching of XML messages into single BAPI transaction requests is done inside the orchestration by calling the default XMLReceive pipeline. General documentation regarding this orchestration feature may be found at How to Use Expressions to Execute Pipelines

 

The choice of in-orchestration pipeline processing over direct processing in the receive port is mostly arbitrary. It allows us to keep this presentation focused on a single place where the different stages are integrated. The orchestration is well-suited for a workflow of multiple actions and custom error handling. There are pros and cons mentioned in the literature regarding both options and it would take another post to cover them in detail.

It is worth mentioning that with in-orchestration pipelines:

- Transforms can happen before debatching, which in some cases could be a hard requirement;

- It is possible to enumerate over messages of different types;

- Failures result in exceptions being thrown rather than messages being suspended by the pipeline (see for instance Error Handling for failure behavior in the pipeline stage). The thrown exceptions can be handled in a catch block within the calling orchestration, which could allow for graceful error handling with BAPI_TRANSACTION_ROLLBACK.

 

Debatching with Receive Pipeline

 

Pipeline processing of messages containing batches of orders can summarized as :

 

Article2PipelineMessageProcessing.PNG

 

Envelope Schema

 

The first step for using a debatching pipeline is to define an envelope schema to represent multiple orders. This is done according to the following process, initially documented in Calling a pipeline inside an orchestration.

 

  1. Add a new schema file to the project.
  2. Change the root node name to "Orders".
  3. In the properties window for the <schema> treeview node: (a) change the Envelope property to Yes, and (b) import the Order schema.
  4. In the properties window for the "Orders" root node, set the Body XPath property to /*[local-name()='Orders' and namespace-uri()='<namespace of the schema here'
  5. Insert a child record under the root node.
  6. In the child record properties, set the data structure type field to Order. As a result, the Order definition will appear under Orders.

 

CreateEnvelopeSchemaREDUX.png

 

Messages initially received by the orchestration contain BAPI transaction requests, which contain an IsCommit field in addition to the envelope schema.

 

Emmanuel_Abram-Profeta_0-1603731225412.png

 

IsCommit is a promoted property which is used later on for deciding whether to commit or rollback the transaction batch. Orders corresponds to the envelope schema imported into RequestsInfo. The Orders element is extracted by a transform shape into a message called SalesOrders.

Note: the RequestsInfo schema could also be an envelope schema for Order, instead of the Orders schema.

 

Implementing the Pipeline

 

Before using the pipeline, the following dependencies must be added to the BizTalk project:

  • Microsoft.XLANGs.Pipeline.dll
  • Microsoft.BizTalk.Pipeline.dll

The pipeline must be inside a scope of type Atomic because it is of non-serializable type. As a result, the orchestration has to be of type "Long running". Inside the atomic scope, the first expression starts the pipeline execution:

 

PipelineOutputMessageVar = Microsoft.XLANGs.Pipeline.XLANGPipelineManager.ExecuteReceivePipeline(typeof(Microsoft.BizTalk.DefaultPipelines.XMLReceive), SalesOrders);

 

where PipelineOutputMessageVar is a variable of type Microsoft.XLANGs.Pipeline.ReceivePipelineOutputMessages and is used to iterate in a loop shape with the expression:

 

PipelineOutputMessageVar.MoveNext()

 

Inside the loop shape, a message of type Order, CurrentOrder, is assigned as follows:

 

CurrentOrder = null;
PipelineOutputMessageVar.GetCurrent(CurrentOrder);

 

CurrentOrder is then mapped to a message (BAPIMessage) of type BUS2032.CREATEFROMDAT2.

 

The figure below shows the entire pipeline stage:

 

AnnotatedPipelineREDUX.png

 

Caching BAPIMessages

 

Ideally, the BAPIMessages should be sent to the SAP server from within the pipeline, by using the send-receive port connected to SAP. However, an atomic scope may not contain both the send and the corresponding receive (see a detailed explanation here); in our case, the SAP adapter port needs to be bidirectional because the orchestration needs the document id contained in the response and which is used later on to query the transactions status. Note that this is specific to our scenario because we need a bi-directional port rather than just sending BAPI transactions, which could be a perfectly valid and simpler scenario.

 

To work around the scope constraint, BAPIMessages are saved in a list object to be used outside the pipeline scope:

 

TempXmlData = BAPIMessage;
BAPIOrders.AddFromXMLString(TempXmlData);

 

where TempXmlData is a variable of type XmlDocument, and BAPIOrders is of custom type BAPIOrderList added in a helper library.

 

namespace SapBAPITxClientDebatching
{
    [Serializable]
    public class BAPIOrdersList : List<CREATEFROMDAT2>
    {
        public BAPIOrdersList() { }

        public void AddFromXMLString(XmlDocument document)
        {
            MemoryStream stream = new MemoryStream();
            document.Save(stream);
            stream.Flush();
            stream.Position = 0;

            XmlSerializer reader = new System.Xml.Serialization.XmlSerializer(typeof(CREATEFROMDAT2));
            StreamReader st = new StreamReader(stream);
            this.Add((CREATEFROMDAT2)reader.Deserialize(st));
            st.Close();
        }

        public CREATEFROMDAT2 Get(int index)
        {
            return this[index];
        }

        public int OrdersCount()
        {
            return this.Count;
        }
    }
}

 

The helper library also contains C# classes corresponding to the BAPI transactions schemas generated by running the xsd.exe utility on the BAPI schemas generated in Visual Studio.

 

Processing the debatched BAPI Transactions

 

Once all Order elements have been debatched, the orchestration exits the pipeline atomic scope and iterates over the list of BAPI transaction messages to serialize and send to the send-receive port (LOBPort) connected to the SAP server. This stage is identical to Stage 2 in SAP BAPI Transactions Tutorial except that here, BAPI transaction requests are provided by the orchestration variable BAPIOrders.

 

DebatchingStage2AnnotatedREDUX.png

 

The Global Picture

 

Subsequent stages of the orchestration are presented in detail in SAP BAPI Transactions Tutorial. In Stage 3, the action to take (Commit/Rollback) is determined by the IsCommit promoted property mentioned earlier.

 

DebatchingOrchestrationREDUXS1.png

DebatchingOrchestrationREDUXS2.png

DebatchingOrchestrationREDUXS3.png

DebatchingOrchestrationREDUXS4.png

 

Concluding Remarks

 

The aim of this post was to extend the BAPI tutorial scenario by showing BAPI transactions working with known BizTalk patterns such as debatching. Another pattern to consider is Scatter-Gather, of which debatching is the first step. This will be the topic of another blog post.

 

All code used in this article is attached.

 

References

 

SAP BAPI Transactions Walkthrough

Calling a pipeline inside an orchestration

Debatching in orchestration

Performance study of debatching within an orchestration

Different techniques of debatching in orchestration

How to Use Expressions to Execute Pipelines

Error Handling in Pipelines

 

For more general info on the SAP Adapter:

Operations on BAPIs in SAP

Run BAPI Transactions in SAP using BizTalk Server

Message Schemas for BAPI Operations

SAP Adapter documentation

Registry setting to enable BAPI transactions

Get Metadata for SAP Operations in Visual Studio

Browse, search, and retrieve metadata from SAP for BAPI operations