Thursday, February 21, 2008
BAPI Sales Order Create Code
Bapi Sales Order Create Code
We saw in the earlier example as to how to create a sales order from the SE37 interface. Now we need to create a program and call the BAPI to create sales orders. Later we will discuss ways to call a BAPI from a non-sap system.
Given an appropriate name to the program. Please follow the naming conventions as per your company. ABAP programs should always start with a 'Z' or a 'Y'.
Enter suitable description.
Create a $tmp objects or create a transport request. Transport requests would be covered in the later tutorials.
Follow the menu path EDIT----->Pattern
Enter the name of the BAPI as shown below.
The inserted BAPI is shown below.
We now need to get the import parameters, export parameters and the tables.
Note: Take care that the data declaration in the program for the above mentioned parameters matches exactly as given in the BAPI. To ensure that please open the BAPI using transaction SE37 and copy the exact names of the parameters from the BAPI structure.
If this is not followed your program will give an 'ABAP DUMP'.
Check the Import parameters
The following figure shows the import parameter BAPISHEAD and we need to declare a structure in our ABAP program as follows.
Data: st_BAPISDHEAD like BAPISDHEAD, " Sales Order Header Data
Make sure you follow the ABAP naming conventions.
Similarly for tables pick up the names from the function module.
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
d_BAPIRETURN1 like BAPIRETURN1, " Bapi return msg
d_vbeln like bapivbeln-VBELN. " Sales Order Number
The complete program is given below. Please make sure that you use the data specific to your system. In the following some of the values are hard coded. You need to use variables and pick up the values.
Please note in the following program, sold to party (SP) has been entered as 'AG' and ship to party (SH) as 'RG'.
SP--------AG
SH--------RG
Order type 'OR' as 'TA'
Please use TA instead of OR
Also if you set the * CONVERT_PARVW_AUART = 'X' parameter to 'X' you can use sold to party as SP and ship to party as SH.
REPORT ZEX_BAPISALESORDCRT .
*-------------------------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
d_BAPIRETURN1 like BAPIRETURN1, " Bapi return msg
d_vbeln like bapivbeln-VBELN. " Sales Order Number
* 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.
* Call the Bapi to create the sales order
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT1'
EXPORTING
ORDER_HEADER_IN = st_BAPISDHEAD
* WITHOUT_COMMIT = ' '
* CONVERT_PARVW_AUART = ' '
IMPORTING
SALESDOCUMENT = d_vbeln
* SOLD_TO_PARTY =
* SHIP_TO_PARTY =
* BILLING_PARTY =
RETURN = d_BAPIRETURN1
TABLES
ORDER_ITEMS_IN = ta_BAPIITEMIN
ORDER_PARTNERS = ta_BAPIPARTNR
* ORDER_ITEMS_OUT =
* ORDER_CFGS_REF =
* ORDER_CFGS_INST =
* ORDER_CFGS_PART_OF =
* ORDER_CFGS_VALUE =
* ORDER_CCARD =
* ORDER_CFGS_BLOB =
* ORDER_SCHEDULE_EX =
.
if d_vbeln <> space.
write: 'Sales order No. ', d_vbeln.
endif.
We saw in the earlier example as to how to create a sales order from the SE37 interface. Now we need to create a program and call the BAPI to create sales orders. Later we will discuss ways to call a BAPI from a non-sap system.
Given an appropriate name to the program. Please follow the naming conventions as per your company. ABAP programs should always start with a 'Z' or a 'Y'.
Enter suitable description.
Create a $tmp objects or create a transport request. Transport requests would be covered in the later tutorials.
Follow the menu path EDIT----->Pattern
Enter the name of the BAPI as shown below.
The inserted BAPI is shown below.
We now need to get the import parameters, export parameters and the tables.
Note: Take care that the data declaration in the program for the above mentioned parameters matches exactly as given in the BAPI. To ensure that please open the BAPI using transaction SE37 and copy the exact names of the parameters from the BAPI structure.
If this is not followed your program will give an 'ABAP DUMP'.
Check the Import parameters
The following figure shows the import parameter BAPISHEAD and we need to declare a structure in our ABAP program as follows.
Data: st_BAPISDHEAD like BAPISDHEAD, " Sales Order Header Data
Make sure you follow the ABAP naming conventions.
Similarly for tables pick up the names from the function module.
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
d_BAPIRETURN1 like BAPIRETURN1, " Bapi return msg
d_vbeln like bapivbeln-VBELN. " Sales Order Number
The complete program is given below. Please make sure that you use the data specific to your system. In the following some of the values are hard coded. You need to use variables and pick up the values.
Please note in the following program, sold to party (SP) has been entered as 'AG' and ship to party (SH) as 'RG'.
SP--------AG
SH--------RG
Order type 'OR' as 'TA'
Please use TA instead of OR
Also if you set the * CONVERT_PARVW_AUART = 'X' parameter to 'X' you can use sold to party as SP and ship to party as SH.
REPORT ZEX_BAPISALESORDCRT .
*-------------------------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
d_BAPIRETURN1 like BAPIRETURN1, " Bapi return msg
d_vbeln like bapivbeln-VBELN. " Sales Order Number
* 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.
* Call the Bapi to create the sales order
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT1'
EXPORTING
ORDER_HEADER_IN = st_BAPISDHEAD
* WITHOUT_COMMIT = ' '
* CONVERT_PARVW_AUART = ' '
IMPORTING
SALESDOCUMENT = d_vbeln
* SOLD_TO_PARTY =
* SHIP_TO_PARTY =
* BILLING_PARTY =
RETURN = d_BAPIRETURN1
TABLES
ORDER_ITEMS_IN = ta_BAPIITEMIN
ORDER_PARTNERS = ta_BAPIPARTNR
* ORDER_ITEMS_OUT =
* ORDER_CFGS_REF =
* ORDER_CFGS_INST =
* ORDER_CFGS_PART_OF =
* ORDER_CFGS_VALUE =
* ORDER_CCARD =
* ORDER_CFGS_BLOB =
* ORDER_SCHEDULE_EX =
.
if d_vbeln <> space.
write: 'Sales order No. ', d_vbeln.
endif.
Subscribe to:
Posts (Atom)
ABAP TIPS
|
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. |