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

need sample code with RV_INVOICE_CREATE used

Former Member
0 Likes
8,073

Hi everybody!

I need sample code with RV_INVOICE_CREATE or similar FMs used.

The thing is that I do not know how to populate parametres of this and other invoicing FMs....

For example, there are some tables to be passed to RV_INVOICE_CREATE

TABLES

XKOMFK = XKOMFK

XKOMV = XKOMV

XTHEAD = XTHEAD

XVBFS = XVBFS

XVBPA = XVBPA

XVBRK = XVBRK

XVBRP = XVBRP

XVBSS = XVBSS

How to populate them? I mean how to fill them with needed values?

Useful answers will be awarded.

Kind regards, M.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
4,775

DATA: VBSK_I LIKE VBSK.

data: d_success type c.

DATA: XKOMFK LIKE KOMFK OCCURS 0 WITH HEADER LINE,

XKOMV LIKE KOMV OCCURS 0 WITH HEADER LINE,

XTHEAD LIKE THEADVB OCCURS 0 WITH HEADER LINE,

XVBFS LIKE VBFS OCCURS 0 WITH HEADER LINE,

XVBPA LIKE VBPAVB OCCURS 0 WITH HEADER LINE,

XVBRK LIKE VBRKVB OCCURS 0 WITH HEADER LINE,

XVBRP LIKE VBRPVB OCCURS 0 WITH HEADER LINE,

XVBSS LIKE VBSS OCCURS 0 WITH HEADER LINE,

XKOMFKGN LIKE KOMFKGN OCCURS 0 WITH HEADER LINE.

refresh: XKOMFK, XKOMV,

XTHEAD, XVBFS,

XVBPA, XVBRK,

XVBRP, XVBSS.

clear : XKOMFK, XKOMV,

XTHEAD, XVBFS,

XVBPA, XVBRK,

XVBRP, XVBSS,

VBSK_I.

VBSK_I-SMART = 'F'.

XKOMFK-VBELN = v_deliv.

XKOMFK-VBTYP = 'J'.

APPEND XKOMFK.

CALL FUNCTION 'RV_INVOICE_CREATE'

EXPORTING

VBSK_I = VBSK_I

WITH_POSTING = 'C'

TABLES

XKOMFK = XKOMFK

XKOMV = XKOMV

XTHEAD = XTHEAD

XVBFS = XVBFS

XVBPA = XVBPA

XVBRK = XVBRK

XVBRP = XVBRP

XVBSS = XVBSS.

if sy-subrc eq 0.

COMMIT WORK.

flag = 'X'.

else.

message i011 with p_vbeln.

endif.

7 REPLIES 7
Read only

suresh_datti
Active Contributor
0 Likes
4,775

Have you checked the Std Report RV56FAKT?

~Suresh

Read only

Former Member
0 Likes
4,776

DATA: VBSK_I LIKE VBSK.

data: d_success type c.

DATA: XKOMFK LIKE KOMFK OCCURS 0 WITH HEADER LINE,

XKOMV LIKE KOMV OCCURS 0 WITH HEADER LINE,

XTHEAD LIKE THEADVB OCCURS 0 WITH HEADER LINE,

XVBFS LIKE VBFS OCCURS 0 WITH HEADER LINE,

XVBPA LIKE VBPAVB OCCURS 0 WITH HEADER LINE,

XVBRK LIKE VBRKVB OCCURS 0 WITH HEADER LINE,

XVBRP LIKE VBRPVB OCCURS 0 WITH HEADER LINE,

XVBSS LIKE VBSS OCCURS 0 WITH HEADER LINE,

XKOMFKGN LIKE KOMFKGN OCCURS 0 WITH HEADER LINE.

refresh: XKOMFK, XKOMV,

XTHEAD, XVBFS,

XVBPA, XVBRK,

XVBRP, XVBSS.

clear : XKOMFK, XKOMV,

XTHEAD, XVBFS,

XVBPA, XVBRK,

XVBRP, XVBSS,

VBSK_I.

VBSK_I-SMART = 'F'.

XKOMFK-VBELN = v_deliv.

XKOMFK-VBTYP = 'J'.

APPEND XKOMFK.

CALL FUNCTION 'RV_INVOICE_CREATE'

EXPORTING

VBSK_I = VBSK_I

WITH_POSTING = 'C'

TABLES

XKOMFK = XKOMFK

XKOMV = XKOMV

XTHEAD = XTHEAD

XVBFS = XVBFS

XVBPA = XVBPA

XVBRK = XVBRK

XVBRP = XVBRP

XVBSS = XVBSS.

if sy-subrc eq 0.

COMMIT WORK.

flag = 'X'.

else.

message i011 with p_vbeln.

endif.

Read only

0 Likes
4,775

Hi Seshu!

thanks for your help. Maybe you have some more code with 'RV_INVOICE_CREATE'?

I mean it is good to know how to define tables to be passed to FM, but as well would be nice to know how to populate them and the meaning of important fields...

I mean, for example: what are the important parametres (like price) to be sent to FM?

And what is the tcode to see the result of 'RV_INVOICE_CREATE'?

Kind regards,

Mindaugas.

Read only

0 Likes
4,775

RV_INVOICE_CREATE is the function module to create invoice based on delivery .

when you pass delivery number ,it will create invoice ,see the invoice number in vf02,vf03 transaction. and also see the data vbrk,vbrp tables

I have done this development and i have cancelled invoice,reverse goods issue,updated the delivery and again i am createing invoice..see the below progrm to get better understanding.

REPORT ZWM_OVERWEIGHT_FIX no standard page heading

message-id zwm.

======================================================================

  • *

  • Program Name : ZWM_OVERWEIGHT_FIX *

  • *

  • Description : Tool to fix Overweight in delivery line item, *

  • Used All Function module to cancel invoice , *

  • Reverse the goods issue ,Update Delivery qty,Create *

  • invoice *

  • *

  • Author : Seshu *

  • Date : 05/08/2007 *

  • *

----


  • MODIFICATION HISTORY *

----


  • DATE | AUTHOR | CHANGE # | DESCRIPTION OF MODIFICATION *

--


|
|

|
--

  • 05/08/07| Seshu | DEVK921979 | Initial *

************************************************************************

************************************************************************

                              • D A T A - D E C L A R A T I O N *******************

************************************************************************

  • Tables

Tables : vbak,

vbap,

vbfa,

likp,

lips,

vbrk,

vbrp.

  • Internal Tables

data : i_lips like lips occurs 0 with header line,

i_vbap like vbap occurs 0 with header line.

  • Variables

data : v_deliv like vbfa-vbelv,

v_invoic like vbfa-vbelv.

  • Data Declaration Part for Post Goods Issue

DATA: l_vbeln LIKE likp-vbeln,

l_vbkok LIKE vbkok,

i_prot LIKE prott OCCURS 0 WITH HEADER LINE,

ef_error_any_0 TYPE c,

ef_error_in_item_deletion_0 TYPE c,

ef_error_in_pod_update_0 TYPE c,

ef_error_in_interface_0 TYPE c,

ef_error_in_goods_issue_0 TYPE c,

ef_error_in_final_check_0 TYPE c,

d_return LIKE bapireturn1.

  • Internal tables for BAPI Function Module

data : i_cret like BAPIRETURN1 occurs 0 with header line,

i_csucess like BAPIVBRKSUCcESS occurs 0 with header line,

i_ret2 like bapiret2 ,

flag type c,

i_mesg like mesg occurs 0 with header line.

  • Data Declaration for Invoice Creation

DATA: VBSK_I LIKE VBSK.

data: d_success type c.

DATA: XKOMFK LIKE KOMFK OCCURS 0 WITH HEADER LINE,

XKOMV LIKE KOMV OCCURS 0 WITH HEADER LINE,

XTHEAD LIKE THEADVB OCCURS 0 WITH HEADER LINE,

XVBFS LIKE VBFS OCCURS 0 WITH HEADER LINE,

XVBPA LIKE VBPAVB OCCURS 0 WITH HEADER LINE,

XVBRK LIKE VBRKVB OCCURS 0 WITH HEADER LINE,

XVBRP LIKE VBRPVB OCCURS 0 WITH HEADER LINE,

XVBSS LIKE VBSS OCCURS 0 WITH HEADER LINE,

XKOMFKGN LIKE KOMFKGN OCCURS 0 WITH HEADER LINE.

************************************************************************

                              • S E L E C T I O N - S C R E E N ******************

************************************************************************

  • Selection-screen

Selection-screen : begin of block blk with frame title text-001.

parameters : p_vbeln like vbak-vbeln obligatory.

selection-screen : end of block blk.

************************************************************************

                              • A T - S E L E C T I O N - S C R E E N ***************

************************************************************************

  • Validation on Sales order

at selection-screen on p_vbeln.

  • Check the data on VBAK Table

select single vbeln from vbak into vbak-vbeln

where vbeln = p_vbeln.

if sy-subrc ne 0.

message e006 with p_vbeln.

endif.

************************************************************************

                              • S T A R T - O F - S E L E C T I O N *******************

************************************************************************

Start-of-selection.

break sreddy.

  • Get the Invoice Number corresponding Sales Order Number

perform get_invoice.

  • Step 1.

  • Cancel the Invoice - Transaction VF11

perform cancel_invoice.

  • Reverse the goods issue

perform reverse_goodsissue.

  • Get the Order and Delivery Items

perform get_sales_deliv.

  • Delivery Change

perform Delivery_change.

  • Create Invoice document

perform invoice_create.

************************************************************************

                              • E N D - O F - S E L E C T I O N *******************

************************************************************************

end-of-selection.

if flag = 'X'.

message i012 with p_vbeln.

endif.

&----


*& Form get_invoice

&----


  • Get Invoice Number

----


FORM get_invoice.

  • Clear Variables

clear : v_deliv,

v_invoic,

flag.

  • Get the Delivery Number First

select single vbeln from vbfa into v_deliv

where vbelv = p_vbeln

and vbtyp_n = 'J'.

if sy-subrc ne 0.

message i004 with p_vbeln.

stop.

endif.

  • Get the Invoice Number

select single vbeln from vbfa into v_invoic

where vbelv = p_vbeln

and vbtyp_n = 'M'.

if sy-subrc ne 0.

message i003 with p_vbeln.

stop.

endif.

ENDFORM. " get_invoice

&----


*& Form cancel_invoice

&----


  • Cancel the Invoice

----


FORM cancel_invoice.

clear : i_ret2,

i_cret,

i_csucess.

refresh : i_cret,

i_csucess.

CALL FUNCTION 'BAPI_BILLINGDOC_CANCEL1'

EXPORTING

BILLINGDOCUMENT = v_invoic

  • TESTRUN =

  • NO_COMMIT =

  • BILLINGDATE =

TABLES

RETURN = i_cret

SUCCESS = i_csucess

.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = space

IMPORTING

RETURN = i_ret2.

  • read table i_cret with key type = 'E'.

if sy-subrc ne 0.

message i005 with v_invoic.

stop.

endif.

ENDFORM. " cancel_invoice

&----


*& Form reverse_goodsissue

&----


  • Reverse the goods Issue

----


FORM reverse_goodsissue.

  • Local Variable

data : lv_vbtyp like likp-vbtyp.

clear : i_mesg,

lv_vbtyp.

refresh : i_mesg.

select single vbtyp from likp into lv_vbtyp

where vbeln = v_deliv.

CALL FUNCTION 'WS_REVERSE_GOODS_ISSUE'

EXPORTING

I_VBELN = v_deliv

I_BUDAT = sy-datum

  • I_COUNT =

  • I_MBLNR =

  • I_TCODE =

I_VBTYP = lv_vbtyp

TABLES

T_MESG = i_mesg

EXCEPTIONS

ERROR_REVERSE_GOODS_ISSUE = 1

OTHERS = 2

.

if sy-subrc ne 0.

message i007 with v_deliv.

endif.

ENDFORM. " reverse_goodsissue

&----


*& Form get_sales_deliv

&----


  • Get the Sales order and Deliv Items

----


FORM get_sales_deliv.

  • Local Variables

data : lv_kwmeng like vbap-kwmeng.

clear : i_lips,

i_vbap.

refresh : i_lips,

i_vbap.

  • Select the data from LIPS

select * from lips into table i_lips

where vbeln = v_deliv.

if sy-subrc ne 0.

message i008 with v_deliv.

stop.

endif.

sort i_lips by vbeln posnr.

  • Get the Sales order Item Data.

select * from vbap into table i_vbap

where vbeln = p_vbeln.

if sy-subrc ne 0.

message i006 with p_vbeln.

stop.

endif.

sort i_vbap by vbeln posnr.

  • Compare delivery Item and Order Items

loop at i_lips.

clear lv_kwmeng.

read table i_vbap with key posnr = i_lips-posnr.

if sy-subrc eq 0.

lv_kwmeng = i_vbap-kwmeng * 2.

if lv_kwmeng >= i_lips-lfimg.

i_lips-lfimg = i_vbap-kwmeng.

modify i_lips.

endif.

endif.

endloop.

ENDFORM. " get_sales_deliv

&----


*& Form Delivery_change

&----


  • Delivery Update

----


FORM Delivery_change.

Clear : i_prot.

refresh : i_prot.

  • Delivery Update

CALL FUNCTION 'LE_MOB_DELIVERY_UPDATE'

EXPORTING

do_commit = 'X'

TABLES

t_delivery_items = i_lips

prot = i_prot

EXCEPTIONS

conversion_overflow = 1

essential_data_missing = 2

error = 3

nothing_to_update = 4

lock_after_update_failed = 5

error_in_delivery_update = 6

OTHERS = 7.

COMMIT WORK.

IF sy-subrc <> 0.

MESSAGE i009 with v_deliv.

endif.

  • Post Goods Issue

CLEAR: d_return,

i_prot,

l_vbeln,

l_vbkok.

REFRESH i_prot.

CLEAR: ef_error_in_item_deletion_0 ,

ef_error_in_pod_update_0 ,

ef_error_in_interface_0 ,

ef_error_in_goods_issue_0 ,

ef_error_in_final_check_0 .

  • carry out goods issue

l_vbeln = v_deliv.

l_vbkok-vbeln_vl = l_vbeln.

l_vbkok-wabuc = 'X'.

  • carry out goods issue

l_vbeln = v_deliv.

l_vbkok-vbeln_vl = l_vbeln.

l_vbkok-wabuc = 'X'.

  • SET UPDATE TASK LOCAL.

CALL FUNCTION 'WS_DELIVERY_UPDATE'

EXPORTING

vbkok_wa = l_vbkok

synchron = 'X'

no_messages_update = ' '

update_picking = 'X'

commit = 'X'

delivery = l_vbeln

nicht_sperren = 'X'

if_error_messages_send_0 = space

IMPORTING

ef_error_any_0 = ef_error_any_0

ef_error_in_item_deletion_0 = ef_error_in_item_deletion_0

ef_error_in_pod_update_0 = ef_error_in_pod_update_0

ef_error_in_interface_0 = ef_error_in_interface_0

ef_error_in_goods_issue_0 = ef_error_in_goods_issue_0

ef_error_in_final_check_0 = ef_error_in_final_check_0

TABLES

prot = i_prot

EXCEPTIONS

error_message = 1

OTHERS = 2.

if sy-subrc ne 0.

message i010 with v_deliv.

else.

COMMIT WORK .

endif.

ENDFORM. " Delivery_change

&----


*& Form invoice_create

&----


  • Invoice Creation

----


FORM invoice_create.

refresh: XKOMFK, XKOMV,

XTHEAD, XVBFS,

XVBPA, XVBRK,

XVBRP, XVBSS.

clear : XKOMFK, XKOMV,

XTHEAD, XVBFS,

XVBPA, XVBRK,

XVBRP, XVBSS,

VBSK_I.

VBSK_I-SMART = 'F'.

XKOMFK-VBELN = v_deliv.

XKOMFK-VBTYP = 'J'.

APPEND XKOMFK.

CALL FUNCTION 'RV_INVOICE_CREATE'

EXPORTING

VBSK_I = VBSK_I

WITH_POSTING = 'C'

TABLES

XKOMFK = XKOMFK

XKOMV = XKOMV

XTHEAD = XTHEAD

XVBFS = XVBFS

XVBPA = XVBPA

XVBRK = XVBRK

XVBRP = XVBRP

XVBSS = XVBSS.

if sy-subrc eq 0.

COMMIT WORK.

flag = 'X'.

else.

message i011 with p_vbeln.

endif.

ENDFORM. " invoice_create

Reward Points if it is helpful

Thanks

Seshu

Read only

0 Likes
4,775

Seshu,

so if I have a delivery number (vbeln?) I can create an invoice,

but I need just difference of the price on the invoice, because I need just debit / credit invoice, so I think it is needed to pass some value of price to the FM, sorry if I am wrong..

BR, M.

Read only

0 Likes
4,775

I am not sure but it should work.

Read only

petra_just
Active Participant
4,775

thank you for your sample coding. I found it useful and managed to post invoices for several deliveries by changing it slightly. Just for any future users:

WITH_POSTING = 'C' means that it posts without error messages. To get the error messages, you can use 'D'.

Petra