Está en la página 1de 17

ALV

ABAP LIST VIEWER

Step by step

Libretilla MarcosJ

Miguel Jess Fernndez

ALV (ABAP LIST VIEWER).


ALV da soporte a la mayora de los informes estndares de ABAP R/3. Contiene
una serie de mdulos de funciones que podran ser aadidos a los cdigos de los
programas.
Tambin puede aadir aspectos de interfaz a los report. Para incluir ALV en un
report:
1.
2.
3.
4.
5.
6.
7.

Declarar data areas.


Declarar internal table.
Select data into internal table.
Build field catalogs.
Build event catalogs.
start ALV con los mdulos.
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 lneas tipo cebra.
gs_layout-detail_popup = 'X'. "Mostrar opcin de informacin 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) 'Cdigo'(009) sy-subrc.
ENDIF.
ENDFORM.
"call_alv
*&---------------------------------------------------------------------*
*&
Form BUILD_HEADER
*&---------------------------------------------------------------------*

Libretilla MarcosJ

Miguel Jess Fernndez

*
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

Libretilla MarcosJ

Miguel Jess Fernndez

CREACIN DE ESTRUCTURAS1
Abriremos la transaccin se11. Escogeremos la opcin DATA TYPE y le
pondremos nombre. Ahora haremos clic en create.

Escogeremos la opcin structure y continuaremos. Ahora le pondremos una


pequea descripcin 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 cdigo:
DATA: tabla TYPE estructura.

Transaccin SE11.

Libretilla MarcosJ

Miguel Jess Fernndez

PROGRAMA ABAP SIN BASES DE DATOS LGICAS.


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 transaccin 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 haramos 3 tablas, una para cada uno:
DATA: i_pa0000 LIKE pa0000
OCCURS 0 WITH HEADER LINE.

Recuperamos la informacin 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-datum3
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.

En el WHERE ponemos esta condicin para que slo nos muestre los empleados activos.
DATUM es una variable del sistema que almacena la fecha actual.
4
Esta condicin 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'.
3

Libretilla MarcosJ

Miguel Jess Fernndez

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 condicin:
IF sy-subrc eq 0.
Tras esta lnea 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. Tambin, 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.

Lo almacenamos con APPEND

Libretilla MarcosJ

Miguel Jess Fernndez

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
INTO
WHERE
AND

*
pa0000
TABLE i_pa0000
begda <= sy-datum
endda >= sy-datum.

Libretilla MarcosJ

Miguel Jess Fernndez

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
*&---------------------------------------------------------------------*

Libretilla MarcosJ

Miguel Jess Fernndez

*&
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.

Libretilla MarcosJ
*

*
*
*
*

*
*
*
*
*
*

Miguel Jess Fernndez

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,

10

Libretilla MarcosJ

Miguel Jess Fernndez

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
PERFORM prepare_layout2.

*
*

PERFORM show_alv2 tables p_gt_fieldcat


using p_gs_layout.
PERFORM show_alv2.

CHANGING p_gs_layout.

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

11

Libretilla MarcosJ
*
*
*
*
*
*

I_PROGRAM_NAME
I_INTERNAL_TABNAME
i_structure_name
I_CLIENT_NEVER_DISPLAY
I_INCLNAME
I_BYPASSING_BUFFER
I_BUFFER_ACTIVE
CHANGING
ct_fieldcat
EXCEPTIONS
inconsistent_interface
program_error
OTHERS
.

Miguel Jess Fernndez


=
=
= 'ZPRUEBA_ESTRUCT78URA2'
= 'X'
=
=
=
= gt_fieldcat[]
= 1
= 2
= 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

12

Libretilla MarcosJ

Miguel Jess Fernndez

PROGRAMA ABAP CON BASES DE DATOS LGICAS.


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 continuacin recogeremos el pernr y haremos mencin a la funcin de insercin:
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 sera:
provide

* from p0000
between pnpbegda and pnpendda.
*CODIGO*
endprovide.

Utilizando loop sera:


LOOP AT p0000

WHERE begda >= pnpbegda AND endda <= pnpendda.

*CODIGO*
ENDLOOP.

Siendo el cdigo:
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.

13

Libretilla MarcosJ

Miguel Jess Fernndez

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.

14

Libretilla MarcosJ

Miguel Jess Fernndez

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.

15

Libretilla MarcosJ

Miguel Jess Fernndez

PERFORM prepare_field_catalog2 tables p_gt_fieldcat.


PERFORM prepare_field_catalog.

PERFORM prepare_layout2
PERFORM prepare_layout.

*
*

PERFORM show_alv2 tables p_gt_fieldcat


using p_gs_layout.
PERFORM show_alv.

CHANGING p_gs_layout.

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

16

Libretilla MarcosJ
is_layout
it_fieldcat
TABLES
t_outtab
EXCEPTIONS
program_error
OTHERS
endform.

Miguel Jess Fernndez


= gs_layout
= gt_fieldcat
= i_aux
= 1
= 2.
" SHOW_ALV

17

También podría gustarte