Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Copy the Sales order using Bapi

Former Member
0 Likes
1,840

Hi

I am having one sales order which have essential data.i want to copy is SO in to other SO.Is there with u any code through Bapi ..

1 ACCEPTED SOLUTION
Read only

b_deterd2
Active Contributor
0 Likes
1,016

Hi,

This should work.


method create_from_inquiry.

  data: lv_auara type auart.
  data: ls_vbak type vbak.
  data: ls_buf type sado_buf_flagstring.
  data: ls_vbakkom type vbakkom.
  data: lv_testrun type xfeld.
  data: ls_ret2 type bapiret2.
  data: lv_error type xfeld.

  move testrun to lv_testrun.

  select single * from vbak
  into ls_vbak
  where vbeln = vbeln_in.

  if new_ordertype is initial.

    select single auara
    from tvak
    into lv_auara
    where auart = ls_vbak-auart.

  else.

    lv_auara = new_ordertype.

  endif.


  sy-tcode = 'VA01'.
  call function 'BAPI_SALESDOCUMENT_COPY'
    exporting
      salesdocument    = vbeln_in
      documenttype     = lv_auara
      testrun          = lv_testrun
    importing
      salesdocument_ex = vbeln_out
    tables
      return           = bapireturn.

  if lv_testrun is initial.

    lv_error = zcl_bapi=>check_for_errors( bapireturn ).

    if lv_error is initial.

      call function 'BAPI_TRANSACTION_COMMIT'
        exporting
          wait = 'X'.

      ls_ret2-type = 'S'.
      ls_ret2-message = 'Verkooporder gecreeerd'.
      ls_ret2-message_v1 = vbeln_out.
      append ls_ret2 to bapireturn.

    endif.

  endif.


endmethod.

2 REPLIES 2
Read only

Former Member
0 Likes
1,016

Hi,

Did you search the forum ?

https://www.sdn.sap.com/irj/scn/advancedsearch?query=bapitocreatesalesorderwithreference&cat=sdn_all

regards,

Advait

Read only

b_deterd2
Active Contributor
0 Likes
1,017

Hi,

This should work.


method create_from_inquiry.

  data: lv_auara type auart.
  data: ls_vbak type vbak.
  data: ls_buf type sado_buf_flagstring.
  data: ls_vbakkom type vbakkom.
  data: lv_testrun type xfeld.
  data: ls_ret2 type bapiret2.
  data: lv_error type xfeld.

  move testrun to lv_testrun.

  select single * from vbak
  into ls_vbak
  where vbeln = vbeln_in.

  if new_ordertype is initial.

    select single auara
    from tvak
    into lv_auara
    where auart = ls_vbak-auart.

  else.

    lv_auara = new_ordertype.

  endif.


  sy-tcode = 'VA01'.
  call function 'BAPI_SALESDOCUMENT_COPY'
    exporting
      salesdocument    = vbeln_in
      documenttype     = lv_auara
      testrun          = lv_testrun
    importing
      salesdocument_ex = vbeln_out
    tables
      return           = bapireturn.

  if lv_testrun is initial.

    lv_error = zcl_bapi=>check_for_errors( bapireturn ).

    if lv_error is initial.

      call function 'BAPI_TRANSACTION_COMMIT'
        exporting
          wait = 'X'.

      ls_ret2-type = 'S'.
      ls_ret2-message = 'Verkooporder gecreeerd'.
      ls_ret2-message_v1 = vbeln_out.
      append ls_ret2 to bapireturn.

    endif.

  endif.


endmethod.