✒️ABAP El ALV jerárquico y el agrupamiento
ABAP El ALV jerárquico y el agrupamiento
UNIDAD 5: REPORTES
LECCION 8:ALV JERARQUICO Y AGRUPAMIENTO
1| Agrupamiento en un ALV
- Se debe declarar una tabla tipo SLIS_T_SORTINFO_ALV y una estructura del tipo
SLIS_SORTINFO_ALV
ti_sort type SLIS_T_SORTINFO_ALV,
st_sort type SLIS_SORTINFO_ALV,
Luego cargamos los registros en la tabla interna con el orden a agrupar
CLEAR st_sort.
st_sort-spos = '1',
st_sort-fieldname = 'ESTADO CIVIL'.
APPEND st_sort TO ti_sort.
Completamos el parámetro exporting IT_SORT del ALV con la Tabla Interna TI_SORT
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = v_repid
i_callback_pf_status_set= 'PF_STATUS'
i_callback_user_command = 'USER_COMMAND'
it_fieldcat = ti_catalog[]
i_callback_top_of_page = 'TOP_OF_PAGE'
is_layout = st_layout
it_sort = ti_sort
TABLES
t_outtab = ti_usuarios.
Y ejecutamos y veremos la agrupación por estado civil.
2| ALV JERARQUICO
- se utilizan cuando mostramos datos de cabecera y posición en el reporte, en los cuales
debe haber al menos un campo en común.
Ejemplo:
* Tabla interna de cabecera
DATA: BEGIN OF ti_cabecera OCCURS 0,
carrid LIKE scarr-carrid,
carrname LIKE scarr-carrname,
END OF ti_cabecera.
* Tabla interna de posiciones
DATA: BEGIN OF ti_detalle OCCURS 0,
carrid LIKE sflight-carrid,
connid LIKE sflight-connid,
fldate LIKE sflight-fldate,
price LIKE sflight-price,
currency LIKE sflight-currency,
planettype LIKE sflight-planettype,
END OF ti_detalle.
declaramos una estructura del tipo SLIS_KEYINFO_ALV, que sera ST_KEYINFO la cual
contendrá la clave que una a los dos tablas.
ST_KEYINFO type SLIS_KEYINFO_ALV.
Cargamos la tabla de cabecera y posición
*Cabecera 1
ti_cabecera-carrid = 'ARG'.
ti_cabecera-carrname = 'Aerolíneas Argentinas'.
APPEND ti_cabecera.
*Detalle 1
ti_detalle-carrid = 'ARG'.
ti_detalle-cconnid = '1010'.
ti_detalle-fldate = '20091111'.
ti_detalle-price = '380'.
ti_detalle-currency = 'USD'.
ti_detalle-planettype = 'A310'.
APPEND ti_detalle.
*Detalle 2
ti_detalle-carrid = 'ARG'.
ti_detalle-cconnid = '1020'.
ti_detalle-fldate = '20091111'.
ti_detalle-price = '300'.
ti_detalle-currency = 'USD'.
ti_detalle-planettype = 'A330'.
APPEND ti_detalle.
Creamos el catalogo del ALV, para ambas tablas y sumamos
los campos en la TI_CATALOGO
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_internal_tabname = 'TI_CABECERA'
i_client_never_display = 'X'
i_inclname = sy-repid
CHANGING
ct_fieldcat = ti_catalog[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_internal_tabname = 'TI_DETALLE'
i_client_never_display = 'X'
i_inclname = sy-repid
CHANGING
ct_fieldcat = ti_catalog[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
Completamos la estructura ST_KEYINFO.
CLEAR st_keyinfo.
st_keyinfo-header01 = 'CARRID'.
st_keyinfo-item01 = 'CARRID'.
Ejecutamos la función REUSE_ALV_HIERSEQ_LIST_DISPLAY
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
i_callback_program = SY-repid
i_callback_pf_status_set= 'PF_STATUS'
It_fieldcat = ti_catalog[]
i_tabname_header = 'TI_CABECERA'
i_tabname_item = 'TI_DETALLE'
is_keyinfo = st_keyinfo
TABLES
t_outtab_header = ti_cabecera.
t_outtab_item = ti_detalle
EXCEPTIONS
program_error = 1
OTHERS = 2.
Ejecutamos.
Nota.- dos cosas que no se pueden hacer en un ALV jerarquico es que no se
puede utilizar el TOP_OF_PAGE (no pasa títulos ni logos) tampoco exportar a excel.
 
 
 
Sobre el autor
Publicación académica de Hernan Cabezas, en su ámbito de estudios para la Carrera Consultor ABAP.
Hernan Cabezas
Peru - Legajo: ZM88T
✒️Autor de: 117 Publicaciones Académicas
🎓Egresado de los módulos:
Certificación Académica de Hernan Cabezas