✒️ABAP / La creación de un ALV TREE orientado a objetos Por Jaime Gomez Arango

Selector Alummnos / Empresas

ABAP La creación de un ALV TREE orientado a objetos

ABAP La creación de un ALV TREE orientado a objetos

Creating an ALV Tree Using Object Orientation

In this tutorial, we'll walk through the creation of a program, Z_LLENAR_SPFLI, which populates data into the standard table SPFLI containing flight information. Then, using transaction SE38, we'll create the program Z_ALV_TREE.

Key Points:

  • Internal Table Declaration: We start by declaring an internal table with 7 fields, which will be displayed on the screen.
  • Instance Variables: We declare variables to instantiate two classes, CL_GUI_ALV_TREE and CL_GUI_CUSTOM_CONTAINER.
  • Data Retrieval: Inside the START-OF-SELECTION event, we construct the obtener_datos subroutine, which retrieves all data from the SPFLI table.
  • Instance Check: We check if the tree has not been instantiated yet, then we instantiate both the tree and the container.
  • Catalog Filling: The fill_catalog_tree subroutine fills the catalog.
  • Hierarchy Building: We build the data hierarchy of the tree using the build_hierarchy_header and create_hierarchy subroutines.
  • Displaying ALV: Finally, we call the method to display the ALV on the screen.
  • Dynpro Creation: We also need to create a dynpro where we place a custom control containing the ALV Tree and a GUI status for screen navigation.
  • Execution: Execute the program to see the output on the screen.

E.g

*&---------------------------------------------------------------------*
*& Report Z_ALV_TREE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT z_alv_tree.

*----------------------------------------------------------------------*
* DECLARACION DE TYPES
*----------------------------------------------------------------------*
TYPES: BEGIN OF ty_spfli,
carrid TYPE spfli-carrid,
connid TYPE spfli-connid,
countryfr TYPE spfli-countryfr,
cityfrom TYPE spfli-cityfrom,
airpfrom TYPE spfli-airpfrom,
countryto TYPE spfli-countryto,
cityto TYPE spfli-cityto,
END OF ty_spfli.

TYPES: BEGIN OF ty_header,
carrid TYPE spfli-carrid,
END OF ty_header.

*----------------------------------------------------------------------*
* DECLARACION DE TABLAS INTERNAS
*----------------------------------------------------------------------*
DATA: t_spfli TYPE STANDARD TABLE OF ty_spfli WITH HEADER LINE,
tab_tree TYPE STANDARD TABLE OF ty_spfli WITH HEADER LINE,
t_tree TYPE STANDARD TABLE OF ty_spfli WITH HEADER LINE,
t_header TYPE STANDARD TABLE OF ty_header WITH HEADER LINE.

*----------------------------------------------------------------------*
* DECLARACION DE VARIABLES
*----------------------------------------------------------------------*
DATA: g_alv_tree TYPE REF TO cl_gui_alv_tree,
l_hierarchy_header TYPE treev_hhdr,
gs_fieldcat TYPE lvc_s_fcat,
gt_fieldcat_tree TYPE lvc_t_fcat,
g_custom_container TYPE REF TO cl_gui_custom_container.

*----------------------------------------------------------------------*
* DECLARACION DE FIELD-SYMBOLS
*----------------------------------------------------------------------*
FIELD-SYMBOLS: <header> LIKE LINE OF t_header,
<spfli> LIKE LINE OF t_spfli.

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

* Obtenemos los datos que se mostrarán en el ALV
PERFORM obtener_datos.

IF g_alv_tree IS INITIAL.
* Se crearán los objetos correspondientes al CONTAINER y el ALV TREE
PERFORM init_tree.

CALL METHOD cl_gui_cfw=>flush
EXCEPTIONS
cntl_system_error = 1
cntl_error = 2.
ENDIF.

CALL SCREEN 100.

*----------------------------------------------------------------------*
* FORM init_tree *
*----------------------------------------------------------------------*
FORM init_tree.

DATA: l_tree_container_name(30) TYPE c.

l_tree_container_name = 'TREE_CONTROL'.

* Creamos el objeto CONTAINER
CREATE OBJECT g_custom_container
EXPORTING
container_name = l_tree_container_name
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.


* Creamos el objeto del ALV TREE
CREATE OBJECT g_alv_tree
EXPORTING
parent = g_custom_container
node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
item_selection = ''
no_html_header = 'X'
no_toolbar = ''
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
illegal_node_selection_mode = 5
failed = 6
illegal_column_name = 7.

* Completamos el catálogo
PERFORM fill_catalog_tree.

* Construimos la jerarquia del ALV TREE
PERFORM build_hierarchy_header CHANGING l_hierarchy_header.

* Ejecutamos el método que muestra el ALV
CALL METHOD g_alv_tree->set_table_for_first_display
EXPORTING
is_hierarchy_header = l_hierarchy_header
CHANGING
it_outtab = t_tree[]
it_fieldcatalog = gt_fieldcat_tree.

PERFORM create_hierarchy.

ENDFORM. "INIT_TREE

*----------------------------------------------------------------------*
* FORM FILL_CATALOG_TREE
*----------------------------------------------------------------------*
FORM fill_catalog_tree.

DATA: gs_fieldcat_add TYPE lvc_s_fcat.

CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 1.
gs_fieldcat-reptext = 'Flight'.
gs_fieldcat-scrtext_s = 'Flight'.
gs_fieldcat-fieldname = 'CONNID'.
gs_fieldcat-tabname = 'T_SPFLI'.
APPEND gs_fieldcat TO gt_fieldcat_tree.

CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 2.
gs_fieldcat-reptext = 'Country'.
gs_fieldcat-scrtext_s = 'Country'.
gs_fieldcat-fieldname = 'COUNTRYFR'.
gs_fieldcat-tabname = 'T_SPFLI'.
APPEND gs_fieldcat TO gt_fieldcat_tree.

CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 3.
gs_fieldcat-reptext = 'Dep.City'.
gs_fieldcat-scrtext_s = 'Dep.City'.
gs_fieldcat-fieldname = 'CITYFROM'.
gs_fieldcat-tabname = 'T_SPFLI'.
gs_fieldcat-outputlen = '15'.
APPEND gs_fieldcat TO gt_fieldcat_tree.

CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 4.
gs_fieldcat-reptext = 'Dep.Airp'.
gs_fieldcat-scrtext_s = 'Dep.Airp'.
gs_fieldcat-fieldname = 'AIRPFROM'.
gs_fieldcat-tabname = 'T_SPFLI'.
gs_fieldcat-outputlen = '20'.
APPEND gs_fieldcat TO gt_fieldcat_tree.

CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 5.
gs_fieldcat-reptext = 'Country'.
gs_fieldcat-scrtext_s = 'Country'.
gs_fieldcat-fieldname = 'COUNTRYTO'.
gs_fieldcat-tabname = 'T_SPFLI'.
gs_fieldcat-outputlen = '15'.
APPEND gs_fieldcat TO gt_fieldcat_tree.

CLEAR gs_fieldcat.
gs_fieldcat-col_pos = 6.
gs_fieldcat-reptext = 'Arr.City'.
gs_fieldcat-scrtext_s = 'Arr.City'.
gs_fieldcat-fieldname = 'CITYTO'.
gs_fieldcat-tabname = 'T_SPFLI'.
gs_fieldcat-outputlen = '20'.
APPEND gs_fieldcat TO gt_fieldcat_tree.

ENDFORM. "FILL_CATALOG_TREE
*----------------------------------------------------------------------*
* FORM build_hierarchy_header
*----------------------------------------------------------------------*
FORM build_hierarchy_header CHANGING p_hierarchy_header TYPE treev_hhdr.
CLEAR p_hierarchy_header.
p_hierarchy_header-heading = 'Airline carrier'(300).
p_hierarchy_header-width = 18.
p_hierarchy_header-width_pix = ' '.
ENDFORM. "BUILD_HIERARCHY_HEADER
*----------------------------------------------------------------------*
* FORM create_hierarchy *
*----------------------------------------------------------------------*
FORM create_hierarchy.

DATA: l_root_key TYPE lvc_nkey,
l_next_key TYPE lvc_nkey,
l_last_key TYPE lvc_nkey,
header TYPE string,
w_menge_text(13) TYPE c.

CLEAR l_root_key.

LOOP AT t_header ASSIGNING <header>.
CLEAR l_root_key.
CLEAR l_next_key.

* Agregamos un nuevo nodo en el ALV TREE
PERFORM add_node USING <header>-carrid l_root_key
CHANGING l_next_key.

LOOP AT t_spfli ASSIGNING <spfli> WHERE carrid EQ <header>-carrid.
MOVE-CORRESPONDING <spfli> TO tab_tree.
PERFORM add_leaf USING tab_tree l_next_key
CHANGING l_last_key.
ENDLOOP.
ENDLOOP.

* Actualizamos el ALV TREE
CALL METHOD g_alv_tree->frontend_update.
ENDFORM. "CREATE_HIERARCHY

*----------------------------------------------------------------------*
* FORM ADD_NODE
*----------------------------------------------------------------------*
FORM add_node USING l_name l_root_key CHANGING l_next_key.

DATA: l_node_text TYPE lvc_value,
ls_tree TYPE ty_spfli.

l_node_text = l_name.

CALL METHOD g_alv_tree->add_node
EXPORTING
i_relat_node_key = l_root_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = ls_tree
IMPORTING
e_new_node_key = l_next_key.

ENDFORM. "ADD_NODE

*----------------------------------------------------------------------*
* FORM ADD_LEAF *
*----------------------------------------------------------------------*
FORM add_leaf USING l_tree TYPE ty_spfli
l_next_key
CHANGING l_last_key.

CALL METHOD g_alv_tree->add_node
EXPORTING
i_relat_node_key = l_next_key
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = tab_tree
IMPORTING
e_new_node_key = l_last_key.

ENDFORM. "ADD_LEAF

*----------------------------------------------------------------------*
* FORM OBTENER_DATOS
*----------------------------------------------------------------------*
FORM obtener_datos.

SELECT carrid connid countryfr cityfrom
airpfrom countryto cityto
INTO TABLE t_spfli
FROM spfli.

IF sy-subrc EQ 0.
LOOP AT t_spfli ASSIGNING <spfli>.
MOVE <spfli>-carrid TO t_header-carrid.
APPEND t_header.
ENDLOOP.

SORT t_header.

DELETE ADJACENT DUPLICATES FROM t_header.

ENDIF.

ENDFORM. "OBTENER_DATOS

*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS '0100'.
SET TITLEBAR '0100'.
ENDMODULE. " STATUS_0100 OUTPUT

*&---------------------------------------------------------------------*
*& Module EXIT_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
MODULE exit_command_0100 INPUT.
LEAVE PROGRAM.
ENDMODULE. " EXIT_COMMAND_0100 INPUT


 

Escanear / Compartir

 

 


Sobre el autor

Publicación académica de Jaime Eduardo Gomez Arango, en su ámbito de estudios para la Carrera Consultor ABAP Nivel Avanzado.

SAP Expert


Jaime Eduardo Gomez Arango

Profesión: Ingeniero de Sistemas y Computación - España - Legajo: SW34C

✒️Autor de: 149 Publicaciones Académicas

🎓Egresado de los módulos:

Disponibilidad Laboral: FullTime

Presentación:

Ingeniero de sistemas y computación con 8 años de experiencia el desarrollo frontend & backend (react/node) y en cloud (aws), actualmente desarrollando habilidades en sap btp, ui5, abap y fiori.

Certificación Académica de Jaime Gomez

✒️+Comunidad Académica CVOSOFT

Continúe aprendiendo sobre el tema "La creación de un ALV TREE orientado a objetos" de la mano de nuestros alumnos.

SAP Master


La creación de un ALV TREE orientado a objetos Objetivo del video Aprender a crear un ALV tree orientado a objetos. Construir el programa Z-- para llenar la tabla estándar SPFLY con datos de vuelos. Desarrollar el programa Z-ALV tree que mostrará el árbol en pantalla. Estructura y componentes clave Tabla interna de siete campos que se visualizará en la pantalla. Variables para instanciar las clases ClGuiALBTree y ClGuiCustomContainer. DimPro con un Custom Control que contendrá el ALV tree. Un estatus GUI para navegar entre pantallas. Procedimiento de implementación En el evento StartOfSelections crear la subrutina...

Acceder a esta publicación

Creado y Compartido por: Juan Ignacio Romero

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Expert



La creación de un ALV Tree orientado a objetos en SAP permite mostrar datos jerárquicos de forma interactiva en ABAP, usando clases estándar como CL_GUI_ALV_TREE o CL_GUI_SIMPLE_TREE. El proceso inicia creando un contenedor (por ejemplo, CL_GUI_CUSTOM_CONTAINER) para alojar el control. Luego, se instancia el objeto ALV Tree y se definen columnas y layout mediante métodos como SET_TABLE_FOR_FIRST_DISPLAY o ADD_NODE. Los nodos se agregan con identificadores únicos, estableciendo relaciones padre-hijo para la jerarquía. Es posible manejar eventos (doble clic, expansión) implementando clases manejadoras y registrándolas con SET_REGISTERED_EVENTS. Este enfoque orientado a objetos facilita la...

Acceder a esta publicación

Creado y Compartido por: David Ibarra / Disponibilidad Laboral: FullTime + Carta Presentación

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

lección "9: La creación de un ALV TREE orientado a objetos": • Introducción y Utilidad del ALV Tree Esta sección introduce el ALV Tree orientado a objetos como una herramienta valiosa en ABAP, destacando su propósito y el alcance de la lección. â—¦ Tipo de Reporte: Es un tipo de reporte útil para completar requerimientos específicos de clientes. â—¦ Frecuencia de Uso: No se utiliza con tanta frecuencia como otros tipos de reportes ALV. â—¦ Objetivo de la Lección: Aprender a crear un ALV Tree orientado a objetos. • Pasos para la Creación del ALV Tree Orientado a Objetos (Programa Z_ALV_TREE) Aquí se detallan los pasos esenciales y las...

Acceder a esta publicación

Creado y Compartido por: Roberto Fluder Ahumada

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Expert


Existe otra clase estándar de ABAP que podemos utilizar para la creación de los ALV TREE orientados a objetos esta clase es la CL_GUI_ALV_TREE_SIMPLE vale la pena destacar que mediante la utilización de la clase CL_GUI_ALV_TREE no es posible crear una jerarquía tal como hacemos con la clase estándar CL_GUI_ALV_TREE podemos tomar como ejemplo el programa estándar BCALV_TREE_SIMPLE_DEMO el cual nos va a servir de referencia para aprender a generar reportes ALV_TREE orientados a objetos utilizando la clase CL_GUI_ALV_TREE_SIMPLE. ************************************************ Existen muchos programas estándar muy útiles que podemos tener en cuenta a la hora de querer implementar diferentes...

Acceder a esta publicación

Creado y Compartido por: Jose Medina / Disponibilidad Laboral: FullTime + Carta Presentación

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Expert


Creating an ALV Tree Using Object Orientation In this tutorial, we'll walk through the creation of a program, Z_LLENAR_SPFLI, which populates data into the standard table SPFLI containing flight information. Then, using transaction SE38, we'll create the program Z_ALV_TREE. Key Points: Internal Table Declaration: We start by declaring an internal table with 7 fields, which will be displayed on the screen. Instance Variables: We declare variables to instantiate two classes, CL_GUI_ALV_TREE and CL_GUI_CUSTOM_CONTAINER. Data Retrieval: Inside the START-OF-SELECTION event, we construct the obtener_datos subroutine, which retrieves all data from the SPFLI table. Instance Check: We check if the tree has not been instantiated yet,...

Acceder a esta publicación

Creado y Compartido por: Jaime Eduardo Gomez Arango / Disponibilidad Laboral: FullTime + Carta Presentación

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Master

CREACION ALV TREE OO: Creamos el reporte Z_LLENAR_SPFLI ( contiene información sobre vuelos). Luego se creamos Z_ALV_TREE, clic en display. Declaramos una tabla interna con campos que luego se muestra en pantalla . En el evento STAR-OF-SELECTION , se creamos la subrutina para recuperar todos los datos de la tabla SPFLI. Si el árbol no fue instanciado construimos una instancia del árbol y del conteiner. Con la rutina fill_catalog-tree se llena el catalogo. Se construye la jerarquía del árbol mediante la subrutina build_hierarchy_header y créate_hierarchy. Clic en screens. Clic en 0100. Clic en LAYOUT t y en STATUS GUI para navegar en pantalla. Ejecutamos el programa y se visualiza por...

Acceder a esta publicación

Creado y Compartido por: Pedro Salazar / Disponibilidad Laboral: FullTime + Carta Presentación

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Master


A continuación veremos un video donde aprenderemos a crear un ALV TREE Orientado a objetos. Si bien es un tipo de reporte que no se utiliza con tanta frecuencia, es muy útil tenerlo en cuenta para cumplimentar requerimientos puntuales del cliente en donde nos desempeñemos como programadores. Programa útiles para tener en cuenta Existen muchos programas estándar muy útiles que podemos tener en cuenta a la hora de querer implementar diferentes funcionalidades a nuestro ALV TREE. Algunos de ellos son: BCALV_TREE_01 BCALV_TREE_02 BCALV_TREE_03 BCALV_TREE_04 BCALV_TREE_05 BCALV_TREE_06 BCALV_TREE_DND_MULTIPLE AUDIO ACLARATIVO: Existe otra clase estándar de ABAP que podemos utilizar para la...

Acceder a esta publicación

Creado y Compartido por: Pedro Antonio Duarte / Disponibilidad Laboral: FullTime

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Expert


LA CREACIÓN DE UN ALV TREE ORIENTADO A OBJETOS Construiremos el programa Z_LLENAR_SPFLI, el cual llena con datos la tabla estándar SPFLI que contiene información sobre vuelos. Luego mediante la transacción SE38 construiremos el programa Z_ALV_TREE. Los puntos más importantes a tener en cuenta del programa son: Declaramos una tabla interna con 7 campos, la cual se mostrará por pantalla. Declaramos una variable para instanciar la clase CL_GUI_ALV_TREE y otra para instanciar la clase CL_GUI_CUSTOM_CONTAINER. Dentro del evento START-OF-SELECTION construimos la subrutina obtener_datos la cual recupera todos los datos de la tabla SPFLI. Luego si el arbol no fue instanciado todavía,...

Acceder a esta publicación

Creado y Compartido por: Ducelvis Lolimar Arcia Cova / Disponibilidad Laboral: FullTime + Carta Presentación

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Expert


1 | ALV TREE orientado a objetos Existen muchos programas estándar muy útiles que podemos tener en cuenta a la hora de querer implementar diferentes funcionalidades a un ALV TREE. Algunos de ellos son: BCALV_TREE_01 BCALV_TREE_02 BCALV_TREE_03 BCALV_TREE_04 BCALV_TREE_05 BCALV_TREE_0 BCALV_TREE_DND_MULTIPLE A parte de la clase CL_GUI_ALV_TREE existe otra clase estándar de ABAP que podemos utilizar para la creación de los ALV TREEs orientados a objetos. Esta clase es la clase CL_GUI_ALV_TREE_SIMPLE. Vale la pena destacar que mediante la utilización de la clase CL_GUI_ALV_TREE_SIMPLE no es posible crear una jerarquía tal como hacemos con la clase CL_GUI_ALV_TREE....

Acceder a esta publicación

Creado y Compartido por: Alex Francisco Lemos Collazos

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Senior

CREACIÓN DE UN ALV TREE ORIENTADO A OBJETOS. En este vídeo aprenderemos a realizar un ALV TREE orientado a objetos para ello construiremos el programa Z_LLENAR_SPFLI el cual llena contactos la tabla estándar SPFLI que contiene información sobre vuelos luego construiremos el programa z _ALV_TREE los puntos más importantes a tener en cuenta del programa son declaramos una tabla interna con 7 campo la cual se mostrará por pantalla declaramos una variable para instanciar la clase CL_GUI_ALV_TREE para instanciar la clase CL_GUI_CUSTOM_CONTAINER dentro del evento STAR-OF-SELECTION construimos la subrutina obtener datos la cual recupera todos los datos de la tabla SPFLI luego si el árbol no fue instanciado...

Acceder a esta publicación

Creado y Compartido por: Diego Armando De Santiago Castanon

 


 

👌Genial!, estos fueron los últimos artículos sobre más de 99.000 publicaciones académicas abiertas, libres y gratuitas compartidas con la comunidad, para acceder a ellas le dejamos el enlace a CVOPEN ACADEMY.

🔎Buscador de Publicaciones:

 


 

No sea Juan... Solo podrá llegar alto si realiza su formación con los mejores!