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 - RV_INVOICE_CREATE_RFC

andrewscott9
Participant
0 Likes
2,715


Hi there,

Has anyone used the BAPI      RV_INVOICE_CREATE_RFC  ??

I have written a piece of ABAP which calls the above BAPI. It seems to work

intermittently for some bizarre reason.

I can run it first thing in the morning and the invoice gets created. If I then

run it again straight away noting gets created.

If I wait an hour or so and run it again it will work !!!

Has anyone had any strange behaviour with this BAPI or would know why

it is only working  intermittently ??

Seems very odd

Many thanks

Andy

1 ACCEPTED SOLUTION
Read only

former_member185054
Active Participant
0 Likes
2,428

hi Andy,

     may i know why you use the bapi-RV_INVOICE_CREATE_RFC, i have used RV_INVOICE_CREATE. it wont trigger this problem.

With regards,

sampath kumar.

16 REPLIES 16
Read only

andrewscott9
Participant
0 Likes
2,428

It seems when I run this in debugger it works every time !!!!

When I run it without debugger it doesn't work at all .

Any suggestions?

Read only

0 Likes
2,428

Hi Andy Scott

Try WAIT command after BAPI posting.

Looks like you it works fine in debugger because it gets enough time due to manual intervention which is not the case when you run the report straight away.

Regards,

NG

Read only

0 Likes
2,428

Hi Nikhil,

Many thanks for your reply.

I have tried both:

WAIT UNTIL sy-subrc = 0.

COMMIT WORK AND WAIT.

But it is the same i.e. invoice not being posted

Thanks

Andy

Read only

0 Likes
2,428

Hi Andy,

How you are calling the BAPI? You are calling inside a loop in Report? Or it is always called once?  Or it is called from external system directly?

Read only

0 Likes
2,428

Hi Rudra,

I am just calling the FM once within a stand-a-lone piece of ABAP

Thanks

Andy

Read only

0 Likes
2,428

Hi Andy,

Then the COMMIT WORK should be good enough. Make sure you are not hitting any error in background. Look for update termination via transaction SM13.

R

Read only

0 Likes
2,428

Hi Andy Scott,

Try BAPI_TRANSACTION_COMMIT instead of COMMIT WORK. And check If your problem still persists. Let me know.


Regards,

NG

Read only

0 Likes
2,428

Hi mate,

Now using:

   

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

After the FM call.

This is so frustrating. Like I said previously when I run in debugger

it all works perfectly fine.

Andy

Read only

0 Likes
2,428

Hi Andy,

Where are you calling BAPI_TRANSACTION_COMMIT?

Inside the FM or inside your report (after FM call)?


Nikhil.

Read only

0 Likes
2,428

Hi,

Inside my report after the FM call

Read only

0 Likes
2,428

Hi Andy,

Try calling BAPI_TRANSACTION_COMMIT Inside the FM right after RV_INVOICE_CREATE_RFC ?


Read only

former_member185054
Active Participant
0 Likes
2,429

hi Andy,

     may i know why you use the bapi-RV_INVOICE_CREATE_RFC, i have used RV_INVOICE_CREATE. it wont trigger this problem.

With regards,

sampath kumar.

Read only

0 Likes
2,428

Hi Sampath,

So you used  RV_INVOICE_CREATE and it worked ??   i.e. without the RFC

I may just amend my code to use that and see what happens?


thanks

Andy

Read only

former_member185054
Active Participant
0 Likes
2,428

if your problem not solved post your code here..

regards,

sampath kumar.

Read only

0 Likes
2,428

Hi Sampath here we go:

REPORT zhrr080.


DATA : wa_bapisdhead       TYPE bapisdhead.                    " Order Header Details
DATA: lv_doc_number        TYPE bapivbeln-vbeln.               " Document Number Returned

DATA: it_order_items_in TYPE STANDARD TABLE OF bapiitemin,  " List of items
      wa_order_items_in TYPE bapiitemin,

      it_order_partners TYPE STANDARD TABLE OF bapipartnr,  " Sold To and Ship to Party
      wa_order_partners TYPE bapipartnr,

*      it_billing_data_in   TYPE STANDARD TABLE OF bapivbrk,
*      wa_billing_data_in   TYPE bapivbrk,

*      it_condition_data_in TYPE STANDARD TABLE OF bapikomv,
*      wa_condition_data_in TYPE bapikomv,

*      it_bapiccard_vf      TYPE STANDARD TABLE OF bapiccard_vf,
*      wa_bapiccard_vf      TYPE bapiccard_vf,

*      it_bapireturn1       TYPE STANDARD TABLE OF bapireturn1,
*      wa_return1           TYPE bapireturn1,

      it_success        TYPE STANDARD TABLE OF bapivbrksuccess.

DATA : wa_return           TYPE bapireturn1.


PARAMETERS: pa_cust        LIKE kna1-kunnr.


*
*-------------------------------------------------------------------*
* KNA1
* -------------------------------------------------------------------*
*
*
*BAPIAD1VL-EXTENS_1

START-OF-SELECTION.

  PERFORM create_billing_document.
  RETURN.

FORM create_billing_document.
*

  wa_bapisdhead-doc_type     = 'ZCM'.
  wa_bapisdhead-sales_org    = '0001'.
  wa_bapisdhead-distr_chan   = '01'.
  wa_bapisdhead-division     = '01'.
  wa_bapisdhead-pmnttrms     = 'PREP'.
  wa_bapisdhead-bill_block   = '14'.
  wa_bapisdhead-ord_reason   = 'O01'.


* Only ever two rows Sold To and Ship To Party
  CLEAR it_order_partners.
  wa_order_partners-partn_role = 'WE'.        " Ship to Party
  wa_order_partners-partn_numb = pa_cust.
  APPEND wa_order_partners TO it_order_partners.

  wa_order_partners-partn_role = 'AG'.        " Sold to Party
  wa_order_partners-partn_numb = pa_cust.
  APPEND wa_order_partners TO it_order_partners.


*    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
*      EXPORTING
*        input  = wa_t510_grd-trfst
*      IMPORTING
*        output = wa_t510_grd-trfst.


*======================== Set up loop for items around ZCRM_ITEM_DETIALS
  wa_order_items_in-itm_number = '01'.
  wa_order_items_in-material   = '000000000000002604'.
  wa_order_items_in-target_qty = '1.000'.
  wa_order_items_in-req_qty    = '1.000'.
  APPEND wa_order_items_in TO it_order_items_in.

  wa_order_items_in-itm_number = '02'.
  wa_order_items_in-material   = '000000000000002604'.
  wa_order_items_in-target_qty = '1.000'.
  wa_order_items_in-req_qty    = '1.000'.
  APPEND wa_order_items_in TO it_order_items_in.
*======================== Set up loop for items


  CALL FUNCTION 'BAPI_SALESDOCU_CREATEFROMDATA'
    EXPORTING
      order_header_in = wa_bapisdhead
      business_object = 'BUS2096'
    IMPORTING
      salesdocument   = lv_doc_number
      return          = wa_return
    TABLES
      order_items_in  = it_order_items_in
      order_partners  = it_order_partners.
*
  IF sy-subrc = 0.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = ''.
  ENDIF.


*set UPDATE TASK LOCAL.

**  CALL FUNCTION 'RV_INVOICE_CREATE_RFC' IN BACKGROUND TASK
*  CALL FUNCTION 'RV_INVOICE_CREATE_RFC'
*    EXPORTING
*      i_refdoc  = lv_doc_number
*      i_reftype = 'L'
*      i_blart   = 'RV'.

  DATA: lt_komfk TYPE TABLE OF komfk.
  DATA: ls_komfk TYPE komfk.
  DATA: ls_vbsk TYPE vbsk.
  DATA:
    lt_xkomv  TYPE TABLE OF komv,
    lt_xthead TYPE TABLE OF theadvb,
    lt_xvbfs  TYPE TABLE OF vbfs,
    lt_xvbpa  TYPE TABLE OF vbpavb,
    lt_xvbrk  TYPE vbrkvb_t,
    lt_xvbrp  TYPE vbrpvb_t,
    lt_xvbss  TYPE vbss_t.

  ls_komfk-vbeln = lv_doc_number.
  ls_komfk-vbtyp = 'L'.
  APPEND ls_komfk TO lt_komfk.

  CALL FUNCTION 'RV_INVOICE_CREATE'
    EXPORTING
*     DELIVERY_DATE             = 0
*     INVOICE_DATE = 0
*     INVOICE_TYPE = '    '
*     PRICING_DATE = 0
      vbsk_i       = ls_vbsk
      with_posting = 'B'
*     SELECT_DATE  = 0
*     I_NO_VBLOG   = ' '
*     I_ANALYZE_MODE            = ' '
*     ID_UTASY     = ' '
*     ID_UTSWL     = ' '
*     ID_UTSNL     = ' '
*     ID_NO_ENQUEUE             = ' '
*     ID_NEW_CANCELLATION       = ' '
      i_blart      = 'RV'
    IMPORTING
      vbsk_e       = ls_vbsk
*     OD_BAD_DATA  =
*     DET_REBATE   =
    TABLES
      xkomfk       = lt_komfk
      xkomv        = lt_xkomv
      xthead       = lt_xthead
      xvbfs        = lt_xvbfs
      xvbpa        = lt_xvbpa
      xvbrk        = lt_xvbrk
      xvbrp        = lt_xvbrp
      xvbss        = lt_xvbss
*     XKOMFKaGN     =
*     XKOMFKKO     =
    .

COMMIT WORK AND WAIT.

*WAIT UNTIL sy-subrc = 0.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = 'X'.


  COMMIT WORK.

ENDFORM.

Read only

0 Likes
2,428

hi scott,

after calling RV_INVOICE_CREATE,


if sy-subrc ne'E'.


CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    EXPORTING

      wait = 'X'.


else.


(throw some message...)


endif.




also check XVBFS table in (RV_INVOICE_CREATE function module)as this contains error log...


this is way it should work...