Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 8419

Detailing Function Module RV_INVOICE_CREATE

$
0
0

The main objective of this document is to explain in detail what goes on inside function module RV_INVOICE_CREATE.

This is one of the most important function modules in SD Billing.

Hopefully this will help you to find out where an issue is being originated.


1. Function RV_INVOICE_CREATE


rvinvoice.JPG


During invoice creation by transactions VF01, VF04 or VF11 the system will always call the function module RV_INVOICE_CREATE.

 

In general, to find out how a field is filled this is what you need to do:

 

  1. set a breakpoint at the begin of function RV_INVOICE_CREATE;
  2. run the transaction;
  3. set a watchpoint on that particular field.

 

This is how the code works:

 

Function RV_INVOICE_CREATE

...

  Fakturen erzeugen

  LOOP AT xkomfk.                         ---> Loop at the sales documents to be billed

    ...

    PERFORM faktura_erzeugen.       ---> Create the billing items and billing header(s)

...

 

1.1 FAKTURA_ERZEUGEN


If we take a look into the form FAKTURA_ERZEUGEN in include LV60AA26, this is what happens:

 

faktura.JPG

 

FORM FAKTURA_ERZEUGEN.

...

IF XKOMFK-VBTYP CA VBTYP_LIEF.

    PERFORM FAKTURA_LIEFERBEZOGEN.       ---> 1.1.1 Delivery related billing

    EXIT.

  ENDIF.

 

  IF XKOMFK-VBTYP CA VBTYP_FAKT.

    PERFORM FAKTURA_FAKTURABEZOGEN.    ---> 1.1.2 Invoice related billing

    EXIT.

  ENDIF.

 

  PERFORM FAKTURA_AUFTRAGSBEZOGEN.    ---> 1.1.3 Order related billing

 


1.1.1 FAKTURA_LIEFERBEZOGEN (Delivery related billing)

 

Now if we go into FAKTURA_LIEFERBEZOGEN in include LV60AA22, for delivery related billing, this is what happens:

 

liefer.JPG

 

form faktura_lieferbezogen.

...

* Prüfen Bedingungen lt. TVCPF

  if *tvcpf-grbed ne 0.

    bedmodul-nr = *tvcpf-grbed.

    perform (bedmodul) in program saplv60a.        ---> Header copy-requirement routine

...

  loop at alips.                                                  ---> Loop at the delivery items

...

* Lieferung/Lieferposition ohne Referenzauftrag

      perform fakturaposi_lieferbezogen_o_ap.       ---> 1.1.1.2 Delivery without reference

    else.

* Lieferposition mit Referenzauftrag

      perform fakturaposi_lieferbezogen.                ---> 1.1.1.1 Delivery with reference

    endif.

  endloop.

 

 

1.1.1.1 FAKTURAPOSI_LIEFERBEZOGEN (Delivery with reference)

 

Now if we go into the form fakturaposi_lieferbezogen in include LV60AA21, for a delivery with reference, this is what happens:


lieferbe.JPG

 

FORM fakturaposi_lieferbezogen.

...

  perform vbrk_vbrp_fuellen.                           ---> Some VBRP and VBRK fields are filled

  perform fakturadaten_lieferbezogen.             ---> Some VBRP and VBRK fields are filled

...

  if tvcpf-grbed ne 0.

    bedmodul-nr = tvcpf-grbed.

    perform (bedmodul) in program saplv60a.    ---> Copy-requirement routine at item-level

...

  perform vbrk_vbrp_datentransport using rc.    ---> Further data is filled in VBRP and VBRK, perform copy-transfer routine

...

  perform xvbrk_bearbeiten.                            ---> VBRK is set to XVBRK and if there is a split a new XVBRK record is created

...

  xvbrp = vbrp.                                               ---> VBRP is copied into the header line of internal table XVBRP

...

  call function 'PRICING_COPY‘                      ---> Execution of PRICING_COPY

...

  perform preisfindung using tvcpf-knprs.          ---> Executes function PRICING

...

  perform xvbrp_hinzufuegen.                          ---> The new XVBRP line is added to internal table

...

  perform vbfa_fuellen using likp-vbeln lips-posnr likp-vbtyp.

  call function 'RV_XVBFA_MAINTAIN‘             ---> Adjust document flow internal table XVBFA

  ...

  call function 'LIPS_STATUS_MAINTAIN‘         ---> Adjust the billing status of the delivery

 


1.1.1.2 FAKTURAPOSI_LIEFERBEZOGEN_O_AP (Delivery without reference)

 

The form fakturaposi_lieferbezogen_o_ap, for a delivery without reference, is in include LV60AA20. It is very similar to form fakturaposi_lieferbezogen just detailed above. The difference is that since there is no sales order, in this form the system will simulate VBAP and VBAK. Then it will perform the same forms as fakturaposi_lieferbezogen.

 

 

1.1.2 FAKTURA_FAKTURABEZOGEN (Invoice related billing)

 

The form FAKTURA_FAKTURABEZOGEN is for invoice related billing. It is found in include LV60AA25.

 

fakturabe.JPG

 

FORM FAKTURA_FAKTURABEZOGEN.

...

CALL FUNCTION 'RV_INVOICE_DOCUMENT_READ‘              ---> Read the reference billing document

...

  IF XFKART = SPACE.

    PERFORM STORNO_ERZEUGEN.               

  ELSE.

    SELECT SINGLE * FROM TVFK INTO *TVFK WHERE FKART = *VBRK-FKART.

    IF SY-SUBRC = 0.

      IF *TVFK-FKARTS = XFKART.

        PERFORM STORNO_ERZEUGEN.                                 ---> During VF11 the system performs STORNO_ERZEUGEN

      ELSE.

        PERFORM FAKTURA_AUS_FAKTURA_ERZEUGEN.      ---> 1.1.2.1 Otherwise, perform billing-related invoicing

 


1.1.2.1 FAKTURA_AUS_FAKTURA_ERZEUGEN

 

Let's have a look into form FAKTURA_AUS_FAKTURA_ERZEUGEN in include LV60AD08 and what goes on in here.

 

fakausfak.JPG

 

FORM FAKTURA_AUS_FAKTURA_ERZEUGEN.

...

* Prüfen Bedingungen lt. TVCPF

  IF *TVCPF-GRBED NE 0.

    BEDMODUL-NR = *TVCPF-GRBED.

    PERFORM (BEDMODUL) IN PROGRAM SAPLV60A.       ---> Perform header copy-requirement routine

 

...

  LOOP AT XVBRP WHERE VBELN = XKOMFK-VBELN.      ---> Loop at the billing items

    ...

    *VBRP = XVBRP.                                                           ---> From now on *VBRP contains the data of the referenced billing item

    PERFORM FAKTURAPOSI_FAKTURABEZOGEN.            ---> Process billing item

  ENDLOOP.

 

 

1.1.3 FAKTURA_AUFTRAGSBEZOGEN (Order related billing)

 

We have already detailed how form FAKTURA_LIEFERBEZOGEN in include LV60AA22, for delivery related billing, works.

Now let's have a look at form FAKTURA_AUFTRAGSBEZOGEN in include LV60AA30, for order related billing.

 

auftrags.JPG

 

FORM faktura_auftragsbezogen.

...

* Prüfen Bedingungen lt. TVCPF

  if *tvcpf-grbed ne 0.

    bedmodul-nr = *tvcpf-grbed.

    perform (bedmodul) in program saplv60a.                         ---> Perform header copy-requirement routine

...

  loop at avbap where fkrel ne con_fkrel_fpl                           ---> Loop at the order item without billing plan

    ...

    perform fakturaposi_auftragsbezogen using da_subrc.       ---> Process order item

    ...

  endloop.

...

  loop at avbkd where fplnr ne space

                and   posnr ne posnr_low.                                   ---> Loop at the order item with billing plan

    do.

*     Lesen der Fakturierungsplanpositionen

      read table xfplt index da_index.                                     ---> Loop at lines in the item billing plan

      ...

      perform fakturaposi_auftragsbezogen using da_subrc.     ---> 1.1.3.1 Process order item

      ...          

    enddo.

 

  endloop.

 

endform.                    "FAKTURA_AUFTRAGSBEZOGEN

 

 

1.1.3.1 FAKTURAPOSI_AUFTRAGSBEZOGEN

 

Let's take a look into form fakturaposi_auftragsbezogen in include LV60AA29 now.

 

auftrags2.JPG

 

FORM fakturaposi_auftragsbezogen

...

  perform vbrk_vbrp_fuellen.                            ---> VBRP and VBRK are filled

  perform fakturadaten_auftragbezogen.           ---> VBRP and VBRK are filled

...

  if tvcpf-grbed ne 0.

    bedmodul-nr = tvcpf-grbed.

    perform (bedmodul) in program saplv60a.     ---> Copy-requirement routine at item level

...

  perform vbrk_vbrp_datentransport using rc.     ---> Further data filled in VBRP and VBRK, copy-transfer routine performed

...

  perform xvbrk_bearbeiten.                             ---> VBRK is set to XVBRK and if there is a split a new XVBRK record is added

...

  xvbrp = vbrp.                                                ---> VBRP is copied into the header line of internal table XVBRP

...

  call function 'PRICING_COPY‘                       ---> Execution of PRICING_COPY

...

  perform preisfindung using tvcpf-knprs.           ---> Executes function PRICING

...

  perform xvbrp_hinzufuegen.                           ---> The new XVBRP line is added to the internal table

...

  perform vbfa_fuellen using vbak-vbeln vbap-posnr vbak-vbtyp.

  call function 'RV_XVBFA_MAINTAIN‘             ---> Adjust document flow internal table XVBFA

...

  call function 'RV_XVBUP_MAINTAIN_FKGSA ‘     ---> Adjust the billing status of the order

 

 

 

1.2 Message Handling

 

During invoice creation the messages are not issued directly to the user by means of Message ABAP statement.

Instead they are stored in the internal table XVBFS.

 

To catch a message, set a breakpoint at the begin of function RV_INVOICE_CREATE and then set a watchpoint on field XVBFS-MSGNO.

 

 

For other important function modules in SD Billing please check:

 


Viewing all articles
Browse latest Browse all 8419

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>