Skip to Content
0

CONTRACT using BAPI_CONTRACT_CREATEFROMDATA by referencing a Sales Order.

Sep 12, 2017 at 05:42 AM

75

avatar image
Former Member

My requirement is to create a CONTRACT with reference to a Sales order. When I am not passing Sales Org, distribution channel and Division as we don't pass while creating manually in TCODE VA41, I am getting error "No Sales area could be determined".

My Code is.

REPORT ztest_2386.

DATA: lwa_cont_hdr_in TYPE bapisdhd1,
lwa_cont_hdr_inx TYPE bapisdhd1x,
lwa_return TYPE bapiret2,
lwa_partner TYPE bapiparnr,
lwa_contract TYPE bapictr,
lwa_contractx TYPE bapictrx.

DATA: lit_return TYPE STANDARD TABLE OF bapiret2,
lit_partner TYPE STANDARD TABLE OF bapiparnr,
lit_contract TYPE STANDARD TABLE OF bapictr,
lit_contractx TYPE STANDARD TABLE OF bapictrx.

DATA: l_salesdoc TYPE bapivbeln-vbeln,
l_sales_org TYPE vbak-vkorg,
l_po_type TYPE vbkd-bsark,
l_flag TYPE char1.

CONSTANTS: lc_us15 TYPE vbak-vkorg VALUE 'US15',
lc_wty TYPE vbkd-bsark VALUE 'WTY',
lc_doc_typ TYPE bapisdhd1-doc_type VALUE 'ZEW',
lc_c TYPE bapisdhd1-ref_doc VALUE 'C',
lc_x TYPE char1 VALUE 'X'.

CLEAR: l_sales_org,l_po_type,l_flag.

* Prepare Contract Header Data
lwa_cont_hdr_in-doc_type = lc_doc_typ. "Contract Type
lwa_cont_hdr_in-ref_doc = '0300014418'.
lwa_cont_hdr_in-refdoc_cat = lc_c.


*lwa_cont_hdr_in-sales_org = lc_us15. "Sales Organization
*lwa_cont_hdr_in-distr_chan = '10'. "Distribution Channel
*lwa_cont_hdr_in-division = '30'. "Division


lwa_cont_hdr_in-bill_date = sy-datum. "Bill Date
lwa_cont_hdr_in-bill_block = ''.

lwa_cont_hdr_inx-updateflag = 'I'.
lwa_cont_hdr_inx-doc_type = lc_x.
lwa_cont_hdr_inx-ref_doc = lc_x.
lwa_cont_hdr_inx-refdoc_cat = lc_x.


*lwa_cont_hdr_inx-sales_org = lc_x.
*lwa_cont_hdr_inx-distr_chan = 'X'.
*lwa_cont_hdr_inx-division = 'X'.


lwa_cont_hdr_inx-bill_date = lc_x.
lwa_cont_hdr_inx-bill_block = lc_x.

* prepare Partner details
lwa_partner-partn_role = 'AG'. "Sold to Party
lwa_partner-partn_numb = '0010042413'.
APPEND lwa_partner TO lit_partner.

*Prepare Contract control
lwa_contract-con_st_dat = sy-datum.
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
date = sy-datum
days = 00
months = 00
signum = '+'
years = 1
IMPORTING
calc_date = lwa_contract-con_en_dat.
APPEND lwa_contract TO lit_contract.
**


lwa_contractx-con_st_dat = lc_x.
lwa_contractx-con_en_dat = lc_x.
APPEND lwa_contractx TO lit_contractx.


CALL FUNCTION 'BAPI_CONTRACT_CREATEFROMDATA'
EXPORTING
SALESDOCUMENTIN = '0300014418'
contract_header_in = lwa_cont_hdr_in
contract_header_inx = lwa_cont_hdr_inx
* SENDER =
* BINARY_RELATIONSHIPTYPE = ‘ ‘
* INT_NUMBER_ASSIGNMENT = ‘ ‘
* BEHAVE_WHEN_ERROR = ‘ ‘
* LOGIC_SWITCH =
* TESTRUN =
* convert = 'X'
IMPORTING
salesdocument = l_salesdoc
TABLES
return = lit_return
* contract_items_in =
* contract_items_inx =
contract_partners = lit_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 = lit_contract
contract_data_inx = lit_contractx
* contract_text =
* CONTRACT_KEYS =
* EXTENSIONIN =
* PARTNERADDRESSES =
* EXTENSIONEX =
.

READ TABLE lit_return TRANSPORTING NO FIELDS WITH KEY type = 'E'.
IF sy-subrc IS NOT INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
WRITE: 'success'.
WRITE: l_salesdoc.
ELSE.
LOOP AT lit_return INTO lwa_return.
WRITE: lwa_return-message.
ENDLOOP.
ENDIF.

10 |10000 characters needed characters left characters exceeded

Hi,

This should be MM contracts, not SRM contracts.

So I adjusted the tag.

BR,

Ivy

0
* Please Login or Register to Answer, Follow or Comment.

0 Answers