✒️ABAP Social Break - Laboratorio de Ideas
ABAP Social Break - Laboratorio de Ideas
USO COMBINADO DE BDL CON ALV JERARQUICO.
Hola: Os dejo el código fuente de un reporte que accede a una base de datos lógica y presenta el resultado en un ALV Jerárquico. Espero que sea de utilidad para alguno de vosotros.
- *&---------------------------------------------------------------------*
- *& Report ZGZ57B_ALV_BDL
- *&
- *&---------------------------------------------------------------------*
- *&
- *&
- *&---------------------------------------------------------------------*
- REPORT zgz57b_alv_bdl.
- TABLES:
- spfli,
- sflight,
- sbook,
- scarr.
- *---------------------------------------------------------------------*
- * Requrimientos ALV
- *---------------------------------------------------------------------*
- TYPE-POOLS:
- slis.
- DATA:
- * Tabla interna y estructura del ALV
- ti_alv TYPE slis_t_fieldcat_alv,
- wa_alv TYPE slis_fieldcat_alv,
- * Estructura para la configuración de la salida
- wa_layout TYPE slis_layout_alv,
- * Tabla interna y estructura para excluir funcionalidades
- ti_alv_excl TYPE slis_t_extab,
- wa_alv_excl TYPE slis_extab,
- * Tabla interna y estructura para la cabecera
- ti_alv_header TYPE slis_t_listheader,
- wa_alv_header TYPE slis_listheader,
- * Tabla interna y estructura para ordenamiento
- ti_alv_sort TYPE slis_t_sortinfo_alv,
- wa_alv_sort TYPE slis_sortinfo_alv,
- * Campo Clave para ALV Jerarquicos
- wa_alv_keyinfo TYPE slis_keyinfo_alv,
- * Tabla interna y estructura del ALV Orientado Objetos
- ti_oalv TYPE lvc_t_fcat,
- wa_oalv TYPE lvc_s_fcat,
- * Estructura para la configuración de la salida OO
- wa_olayout TYPE lvc_s_layo,
- * Tabla interna y estructura para excluir funcionalidades
- * ti_alv_excl TYPE slis_t_extab,
- * wa_alv_excl TYPE slis_extab,
- * Tabla interna y estructura para la cabecera
- * ti_oalv_header TYPE slis_t_listheader,
- * wa_oalv_header TYPE slis_listheader,
- * Tabla interna y estructura para ordenamiento
- * ti_oalv_sort TYPE slis_t_sortinfo_alv,
- * wa_oalv_sort TYPE slis_sortinfo_alv,
- * Variable con el nombre del programa
- v_repid LIKE sy-repid.
- DATA:
- g_oalv_grid TYPE REF TO cl_gui_alv_grid,
- g_disp_cont TYPE REF TO cl_gui_custom_container.
- DATA:
- g_user_fn(30) TYPE c.
- *--------------- Fin Requerimientos ALV ------------------------------*
- *---------------------------------------------------------------------*
- * Tipos para las Tablas de los Informes
- *---------------------------------------------------------------------*
- TYPES:
- BEGIN OF ty_trayectos,
- carrid LIKE spfli-carrid, "Codigo Aerolinea
- connid LIKE spfli-connid, "Codigo Trayecto
- carrname LIKE scarr-carrname, "Nombre Aerolinea
- cityfrom LIKE spfli-cityfrom, "Ciudad Origen
- airpfrom LIKE spfli-airpfrom, "Aeropuerto Origen
- cityto LIKE spfli-cityto, "Ciudad Destino
- airpto LIKE spfli-airpto, "Aeropuerto Destino
- deptime LIKE spfli-deptime, "Hora Despegue
- arrtime LIKE spfli-arrtime, "Hora Aterrizaje
- checkh(1) TYPE c, "Checkbox
- END OF ty_trayectos.
- TYPES:
- BEGIN OF ty_vuelos,
- carrid LIKE sflight-carrid, "Codigo Aerolinea
- connid LIKE sflight-connid, "Codigo Trayecto
- planetype LIKE sflight-planetype, "Tipo Avion
- fldate LIKE sflight-fldate, "Fecha Vuelo
- price LIKE sflight-price, "Precio
- paymentsum LIKE sflight-paymentsum, "Total Recaudado
- currency LIKE sflight-currency, "Moneda
- seatsocc LIKE sflight-seatsocc, "Billetes Turista
- seatsocc_b LIKE sflight-seatsocc_b, "Billetes Business
- seatsocc_f LIKE sflight-seatsocc_f, "Billetes Primera
- checkd(1) TYPE c, "Checkbox
- END OF ty_vuelos.
- *---------------------------------------------------------------------*
- * Tablas Internas y Registros (Workareas)
- *---------------------------------------------------------------------*
- DATA:
- ti_header TYPE STANDARD TABLE OF ty_trayectos,
- wa_header TYPE ty_trayectos,
- ti_detalle TYPE STANDARD TABLE OF ty_vuelos,
- wa_detalle TYPE ty_vuelos.
- DATA:
- BEGIN OF wa_scarr,
- carrname LIKE scarr-carrname,
- END OF wa_scarr.
- *----------------------------------------------------------------------*
- START-OF-SELECTION.
- *----------------------------------------------------------------------*
- GET spfli.
- SELECT SINGLE carrname FROM scarr
- INTO wa_scarr
- WHERE carrid = spfli-carrid.
- CLEAR wa_header.
- MOVE-CORRESPONDING spfli TO wa_header.
- wa_header-carrname = wa_scarr-carrname.
- APPEND wa_header TO ti_header.
- GET sflight.
- CLEAR wa_detalle.
- MOVE-CORRESPONDING sflight TO wa_detalle.
- APPEND wa_detalle TO ti_detalle.
- *----------------------------------------------------------------------*
- END-OF-SELECTION.
- *----------------------------------------------------------------------*
- PERFORM set_alv_layout USING wa_layout 'Informe de Trayectos y Vuelos por Aerolinea' "Titulo
- 'X' "Zebra
- ' ' "Sin linea vertical
- ' ' "Sin linea horizontal
- ' ' "Optimizar columnas
- ' ' "Totales Primero
- ' ' "Solo Subtotales
- 'CHECKD' "Campo Checkbox
- 'TI_DETALLE'. "Tabla checkbox
- PERFORM build_sort_group TABLES ti_alv_sort.
- PERFORM build_alv_hier TABLES ti_alv.
- CLEAR wa_alv_keyinfo.
- wa_alv_keyinfo-header01 = 'CARRID'.
- wa_alv_keyinfo-item01 = 'CARRID'.
- wa_alv_keyinfo-header02 = 'CONNID'.
- wa_alv_keyinfo-item02 = 'CONNID'.
- PERFORM run_alv_hier TABLES ti_alv ti_header ti_detalle ti_alv_sort
- USING 'TI_HEADER' 'TI_DETALLE' wa_layout.
- *&---------------------------------------------------------------------*
- *& Form BUID_ALV_HIER
- *&---------------------------------------------------------------------*
- * text
- *----------------------------------------------------------------------*
- * --> p1 text
- * <-- p2 text
- *----------------------------------------------------------------------*
- FORM build_alv_hier TABLES p_ti_alv TYPE slis_t_fieldcat_alv.
- REFRESH p_ti_alv.
- PERFORM alv_add_field TABLES p_ti_alv
- USING 'x' 'TI_HEADER' 'CARRID' 3 'L' 'IAA' '' '' '' 1.
- PERFORM alv_add_field TABLES p_ti_alv
- USING 'x' 'TI_HEADER' 'CARRNAME' 20 'L' 'Aerolinea' '' '' '' 1.
- PERFORM alv_add_field TABLES p_ti_alv
- USING 'x' 'TI_HEADER' 'CONNID' 5 'Z' 'Vuelo' '' '' '' 1.
- PERFORM alv_add_field TABLES p_ti_alv
- USING 'x' 'TI_HEADER' 'CITYFROM' 20 'L' 'Ciudad Origen' '' '' '' 1.
- PERFORM alv_add_field TABLES p_ti_alv
- USING 'x' 'TI_HEADER' 'AIRPFROM' 6 'C' 'Origen' '' '' '' 1.
- PERFORM alv_add_field TABLES p_ti_alv
- USING 'x' 'TI_HEADER' 'CITYTO' 20 '' 'Ciudad Destino' '' '' '' 1.
- PERFORM alv_add_field TABLES p_ti_alv
- USING 'x' 'TI_HEADER' 'AIRPTO' 6 'C' 'Destino' '' '' '' 1.
- PERFORM alv_add_field TABLES p_ti_alv
- USING 'x' 'TI_HEADER' 'DEPTIME' 8 'L' 'H.Salida' '' '' '' 1.
- PERFORM alv_add_field TABLES p_ti_alv
- USING 'x' 'TI_HEADER' 'ARRTIME' 8 'L' 'H.Llegada' '' '' '' 1.
- PERFORM alv_add_field TABLES p_ti_alv
- USING 'x' 'TI_DETALLE' 'PLANETYPE' 12 '' 'Mod.Avion' '' '' '' 1.
- PERFORM alv_add_field TABLES p_ti_alv
- USING 'x' 'TI_DETALLE' 'FLDATE' 10 '' 'Fecha' '' '' '' 1.
- PERFORM alv_add_field TABLES p_ti_alv
- USING 'x' 'TI_DETALLE' 'PRICE' 10 '' 'Precio' '' '' '' 1.
- PERFORM alv_add_field TABLES p_ti_alv
- USING 'x' 'TI_DETALLE' 'PAYMENTSUM' 15 '' 'Total' '' '' '' 1.
- PERFORM alv_add_field TABLES p_ti_alv
- USING 'x' 'TI_DETALLE' 'CURRENCY' 6 'C' 'Moneda' '' '' '' 1.
- PERFORM alv_add_field TABLES p_ti_alv
- USING 'x' 'TI_DETALLE' 'SEATSOCC' 7 'R' 'Turista' '' '' '' 1.
- PERFORM alv_add_field TABLES p_ti_alv
- USING 'x' 'TI_DETALLE' 'SEATSOCC_B' 8 'R' 'Business' '' '' '' 1.
- PERFORM alv_add_field TABLES p_ti_alv
- USING 'x' 'TI_DETALLE' 'SEATSOCC_F' 7 'R' 'Primera' '' '' '' 1.
- ENDFORM. "BUID_ALV_HIER
- *&---------------------------------------------------------------------*
- *& Form BUILD_SORT_GROUP
- *&---------------------------------------------------------------------*
- * text
- *----------------------------------------------------------------------*
- * -->P_TI_ALV_SORT text
- * -->P_P_TPAIS text
- * -->P_P_TCITY text
- * -->P_P_TCLI text
- * -->P_P_TFRA text
- * -->P_P_SPAIS text
- * -->P_P_SCITY text
- *----------------------------------------------------------------------*
- FORM build_sort_group TABLES p_ti_alv_sort TYPE slis_t_sortinfo_alv.
- DATA:
- wal LIKE LINE OF p_ti_alv_sort,
- lv_sorttabname TYPE string,
- lv_count_pos TYPE i.
- lv_count_pos = 1.
- *types: begin of slis_sortinfo_alv,
- * wal-spos like alvdynp-sortpos,
- * wal-fieldname type slis_fieldname,
- * wal-tabname type slis_fieldname,
- * wal-up like alvdynp-sortup,
- * wal-down like alvdynp-sortdown,
- * wal-group like alvdynp-grouplevel,
- * wal-subtot like alvdynp-subtotals,
- * wal-comp(1) type c,
- * wal-expa(1) type c,
- * wal-obligatory(1) type c,
- * end of slis_sortinfo_alv.
- lv_sorttabname = 'TI_HEADER'.
- CLEAR wal.
- wal-spos = lv_count_pos.
- wal-fieldname = 'CARRID'.
- wal-tabname = lv_sorttabname.
- wal-up = 'X'.
- * wal-group = 'X'.
- * wal-expa = 'X'.
- * wal-comp = 'X'.
- APPEND wal TO p_ti_alv_sort.
- ADD 1 TO lv_count_pos.
- CLEAR wal.
- wal-spos = lv_count_pos.
- wal-fieldname = 'CONNID'.
- wal-tabname = lv_sorttabname.
- wal-up = 'X'.
- wal-group = 'X'.
- * wal-expa = 'X'.
- wal-comp = 'X'.
- wal-subtot = 'X'.
- APPEND wal TO p_ti_alv_sort.
- ADD 1 TO lv_count_pos.
- ENDFORM. " BUILD_SORT_GROUP
- *----------------------------------------------------------------------*
- * Rutinas de Ayuda y Soporte de ALV
- *----------------------------------------------------------------------*
- *&---------------------------------------------------------------------*
- *& Form RUN_ALV_HIER
- *&---------------------------------------------------------------------*
- * text
- *----------------------------------------------------------------------*
- FORM run_alv_hier TABLES p_ti_alv TYPE slis_t_fieldcat_alv
- p_ti_head
- p_ti_item
- p_ti_sort TYPE slis_t_sortinfo_alv
- USING p_header
- p_item
- p_layout.
- CLEAR v_repid.
- v_repid = sy-repid.
- CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
- EXPORTING
- i_callback_program = sy-repid
- is_layout = p_layout
- it_fieldcat = p_ti_alv[]
- i_tabname_header = p_header
- i_tabname_item = p_item
- is_keyinfo = wa_alv_keyinfo
- it_sort = p_ti_sort[]
- TABLES
- t_outtab_header = p_ti_head
- t_outtab_item = p_ti_item
- EXCEPTIONS
- program_error = 1
- OTHERS = 2.
- IF sy-subrc NE 0.
- MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
- WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
- ENDIF.
- ENDFORM. "RUN_ALV_HIER
- *&---------------------------------------------------------------------*
- *& Form ALV_ADD_FIELD
- *&---------------------------------------------------------------------*
- * text
- *----------------------------------------------------------------------*
- * --> p1 text
- * <-- p2 text
- *----------------------------------------------------------------------*
- FORM alv_add_field TABLES p_ti_alv TYPE slis_t_fieldcat_alv
- USING value(p_islist) "ALV Modo Grid
- value(p_tabview) "Nombre Tabla
- value(p_field) "Nombre del campo
- value(p_length) "Ancho de la columna
- value(p_just) "Alineación
- value(p_header) "Descripción Cabecera
- value(p_sumup) "Campo que subtotaliza
- value(p_key) "Descripción Cabecera
- value(p_check) "Campo que subtotaliza
- value(p_line). "Campo que subtotaliza
- DATA:
- wal LIKE LINE OF p_ti_alv.
- DATA:
- lv_m(20) TYPE c,
- lv_l(40) TYPE c.
- CLEAR wal.
- wal-tabname = p_tabview.
- wal-fieldname = p_field.
- wal-outputlen = p_length.
- IF p_line IS NOT INITIAL.
- wal-row_pos = p_line.
- ENDIF.
- IF p_just = 'Z'.
- wal-lzero = 'X'.
- ELSE.
- wal-just = p_just.
- ENDIF.
- wal-seltext_s = p_header.
- wal-seltext_m = p_header.
- wal-seltext_l = p_header.
- wal-do_sum = p_sumup.
- wal-edit = p_check.
- wal-checkbox = p_check.
- wal-key = p_key.
- APPEND wal TO p_ti_alv.
- ENDFORM. "ALV_ADD_FIELD
- *&---------------------------------------------------------------------*
- *& Form SET_ALV_LAYOUT
- *&---------------------------------------------------------------------*
- * text
- *----------------------------------------------------------------------*
- FORM set_alv_layout USING wal TYPE slis_layout_alv
- value(p_title)
- value(p_zebra)
- value(p_novlin)
- value(p_nohlin)
- value(p_coptima)
- value(p_tfirst)
- value(p_stonly)
- value(p_fbox)
- value(p_tbox).
- *types: begin of slis_layout_alv,
- * no_colhead(1) type c, " no headings
- * no_hotspot(1) type c, " headings not as hotspot
- * zebra(1) type c, " striped pattern
- * no_vline(1) type c, " columns separated by space
- * no_hline(1) type c, "rows separated by space B20K8A0N5D
- * cell_merge(1) type c, " not suppress field replication
- * edit(1) type c, " for grid only
- * edit_mode(1) type c, " for grid only
- * numc_sum(1) type c, " totals for NUMC-Fields possib.
- * no_input(1) type c, " only display fields
- * f2code like sy-ucomm, "
- * reprep(1) type c, " report report interface active
- * no_keyfix(1) type c, " do not fix keycolumns
- * expand_all(1) type c, " Expand all positions
- * no_author(1) type c, " No standard authority check
- * ***** PF-status
- * def_status(1) type c, " default status space or 'A'
- * item_text(20) type c, " Text for item button
- * countfname type lvc_fname,
- * ***** Display options
- * colwidth_optimize(1) type c,
- * no_min_linesize(1) type c, " line size = width of the list
- * min_linesize like sy-linsz, " if initial min_linesize = 80
- * max_linesize like sy-linsz, " Default 250
- * window_titlebar like sy-title,
- * no_uline_hs(1) type c,
- * ***** Exceptions
- * lights_fieldname type slis_fieldname," fieldname for exception
- * lights_tabname type slis_tabname, " fieldname for exception
- * lights_rollname like dfies-rollname," rollname f. exceptiondocu
- * lights_condense(1) type c, " fieldname for exception
- * ***** Sums
- * no_sumchoice(1) type c, " no choice for summing up
- * no_totalline(1) type c, " no total line
- * no_subchoice(1) type c, " no choice for subtotals
- * no_subtotals(1) type c, " no subtotals possible
- * no_unit_splitting type c, " no sep. tot.lines by inh.units
- * totals_before_items type c, " diplay totals before the items
- * totals_only(1) type c, " show only totals
- * totals_text(60) type c, " text for 1st col. in total line
- * subtotals_text(60) type c, " text for 1st col. in subtotals
- * ***** Interaction
- * box_fieldname type slis_fieldname, " fieldname for checkbox
- * box_tabname type slis_tabname," tabname for checkbox
- * box_rollname like dd03p-rollname," rollname for checkbox
- * expand_fieldname type slis_fieldname, " fieldname flag 'expand'
- * hotspot_fieldname type slis_fieldname, " fieldname flag hotspot
- * confirmation_prompt, " confirm. prompt when leaving
- * key_hotspot(1) type c, " keys as hotspot " K_KEYHOT
- * flexible_key(1) type c, " key columns movable,...
- * group_buttons(1) type c, " buttons for COL1 - COL5
- * get_selinfos(1) type c, " read selection screen
- * group_change_edit(1) type c, " Settings by user for new group
- * no_scrolling(1) type c, " no scrolling
- * ***** Detailed screen
- * detail_popup(1) type c, " show detail in popup
- * detail_initial_lines(1) type c, " show also initial lines
- * detail_titlebar like sy-title," Titlebar for detail
- * ***** Display variants
- * header_text(20) type c, " Text for header button
- * default_item(1) type c, " Items as default
- * ***** colour
- * info_fieldname type slis_fieldname, " infofield for listoutput
- * coltab_fieldname type slis_fieldname, " colors
- * others
- * list_append(1) type c, " no call screen
- * xifunckey type aqs_xikey, " eXtended interaction(SAPQuery)
- * xidirect type flag, " eXtended INTeraction(SAPQuery)
- * dtc_layout type dtc_s_layo, "Layout for configure the Tabstip
- * allow_switch_to_list(1) type c, "ACC: Switch from FullGrid to List
- * end of slis_layout_alv.
- CLEAR wal.
- wal-no_colhead = ' '. " no headings
- wal-no_hotspot = ' '. " headings not as hotspot
- wal-zebra = p_zebra. " striped pattern
- wal-no_vline = p_novlin. " columns separated by space
- wal-no_hline = p_nohlin. "rows separated by space B20K8A0N5D
- wal-cell_merge = 'X'. " not suppress field replication
- wal-edit = ' '. " for grid only
- *wal-edit_mode = ' ' " for grid only
- wal-numc_sum = 'X'. " totals for NUMC-Fields possib.
- wal-no_input = ' '. " only display fields
- *wal-f2code = "
- wal-reprep = 'X'. " report report interface active
- wal-no_keyfix = ' '. " do not fix keycolumns
- *wal-expand_all = 'X'. " Expand all positions
- *wal-no_autho = ' '. " No standard authority check
- * ***** PF-status
- *wal-def_status = ' '. " default status space or 'A'
- *wal-item_text = ' '. " Text for item button
- *wal-countfname = ' '.
- * ***** Display options
- wal-colwidth_optimize = p_coptima.
- wal-no_min_linesize = ' '. " line size = width of the list
- wal-min_linesize = 80. " if initial min_linesize = 80
- wal-max_linesize = 250. " Default 250
- wal-window_titlebar = p_title.
- wal-no_uline_hs = ' '.
- * ***** Exceptions
- *wal-lights_fieldname type slis_fieldname," fieldname for exception
- *wal-lights_tabname type slis_tabname, " fieldname for exception
- *wal-lights_rollname like dfies-rollname," rollname f. exceptiondocu
- *wal-lights_condense(1) type c, " fieldname for exception
- * ***** Sums
- wal-no_sumchoice = ' '. " no choice for summing up
- wal-no_totalline = ' '. " no total line
- wal-no_subchoice = ' '. " no choice for subtotals
- wal-no_subtotals = ' '. " no subtotals possible
- wal-no_unit_splitting = ' '. " no sep. tot.lines by inh.units
- wal-totals_before_items = p_tfirst. " diplay totals before the items
- wal-totals_only = p_stonly. " show only totals
- wal-totals_text = ' '. " text for 1st col. in total line
- wal-subtotals_text = ' '. " text for 1st col. in subtotals
- * ***** Interaction
- IF p_fbox IS NOT INITIAL AND p_tbox IS NOT INITIAL.
- wal-box_fieldname = p_fbox. " fieldname for checkbox
- wal-box_tabname = p_tbox. " tabname for checkbox
- ENDIF.
- *wal-box_rollname = ' '. " rollname for checkbox
- *wal-expand_fieldname = ' '. " fieldname flag 'expand'
- *wal-hotspot_fieldname = ' '. " fieldname flag hotspot
- *wal-confirmation_prompt = ' '. " confirm. prompt when leaving
- *wal-key_hotspot = ' '. " keys as hotspot " K_KEYHOT
- *wal-flexible_key = ' '. " key columns movable,...
- wal-group_buttons = 'X'. " buttons for COL1 - COL5
- *wal-get_selinfos = ' '. " read selection screen
- *wal-group_change_edit = ' '. " Settings by user for new group
- *wal-no_scrolling = ' '. " no scrolling
- * ***** Detailed screen
- *wal-detail_popup = ' '. " show detail in popup
- *wal-detail_initial_lines = ' '. " show also initial lines
- *wal-detail_titlebar = ' '. " Titlebar for detail
- * ***** Display variants
- *wal-header_text = ' '. " Text for header button
- *wal-default_item = ' '. " Items as default
- * ***** colour
- *wal-info_fieldname = ' '. " infofield for listoutput
- *wal-coltab_fieldname = ' '. " colors
- * others
- *wal-list_append = ' '. " no call screen
- *wal-allow_switch_to_list = ' '. "ACC: Switch from FullGrid to List
- ENDFORM. " SET_ALV_LAYOUT
 
 
 
Agradecimiento:
Ha agradecido este aporte: Pedro Salazar
Sobre el autor
Publicación académica de Carlos Piles Rosell, en su ámbito de estudios para la Carrera Consultor ABAP.
Carlos Piles Rosell
Profesión: Analista de Sistemas y Programador - España - Legajo: GZ57B
✒️Autor de: 24 Publicaciones Académicas
🎓Egresado de los módulos:
Disponibilidad Laboral: PartTime
Certificación Académica de Carlos Piles