17
ALV ABAP LIST VIEWER Step by step…

Manual ALV

Tags:

Embed Size (px)

Citation preview

Page 1: Manual ALV

ALV

ABAP LIST VIEWER

Step by step…

Page 2: Manual ALV

Libretilla MarcosJ Miguel Jesús Fernández

2

ALV (ABAP LIST VIEWER).

ALV da soporte a la mayoría de los informes estándares de ABAP R/3. Contiene

una serie de módulos de funciones que podrían ser añadidos a los códigos de los

programas.

También puede añadir aspectos de interfaz a los report. Para incluir ALV en un

report:

1. Declarar data areas.

2. Declarar internal table.

3. Select data into internal table.

4. Build field catalogs.

5. Build event catalogs.

6. start ALV con los módulos.

7. Process call back events.

FUNCIONES ALV. *&---------------------------------------------------------------------*

*& Form BUILD_LAYOUT

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM build_layout .

gs_layout-colwidth_optimize = 'X'. "Optimizar ancho del listado

gs_layout-zebra = 'X'. "Mostrar líneas tipo cebra.

gs_layout-detail_popup = 'X'. "Mostrar opción de información detalle

ENDFORM. " BUILD_LAYOUT

*&---------------------------------------------------------------------*

*& Form call_alv

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* -->ALV_EMPLOYEE text

*----------------------------------------------------------------------*

FORM call_alv TABLES alv_employee.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = z_pruebareportalv

is_layout = gs_layout

it_fieldcat = gt_fieldcat[]

TABLES

t_outtab = i_aux

EXCEPTIONS

program_error = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE i799(cu) WITH 'Error creando el ALV'(008) 'Código'(009) sy-subrc.

ENDIF.

ENDFORM. "call_alv

*&---------------------------------------------------------------------*

*& Form BUILD_HEADER

*&---------------------------------------------------------------------*

Page 3: Manual ALV

Libretilla MarcosJ Miguel Jesús Fernández

3

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM build_header .

* explain field description to alv

CLEAR gt_fieldcat.

REFRESH gt_fieldcat.

fieldcat_ln-fieldname = 'PERNR'.

fieldcat_ln-seltext_l = 'NAME'(003).

APPEND fieldcat_ln TO gt_fieldcat.

fieldcat_ln-fieldname = 'NAME'.

fieldcat_ln-seltext_l = 'Date'(002).

APPEND fieldcat_ln TO gt_fieldcat.

fieldcat_ln-fieldname = 'LASTNAME'.

fieldcat_ln-seltext_l ='Time'(005).

APPEND fieldcat_ln TO gt_fieldcat.

fieldcat_ln-fieldname = 'BIRTH_DATE'.

fieldcat_ln-seltext_l ='Correlative Number'(006).

APPEND fieldcat_ln TO gt_fieldcat.

fieldcat_ln-fieldname = 'STREET_&_HOUSEN'.

fieldcat_ln-seltext_l ='Correct Execution'(007).

APPEND fieldcat_ln TO gt_fieldcat.

fieldcat_ln-fieldname = 'CITY'.

fieldcat_ln-seltext_l ='COMMENTS'(008).

APPEND fieldcat_ln TO gt_fieldcat.

fieldcat_ln-fieldname = 'COUNTRY'.

fieldcat_ln-seltext_l ='COMMENTS'(008).

APPEND fieldcat_ln TO gt_fieldcat.

* data sorting and subtotal

DATA: gs_sort TYPE slis_sortinfo_alv.

CLEAR gs_sort.

gs_sort-fieldname = 'SAP_SD_SEQNR'.

gs_sort-spos = 7.

gs_sort-up = 'X'.

APPEND gs_sort TO gt_sort.

ENDFORM. " BUILD_HEADER

Page 4: Manual ALV

Libretilla MarcosJ Miguel Jesús Fernández

4

CREACIÓN DE ESTRUCTURAS1

Abriremos la transacción se11. Escogeremos la opción “DATA TYPE” y le

pondremos nombre. Ahora haremos clic en “create”.

Escogeremos la opción “structure” y continuaremos. Ahora le pondremos una

pequeña descripción a nuestra estructura.

Tras esto comenzaremos a ponerle los campos que deseemos en la columna

“component”. Para darle un formato a ese campo cogeremos campos de los distintos

infotipos, por ejemplo, si cogemos el campo nombre buscaremos un infotipo que

contenga ese campo, comprobaremos el component type(presionando F1 sobre el campo

y clickando en las herramientas) y lo pondremos en la misma fila que nuestro

component. Tras esto guardaremos y la estructura estará creada.

*Para crear una tabla en ABAP a partir de una estructura utilizaremos el siguente trozo

de código:

DATA: tabla TYPE estructura.

1 Transacción SE11.

Page 5: Manual ALV

Libretilla MarcosJ Miguel Jesús Fernández

5

PROGRAMA ABAP SIN BASES DE DATOS LÓGICAS.

“Recoge datos de diferentes infotipos y los almacena en una tabla interna con formato

de una estructura previamente creada”.

Z_PRUEBAREPORTALV

Para comenzar con ello debemos crear nuestra estructura en la transacción se11 como se

dijo anteriormente.

Ahora crearemos una tabla(i_aux) interna del programa con el formato de la estructura

que creamos anteriormente.

“DATA: i_aux LIKE estructura_nombre

OCCURS 0 WITH HEADER LINE.”

Una vez creada esta tabla crearemos otra para cada infotipo al que recurramos y el 0000,

es decir, si necesitamos los infotipos 0002 y 0006 haríamos 3 tablas, una para cada uno:

“DATA: i_pa0000 LIKE pa0000

OCCURS 0 WITH HEADER LINE.”

Recuperamos la información de los infotipos haciendo una consulta y almacenando los

resultados en cada una de las tablas que hemos creado:

“SELECT *

FROM pa0000

INTO TABLE i_pa0000

WHERE2 begda <= sy-datum

3

AND endda >= sy-datum.”

Para las otras tablas:

“SELECT *

FROM pa0002

INTO TABLE i_pa0002

FOR ALL ENTRIES IN i_pa0000

WHERE pernr EQ i_pa0000-pernr

AND begda <= sy-datum

AND endda >= sy-datum.”

“SELECT *

FROM pa0006

INTO TABLE i_pa0006

FOR ALL ENTRIES IN i_pa0000

WHERE pernr EQ i_pa0000-pernr

AND subty EQ c_subty1 4

AND begda <= sy-datum

AND endda >= sy-datum. ”

2 En el WHERE ponemos esta condición para que sólo nos muestre los empleados activos.

3 DATUM es una variable del sistema que almacena la fecha actual.

4 Esta condición hace que se recorra el subtipo 1 del infotipo 6. Para hacerlo menos complejo creo una

constante llamada subty1 con el valor ‘0001’: “CONSTANTS: c_subty1 LIKE pa0006-subty VALUE '1'.”

Page 6: Manual ALV

Libretilla MarcosJ Miguel Jesús Fernández

6

Una vez hecho esto y para comprobar que existen valores utilizamos la variable del

sistema sy-subrc, que siempre que haya valores tendrá 0 como valor, así una vez

recorramos la pa0000 escribiremos la condición:

“IF sy-subrc eq 0.”

Tras esta línea recorreremos nuestras otras dos tablas y pondremos el else como:

“ELSE. MESSAGE a000(z1) WITH text-001.

ENDIF.”

Así habremos terminado la parte de recorrido de infotipos y almacenamiento en tablas

internas. Ahora lo que nos interesa es, de cada tabla, coger los campos que necesitamos,

es decir, los campos que creamos en nuestra estructura.

Para ello haremos un LOOP que recorra toda la p0000 y dos Read Table uno para cada

infotipo de los que recogemos datos. También, para evitar redundancias haremos un

REFRESH sobre nuestra tabla antes del LOOP y un CLEAR cada vez que entre en el

LOOP:

“REFRESH i_aux. LOOP AT i_pa0000. CLEAR i_aux. READ TABLE i_pa0000 WITH KEY pernr = i_pa0000-pernr. IF sy-subrc EQ 0. i_aux-pernr = i_pa0000-pernr. ENDIF. READ TABLE i_pa0002 WITH KEY pernr = i_pa0000-pernr. IF sy-subrc EQ 0. i_aux-name = i_pa0002-vorna. i_aux-lastname = i_pa0002-nachn. i_aux-birth_date = i_pa0002-gbdat. ENDIF. READ TABLE i_pa0006 WITH KEY pernr = i_pa0000-pernr. IF sy-subrc EQ 0. i_aux-street_&_housen = i_pa0006-stras. i_aux-city = i_pa0006-ort01. i_aux-country = i_pa0006-land1. ENDIF. APPEND i_aux.5

ENDLOOP.”

5 Lo almacenamos con APPEND

Page 7: Manual ALV

Libretilla MarcosJ Miguel Jesús Fernández

7

CODIGO COMPLETO Z_PRUEBAREPORTALV:

*&---------------------------------------------------------------------* *& Report Z_PRUEBAREPORTALV *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT z_pruebareportalv. *infotypes:0001,0002,0006. TYPE-POOLS: slis. CONSTANTS: c_subty1 LIKE pa0006-subty VALUE '1'. DATA: i_pa0000 LIKE pa0000 OCCURS 0 WITH HEADER LINE, i_pa0002 LIKE pa0002 OCCURS 0 WITH HEADER LINE, i_pa0006 LIKE pa0006 OCCURS 0 WITH HEADER LINE, i_aux LIKE zprueba_estructura2 OCCURS 0 WITH HEADER LINE. DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid. * Name of the custom control added on the screen DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV'. * Custom container instance reference DATA gr_ccontainer TYPE REF TO cl_gui_custom_container. * Field catalog DATA gt_fieldcat TYPE slis_t_fieldcat_alv. * Layout structure DATA gs_layout TYPE slis_layout_alv. * i_tab LIKE zprueba_estructura2 OCCURS 0 WITH HEADER LINE. INITIALIZATION. START-OF-SELECTION. PERFORM retrieve_infotypes. END-OF-SELECTION. IF NOT i_pa0000[] IS INITIAL. PERFORM lectura_inserccion. ENDIF. * PERFORM mostrar_write. * PERFORM display_alv. * PERFORM display_alv_funciones tables gt_fieldcat * using gs_layout. PERFORM display_alv_funciones. *&---------------------------------------------------------------------* *& Form RETRIEVE_INFOTYPES *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM retrieve_infotypes. SELECT * FROM pa0000 INTO TABLE i_pa0000 WHERE begda <= sy-datum AND endda >= sy-datum.

Page 8: Manual ALV

Libretilla MarcosJ Miguel Jesús Fernández

8

IF sy-subrc EQ 0. SELECT * FROM pa0002 INTO TABLE i_pa0002 FOR ALL ENTRIES IN i_pa0000 WHERE pernr EQ i_pa0000-pernr AND begda <= sy-datum AND endda >= sy-datum. IF sy-subrc EQ 0. SELECT * FROM pa0006 INTO TABLE i_pa0006 FOR ALL ENTRIES IN i_pa0000 WHERE pernr EQ i_pa0000-pernr AND subty EQ c_subty1 AND begda <= sy-datum AND endda >= sy-datum. ENDIF. ELSE. MESSAGE a000(z1) WITH text-001. ENDIF. ENDFORM. " RETRIEVE_INFOTYPES *&---------------------------------------------------------------------* *& Form LECTURA_INSERCCION *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM lectura_inserccion. REFRESH i_aux. LOOP AT i_pa0000. CLEAR i_aux. READ TABLE i_pa0000 WITH KEY pernr = i_pa0000-pernr. IF sy-subrc EQ 0. i_aux-pernr = i_pa0000-pernr. ENDIF. READ TABLE i_pa0002 WITH KEY pernr = i_pa0000-pernr. IF sy-subrc EQ 0. i_aux-name = i_pa0002-vorna. i_aux-lastname = i_pa0002-nachn. i_aux-birth_date = i_pa0002-gbdat. ENDIF. READ TABLE i_pa0006 WITH KEY pernr = i_pa0000-pernr. IF sy-subrc EQ 0. i_aux-street_&_housen = i_pa0006-stras. i_aux-city = i_pa0006-ort01. i_aux-country = i_pa0006-land1. ENDIF. APPEND i_aux. ENDLOOP. ENDFORM. " LECTURA_INSERCCION *&---------------------------------------------------------------------*

Page 9: Manual ALV

Libretilla MarcosJ Miguel Jesús Fernández

9

*& Form DISPLAY_ALV *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM display_alv. IF gr_alvgrid IS INITIAL. * create custom container instance CREATE OBJECT gr_ccontainer EXPORTING container_name = gc_custom_control_name. * EXCEPTIONS * CNTL_ERROR = 1 * CNTL_SYSTEM_ERROR = 2 * CREATE_ERROR = 3 * LIFETIME_ERROR = 4 * LIFETIME_DYNPRO_DYNPRO_LINK = 5 * others = 6. IF sy-subrc <> 0. ENDIF. CREATE OBJECT gr_alvgrid EXPORTING i_parent = gr_ccontainer EXCEPTIONS error_cntl_create = 1 error_cntl_init = 2 error_cntl_link = 3 error_dp_create = 4 OTHERS = 5. IF sy-subrc <> 0. ENDIF. * Preparing field catalog. * PERFORM prepare_field_catalog CHANGING gt_fieldcat. * Preparing layout structure * PERFORM prepare_layout CHANGING gs_layout. * CALL METHOD gr_alvgrid->set_table_for_first_display * EXPORTING * is_layout = gs_layout * CHANGING * it_outtab = i_aux[] * it_fieldcatalog = gt_fieldcat. IF sy-subrc <> 0. ENDIF. ELSE. CALL METHOD gr_alvgrid->refresh_table_display. ENDIF. ENDFORM. " DISPLAY_ALV *&---------------------------------------------------------------------* *& Form PREPARE_FIELD_CATALOG *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * <--P_GT_FIELDCAT text *----------------------------------------------------------------------* FORM prepare_field_catalog CHANGING p_gt_fieldcat TYPE lvc_t_fcat.

Page 10: Manual ALV

Libretilla MarcosJ Miguel Jesús Fernández

10

* DATA ls_fcat type lvc_t_fcat. CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING * I_BUFFER_ACTIVE = i_structure_name = 'ZPRUEBA_ESTRUCTURA2' * I_CLIENT_NEVER_DISPLAY = 'X' * I_BYPASSING_BUFFER = * I_INTERNAL_TABNAME = 'i_aux' CHANGING ct_fieldcat = p_gt_fieldcat[] EXCEPTIONS inconsistent_interface = 1 program_error = 2 OTHERS = 3. CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' EXPORTING * I_PROGRAM_NAME = * I_INTERNAL_TABNAME = i_structure_name = 'ZPRUEBA_ESTRUCTURA2' * I_CLIENT_NEVER_DISPLAY = 'X' * I_INCLNAME = * I_BYPASSING_BUFFER = * I_BUFFER_ACTIVE = CHANGING ct_fieldcat = p_gt_fieldcat[] EXCEPTIONS inconsistent_interface = 1 program_error = 2 OTHERS = 3. IF sy-subrc <> 0. ENDIF. ENDFORM. " PREPARE_FIELD_CATALOG *&---------------------------------------------------------------------* *& Form PREPARE_LAYOUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * <--P_GS_LAYOUT text *----------------------------------------------------------------------* FORM prepare_layout CHANGING p_gs_layout TYPE lvc_s_layo. p_gs_layout-zebra = 'X'. p_gs_layout-grid_title = 'ALV report'. p_gs_layout-smalltitle = 'X'. ENDFORM. " PREPARE_LAYOUT *&---------------------------------------------------------------------* *& Form MOSTRAR_WRITE *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM mostrar_write . LOOP AT i_aux. WRITE: / i_aux-pernr, i_aux-name, i_aux-lastname, i_aux-birth_date,

Page 11: Manual ALV

Libretilla MarcosJ Miguel Jesús Fernández

11

i_aux-street_&_housen, i_aux-city, i_aux-country. ENDLOOP. ENDFORM. " MOSTRAR_WRITE *&---------------------------------------------------------------------* *& Form SHOW_ALV *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_P_GT_FIELDCAT text * -->P_P_GS_LAYOUT text *----------------------------------------------------------------------* FORM show_alv USING p_gt_fieldcat p_gs_layout. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING is_layout = p_gs_layout it_fieldcat = p_gt_fieldcat TABLES t_outtab = i_aux EXCEPTIONS program_error = 1 OTHERS = 2. ENDFORM. " SHOW_ALV *&---------------------------------------------------------------------* *& Form DISPLAY_ALV_FUNCIONES *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * <--P_GT_FIELDCAT text * <--P_GS_LAYOUT text *----------------------------------------------------------------------* form DISPLAY_ALV_FUNCIONES. * tables p_gt_fieldcat * using p_gs_layout. * PERFORM prepare_field_catalog2 tables p_gt_fieldcat. PERFORM prepare_field_catalog2. * PERFORM prepare_layout2 CHANGING p_gs_layout. PERFORM prepare_layout2. * PERFORM show_alv2 tables p_gt_fieldcat * using p_gs_layout. PERFORM show_alv2. endform. " DISPLAY_ALV_FUNCIONES *&---------------------------------------------------------------------* *& Form PREPARE_FIELD_CATALOG2 *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * <--P_P_GT_FIELDCAT text *----------------------------------------------------------------------* *form PREPARE_FIELD_CATALOG2 tables p_gt_fieldcat. form PREPARE_FIELD_CATALOG2. CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' EXPORTING

Page 12: Manual ALV

Libretilla MarcosJ Miguel Jesús Fernández

12

* I_PROGRAM_NAME = * I_INTERNAL_TABNAME = i_structure_name = 'ZPRUEBA_ESTRUCT78URA2' * I_CLIENT_NEVER_DISPLAY = 'X' * I_INCLNAME = * I_BYPASSING_BUFFER = * I_BUFFER_ACTIVE = CHANGING ct_fieldcat = gt_fieldcat[] EXCEPTIONS inconsistent_interface = 1 program_error = 2 OTHERS = 3 . endform. " PREPARE_FIELD_CATALOG2 *&---------------------------------------------------------------------* *& Form PREPARE_LAYOUT2 *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * <--P_P_GS_LAYOUT text *----------------------------------------------------------------------* *form PREPARE_LAYOUT2 changing p_gs_layout. form PREPARE_LAYOUT2. gs_layout-zebra = 'X'. * gs_layout-grid_title = 'ALV report'. * gs_layout-smalltitle = 'X'. endform. " PREPARE_LAYOUT2 *&---------------------------------------------------------------------* *& Form SHOW_ALV2 *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_P_GT_FIELDCAT text * -->P_P_GS_LAYOUT text *----------------------------------------------------------------------* form SHOW_ALV2. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING is_layout = gs_layout it_fieldcat = gt_fieldcat TABLES t_outtab = i_aux EXCEPTIONS program_error = 1 OTHERS = 2. endform. " SHOW_ALV2

Page 13: Manual ALV

Libretilla MarcosJ Miguel Jesús Fernández

13

PROGRAMA ABAP CON BASES DE DATOS LÓGICAS.

“Recoge datos de diferentes infotipos y los almacena en una tabla interna con formato

de una estructura previamente creada”.

Z_PRUEBAREPORTALV2

Para empezar hemos creado una estructura que contiene campos de diferentes

infotipos(z_structuratest). En primer lugar insertamos las tablas a las que hacemos

acceso:

“TABLES:pernr.”

Luego los infotipos:

“INFOTYPES:0000,0001,0002,0006,0009.”

Ahora declaramos la tabla interna en la que almacenaremos los datos:

“DATA: i_aux LIKE zstructuretest OCCURS 0 WITH HEADER LINE.”

A continuación recogeremos el pernr y haremos mención a la función de inserción:

“INITIALIZATION. START-OF-SELECTION. GET pernr. PERFORM lectura_inserccion.

END-OF-SELECTION.”

Ahora picaremos nuestra function:

“FORM lectura_inserccion .”

Tenemos dos opciones utilizando provide o loop, con provide sería:

“provide * from p0000 between pnpbegda and pnpendda. *CODIGO*

endprovide.”

Utilizando loop sería:

“LOOP AT p0000 WHERE begda >= pnpbegda AND endda <= pnpendda. *CODIGO*

ENDLOOP.”

Siendo el código:

“ i_aux-personal_number = p0001-pernr. i_aux-company_code = p0001-bukrs. i_aux-personal_area = p0001-werks. i_aux-employee_group = p0001-persg. i_aux-employee_subgroup = p0001-persk. i_aux-organizational_key = p0001-vdsk1. i_aux-payroll_area = p0001-abkrs. i_aux-first_name = p0002-vorna. i_aux-last_name = p0002-nachn. i_aux-street_&_housen = p0006-stras. i_aux-city = p0006-ort01. i_aux-country = p0006-land1. i_aux-bank_key = p0009-bankl. i_aux-bank_account = p0009-bankn. i_aux-payroll_area = p0009-bkont.

APPEND i_aux.”

Page 14: Manual ALV

Libretilla MarcosJ Miguel Jesús Fernández

14

CODIGO COMPLETO Z_PRUEBAREPORTALV2:

*&---------------------------------------------------------------------* *& Report Z_PRUEBAREPORTALV2 *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT z_pruebareportalv2 line-SIZE 400. TABLES:pernr. INFOTYPES:0000,0001,0002,0006,0009. DATA: i_aux LIKE zstructuretest OCCURS 0 WITH HEADER LINE. DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid. * Name of the custom control added on the screen DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV'. * Custom container instance reference DATA gr_ccontainer TYPE REF TO cl_gui_custom_container. * Field catalog DATA gt_fieldcat TYPE slis_t_fieldcat_alv. * Layout structure DATA gs_layout TYPE slis_layout_alv. INITIALIZATION. START-OF-SELECTION. GET pernr. PERFORM lectura_inserccion. END-OF-SELECTION. PERFORM write. PERFORM display_alv_funciones. *&---------------------------------------------------------------------* *& Form LECTURA_INSERCCION *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM lectura_inserccion . *podemos usar un loop o un provide para realizar la inserccion de los datos en la *nuestra tabla i_aux. * Asi seria con un provide *provide * from p0000 * between pnpbegda and pnpendda. * aqui vendria nuestro codigo * endprovide. LOOP AT p0000 WHERE begda >= pnpbegda AND endda <= pnpendda. i_aux-personal_number = p0001-pernr. i_aux-company_code = p0001-bukrs. i_aux-personal_area = p0001-werks.

Page 15: Manual ALV

Libretilla MarcosJ Miguel Jesús Fernández

15

i_aux-employee_group = p0001-persg. i_aux-employee_subgroup = p0001-persk. i_aux-organizational_key = p0001-vdsk1. i_aux-payroll_area = p0001-abkrs. i_aux-first_name = p0002-vorna. i_aux-last_name = p0002-nachn. i_aux-street_&_housen = p0006-stras. i_aux-city = p0006-ort01. i_aux-country = p0006-land1. i_aux-bank_key = p0009-bankl. i_aux-bank_account = p0009-bankn. i_aux-payroll_area = p0009-bkont. APPEND i_aux. ENDLOOP. ENDFORM. " LECTURA_INSERCCION *&---------------------------------------------------------------------* *& Form WRITE *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM write . DELETE ADJACENT DUPLICATES FROM I_AUX. LOOP AT i_aux. WRITE: / i_aux-personal_number, i_aux-company_code, i_aux-personal_area, i_aux-employee_group, i_aux-employee_subgroup, i_aux-organizational_key, i_aux-payroll_area, i_aux-first_name, i_aux-last_name, i_aux-street_&_housen, i_aux-city, i_aux-country, i_aux-bank_key, i_aux-bank_account, i_aux-payroll_area. ENDLOOP. ENDFORM. " WRITE *&---------------------------------------------------------------------* *& Form DISPLAY_ALV_FUNCIONES *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * <--P_GT_FIELDCAT text * <--P_GS_LAYOUT text *----------------------------------------------------------------------* form DISPLAY_ALV_FUNCIONES. * tables p_gt_fieldcat * using p_gs_layout.

Page 16: Manual ALV

Libretilla MarcosJ Miguel Jesús Fernández

16

* PERFORM prepare_field_catalog2 tables p_gt_fieldcat. PERFORM prepare_field_catalog. * PERFORM prepare_layout2 CHANGING p_gs_layout. PERFORM prepare_layout. * PERFORM show_alv2 tables p_gt_fieldcat * using p_gs_layout. PERFORM show_alv. endform. " DISPLAY_ALV_FUNCIONES *&---------------------------------------------------------------------* *& Form PREPARE_FIELD_CATALOG *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * <--P_P_GT_FIELDCAT text *----------------------------------------------------------------------* *form PREPARE_FIELD_CATALOG tables p_gt_fieldcat. form PREPARE_FIELD_CATALOG. CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' EXPORTING * I_PROGRAM_NAME = * I_INTERNAL_TABNAME = i_structure_name = 'zstructuretest' * I_CLIENT_NEVER_DISPLAY = 'X' * I_INCLNAME = * I_BYPASSING_BUFFER = * I_BUFFER_ACTIVE = CHANGING ct_fieldcat = gt_fieldcat[] EXCEPTIONS inconsistent_interface = 1 program_error = 2 OTHERS = 3. endform. " PREPARE_FIELD_CATALOG *&---------------------------------------------------------------------* *& Form PREPARE_LAYOUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * <--P_P_GS_LAYOUT text *----------------------------------------------------------------------* *form PREPARE_LAYOUT changing p_gs_layout. form PREPARE_LAYOUT. gs_layout-zebra = 'X'. * gs_layout-grid_title = 'ALV report'. * gs_layout-smalltitle = 'X'. endform. " PREPARE_LAYOUT *&---------------------------------------------------------------------* *& Form SHOW_ALV *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_P_GT_FIELDCAT text * -->P_P_GS_LAYOUT text *----------------------------------------------------------------------* form SHOW_ALV. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING

Page 17: Manual ALV

Libretilla MarcosJ Miguel Jesús Fernández

17

is_layout = gs_layout it_fieldcat = gt_fieldcat TABLES t_outtab = i_aux EXCEPTIONS program_error = 1 OTHERS = 2. endform. " SHOW_ALV