BAPI Create
BAPI Create
com/in/mickaelquesnot/
They provide stable and standardized methods to achieve seamless integration between the SAP
System and external applications, legacy systems and add-ons.
BAPIs are defined in the BOR(Business object repository) as methods of SAP business object types that
carry out specific business functions. They are implemented as RFC-enabled function modules and are
created in the Function Builder of the ABAP Workbench.
Some BAPIs and methods provide basic functions and can be used for most SAP Business Objects.
These are called STANDARDIZED BAPI’s.
Do not forget to save it in a package. Check the structure (ctrl + F2) and activate (ctrl + F3) the
structure.
FUNCTION ZBAPI_CROSS_SELLING .
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(PV_KSCHL) TYPE ZBAPIVB41-KSCHL DEFAULT 'CS01'
*" VALUE(PV_KOTABNR) TYPE ZBAPIVB41-KOTABNR DEFAULT '011'
*" VALUE(PV_MATWA) TYPE ZBAPIVB41-MATWA DEFAULT ' '
*" VALUE(PV_SMATN) TYPE ZBAPIVB41-SMATN DEFAULT ' '
*" VALUE(PV_MEINS) TYPE ZBAPIVB41-MEINS DEFAULT ' '
*" VALUE(PV_SUGRD) TYPE ZBAPIVB41-SUGRD DEFAULT ' '
*" VALUE(PV_DATAB) TYPE ZBAPIVB41-DATAB DEFAULT SY-DATUM
*" VALUE(PV_DATBI) TYPE ZBAPIVB41-DATBI DEFAULT '99991231'
*" EXPORTING
*" VALUE(RETURN) TYPE BAPIRET2
*" TABLES
*" ZBAPIVB41 STRUCTURE ZBAPIVB41
*"----------------------------------------------------------------------
INCLUDE Z_MME_CROSS_SELLING_TOP.
XVAKE-VAKEY = PV_MATWA.
XKONDD-SMATN = PV_SMATN.
TIME_VAKE_KEY-KAPPL = 'VS'.
TIME_VAKE_KEY-KVEWE = 'D'.
TIME_VAKE_KEY-KOTABNR = PV_KOTABNR.
TIME_VAKE_KEY-KSCHL = 'CS01'. "PV_KSCHL.
TIME_VAKE_KEY-VAKEY = XVAKE-VAKEY.
IF PV_DATAB IS INITIAL.
LV_DATAB = SY-DATUM.
ELSE.
LV_DATAB = PV_DATAB.
ENDIF.
*Material
CLEAR LS_VAKEDB.
SELECT SINGLE * INTO CORRESPONDING FIELDS OF LS_VAKEDB
FROM KOTD011
WHERE KAPPL EQ TIME_VAKE_KEY-KAPPL
AND KSCHL EQ TIME_VAKE_KEY-KSCHL
AND MATNR EQ PV_MATWA
AND DATBI GE LV_DATAB
AND DATAB LE LV_DATAB.
IF SY-SUBRC = 0.
SELECT SINGLE * FROM KONDD WHERE KNUMH = NV_NEW_NUMBER AND SMATN = PV_SMATN.
IF SY-SUBRC = 0.
EXIT.
ELSE.
NV_NEW_NUMBER = LS_VAKEDB-KNUMH.
ENDIF.
ENDIF.
XKONDDP-KPOSN = 1.
XKONDDP-KNUMH = NV_NEW_NUMBER.
XKONDDP-SMATN = XKONDD-SMATN.
IF LS_VAKEDB-KNUMH IS INITIAL.
XKONDDP-UPDKZ = ' '.
XKONDDP-KPOSN = 1.
ELSE.
CLEAR LV_COUNT.
SELECT COUNT(*) INTO LV_COUNT FROM KONDD WHERE KNUMH = NV_NEW_NUMBER.
XKONDDP-UPDKZ = 'I'.
XKONDDP-KPOSN = LV_COUNT + 1.
CLEAR : TIME_VAKE_DB, XKONDAT, YKONDAT.
ENDIF.
APPEND XKONDDP.
IF LS_VAKEDB-KNUMH IS INITIAL.
* Condition Maintenance - General
CALL FUNCTION 'RV_KONDITION_SICHERN' IN UPDATE TASK
TABLES
VAKEDB_TAB = TIME_VAKE_DB.
ENDIF.
BOOLE_T = 'X'.
ENDFUNCTION.
Step 1.Go to transaction swo1 (Tools->Business Framework -> BAPI Development ->Business Object
builder ) .Select the business object, according to the functional requirement for which the BAPI is
being created.
Step2.Open the business object in change mode. Then Select Utilities ->API Methods ->Add method.
Then enter the name of the function module and select Continue.
Step4.To create the method select Yes in the next dialog box.
Step5. After the program has been generated and executed, check the program in the method just
created. Thus , a BAPI is created.
• To release the BAPI , first release the function module (using transaction se37 ) .
• Set the status of the method to ‘released’ in the Business Object Builder ( using transaction
SWo1 – Edit-> change status-> released. )