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

Library for creating a financial document



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



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Wed Jul 02, 2008 9:19 am    Post subject: Library for creating a financial document Reply with quote

ZIFIPIDOC

Code:
************************************************************************
*
*  INCLUDE ZIFIPIDOC.
*
*  DESCRIPCION: Include con forms para la utilizacion del grupo de
*  funciones FIPI para creacion, compensacion y anulacion de documentos
*  financieros.
*
*  INSTRUCCIONES: Se han definido los siguientes forms para un correcto
*  funcionamiento:
*----------------------------------------------------------------------*
*      FORM  fipi_start.-  Se inicializa la interfase con las opciones
*      que se pasan como parametros
*      -->  p_function   B - Batch Input, C - Call Transaction
*      -->  p_group      Solo para Batch Input: Nombre del juego de
*                        datos
*      -->  p_holddate   Solo para Batch Input: Bloquear ejecucion
*                        hasta la fecha indicada
*      -->  p_keep       Solo para Batch Input: No borrar el juego de
*                        datos una vez procesados
*      -->  p_mode       Solo para Call Transaction: Modo de ejecucion
*                           A  Visual.pant.(todas)
*                           E  Visualizar solo errores
*                           N  Sin visualizacion
*      -->  p_update     Solo para Call Transaction:
*                           A  Actualizacion asincronica
*                           S  Actualizacion sincronica
*      -->  p_user       Usuario a usar para autorizaciones de ejecucion
*                        en fondo
*      -->  p_xbdcc      X - Batch input en caso de error en transaccion
*                        de llamada
*----------------------------------------------------------------------*
*      FORM  fipi_end.- Se cierra la interfase (cierra el juego de datos
*      o lanza el Call Transaction dependiendo de las opciones elegidas
*      al iniciar dicha interfase
*      -->  p_bdcimmed  En caso de Juego de Datos lo lanza
*                       inmediatamente
*      -->  p_bdcstrtdt En caso de Juego de Datos fecha de ejecucion
*      -->  p_bdcstrttm En caso de Juego de Datos hora de ejecucion
*---------------------------------------------------------------------*
*      FORM  fipi_crear_documento.- Mediante este perform se puede
*      crear un documento financiero
*      -->  t_ftpost    Cabecera y posiciones de doc. para
*                       interfase interna contab.
*      -->  t_fttax     Impuestos para interfase de contabilizacion
*                       interna
*      -->  p_tcode     Transaccion por la cual se quiere crear el
*                       documento
*                            FB01 - Contabilizar documento
*                            FBS1 - Registrar documento periodificacion
*                            FB41 - Contabilizar cargo IVA
*                            ABF1 - Contabilizar documento
*                            FBB1 - Contab.valoracion de ME
*                            FBVB - Contab.documento preliminar
*                            FBV1 - Registrar docum.de forma preliminar
*                            FBD5 - Realizar contab. periodica
*      -->  p_no_auth   No comprobar si existe autorizacion para la
*                       transaccion
*      <--  p_bukrs_out Sociedad en la que se creo el documento
*      <--  p_belnr_out N? se documento creado
*      <--  p_gjahr_out Ejercicio en el que se creo el documento
*      <--  p_message   Mensaje que devuelve la creacion del documento
*---------------------------------------------------------------------*
*      FORM  fipi_anular_documento.-  Se pasan los parametros de
*      anulacion del documento y lo anula segun los parametros indicados
*      en la interfase.
*      -->  p_bukrs     Sociedad del documento a anular
*      -->  p_belnr_in  N? de documento a anular
*      -->  p_gjahr     Ejercicio del documento a anular
*      -->  p_monat     Periodo para la anulacion. Si no se indica
*                       se usa el periodo de la fecha de contabilizacion
*      -->  p_budat     Fecha de contabilizacion de la anulacion
*      -->  p_stgrd     Motivo de anulacion
*      -->  p_voidr     Causa de no validez en caso de cheque anulado
*      -->  p_no_auth   No comprobar si existe autorizacion para la
*                       transaccion
*      <--  p_belnr_out N? se documento de anulacion.
*      <--  p_message   Mensaje que devuelve la anulacion.
*---------------------------------------------------------------------*
*      FORM  fipi_lanzar_compensacion.-  Mediante este perform se puede
*      lanzar cualquier operacion de compensacion existente en la
*      transaccion FB05.
*      -->  t_ftclear   Datos de compensacion para interfase interna
*                       de contabilizacion.
*      -->  t_ftpost    Cabecera y posiciones de doc. para interfase
*                       interna contab.
*      -->  t_fttax     Impuestos para interfase de contabilizacion
*                       interna
*      -->  p_auglv     Operacion de compensacion segun tabla T041A.
*                       Las operaciones estandar son:
*                            'AUSGZAHL' - Salida de pagos
*                            'EINGZAHL' - Entrada de pagos
*                            'GUTSCHRI' - Abonos
*                            'UMBUCHNG' - Traslado con compensacion
*      -->  p_no_auth   No comprobar si existe autorizacion para la
*                       transaccion
*      <--  p_bukrs_out Sociedad de compensacion
*      <--  p_belnr_out N? se documento de compensacion
*      <--  p_gjahr_out Ejercicio de compensacion
*      <--  p_message   Mensaje que devuelve la compensacion
*---------------------------------------------------------------------*
*      FORM  fipi_anular_compensacion.- Se pasan los parametros de
*      anulacion del documento y lo anula segun los parametros
*      indicados en la interfase.
*      -->  p_bukrs     Sociedad del documento a anular
*      -->  p_belnr_in  N? de documento a anular
*      -->  p_gjahr     Ejercicio del documento a anular
*      -->  p_no_auth   No comprobar si existe autorizacion para la
*                       transaccion
*      <--  p_belnr_out N? se documento de anulacion.
*      <--  p_message   Mensaje que devuelve la anulacion.
*---------------------------------------------------------------------*
*      FORM  fipi_chequear_errores.- Este include devuelve mediante el
*      status de campo los campos que le faltan a las structuras BKPF,
*      BSEG y BSEC. (Si el campo esta vacio y sin embargo es obligatorio
*      devuelve error)
*      <--T_BAPIRET  Errores del tipo bapiret2
*      -->P_BSEG     Datos de posicion
*      -->P_BSEC     Datos de CPD
*      -->P_BKPF     Datos de cabecera
*      -->P_TCODE    Trasaccion mediante la que se creara el documento
*---------------------------------------------------------------------*
*      FORM  fipi_rellenar_ftpos.- Rellena la estructura GT_FTPOS
*      necesarias para la generacion de documentos dependiendo de las
*      estructuras BKPF, BSEG y BSEC y los status de campo para dichas
*      estructuras.
*      Este perform obvia los campos rellenos en las estructuras pero
*      que por status de campo se encuentran invisibles en pantalla y
*      por lo tanto fallaria el batch-input.
*      -->P_BSEG     Datos de posicion
*      -->P_BSEC     Datos de CPD
*      -->P_BKPF     Datos de cabecera
*      -->P_TCODE    Trasaccion mediante la que se creara el documento
*---------------------------------------------------------------------*
*      FORM fipi_next_dynpro.- Devuelve la siguiente dynpro, inspirado
*      en el form DYNPRO_ERMITTELN del grupo de funciones FIPI. (USO
*      INTERNO)
*---------------------------------------------------------------------*
*      FORM  fipi_status_campo_c.- Devuelve el status de campo de la
*      pantalla inicial del documento a cargar que ser rellena con los
*      datos de cabecera.
*      -->PT_FIELDSTATUS  Estructura de status campo
*      -->P_TCODE         Transaccion mediante la que se cargara el
*                         documento
*      -->P_BUKRS         Sociedad en la que se cargara el documento
*      -->P_BLART         Clase de documento
*      -->P_BKPF          Datos de cabecera
*---------------------------------------------------------------------*
*      FORM  fipi_status_campo_p.- Devuelve el status de campo de la
*      posicion en cuestion que se solicite. Habra que hacer una llamada
*      a este perform por cada posicion del documento que deseemos crear
*      o comprobar.
*      <--PT_FIELDSTATUS  Estructura de status campo
*      -->P_TCODE         Transaccion mediante la que se cargara el
*                         documento
*      -->P_BUKRS         Sociedad en la que se cargara el documento
*      -->P_BSCHL         Clave de contabilizacion de la posicion
*      -->P_HKONT         Cuenta contable de la posicion
*      -->P_UMSKZ         Indicador CME de la posicion
*      -->P_KOART         Clase de cuenta de la posicion
*      -->P_BKPF          Datos de cabecera
*      -->P_BSEG          Datos de posicion
*      -->P_BSEC          Datos de CPD
*      -->P_BSEZ          Informacion adicional de apunte (dialogo)
*---------------------------------------------------------------------*
*      FORM  fipi_status_field_cpd: inspirado en MODULE D0100_EXT_MODIF
*      del programa LFCPDO00.- Devuelve modificaciones especiales para
*      status de campo de estructura CPD. (USO INTERNO)
*---------------------------------------------------------------------*
*
*  MODULO AL QUE PERTENECE:
*
*  AUTOR: Ignacio Arnaiz Piorno                        FECHA: 28-09-2006
*  CONTACTO: [email protected]
*
* ----------------------------------------------------------------------
* CONTROL DE MODIFICACIONES
*   AUTOR         EMPRESA     FECHA       MOTIVO
* ..........      .......   DD/MM/AA  ................................
* ..........      .......   DD/MM/AA  ................................
*-----------------------------------------------------------------------
************************************************************************
 
 
************************************************************************
*                       INCLUDES
************************************************************************
  INCLUDE mseusdat.
  INCLUDE incldata.                      " Datenbank, Atab, Felder
************************************************************************
* Definicion de type pools
************************************************************************
 
************************************************************************
* Definicion de constantes
************************************************************************
  DATA c_fipi_trans_anulacion       LIKE sy-tcode VALUE 'FB08'.
  DATA c_fipi_trans_compensacion    LIKE sy-tcode VALUE 'FB05'.
  DATA c_fipi_trans_descompensacion LIKE sy-tcode VALUE 'FBRA'.
  DATA c_fipi_trans_contab_fb01     LIKE sy-tcode VALUE 'FB01'.
  DATA c_fipi_trans_contab_fbs1     LIKE sy-tcode VALUE 'FBS1'.
  DATA c_fipi_trans_contab_fb41     LIKE sy-tcode VALUE 'FB41'.
  DATA c_fipi_trans_contab_abf1     LIKE sy-tcode VALUE 'ABF1'.
  DATA c_fipi_trans_contab_fbb1     LIKE sy-tcode VALUE 'FBB1'.
  DATA c_fipi_trans_contab_fbvb     LIKE sy-tcode VALUE 'FBVB'.
  DATA c_fipi_trans_contab_fbv1     LIKE sy-tcode VALUE 'FBV1'.
  DATA c_fipi_trans_contab_fbd5     LIKE sy-tcode VALUE 'FBD5'.
************************************************************************
* Definicion de variables
************************************************************************
 
************************************************************************
* Definicion de estructuras
************************************************************************
  DATA d_fipi_bseg TYPE bseg.
************************************************************************
* Definicion de tablas internas
************************************************************************
  DATA: gt_blntab  TYPE blntab OCCURS 0 WITH HEADER LINE,
        gt_ftclear TYPE ftclear OCCURS 0 WITH HEADER LINE,
        gt_ftpost  TYPE ftpost OCCURS 0 WITH HEADER LINE,
        gt_fttax   TYPE fttax OCCURS 0 WITH HEADER LINE.
 
  DATA fipi_xtbsl LIKE tbsl OCCURS 0 WITH HEADER LINE.
 
  DATA gt_fieldstatus_hd TYPE fieldstatus OCCURS 0 WITH HEADER LINE.
  DATA gt_fieldstatus_pos TYPE fieldstatus OCCURS 0 WITH HEADER LINE.
 
************************************************************************
* Definicion de parametros
************************************************************************
 
************************************************************************
* Definicion de rango de seleccion
************************************************************************
 
************************************************************************
* Definicion de la pantalla de seleccion
************************************************************************
 
************************************************************************
* Definicion de FIELD-SYMBOLS
************************************************************************
 
************************************************************************
* Definicion de MACROS
************************************************************************
*-- Macro para rellenar una linea de la tabla gt_ftpost pasandole los
*-- campos que este requiere.
*-- Siempre se debera pasar por orden, primer campos de cabecera y
*-- despues los de posicion
*-- &1 - Tipo del campo 'K' - Cabecera, 'P' - Posicion
*-- &2 - Contador de Cabeceras/Posiciones
*-- &3 - Nombre del campo en la pantalla a rellenar
*-- &4 - Valor del campo en la pantalla a rellenar
  DEFINE rellena_ftpost.
    clear gt_ftpost.
    if not &4 is initial.
      gt_ftpost-count = &2.
      gt_ftpost-fnam  = &3.
      write &4 to gt_ftpost-fval left-justified.
      if gt_ftpost-fnam+0(5) = 'RF05A'
     and &1 = 'P'
     and &2 = 1.
        gt_ftpost-stype = 'K'.
      else.
        gt_ftpost-stype = &1.
      endif.
      if gt_ftpost-fnam = 'BKPF-XMWST'.
        gt_ftpost-stype = 'P'.
        gt_ftpost-count = 1.
      endif.
      append gt_ftpost.
    endif.
  END-OF-DEFINITION.
*-- Macro para rellenar una linea de la tabla gt_ftclear e indicar de
*-- forma univoca una posicion de un documento contable a contabilizar
*-- &1 - Sociedad del documento a compensar
*-- &2 - N? del documento a compensar
*-- &3 - Ejercicio del documento a compensar
*-- &4 - Posicion del documento a compensar
  DEFINE rellena_ftclear.
    clear gt_ftclear.
    select single *
      from bseg
      into d_fipi_bseg
     where bukrs = &1
       and belnr = &2
       and gjahr = &3
       and buzei = &4.
    gt_ftclear-agkoa = d_fipi_bseg-koart.
    gt_ftclear-agbuk = d_fipi_bseg-bukrs.
    gt_ftclear-selfd = 'BELNR'.
    if d_fipi_bseg-umskz is initial.
      gt_ftclear-xnops = 'X'.
    else.
      gt_ftclear-agums = d_fipi_bseg-umskz.
    endif.
    concatenate d_fipi_bseg-belnr
                d_fipi_bseg-gjahr
                d_fipi_bseg-buzei
           into gt_ftclear-selvon.
    append gt_ftclear.
  END-OF-DEFINITION.
*-- Macro para rellenar una linea de la tabla gt_fttax y pasar a la
*-- interfase los distintos impuestos.
*-- &1 - Importe de impuesto en moneda documento
*-- &2 - Indicador IVA
*-- &3 - Clave de contabilizacion
*-- &4 - Cod.emplazamiento fiscal: Emplazamiento p.calculo impuestos
*-- &5 - Importe del impuesto en moneda local
*-- &6 - Clase de condicion
*-- &7 - Indicador de fin de registro para interfase batch input
*-- &8 - Conversion segun tipo de cambio para impuestos
  DEFINE rellena_fttax.
    clear gt_fttax.
    write &1 to gt_fttax-fwste left-justified.
    gt_fttax-mwskz = &2.
    gt_fttax-bschl = &3.
    gt_fttax-txjcd = &4.
    write &5 to gt_fttax-hwste left-justified.
    gt_fttax-kschl = &6.
    gt_fttax-sende = &7.
    gt_fttax-txkrs = &8.
    append gt_fttax.
  END-OF-DEFINITION.
 
************************************************************************
*
*                  FORMS ADICIONALES
*
************************************************************************
 
*&---------------------------------------------------------------------*
*&      Form  fipi_start
*&---------------------------------------------------------------------*
*       Se inicializa la interfase con las opciones que se pasan como +
*       parametros
*----------------------------------------------------------------------*
*  -->  p_function   B - Batch Input, C - Call Transaction
*  -->  p_group      Solo para Batch Input: Nombre del juego de datos
*  -->  p_holddate   Solo para Batch Input: Bloquear ejecucion hasta la
*                    fecha indicada
*  -->  p_keep       Solo para Batch Input: No borrar el juego de datos
*                    una vez procesados
*  -->  p_mode       Solo para Call Transaction: Modo de ejecucion
*                       A      Visual.pant.(todas)
*                       E      Visualizar solo errores
*                       N      Sin visualizacion
*  -->  p_update     Solo para Call Transaction:
*                       A      Actualizacion asincronica
*                       S      Actualizacion sincronica
*  -->  p_user       Usuario a usar para autorizaciones de ejecucion en
*                    fondo
*  -->  p_xbdcc      X - Batch input en caso de error en transaccion de
*                    llamada
*----------------------------------------------------------------------*
  FORM fipi_start USING p_function LIKE rfipi-funct
                        p_group    LIKE apqi-groupid
                        p_holddate LIKE apqi-startdate
                        p_keep     LIKE apqi-qerase
                        p_mode     LIKE rfpdo-allgazmd
                        p_update   LIKE rfpdo-allgvbmd
                        p_user     LIKE apqi-userid
                        p_xbdcc    LIKE rfipi-xbdcc.
 
* Inicializar la interfase
    CALL FUNCTION 'POSTING_INTERFACE_START'
      EXPORTING
*     I_CLIENT                 = SY-MANDT
        i_function               = p_function
        i_group                  = p_group
        i_holddate               = p_holddate
        i_keep                   = p_keep
        i_mode                   = p_mode
        i_update                 = p_update
        i_user                   = p_user
        i_xbdcc                  = p_xbdcc
      EXCEPTIONS
        client_incorrect         = 1
        function_invalid         = 2
        group_name_missing       = 3
        mode_invalid             = 4
        update_invalid           = 5
        OTHERS                   = 6
              .
    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.                    " fipi_start
 
*&---------------------------------------------------------------------*
*&      Form  fipi_end
*&---------------------------------------------------------------------*
*       Se cierra la interfase (cierra el juego de datos o lanza el Call
*       Transaction dependiendo de las opciones elegidas al iniciar
*       dicha interfase
*----------------------------------------------------------------------*
*  -->  p_bdcimmed  En caso de Juego de Datos lo lanza inmediatamente
*  -->  p_bdcstrtdt En caso de Juego de Datos fecha de ejecucion
*  -->  p_bdcstrttm En caso de Juego de Datos hora de ejecucion
*----------------------------------------------------------------------*
  FORM fipi_end USING p_bdcimmed  LIKE rfipi-bdcimmed
                      p_bdcstrtdt TYPE btcsdate
                      p_bdcstrttm TYPE btcstime.
* Cerramos la interfase.
    CALL FUNCTION 'POSTING_INTERFACE_END'
         EXPORTING
              i_bdcimmed              = p_bdcimmed
              i_bdcstrtdt             = p_bdcstrtdt
              i_bdcstrttm             = p_bdcstrttm
         EXCEPTIONS
              session_not_processable = 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.
 
    REFRESH: gt_blntab,
             gt_ftclear,
             gt_ftpost,
             gt_fttax.
 
  ENDFORM.                    " fipi_end
 
*&---------------------------------------------------------------------*
*&      Form  fipi_anular_documento
*&---------------------------------------------------------------------*
*       Se pasan los parametros de anulacion del documento y lo anula
*       segun los parametros indicados en la interfase.
*----------------------------------------------------------------------*
*  -->  p_bukrs     Sociedad del documento a anular
*  -->  p_belnr_in  N? de documento a anular
*  -->  p_gjahr     Ejercicio del documento a anular
*  -->  p_monat     Periodo para la anulacion. Si no se indica se usa el
*                   periodo de la fecha de contabilizacion
*  -->  p_budat     Fecha de contabilizacion de la anulacion
*  -->  p_stgrd     Motivo de anulacion
*  -->  p_voidr     Causa de no validez en caso de cheque anulado
*  -->  p_no_auth   No comprobar si existe autorizacion para la
*                   transaccion
*  <--  p_belnr_out N? se documento de anulacion.
*  <--  p_message   Mensaje que devuelve la anulacion.
*----------------------------------------------------------------------*
  FORM fipi_anular_documento USING p_bukrs     LIKE bkpf-bukrs
                                   p_belnr_in  LIKE bkpf-belnr
                                   p_gjahr     LIKE bkpf-gjahr
                                   p_monat     LIKE bkpf-monat
                                   p_budat     LIKE bkpf-budat
                                   p_stgrd     LIKE bkpf-stgrd
                                   p_voidr     LIKE rf05a-voidr
                                   p_no_auth   LIKE uf05a-stgrd
                                   p_belnr_out LIKE bkpf-belnr
                                   p_message.
 
    DATA: t_blntab LIKE blntab OCCURS 0 WITH HEADER LINE.
    DATA l_budat LIKE bsis-budat.
 
    WRITE p_budat TO l_budat.
 
* Se lanza
    CALL FUNCTION 'POSTING_INTERFACE_REVERSE_DOC'
      EXPORTING
        i_belns                        = p_belnr_in
        i_budat                        = l_budat
        i_bukrs                        = p_bukrs
        i_gjahs                        = p_gjahr
        i_monat                        = p_monat
        i_tcode                        = c_fipi_trans_anulacion
        i_voidr                        = p_voidr
        i_stgrd                        = p_stgrd
        i_no_auth                      = p_no_auth
     IMPORTING
        e_msgid                        = sy-msgid
        e_msgno                        = sy-msgno
        e_msgty                        = sy-msgty
        e_msgv1                        = sy-msgv1
        e_msgv2                        = sy-msgv2
        e_msgv3                        = sy-msgv3
        e_msgv4                        = sy-msgv4
*     E_SUBRC                        =
      TABLES
        t_blntab                       = t_blntab
      EXCEPTIONS
        transaction_code_invalid       = 1
        no_authorization               = 2
        OTHERS                         = 3
              .
    IF NOT sy-msgid IS INITIAL.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
         INTO p_message.
    ENDIF.
    READ TABLE t_blntab INDEX 1.
    IF sy-subrc IS INITIAL.
      p_belnr_out = t_blntab-belnr.
    ENDIF.
 
  ENDFORM.                    " fipi_anular_documento
 
*&---------------------------------------------------------------------*
*&      Form  fipi_anular_compensacion
*&---------------------------------------------------------------------*
*       Se pasan los parametros de anulacion del documento y lo anula
*       segun los parametros indicados en la interfase.
*----------------------------------------------------------------------*
*  -->  p_bukrs     Sociedad del documento a anular
*  -->  p_belnr_in  N? de documento a anular
*  -->  p_gjahr     Ejercicio del documento a anular
*  -->  p_no_auth   No comprobar si existe autorizacion para la
*                   transaccion
*  <--  p_belnr_out N? se documento de anulacion.
*  <--  p_message   Mensaje que devuelve la anulacion.
*----------------------------------------------------------------------*
  FORM fipi_anular_compensacion USING p_bukrs     LIKE bkpf-bukrs
                                      p_belnr_in  LIKE bkpf-belnr
                                      p_gjahr     LIKE bkpf-gjahr
                                      p_no_auth   LIKE uf05a-stgrd
                                      p_belnr_out LIKE bkpf-belnr
                                      p_message.
 
    DATA: t_blntab LIKE blntab OCCURS 0 WITH HEADER LINE.
 
* Se lanza
    CALL FUNCTION 'POSTING_INTERFACE_RESET_CLEAR'
      EXPORTING
        i_augbl                        = p_belnr_in
        i_bukrs                        = p_bukrs
        i_gjahr                        = p_gjahr
        i_tcode                        = c_fipi_trans_descompensacion
        i_no_auth                      = p_no_auth
     IMPORTING
        e_msgid                        = sy-msgid
        e_msgno                        = sy-msgno
        e_msgty                        = sy-msgty
        e_msgv1                        = sy-msgv1
        e_msgv2                        = sy-msgv2
        e_msgv3                        = sy-msgv3
        e_msgv4                        = sy-msgv4
*       E_SUBRC                        =
      TABLES
        t_blntab                       = t_blntab
      EXCEPTIONS
        transaction_code_invalid       = 1
        no_authorization               = 2
        OTHERS                         = 3
              .
 
    IF NOT sy-msgid IS INITIAL.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
         INTO p_message.
    ENDIF.
 
*    READ TABLE t_blntab INDEX 1.
*    IF sy-subrc IS INITIAL.
*      p_belnr_out = t_blntab-belnr.
*    ENDIF.
 
* En este caso no devuelve el codigo de documento en la tabla t_Blntab.
    IF sy-msgid = 'F5'
   AND sy-msgty = 'S'
   AND sy-msgno = '539'.
      p_belnr_out = sy-msgv1.
    ENDIF.
  ENDFORM.                    " fipi_anular_compensacion
 
*&---------------------------------------------------------------------*
*&      Form  fipi_lanzar_compensacion
*&---------------------------------------------------------------------*
*       Mediante este perform se puede lanzar cualquier operacion de
*       compensacion existente en la transaccion FB05.
*----------------------------------------------------------------------*
*  -->  t_ftclear   Datos de compensacion para interfase interna de
*                   contabilizacion.
*  -->  t_ftpost    Cabecera y posiciones de doc. para interfase interna
*                   contab.
*  -->  t_fttax     Impuestos para interfase de contabilizacion interna
*  -->  p_auglv     Operacion de compensacion segun tabla T041A.
*                   Las operaciones estandar son:
*                        'AUSGZAHL' - Salida de pagos
*                        'EINGZAHL' - Entrada de pagos
*                        'GUTSCHRI' - Abonos
*                        'UMBUCHNG' - Traslado con compensacion
*  -->  p_no_auth   No comprobar si existe autorizacion para la
*                   transaccion
*  <--  p_bukrs_out Sociedad de compensacion
*  <--  p_belnr_out N? de documento de compensacion
*  <--  p_gjahr_out Ejercicio de compensacion
*  <--  p_message   Mensaje que devuelve la compensacion
*----------------------------------------------------------------------*
  FORM fipi_lanzar_compensacion TABLES t_ftclear STRUCTURE ftclear
                                       t_ftpost  STRUCTURE ftpost
                                       t_fttax   STRUCTURE fttax
                                 USING p_auglv     LIKE t041a-auglv
                                       p_no_auth   LIKE uf05a-stgrd
                                       p_bukrs_out LIKE bkpf-bukrs
                                       p_belnr_out LIKE bkpf-belnr
                                       p_gjahr_out LIKE bkpf-gjahr
                                       p_message.
 
    DATA: t_blntab  TYPE blntab OCCURS 0 WITH HEADER LINE.
 
    CALL FUNCTION 'POSTING_INTERFACE_CLEARING'
      EXPORTING
        i_auglv                          = p_auglv
        i_tcode                          = c_fipi_trans_compensacion
*     I_SGFUNCT                        = ' '
        i_no_auth                        = p_no_auth
      IMPORTING
        e_msgid                          = sy-msgid
        e_msgno                          = sy-msgno
        e_msgty                          = sy-msgty
        e_msgv1                          = sy-msgv1
        e_msgv2                          = sy-msgv2
        e_msgv3                          = sy-msgv3
        e_msgv4                          = sy-msgv4
*     e_subrc                          = sy-subrc
      TABLES
        t_blntab                         = t_blntab
        t_ftclear                        = t_ftclear
        t_ftpost                         = t_ftpost
        t_fttax                          = t_fttax
      EXCEPTIONS
        clearing_procedure_invalid       = 1
        clearing_procedure_missing       = 2
        table_t041a_empty                = 3
        transaction_code_invalid         = 4
        amount_format_error              = 5
        too_many_line_items              = 6
        company_code_invalid             = 7
        screen_not_found                 = 8
        no_authorization                 = 9
        OTHERS                           = 10
              .
    IF NOT sy-msgid IS INITIAL.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
              INTO p_message.
    ENDIF.
    READ TABLE t_blntab INDEX 1.
    IF sy-subrc IS INITIAL.
      p_bukrs_out = t_blntab-bukrs.
      p_belnr_out = t_blntab-belnr.
      p_gjahr_out = t_blntab-gjahr.
    ENDIF.
 
  ENDFORM.                    "fipi_lanzar_compensacion
 
*&---------------------------------------------------------------------*
*&      Form  fipi_crear_documento
*&---------------------------------------------------------------------*
*       Mediante este perform se puede crear un documento financiero
*----------------------------------------------------------------------*
*  -->  t_ftpost    Cabecera y posiciones de doc. para interfase interna
*                   contab.
*  -->  t_fttax     Impuestos para interfase de contabilizacion interna
*  -->  p_tcode     Transaccion por la cual se quiere crear el documento
*                          FB01 - Contabilizar documento
*                          FBS1 - Registrar documento periodificacion
*                          FB41 - Contabilizar cargo IVA
*                          ABF1 - Contabilizar documento
*                          FBB1 - Contab.valoracion de ME
*                          FBVB - Contab.documento preliminar
*                          FBV1 - Registrar docum.de forma preliminar
*                          FBD5 - Realizar contab. periodica
*  -->  p_no_auth   No comprobar si existe autorizacion para la
*                   transaccion
*  <--  p_bukrs_out Sociedad en la que se creo el documento
*  <--  p_belnr_out N? se documento creado
*  <--  p_gjahr_out Ejercicio en el que se creo el documento
*  <--  p_message   Mensaje que devuelve la creacion del documento
*----------------------------------------------------------------------*
  FORM fipi_crear_documento TABLES t_ftpost  STRUCTURE ftpost
                                   t_fttax   STRUCTURE fttax
                             USING p_tcode     LIKE sy-tcode
                                   p_no_auth   LIKE uf05a-stgrd
                                   p_bukrs_out LIKE bkpf-bukrs
                                   p_belnr_out LIKE bkpf-belnr
                                   p_gjahr_out LIKE bkpf-gjahr
                                   p_message.
 
    DATA: t_blntab  TYPE blntab OCCURS 0 WITH HEADER LINE.
 
    CALL FUNCTION 'POSTING_INTERFACE_DOCUMENT'
      EXPORTING
        i_tcode                        = p_tcode
*     I_SGFUNCT                      = ' '
        i_no_auth                      = p_no_auth
      IMPORTING
        e_msgid                        = sy-msgid
        e_msgno                        = sy-msgno
        e_msgty                        = sy-msgty
        e_msgv1                        = sy-msgv1
        e_msgv2                        = sy-msgv2
        e_msgv3                        = sy-msgv3
        e_msgv4                        = sy-msgv4
*     e_subrc                        = sy-subrc
      TABLES
        t_blntab                       = t_blntab
        t_ftpost                       = t_ftpost
        t_fttax                        = t_fttax
      EXCEPTIONS
        account_missing                = 1
        company_code_missing           = 2
        posting_key_invalid            = 3
        posting_key_missing            = 4
        record_type_invalid            = 5
        transaction_code_invalid       = 6
        amount_format_error            = 7
        too_many_line_items            = 8
        company_code_invalid           = 9
        screen_not_found               = 10
        no_authorization               = 11
        OTHERS                         = 12
              .
    IF NOT sy-msgid IS INITIAL.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
              INTO p_message.
    ENDIF.
 
    READ TABLE t_blntab INDEX 1.
    IF sy-subrc IS INITIAL.
      p_bukrs_out = t_blntab-bukrs.
      p_belnr_out = t_blntab-belnr.
      p_gjahr_out = t_blntab-gjahr.
    ENDIF.
 
  ENDFORM.                    "fipi_lanzar_compensacion
 
*&---------------------------------------------------------------------*
*&      Form  fipi_rellenar_ftpos
*&---------------------------------------------------------------------*
*       Rellena la estructura GT_FTPOS necesarias para la generacion de
*       documentos dependiendo de las estructuras BKPF, BSEG y BSEC y
*       los status de campo para dichas estructuras.
*       Este perform obvia los campos rellenos en las estructuras pero
*       que por status de campo se encuentran invisibles en pantalla y
*       por lo tanto fallaria el batch-input.
*----------------------------------------------------------------------*
*      -->P_BSEG     Datos de posicion
*      -->P_BSEC     Datos de CPD
*      -->P_BKPF     Datos de cabecera
*      -->P_TCODE    Trasaccion mediante la que se creara el documento
*----------------------------------------------------------------------*
  FORM fipi_rellenar_ftpos TABLES t_bseg STRUCTURE bseg
                                  t_bsec STRUCTURE bsec
                            USING p_bkpf TYPE bkpf
                                  p_tcode.
 
 
    DATA l_aux(100).
    FIELD-SYMBOLS <fs_campo>.
    DATA lt_fieldstatus TYPE fieldstatus OCCURS 0 WITH HEADER LINE.
 
    DATA t_bsez TYPE bsez.
    DATA p_cobl LIKE cobl.
 
    PERFORM fipi_status_campo_c
                TABLES
                   lt_fieldstatus
                USING
                   p_tcode
                   p_bkpf-bukrs
                   p_bkpf-blart
                   p_bkpf.
 
    LOOP AT lt_fieldstatus.
 
      IF lt_fieldstatus-status = '+'
      OR lt_fieldstatus-status = '.'.
        IF lt_fieldstatus-longn(3) = 'BSE'.
          CONCATENATE 'T' '_' lt_fieldstatus-longn
                 INTO l_aux.
        ELSE.
          CONCATENATE 'P' '_' lt_fieldstatus-longn
                 INTO l_aux.
        ENDIF.
        ASSIGN (l_aux) TO <fs_campo>.
        IF sy-subrc IS INITIAL.
          rellena_ftpost 'K' 1 lt_fieldstatus-longn <fs_campo>.
        ENDIF.
      ENDIF.
 
    ENDLOOP.
 
    rellena_ftpost 'K' 1 'BKPF-XMWST' p_bkpf-xmwst.
 
    LOOP AT t_bseg.
      READ TABLE t_bsec WITH KEY bukrs = t_bseg-bukrs
                                 belnr = t_bseg-belnr
                                 gjahr = t_bseg-gjahr
                                 buzei = t_bseg-buzei.
      IF NOT sy-subrc IS INITIAL.
        CLEAR t_bsec.
      ENDIF.
      CLEAR t_bsez.
      MOVE-CORRESPONDING t_bsec TO t_bsez.
      MOVE-CORRESPONDING t_bseg TO t_bsez.
      MOVE-CORRESPONDING p_bkpf TO p_cobl.
      MOVE-CORRESPONDING t_bseg TO p_cobl.
 
      PERFORM fipi_status_campo_p
                      TABLES lt_fieldstatus
                       USING p_tcode
                             t_bseg-bukrs
                             t_bseg-bschl
                             t_bseg-hkont
                             t_bseg-umskz
                             t_bseg-koart
                             p_bkpf
                             t_bseg
                             t_bsec
                             t_bsez.
 
      LOOP AT lt_fieldstatus WHERE NOT fldnm = 'HKONT'
                               AND NOT fldnm = 'BSCHL'
                               AND NOT fldnm = 'UMSKZ'
                               AND NOT fldnm = 'ANBWA'.
 
        IF lt_fieldstatus-status = '+'
        OR lt_fieldstatus-status = '.'.
          IF lt_fieldstatus-longn(3) = 'BSE'.
            CONCATENATE 'T' '_' lt_fieldstatus-longn
                   INTO l_aux.
          ELSE.
            CONCATENATE 'P' '_' lt_fieldstatus-longn
                   INTO l_aux.
          ENDIF.
          ASSIGN (l_aux) TO <fs_campo>.
          IF sy-subrc IS INITIAL.
        rellena_ftpost 'P' t_bseg-buzei lt_fieldstatus-longn <fs_campo>.
          ENDIF.
        ENDIF.
 
      ENDLOOP.
      IF sy-subrc IS INITIAL.
        CASE t_bseg-koart. "Clase de cuenta
          WHEN 'A'. "Activos fijos
            rellena_ftpost 'P' t_bseg-buzei 'RF05A-NEWKO' t_bseg-anln1.
          WHEN 'D'. "Deudores
            rellena_ftpost 'P' t_bseg-buzei 'RF05A-NEWKO' t_bseg-kunnr.
          WHEN 'K'. "Acreedores
            rellena_ftpost 'P' t_bseg-buzei 'RF05A-NEWKO' t_bseg-lifnr.
          WHEN 'M'. "Materiales
            rellena_ftpost 'P' t_bseg-buzei 'RF05A-NEWKO' t_bseg-matnr.
          WHEN 'S'. "Cuentas de mayor
            rellena_ftpost 'P' t_bseg-buzei 'RF05A-NEWKO' t_bseg-hkont.
        ENDCASE.
        rellena_ftpost 'P' t_bseg-buzei 'RF05A-NEWBS' t_bseg-bschl.
        rellena_ftpost 'P' t_bseg-buzei 'RF05A-NEWUM' t_bseg-umskz.
        rellena_ftpost 'P' t_bseg-buzei 'RF05A-NEWBW' t_bseg-anbwa.
      ENDIF.
 
 
    ENDLOOP.
 
    DELETE ADJACENT DUPLICATES FROM gt_ftpost.
 
  ENDFORM.                   "fipi_rellenar_ftpos
 
*-----------------------------------------------------------------------
*        Form fipi_next_dynpro
*-----------------------------------------------------------------------
*        Devuelve la siguiente dynpro, inspirado en el form
*        DYNPRO_ERMITTELN del grupo de funciones FIPI
*        (USO INTERNO)
*-----------------------------------------------------------------------
  FORM fipi_next_dynpro USING p_tcode TYPE tcode
                              p_bukrs TYPE bukrs
                              p_bschl TYPE bschl
                              p_konto TYPE hkont
                              p_umskz TYPE umskz
                              p_dynnr
                              p_mpool
                              p_winnr.
    .
    DATA: konto_n(10)   TYPE n.
    DATA: winfk LIKE t019w-winfk.   " Window-Funktion (T019W)
*    DATA: winnr LIKE t019w-winnr.   " Window-Nummer
 
    DATA l_mpool LIKE t019w-mpool.
    DATA l_dynnr LIKE tstc-dypno.
 
* Se recuperan los datos de transaccion
    DATA st_t020   LIKE t020.
    SELECT SINGLE *
      FROM t020
      INTO st_t020
     WHERE tcode = p_tcode.
    IF NOT sy-subrc IS INITIAL.
      EXIT.
    ENDIF.
 
    l_mpool = p_mpool.
    l_dynnr = p_dynnr.
 
*------- Tabelle TBSL  lesen: (1. interne Tabelle, 2. ATAB-Tabelle) ----
    LOOP AT fipi_xtbsl WHERE bschl = p_bschl.
      EXIT.
    ENDLOOP.
    IF sy-subrc NE 0.
      SELECT SINGLE * FROM tbsl INTO fipi_xtbsl WHERE bschl = p_bschl.
      IF sy-subrc = 0.
        APPEND fipi_xtbsl.
      ELSE.
*     exit, wg  FB05 ohne Buchungszeilen
        EXIT.
*     MESSAGE E008 WITH BSCHL RAISING POSTING_KEY_INVALID.
      ENDIF.
    ENDIF.
 
*------- Windowfunktion setzen -----------------------------------------
    CLEAR winfk.
    CASE fipi_xtbsl-koart.
      WHEN 'D'.
        winfk = 'ZKOD'.
      WHEN 'K'.
        winfk = 'ZKOK'.
      WHEN 'S'.
        winfk = 'ZKOS'.
      WHEN 'A'.
        winfk = 'ZKOA'.
    ENDCASE.
 
*------- Steuerkategorie ermitteln -------------------------------------
 
    IF fipi_xtbsl-koart = 'S'.
      IF p_konto CO ' 0123456789'.
        konto_n = p_konto.
        p_konto   = konto_n.
      ENDIF.
      DATA st_skb1 LIKE skb1.
      SELECT SINGLE * FROM skb1 INTO st_skb1 WHERE bukrs = p_bukrs
                                               AND saknr = p_konto.
    ENDIF.
 
 
*------- Dynpronummern ermitteln ---------------------------------------
    CALL FUNCTION 'NEXT_DYNPRO_SEARCH'
         EXPORTING
              i_bschl  = p_bschl
              i_bukrs  = p_bukrs
              i_mwskzs = st_skb1-mwskz
              i_tcode  = p_tcode
              i_umskz  = p_umskz
              i_winfk  = winfk
         IMPORTING
              e_dynnra = l_dynnr
              e_mpool  = l_mpool
              e_winnrz = p_winnr
         EXCEPTIONS  "nur noch nicht bereits geprueften Ausnahmen
              bukrs_nf = 1
              dynnr_nf = 2
              tcodd_nf = 3
              tcodm_nf = 4
              winnr_nf = 5
              OTHERS   = 6.
 
    IF sy-subrc <> 0.
      CASE sy-subrc.
        WHEN '1'.
          MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
                  RAISING company_code_invalid.
        WHEN '2' OR '5' OR '6'.
          MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
                  RAISING screen_not_found.
        WHEN '3' OR '4'.
          MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
                  RAISING transaction_code_invalid.
      ENDCASE.
    ENDIF.
 
* Dynpro andern bei der Umbuchung der Steuerlast
    IF p_tcode = 'FB41' AND l_dynnr = '312'.
      l_dynnr = '300'.
    ENDIF.
 
    p_mpool = l_mpool.
    p_dynnr = l_dynnr.
 
  ENDFORM.                    " fipi_next_dynpro
 
*&---------------------------------------------------------------------*
*&      Form  fipi_status_campo_p
*&---------------------------------------------------------------------*
*       Devuelve el status de campo de la posicion en cuestion que se
*       solicite. Habra que hacer una llamada a este perform por cada
*       posicion del documento que deseemos crear / comprobar.
*----------------------------------------------------------------------*
*      <--PT_FIELDSTATUS  Estructura de status campo
*      -->P_TCODE         Transaccion mediante la que se cargara el
*                         documento
*      -->P_BUKRS         Sociedad en la que se cargara el documento
*      -->P_BSCHL         Clave de contabilizacion de la posicion
*      -->P_HKONT         Cuenta contable de la posicion
*      -->P_UMSKZ         Indicador CME de la posicion
*      -->P_KOART         Clase de cuenta de la posicion
*      -->P_BKPF          Datos de cabecera
*      -->P_BSEG          Datos de posicion
*      -->P_BSEC          Datos de CPD
*      -->P_BSEZ          Informacion adicional de apunte (dialogo)
*----------------------------------------------------------------------*
  FORM fipi_status_campo_p TABLES pt_fieldstatus STRUCTURE fieldstatus
                            USING p_tcode
                                  p_bukrs
                                  p_bschl
                                  p_hkont
                                  p_umskz
                                  p_koart
                                  p_bkpf STRUCTURE bkpf
                                  p_bseg STRUCTURE bseg
                                  p_bsec STRUCTURE bsec
                                  p_bsez STRUCTURE bsez.
 
    REFRESH pt_fieldstatus.
 
    DATA st_tbsl   LIKE tbsl.
    DATA st_screen LIKE screen.
    DATA st_t020   LIKE t020.
    DATA l_winnr   LIKE t019w-winnr.
    DATA f_flag_cpd.
    DATA f_flag_bloque_imputacion.
 
    DATA lt_dynp_id LIKE dynp_id OCCURS 0 WITH HEADER LINE.
 
    DATA l_hkont TYPE bseg-hkont.
 
    DATA p_lfa1 LIKE lfa1.
    DATA p_kna1 LIKE kna1.
    DATA p_lfb1 LIKE lfb1.
    DATA p_knb1 LIKE knb1.
 
    DATA l_ktogr LIKE lfa1-ktock.
 
    IF NOT p_bsec IS INITIAL.
      CASE p_bseg-koart.
        WHEN 'K'.
          SELECT SINGLE *
            FROM lfa1
            INTO p_lfa1
           WHERE lifnr = p_bseg-lifnr.
          IF NOT p_lfa1-xcpdk IS INITIAL.
            f_flag_cpd = 'X'.
            l_ktogr = p_lfa1-ktock.
          ENDIF.
        WHEN 'D'.
          SELECT SINGLE *
            FROM kna1
            INTO p_kna1
           WHERE kunnr = p_bseg-kunnr.
          IF NOT p_kna1-xcpdk IS INITIAL.
            f_flag_cpd = 'X'.
            l_ktogr = p_kna1-ktokd.
          ENDIF.
      ENDCASE.
    ENDIF.
 
    CASE p_koart.
      WHEN 'K'.
        SELECT SINGLE *
          FROM knb1
          INTO p_knb1
         WHERE kunnr = p_hkont
           AND bukrs = p_bukrs.
        l_hkont = p_lfb1-akont.
 
      WHEN 'D'.
        SELECT SINGLE *
          FROM lfb1
          INTO p_lfb1
         WHERE lifnr = p_hkont
           AND bukrs = p_bukrs.
        l_hkont = p_lfb1-akont.
      WHEN 'S'.
        l_hkont = p_hkont.
    ENDCASE.
 
* Se recuperan los datos de transaccion
    SELECT SINGLE *
      FROM t020
      INTO st_t020
     WHERE tcode = p_tcode.
 
    CHECK NOT l_hkont IS INITIAL.
 
    CALL FUNCTION 'FI_FIELD_SELECTION_DETERMINE'
         EXPORTING
              i_bschl     = p_bschl
              i_bukrs     = p_bukrs
              i_saknr     = l_hkont
         IMPORTING
              e_faus1     = st_tbsl-faus1
              e_faus2     = st_tbsl-faus2
         EXCEPTIONS
              customizing = 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.
 
    FIELD-SYMBOLS <flg_more_active>.
 
    DATA char.
    DATA int_coblf LIKE coblf OCCURS 0 WITH HEADER LINE.
    DATA p_cobl LIKE cobl.
 
    MOVE-CORRESPONDING p_bkpf TO p_cobl.
    MOVE-CORRESPONDING p_bseg TO p_cobl.
    sy-binpt = 'X'.
    PERFORM kontierungsblock_ermitteln(sapff001)
            TABLES int_coblf
            USING  char(1)
                   st_tbsl-faus1 st_tbsl-faus2 p_bseg-ktosl.
 
    DATA xbuzpp LIKE bseg-buzei.    " -> COBL  Note 383578
 
    PERFORM kontierungsblock_send_pbo(sapff001)
              TABLES   int_coblf
           USING    p_bseg p_bsez p_cobl                    "Note 390138
                    xbuzpp                                  "Note 383578
              CHANGING dynp_id-dnum dynp_id-prog.
    CLEAR sy-binpt.
 
    ASSIGN ('(SAPLKACB)FLG_MORE_ACTIVE') TO <flg_more_active>.
    IF <flg_more_active> IS ASSIGNED.
      f_flag_bloque_imputacion = <flg_more_active>.
    ENDIF.
 
    IF NOT f_flag_cpd IS INITIAL.
      dynp_id-dnum = '0100'.
      dynp_id-prog = 'SAPLFCPD'.
      APPEND dynp_id TO lt_dynp_id.
    ENDIF.
 
    PERFORM fipi_next_dynpro
                USING
                   p_tcode
                   p_bukrs
                   p_bschl
                   l_hkont
                   p_umskz
                   dynp_id-dnum
                   dynp_id-prog
                   l_winnr.
 
    APPEND dynp_id TO lt_dynp_id.
    IF NOT l_winnr IS INITIAL.
      dynp_id-dnum = l_winnr.
      APPEND dynp_id TO lt_dynp_id.
    ENDIF.
 
    IF NOT f_flag_bloque_imputacion IS INITIAL.
      dynp_id-dnum = '0002'.
      dynp_id-prog = 'SAPLKACB'.
      APPEND dynp_id TO lt_dynp_id.
    ENDIF.
 
 
    LOOP AT lt_dynp_id INTO dynp_id.
 
      IMPORT DYNPRO h f e m ID dynp_id.
      IF sy-subrc <> 0.
        MESSAGE e514(37) WITH dynp_id-prog dynp_id-dnum.
      ENDIF.
 
 
      LOOP AT f.
 
        CHECK f-fill CA 'RA '. " Solo radiobuttons, checks
 
        IF f-fill IS INITIAL.
          CHECK f-flg1 O flg1edt.
        ENDIF.
 
 
        CLEAR st_screen.
        st_screen-name      = f-fnam.
        st_screen-group1    = f-grp1.
        st_screen-group2    = f-grp2.
        st_screen-group3    = f-grp3.
        st_screen-group4    = f-grp4.
        st_screen-input     = 0.
        st_screen-output    = 0.
        st_screen-required  = 0.
        st_screen-invisible = 0.
 
        IF f-flg1 O flg1edt.             "Schablone
          IF f-fmb1 Z fmb1ges. st_screen-input     = 1. ENDIF.
          IF f-flg3 O flg3out. st_screen-output    = 1. ENDIF.
        ENDIF.
 
        IF f-flg3 O flg3obl. st_screen-required    = 1. ENDIF.
 
        CASE dynp_id-prog.
          WHEN 'SAPLFCPD'.
            PERFORM fipi_status_field_cpd
                        USING
                           p_bseg-koart
                           l_ktogr
                           st_screen-group1
                           st_screen-input
                           st_screen-output
                           st_screen-required
                           st_screen-invisible.
          WHEN 'SAPLKACB'.
            DATA l_tabnam(30).
            SPLIT st_screen-name AT '-' INTO l_tabnam int_coblf-fdnam.
            IF sy-subrc IS INITIAL.
              READ TABLE int_coblf WITH KEY fdnam = int_coblf-fdnam.
              IF sy-subrc IS INITIAL.
                st_screen-invisible = int_coblf-invisible.
                st_screen-output    = int_coblf-output.
                st_screen-required  = int_coblf-required.
              ELSE.
                st_screen-invisible = 1.
                st_screen-input     = 0.
                st_screen-output    = 0.
                st_screen-required  = 0.
              ENDIF.
            ENDIF.
 
          WHEN OTHERS.
 
            CALL FUNCTION 'LINEITEM_FIELD_MODIFY'
              EXPORTING
                i_name            = st_screen-name
                i_group1          = st_screen-group1
                i_group2          = st_screen-group2
                i_group3          = st_screen-group3
                i_group4          = st_screen-group4
                i_faus1           = st_tbsl-faus1
                i_faus2           = st_tbsl-faus2
                i_aktyp           = st_t020-aktyp
                i_koart           = p_koart
*           I_FIRSTCALL       =
                i_bkpf            = p_bkpf
                i_bseg            = p_bseg
                i_bsez            = p_bsez
                i_bsec            = p_bsec
              CHANGING
                c_input           = st_screen-input
                c_output          = st_screen-output
                c_required        = st_screen-required
                c_invisible       = st_screen-invisible
              EXCEPTIONS
                OTHERS                 = 1        .
 
 
 
* Campos especiales. (copiado de form ZEILE_MODIFIZIEREN en programa
* SAPFF001)
            IF st_screen-group2 > 0
          AND st_screen-invisible = 0.                    "#EC PORTABLE
              DATA rc LIKE sy-subrc.
              rc = 0.
 
              bkpf = p_bkpf.
              bseg = p_bseg.
              bsec = p_bsec.
              bsez = p_bsez.
 
              SELECT SINGLE *
                FROM skb1
               WHERE bukrs = p_bseg-bukrs
                 AND saknr = p_bseg-hkont.
 
              PERFORM dynpro_modif_int
                   IN PROGRAM sapff001
                      USING    st_screen-group2 st_screen-name
                      CHANGING rc.
              CASE rc.
                WHEN 0.
*           new return value: if visibility of field depends on value of
*           another screen field, the field must be checked at pai, see
*           note 519945.
                WHEN 6.
                  st_screen-required  = 0.
                WHEN 8.
                  st_screen-input     = 0.
                  st_screen-required  = 0.
                WHEN OTHERS.
                  st_screen-input     = 0.
                  st_screen-output    = 0.
                  st_screen-required  = 0.
                  st_screen-invisible = 1.
              ENDCASE.
            ENDIF.
        ENDCASE.
 
        CLEAR pt_fieldstatus.
        SPLIT st_screen-name AT '-'
         INTO pt_fieldstatus-tabnm
              pt_fieldstatus-fldnm.
        IF NOT sy-subrc IS INITIAL.
          CLEAR pt_fieldstatus.
        ENDIF.
        pt_fieldstatus-fauna  = 'SKB1-FAUS1'.
        pt_fieldstatus-modif  = st_screen-group1.
        pt_fieldstatus-longn  = st_screen-name.
        pt_fieldstatus-status = '.'.
        IF NOT st_screen-required = 0.
          pt_fieldstatus-status = '+'.
        ELSEIF NOT st_screen-invisible = 0.
          pt_fieldstatus-status = '-'.
        ELSEIF st_screen-input = 0.
          pt_fieldstatus-status = '*'.
        ENDIF.
 
        APPEND pt_fieldstatus.
 
      ENDLOOP.
 
    ENDLOOP.
 
    SORT pt_fieldstatus.
    DELETE ADJACENT DUPLICATES FROM pt_fieldstatus.
 
  ENDFORM.                    " fipi_status_campo_p


continued in the next post
Back to top
View user's profile Send private message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Wed Jul 02, 2008 9:20 am    Post subject: Reply with quote

Code:
*&---------------------------------------------------------------------*
*&      Form  fipi_status_campo_c
*&---------------------------------------------------------------------*
*       Devuelve el status de campo de la pantalla inicial del documento
*       a cargar que ser rellena con los datos de cabecera.
*----------------------------------------------------------------------*
*      -->PT_FIELDSTATUS  Estructura de status campo
*      -->P_TCODE         Transacción mediante la que se cargará el
*                         documento
*      -->P_BUKRS         Sociedad en la que se cargara el documento
*      -->P_BLART         Clase de documento
*      -->P_BKPF          Datos de cabecera
*----------------------------------------------------------------------*
  FORM fipi_status_campo_c TABLES pt_fieldstatus STRUCTURE fieldstatus
                            USING p_tcode
                                  p_bukrs
                                  p_blart
                                  p_bkpf STRUCTURE bkpf.
 
    DATA st_screen    LIKE screen.
    DATA st_screen2   LIKE screen.
    DATA st_t020      LIKE t020.
    DATA st_acgl_head LIKE acgl_head.
    DATA st_rfopt     LIKE rfopt.
    DATA st_rfopte    LIKE rfopte.
    DATA st_rfopt2    LIKE rfopt2.
    DATA st_tstc      TYPE tstc.
    DATA l_fieldname  TYPE fieldname.
    DATA l_changed    TYPE boolean.
 
    REFRESH pt_fieldstatus.
 
    MOVE-CORRESPONDING p_bkpf TO st_acgl_head.
 
* Se recuperan los datos de transacción
    SELECT SINGLE *
      FROM t020
      INTO st_t020
     WHERE tcode = p_tcode.
 
    SELECT SINGLE *
      FROM tstc
      INTO st_tstc
     WHERE tcode = p_tcode.
 
    SELECT SINGLE *
      FROM t003
     WHERE blart = p_bkpf-blart.
 
    SELECT SINGLE *
      FROM t001
     WHERE bukrs = bkpf-bukrs.
 
    SELECT SINGLE *
      FROM t005
     WHERE land1 = t001-land1.
 
    bkpf = p_bkpf.
 
    dynp_id-prog = st_tstc-pgmna.
    dynp_id-dnum = st_tstc-dypno.
 
    IMPORT DYNPRO h f e m ID dynp_id.
    IF sy-subrc <> 0.
      MESSAGE e514(37) WITH dynp_id-prog dynp_id-dnum.
    ENDIF.
 
    CALL FUNCTION 'DOCHEADERFIELD_INIT'
     EXPORTING
       i_firstcall             = 'X'
*      I_KOART                 =
       i_t020                  = st_t020
*      I_BUSCS                 =
       i_document_exists       = ' '
     IMPORTING
       e_rfopt                 = st_rfopt
       e_rfopt2                = st_rfopt2
      CHANGING
        c_head                 = st_acgl_head
      EXCEPTIONS
        OTHERS                 = 1
              .
 
    LOOP AT f.
 
      CHECK f-fill CA 'RA '. " Solo radiobuttons, checks
 
      IF f-fill IS INITIAL.
        CHECK f-flg1 O flg1edt.
      ENDIF.
 
 
      CLEAR st_screen.
      st_screen-name      = f-fnam.
      l_fieldname         = f-fnam.
      st_screen-group1    = f-grp1.
      st_screen-group2    = f-grp2.
      st_screen-group3    = f-grp3.
      st_screen-group4    = f-grp4.
      st_screen-input     = 0.
      st_screen-output    = 0.
      st_screen-required  = 0.
      st_screen-invisible = 0.
 
      IF f-flg1 O flg1edt.             "Schablone
        IF f-fmb1 Z fmb1ges. st_screen-input     = 1. ENDIF.
        IF f-flg3 O flg3out. st_screen-output    = 1. ENDIF.
      ENDIF.
 
      IF f-flg3 O flg3obl. st_screen-required    = 1. ENDIF.
 
 
      GET PARAMETER ID 'FO3' FIELD st_rfopte.
 
      CALL FUNCTION 'DOCHEADERFIELD_MODIFY'
        EXPORTING
          i_bkpf                  = p_bkpf
          i_sgroup2               = st_screen-group2
          i_sgroup3               = st_screen-group3
          i_sgroup4               = st_screen-group4
          i_parame                = st_rfopte
          i_param                 = st_rfopt
          i_t020                  = st_t020
          i_name                  = l_fieldname
*         I_FIRSTCALL             =
*         I_XSTVR                 =
*         I_ANZBZ                 = '0'
*         I_DOCUMENT_EXISTS       =
*         I_STATUS                = '1'
*         I_HEADVALCH             =
        IMPORTING
          e_screeninput           = st_screen2-input
          e_screenoutput          = st_screen2-output
          e_screenrequired        = st_screen2-required
          e_screeninvisible       = st_screen2-invisible
          e_changed               = l_changed
        EXCEPTIONS
          OTHERS                 = 1.
 
      IF NOT l_changed IS INITIAL.
        st_screen-input     = st_screen2-input.
        st_screen-output    = st_screen2-output.
        st_screen-required  = st_screen2-required.
        st_screen-invisible = st_screen2-invisible.
      ENDIF.
 
      CLEAR pt_fieldstatus.
      SPLIT st_screen-name AT '-'
       INTO pt_fieldstatus-tabnm
            pt_fieldstatus-fldnm.
      IF NOT sy-subrc IS INITIAL.
        CLEAR pt_fieldstatus.
      ENDIF.
      pt_fieldstatus-fauna  = 'SKB1-FAUS1'.
      pt_fieldstatus-modif  = st_screen-group1.
      pt_fieldstatus-longn  = st_screen-name.
      pt_fieldstatus-status = '.'.
      IF NOT st_screen-required = 0.
        pt_fieldstatus-status = '+'.
      ELSEIF NOT st_screen-invisible = 0.
        pt_fieldstatus-status = '-'.
      ELSEIF st_screen-input = 0.
        pt_fieldstatus-status = '*'.
      ENDIF.
 
* Campos especiales
      CASE pt_fieldstatus-longn.
        WHEN 'BKPF-BELNR'.
* Se verifica la asignación interna o externa de numeros.
          IF NOT p_bkpf-blart IS INITIAL.
            CALL FUNCTION 'FI_DOCUMENT_NUMBER_CHECK'
                 EXPORTING
                      i_belnr                    = p_bkpf-belnr
                      i_blart                    = p_bkpf-blart
                      i_bukrs                    = p_bkpf-bukrs
                      i_gjahr                    = p_bkpf-gjahr
                      i_bstat                    = p_bkpf-bstat
*                      i_rldnr                    = p_bkpf-rldnr
                 EXCEPTIONS
                      external_number_assignment = 1
                      internal_number_assignment = 2
                      number_already_assigned    = 3
                      number_not_in_range        = 4
                      OTHERS                     = 5.
            IF sy-subrc = 1.
              pt_fieldstatus-status = '+'.
            ELSEIF sy-subrc = 2.
              pt_fieldstatus-status = '-'.
            ENDIF.
          ENDIF.
        WHEN 'BKPF-BKTXT'.
          IF  t003-xmtxt NE space.
            pt_fieldstatus-status = '+'.
          ENDIF.
        WHEN 'BKPF-XBLNR'.
*            ------ mussfeld referenznummer ? -------------
          IF  t003-xmref NE space.
            pt_fieldstatus-status = '+'.
          ENDIF.
        WHEN OTHERS.
      ENDCASE.
 
      IF  st_screen-group2 = 048 "Datos de anulación
      AND sy-tcode <> 'FBS1'
      AND dynp_id-prog = 'SAPMF05A'
      AND dynp_id-dnum = '0100'.
        pt_fieldstatus-status = '-'.
      ENDIF.
 
      APPEND pt_fieldstatus.
 
    ENDLOOP.
 
    SORT pt_fieldstatus.
    DELETE ADJACENT DUPLICATES FROM pt_fieldstatus.
 
 
  ENDFORM. "fipi_status_campo_c
 
 
*&---------------------------------------------------------------------*
*&      Form  fipi_chequear_errores
*&---------------------------------------------------------------------*
*       Este include devuelve mediante el status de campo los campos que
*       le faltan a las structuras BKPF, BSEG y BSEC. (Si el campo está
*       vacío y sin embargo es obligatorio devuelve error)
*----------------------------------------------------------------------*
*      <--T_BAPIRET  Errores del tipo bapiret2
*      -->P_BSEG     Datos de posición
*      -->P_BSEC     Datos de CPD
*      -->P_BKPF     Datos de cabecera
*      -->P_TCODE    Trasacción mediante la que se creará el documento
*----------------------------------------------------------------------*
  FORM fipi_chequear_errores TABLES t_bapiret STRUCTURE bapiret2
                                    t_bseg    STRUCTURE bseg
                                    t_bsec    STRUCTURE bsec
                              USING p_bkpf    TYPE bkpf
                                    p_tcode.
 
 
    DATA l_aux(100).
    FIELD-SYMBOLS <fs_campo>.
    DATA lt_fieldstatus TYPE fieldstatus OCCURS 0 WITH HEADER LINE.
    DATA st_dd03m TYPE dd03m.
    DATA t_bsez TYPE bsez.
 
    DEFINE fipi_bapiret.
      t_bapiret-type       = &1.
      t_bapiret-id         = &2.
      t_bapiret-number     = &3.
      t_bapiret-message_v1 = &4.
      t_bapiret-message_v2 = &5.
      t_bapiret-message_v3 = &6.
      t_bapiret-message_v4 = &7.
      message id t_bapiret-id
         type t_bapiret-type
       number t_bapiret-number
         with t_bapiret-message_v1
              t_bapiret-message_v2
              t_bapiret-message_v3
              t_bapiret-message_v4
         into t_bapiret-message.
      append t_bapiret.
    END-OF-DEFINITION.
 
* Se recuperan los datos de transacción
    DATA st_t020   LIKE t020.
    SELECT SINGLE *
      FROM t020
      INTO st_t020
     WHERE tcode = p_tcode.
    IF NOT sy-subrc IS INITIAL.
* El CódT & no está previsto (notifique a responsable sistema).
      fipi_bapiret 'E' 'F5' '512' p_tcode
                                 
                                 
                                  .
      EXIT.
    ENDIF.
 
 
    REFRESH t_bapiret.
    PERFORM fipi_status_campo_c
                TABLES
                   lt_fieldstatus
                USING
                   p_tcode
                   p_bkpf-bukrs
                   p_bkpf-blart
                   p_bkpf.
 
    LOOP AT lt_fieldstatus.
 
      IF lt_fieldstatus-longn(3) = 'BSE'.
        CONCATENATE 'T' '_' lt_fieldstatus-longn
               INTO l_aux.
      ELSE.
        CONCATENATE 'P' '_' lt_fieldstatus-longn
               INTO l_aux.
      ENDIF.
      ASSIGN (l_aux) TO <fs_campo>.
      IF sy-subrc IS INITIAL.
        IF lt_fieldstatus-status = '+'
       AND <fs_campo> IS INITIAL.
          SELECT SINGLE *
            FROM dd03m
            INTO st_dd03m
           WHERE tabname    = lt_fieldstatus-tabnm
             AND fieldname  = lt_fieldstatus-fldnm
             AND ddlanguage = sy-langu.
 
*   El campo &1(&2) es campo entrada obligatorio: Indique valor
          fipi_bapiret 'E' 'RSM1' '059' lt_fieldstatus-fldnm
                                        st_dd03m-ddtext
                                       
                                        .
        ENDIF.
      ENDIF.
 
    ENDLOOP.
 
 
 
    LOOP AT t_bseg.
      READ TABLE t_bsec WITH KEY bukrs = t_bseg-bukrs
                                 belnr = t_bseg-belnr
                                 gjahr = t_bseg-gjahr
                                 buzei = t_bseg-buzei.
      IF NOT sy-subrc IS INITIAL.
        CLEAR t_bsec.
      ENDIF.
      CLEAR t_bsez.
      MOVE-CORRESPONDING t_bsec TO t_bsez.
      MOVE-CORRESPONDING t_bseg TO t_bsez.
 
 
      CALL FUNCTION 'FI_GL_ACCOUNT_CHECK'
           EXPORTING
                i_bukrs      = t_bseg-bukrs
                i_saknr      = t_bseg-hkont
           EXCEPTIONS
                gl_account_a = 1
                gl_account_b = 2
                OTHERS       = 3.
      IF sy-subrc <> 0.
        fipi_bapiret sy-msgty sy-msgid sy-msgno
                                       sy-msgv1
                                       sy-msgv2
                                       sy-msgv3
                                       sy-msgv4.
        CONTINUE.
      ENDIF.
 
 
 
      PERFORM fipi_status_campo_p
                      TABLES lt_fieldstatus
                       USING p_tcode
                             t_bseg-bukrs
                             t_bseg-bschl
                             t_bseg-hkont
                             t_bseg-umskz
                             t_bseg-koart
                             p_bkpf
                             t_bseg
                             t_bsec
                             t_bsez.
 
      LOOP AT lt_fieldstatus.
 
        IF lt_fieldstatus-longn(3) = 'BSE'.
          CONCATENATE 'T' '_' lt_fieldstatus-longn
                 INTO l_aux.
        ELSE.
          CONCATENATE 'P' '_' lt_fieldstatus-longn
                 INTO l_aux.
        ENDIF.
        ASSIGN (l_aux) TO <fs_campo>.
        IF sy-subrc IS INITIAL.
          IF lt_fieldstatus-status = '+'
         AND <fs_campo> IS INITIAL.
            SELECT SINGLE *
              FROM dd03m
              INTO st_dd03m
             WHERE tabname    = lt_fieldstatus-tabnm
               AND fieldname  = lt_fieldstatus-fldnm
               AND ddlanguage = sy-langu.
 
*   El campo &1(&2) es campo entrada obligatorio: Indique valor
            fipi_bapiret 'E' 'RSM1' '059' lt_fieldstatus-fldnm
                                          st_dd03m-ddtext
                                         
                                          .
          ENDIF.
        ENDIF.
 
      ENDLOOP.
 
 
    ENDLOOP.
 
    DELETE ADJACENT DUPLICATES FROM gt_ftpost.
 
  ENDFORM.                   "fipi_chequear_errores
 
 
 
*&---------------------------------------------------------------------*
*&      Form  fipi_status_field_cpd: inspirado en MODULE D0100_EXT_MODIF
*&      del programa LFCPDO00
*&---------------------------------------------------------------------*
*       Devuelve modificaciones especiales para status de campo de
*       estructura CPD
*       (USO INTERNO)
*----------------------------------------------------------------------*
  FORM fipi_status_field_cpd USING p_koart
                                   p_ktogr
                                   p_group1
                                   p_input
                                   p_output
                                   p_required
                                   p_invisible.
 
    DATA st_t077d LIKE t077d OCCURS 0 WITH HEADER LINE.
    DATA st_t077k LIKE t077k OCCURS 0 WITH HEADER LINE.
    DATA fausw(120) TYPE c. "Feldstatusleiste
    DATA offset(3)  TYPE p. "Offset für FAUSW
*------- Feldstatus der Referenzkontengruppe besorgen ------------------
    IF p_koart = 'D'.
      SELECT SINGLE * FROM t077d
                      INTO st_t077d
             WHERE ktokd = p_ktogr.
      fausw(40)    = st_t077d-fausa.
      fausw+40(40) = st_t077d-faus1.
      fausw+80(40) = st_t077d-faus2.
    ELSE.
      SELECT SINGLE * FROM t077k
                      INTO st_t077k
             WHERE ktokk = p_ktogr.
      fausw(40)    = st_t077k-fausa.
      fausw+40(40) = st_t077k-faus1.
      fausw+80(40) = st_t077k-faus2.
    ENDIF.
 
*------- Felder modifizieren, ausgeblendete Felder in AUSTAB merken, ---
*        nur angezeigte Felder in ANZTAB merken (für Kopierfunktion);
*        STCEG bei den Stammdaten hat beim Debitor Screen-Group1 '034'
*        (wie auf dem CPD-Bild), beim creditor aber '024'.
 
    CHECK p_group1 <> space
    OR    p_group1 <> 0.
    IF  p_group1 = '034'
    AND p_koart = 'K'.
      offset = 23.
    ELSEIF p_group1 = '051'
    AND    p_koart = 'K'.
      offset = 33.
    ELSE.
      offset = p_group1 - 1.
    ENDIF.
    CASE fausw+offset(1).
      WHEN '+'.
        p_required  = 1.
      WHEN '.'.
        p_required  = 0.
      WHEN '*'.
        p_required  = 0.
        p_input     = 0.
      WHEN '-'.
        p_required  = 0.
        p_input     = 0.
        p_output    = 0.
        p_invisible = 1.
    ENDCASE.
 
ENDFORM.                    "fipi_status_field_cpd
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 -> FI 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.