Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
brunobex
Active Participant

This blog is published in the language "Portuguese" permitted by new policies of SDN.


Introduction/Introdução:

Portuguese:

Com esse Blog você vai ver uma maneira que eu desenvolvi para simular o documento contábil de FI antes de gravar a Fatura de SD pela transação VF01.

Esse programa foi útil em cliente onde o índice de estornos VF11 estava muito alto porque os documentos contábeis foram gerados incorretamente e porque não há uma maneira standard para simular o documento contábil pela VF01 até onde eu sei.

Primeiramente irei mostrar três cenários:

1) Simulação do documento contábil da VF01 baseado em remessa VL01N

2) Simulação do documento contábil da VF01 baseado em ordem de venda VA01

3) Simulação de um erro O programa não é perfeito, sinta-se a vontade para adaptar o código fonte.

OBS: os cenários são fictícios e não correspondem os valores da realidade.  

English:

With this blog you will see a way that I developed of simulate FI accounting document before saving the SD Billing Document for the transaction VF01.

This program was useful in client where the rate of reversals VF11 was very high because the accounting documents were generated incorrectly and because there is no standard way to simulate the accounting document by VF01 as far as I know.

First I will show three scenarios:

1) Simulation accounting document with the VF01 based document delivery VL01N

2) Simulation accounting document with VF01 based sales order VA01

3) Simulation of an error The program is not perfect, feel free to adapt the source code.

NOTE: The scenarios are fictitious and do not match reality values

1) Simulação do documento contábil da VF01 baseado em remessa VL01N

   

     No programa Z, informe a remessa e execute F8
       


     O programa Z irá mostrar como deve ficar o documento contábil:      

       

     Criando o documento real de faturamento na transação VF01 com a mesma remessa:

      

     Documento que foi gerado:   

     Conferindo o fluxo de documentos na transação VF03 para ter a certeza dos documentos gerados:

    

     

      Conferindo o documento contábil ainda na transação VF03:                              

      

     Resultado final: Documento real ficou igual ao simulado.          

    

2) Simulação do documento contábil da VF01 baseado em ordem de venda VA01

     No programa Z, informe a ordem de venda/item e execute F8

       

     O programa Z irá mostrar como deve ficar o documento contábil:     

    

     Criando o documento real de faturamento na transação VF01 com a mesma ordem de venda:

    

     Documento que foi gerado:

     Conferindo o fluxo de documentos na transação VF03 para ter a certeza dos documentos gerados:

      

    

     Conferindo o documento contábil ainda na transação VF03:     

    

     Resultado final: Documento real ficou igual ao simulado.

    

3) Simulação de um erro

     Nesse exemplo tenho uma remessa com problema na determinação de conta. O programa irá mostrar os erros em um pop-up.     

    

    

Código Fonte:

Report: zsd_simula_vf01

REPORT zsd_simula_vf01 .

TYPE-POOLS: slis.

TYPES: BEGIN OF ty_bseg.

        INCLUDE STRUCTURE bseg.

TYPES:  ktext TYPE rfpsd-ktext,

        kursf type acccr-KURSF,

        END   OF ty_bseg,

        ty_t_bseg TYPE TABLE OF ty_bseg.

CONSTANTS: c_c(1)  TYPE c VALUE 'C',

           c_j(1)  TYPE c VALUE 'J',

           c_pcmt  TYPE skat-ktopl VALUE 'PCMT',

           c_brl   type acccr-WAERS value 'BRL'.

PARAMETERS: p_vbeln TYPE likp-vbeln.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS:

            p_vbelnv type vbap-vbeln,

            p_posnr  type vbap-posnr.

SELECTION-SCREEN END OF BLOCK b1.

DATA:

      t_billing_data_in    TYPE TABLE OF    bapivbrk,

      w_billind_data_in     LIKE LINE OF t_billing_data_in,

      t_condition_data_in    TYPE TABLE OF bapikomv,

      t_returnlog_out    TYPE TABLE OF bapireturn1,

      t_success_doc_out    TYPE TABLE OF bapisucc,

      t_xaccit         TYPE TABLE OF accit,

      t_xacccr         TYPE TABLE OF acccr,

      lv_simulate(1)        TYPE c,

      xbseg                 TYPE ty_t_bseg,

      w_bseg                LIKE LINE OF xbseg.

DATA:

      w_layout      TYPE slis_layout_alv,

      w_gs_print    TYPE slis_print_alv,

      t_fieldcat    TYPE slis_t_fieldcat_alv,

      w_fieldcat    LIKE LINE OF t_fieldcat.

START-OF-SELECTION.

  if p_vbeln  is initial and

     p_vbelnv is initial and

     p_posnr  is initial.

*Preencha Fornecedimento ou  OV/item.

     message i208(00) with text-e03.

     exit.

  endif.

  if not p_vbeln is initial and

     ( not p_vbelnv is initial or

       not p_posnr  is initial ).

*Somente pode ser preenchido Fornecimento ou OV.

     message i208(00) with text-e01.

     exit.

  endif.

*Se fornecimento não for preenchido ordem e item são obrigatorios.

  if p_vbeln is initial.

     if p_vbelnv is initial or

        p_posnr  is initial.

*Documento ou  Item de venda não foi preenchido.

       message i208(00) with text-e02.

       exit.

     endif.

  endif.

*Fornecimento/Picking

  if not p_vbeln is initial.

    CLEAR w_billind_data_in.

    w_billind_data_in-ref_doc    = p_vbeln.

    w_billind_data_in-ref_doc_ca = c_j.

    APPEND w_billind_data_in TO t_billing_data_in.

  else.

    CLEAR w_billind_data_in.

    w_billind_data_in-ref_doc    = p_vbelnv.

    w_billind_data_in-ref_item   = p_posnr.

    w_billind_data_in-ref_doc_ca = c_c.

    APPEND w_billind_data_in TO t_billing_data_in.

  endif.

*Exporta para EXIT_SAPLV60B_008

  lv_simulate = 'X'.

  EXPORT p1 = lv_simulate

  TO MEMORY ID 'ZBILLINGDOC_SIMULATE'.

  CALL FUNCTION 'BAPI_BILLINGDOC_SIMULATE'

       TABLES

            billing_data_in   = t_billing_data_in

            condition_data_in = t_condition_data_in

            returnlog_out     = t_returnlog_out

            success_doc_out   = t_success_doc_out

       EXCEPTIONS

            error_message     = 1

            OTHERS            = 2.

  IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

  ENDIF.

  IMPORT p1 = t_xaccit[]

         p2 = t_xacccr[]

  FROM MEMORY ID 'ZBILLINGDOC_SIMULATE_TAB'.

  PERFORM f_preenche_alv.

  PERFORM f_alv.

*&---------------------------------------------------------------------*

*&      Form  f_alv

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM f_alv.

*Lista ALV igual a FB03

*Layout

  w_layout-zebra = 'X'.

  w_layout-min_linesize = 100.

*Print

  w_gs_print-no_print_listinfos = 'X'.

*Fielcat

  PERFORM f_fieldcat.

*Libera o documento

  ROLLBACK WORK.

  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

   EXPORTING

        i_interface_check        = ' '

*     i_buffer_active             = 'X'                      "ALRK241034

        i_callback_program       = 'ZSD_SIMULA_VF01'

*          i_callback_pf_status_set = 'PF_STATUS_SET'

*          i_callback_user_command  = 'HANDLE_USER_COMMAND'

*          I_STRUCTURE_NAME         = 'BSEG'

        is_layout                = w_layout

        it_fieldcat              = t_fieldcat

        i_default                = 'X'

        i_save                   = 'A'                 "Note 319936

        is_print                 = w_gs_print

     TABLES

          t_outtab                 = xbseg

     EXCEPTIONS

          program_error            = 1

          OTHERS                   = 2.

  IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

  ENDIF.

ENDFORM.                    " f_alv

*&---------------------------------------------------------------------*

*&      Form  f_fieldcat

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM f_fieldcat.

  CLEAR w_fieldcat.

  w_fieldcat-fieldname      = 'BUZEI'.

  w_fieldcat-tabname         = 'XBSEG'.

  w_fieldcat-ref_fieldname  = 'BUZEI'.

  w_fieldcat-ref_tabname    = 'BSEG'.

  w_fieldcat-key            = 'X'.

  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.

  w_fieldcat-fieldname      = 'BSCHL'.

  w_fieldcat-emphasize      = '$'.

  w_fieldcat-tabname         = 'XBSEG'.

  w_fieldcat-ref_fieldname  = 'BSCHL'.

  w_fieldcat-ref_tabname    = 'BSEG'.

  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.

  w_fieldcat-fieldname      = 'HKONT'.

  w_fieldcat-tabname         = 'XBSEG'.

  w_fieldcat-ref_fieldname  = 'KONTO'.

  w_fieldcat-ref_tabname  = 'RFPSD'.

  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.

  w_fieldcat-fieldname      = 'KTEXT'.

  w_fieldcat-tabname         = 'XBSEG'.

  w_fieldcat-ref_fieldname  = 'KTEXT'.

  w_fieldcat-ref_tabname    = 'RFPSD'.

  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.

  w_fieldcat-fieldname      = 'ZUONR'.

  w_fieldcat-tabname         = 'XBSEG'.

  w_fieldcat-ref_fieldname  = 'ZUONR'.

  w_fieldcat-ref_tabname    = 'BSEG'.

  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.

  w_fieldcat-fieldname      = 'MWSKZ'.

  w_fieldcat-emphasize      = '$'.

  w_fieldcat-tabname         = 'XBSEG'.

  w_fieldcat-ref_fieldname  = 'MWSKZ'.

  w_fieldcat-ref_tabname    = 'BSEG'.

  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.

  w_fieldcat-fieldname      = 'WRBTR'.

  w_fieldcat-tabname         = 'XBSEG'.

  w_fieldcat-ref_tabname    = 'BSEG'.

  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.

  w_fieldcat-fieldname      = 'DMBTR'.

  w_fieldcat-tabname         = 'XBSEG'.

  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.

  w_fieldcat-fieldname      = 'KURSF'.

  w_fieldcat-tabname         = 'XBSEG'.

  w_fieldcat-ref_fieldname  = 'KURSF'.

  w_fieldcat-ref_tabname    = 'ACCCR'.

  APPEND w_fieldcat TO t_fieldcat.

ENDFORM.                    " f_fieldcat

*&---------------------------------------------------------------------*

*&      Form  f_preenche_alv

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM f_preenche_alv.

  FIELD-SYMBOLS: <lf_xaccit> LIKE LINE OF t_xaccit,

                 <lf_xacccr> LIKE LINE OF t_xacccr,

                 <lf_bseg>   LIKE LINE OF xbseg.

  DATA: lv_buzei TYPE bseg-buzei.

*Primeiro acha o clientes

  LOOP AT t_xaccit ASSIGNING <lf_xaccit>

  WHERE kunnr <> space.

    CLEAR w_bseg.

    w_bseg-bschl = <lf_xaccit>-bschl.

    w_bseg-hkont = <lf_xaccit>-kunnr.

    w_bseg-zuonr = <lf_xaccit>-zuonr.

    w_bseg-mwskz = <lf_xaccit>-mwskz.

    SELECT SINGLE name1 INTO w_bseg-ktext

    FROM kna1

    WHERE kunnr = <lf_xaccit>-kunnr.

    READ TABLE t_xacccr ASSIGNING <lf_xacccr>

     WITH KEY posnr = <lf_xaccit>-posnr.

    IF sy-subrc = 0.

      w_bseg-wrbtr = <lf_xacccr>-wrbtr.

      w_bseg-kursf = <lf_xacccr>-kursf.

*Verifica se é diferente de BRL

      if <lf_xacccr>-WAERS <> c_brl.

          unassign <lf_xacccr>.

          READ TABLE t_xacccr ASSIGNING <lf_xacccr>

           WITH KEY posnr = <lf_xaccit>-posnr

                    waers = c_brl.

          if sy-subrc = 0.

            w_bseg-dmbtr = <lf_xacccr>-wrbtr.

          endif.

      endif.

    ENDIF.

    IF NOT w_bseg-wrbtr IS INITIAL.

      COLLECT w_bseg INTO xbseg.

    ENDIF.

  ENDLOOP.

*Contas somente sem cliente

  LOOP AT t_xaccit ASSIGNING <lf_xaccit>

      WHERE hkont <> space AND

            kunnr = space.

*Somente pode entrar

    CLEAR w_bseg.

    w_bseg-bschl = <lf_xaccit>-bschl.

    w_bseg-hkont = <lf_xaccit>-hkont.

    w_bseg-zuonr = <lf_xaccit>-bldat.

    w_bseg-mwskz = <lf_xaccit>-mwskz.

    READ TABLE t_xacccr ASSIGNING <lf_xacccr>

     WITH KEY posnr = <lf_xaccit>-posnr.

    IF sy-subrc = 0.

      w_bseg-wrbtr = <lf_xacccr>-wrbtr.

      w_bseg-kursf = <lf_xacccr>-kursf.

*Verifica se é diferente de BRL

      if <lf_xacccr>-WAERS <> c_brl.

          unassign <lf_xacccr>.

          READ TABLE t_xacccr ASSIGNING <lf_xacccr>

           WITH KEY posnr = <lf_xaccit>-posnr

                    waers = c_brl.

          if sy-subrc = 0.

            w_bseg-dmbtr = <lf_xacccr>-wrbtr.

          endif.

      endif.

    ENDIF.

*TABLE BUFFER!!!

    SELECT SINGLE txt50 INTO w_bseg-ktext

    FROM skat

    WHERE spras = sy-langu

    AND   ktopl = c_pcmt

    AND   saknr = <lf_xaccit>-hkont.

    IF NOT w_bseg-wrbtr IS INITIAL.

      COLLECT w_bseg INTO xbseg.

    ENDIF.

  ENDLOOP.

*Arruma numeracao dos itens

  LOOP AT xbseg ASSIGNING <lf_bseg>.

    ADD 1 TO lv_buzei.

    <lf_bseg>-buzei = lv_buzei.

  ENDLOOP.

ENDFORM.                    " f_preenche_alv

Customer-Exit: EXIT_SAPLV60B_008

Ampliação: SDVFX008

INCLUDE ZXVVFU08

*----------------------------------------------------------------------*

*   INCLUDE ZXVVFU08                                                   *

*----------------------------------------------------------------------*

CONSTANTS:

      lc_xacchd(18) TYPE c VALUE '(SAPLV60B)xacchd[]'.

DATA:

      lv_simulate(1) TYPE c.

FIELD-SYMBOLS: <lf_t_xacchd> TYPE STANDARD TABLE.

IMPORT p1 = lv_simulate

FROM MEMORY ID 'ZBILLINGDOC_SIMULATE'.

IF sy-subrc = 0 AND lv_simulate = 'X'.

  FREE MEMORY ID 'ZBILLINGDOC_SIMULATE'.

  ASSIGN (lc_xacchd) TO <lf_t_xacchd>.

  IF <lf_t_xacchd> IS ASSIGNED.

    CALL FUNCTION 'AC_DOCUMENT_CREATE'

         EXPORTING

              i_free_table  = ' '

         TABLES

              t_acchd       = <lf_t_xacchd>

              t_accit       = xaccit

              t_acccr       = xacccr

              t_accfi       = xaccfi

         EXCEPTIONS

              error_message = 01.

    FREE MEMORY ID 'ZBILLINGDOC_SIMULATE_TAB'.

    EXPORT p1 = xaccit[]

           p2 = xacccr[]

    TO MEMORY ID 'ZBILLINGDOC_SIMULATE_TAB'.

  ENDIF.

ENDIF.

Textos de Seleção e Símbolos de Texto

P_POSNR    Item Documento de Venda

P_VBELN    Fornecimento/Picking

P_VBELNV    Documento de vendas

001    OV Serviço

E01    Somente pode ser preenchido Fornecimento ou OV.

E02    Documento ou  Item de venda não foi preenchido.

E03    Preencha Fornecedimento ou  OV/item.