2014 Oct 31 3:42 AM
Hi All,
I am trying to create an upload file for customer contract creation using BAPI_CONTRACT_CREATEFROMDATA. All of the fields are updated except for CONTRACT START( CT_VALID_F) and CONTRACT END( CT_VALID_T). I also have used CONTRACT_HEADER_INX but still not working. Can anyone help me with this?
Best Regards,
Charlie
2014 Oct 31 4:44 AM
2014 Nov 02 6:06 AM
Hi Krishna,
Here is my BAPI. Other fields were actually updated except for the date. Hope you can help me with this. thanks.
CALL FUNCTION 'BAPI_CONTRACT_CREATEFROMDATA'
EXPORTING
* SALESDOCUMENTIN =
contract_header_in = v_contract_header_in
CONTRACT_HEADER_INX = v_contract_header_inx
* SENDER =
* BINARY_RELATIONSHIPTYPE = ' '
* INT_NUMBER_ASSIGNMENT = ' '
* BEHAVE_WHEN_ERROR = ' '
* LOGIC_SWITCH =
TESTRUN = lc_test
* CONVERT = ' '
IMPORTING
SALESDOCUMENT = lc_vbeln
TABLES
RETURN = gt_return
CONTRACT_ITEMS_IN = v_contract_items_in
CONTRACT_ITEMS_INX = v_contract_items_inx
CONTRACT_PARTNERS = v_contract_partners
* 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 =
.
Best Regards,
Charlie
2014 Nov 03 12:22 AM
Hi All,
Anyone knows what might have caused this problem?
Cheers,
Charlie
2014 Nov 03 4:38 AM
Hi Charlie,
You should pass the date feild in the format 20140101 if the date is 1st of Jan 2014.
If you are passing the date in you file in this format 01.01.2014. Then you must use concatenate and pass the values accordingly.
Also you must declare the date as type C in you structure.
for e.g.
TYPES : BEGIN OF STR,
CT_VALID_F(10) TYPE C,
CT_VALID_T(10) TYPE C,
END OF STR,
DATA : ITAB TYPE TABLE OF STR WITH HEADER LINE.
CONCATENATE ITAB-CT_VALID_F+6(4) ITAB-CT_VALID_F+3(2) ITAB-CT_VALID_F+0(2) INTO ITAB-CT_VALID_F.
V_CONTRACT_HEADER_IN-CT_VALID_F = ITAB-CT_VALID_F.
CONCATENATE ITAB-CT_VALID_F+6(4) ITAB-CT_VALID_F+3(2) ITAB-CT_VALID_F+0(2) INTO ITAB-CT_VALID_F.
V_CONTRACT_HEADER_IN-CT_VALID_T = ITAB-CT_VALID_T.
CALL FUNCTION 'BAPI_CONTRACT_CREATEFROMDATA'
EXPORTING
* SALESDOCUMENTIN =
contract_header_in = v_contract_header_in
CONTRACT_HEADER_INX = v_contract_header_inx
* SENDER =
* BINARY_RELATIONSHIPTYPE = ' '
* INT_NUMBER_ASSIGNMENT = ' '
* BEHAVE_WHEN_ERROR = ' '
* LOGIC_SWITCH =
TESTRUN = lc_test
* CONVERT = ' '
IMPORTING
SALESDOCUMENT = lc_vbeln
TABLES
RETURN = gt_return
CONTRACT_ITEMS_IN = v_contract_items_in
CONTRACT_ITEMS_INX = v_contract_items_inx
CONTRACT_PARTNERS = v_contract_partners
* 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 =
.
2014 Nov 03 6:33 AM
Hi Anish,
Thank you for your reply. I have applied the code that you have given me, unfortunately it didn't work. I have changed the date format to cater the code that you gave me, Its actually returning an error. By default, I am actually using the format of the date of CT_VALID_F/CT_VALID_T for me to no longer convert it, and as to the data type, i'm currently referring to the structure of BAPISDHD1, but sitll it wont update. Upon checking through debugging mode, the date is actually reflecting but when viewing in TCode VA43, contract start and contract end is not updated.
Best Regards,
Charlie
2014 Nov 03 8:13 AM
Hi Charlie,
I tried running the code give below and it displayed the correct output.
TYPES : BEGIN OF STR,
CT_VALID_F(10) TYPE C,
CT_VALID_T(10) TYPE C,
END OF STR.
DATA : ITAB TYPE TABLE OF STR WITH HEADER LINE,
V_CONTRACT_HEADER_IN TYPE BAPISDHD1.
ITAB-CT_VALID_F = '01.01.2014'.
ITAB-CT_VALID_T = '01.01.2014'.
APPEND ITAB.
LOOP AT ITAB.
CONCATENATE ITAB-CT_VALID_F+6(4) ITAB-CT_VALID_F+3(2) ITAB-CT_VALID_F+0(2) INTO ITAB-CT_VALID_F.
V_CONTRACT_HEADER_IN-CT_VALID_F = ITAB-CT_VALID_F.
CONCATENATE ITAB-CT_VALID_T+6(4) ITAB-CT_VALID_T+3(2) ITAB-CT_VALID_T+0(2) INTO ITAB-CT_VALID_T.
V_CONTRACT_HEADER_IN-CT_VALID_T = ITAB-CT_VALID_T.
ENDLOOP.
WRITE : V_CONTRACT_HEADER_IN-CT_VALID_F , V_CONTRACT_HEADER_IN-CT_VALID_T.
Please cross check the code. If you still face any problems try using the function module CONVERT_DATE_TO_INTERNAL for converting date into SAP format.
Please check the below link for example.
http://scn.sap.com/thread/3494909
Hope this would be useful.
2014 Nov 03 8:49 AM
Hi Anish,
Thanks for the reply.... However, im still having the same error. Please see image below.
I have used '01.01.2014' and '01.01.2015' for the dates and performed the concatenations. I have a question, why do i need to set my date format when I can make it the same as what it is supposed to be, with that I also do not need to perform any conversion.
Thanks and best Regards,
Charllie
2014 Nov 03 8:57 AM
Hi Charllie,
The length of the date fields of from date and to date is 8 characters.
so whenever you are passing the vale for that date is yearmonthdate(yyyymmdd).
Please pass like that and try.
Regards,
Krishna
2014 Nov 03 9:07 AM
Hi Krishna,
That is actually the value that I am passing. But it wont update the contract start and contract end date. All fields are okay except for these 2.Please see the value I am passing under CONTRACT_HEADER_IN in my BAPI. (Debugger mode).
Best Regards,
Charlie
2014 Nov 03 9:17 AM
Hi ,
please pass the QT_VALID_F & QT_VALID_T values also and try.
Regards,
Krishna
2014 Nov 03 9:27 AM
Hi Krishna,
Isn't QT_VALID_F & QT_VALID_T for quotations? Anyways,tried your suggestion, but still not working. Do you have a program for this? Can I ask for your code if you don't mind.
Best Regards,
Charlie
2014 Nov 03 9:51 AM
Hi Charlie,
did you try using the function module CONVERT_DATE_TO_INTERNAL for converting date into SAP format.
Please check the below link for example.
http://scn.sap.com/thread/3494909
Convert date to internal format
Function CONVERT_DATE_TO_INTERNAL
how to convert character string into date format????
Also check if the date gets updated if you pass the input as 20140101 instead of 01.01.2014 in your file. Please share the screenshot of the return message gt_return for a better view of the error.
2014 Nov 03 10:01 AM
Hi Anish,
Already did, I actually did that at first, but still no luck. 😕
Cheers,
Charlie
2014 Nov 03 10:06 AM
Hi Charlie,
Could you please attach Screenshot of the return message gt_return in order to check the error/successful message you are receiving
2014 Nov 03 10:10 AM
Hi Anish,
As requested. Please see image below.
Best Regards,
Charlie
2014 Nov 03 11:18 AM
Hi Charlie,
It seems that BAPI document is incomplete as per the warning.
Please check if you are able to save the document manually VA41 and see the date in VA43.
You can use the following code for your reference inorder to compare any missing values in your report.
Report contractbapi.
data: w_header like bapisdhd1,
v_order like bapivbeln-vbeln,
w_return like bapiret2,
t_return like bapiret2 occurs 0,
w_items like bapisditm,
t_items like bapisditm occurs 0,
w_partners like bapiparnr,
t_partners like bapiparnr occurs 0,
w_conds like bapicond,
t_conds like bapicond occurs 0,
w_sched like bapischdl,
t_sched like bapischdl occurs 0,
w_texts like bapisdtext,
t_texts like bapisdtext occurs 0,
v_exit.
selection-screen begin of block b1 with frame.
parameters: p_sp type kunnr,
p_sh type kunnr,
p_bppy type kunnr,
* p_auart type AUART,
p_auart type AUART,
* p_auart like VBAK-AUART,
p_vkorg type vkorg,
p_vtweg type vtweg,
p_spart type spart,
p_bname type bname_v,
p_date type audat,
p_gueen type gueen,
p_guebg type guebg,
p_bstkd type bstkd,
p_inco1 type inco1,
p_inco2 type inco2,
ZTERM TYPE DZTERM.
selection-screen end of block b1.
selection-screen begin of block b2 with frame.
parameters: p_matnr1 type matnr,
p_quan1 type dzmeng,
p_charg type CHARG_D,
p_werks type werks,
p_VSTEL type VSTEL,
p_werds type SDABW,
p_pstyv type PSTYV,
p_unit1 type dzieme,
p_brgew1 type brgew,
p_ntgew1 type ntgew,
p_gewei1 type gewei,
p_netwr1 type bapicurext,
p_matnr2 type matnr,
p_quan2 type dzmeng,
p_unit2 type dzieme,
p_brgew2 type brgew,
p_ntgew2 type ntgew,
p_gewei2 type gewei,
p_netwr2 type bapicurext.
selection-screen end of block b2.
selection-screen begin of block b3 with frame.
parameters: p_text1(44),
p_text2(44),
p_text3(44).
selection-screen end of block b3.
start-of-selection.
***** HEADER *****
move: p_auart to w_header-doc_type,
p_bstkd to w_header-PURCH_NO_C,
p_guebg to w_header-CT_VALID_F,
p_gueen to w_header-CT_VALID_T,
p_vkorg to w_header-sales_org,
p_vtweg to w_header-distr_chan,
p_spart to w_header-division,
p_date to w_header-req_date_h,
p_date to w_header-price_date,
p_inco1 to w_header-incoterms1,
p_inco2 to w_header-incoterms2,
ZTERM TO w_header-PMNTTRMS,
sy-uzeit to w_header-purch_no_c,
sy-uzeit to w_header-ref_doc_l,
p_bname to w_header-name.
***** ITEMS *****
move: p_matnr1 to w_items-material,
p_werks to w_items-PLANT,
p_VSTEL to w_items-SHIP_POINT,
p_charg to w_items-BATCH,
p_werds to w_items-S_PROC_IND,
p_pstyv to w_items-ITEM_CATEG,
p_quan1 to w_items-target_qty,
p_unit1 to w_items-target_qu,
p_brgew1 to w_items-gross_wght,
p_ntgew1 to w_items-net_weight,
p_gewei1 to w_items-untof_wght,
p_gewei1 to w_items-unof_wtiso,
'000010' to w_items-itm_number.
* p_netwr1 to w_items-target_val,
* 'USD' to w_items-currency,
* 'USD' to w_items-curr_iso.
append w_items to t_items.
clear w_items.
move: p_matnr2 to w_items-material,
p_quan2 to w_items-target_qty,
p_unit2 to w_items-target_qu,
p_brgew2 to w_items-gross_wght,
p_ntgew2 to w_items-net_weight,
p_gewei2 to w_items-untof_wght,
p_gewei2 to w_items-unof_wtiso,
'000020' to w_items-itm_number.
* p_netwr2 to w_items-target_val,
* 'USD' to w_items-currency,
* 'USD' to w_items-curr_iso.
append w_items to t_items.
***** PRICING *****
move: 'PR01' to w_conds-cond_type,
p_netwr1 to w_conds-cond_value,
* p_netwr1 to w_conds-conbaseval,
'CNY' to w_conds-currency,
p_unit1 to w_conds-cond_unit,
'1' to w_conds-cond_p_unt,
'B' to w_conds-calctypcon,
'000010' to w_conds-itm_number,
'011' to w_conds-cond_st_no,
'00' to w_conds-cond_count.
append w_conds to t_conds.
move: 'PR00' to w_conds-cond_type,
p_netwr2 to w_conds-cond_value,
* p_netwr1 to w_conds-conbaseval,
p_unit2 to w_conds-cond_unit,
'000020' to w_conds-itm_number,
'011' to w_conds-cond_st_no.
* append w_conds to t_conds.
***** SCHEDULE LINES *****
move: '000010' to w_sched-itm_number,
'0001' to w_sched-sched_line,
'20050112' to w_sched-req_date,
'1' to w_sched-date_type,
sy-uzeit to w_sched-req_time,
p_quan1 to w_sched-req_qty.
append w_sched to t_sched.
move: '000020' to w_sched-itm_number,
p_quan2 to w_sched-req_qty.
* append w_sched to t_sched.
***** PARTNERS *****
move: 'SP' to w_partners-partn_role,
p_sp to w_partners-partn_numb.
append w_partners to t_partners.
move: 'SH' to w_partners-partn_role,
p_sh to w_partners-partn_numb.
append w_partners to t_partners.
move: 'BP' to w_partners-partn_role,
p_bppy to w_partners-partn_numb.
append w_partners to t_partners.
move: 'PY' to w_partners-partn_role,
p_bppy to w_partners-partn_numb.
append w_partners to t_partners.
***** TEXTS *****
move: '0002' to w_texts-text_id,
'000010' to w_texts-itm_number,
'E' to w_texts-langu,
'EN' to w_texts-langu_iso,
'*' to w_texts-format_col,
p_text1 to w_texts-text_line.
append w_texts to t_texts.
move: '0002' to w_texts-text_id,
'000010' to w_texts-itm_number,
'E' to w_texts-langu,
'EN' to w_texts-langu_iso,
'*' to w_texts-format_col,
p_text2 to w_texts-text_line.
append w_texts to t_texts.
move: '0002' to w_texts-text_id,
'000010' to w_texts-itm_number,
'E' to w_texts-langu,
'EN' to w_texts-langu_iso,
'*' to w_texts-format_col,
p_text3 to w_texts-text_line.
append w_texts to t_texts.
call function 'BAPI_CONTRACT_CREATEFROMDATA'
exporting
CONTRACT_HEADER_IN = w_header
* ORDER_HEADER_INX
* BEHAVE_WHEN_ERROR
* LOGIC_SWITCH
* TESTRUN
convert = 'X'
importing
salesdocument = v_order
tables
return = t_return
CONTRACT_items_in = t_items
CONTRACT_partners = t_partners
CONTRACT_schedules_in = t_sched
CONTRACT_conditions_in = t_conds
CONTRACT_text = t_texts
.
call function 'BAPI_TRANSACTION_COMMIT'.
write: 'Sales document', v_order, 'has been created'.
if sy-subrc <> 0.
loop at t_return into w_return.
message id w_return-id type 'I' number w_return-number
with w_return-message_v1
w_return-message_v2
w_return-message_v3
w_return-message_v4.
endloop.
endif.
2014 Nov 06 1:34 AM
Hi Anish,
Good day!
I have tried using your code, it did not show any error. However, no contract document were created. Also, just want to inform you that in the image I posted earlier, it says some data were not complete but it can still create a contract document number, its just that it does not update the contract start and contract end dates.
Cheers,
Charlie
2015 Jan 05 3:17 PM
Hello Charlie,
To create contracts using BAPI_CONTRACT_CREATEFROMDATA u need pass more data. Field at least this tables:
TRY.
CALL FUNCTION 'BAPI_CONTRACT_CREATEFROMDATA'
EXPORTING
contract_header_in = bapi-contract_header_in
contract_header_inx = bapi-contract_header_inx
IMPORTING
salesdocument = bapi-salesdocument
TABLES
return = bapi-return
contract_items_in = bapi-contract_items_in
contract_items_inx = bapi-contract_items_inx
contract_partners = bapi-contract_partners
contract_conditions_in = bapi-contract_conditions_in
contract_conditions_inx = bapi-contract_conditions_inx
contract_data_in = bapi-contract_data_in
contract_data_inx = bapi-contract_data_inx.
CATCH cx_root.
ENDTRY.
To convert dates use:
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
date_external = p_date
IMPORTING
date_internal = c_date
EXCEPTIONS
date_external_is_invalid = 1
OTHERS = 2.
Regards,
Diogo Pimenta