Contract Create Using BAPI-BAPI_CONTRACT_CREATEFROMDATA

lightContract Create Using BAPI-BAPI_CONTRACT_CREATEFROMDATA

 

 


The post describes how to create a contract( Quantity Contract)  by using standard BAPI- BAPI_CONTRACT_CREATEFROMDATA.

Also Tx- VA41 can  be used to created contract online. Let’s try to create a contract using Tx- VA41 so that we can get to know minimum info required to create a contract and then will create a contract using BAPI.


Execute transaction- VA41

1

For the contract type – the F4 help shows a list of contract types and we are going to create a quantity contract – CQ. Choose CQ.

2

Provide the sales area data like sales org, distribution channel and division.

3

Provide the sold to party, PO number,  contract valid from date and valid to date, material number, its quantity and Save it. ( need fields highlighted).

4

Contract created.

5

Use Tx- VA43 to open the contract in display mode.

6

Open  table- VBAK in Tx- SE11 and open the contract.

Here the contract type- AUART – is KM but we have selected contract type as CQ in Tx- VA41.

7

All sales doc types(contract types) defined in the table TVAk. Open table TVAK in Tx- SE16n and  search for the sales doc type as CQ.

8

Select the line and choose Details button. The pop up shows that the  original AUART- for CQ is KM. This is required because in the BAPI if we provide doc type as CQ system shows the error . So we have to pass the real value as KM for CQ.

9

In the contract the material unit is provided as PC. Now check its internal representation.

Open table T006B in Tx- SE16n and search for the language En and commercial as PC

10

Select the record and choose details. So the Internal Meas unit is ST.

11


Code Snippet:

DATA: ls_cont_hdr_in TYPE bapisdhd1,
             ls_cont_hdr_inx TYPE bapisdhd1x,
             lv_salesdoc TYPE bapivbeln-vbeln,
              lt_return TYPE TABLE OF bapiret2,
             lt_partner TYPE TABLE OF bapiparnr,
             lt_item_in TYPE TABLE OF bapisditm,
             lt_item_inx TYPE TABLE OF bapisditmx,
            lv_msg TYPE string.

START-OF-SELECTION.
” Prepare Contract Header Data
ls_cont_hdr_in-doc_type = ‘KM’. ” Contract Type( CQ->KM)
ls_cont_hdr_in-purch_no_c = ‘PO_NUM’. ” Purchase Order
ls_cont_hdr_in-sales_org = ‘1000’. ” Sales Organization
ls_cont_hdr_in-distr_chan = ’10’. ” Distribution Channel
ls_cont_hdr_in-division = ’10’. ” Division
ls_cont_hdr_in-ct_valid_f = ‘20170106’. ” Contract Valid From date
ls_cont_hdr_in-ct_valid_t = ‘20170131’. ” Contract valid to date

ls_cont_hdr_inx-doc_type = ‘X’.
ls_cont_hdr_inx-purch_no_c = ‘X’.
ls_cont_hdr_inx-sales_org = ‘X’.
ls_cont_hdr_inx-distr_chan = ‘X’.
ls_cont_hdr_inx-division = ‘X’.
ls_cont_hdr_inx-ct_valid_f = ‘X’.
ls_cont_hdr_inx-ct_valid_t = ‘X’.

* Prepare Contract Item Data
APPEND INITIAL LINE TO lt_item_in ASSIGNING FIELD-SYMBOL(<fs_item_in>).
<fs_item_in>-itm_number = ‘000010’.
<fs_item_in>-material = ‘H11’.
<fs_item_in>-plant = ‘1000’.
<fs_item_in>-ship_point = ‘1000’.
<fs_item_in>-target_qty = ’10’.
<fs_item_in>-target_qu = ‘ST’. ” PC->ST

APPEND INITIAL LINE TO lt_item_inx ASSIGNING FIELD-SYMBOL(<fs_item_inx>).
<fs_item_inx>-itm_number = ‘X’.
<fs_item_inx>-material = ‘X’.
<fs_item_inx>-plant = ‘X’.
<fs_item_inx>-ship_point = ‘X’.
<fs_item_inx>-target_qty = ‘X’.
<fs_item_inx>-target_qu = ‘X’.
* prepare Partner details
APPEND INITIAL LINE TO lt_partner ASSIGNING FIELD-SYMBOL(<fs_partner>).
<fs_partner>-partn_role = ‘AG’. ” Sold to Party
<fs_partner>-partn_numb = ‘0000491000’. 

CALL FUNCTION ‘BAPI_CONTRACT_CREATEFROMDATA’
EXPORTING
* SALESDOCUMENTIN =
contract_header_in = ls_cont_hdr_in
contract_header_inx = ls_cont_hdr_inx
* SENDER =
* BINARY_RELATIONSHIPTYPE = ‘ ‘
* INT_NUMBER_ASSIGNMENT = ‘ ‘
* BEHAVE_WHEN_ERROR = ‘ ‘
* LOGIC_SWITCH =
* TESTRUN =
* CONVERT = ‘ ‘
IMPORTING
salesdocument = lv_salesdoc
TABLES
return = lt_return
contract_items_in = lt_item_in
contract_items_inx = lt_item_inx
contract_partners = lt_partner
* CONTRACT_CONDITIONS_IN =
* CONTRACT_CONDITIONS_INX =
* CONTRACT_CFGS_REF =
* CONTRACT_CFGS_INST =
* CONTRACT_CFGS_PART_OF =
* CONTRACT_CFGS_VALUE =
* CONTRACT_CFGS_BLOB =
* CONTRACT_CFGS_VK =
* CONTRACT_CFGS_REFINST =
* contract_data_in =
* contract_data_inx =
* CONTRACT_TEXT =
* CONTRACT_KEYS =
* EXTENSIONIN =
* PARTNERADDRESSES =
* EXTENSIONEX =
.

READ TABLE lt_return TRANSPORTING NO FIELDS WITH KEY type = ‘E’.
IF sy-subrc IS NOT INITIAL.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
EXPORTING
wait = ‘X’.
LOOP AT lt_return ASSIGNING FIELD-SYMBOL(<fs_return>).
CALL FUNCTION ‘FORMAT_MESSAGE’
EXPORTING
ID = <fs_return>-id
LANG = ‘EN’
NO = <fs_return>-number
V1 = <fs_return>-message_v1
V2 = <fs_return>-message_v2
V3 = <fs_return>-message_v3
V4 = <fs_return>-message_v4
IMPORTING
MSG = lv_msg
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.

IF sy-subrc <> 0.
ENDIF.
WRITE :/ lv_msg.
ENDLOOP.
WRITE :/ ‘Contract:’, lv_salesdoc , ‘has been created’ .
ELSE.
CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK’.

ENDIF.


 

12


Execute the program and here we have the output.

13


Check the contract in Tx- VA43.

14


 

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s