Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

BAPI SALES ORDER & Copy with reference

Hello,

I'm creating sales order copied with reference to an invoice. My problem is that the data item is empty. When I create the sales order manually and use the option 'Create with reference' and choose an invoice, the sales order is created with all data item. I don't know how I can get to copy the data item from the invoice in the new sales order. The code that I'm using is the following:

DATA: order_header_in LIKE bapisdhd1,

order_partners LIKE bapiparnr OCCURS 0 WITH HEADER LINE,

order_text LIKE bapisdtext OCCURS 0 WITH HEADER LINE,

order_header_inx LIKE bapisdhd1x,

order_item_in LIKE bapisditm OCCURS 0 WITH HEADER LINE,

order_schedules_in LIKE bapischdl OCCURS 0 WITH HEADER LINE,

order_conditions_in LIKE bapicond OCCURS 0 WITH HEADER LINE,

extensionin LIKE bapiparex OCCURS 0 WITH HEADER LINE,

partneraddresses LIKE bapiaddr1 OCCURS 0 WITH HEADER LINE,

order_cfgs_ref like BAPICUCFG occurs 0 with header line.

DATA: salesdocument LIKE bapivbeln-vbeln.

DATA: return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.

order_header_in-doc_type = 'ZA09'.

order_header_in-sales_org = '1700'.

order_header_in-distr_chan = '01'.

order_header_in-division = '01'.

order_header_in-BILL_DATE = '20060701'.

order_header_in-ref_doc = '0900000019'.

order_header_in-refdoc_cat = 'M'.

*order_header_in-REF_DOC_L_LONG = '0900000019'.

order_header_in-purch_no_c ='prueba'.

*order_header_in-ord_reason = '003'.

*order_header_in-pmnttrms = '0002'.

*order_header_in-sales_off = '2800'.

order_header_in-ref_doc_l = 'FACTURA ES'.

*order_header_in-fix_val_dy = '20060701'.

*order_header_in-currency = 'USD'.

*order_header_in-exchg_rate = '1.2'.

order_partners-partn_role = 'AG'.

order_partners-partn_numb = '0000000001'.

order_partners-langu = 'EN'.

order_partners-name = 'El corte aleman'.

order_partners-country = 'ES'.

APPEND order_partners.

order_partners-partn_role = 'RE'.

order_partners-partn_numb = 'ARR000'.

order_partners-addr_link = '0000030044'.

APPEND order_partners.

CALL FUNCTION 'ADDR_GET_COMPLETE_ALL_TYPES'

EXPORTING

addrnumber = order_partners-addr_link

  • PERSNUMBER =

address_object_type = '1'

  • IV_CURRENT_COMM_DATA = 'X'

IMPORTING

  • ADDR1_COMPLETE =

  • ADDR2_COMPLETE =

  • ADDR3_COMPLETE =

ADDR1_COMPLETE_BAPI = partneraddresses

  • ADDR2_COMPLETE_BAPI =

  • ADDR3_COMPLETE_BAPI =

  • EXCEPTIONS

  • PARAMETER_ERROR = 1

  • ADDRESS_NOT_EXIST = 2

  • PERSON_NOT_EXIST = 3

  • INTERNAL_ERROR = 4

  • OTHERS = 5

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

data: vl_texto(40) value 'NUEVOOOOO'.

partneraddresses-name = vl_texto. clear vl_texto.

partneraddresses-name_2 = vl_texto.

partneraddresses-name_3 = vl_texto.

partneraddresses-name_4 = vl_texto.

partneraddresses-langu = 'E'.

APPEND partneraddresses.

DATA: vl_cantidad LIKE bapisditm-target_qty.

vl_cantidad = 1.

order_item_in-itm_number = 10.

order_item_in-material = 'HONORARIOS'.

order_item_in-ref_doc = '0900000019'.

order_item_in-ref_doc_it = 10.

order_item_in-ref_doc_ca = 'M'.

APPEND order_item_in.

order_schedules_in-itm_number = 10.

order_schedules_in-req_qty = vl_cantidad.

APPEND order_schedules_in.

order_text-text_id = 'Z001'.

order_text-ITM_NUMBER = ''.

order_text-langu = 'EN'.

order_text-text_line = 'Hola, CARACOLAcola'.

APPEND order_text.

order_text-text_id = 'Z001'.

order_text-langu = 'EN'.

order_text-text_line = 'Adios caracol'.

APPEND order_text.

order_text-itm_number = '000010'.

order_text-text_id = '0001'.

order_text-langu = 'EN'.

order_text-text_line = 'Hola, POSICIÓN'.

APPEND order_text.

extensionin-structure = 'BAPE_VBAK'.

extensionin-valuepart1 = ' BCL 7'.

APPEND extensionin.

order_cfgs_ref-posex = '10'.

order_cfgs_ref-config_id = '10'.

order_cfgs_ref-root_id = '00000001'.

append order_cfgs_ref.

CALL FUNCTION 'ZBAPI_SALESORDER_CREATEFROMDT2'

EXPORTING

  • SALESDOCUMENTIN = salesdocument

order_header_in = order_header_in

  • ORDER_HEADER_INX = order_header_inx

  • SENDER =

  • BINARY_RELATIONSHIPTYPE =

  • INT_NUMBER_ASSIGNMENT =

  • BEHAVE_WHEN_ERROR =

  • LOGIC_SWITCH =

  • TESTRUN =

  • CONVERT = ' '

IMPORTING

salesdocument = salesdocument

TABLES

return = return

order_items_in = order_item_in

  • ORDER_ITEMS_INX =

order_partners = order_partners

order_schedules_in = order_schedules_in

  • ORDER_SCHEDULES_INX =

order_conditions_in = order_conditions_in

  • ORDER_CONDITIONS_INX =

ORDER_CFGS_REF = order_cfgs_ref

  • ORDER_CFGS_INST =

  • ORDER_CFGS_PART_OF =

  • ORDER_CFGS_VALUE =

  • ORDER_CFGS_BLOB =

  • ORDER_CFGS_VK =

  • ORDER_CFGS_REFINST =

  • ORDER_CCARD =

order_text = order_text

  • ORDER_KEYS =

  • extensionin = extensionin

partneraddresses = partneraddresses

.

PERFORM report TABLES return.

*----

-


*DATA: salesdocument LIKE bapivbeln-vbeln.

*DATA: return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.

*refresh return.

*

*CALL FUNCTION 'BAPI_SALESDOCUMENT_COPY'

  • EXPORTING

  • salesdocument = '0400000191'

  • documenttype = 'ZA04'

    • TESTRUN = ' '

  • IMPORTING

  • SALESDOCUMENT_EX = salesdocument

  • TABLES

  • RETURN = return

  • .

*PERFORM report TABLES return.

*write: / salesdocument.

*----

-


CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

  • EXPORTING

  • WAIT =

  • IMPORTING

  • RETURN =

.

*&----


*

*& Form report

*&----


*

  • text

*----


*

  • -->P_MENSAJE text

*----


*

FORM report TABLES p_mensaje STRUCTURE bapiret2.

DATA: vl_mensaje TYPE string.

LOOP AT return.

CLEAR vl_mensaje.

MESSAGE ID return-id

TYPE return-type

NUMBER return-number

INTO vl_mensaje

WITH return-message_v1

return-message_v2

return-message_v3

return-message_v4.

WRITE: / vl_mensaje.

ENDLOOP.

ENDFORM. " report

Tags:
Not what you were looking for? View more on this topic or Ask a question