In SAP before creating a sales order there is a way to simulate it using a BAPI. This can be done using the following BAPI.
SAP ABAP BAPI to Simulate a Sales Order.
BAPI_SALESORDER_SIMULATE
This is very useful in case you want to check the Availability and Pricing. The parameters obtained are given below.
BAPIITEMEX Communication Fields: Issue SD Document Item: WWW BAPISDHEDU Struture of VBEP (Sales Document: Schedule Line Data) BAPICOND Communication Fields for Maintaining Conditions in the Order BAPIINCOMP Communication Fields: Incompletion
Find the code below.
Note: This is very similar to Sales Order Create BAPI 'BAPI_SALESORDER_CREATEFROMDAT1' but in this case the actual Sales Order is not created instead a simulation is carried out.
REPORT ZEX_SALORDSIMULATE.
*-------------------------Data Declaration-----------------------------* Data: st_BAPISDHEAD like BAPISDHEAD, " Sales Order Header Data ta_BAPIITEMIN like BAPIITEMIN occurs 0 with header line, " Ln item ta_BAPIPARTNR like BAPIPARTNR occurs 0 with header line, " Partner int_BAPIITEMEX like BAPIITEMEX occurs 0 with header line, int_BAPISDHEDU like BAPISDHEDU occurs 0 with header line, int_BAPICOND like BAPICOND occurs 0 with header line, int_BAPIINCOMP like BAPIINCOMP occurs 0 with header line, d_BAPIRETURN1 like BAPIRETURN. " Bapi return msg
* Move the data to create sales order in the repective parameters------* move: 'TA' to st_BAPISDHEAD-DOC_TYPE, " Sales document type '15493' to st_BAPISDHEAD-PURCH_NO_C, '00010' to ta_BAPIITEMIN-ITM_NUMBER, 'Y-351' to ta_BAPIITEMIN-MATERIAL, '1100' to ta_BAPIITEMIN-PLANT, '1' to ta_BAPIITEMIN-REQ_QTY, 'AG' to ta_BAPIPARTNR-PARTN_ROLE, " Sold to Party '0000007777' to ta_BAPIPARTNR-PARTN_NUMB. * Append the internal tables-------------------------------------------* append ta_BAPIPARTNR. clear ta_BAPIPARTNR. append ta_BAPIITEMIN. clear ta_BAPIITEMIN. * Move ship to party---------------------------------------------------* move: 'RG' to ta_BAPIPARTNR-PARTN_ROLE, " Ship to party '0000007777' to ta_BAPIPARTNR-PARTN_NUMB. * Append the internal tables-------------------------------------------* append ta_BAPIPARTNR. clear ta_BAPIPARTNR.
To get a list of all the BAPIs in the system the following BAPI can be used.
BAPI_MONITOR_GETLIST ____________________________
The following Parameters should be passed to the above mentioned BAPI
Object type Release /Reference Release to Display Display Potential BAPIs Display New BAPIs in Release Display BAPIs from Previous Releases Release Status of BAPIs Release Status of Function Modules
The BAPI returns a table with the following information.
Object type, Object name, Method name of BAPI, Function module name, Application component ID, Release at creation, Author, Last changed on, Last changed by, R/3 System, name of R/3 System, Application area or BAPI Work Group reponsible, Interface object type, Release status of BAPI methods, Release status of function module, Release in which object type was set as obsolete, Documentation on function module exists, Documentation for business object exists, Message type, Object type component, Description.
Example:
REPORT ZEX_BAPI_GETLIST .
* Parameters-----------------------------------------------------------* Parameter: p_ojtpe like BAPIMONIT-OBJTYPE default '*', p_rel like BAPIMONIT-CREA_REL default SY-SAPRL, p_poten like BAPIMONIT-OPTSEL default ' ', p_newbp like BAPIMONIT-OPTSEL default 'X', p_oldbp like BAPIMONIT-OPTSEL default 'X', p_relbp like BAPIMONIT-OPTSEL default '*', p_relfun like BAPIMONIT-FUNCREL default '*'.
* Data Declaration-----------------------------------------------------* Data: d_ret like BAPIRET2.
* Internal Table Declaration-------------------------------------------* Data: int_comsel like BAPIMONCOM occurs 0 with header line, int_orgBP like BAPISRCSYS occurs 0 with header line, int_selbap like BAPIMONSTR occurs 0 with header line.
If you wish to edit a Material, you can use the following BAPI.
BAPI_MATERIAL_EDIT
The above mentioned BAPI makes use of CALL TRANSACTION MM02 or MM42 to edit the MATERIAL. The selection of the appropriate transaction is made based on the entered material. The table MAW1 is checked for the existence of material, if the material exists in MAW1 then the transaction MM02 is called else transaction MM42 is called.
BAPI_MATERIAL_EDIT in turn calls the following function modules.
BAPI_MATERIAL_EXISTENCECHECK and CONVERSION_EXIT_MATN1_OUTPUT
The user is then presented with the change material screen either for MM02 or MM42.
The code below shows the values of the input parameters for the BAPI BAPI_MATERIAL_EDI
REPORT ZEX_CHANGEMAT .
Parameters: p_matnr like BAPIMATALL-MATERIAL, p_fscrn like BAPIMATALL-SKIP_1ST_SCREEN.
Data: d_ret like BAPIRET1.
CALL FUNCTION 'BAPI_MATERIAL_EDIT' EXPORTING MATERIAL = p_matnr SKIP_1ST_SCREEN = p_fscrn IMPORTING RETURN = d_ret .
In part 1 SAP ABAP Creating a Material using a BAPI Part 1we have seen how to get the next Material Number. In this Part we will see the parameters that need to be passed for creating the actual Material. For simplicity let us keep the number of parameters to minimum. We will just pass the mandatory fields as per the system that I am using. Please note that you need to pass the Material Number Obtained in the previous Part. Also make sure that you run the following BAPIs in the Order shown below.
To create a Material in SAP using a BAPI you need to use the following 2 BAPIs
BAPI_MATERIAL_GETINTNUMBER _______________________________________________ Pass the Material Number obtained from the above BAPI to the following BAPI _______________________________________________
In SAP ABAP you can create a Material using a BAPI. To do so you first need to get the Next Material Number. This can be obtained by using the following BAPI.
To create a Material in SAP using a BAPI you need to use the following 2 BAPIs
BAPI_MATERIAL_GETINTNUMBER
BAPI_MATERIAL_SAVEDATA
If you are suing the transaction MM01 to create a Material, you can see the Material Number being assigned automatically. If you have not noticed this please run the transaction MM01 and enter the values in the initial screen. After hitting enter you will see the Material Number appear in the next screen automatically.
Let us now see the parameters that need to be passed to the BAPI BAPI_MATERIAL_GETINTNUMBER.
The Mandatory Parameters that need to be passed to the BAPI are as follows.
Material Type Industry Sector Required Numbers
Enter the desired values and generate the Next Material Number. Once you obtain the Material Number, you then need to pass this number to the following BAPI.
BAPI to create Material in SAP
BAPI_MATERIAL_SAVEDATA
The following program demonstrates the BAPI BAPI_MATERIAL_GETINTNUMBER
REPORT ZEX_GETMATNUM .
Parameters: p_matype like BAPIMATDOA-MATL_TYPE, p_indsr like BAPIMATDOA-IND_SECTOR, p_reqnum like BAPIMATALL-REQ_NUMBERS.
Material Type HAWA Industry Sector C Required Numbers 1
See Also: SAP ABAP Creating a Material using a BAPI Part 2 ____________________________________________________________________________________________________________________________________________________________________
If you wish to display Material data related to Material General Data, Material Plant Data and Material Valuation Data then you can use the following BAPI. This BAPI displays the above mentioned data for a Material.
BAPI/Function Module to display Material Data / Display Material Data BAPI/Function Module
BAPI_MATERIAL_GET_DETAIL
This BAPI has 4 input parameters
Material (Mandatory) Plant Valuation Area Valuation Type
Please find the code below.
REPORT ZEX_GETMATDET .
Parameters: p_matnr like BAPIMATDET-MATERIAL, p_werks like BAPIMATALL-PLANT, p_valara like BAPIMATALL-VAL_AREA, p_valtyp like BAPIMATALL-VAL_TYPE.
Data: st_matgendata like BAPIMATDOA, st_matplantdat like BAPIMATDOC, st_matvaldat like BAPIMATDOBEW, d_return like BAPIRETURN.
If you wish to extract the bank details of a particular vendor then you can use the following BAPI.
BAPI/Function Module for vendor bank details extraction
BAPI_VENDOR_GETDETAIL
Please find below the code to extract vendor Bank Details.
REPORT ZEX_CUSTOMERBANK .
Parameters: p_kunnr like BAPICUSTOMER_ID-CUSTOMER, p_bukrs like BAPICUSTOMER_ID-COMP_CODE.
Data: ty_knbk type knbk, ty_custadd type BAPICUSTOMER_04, ty_custgendet type BAPICUSTOMER_KNA1, ty_custcompdet type BAPICUSTOMER_05, d_ret like BAPIRET1.
Data: wa_custadd like ty_custadd, wa_custgendet like ty_custgendet, wa_custcompdet like ty_custcompdet.
In case you wish to extract the Bank Data for a particular customer, you can use the following BAPI. This BAPI extracts the Customer's Address, General Data, Company Code Data and the Bank Details.
SAP ABAP to get customer Bank Details
BAPI_CUSTOMER_GETDETAIL2
For reference please find below the transaction codes to Create/Change/Display a customer
VD01 Create Customer Sales and Distribution VD02 Change Customer Sales and Distribution VD03 Display Customer Sales and Distribution
Also Find below the tables related to the BAPI BAPI_CUSTOMER_GETDETAIL2
KNBK-Customer Master (Bank Details) ADRC- Addresses (central address admin.) KNA1-General Data in Customer Master KNB1-Customer Master (Company Code)
The following code extracts the above mentioned details from the SAP R/3 System
REPORT ZEX_CUSTOMERBANK .
Parameters: p_kunnr like BAPICUSTOMER_ID-CUSTOMER, p_bukrs like BAPICUSTOMER_ID-COMP_CODE.
Data: ty_knbk type knbk, ty_custadd type BAPICUSTOMER_04, ty_custgendet type BAPICUSTOMER_KNA1, ty_custcompdet type BAPICUSTOMER_05, d_ret like BAPIRET1.
Data: wa_custadd like ty_custadd, wa_custgendet like ty_custgendet, wa_custcompdet like ty_custcompdet.
In case you wish to read the customer data you can use the following BAPI, it retrieves the Customer Master (Company Code) Data and the General Data in Customer Master.
SAP ABAP BAPI to Read Customer Master Data
CUSTOMER_READ
You need to pass the Customer Number and the Company Code. See the example given below.
REPORT ZEX_CUSTOMERREAD .
Parameters: p_bukrs like KNB1-BUKRS, p_kunnr like KNA1-KUNNR.
Data: ty_kna1 type kna1, ty_knb1 type knb1.
Data: int_kna1 like ty_kna1, int_knb1 like ty_knb1.
CALL FUNCTION 'CUSTOMER_READ' EXPORTING I_BUKRS = p_bukrs I_KUNNR = p_kunnr IMPORTING E_KNA1 = int_Kna1 E_KNB1 = int_knb1 EXCEPTIONS NOT_FOUND = 1 OTHERS = 2 . IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.
If you wish to transfer Purchase Order related Data to SAP, you can do so by using the following BAPI.
BAPI_PO_CREATE
Many a times there is a requirement to transfer purchase order data from a third party to SAP, it can be done by the following methods.
1) BAPI 3) BDC 3) EDI
This this tutorial we will see how to create a Purchase Order using the above mentioned BAPI.
Please note that if you wish to create Real Time Purchase Orders from an external system into SAP R/3 then you need to use either the JCO connector, .NET connector or XI. The example below shows creation of a single purchase order, if you have data required to create purchase orders then you first need to upload it into an internal table and then pass the table to the BAPI.
Please find the code below to create a Purchase order using the BAPI BAPI_PO_CREATE
REPORT ZEX_POCREATE .
Data: int_pohead like BAPIEKKOC, int_poitem like BAPIEKPOC occurs 0 with header line, int_posched like BAPIEKET occurs 0 with header line, int_ret like BAPIRETURN occurs 0 with header line. Data: d_purchord like BAPIEKKOC-PO_NUMBER.
Move: 'NB' to int_pohead-DOC_TYPE, '1000' to int_pohead-PURCH_ORG, '001' to int_pohead-PUR_GROUP, '0000001234' to int_pohead-vendor,
'00010' to int_poitem-po_item, 'Material' to int_poitem-material, 'Material' to int_poitem-pur_mat, '1000' to int_poitem-plant,
'00010' to int_posched-PO_ITEM, '20080531' to int_posched-DELIV_DATE, '2' to int_posched-QUANTITY.
Always use Pretty Printer and Extended Program Check before releasing the code.
Do not leave unused code in the program. Comment the code thoroughly. Align the comments and the Code. Follow the SAP Standards and SAP Best Practices guidelines. It’s a good practice to take a dump of the code on your local drive.