Skip to Content
author's profile photo Former Member
Former Member

BAPI_CONTRACT_CREATEFROMDATA

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Oct 31, 2014 at 04:44 AM

    Hi Charlie,

    Can you please share code.

    Regards,

    Krishna

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • author's profile photo Former Member
    Former Member
    Posted on Nov 03, 2014 at 12:22 AM

    Hi All,

    Anyone knows what might have caused this problem?

    Cheers,

    Charlie

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 03, 2014 at 04: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 =

    .

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 03, 2014 at 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.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • Posted on Jan 05, 2015 at 03: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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.