MUNDOSAP

MUNDOSAP (foro/index.php)
-   Programación ABAP IV (foro/forumdisplay.php?f=4)
-   -   Como recalcular totales en reporte ALV?? (foro/showthread.php?t=62418)

Eduesqueda 26/04/12 16:35:21

Como recalcular totales en reporte ALV??
 
Hola a todos de casualidad alguien sabe lo siguiente:

1.- Tengo un reporte ALV que despliega ciertas columnas y la última columna es un checkbox para seleccionar o deseleccionar el renglón.
2.- También al desplegar mi reporte me muestra totales por proveedor (LIFNR) y un total TOTAL. Y lo que sumariza es el importe (WRBTR). Todos los renglones la primer vez aparecen seleccionados o marcados.
3.- Tengo el evento "data_changed" que me detecta si el usuario selecciona o deselecciona el checkbox del renglón. Si el usuario "Deselecciona" entonces se limpia el Checkbox....si el usuario "Selecciona" entonces se marca el checkbox. Y también se actualiza el checkbox en mi tabla de salida. De tal manera que mi tabla de salida es un reflejo del reporte ALV.

La duda es??:

Como le podría hacer para que me esté recalculando los totales ( proveedor y total total) dependiendo de los renglones que se estén seleccionando?


Ejemplo de ALV al principio:

lifnr wrbtr checkbox
10 200 x
10 150 x

TOTAL 10 350

20 300 x
20 131 x
20 70 x

TOTAL 20 501

TOTAL 851


Ahora si yo desmarco
el proveedor 10 importe 200 y
el proveddor 20 importe 70 poniendole al checkbox blancos,
quiero que me quede asi EN LOS TOTALES:

lifnr wrbtr checkbox
10 200
10 150 x

TOTAL 10 150

20 300 x
20 131 x
20 70

TOTAL 20 431

TOTAL 581

La tabla de salida para el alv tiene estas columnas: lifnr, wrbtr, envio (que es el checkbox).
El campo envio se actualiza con espacios o x cada vez que el usuario deselecciona o selecciona.
Siempre tengo que mostrar los marcados y no marcados en la tabla de salida para el ALV por lo que no le puedo mandar en una tabla de salida al ALV solo los registros marcados para el recálculo de totales.

EN BASE A LO ANTERIOR:
Se puede recalcular los totales, DEPENDIENDO DEL CHECKBOX AL MOMENTO QUE SE ESTA SELECCIONANDO O DESELECCIONANDO?? Como??

Y la tabla de salida está así después de seleccionar o deseleccionar por renglón según el evento "Data_Changed":

lifnr wrbtr envio
10 200
10 150 x
20 300 x
20 131 x
20 70

ES DECIR QUIERO QUE PARA LOS TOTALES SOLO SUME LOS REGISTROS MARCADOS CON X CUANDO MUESTRO LA TABLA EN ALV YA QUE AHORITA SUMA TODOS LOS RENGLONES DE LA TABLA DE SALIDA AL ALV.


Saludos y espero alguien me pueda ayudar.
Gracias.

kibo 26/04/12 19:54:39

La suma la hace de manera std? deberias de hacer la suma manual. Entonces en tu evento de data change, haces los calculos manuales y le "appendias" la linea a tu tabla de salida.

Es medio picapiedra la cosa

Eduesqueda 26/04/12 20:19:13



Si gracias, lo que pasa es que no puedo agregar nada a la tabla de salida porque esto es lo que el usuario está viendo y va a seleccionar para generar un archivo de salida con lo seleccionado y si lo hago como tú dices entonces los botones estandard de SAP en ALV para grupos, cortes y totales me van a incluír en la suma los totales que yo calculé como me estás diciendo y aparte me va a activar el checkbox en estos renglones calculados y el usuario los podría seleccionar cuando no debe ser.

Por lo que mejor lo hago de manera estandard con las rutinas ya creadas por sap, pasandole solo la tabla de salida con sus registros a sumarizar y que SAP haga los totales pero solo quiero que no me sume o no me incluya en los totales los que no tienen el checkbox seleccionado.

Esto ya está en la tabla a desplegar con los campos: lifnr, wrbtr y checkbox solo que me suma todos los registros.....y solo quiero los marcados en el checkbox.

Utilizo las rutinas estandar de SAP como:

1.- * Construction of the Layout.
PERFORM f_construction_layout.----> llena estructura con valores de layout

2.- * Build field catalog
PERFORM f_build_fieldcatalog---> utiliza la funcion: FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

*Aqui especifico que el importe es el campo que se sumará.
WHEN 'WRBTR'.
lw_fieldcat-do_sum = c_x.

3.- * Build Events
PERFORM f_build_events---> llena evento estatus y data_changed
CHANGING i_events.

4.- * Build Sort Criteria
PERFORM f_build_sortCat.--->llena estructura para que sume por proveedor como:

CLEAR wa_sort.
REFRESH it_sortCat.
wa_sort-spos = 1.
wa_sort-fieldname = 'LIFNR'.
wa_sort-up = c_x.
wa_sort-subtot = c_x. "subtotals any totals column by this field
APPEND wa_sort TO it_sortCat.
CLEAR wa_sort.

5.- * Display alv report on output screen
PERFORM f_display_alv_report.--->utiliza la funcion:
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

Eduesqueda 27/04/12 16:52:19



TIENES ALGUNA OTRA IDES KIBO? O ALGUIEN MAS??
HELP, PLEASE!!

kibo 27/04/12 17:02:26

No creo que al ALV_GRID puedas hacer de manera std eso... o al menos yo no lo se, si estuviera en Objetos tenes un poco mas de chances.

La UNICA que se me ocurre, es que copies la funcion de sumarizacion e un Z y ahi le puedas metar vos que solo tenga en cuenta los registros marcados.

No es muy alentadora la idea porque tendras que debuguear el std un rato pero desde mis pocos conocimientos no se me ocurre mas, tal vez puedas buscar en SDN a ver si saben algo.

Y sino la respuesta mas habitual "No, mira... eso SAP no lo contempla, bajalo a Excel y cualquier cosa preguntale a Microsft :p "

Eduesqueda 27/04/12 17:34:16



OK.....KIBO....MUCHAS GRACIAS....ESO ES LO QUE ESTABA DEBUGUEANDO HACE RATO LA FUNCION: REUSE_ALV_GRID_DISPLAY PERO ME DESESPERE...voy a ver si encuentro el sumarizado para excluír los que no fueron marcados.....

y si no les voy a decir que no se puede en SAP....

GRACIAS y te aviso si pude encontrar el punto exacto para cambiar en la funcion.

Saludos

DCErick 27/04/12 20:04:23

Puedes truquear los subtotales con el evento SUBTOTAL_TEXT, hacer tu calculo con los registros marcados y reemplazar el valor, pero el grand total seguirá siendo el de todos los registros de la tabla....

DCErick 27/04/12 21:00:16

En el evento changed, haz lo sigiuente:


Bueno ya tu le metes la lógica para calcular los totales en base a tu check.... Creo que tendré que ir a tu consultora a pasarte mas trucos xD.

Eduesqueda 27/04/12 21:39:13



JIJIJIJI....Si verdad, me falta mucho, yo sé. Muchas Gracias, DERICK, lo voy a probar te estoy avisando...gracias y saludos.


HOLA DCERICK, FIJATE QUE PROBE EL CODIGO COMO ME DIJISTES EN EL EVENTO DATA_CHANGED Y SI VI QUE FUNCIONA MUY BIEN. ** CAMBIA EL RENGLON DE LA TABLA DEL EL TOTAL TOTAL AL VALOR 100 ó 1000 (WRBTR)
** CAMBIA TODA LA INFO DE LA TABLA DE LOS SUBTOTALES POR PROVEEDOR AL VALOR 100 (WRBTR)

PERO NO ME CAMBIA EN MI ALV O PANTALLA NADA al salir del evento DATA_CHANGED y regresa a mi ALV, DEBERIA VER EL TOTAL TOTAL con 1000 Y LOS TOTALES POR PROVEEDOR CON 100.
PERO SIGUE CON LOS DATOS ORIGINALES...PORQUE?

GRACIAS Y SI ME PUDIERAS DECIR TE LO AGRADECERIA DE TODO CUCHARON.
SALUDOS.

DCErick 27/04/12 23:09:25

mmm sabes, no tengo forma de probarlo ahorita con el user_command

Yo lo puse en el top_of_page y me jala bien....

Eduesqueda 30/04/12 14:37:43

____________________________________________________________

Buen día, DERICK y hola: disculpa esta forma que me dijistes al final me debe actualizar los totales de mi alv en pantalla autómaticamente? Será que a mi no me funcionó porque estoy usando funciones estandar de sap para desplegar mi alv?

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

mi tabla al alv se llama i_alv. y solo contiene los registros a sumarizar.

saludos

DCErick 30/04/12 15:13:29


Asi es, eso te coloca los totales en tu ALV, ah yo tambien lo hice con REUSE_ALV_GRID_DISPLAY, recuerda agregar el evento yo lo hice desde el parametro i_callback_top_of_page


'SUB_ALV_TOP_OF_PAGE' <- Nombre del form donde coloqué el código que te mandé xD.

Eduesqueda 30/04/12 16:33:38



________________________________________________________

YA LO HICE TAMBIEN ASI Y NO ME FUNCIONO, NI MODO...GRACIAS DERICK.

DCErick 30/04/12 16:46:21



Algo te debe estar faltando....
Que versión de SAP tienes?
¿Puedes compartir tu programa para ver como le estas haciendo?

Eduesqueda 30/04/12 20:20:24

_____________________________________________________________
VERSION 6.4 (COMO COMPARTO EL PGMA Y SUS INCLUDES? ESQUE NO ME DEJA ATACHARLOS TODOS PERO HAY VAN SOLO 3 RUTINAS)

PROGRAME LO QUE ME DIJISTES EN LA RUTINA DEL TOP ANTES DEL ENDFORM

_____________________________________________________________
ESTA ES LA RUTINA DEL DISPLAY ALV
_____________________________________________________________

*&---------------------------------------------------------------------*
*& Form F_DISPLAY_ALV_REPORT *
*&---------------------------------------------------------------------*
* Display alv report on output screen *
*----------------------------------------------------------------------*

FORM f_display_alv_report .

* Local variables------------------------------------------------------*
DATA: lv_program TYPE sy-repid,
i_lvc_s_glay LIKE lvc_s_glay.

i_lvc_s_glay-edt_cll_cb = 'X'.

CLEAR w_variant.

lv_program = sy-repid.

* Variant for ALV.
w_variant-report = lv_program.
w_variant-variant = p_vari.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = lv_program
i_callback_pf_status_set = 'C'
i_callback_user_command = 'USER_COMMAND'
i_callback_top_of_page = 'F_ALV_TOP'
i_structure_name = 'I_ALV'
i_grid_settings = i_lvc_s_glay
is_layout = w_layout
it_fieldcat = i_fieldcat
it_sort = it_sortCat
i_default = c_x
i_save = c_a
is_variant = w_variant
it_events = i_events
TABLES
t_outtab = i_alv
EXCEPTIONS
program_error = 1
OTHERS = 2.

IF sy-subrc <> c_zeros.

MESSAGE ID sy-msgid
TYPE sy-msgty
NUMBER sy-msgno
WITH sy-msgv1
sy-msgv2
sy-msgv3
sy-msgv4.
ENDIF.

ENDFORM. " F_DISPLAY_ALV_REPORT
_____________________________________________________________

ESTA ES LA RUTINA DEL TOP
_____________________________________________________________


*&---------------------------------------------------------------------*
*& Form f_alv_top *
*&---------------------------------------------------------------------*
* Routine To generate the headed one of the ALV *
*----------------------------------------------------------------------*
FORM f_alv_top.

* Local Variables------------------------------------------------------*
DATA: lv_date(10) TYPE c,
lv_layout(50) TYPE c,
lv_textvar LIKE varit-vtext,
lv_variant(50) TYPE c.

* to verify that the Head does not have data.
REFRESH i_list_top.
* CHECK i_list_top[] IS INITIAL.

* Change Sy-Datum by Sy-Datlo.
WRITE sy-datlo TO lv_date DD/MM/YYYY.

* Create the name of the file to be generated.
CLEAR: i_gs_line.
i_gs_line-typ = c_s.
i_gs_line-key = text-t03. "File
i_gs_line-info = p_displ.
APPEND i_gs_line TO i_list_top.

* Create Date
CLEAR: i_gs_line.
i_gs_line-typ = c_s.
i_gs_line-key = text-t01. "Date
i_gs_line-info = lv_date.
APPEND i_gs_line TO i_list_top.

* Create User
CLEAR: i_gs_line.
i_gs_line-typ = c_s. "Line type [H]eader
i_gs_line-key = text-t02. "User
i_gs_line-info = sy-uname.
APPEND i_gs_line TO i_list_top.
CLEAR: i_gs_line.

* Create Total Records
CLEAR: i_gs_line.
i_gs_line-typ = c_s. "Line type [H]eader
i_gs_line-key = text-t04. "Total records
i_gs_line-info = v_tot_reg_t.
APPEND i_gs_line TO i_list_top.

CALL FUNCTION 'RS_VARIANT_TEXT'
EXPORTING
curr_report = sy-cprog
langu = sy-langu
variant = sy-slset
IMPORTING
v_text = lv_textvar
EXCEPTIONS
no_text = 1.
IF sy-subrc EQ c_zeros.
CONCATENATE sy-slset
lv_textvar
INTO lv_variant
SEPARATED BY space.
ENDIF.

* i_gs_line-typ = c_s. " Line type [H]eader
* i_gs_line-key = text-t05. " Variant
* i_gs_line-info = lv_variant.
* APPEND i_gs_line TO i_list_top.

* Create the Third label of Title
CLEAR: i_gs_line.

CONCATENATE p_vari
v_text_lay
INTO lv_layout
SEPARATED BY space.

CLEAR: i_gs_line.
i_gs_line-typ = c_s. " Line type [H]eader
i_gs_line-key = text-t06. " Layout
i_gs_line-info = lv_layout.
APPEND i_gs_line TO i_list_top.

* Write the Headed
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = i_list_top.

ENDFORM. " f_alv_top
_____________________________________________________________

ESTA ES LA RUTINA DE DATA_CHANGED
_____________________________________________________________


*&---------------------------------------------------------------------*
*& Form DATA_CHANGED
*&---------------------------------------------------------------------*
* Modifies the CheckBox in the ALV Report
*----------------------------------------------------------------------*
* <--P_I_EXTAB text
*----------------------------------------------------------------------*
FORM data_changed
USING rr_data TYPE REF TO cl_alv_changed_data_protocol.

DATA : ls_mod_cell TYPE lvc_s_modi,
lv_value TYPE lvc_value.

SORT rr_data->mt_mod_cells BY row_id .
LOOP AT rr_data->mt_mod_cells INTO ls_mod_cell.
IF ls_mod_cell-fieldname = 'DESPU'.
READ TABLE i_alv index ls_mod_cell-row_id .
IF sy-subrc = 0.
i_alv-despu = ls_mod_cell-value.
MODIFY i_alv index ls_mod_cell-row_id.
CALL METHOD rr_data->MODIFY_CELL
EXPORTING
i_row_id = ls_mod_cell-row_id
i_fieldname = 'DESPU'
i_value = ls_mod_cell-value.
ENDIF.
ENDIF.
ENDLOOP.

ENDFORM.

DCErick 30/04/12 20:39:14

mmm

No veo nada en el f_alv_top no está el código que te pase.

Eduesqueda 30/04/12 21:38:38

_____________________________________________________________

Si lo quité,, ya la acabo de poner y probar y los totales no cambian al valor de 100.
Asi quedó la rutina:

*&---------------------------------------------------------------------*
*& Form f_alv_top *
*&---------------------------------------------------------------------*
* Routine To generate the headed one of the ALV *
*----------------------------------------------------------------------*
FORM f_alv_top.

* Local Variables------------------------------------------------------*
DATA: lv_date(10) TYPE c,
lv_layout(50) TYPE c,
lv_textvar LIKE varit-vtext,
lv_variant(50) TYPE c.


DATA: BEGIN OF i_sumSel OCCURS 0,
waers LIKE i_alv-waers, "Moneda
wrbtr LIKE i_alv-wrbtr, "Importe
END OF i_sumSel.

* to verify that the Head does not have data.
REFRESH i_list_top.
* CHECK i_list_top[] IS INITIAL.

* Change Sy-Datum by Sy-Datlo.
WRITE sy-datlo TO lv_date DD/MM/YYYY.

* Create the name of the file to be generated.
CLEAR: i_gs_line.
i_gs_line-typ = c_s.
i_gs_line-key = text-t03. "File
i_gs_line-info = p_displ.
APPEND i_gs_line TO i_list_top.

* Create Date
CLEAR: i_gs_line.
i_gs_line-typ = c_s.
i_gs_line-key = text-t01. "Date
i_gs_line-info = lv_date.
APPEND i_gs_line TO i_list_top.

* Create User
CLEAR: i_gs_line.
i_gs_line-typ = c_s.
i_gs_line-key = text-t02. "User
i_gs_line-info = sy-uname.
APPEND i_gs_line TO i_list_top.
CLEAR: i_gs_line.

* Create Total Records
DESCRIBE TABLE i_alv
LINES v_tot_reg_t.

CLEAR: i_gs_line.
i_gs_line-typ = c_s.
i_gs_line-key = text-t04. "Total records
i_gs_line-info = v_tot_reg_t.
APPEND i_gs_line TO i_list_top.

* Create Selected Total Records
v_tot_reg_s = c_zeros.
REFRESH i_sumSel.
CLEAR i_sumSel.
LOOP AT i_alv.
IF i_alv-despu = c_x.
v_tot_reg_s = v_tot_reg_s + c_uno.
i_sumSel-waers = i_alv-waers.
i_sumSel-wrbtr = i_alv-wrbtr.
COLLECT i_sumSel.
ENDIF.
ENDLOOP.

CLEAR: i_gs_line.
i_gs_line-typ = c_s.
i_gs_line-key = text-t05. "Total Selected
i_gs_line-info = v_tot_reg_s.
APPEND i_gs_line TO i_list_top.

* Create Total Moneda
LOOP AT i_sumSel.
CLEAR: i_gs_line.
i_gs_line-typ = c_s.

CONCATENATE text-t06 "Total Moneda
i_sumSel-waers
INTO i_gs_line-key
SEPARATED BY SPACE.

CONCATENATE i_gs_line-key
c_2ptos
INTO i_gs_line-key.

i_gs_line-info = i_sumSel-wrbtr.
APPEND i_gs_line TO i_list_top.
ENDLOOP.

CALL FUNCTION 'RS_VARIANT_TEXT'
EXPORTING
curr_report = sy-cprog
langu = sy-langu
variant = sy-slset
IMPORTING
v_text = lv_textvar
EXCEPTIONS
no_text = 1.
IF sy-subrc EQ c_zeros.
CONCATENATE sy-slset
lv_textvar
INTO lv_variant
SEPARATED BY space.
ENDIF.

* i_gs_line-typ = c_s. " Line type [H]eader
* i_gs_line-key = text-t05. " Variant
* i_gs_line-info = lv_variant.
* APPEND i_gs_line TO i_list_top.

* Create the Third label of Title
CLEAR: i_gs_line.

CONCATENATE p_vari
v_text_lay
INTO lv_layout
SEPARATED BY space.

CLEAR: i_gs_line.
i_gs_line-typ = c_s. " Line type [H]eader
i_gs_line-key = text-t07. " Layout
i_gs_line-info = lv_layout.
APPEND i_gs_line TO i_list_top.

* Write the Headed
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = i_list_top.

* Código que me pasastes.

DATA: lo_grid TYPE REF TO cl_gui_alv_grid.

* Obtenemos referencia al ALV
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = lo_grid.

* Tablas internas para grantotal y subtotal.
* En este caso solo tenemos un subtotal, si se subtotalizara por otros
* campos hay que agregar mas it_##.
DATA: it_00 TYPE REF TO data,
it_01 TYPE REF TO data.

CALL METHOD lo_grid->get_subtotals
IMPORTING
ep_collect00 = it_00 "Gran Total
ep_collect01 = it_01. "Novel LIFNR

* Cambiamos los datos.
FIELD-SYMBOLS: <ft_tab> TYPE ANY TABLE,
<fs_tab> TYPE ANY,
<ff_field> TYPE ANY.

* Gran Total
ASSIGN it_00->* TO <ft_tab>.
LOOP AT <ft_tab> ASSIGNING <fs_tab>.
ASSIGN COMPONENT 'WRBTR' OF STRUCTURE <fs_tab> TO <ff_field>.
<ff_field> = '1000'. "Modificamos
ENDLOOP.

* LIFNR Level
ASSIGN it_01->* TO <ft_tab>.
LOOP AT <ft_tab> ASSIGNING <fs_tab>.
ASSIGN COMPONENT 'WRBTR' OF STRUCTURE <fs_tab> TO <ff_field>.
<ff_field> = '100'. "Modificamos
ENDLOOP.

ENDFORM. " f_alv_top

DCErick 30/04/12 21:45:02

1 Adjunto(s)
Hola, trata de usar etiquetas para encerrar tu código, es medio molesto leerlo sin etiquetas xD ""....

Como ultimo intento te dejo un ejemplo, si ese no te funciona dile a tu usuario que no se puede jajaja.

Eduesqueda 30/04/12 22:26:56

____________________________________________________________

GRACIAS MUCHAS.....LO VOY A CHECAR....TE AVISO.....SALUDOS.
GRACIAS POR LA MOLESTIA.
BYE.
_____________________________________________________________
HOLA DCERICK NO SE PUDO TAMPOCO, PERO LO QUE HICE FUE PONERLE DOS TOTALES POR MONEDA TOTALES EN EL TOP DEL ALV Y UN TOTAL DE REGISTROS SELECCIONADOS.
CADA VEZ QUE SELECCIONO O DESELECCIONO UN RENGLON DEL ALV ESTOS TRES INDICADORES CAMBIAN.
GRACIAS.


Husos Horarios son GMT. La hora en este momento es 23:54:46.

www.mundosap.com 2006 - Spain
software crm, crm on demand, software call center, crm act, crm solutions, crm gratis, crm web