SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Create Invoice with reference to delivery



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SD
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Sun Aug 24, 2008 1:18 pm    Post subject: Create Invoice with reference to delivery Reply with quote

In MV50AFZ1 Exit:
Code:
If sy-UCOMM = 'WABU'
   OR sy-UCOMM = 'WABU_T'.

  If likp-expkz = 'X'.

   CALL FUNCTION 'Z_FAKTURA_ANLEGEN'
                         STARTING NEW TASK 'Z_FAKT_ANL'
               EXPORTING
                    I_VBELN                = likp-vbeln
                    I_MJAHR                = emkpf-mjahr
                    I_MBLNR                = emkpf-mblnr.

  Endif.
Endif.


Function block "Z_FAKTURA_ANLEGEN":
Code:
FUNCTION Z_FAKTURA_ANLEGEN.
*"------------------------------------------------ ----------------------
* "*" Local Interface:
*"  IMPORTING
*"     VALUE(I_VBELN) LIKE  LIKP-VBELN
*"     VALUE(I_FKART) TYPE  FKART DEFAULT 'ZF8D'
*"     VALUE(I_MJAHR) TYPE  MKPF-MJAHR OPTIONAL
*"     VALUE(I_MBLNR) TYPE  MKPF-MBLNR OPTIONAL
*"  EXPORTING
*"     VALUE(E_VBELN) TYPE  VBELN_VF
*"----------------------------------------------------------------------

* USE FuBa of:
* FuBa is userexit form userexit_save_document (MV50AFZ1)
* Called. (Transaction VL02N)
*
* FUNCTIONALITY:
* 1) The update will wait
* 2) After recording the billing is created (V01)
*__________________________________________________

  data: l_mode     type char1 value 'N',
        l_subrc    like sy-subrc,
        l_errmail  type flag.
  field-symbols: <fs_msg> TYPE BDCMSGCOLL.
*__________________________________________________

  refresh: gt_msg, gt_mail.

*** (First wait for the update, and then examine the table KNA1)
  PERFORM wait_for_update_of_bel1
                      USING   i_vbeln i_mblnr i_mjahr
                      CHANGING l_subrc.
  if l_subrc ne 0.
* Raise NOCH_NICHT_VERBUCHT. "--- Update is not yet finished
message e398 (00) with 'update was not finished.' (010)
                     into gs_mail.
    append gs_mail to gt_mail.
  endif.

  if l_subrc is initial.

    perform faktura_anlegen_fubas using i_fkart
                                 changing i_vbeln gt_mail[] l_errmail
                                          e_VBELN.

  endif.

  if not l_errmail is initial.
    perform sendmail_fehlerlist using i_vbeln i_fkart
                                      gt_mail[].
  endif.

ENDFUNCTION.


Form "WAIT_FOR_UPDATE_OF_BEL1":
Code:
*&---------------------------------------------------------------------
*&      Form  WAIT_FOR_UPDATE_OF_BEL1
*&---------------------------------------------------------------------
FORM wait_for_update_of_bel1 USING    p_vbeln      TYPE likp-vbeln
                                      p_mblnr      TYPE mkpf-mblnr
                                      p_mjahr      TYPE mkpf-mjahr
*                                     p_wait_up_to_seconds TYPE i
                             CHANGING p_subrc TYPE sy-subrc.
  DATA: l_garg       TYPE seqg3-garg,
        lt_enq       TYPE STANDARD TABLE OF seqg3,
        l_start_time TYPE sy-uzeit,
        l_runtime    TYPE i,
        p_wait_up_to_seconds  TYPE i value 15,
        l_subrc      TYPE sy-subrc.
*______________________________________________________________________
* First wait for the update, and then examine the table KNA1
* Update wait (barring read)
  CONCATENATE sy-mandt p_vbeln INTO l_garg.
  MOVE sy-uzeit TO l_start_time.
  APPEND INITIAL LINE TO lt_enq[].
  WHILE l_subrc = 0 AND NOT lt_enq[] IS INITIAL
                    AND l_runtime =< p_wait_up_to_seconds.
    REFRESH lt_enq.
    CALL FUNCTION 'ENQUEUE_READ'
         EXPORTING
*             GCLIENT               = SY-MANDT
              gname                 = 'LIKP'
              garg                  = l_garg
*             GUNAME                = SY-UNAME
*             LOCAL                 = ' '
         IMPORTING
*             NUMBER                =
              subrc                 = l_subrc
         TABLES
              enq                   = lt_enq[]
*        EXCEPTIONS
*             COMMUNICATION_FAILURE = 1
*             SYSTEM_FAILURE        = 2
*             OTHERS                = 3
              .
    IF sy-subrc <> 0.
*     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*           WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    l_runtime = sy-uzeit - l_start_time.
  ENDWHILE.
* Check update: MKPF read until there is proof.
  MOVE sy-uzeit TO l_start_time.
  SELECT SINGLE COUNT( * ) FROM mkpf WHERE mblnr = p_mblnr
                                       AND mjahr = p_mjahr.
  WHILE sy-subrc = 4 AND l_runtime =< p_wait_up_to_seconds.
    WAIT UP TO 1 SECONDS.
    l_runtime = sy-uzeit - l_start_time.
    SELECT SINGLE COUNT( * ) FROM mkpf WHERE mblnr = p_mblnr
                                         AND mjahr = p_mjahr.
  ENDWHILE.
* Either everything in order or waiting period has expired.
  IF lt_enq[] IS INITIAL AND sy-subrc = 0.
* Customer Equip: Updates right expired and customer data are there.
    CLEAR p_subrc.
  ELSEIF NOT lt_enq[] IS INITIAL AND sy-subrc = 0.
* Customer Change: Updates not yet expired,
    p_subrc = 2.
  ELSEIF lt_enq[] IS INITIAL AND sy-subrc <> 0.
* Update already expired,
* Workforce but are still not there (update canceled?).
    p_subrc = 4.
  ELSEIF NOT lt_enq[] IS INITIAL AND sy-subrc <> 0.
* Update has not yet expired
* Document is still not there (delay?).
    p_subrc = 8.
  ENDIF.
* START TEST: In the event of errors, notify the competent persons
  IF p_subrc <> 0.

  ENDIF.
* START TEST: In the event of errors, notify the competent persons

ENDFORM.                    " WAIT_FOR_UPDATE_OF_BEL1


Form "FAKTURA_ANLEGEN_FUBAS":
Code:
*&---------------------------------------------------------------------*
*&      Form  FAKTURA_ANLEGEN_FUBAS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form faktura_anlegen_fubas using    i_fkart    TYPE FKART
                           changing i_vbeln    like LIKP-VBELN
                                   it_mail     type tt_mail
                                   i_errmail   type flag
                                   E_VBELN_vf  TYPE VBELN_VF.

* Kommumikationstabelle XKOMFK
  DATA:   BEGIN OF XKOMFK OCCURS 0.
          INCLUDE STRUCTURE KOMFK.
  DATA:   END   OF XKOMFK.

  DATA:   BEGIN OF XTHEAD OCCURS 50.    "aktueller Tabellenstand
          INCLUDE STRUCTURE THEADVB.
  DATA:   END OF XTHEAD.

* Current status table VBFS
  DATA:    BEGIN OF XVBFS OCCURS 20.
          INCLUDE STRUCTURE VBFS.
  DATA:    END OF XVBFS.

* Current status table VBSS
  DATA:    BEGIN OF XVBSS OCCURS 10.
          INCLUDE STRUCTURE VBSS.
  DATA:    END OF XVBSS.

* Current status table
  DATA:    BEGIN OF XVBRK OCCURS 10.
          INCLUDE STRUCTURE VBRKVB.
  DATA:    END OF XVBRK.

* Current status table
  DATA:  BEGIN OF XVBRP OCCURS 100.
          INCLUDE STRUCTURE VBRPVB.
  DATA:  END OF XVBRP.

* Staff Partners Table: Current status table
  DATA: BEGIN OF XVBPA OCCURS 0.
          INCLUDE STRUCTURE VBPAVB.
  DATA: END OF XVBPA.

  DATA:   BEGIN OF XKOMV OCCURS 50.
          INCLUDE STRUCTURE KOMV.
  DATA:   END   OF XKOMV.

  DATA : LV_BAD_DATA LIKE RVSEL-XFELD.

*__________________________________________________

  clear: vbsk.
  refresh xkomfk.

  RV60A-fkart = i_fkart.

  vbsk-mandt = sy-mandt.
  vbsk-smart = 'F'.
  vbsk-ernam = sy-uname.
  vbsk-erdat = sy-datum.
  vbsk-uzeit = sy-uzeit.

  xkomfk-mandt = sy-mandt.
  xkomfk-vbeln = i_vbeln.
  xkomfk-vbtyp = 'J'.
  append xkomfk.

  i_errmail = 'X'. "- error. Deleted after successfully creating

*** Generate invoices
  CALL FUNCTION 'RV_INVOICE_CREATE'
       EXPORTING
            INVOICE_TYPE  = RV60A-FKART
            INVOICE_DATE  = RV60A-FKDAT
            PRICING_DATE  = RV60A-PRSDT
            DELIVERY_DATE = RV60A-FBUDA
            SELECT_DATE   = RV60A-SELDAT
            VBSK_I        = VBSK
       IMPORTING
            VBSK_E        = VBSK
            OD_BAD_DATA   = LV_BAD_DATA
       TABLES
            XKOMFK        = XKOMFK
            XTHEAD        = XTHEAD
            XVBFS         = XVBFS
            XVBSS         = XVBSS
            XVBRK         = XVBRK
            XVBRP         = XVBRP
            XVBPA         = XVBPA
            XKOMV         = XKOMV.

* Messages in the mail table collect
  loop at xvbfs.
    MESSAGE ID xvbfs-msgid TYPE xvbfs-msgty
        NUMBER xvbfs-msgno
        WITH xvbfs-msgv1 xvbfs-msgv2 xvbfs-msgv3 xvbfs-msgv4
        into gs_mail-text.
    append gs_mail to it_mail.
  endloop.
* Error when creating the document? --> FehlerKz set (for mail)
  read table xvbfs with key msgty = 'E' transporting no fields.
  check not sy-subrc is initial.  "Kein Fehler aufgetreten

*** Add billing document
  CALL FUNCTION 'RV_INVOICE_DOCUMENT_ADD'
       EXPORTING
            VBSK_I           = VBSK
            WITH_POSTING     = 'A'
*            WITHOUT_REFRESH  = ' '
            PREISFINDUNGSART = 'I'
*            I_NO_VBLOG       = ' '
*            I_NO_NAST        = ' '
*            I_NO_FI_DOC      = ' '
*            I_NO_PRICING     = ' '
      IMPORTING
           VBSK_E           = VBSK
       TABLES
            XKOMFK           = xkomfk
            XKOMV            = xkomv
            XTHEAD           = xthead
            XVBFS            = xvbfs
            XVBPA            = xvbpa
            XVBRK            = xvbrk
            XVBRP            = xvbrp
            XVBSS            = xvbss.

* Error when creating the document? --> FehlerKz set (for mail)
* Messages in the mail table collect
  if not xvbfs[] is initial.
    loop at xvbfs.
      "--- Billing document number over ---"
      if xvbfs-msgty = 'S' and xvbfs-msgid = 'VF'
                           and xvbfs-msgno = '311'.
        move xvbfs-msgv1 to E_VBELN_vf.  "---Fakturabelegnummer
        clear i_errmail.
      endif.
      MESSAGE ID xvbfs-msgid TYPE xvbfs-msgty
          NUMBER xvbfs-msgno
          WITH xvbfs-msgv1 xvbfs-msgv2 xvbfs-msgv3 xvbfs-msgv4
          into gs_mail-text.
      append gs_mail to it_mail.
    endloop.
  else.
    if xvbfs-msgty = 'S' and xvbfs-msgid = 'VF' and xvbfs-msgno = '311'.
      clear i_errmail.
      move xvbfs-msgv1 to E_VBELN_vf.  "billing document number ---
      MESSAGE ID xvbfs-msgid TYPE xvbfs-msgty
          NUMBER xvbfs-msgno
          WITH xvbfs-msgv1 xvbfs-msgv2 xvbfs-msgv3 xvbfs-msgv4
          into gs_mail-text.
      append gs_mail to it_mail.
    else.
      "- Messageb need not hingefügt ...?
    endif.
  endif.

*  break-point.

ENDFORM.                    " FAKTURA_ANLEGEN_FUBAS
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SD All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.