Mostrar Mensajes

Esta sección te permite ver todos los posts escritos por este usuario. Ten en cuenta que sólo puedes ver los posts escritos en zonas a las que tienes acceso en este momento.


Mensajes - oscar

Páginas: 1 ... 4 5 [6] 7 8
76
Programación ABAP / Re: Campo NULL
« en: 28 de Septiembre de 2007, 01:05:39 pm »
Hola Carlos.

Un campo NULL en un campo vacío.

Te lo explico con un ejemplo que se entenderá mejor:

Tu tienes una tabla que contiene registros.
A esa tabla le creas un campo nuevo.
Entonces ocurre que esa tabla aparece con los campos vacíos, a esos campos se les denomina campos NULL.

Esto tiene bastante importancia porque generalmente cuando hacemos un:
  SELECT SINGLE * FROM x_tabla
                 WHERE x_campo IS INITIAL.


Si "x_campo" es NULL no nos saldrán todos los registros que queremos.

Dos soluciones para ello:
- La primera es hacer un UPDATE a la tabla de esta forma.
    UPDATE x_tabla SET x_campo = ' '.

De esta forma conseguimos que el campo deje de ser NULL.

- Y la segunda sería hacer este tipo de SELECT:
    SELECT SINGLE * FROM x_tabla
                   WHERE x_campo IS INITIAL OR
                         x_campo IS NULL.



Un saludo,
Oscar.

77
Programación ABAP / MOVIDO: Buscamos Analistas Programadores
« en: 27 de Septiembre de 2007, 08:34:23 am »

78
Reports / Como descargar una imagen de la SE78
« en: 20 de Septiembre de 2007, 01:12:28 pm »
Alguna vez has intentado descargarte una imagen de la SE78 porque la habías perdido?  ???

Este en un programa que te permite bajar cualquier imagen que tengas, de SAP... a tu PC.  ;D



*&---------------------------------------------------------------------*
*& Report  ZRECUPERAR_IMAGEN_SE78
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zrecuperar_imagen_se78.

DATA: l_bytecount TYPE i,
      l_tdbtype LIKE stxbitmaps-tdbtype,
      l_content TYPE STANDARD TABLE OF bapiconten
      INITIAL SIZE 0.

DATA: graphic_size TYPE i.

DATA: BEGIN OF graphic_table OCCURS 0,
      line(255) TYPE x,
      END OF graphic_table.


DATA: btype LIKE  stxbitmaps-tdbtype.


SELECTION-SCREEN BEGIN OF BLOCK uno WITH FRAME TITLE text-001.
PARAMETERS: name_img LIKE stxbitmaps-tdname DEFAULT 'ENJOY',
            filename TYPE  string DEFAULT 'C:\Oscar\Imagen_recup.bmp'.

SELECTION-SCREEN SKIP.

PARAMETERS: p_bcol RADIOBUTTON GROUP rad1,
            p_bmon RADIOBUTTON GROUP rad1.
SELECTION-SCREEN END OF BLOCK uno.



IF p_bcol = 'X'.
  btype = 'BCOL'.
ELSE.
  btype = 'BMON'.
ENDIF.


CALL FUNCTION 'SAPSCRIPT_GET_GRAPHIC_BDS'
  EXPORTING
    i_object       = 'GRAPHICS'
    i_name         = name_img    " Nombre del Logo
    i_id           = 'BMAP'
    i_btype        = btype
  IMPORTING
    e_bytecount    = l_bytecount
  TABLES
    content        = l_content
  EXCEPTIONS
    not_found      = 1
    bds_get_failed = 2
    bds_no_content = 3
    OTHERS         = 4.


CALL FUNCTION 'SAPSCRIPT_CONVERT_BITMAP'
  EXPORTING
    old_format               = 'BDS'
    new_format               = 'BMP'
    bitmap_file_bytecount_in = l_bytecount
  IMPORTING
    bitmap_file_bytecount    = graphic_size
  TABLES
    bds_bitmap_file          = l_content
    bitmap_file              = graphic_table
  EXCEPTIONS
    OTHERS                   = 1.



CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
    bin_filesize = graphic_size
    filename     = filename
    filetype     = 'BIN'
  TABLES
    data_tab     = graphic_table.

IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.




79
Programación ABAP / Re: autorizaciones
« en: 10 de Septiembre de 2007, 03:56:54 pm »
Puedes probar con esto.

http://www.abap.es/Fichero_debuggear_POPUPS.htm

No confío mucho en que sea la solución porque el comando que se esta ejecutando es el '/h', pero prueba por si acaso.

Otra solución sería la de poner en el mismo código del programa un BREAK-POINT.
Pero si no tienes autorización para el '/h', me imagino que tampoco lo tengas para modificar un report.


Un saludo.

80
Reports / Re: Enviar mail a un correo externo
« en: 10 de Septiembre de 2007, 08:43:36 am »
La versión en la que estoy trabajando es la ECC 6.0.

Me imagino que la función 'SO_OBJECT_SEND' si que exista en la versión que trabajas. Tal cual está el código escrito a mi me funciona perfectamente.

Un saludo.

81
Programación ABAP / MOVIDO: Recién Titulados para Plan de Carrera ABAP IV
« en: 05 de Septiembre de 2007, 06:31:56 pm »

82
Programación ABAP / MOVIDO: - ANALISTAS ABAP IV -
« en: 05 de Septiembre de 2007, 06:31:32 pm »

83
Programación ABAP / Re: Error al cerrar el fichero despues de la transmisión
« en: 05 de Septiembre de 2007, 10:53:34 am »
Hola Endi.

Pues yo no se que pasaría nunca lo he probado, lo mas sencillo es que lo pruebes tu misma que no va a pasar nada.  ;)


Un saludo.
Oscar.

84
Programación ABAP / Re: Error al cerrar el fichero despues de la transmisión
« en: 03 de Septiembre de 2007, 01:33:05 pm »
Hola.

Por algún sitio leí algo parecido y una de las posibles soluciones que daban era la de renombrar las carpetas a MAYUSCULAS.

Ej: /tmp/test --> /TMP/TEST

Es algo que no tiene mucha lógica pero prueba y nos cuantas que tal fue la cosa.

Un saludo y suerte...
Oscar.

85
Lista todos los programas de un 'sy-langu' y crea una orden con todos ellos.




REPORT zbctrans LINE-SIZE 128 NO STANDARD PAGE HEADING.

* Data definition
TABLES: trdir, t002, e070, e071, e07t.
DATA: BEGIN OF itab OCCURS 0,
      prog LIKE rs38m-programm,
      text LIKE rs38m-repti,
      END OF itab.
DATA: BEGIN OF iout OCCURS 0,
      prog LIKE rs38m-programm,
      END OF iout.
DATA: BEGIN OF itext OCCURS 200.
        INCLUDE STRUCTURE textpool.
DATA: END OF itext.
* Table for the tasks created.
DATA: BEGIN OF tasks OCCURS 1.
        INCLUDE STRUCTURE e070.
DATA: END OF tasks.
* Table for the objects to insert in the order.
DATA: BEGIN OF t_e071 OCCURS 0.
        INCLUDE STRUCTURE e071.
DATA: END OF t_e071.
DATA: BEGIN OF t_e071k OCCURS 0.
        INCLUDE STRUCTURE e071k.
DATA: END OF t_e071k.
* Variables
DATA: answer,
      l_checkbox,
      l_prog LIKE rs38m-programm,
      ew_order LIKE e070,
      ev_order LIKE e070-trkorr,
      ev_task LIKE  e070-trkorr,
      v_subrc LIKE sy-subrc,
      color,
      checkbox.

* Selection screen.
SELECTION-SCREEN BEGIN OF BLOCK 001 WITH FRAME TITLE text-001.
SELECT-OPTIONS: reps FOR trdir-name,
                lang FOR t002-spras NO-EXTENSION NO INTERVALS
                                    OBLIGATORY.
SELECTION-SCREEN END OF BLOCK 001.

* User input.
AT USER-COMMAND.
  CASE sy-ucomm.
* Create request.
    WHEN 'REQ'.
      PERFORM confirm USING text-005 text-006.
      IF answer = 'J'.
        PERFORM choice.
        PERFORM request.
        IF sy-subrc = 0.
          PERFORM ok.
        ELSE.
          v_subrc = sy-subrc.
          PERFORM error.
        ENDIF.
      ENDIF.
* Select all.
    WHEN 'SEL'.
      PERFORM select.
* Unselect all.
    WHEN 'UNS'.
      PERFORM unselect.
  ENDCASE.
* Process.
START-OF-SELECTION.
* Warning if the user tries to select standard programs.
  READ TABLE reps INDEX 1.
  IF reps-low(1) NE 'Z'.
    PERFORM confirm USING text-003 text-004.
  ENDIF.
  IF answer = 'J' OR reps-low(1) = 'Z'.
* We place the list of programs in the internal table.
    SELECT * FROM trdir WHERE name IN reps.
      MOVE trdir-name TO itab-prog.
      APPEND itab. CLEAR itab.
    ENDSELECT.
    READ TABLE lang INDEX 1.
    LOOP AT itab.
      READ TEXTPOOL itab-prog LANGUAGE lang-low INTO itext.
      LOOP AT itext WHERE id = 'R'.
        itab-text = itext-entry.
        MODIFY itab. CLEAR itab.
        EXIT.
      ENDLOOP.
      REFRESH itext. CLEAR itext.
    ENDLOOP.
* List output.
    SET PF-STATUS 'LIST'.
    ULINE.
    FORMAT COLOR 1 INTENSIFIED ON.
    WRITE: / sy-vline,
           4 text-010,
           15 text-011,
           128 sy-vline.
    ULINE.
    LOOP AT itab WHERE NOT text IS INITIAL.
      IF color = 'X'.
        CLEAR color.
        FORMAT COLOR 2 INTENSIFIED OFF.
      ELSE.
        color = 'X'.
        FORMAT COLOR 2 INTENSIFIED ON.
      ENDIF.
      WRITE: / sy-vline,
             2 checkbox AS CHECKBOX,
             4 itab-prog,
             15 itab-text,
             128 sy-vline.
    ENDLOOP.
    IF sy-subrc NE 0.
      FORMAT COLOR 6 INTENSIFIED OFF.
      WRITE: / sy-vline, 4 text-012, 128 sy-vline.
    ENDIF.
    ULINE.
  ENDIF.

*---------------------------------------------------------------------*
*       FORM CONFIRM                                                  *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  LINE1                                                         *
*  -->  LINE2                                                         *
*---------------------------------------------------------------------*

FORM confirm USING line1 line2.
  CLEAR answer.
  CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
    EXPORTING
      defaultoption = 'N'
      textline1     = line1
      textline2     = line2
      titel         = text-002
      start_column  = 25
      start_row     = 6
    IMPORTING
      answer        = answer
    EXCEPTIONS
      OTHERS        = 1.
ENDFORM.                    "CONFIRM

*---------------------------------------------------------------------*
*       FORM SELECT                                                   *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*

FORM select.
  DO.
    READ LINE sy-index FIELD VALUE checkbox.
    IF sy-subrc NE 0.
      EXIT.
    ENDIF.
    MODIFY CURRENT LINE FIELD VALUE checkbox FROM 'X'.
  ENDDO.
ENDFORM.                    "SELECT

*---------------------------------------------------------------------*
*       FORM UNSELECT                                                 *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*

FORM unselect.
  DO.
    READ LINE sy-index FIELD VALUE checkbox.
    IF sy-subrc NE 0.
      EXIT.
    ENDIF.
    MODIFY CURRENT LINE FIELD VALUE checkbox FROM ' '.
  ENDDO.
ENDFORM.                    "UNSELECT

*---------------------------------------------------------------------*
*       FORM CHOICE                                                   *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*

FORM choice.
  REFRESH iout. CLEAR iout.
  DO.
    CLEAR: l_checkbox, l_prog.
    READ LINE sy-index FIELD VALUE checkbox INTO l_checkbox
                                   itab-prog INTO l_prog.
    IF sy-subrc NE 0.
      EXIT.
    ENDIF.
    IF l_checkbox = 'X'.
      MOVE l_prog TO iout-prog.
      APPEND iout. CLEAR iout.
    ENDIF.
  ENDDO.
ENDFORM.                    "CHOICE

*---------------------------------------------------------------------*
*       FORM REQUEST                                                  *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*

FORM request.
* First we create the order.
  CALL FUNCTION 'TR_ORDER_CREATE'
    EXPORTING
      iv_start_column   = 1
      iv_start_row      = 8
      iv_client         = sy-mandt
      iv_new_order_type = 'A'
      iv_new_task_type  = 'X'
      iv_category       = 'SYST'
    IMPORTING
      ew_order          = ew_order
      ev_order          = ev_order
      ev_task           = ev_task
    TABLES
      tt_tasks          = tasks
    EXCEPTIONS
      no_authorization  = 1
      OTHERS            = 2.
* Set the order as transportable...
  ew_order-trfunction = 'K'.
  CALL FUNCTION 'TRINT_CHANGE_OF_ATTRIBUTES'
    EXPORTING
      is_e070           = ew_order
    EXCEPTIONS
      change_error      = 1
      e070_update_error = 2
      e070_not_filled   = 3
      OTHERS            = 4.
* ...and the task.
  READ TABLE tasks INDEX 1.
  tasks-trfunction = 'S'.
  CALL FUNCTION 'TRINT_CHANGE_OF_ATTRIBUTES'
    EXPORTING
      is_e070           = tasks
    EXCEPTIONS
      change_error      = 1
      e070_update_error = 2
      e070_not_filled   = 3
      OTHERS            = 4.
* Include the programs in the transference table.
  LOOP AT iout.
    MOVE: tasks-trkorr TO t_e071-trkorr,
          '999999' TO t_e071-as4pos,
          'LIMU' TO t_e071-pgmid,
          'REPT' TO t_e071-object,
          iout-prog TO t_e071-obj_name.
    APPEND t_e071. CLEAR t_e071.
  ENDLOOP.
* Insert the objects.
  SELECT SINGLE * FROM e070 WHERE trkorr = tasks-trkorr.
  SELECT SINGLE * FROM e07t WHERE trkorr = tasks-trkorr.
  CALL FUNCTION 'TRINT_MODIFY_COMM'
    EXPORTING
      wi_called_by_editor            = ' '
      wi_e070                        = e070
      wi_e07t                        = e07t
      wi_lock_sort_flag              = 'X'
      wi_save_user                   = ' '
      wi_sel_e071                    = 'X'
      wi_sel_e071k                   = ' '
      wi_sel_e07t                    = ' '
    TABLES
      wt_e071                        = t_e071
      wt_e071k                       = t_e071k
    EXCEPTIONS
      chosen_project_closed          = 1
      e070_insert_error              = 2
      e070_update_error              = 3
      e071k_insert_error             = 4
      e071k_update_error             = 5
      e071_insert_error              = 6
      e071_update_error              = 7
      e07t_insert_error              = 8
      e07t_update_error              = 9
      locked_entries                 = 10
      locked_object_not_deleted      = 11
      ordername_forbidden            = 12
      order_change_but_locked_object = 13
      order_released                 = 14
      order_user_locked              = 15
      tr_check_keysyntax_error       = 16
      no_authorization               = 17
      e070c_insert_error             = 18
      e070c_update_error             = 19
      wrong_client                   = 20
      unallowed_source_client        = 21
      unallowed_user                 = 22
      OTHERS                         = 23.
ENDFORM.                    "REQUEST

*---------------------------------------------------------------------*
*       FORM ok                                                       *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*

FORM ok.
  CALL FUNCTION 'POPUP_TO_INFORM'
    EXPORTING
      titel = text-007
      txt1  = text-008
      txt2  = ' '.
ENDFORM.                    "ok

*---------------------------------------------------------------------*
*       FORM error                                                    *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*

FORM error.
  CALL FUNCTION 'POPUP_TO_INFORM'
    EXPORTING
      titel = text-007
      txt1  = text-009
      txt2  = v_subrc.
ENDFORM.                    "error


86
Informes / Informe en ALV para ver los Balances de las Cuentas Generales.
« en: 27 de Agosto de 2007, 06:32:22 pm »
En este informe podemos ver los Balances de las Cuentas Generales, para ello utilizamos la BAPI BAPI_GL_GETGLACCPERIODBALANCES.

El Include ZALV lo podemos copiar de este mismo foro en el apartado de los Includes.


REPORT  zfi_bal_generaux.

************************************************************************
*  DEFINICION TABLAS, ESTRUCTURAS Y TIPOS                              *
************************************************************************


*--DEFINICION DE TABLAS DE SISTEMA
TABLES: bsad,       "Contabilidad: índice secundario para deudores
        glt0,       "Cifras movimientos reg.maestro ctas.mayor
        skb1,
        skat,
        t001,
        ska1.




*--DEFINICION DE TABLAS INTERNAS
*-- tabla de clientes

DATA: BEGIN OF i_cliente OCCURS 0,
    saknr LIKE skb1-saknr.
DATA: END OF i_cliente.

*-- tabla para ALV
DATA: BEGIN OF i_datos OCCURS 0,
    clase(10),
    debe      LIKE bsid-dmbtr,
    haber     LIKE bsid-dmbtr,
    saknr     LIKE skb1-saknr,
    name1     LIKE skat-txt20,
    dif_debe  LIKE bsid-dmbtr,
    dif_haber LIKE bsid-dmbtr,
    saldo     LIKE bsid-dmbtr,
      END OF i_datos.

DATA: BEGIN OF i_datos2 OCCURS 0,
    clase2(10),
    debe      LIKE bsid-dmbtr,
    haber     LIKE bsid-dmbtr,
    altkt     LIKE skb1-altkt,
    name2     LIKE skat-txt20,
    dif_debe  LIKE bsid-dmbtr,
    dif_haber LIKE bsid-dmbtr,
    saldo     LIKE bsid-dmbtr,
      END OF i_datos2.

DATA: i_datos_bilan   LIKE i_datos OCCURS 0 WITH HEADER LINE.
DATA: i_datos_gestion LIKE i_datos OCCURS 0 WITH HEADER LINE.

DATA: saldo   LIKE bsid-dmbtr.


DATA: gs_disvariant TYPE disvariant.

* Type Pool donde vienen definidas todas las estructuras y tablas
TYPE-POOLS: slis.

* Catálogo de campos: contiene la descripción de los campos de salida
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
      alv_sort    TYPE slis_t_sortinfo_alv WITH HEADER LINE,
      alv_sort2   TYPE slis_t_sortinfo_alv WITH HEADER LINE.



INCLUDE zalv.

************************************************************************
*  DEFINICION DE PARAMETROS DE SELECCION                               *
************************************************************************


SELECTION-SCREEN BEGIN OF BLOCK uno WITH FRAME TITLE text-001.
SELECTION-SCREEN SKIP.
PARAMETERS:     p_bukrs LIKE glt0-bukrs OBLIGATORY.   "Sociedad
SELECT-OPTIONS: s_saknr FOR skb1-saknr,               "Nº cuenta
*               s_budat FOR bsad-budat OBLIGATORY,    "Fecha contab.
                s_monat FOR bsad-monat OBLIGATORY.    "Mes contable
PARAMETERS:     p_gjahr LIKE bsad-gjahr OBLIGATORY.   "Ejerc. Contable
SELECTION-SCREEN END OF BLOCK uno.

SELECTION-SCREEN BEGIN OF BLOCK dos WITH FRAME TITLE text-200.
PARAMETERS: cta_alt AS CHECKBOX DEFAULT space.
SELECTION-SCREEN END OF BLOCK dos.




************************************************************************
*  DEFINICION DE VARIABLES                                             *
************************************************************************






************************************************************************
*                                                                      *
*                                                                      *
*                        T R A T A M I E N T O                         *
*                                                                      *
*                                                                      *
************************************************************************

*----------------------------------------------------------------------*
*     START-OF-SELECTION                                               *
*----------------------------------------------------------------------*

START-OF-SELECTION.
  PERFORM selecciona_datos.
  PERFORM procesa_datos.
  IF NOT cta_alt IS INITIAL.
    PERFORM ctaltern.
  ENDIF.

END-OF-SELECTION.
  PERFORM pinta.




************************************************************************
*                                                                      *
*                                                                      *
*                        S U B - R U T I N A S                         *
*                                                                      *
*                                                                      *
************************************************************************
*&---------------------------------------------------------------------*
*&      Form  selecciona_datos
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*

FORM selecciona_datos .

  SELECT * APPENDING CORRESPONDING FIELDS OF TABLE i_cliente
                FROM skb1
               WHERE bukrs = p_bukrs
                 AND saknr IN s_saknr.

ENDFORM.                    " selecciona_datos

*&---------------------------------------------------------------------*
*&      Form  procesa_datos
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*

FORM procesa_datos .
  DATA: BEGIN OF i_items OCCURS 0.
          INCLUDE STRUCTURE bapi1028_4.
  DATA: END   OF i_items.

  DATA: companycode  LIKE bapi1028_0-comp_code,
        glacct       LIKE bapi1028_0-gl_account,
        fiscalyear   LIKE bapi1028_4-fisc_year,
        currencytype LIKE bapi1028_5-curr_type,
        date_from    LIKE bapi3007-from_date,
        date_to      LIKE bapi3007-to_date,
        v_debe       LIKE bsid-dmbtr,
        v_haber      LIKE bsid-dmbtr,
        v_dif        LIKE bsid-dmbtr.

  IF s_monat-high IS INITIAL.
    s_monat-high = s_monat-low.
  ENDIF.

  companycode  = p_bukrs.
  fiscalyear   = p_gjahr.
  currencytype = '10'.

  LOOP AT i_cliente.
    CLEAR i_items. REFRESH i_items.
    glacct    = i_cliente-saknr.


    CALL FUNCTION 'BAPI_GL_GETGLACCPERIODBALANCES'
      EXPORTING
        companycode                   = companycode
        glacct                        = glacct
        fiscalyear                    = fiscalyear
        currencytype                  = currencytype
*     IMPORTING
*       BALANCE_CARRIED_FORWARD       =
*       RETURN                        =

      TABLES
        account_balances              = i_items.


    CLEAR: v_debe, v_haber.
    LOOP AT i_items WHERE fis_period IN s_monat.

      i_items-credit_per = i_items-credit_per * ( - 1 ).
      v_haber = v_haber + i_items-credit_per.
      v_debe  = v_debe  + i_items-debits_per.
    ENDLOOP.



    PERFORM name1_cliente USING i_cliente-saknr.
    PERFORM saldo USING i_datos-saldo.

    IF glacct = '0129000000'.
      PERFORM grupo0129 USING saldo.
    ENDIF.
    IF saldo < 0.
      v_haber = v_haber + ( saldo * ( - 1 ) ).
    ELSE.
      v_debe = v_debe + saldo.
    ENDIF.
    CLEAR saldo.

    IF glacct(2) NE '06' AND
      glacct(2) NE '07'.
      IF i_datos-saldo < 0.
        v_haber = v_haber + ( i_datos-saldo * ( - 1 ) ).
      ELSE.
        v_debe = v_debe + i_datos-saldo.
      ENDIF.
    ENDIF.

    MOVE: v_debe             TO i_datos-debe,
          v_haber            TO i_datos-haber,
          i_cliente-saknr    TO i_datos-saknr,
          skat-txt20         TO i_datos-name1.

    CONCATENATE 'Clase' i_cliente-saknr+1(1)
           INTO i_datos-clase SEPARATED BY space.

    v_dif = v_debe - v_haber.
    IF v_dif < 0.
      i_datos-dif_haber = v_dif * ( - 1 ).
    ELSE.
      i_datos-dif_debe  = v_dif.
    ENDIF.

    IF i_datos-debe      IS INITIAL AND
       i_datos-haber     IS INITIAL AND
       i_datos-saldo     IS INITIAL.
    ELSE.
      APPEND i_datos.
      CLEAR  i_datos.
    ENDIF.

  ENDLOOP.

ENDFORM.                    " procesa_datos

*&---------------------------------------------------------------------*
*&      Form  name1_cliente
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_CLIENTE_SAKNR  text
*----------------------------------------------------------------------*

FORM name1_cliente  USING    p_saknr.

  SELECT SINGLE * FROM skat WHERE spras = 'FR'
                              AND ktopl = 'SOCU'
                              AND saknr = p_saknr.

ENDFORM.                    " name1_cliente

*&---------------------------------------------------------------------*
*&      Form  saldo
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_DATOS_saldo  text
*----------------------------------------------------------------------*

FORM saldo  USING    p_saldo.
  DATA: BEGIN OF balance OCCURS 0.
          INCLUDE STRUCTURE bapi1028_3.
  DATA: END   OF balance.

  DATA: companycode   LIKE bapi1028_0-comp_code,
        glacct        LIKE bapi1028_0-gl_account,
        fiscalyear    LIKE bapi1028_3-fisc_year,
        currencytype  LIKE bapi1028_5-curr_type.

  companycode  = p_bukrs.
  glacct       = i_cliente-saknr.
  fiscalyear   = p_gjahr - 1.
  currencytype = '10'.

*-- bapi para sacar el saldo anterior.
  CALL FUNCTION 'BAPI_GL_GETGLACCBALANCE'
    EXPORTING
      companycode     = companycode
      glacct          = glacct
      fiscalyear      = fiscalyear
      currencytype    = currencytype
    IMPORTING
      account_balance = balance.
*     RETURN                = .

  p_saldo = balance-balance.

ENDFORM.                    " saldo

*&---------------------------------------------------------------------*
*&      Form  pinta
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*

FORM pinta .
  DATA: var_saldo(30),
        var_debe(30),
        var_haber(30),
        anio(4).

  repname = sy-repid.
  anio    = p_gjahr - 1.

* Descripción estándar de campos
  IF NOT cta_alt IS INITIAL.
    PERFORM obt_descrip_campos_tabla USING repname 'I_DATOS2'.
  ELSE.
    PERFORM obt_descrip_campos_tabla USING repname 'I_DATOS'.
  ENDIF.
* Asignar TOP OF PAGE
  PERFORM asignar_top_of_page.
* Quitamos el cero de los importes.
  PERFORM no_zero USING: 'DEBE'         'X',
                         'HABER'        'X',
                         'DIF_DEBE'     'X',
                         'DIF_HABER'    'X',
                         'SALDO'        'X'.
* Marcamos los campos de los sumatorios.
  PERFORM do_sum USING:  'DEBE'         'X',
                         'HABER'        'X',
                         'DIF_DEBE'     'X',
                         'DIF_HABER'    'X',
                         'SALDO'        'X'.

* Cambiamos la descripción
  CONCATENATE 'Débiteur' p_gjahr
         INTO var_debe SEPARATED BY space.

  CONCATENATE 'Créditeur' p_gjahr
         INTO var_haber SEPARATED BY space.

  CONCATENATE 'Solde' anio
         INTO var_saldo SEPARATED BY space.

  IF NOT cta_alt IS INITIAL.
    PERFORM cambio_descripcion USING:
     'CLASE2'                 'Clase'    'Clase'
                              'Clase'    'Clase',
     'DEBE'                  'Cumul Débit'    'Cumul Débit'
                             'Cumul Débit'    'Cumul Débit',
     'HABER'                 'Cumul Crédit'   'Cumul Crédit'
                             'Cumul Crédit'   'Cumul Crédit',
     'ALTKT'                 'Nº Compte'      'Nº Compte'
                             'Nº Compte'      'Nº Compte',
     'NAME1'                 'Intitulé'       'Intitulé'
                             'Intitulé'       'Intitulé',
     'DIF_DEBE'              var_debe         var_debe
                             var_debe         var_debe,
     'DIF_HABER'             var_haber        var_haber
                             var_haber        var_haber,
     'SALDO'                 var_saldo        var_saldo
                             var_saldo        var_saldo.
  ELSE.
    PERFORM cambio_descripcion USING:
     'CLASE'                 'Clase'    'Clase'
                             'Clase'    'Clase',
     'DEBE'                  'Cumul Débit'    'Cumul Débit'
                             'Cumul Débit'    'Cumul Débit',
     'HABER'                 'Cumul Crédit'   'Cumul Crédit'
                             'Cumul Crédit'   'Cumul Crédit',
     'SAKNR'                 'Nº Compte'      'Nº Compte'
                             'Nº Compte'      'Nº Compte',
     'NAME1'                 'Intitulé'       'Intitulé'
                             'Intitulé'       'Intitulé',
     'DIF_DEBE'              var_debe         var_debe
                             var_debe         var_debe,
     'DIF_HABER'             var_haber        var_haber
                             var_haber        var_haber,
     'SALDO'                 var_saldo        var_saldo
                             var_saldo        var_saldo.
  ENDIF.

* Características generales del listado
  PERFORM carac_gen_listado.
  PERFORM subtotal.

* Disposición
  gs_disvariant-report  = repname.

* Se muestra el listado
  IF NOT cta_alt IS INITIAL.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
        i_callback_program       = repname
        i_callback_pf_status_set = formname_pf_status_set
        i_callback_user_command  = formname_user_command
        is_layout                = layout
        it_fieldcat              = fieldtab[]
        it_events                = events[]
        i_save                   = 'A'
        it_sort                  = alv_sort[]
        is_variant               = gs_disvariant
      TABLES
        t_outtab                 = i_datos2
      EXCEPTIONS
        program_error            = 1
        OTHERS                   = 2.
  ELSE.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program       = repname
      i_callback_pf_status_set = formname_pf_status_set
      i_callback_user_command  = formname_user_command
      is_layout                = layout
      it_fieldcat              = fieldtab[]
      it_events                = events[]
      i_save                   = 'A'
      it_sort                  = alv_sort[]
      is_variant               = gs_disvariant
    TABLES
      t_outtab                 = i_datos
    EXCEPTIONS
      program_error            = 1
      OTHERS                   = 2.
  ENDIF.


ENDFORM.                    " pinta


*&---------------------------------------------------------------------*
*&      Form  subtotal
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*

FORM subtotal.

  IF NOT cta_alt IS INITIAL.
    REFRESH alv_sort.
    CLEAR alv_sort.
    alv_sort-fieldname = 'CLASE2'.
    alv_sort-subtot = 'X'.
    APPEND alv_sort.

    REFRESH alv_sort2.
    CLEAR alv_sort.
    alv_sort2-fieldname = 'CLASE2'.
    alv_sort2-subtot = 'X'.
    alv_sort2-expa   = 'X'.
    alv_sort2-comp   = ' '.
    APPEND alv_sort2.
  ELSE.
    REFRESH alv_sort.
    CLEAR alv_sort.
    alv_sort-fieldname = 'CLASE'.
    alv_sort-subtot = 'X'.
    APPEND alv_sort.

    REFRESH alv_sort2.
    CLEAR alv_sort.
    alv_sort2-fieldname = 'CLASE'.
    alv_sort2-subtot = 'X'.
    alv_sort2-expa   = 'X'.
    alv_sort2-comp   = ' '.
    APPEND alv_sort2.
  ENDIF.

ENDFORM. " subtotal


*&---------------------------------------------------------------------*
*&      Form  cambio_descripcion
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*

FORM cambio_descripcion USING pf_fieldname
                              pf_scrtext_l
                              pf_scrtext_m
                              pf_scrtext_s
                              pf_coltext.

  READ TABLE fieldtab WITH KEY fieldname = pf_fieldname ASSIGNING <fs>.
  IF sy-subrc EQ 0.
    <fs>-seltext_l = pf_scrtext_l.
    <fs>-seltext_m = pf_scrtext_m.
    <fs>-seltext_s = pf_scrtext_s.
    <fs>-reptext_ddic = pf_coltext.
  ENDIF.

ENDFORM.                    " cambio_descripcion

*&---------------------------------------------------------------------*
*&      Form  no_zero
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*

FORM no_zero USING pf_fieldname
                   p_zero.

  READ TABLE fieldtab WITH KEY fieldname = pf_fieldname ASSIGNING <fs>.
  IF sy-subrc EQ 0.
    <fs>-no_zero = p_zero.
  ENDIF.

ENDFORM.                    " no_zero

*&---------------------------------------------------------------------*
*&      Form  do_sum
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*

FORM do_sum USING pf_fieldname
                  p_sum.

  READ TABLE fieldtab WITH KEY fieldname = pf_fieldname ASSIGNING <fs>.
  IF sy-subrc EQ 0.
    <fs>-do_sum  = p_sum.
  ENDIF.

ENDFORM.                    " do_sum

*---------------------------------------------------------------------*
*       FORM alv_top_of_page                                          *
*---------------------------------------------------------------------*
*     Textos de cabecera
*       - typ,   " H = Header, S = Selection, A = Action
*       - key,
*       - info,
*---------------------------------------------------------------------*

FORM alv_top_of_page.

  DATA: lt_list_commentary TYPE slis_t_listheader,
        ls_list_commentary TYPE slis_listheader.
  DATA: v_date(60).

  SELECT SINGLE * FROM t001 WHERE bukrs = p_bukrs.

  CONCATENATE 'Du' '01/'
                   s_monat-low '/'
                   p_gjahr   'au'
                   '31/'
                   s_monat-high '/'
                   p_gjahr
         INTO v_date SEPARATED BY space.

* Componemos texto de cabecera
  CLEAR ls_list_commentary.
  ls_list_commentary-typ  = 'H'.
  ls_list_commentary-info = 'Balance des comptes généraux'.
  APPEND ls_list_commentary TO lt_list_commentary.
*
  CLEAR ls_list_commentary.
  ls_list_commentary-typ  = 'S'.
  ls_list_commentary-key  = 'Société:'.
  ls_list_commentary-info = t001-butxt.
  APPEND ls_list_commentary TO lt_list_commentary.
*
  CLEAR ls_list_commentary.
  ls_list_commentary-typ  = 'S'.
  ls_list_commentary-key  = 'Date comptable:'.
  ls_list_commentary-info = v_date.
  APPEND ls_list_commentary TO lt_list_commentary.
*
  CLEAR ls_list_commentary.
  ls_list_commentary-typ  = 'A'.
  ls_list_commentary-info = 'Edition Provisiore - Experimé en euros'.
  APPEND ls_list_commentary TO lt_list_commentary.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = lt_list_commentary.

ENDFORM.                    "alv_top_of_page

*&---------------------------------------------------------------------
*&    Form PF_STATUS
*&---------------------------------------------------------------------

FORM pf_status USING lt_cua_exclude TYPE slis_t_extab.
  SET PF-STATUS 'STATUS_100'.
ENDFORM.                    "pf_status

*&---------------------------------------------------------------------
*&    Form USER_COMMAND
*&---------------------------------------------------------------------

FORM user_command USING r_ucomm LIKE sy-ucomm
                        ls_selfield TYPE slis_selfield.

  CASE r_ucomm.
    WHEN '/&F03'.
      LEAVE TO TRANSACTION 'ZFIBAL029'.
*-- Gener
    WHEN 'GENER'.
      PERFORM alv_gener.
*-- Bilan
    WHEN 'BILAN'.
      PERFORM alv_bilan.

*-- Gestion
    WHEN 'GESTION'.
      PERFORM alv_gestion.
  ENDCASE.

ENDFORM.                    "user_command

*&---------------------------------------------------------------------*
*&      Form  alv_gener
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*

FORM alv_gener .

* Se muestra el listado general
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program       = repname
      i_callback_pf_status_set = formname_pf_status_set
      i_callback_user_command  = formname_user_command
      is_layout                = layout
      it_fieldcat              = fieldtab[]
      it_events                = events[]
      i_save                   = 'A'
      it_sort                  = alv_sort[]
      is_variant               = gs_disvariant
    TABLES
      t_outtab                 = i_datos
    EXCEPTIONS
      program_error            = 1
      OTHERS                   = 2.

ENDFORM.                    " alv_gener

*&---------------------------------------------------------------------*
*&      Form  alv_bilan
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*

FORM alv_bilan .
  CLEAR i_datos_bilan. REFRESH i_datos_bilan.

  LOOP AT i_datos WHERE clase+6(1) <= 5.
    MOVE-CORRESPONDING i_datos TO i_datos_bilan.
    APPEND i_datos_bilan.
    CLEAR  i_datos_bilan.
  ENDLOOP.

* Se muestra el listado bilan
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program       = repname
      i_callback_pf_status_set = formname_pf_status_set
      i_callback_user_command  = formname_user_command
      is_layout                = layout
      it_fieldcat              = fieldtab[]
      it_events                = events[]
      i_save                   = 'A'
      it_sort                  = alv_sort2[]
      is_variant               = gs_disvariant
    TABLES
      t_outtab                 = i_datos_bilan
    EXCEPTIONS
      program_error            = 1
      OTHERS                   = 2.

ENDFORM.                    " alv_bilan

*&---------------------------------------------------------------------*
*&      Form  alv_gestion
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*

FORM alv_gestion .
  CLEAR i_datos_gestion. REFRESH i_datos_gestion.

  LOOP AT i_datos WHERE ( clase+6(1) = 6 OR
                          clase+6(1) = 7 ).
    MOVE-CORRESPONDING i_datos TO i_datos_gestion.
    APPEND i_datos_gestion.
    CLEAR  i_datos_gestion.
  ENDLOOP.

* Se muestra el listado gestion
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program       = repname
      i_callback_pf_status_set = formname_pf_status_set
      i_callback_user_command  = formname_user_command
      is_layout                = layout
      it_fieldcat              = fieldtab[]
      it_events                = events[]
      i_save                   = 'A'
      it_sort                  = alv_sort2[]
      is_variant               = gs_disvariant
    TABLES
      t_outtab                 = i_datos_gestion
    EXCEPTIONS
      program_error            = 1
      OTHERS                   = 2.

ENDFORM.                    " alv_gestion
*&---------------------------------------------------------------------*
*&      Form  grupo0129
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_SALDO  text
*----------------------------------------------------------------------*

FORM grupo0129  USING    P_R_SALDO.

  DATA: BEGIN OF balan1 OCCURS 0.
          INCLUDE STRUCTURE bapi1028_3.
  DATA: END   OF balan1.

  DATA: companycod1   LIKE bapi1028_0-comp_code,
        glacc1       LIKE bapi1028_0-gl_account,
        fiscalyea1    LIKE bapi1028_3-fisc_year,
        currencytyp1  LIKE bapi1028_5-curr_type.


  SELECT * FROM ska1 WHERE ktopl = 'SOCU'
                           AND     saknr BETWEEN '0600000000'
                           AND     '0799999999'.

    companycod1  = p_bukrs.
    glacc1       = ska1-saknr.
    fiscalyea1   = p_gjahr - 1.
    currencytyp1 = '10'.

*-- bapi para sacar el saldo anterior.
    CALL FUNCTION 'BAPI_GL_GETGLACCBALANCE'
      EXPORTING
        companycode     = companycod1
        glacct          = glacc1
        fiscalyear      = fiscalyea1
        currencytype    = currencytyp1
      IMPORTING
        account_balance = balan1.
*     RETURN                = .

      p_r_saldo = p_r_saldo + balan1-balance.
  ENDSELECT.

ENDFORM.                    " grupo0129
*&---------------------------------------------------------------------*
*&      Form  ctaltern
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*

FORM ctaltern .

  LOOP AT i_datos.
    CALL FUNCTION 'READ_SKB1'
        EXPORTING
          xbukrs = p_bukrs
          xsaknr = i_datos-saknr
        IMPORTING
          xskb1  = skb1.

*    SELECT SINGLE * FROM t001
*                    WHERE bukrs = p_bukrs.

*    SELECT SINGLE * FROM skat
*                    WHERE ktopl = t001-ktop2
*                    AND saknr   = skb1-altkt.
*    IF skat-txt50 IS INITIAL.
*      MOVE text-601 TO skat-txt50.
*    ENDIF.
*    one_gsb = ' '.
*    MOVE skb1-altkt TO konto.

    MOVE-CORRESPONDING i_datos TO i_datos2.
    CONCATENATE 'Clase' skb1-altkt+1(1)
           INTO i_datos2-clase2 SEPARATED BY space.
    MOVE skb1-altkt TO i_datos2-altkt.
    COLLECT i_datos2.
    clear skb1.
  ENDLOOP.

  SORT i_datos2 BY altkt.
  DELETE ADJACENT DUPLICATES FROM i_datos2.


  SELECT SINGLE * FROM t001
                  WHERE bukrs = p_bukrs.
  LOOP AT i_datos2.
    PERFORM name2_cliente USING i_datos2-altkt t001-ktop2.
  ENDLOOP.

ENDFORM.                    " ctaltern
*&---------------------------------------------------------------------*
*&      Form  name2_cliente
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_DATOS2_ALTKT  text
*----------------------------------------------------------------------*

FORM name2_cliente  USING    P_I_DATOS2_ALTKT p_i_t001_ktop2.

  SELECT SINGLE * FROM skat WHERE spras = 'FR'
                              AND ktopl = p_i_t001_ktop2
                              AND saknr = p_i_datos2_altkt.

  i_datos2-name2 = skat-txt20.
  MODIFY i_datos2.
  CLEAR skat.

ENDFORM.                    " name2_cliente

87
Informes / Informe en ALV para ver los Balances de los Proveedores.
« en: 27 de Agosto de 2007, 06:20:02 pm »
En este informe podemos ver los Balances de los Proveedores, para ello utilizamos la BAPI BAPI_AP_ACC_GETSTATEMENT.

El Include ZALV lo podemos copiar de este mismo foro en el apartado de los Includes.




REPORT  zfi_bal_fournisseurs.

************************************************************************
*  DEFINICION TABLAS, ESTRUCTURAS Y TIPOS                              *
************************************************************************

*--DEFINICION DE TABLAS DE SISTEMA

TABLES: bsad,       "Contabilidad: índice secundario para deudores
        glt0,       "Cifras movimientos reg.maestro ctas.mayor
        lfa1,
        t001.




*--DEFINICION DE TABLAS INTERNAS
*-- tabla de clientes

DATA: BEGIN OF i_cliente OCCURS 0,
    lifnr LIKE lfa1-lifnr.
DATA: END OF i_cliente.

*-- tabla para ALV
DATA: BEGIN OF i_datos OCCURS 0,
    debe      LIKE bsid-dmbtr,
    haber     LIKE bsid-dmbtr,
    lifnr     LIKE lfa1-lifnr,
    name1     LIKE lfa1-name1,
    dif_debe  LIKE bsid-dmbtr,
    dif_haber LIKE bsid-dmbtr,
    saldo     LIKE bsid-dmbtr,
      END OF i_datos.

DATA: gs_disvariant TYPE disvariant.

INCLUDE zalv.

************************************************************************
*  DEFINICION DE PARAMETROS DE SELECCION                               *
************************************************************************


SELECTION-SCREEN BEGIN OF BLOCK uno WITH FRAME TITLE text-001.
SELECTION-SCREEN SKIP.
PARAMETERS: p_bukrs LIKE glt0-bukrs OBLIGATORY.       "Sociedad
SELECT-OPTIONS: s_lifnr FOR bsad-kunnr,               "Nº cuenta
                s_budat FOR bsad-budat OBLIGATORY.    "Fecha contab.

SELECTION-SCREEN END OF BLOCK uno.





************************************************************************
*  DEFINICION DE VARIABLES                                             *
************************************************************************






************************************************************************
*                                                                      *
*                                                                      *
*                        T R A T A M I E N T O                         *
*                                                                      *
*                                                                      *
************************************************************************

*----------------------------------------------------------------------*
*     START-OF-SELECTION                                               *
*----------------------------------------------------------------------*


START-OF-SELECTION.
  PERFORM selecciona_datos.
  PERFORM procesa_datos.

END-OF-SELECTION.
  PERFORM pinta.




************************************************************************
*                                                                      *
*                                                                      *
*                        S U B - R U T I N A S                         *
*                                                                      *
*                                                                      *
************************************************************************
*&---------------------------------------------------------------------*
*&      Form  selecciona_datos
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*

FORM selecciona_datos .

  SELECT * APPENDING CORRESPONDING FIELDS OF TABLE i_cliente
                FROM lfa1
               WHERE lifnr IN s_lifnr.

ENDFORM.                    " selecciona_datos

*&---------------------------------------------------------------------*
*&      Form  procesa_datos
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*

FORM procesa_datos .

  DATA: BEGIN OF i_items OCCURS 0.
          INCLUDE STRUCTURE bapi3008_2.
  DATA: END   OF i_items.

  DATA: companycode LIKE  bapi3008_1-comp_code,
        vendor      LIKE  bapi3008_1-vendor,
        date_from   LIKE  bapi3008-from_date,
        date_to     LIKE  bapi3008-to_date,
        v_debe      LIKE bsid-dmbtr,
        v_haber     LIKE bsid-dmbtr,
        v_dif       LIKE bsid-dmbtr.

  IF s_budat-high IS INITIAL.
    s_budat-high = s_budat-low.
  ENDIF.

  companycode = p_bukrs.
  date_from   = s_budat-low.
  date_to     = s_budat-high.


  LOOP AT i_cliente.
    CLEAR i_items. REFRESH i_items.
    vendor    = i_cliente-lifnr.



    CALL FUNCTION 'BAPI_AP_ACC_GETSTATEMENT'
      EXPORTING
        companycode       = p_bukrs
        vendor            = vendor
        date_from         = date_from
        date_to           = date_to
*     NOTEDITEMS        = ' '
*     IMPORTING
*      RETURN            =

      TABLES
        lineitems         = i_items.


    CLEAR: v_debe, v_haber.
    LOOP AT i_items.

      IF i_items-db_cr_ind = 'S'.
        v_debe  = v_debe + i_items-amount.
      ELSE.
        v_haber = v_haber + i_items-amount.
      ENDIF.

    ENDLOOP.

    PERFORM name1_cliente USING i_cliente-lifnr.
    PERFORM saldo USING i_datos-saldo.
    if i_datos-saldo < 0.
      v_haber = v_haber + ( i_datos-saldo * ( - 1 ) ).
    else.
      v_debe = v_debe + i_datos-saldo.
    endif.

    MOVE: v_debe          TO i_datos-debe,
          v_haber         TO i_datos-haber,
          i_cliente-lifnr TO i_datos-lifnr,
          lfa1-name1      TO i_datos-name1.

    v_dif = v_debe - v_haber.
    IF v_dif < 0.
      i_datos-dif_haber = v_dif * ( - 1 ).
    ELSE.
      i_datos-dif_debe  = v_dif.
    ENDIF.

*   PERFORM saldo USING i_datos-saldo.
    IF i_datos-debe      IS INITIAL AND
       i_datos-haber     IS INITIAL AND
       i_datos-saldo     IS INITIAL.
    ELSE.
      APPEND i_datos.
      CLEAR  i_datos.
    ENDIF.

  ENDLOOP.

ENDFORM.                    " procesa_datos

*&---------------------------------------------------------------------*
*&      Form  name1_cliente
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LIFNR  text
*----------------------------------------------------------------------*

FORM name1_cliente  USING    p_lifnr.

  SELECT SINGLE * FROM lfa1 WHERE lifnr = p_lifnr.

ENDFORM.                    " name1_cliente

*&---------------------------------------------------------------------*
*&      Form  saldo
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_DATOS_saldo  text
*----------------------------------------------------------------------*

FORM saldo  USING    p_saldo.
  DATA: BEGIN OF keybalance OCCURS 0.
          INCLUDE STRUCTURE bapi3008_3.
  DATA: END   OF keybalance.

  DATA: companycode LIKE bapi3008_1-comp_code,
        vendor      LIKE bapi3008_1-vendor,
        keydate     LIKE bapi3008-key_date,
        anio(4).

  companycode = p_bukrs.
  vendor      = i_cliente-lifnr.
  anio        = s_budat-high(4) - 1.

  CONCATENATE anio '1231' INTO keydate.

*-- BAPI para sacar el Saldo Anterior.
  CALL FUNCTION 'BAPI_AP_ACC_GETKEYDATEBALANCE'
    EXPORTING
      companycode = companycode
      vendor      = vendor
      keydate     = keydate
    TABLES
      keybalance  = keybalance.

  p_saldo = keybalance-lc_bal.

ENDFORM.                    " saldo

*&---------------------------------------------------------------------*
*&      Form  pinta
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*

FORM pinta .
  DATA: var_saldo(30),
        var_debe(30),
        var_haber(30),
        anio(4).

  repname = sy-repid.
  anio    = s_budat-high(4) - 1.

* Descripción estándar de campos
  PERFORM obt_descrip_campos_tabla USING repname 'I_DATOS'.
* Asignar TOP OF PAGE
  PERFORM asignar_top_of_page.
* Quitamos el cero de los importes.
  PERFORM no_zero USING: 'DEBE'         'X',
                         'HABER'        'X',
                         'DIF_DEBE'     'X',
                         'DIF_HABER'    'X',
                         'SALDO'        'X'.
* Marcamos los campos de los sumatorios.
  PERFORM no_sum USING: 'DEBE'         'X',
                        'HABER'        'X',
                        'DIF_DEBE'     'X',
                        'DIF_HABER'    'X',
                        'SALDO'        'X'.
* Cambiamos la descripción
  CONCATENATE 'Débiteur' s_budat-high(4)
         INTO var_debe SEPARATED BY space.

  CONCATENATE 'Créditeur' s_budat-high(4)
         INTO var_haber SEPARATED BY space.

  CONCATENATE 'Solde' anio
         INTO var_saldo SEPARATED BY space.

  PERFORM cambio_descripcion USING:
   'DEBE'                  'Cumul Débit'    'Cumul Débit'
                           'Cumul Débit'    'Cumul Débit',
   'HABER'                 'Cumul Crédit'   'Cumul Crédit'
                           'Cumul Crédit'   'Cumul Crédit',
   'LIFNR'                 'Nº Compte'      'Nº Compte'
                           'Nº Compte'      'Nº Compte',
   'NAME1'                 'Intitulé'       'Intitulé'
                           'Intitulé'       'Intitulé',
   'DIF_DEBE'              var_debe         var_debe
                           var_debe         var_debe,
   'DIF_HABER'             var_haber        var_haber
                           var_haber        var_haber,
   'SALDO'                 var_saldo        var_saldo
                           var_saldo        var_saldo.

* Características generales del listado
  PERFORM carac_gen_listado.

* Disposición
  gs_disvariant-report  = repname.

* Se muestra el listado
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = repname
      is_layout          = layout
      it_fieldcat        = fieldtab[]
      it_events          = events[]
      i_save             = 'A'
      is_variant         = gs_disvariant
    TABLES
      t_outtab           = i_datos
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.

ENDFORM.                    " pinta

*&---------------------------------------------------------------------*
*&      Form  cambio_descripcion
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*

FORM cambio_descripcion USING pf_fieldname
                              pf_scrtext_l
                              pf_scrtext_m
                              pf_scrtext_s
                              pf_coltext.

  READ TABLE fieldtab WITH KEY fieldname = pf_fieldname ASSIGNING <fs>.
  IF sy-subrc EQ 0.
    <fs>-seltext_l = pf_scrtext_l.
    <fs>-seltext_m = pf_scrtext_m.
    <fs>-seltext_s = pf_scrtext_s.
    <fs>-reptext_ddic = pf_coltext.
  ENDIF.

ENDFORM.                    " cambio_descripcion

*&---------------------------------------------------------------------*
*&      Form  no_zero
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*

FORM no_zero USING pf_fieldname
                   p_zero.

  READ TABLE fieldtab WITH KEY fieldname = pf_fieldname ASSIGNING <fs>.
  IF sy-subrc EQ 0.
    <fs>-no_zero = p_zero.
  ENDIF.

ENDFORM.                    " no_zero

*&---------------------------------------------------------------------*
*&      Form  no_sum
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*

FORM no_sum USING pf_fieldname
                  p_sum.

  READ TABLE fieldtab WITH KEY fieldname = pf_fieldname ASSIGNING <fs>.
  IF sy-subrc EQ 0.
    <fs>-do_sum  = p_sum.
  ENDIF.

ENDFORM.                    " p_sum

*---------------------------------------------------------------------*
*       FORM alv_top_of_page                                          *
*---------------------------------------------------------------------*
*     Textos de cabecera
*       - typ,   " H = Header, S = Selection, A = Action
*       - key,
*       - info,
*---------------------------------------------------------------------*

FORM alv_top_of_page.

  DATA: lt_list_commentary TYPE slis_t_listheader,
        ls_list_commentary TYPE slis_listheader.
  DATA: v_date(60).

  SELECT SINGLE * FROM t001 WHERE bukrs = p_bukrs.

  CONCATENATE 'Du' s_budat-low+6(2) '/'
                   s_budat-low+4(2) '/'
                   s_budat-low(4)   'au'
                   s_budat-high+6(2) '/'
                   s_budat-high+4(2) '/'
                   s_budat-high(4)
         INTO v_date SEPARATED BY space.

* Componemos texto de cabecera
  CLEAR ls_list_commentary.
  ls_list_commentary-typ  = 'H'.
  ls_list_commentary-info = 'Balance des comptes fournisseurs'.
  APPEND ls_list_commentary TO lt_list_commentary.
*
  CLEAR ls_list_commentary.
  ls_list_commentary-typ  = 'S'.
  ls_list_commentary-key  = 'Société:'.
  ls_list_commentary-info = t001-butxt.
  APPEND ls_list_commentary TO lt_list_commentary.
*
  CLEAR ls_list_commentary.
  ls_list_commentary-typ  = 'S'.
  ls_list_commentary-key  = 'Date comptable:'.
  ls_list_commentary-info = v_date.
  APPEND ls_list_commentary TO lt_list_commentary.
*
  CLEAR ls_list_commentary.
  ls_list_commentary-typ  = 'A'.
  ls_list_commentary-info = 'Edition Provisiore - Experimé en euros'.
  APPEND ls_list_commentary TO lt_list_commentary.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = lt_list_commentary.

ENDFORM.                    "alv_top_of_page

88
Informes / Informe en ALV para ver los Balances de los Clientes.
« en: 27 de Agosto de 2007, 06:06:14 pm »
En este informe podemos ver los Balances de los Clientes.

El Include ZALV lo podemos copiar de este mismo foro en el apartado de los Includes.



REPORT  zfi_bal_client.


************************************************************************
*  DEFINICION TABLAS, ESTRUCTURAS Y TIPOS                              *
************************************************************************

*--DEFINICION DE TABLAS DE SISTEMA

TABLES: bsad,       "Contabilidad: índice secundario para deudores
        glt0,       "Cifras movimientos reg.maestro ctas.mayor
        kna1,
        t001.




*--DEFINICION DE TABLAS INTERNAS
*-- tabla de clientes

DATA: BEGIN OF i_cliente OCCURS 0,
    kunnr LIKE kna1-kunnr.
DATA: END OF i_cliente.

*-- tabla para ALV
DATA: BEGIN OF i_datos OCCURS 0,
    debe      LIKE bsid-dmbtr,
    haber     LIKE bsid-dmbtr,
    kunnr     LIKE kna1-kunnr,
    name1     LIKE kna1-name1,
    dif_debe  LIKE bsid-dmbtr,
    dif_haber LIKE bsid-dmbtr,
    saldo     LIKE bsid-dmbtr,
      END OF i_datos.

DATA: gs_disvariant TYPE disvariant.

INCLUDE zalv.


************************************************************************
*  DEFINICION DE PARAMETROS DE SELECCION                               *
************************************************************************


SELECTION-SCREEN BEGIN OF BLOCK uno WITH FRAME TITLE text-001.
SELECTION-SCREEN SKIP.
PARAMETERS: p_bukrs LIKE glt0-bukrs OBLIGATORY.       "Sociedad
SELECT-OPTIONS: s_kunnr FOR bsad-kunnr,               "Nº cuenta
                s_budat FOR bsad-budat OBLIGATORY.    "Fecha contab.

SELECTION-SCREEN END OF BLOCK uno.






************************************************************************
*  DEFINICION DE VARIABLES                                             *
************************************************************************






************************************************************************
*                                                                      *
*                                                                      *
*                        T R A T A M I E N T O                         *
*                                                                      *
*                                                                      *
************************************************************************

*----------------------------------------------------------------------*
*     START-OF-SELECTION                                               *
*----------------------------------------------------------------------*

START-OF-SELECTION.
  PERFORM selecciona_datos.
  PERFORM procesa_datos.

END-OF-SELECTION.
  PERFORM pinta.





************************************************************************
*                                                                      *
*                                                                      *
*                        S U B - R U T I N A S                         *
*                                                                      *
*                                                                      *
************************************************************************
*&---------------------------------------------------------------------*
*&      Form  selecciona_datos
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*

FORM selecciona_datos .

  SELECT * APPENDING CORRESPONDING FIELDS OF TABLE i_cliente
                FROM kna1
               WHERE kunnr IN s_kunnr.

ENDFORM.                    " selecciona_datos


*&---------------------------------------------------------------------*
*&      Form  procesa_datos
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*

FORM procesa_datos .
  DATA: BEGIN OF i_items OCCURS 0.
          INCLUDE STRUCTURE bapi3007_2.
  DATA: END   OF i_items.

  DATA: companycode LIKE  bapi3007_1-comp_code,
        customer    LIKE  bapi3007_1-customer,
        date_from   LIKE  bapi3007-from_date,
        date_to     LIKE  bapi3007-to_date,
        v_debe      LIKE bsid-dmbtr,
        v_haber     LIKE bsid-dmbtr,
        v_dif       LIKE bsid-dmbtr.

  IF s_budat-high IS INITIAL.
    s_budat-high = s_budat-low.
  ENDIF.

  companycode = p_bukrs.
  date_from   = s_budat-low.
  date_to     = s_budat-high.


  LOOP AT i_cliente.
    CLEAR i_items. REFRESH i_items.
    customer    = i_cliente-kunnr.



    CALL FUNCTION 'BAPI_AR_ACC_GETSTATEMENT'
      EXPORTING
        companycode       = p_bukrs
        customer          = customer
        date_from         = date_from
        date_to           = date_to
*     NOTEDITEMS        = ' '
*     IMPORTING
*      RETURN            =

      TABLES
        lineitems         = i_items.


    CLEAR: v_debe, v_haber.
    LOOP AT i_items.

      IF i_items-db_cr_ind = 'S'.
        v_debe  = v_debe + i_items-amount.
      ELSE.
        v_haber = v_haber + i_items-amount.
      ENDIF.

    ENDLOOP.

    PERFORM name1_cliente USING i_cliente-kunnr.
    PERFORM saldo USING i_datos-saldo.
    if i_datos-saldo < 0.
      v_haber = v_haber + ( i_datos-saldo * ( - 1 ) ).
    else.
      v_debe = v_debe + i_datos-saldo.
    endif.

    MOVE: v_debe          TO i_datos-debe,
          v_haber         TO i_datos-haber,
          i_cliente-kunnr TO i_datos-kunnr,
          kna1-name1      TO i_datos-name1.

    v_dif = v_debe - v_haber.
    IF v_dif < 0.
      i_datos-dif_haber = v_dif * ( - 1 ).
    ELSE.
      i_datos-dif_debe  = v_dif.
    ENDIF.


*    PERFORM saldo USING i_datos-saldo.

    IF i_datos-debe      IS INITIAL AND
       i_datos-haber     IS INITIAL AND
       i_datos-saldo     IS INITIAL.
    ELSE.
      APPEND i_datos.
      CLEAR  i_datos.
    ENDIF.

  ENDLOOP.

ENDFORM.                    " procesa_datos


*&---------------------------------------------------------------------*
*&      Form  name1_cliente
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_CLIENTE_KUNNR  text
*----------------------------------------------------------------------*

FORM name1_cliente  USING    p_kunnr.

  SELECT SINGLE * FROM kna1 WHERE kunnr = p_kunnr.

ENDFORM.                    " name1_cliente


*&---------------------------------------------------------------------*
*&      Form  saldo
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_DATOS_saldo  text
*----------------------------------------------------------------------*

FORM saldo  USING    p_saldo.
  DATA: BEGIN OF keybalance OCCURS 0.
          INCLUDE STRUCTURE bapi3007_3.
  DATA: END   OF keybalance.

  DATA: companycode LIKE bapi3007_1-comp_code,
        customer    LIKE bapi3007_1-customer,
        keydate     LIKE bapi3007-key_date,
        anio(4).

  companycode = p_bukrs.
  customer    = i_cliente-kunnr.
  anio        = s_budat-high(4) - 1.

  CONCATENATE anio '1231' INTO keydate.


*-- BAPI para sacar el Saldo Anterior.

  CALL FUNCTION 'BAPI_AR_ACC_GETKEYDATEBALANCE'
    EXPORTING
      companycode = companycode
      customer    = customer
      keydate     = keydate
    TABLES
      keybalance  = keybalance.

  p_saldo = keybalance-lc_bal.

ENDFORM.                    " saldo


*&---------------------------------------------------------------------*
*&      Form  pinta
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*

FORM pinta .
  DATA: var_saldo(30),
        var_debe(30),
        var_haber(30),
        anio(4).

  repname = sy-repid.
  anio    = s_budat-high(4) - 1.

* Descripción estándar de campos
  PERFORM obt_descrip_campos_tabla USING repname 'I_DATOS'.
* Asignar TOP OF PAGE
  PERFORM asignar_top_of_page.
* Quitamos el cero de los importes.
  PERFORM no_zero USING: 'DEBE'         'X',
                         'HABER'        'X',
                         'DIF_DEBE'     'X',
                         'DIF_HABER'    'X',
                         'SALDO'        'X'.
* Marcamos los campos de los sumatorios.
  PERFORM no_sum USING: 'DEBE'         'X',
                        'HABER'        'X',
                        'DIF_DEBE'     'X',
                        'DIF_HABER'    'X',
                        'SALDO'        'X'.
* Cambiamos la descripción
  CONCATENATE 'Débiteur' s_budat-high(4)
         INTO var_debe SEPARATED BY space.

  CONCATENATE 'Créditeur' s_budat-high(4)
         INTO var_haber SEPARATED BY space.

  CONCATENATE 'Solde' anio
         INTO var_saldo SEPARATED BY space.

  PERFORM cambio_descripcion USING:
   'DEBE'                  'Cumul Débit'    'Cumul Débit'
                           'Cumul Débit'    'Cumul Débit',
   'HABER'                 'Cumul Crédit'   'Cumul Crédit'
                           'Cumul Crédit'   'Cumul Crédit',
   'KUNNR'                 'Nº Compte'      'Nº Compte'
                           'Nº Compte'      'Nº Compte',
   'NAME1'                 'Intitulé'       'Intitulé'
                           'Intitulé'       'Intitulé',
   'DIF_DEBE'              var_debe         var_debe
                           var_debe         var_debe,
   'DIF_HABER'             var_haber        var_haber
                           var_haber        var_haber,
   'SALDO'                 var_saldo        var_saldo
                           var_saldo        var_saldo.

* Características generales del listado
  PERFORM carac_gen_listado.

* Disposición  gs_disvariant-report  = repname.

* Se muestra el listado
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = repname
      is_layout          = layout
      it_fieldcat        = fieldtab[]
      it_events          = events[]
      i_save             = 'A'
      is_variant         = gs_disvariant
    TABLES
      t_outtab           = i_datos
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.

ENDFORM.                    " pinta

*&---------------------------------------------------------------------*
*&      Form  cambio_descripcion
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*

FORM cambio_descripcion USING pf_fieldname
                              pf_scrtext_l
                              pf_scrtext_m
                              pf_scrtext_s
                              pf_coltext.

  READ TABLE fieldtab WITH KEY fieldname = pf_fieldname ASSIGNING <fs>.
  IF sy-subrc EQ 0.
    <fs>-seltext_l = pf_scrtext_l.
    <fs>-seltext_m = pf_scrtext_m.
    <fs>-seltext_s = pf_scrtext_s.
    <fs>-reptext_ddic = pf_coltext.
  ENDIF.

ENDFORM.                    " cambio_descripcion

*&---------------------------------------------------------------------*
*&      Form  no_zero
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*

FORM no_zero USING pf_fieldname
                   p_zero.

  READ TABLE fieldtab WITH KEY fieldname = pf_fieldname ASSIGNING <fs>.
  IF sy-subrc EQ 0.
    <fs>-no_zero = p_zero.
  ENDIF.

ENDFORM.                    " no_zero

*&---------------------------------------------------------------------*
*&      Form  no_sum
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*

FORM no_sum USING pf_fieldname
                  p_sum.

  READ TABLE fieldtab WITH KEY fieldname = pf_fieldname ASSIGNING <fs>.
  IF sy-subrc EQ 0.
    <fs>-do_sum  = p_sum.
  ENDIF.

ENDFORM.                    " p_sum

*---------------------------------------------------------------------*
*       FORM alv_top_of_page                                          *
*---------------------------------------------------------------------*
*     Textos de cabecera
*       - typ,   " H = Header, S = Selection, A = Action
*       - key,
*       - info,
*---------------------------------------------------------------------*

FORM alv_top_of_page.

  DATA: lt_list_commentary TYPE slis_t_listheader,
        ls_list_commentary TYPE slis_listheader.
  DATA: v_date(60).

  SELECT SINGLE * FROM t001 WHERE bukrs = p_bukrs.

  CONCATENATE 'Du' s_budat-low+6(2) '/'
                   s_budat-low+4(2) '/'
                   s_budat-low(4)   'au'
                   s_budat-high+6(2) '/'
                   s_budat-high+4(2) '/'
                   s_budat-high(4)
         INTO v_date SEPARATED BY space.

* Componemos texto de cabecera
  CLEAR ls_list_commentary.
  ls_list_commentary-typ  = 'H'.
  ls_list_commentary-info = 'Balance des comptes clients'.
  APPEND ls_list_commentary TO lt_list_commentary.
*
  CLEAR ls_list_commentary.
  ls_list_commentary-typ  = 'S'.
  ls_list_commentary-key  = 'Société:'.
  ls_list_commentary-info = t001-butxt.
  APPEND ls_list_commentary TO lt_list_commentary.
*
  CLEAR ls_list_commentary.
  ls_list_commentary-typ  = 'S'.
  ls_list_commentary-key  = 'Date comptable:'.
  ls_list_commentary-info = v_date.
  APPEND ls_list_commentary TO lt_list_commentary.
*
  CLEAR ls_list_commentary.
  ls_list_commentary-typ  = 'A'.
  ls_list_commentary-info = 'Edition Provisiore - Experimé en euros'.
  APPEND ls_list_commentary TO lt_list_commentary.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = lt_list_commentary.

ENDFORM.                    "alv_top_of_page

89
Programación ABAP / Re: Sy-uname Nombre largo del usuario
« en: 10 de Agosto de 2007, 10:12:08 am »
Hola,

No entiendo muy bien porque igualas SY-UNAME = YPACHECO, pero aquí te dejo un pequeño código para que veas de donde se sacan los nombres completos.


    SELECT SINGLE * FROM usr21
                   WHERE bname = sy-uname.

    SELECT SINGLE name_text INTO v_nombre FROM adrp
                            WHERE persnumber = usr21-persnumber.



Espero que sea esto lo que buscas.

Un saludo,
Oscar.

90
Programación ABAP / Re: variables compuesta
« en: 07 de Agosto de 2007, 09:06:35 am »
Hola Irua,

A la hora de declarar la tabla interna se puede declarar T_inicial = T_NACHN+0(1).

Yo en su lugar pondría:


DATA: BEGIN OF T_PA0002 OCCURS 0,
      T_NACHN LIKE PA0002-NACHN,
      T_PERNR LIKE PA0002-PERNR,
      T_VORNA LIKE PA0002-VORNA,
      T_inicial(1).
END OF T_PA0002.


Y luego si... haciendo un loop a la tabla interna le pasas el primer caracter de la tabla T_NACHN.

T_inicial = T_NACHN(1).


Un saludo.

Páginas: 1 ... 4 5 [6] 7 8