ERPClimb logoERPClimb
BAPI
ABAP Developmentbeginner 11 min read

BAPI Part 2: Calling a BAPI — Inputs, X Structures, RETURN and Commit

Preview · a free account unlocks the full lesson

Key takeaway

Call BAPI SALESORDER CREATEFROMDAT2 step by step: fill header, item, partner and schedule structures, set the corresponding X (change flag) structures, use internal formats, evaluate RETURN, then commit with wait or roll back.

In this lessonShow sections

Visual overview

BAPI Part 2: Calling a BAPI — Inputs, X Structures, RETURN and Commit — learning sheetFlow: Run the code example in a test system with valid customer/material data → Remove the X flag for PURCH_NO_C and see that the PO number is missing → Enter an invalid material and read the RETURN messages. Key ideas: THE PARAMETERS (BAPI_SALESORDER_CREATEFROMDAT2); X STRUCTURES; INTERNAL FORMATS; AFTER THE CALL. Watch out: Forgetting an X flag means the BAPI ignores the value — no error, just missing data.ERPClimb.com / ABAP / LESSON 2/10 / LEARNING SHEETBAPI Part 2: Calling a BAPI — Inputs, X Structures, RETURNand Commit1 · HOW IT FLOWS1Run the code example in atest system with validcustomer/material data2Remove the X flag forPURCH_NO_C and see thatthe PO number is missing3Enter an invalid materialand read the RETURNmessages2 · KEY IDEAS EXPLAINEDThe Parameters…ORDER_HEADER_IN (BAPISDHD1): DOC_TYPE, SALES_ORG,DISTR_CHAN, DIVISION, PURCH_NO_C …ORDER_HEADER_INX (BAPISDHD1X): same fields asflags, plus UPDATEFLAG = 'I'.X StructuresThey tell the BAPI which fields you are passing(especially important in change BAPIs, whereinitial means "don't change"). Rule…Internal FormatsCONVERSION_EXIT_ALPHA_INPUT forKUNNR/MATNR/VBELN-like fields when input comeswithout zeros.Units: internal code (e.g. 'ST'),CONVERSION_EXIT_CUNIT_INPUT for external input.After The CallRETURN type E/A → error → rollback.Only S/W/I → commit with WAIT = 'X' and check itsRETURN.3 · REMEMBER · WATCH OUTRememberFill the data structures (…_IN) and, where the BAPI has them, thematching X structures (…_INX) with 'X' for every field you supply.Use SAP internal formats: leading zeros for customer/material numbers(ALPHA conversion), internal unit codes, dates as YYYYMMDD.After the call: check RETURN for types E and A; thenBAPI_TRANSACTION_COMMIT (WAIT = 'X') or BAPI_TRANSACTION_ROLLBACK.!Watch outForgetting an X flag means the BAPIignores the value — no error, justmissing data.4 · IN A REAL PROJECTAn e-commerce integration created orders successfully, but customer PO numbers were missing on all of them.The mapping filled PURCH_NO_C but not the X flag in ORDER_HEADER_INX, so the BAPI ignored the value withoutany message. The team added a mapping unit test comparing each filled field with its X flag, and a…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Part 1 explained what BAPIs are in general. Now we call one of the most heavily used ones in practice: creating a sales order with BAPI_SALESORDER_CREATEFROMDAT2.

Its parameters break down by area. ORDER_HEADER_IN, of type BAPISDHD1, carries fields like DOC_TYPE, SALES_ORG, DISTR_CHAN, DIVISION and PURCH_NO_C. ORDER_HEADER_INX, of type BAPISDHD1X, mirrors those same fields as flags and also carries UPDATEFLAG = 'I'. ORDER_ITEMS_IN and ORDER_ITEMS_INX carry ITM_NUMBER, MATERIAL and TARGET_QTY, among others. ORDER_PARTNERS carries PARTN_ROLE — 'AG' for sold-to, 'WE' for ship-to — together with PARTN_NUMB. ORDER_SCHEDULES_IN and _INX carry ITM_NUMBER, SCHED_LINE and REQ_QTY. RETURN carries the resulting messages, and SALESDOCUMENT returns the new document number.

The X structures exist to tell the BAPI exactly which fields you are actually passing — this matters especially in change BAPIs, where a field left initial means "don't change this," rather than "set this to blank." The rule is simple: every field you fill gets a corresponding 'X' in the X structure, and key fields such as ITM_NUMBER are repeated there as well.

Fill the data structures (…_IN) and, where the BAPI has them, the matching X structures (…_INX) with 'X' for every field you supply. Forgetting an X flag means the BAPI ignores the value — no error is raised, the data is just silently missing from the result.

Free account

Create a free account to keep reading

You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.

  • Full explanation
  • Code example
  • Real project scenario
  • Common mistakes
  • Best practices
  • Interview angle

One tap with Google works too. Every topic keeps its first lesson open to everyone.

Keep exploring

Referenced SAP objects

Reviewed reference pages for the objects this page mentions.

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.