Retroactive Billing – VFRB Modification to add credit/debit line

JackWu發表於2018-10-26

Retro billing process is used to create price differences documents (credit / debit memo) after price changes in SAP.

For further : https://blogs.sap.com/2013/05/07/retro-billing-sd-vfrb/

OEM suppliers benefit from this program but some of them need some developments on it. In our client, standard program SDREBI02 is modified to add credit/debit line manually .

1- May i add manuel credit/debit line ? Because, OEM calculates different total amount but they balance this items with debit/credit lines.

Enhancement :

SDREBI02 is modified to add credit/debit line manually.

Form ‘create documents’ create debit/credit memo that’s why enhancement is located start of this form.

*&---------------------------------------------------------------------*
*&      Form  CREATE_DOCUMENTS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM create_documents.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(1) Form CREATE_DOCUMENTS, Start                                                                                                                      A
*$*$-Start: (1)---------------------------------------------------------------------------------$*$*
ENHANCEMENT 1  ZSDREBI02.    "active version
*BREAK OUNAL.
 DATA: popup_return  TYPE C,
       ivals         TYPE TABLE OF sval,
       xvals         TYPE sval,
       lv_netwr      TYPE netwr.

 IF sy-tcode = 'ZVFRB'.
  READ TABLE xkomfkgn_gs INDEX 1. "Credit check
  IF sy-subrc IS INITIAL.

    CALL FUNCTION 'POPUP_TO_CONFIRM'
    EXPORTING
    titlebar              = 'ADD CREDIT ITEM'
    text_question         = 'Will you add credit line?'
    text_button_1         = 'Yes'
    text_button_2         = 'No'
    default_button        = '2'
*    display_cancel_button = 'X'
    IMPORTING
    answer                = popup_return
    EXCEPTIONS
    text_not_found        = 1
    OTHERS                = 2.

    CASE popup_return.
       WHEN '1'.
*/ Fill out referance document number
        xvals-tabname   = 'VBRP'.
        xvals-fieldname = 'VGBEL'.
        APPEND xvals TO ivals.

        CALL FUNCTION 'POPUP_GET_VALUES'
            EXPORTING
              popup_title     = 'Referance Order Document Number ?'
            TABLES
              fields          = ivals
            EXCEPTIONS
              error_in_fields = 1
            OTHERS          = 2.

          READ TABLE ivals INTO xvals INDEX 1.
          CONDENSE xvals-value.
          IF sy-subrc  = 0 and xvals-value ne ''.
*/ Check order status !
           SELECT SINGLE * FROM vbak
             INTO @DATA(wa_vbak)
             WHERE vbeln = @xvals-value.
             IF sy-subrc IS INITIAL.
               SELECT SINGLE * FROM vbuk
                 INTO @DATA(wa_vbuk)
                 WHERE vbeln = @xvals-value.
             ENDIF.

           IF sy-subrc = 0 AND
            ( wa_vbak-faksk NE space OR "Block status
              wa_vbak-auart NE 'ZCR' OR "Order type
              wa_vbuk-fksak EQ 'C'   OR "Invoicing
              wa_vbuk-abstk EQ 'C'   OR "Order canceled
              wa_vbuk-uvals NE 'C' ).   "Incompleteness

            MESSAGE 'Check order, you can not invoice this referance'
             TYPE 'E'.
           ELSE.

*/ Add credit line !
            CLEAR xkomfkgn_gs.
            xkomfkgn_gs-mandt   = sy-mandt.
            xkomfkgn_gs-vgtyp   = 'C'.
            xkomfkgn_gs-vgbel   = xvals-value.
            xkomfkgn_gs-vgpos   = '000010'.
            xkomfkgn_gs-augru   = augru_gs.
            xkomfkgn_gs-shkzg   = 'H'.
            APPEND XKOMFKGN_GS.

            CLEAR xkomfkko_gs.
            xkomfkko_gs-mandt = sy-mandt.
            xkomfkko_gs-knumv = xvals-value.
            xkomfkko_gs-kposn = '000010'.
            xkomfkko_gs-kschl = 'PDIF'.
            SELECT SINGLE netwr
              FROM VBAK
              INTO lv_netwr
              WHERE vbeln = xvals-value.
             IF sy-subrc IS INITIAL AND lv_netwr GT 0.
               xkomfkko_gs-kbetr = lv_netwr.
             ENDIF.
            APPEND xkomfkko_gs.
           ENDIF.
          ENDIF.
      WHEN '2' OR 'A'.
    ENDCASE.
  ENDIF.
  READ TABLE xkomfkgn_ls INDEX 1. "Debit check
  IF sy-subrc IS INITIAL.

    CALL FUNCTION 'POPUP_TO_CONFIRM'
    EXPORTING
    titlebar              = 'ADD DEBIT ITEM'
    text_question         = 'Will you add debit line?'
    text_button_1         = 'Yes'
    text_button_2         = 'No'
    default_button        = '2'
*    display_cancel_button = 'X'
    IMPORTING
    answer                = popup_return
    EXCEPTIONS
    text_not_found        = 1
    OTHERS                = 2.

    CASE popup_return.
       WHEN '1'.
*/ Fill out referance document number
        CLEAR : xvals.
        REFRESH : ivals.
        xvals-tabname   = 'VBRP'.
        xvals-fieldname = 'VGBEL'.
        APPEND xvals TO ivals.

        CALL FUNCTION 'POPUP_GET_VALUES'
            EXPORTING
              popup_title     = 'Referance Order Document Number ?'
            TABLES
              fields          = ivals
            EXCEPTIONS
              error_in_fields = 1
            OTHERS          =   2.

          READ TABLE ivals INTO xvals INDEX 1.
          CONDENSE xvals-value.
          IF sy-subrc  = 0 and xvals-value ne ''.
*/ Check order status !
           SELECT SINGLE * FROM vbak
             INTO @DATA(wa_vbak2)
             WHERE vbeln = @xvals-value.
             IF sy-subrc IS INITIAL.
               SELECT SINGLE * FROM vbuk
                 INTO @DATA(wa_vbuk2)
                 WHERE vbeln = @xvals-value.
             ENDIF.

           IF sy-subrc = 0 AND
            ( wa_vbak2-faksk NE space  OR "Block status
              wa_vbak2-auart NE 'ZDB1' OR "Order type
              wa_vbuk2-fksak EQ 'C'    OR "Invoicing
              wa_vbuk2-abstk EQ 'C'    OR "Order canceled
              wa_vbuk2-uvals NE 'C' ).    "Incompleteness

            MESSAGE 'Check order, you can not invoice this referance'
             TYPE 'E'.
           ELSE.
*/ Add debit line
            "Siparişi check et.
            CLEAR xkomfkgn_ls..
            xkomfkgn_ls-mandt   = sy-mandt.
            xkomfkgn_ls-vgtyp   = 'C'.
            xkomfkgn_ls-vgbel   = xvals-value.
            xkomfkgn_ls-vgpos   = '000010'.
            xkomfkgn_ls-augru   = augru_ls.
            xkomfkgn_ls-shkzg   = 'S'.
            APPEND xkomfkgn_ls.

            CLEAR xkomfkko_ls.
            xkomfkko_ls-mandt = sy-mandt.
            xkomfkko_ls-knumv = xvals-value.
            xkomfkko_ls-kposn = '000010'.
            xkomfkko_ls-kschl = 'PDIF'.
            SELECT SINGLE netwr
              FROM VBAK
              INTO lv_netwr
              WHERE vbeln = xvals-value.
             IF sy-subrc IS INITIAL AND lv_netwr GT 0.
               xkomfkko_ls-kbetr = lv_netwr.
             ENDIF.
            APPEND xkomfkko_ls.
           ENDIF.
          ENDIF.
      WHEN '2' OR 'A'.
    ENDCASE.
  ENDIF.
 ENDIF.

ENDENHANCEMENT.
*$*$-End:   (1)---------------------------------------------------------------------------------$*$*

  READ TABLE xkomfkgn_gs INDEX 1.
  IF sy-subrc EQ 0.
    PERFORM belege_erzeugen TABLES xkomfkgn_gs
                                   xkomfkko_gs
                            USING  zposting
                                   fkart_gs.
    vbsk_vbnum_c = vbsk_vbnum_c + vbsk-vbnum.
    vbsk_ernum_c = vbsk_ernum_c + vbsk-ernum.
  ENDIF.

  READ TABLE xkomfkgn_ls INDEX 1.
  IF sy-subrc EQ 0.
    PERFORM belege_erzeugen TABLES xkomfkgn_ls
                                   xkomfkko_ls
                            USING  zposting
                                   fkart_ls.
    vbsk_vbnum_d = vbsk_vbnum_d + vbsk-vbnum.
    vbsk_ernum_d = vbsk_ernum_d + vbsk-ernum.
  ENDIF.

* SIMULATION = 'H'
  IF zposting = 'B'.
    COMMIT WORK.
  ENDIF.

ENDFORM.                    " CREATE_DOCUMENTS

How to use this new design ! When program start credit/debit memo , a pop-up ask to user ‘Do you  want to add credit/debit line ?’ If yes, user has to fill out credit/debit memo request.

Implementation :

Run program (F8) .

Select line/s and click retroactive billing.

A pop-up will be asking for additional lines depend on credit/debit memo ! Because, SAP standard provide that you can only credit or debit line in one document !

If you select ‘Yes’, a new pop-up will be asking for referance document. Else, program will be working like a standard behaviour.

Click ‘OK’ , program will be add a new line in invoicing document ! Also,  you can report these lines.

Look at referance document !

Document flow !

source link:https://blogs.sap.com/2017/10/04/retroactive-billing-vfrb-modification-to-add-creditdebit-line/

相關文章