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

BAPI_SALESDOCUMENT_COPY is not returning document number.

Former Member
0 Likes
1,753

Hi,

I am trying to create  sales document with refrence to contract by using BAPI 'BAPI_SALESDOCUMENT_COPY', It is returning the document number for the first iteration and not returning for other iteratons and not returning errors too. Can you please suggest, what could be the reason.

Here is my code.

data:

         L_VBELN         TYPE      VBELN_VA,      

         LI_RETURN       TYPE  TABLE OF BAPIRET2.

   * Create DMR by copying the contract.
  CALL FUNCTION 'BAPI_SALESDOCUMENT_COPY'
    EXPORTING
      SALESDOCUMENT    = WA_VBAK-VBELN
      DOCUMENTTYPE     = 'ZIRS'
*      TESTRUN          = ' '
    IMPORTING
      SALESDOCUMENT_EX = L_VBELN
    TABLES
      RETURN           = LI_RETURN.

    IF L_VBELN IS NOT INITIAL.

   CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      WAIT = 'X'.

     endif.

Regards,

Srikanth.

5 REPLIES 5
Read only

Former Member
0 Likes
986

Hi Srikant,

Can you please chek the data being passed to the BAPI after 1st iteration.

There could be a possibility that as you have not cleared the variables the same data is being passed again.

Kindly check and revert back.

Regards,

Amit

Read only

0 Likes
986

Hi Amit,

I have checked the values in runtime, i am passing different contract numbers.

Regards,

Srikanth.

Read only

0 Likes
986

HI Srikant,

Can you please share the code which you are using , i mean show us the loop.

Regards,

Amit

Read only

0 Likes
986

Hi Amit,

Here is the code.

loop ay i_vbak into wa_vbak.

   Create DMR by copying the contract.
  CALL FUNCTION 'BAPI_SALESDOCUMENT_COPY'
    EXPORTING
      SALESDOCUMENT    = WA_VBAK-VBELN
      DOCUMENTTYPE     = 'ZIRS'
*      TESTRUN          = ' '
    IMPORTING
      SALESDOCUMENT_EX = L_VBELN
    TABLES
      RETURN           = LI_RETURN.

    CLEAR :li_return, wa_vbak,l_vbeln.
  REFRESH : LI_RETURN,

endloop.

Read only

0 Likes
986

Hi Srikant,

You are hardcoding the Doctype as 'ZIRS'.

We need to check whether this doc type is valid for all the sales order or not.

Can you please chek this FM SD_SALES_DOCUMENT_COPY.

and check the value of  da_vbakkom and sy-subrc.

If sy-subrc is Zero , then only this document can be copied else not.

Please try and revert back.

Regards,

Amit