En este informe podemos ver los Balances de los Proveedores, para ello utilizamos la BAPI
.
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