Descripción
- En primer lugar creamos nuestro report ALV.
Herramientas / Workbench ABAP / Desarrollo / SE38 - Editor ABAP
- Definimos las variables que utilizaremos en nuestro report. Por regla general yo he utlizado en los reports ALV que he escrito las siguientes variables:
*Type pools
*********************************************************
type-pools: slis.
*********************************************************
*Variables globales
*********************************************************
data: xrepid like sy-repid
*********************************************************
*Declaración tablas internas
*********************************************************
data:
wa_fieldcat type slis_fieldcat_alv,
t_fieldcat type slis_t_fieldcat_alv,
e_layout type slis_layout_alv,
e_print type slis_print_alv.
data:
begin of i_nif occurs 0,
xxx
end of i_nif.
- Seguidamente buscamos la información y la cargamos en la tabla interna i_nif. Ésta será nuestra tabla de output a mostrar.
- Definimos las parametrizaciones de impresión del ALV.
e_print-no_print_selinfos = 'X'.
e_print-no_print_listinfos = 'X'.
- Definimos la denominación de cada uno de los campos y cómo se referenciarán.
wa_fieldcat-tabname = 'I_NIF'.
wa_fieldcat-seltext_m = 'NIF'.
append wa_fieldcat to t_fieldcat.
clear wa_fieldcat.
- Definimos el layout del ALV.
e_layout-zebra = 'X'.
e_layout-colwidth_optimize = 'X'.
- Llamamos a la función que genera el listado ALV 'REUSE_ALV_GRID_DISPLAY'. Aquí indicamos el nombre de nuestro report, el layout (cómo se mostrarán las columnas), el catálogo de campos, si queremos que se puedan o no grabar variantes de layout y la tabla de output que contiene la información a mostrar. Por supuesto, esta función permite diversas parametrizaciones del ALV que se pueden consultar directamente en la documentación de la función.
exporting
i_callback_program = xrepid
is_layout = e_layout
it_fieldcat = t_fieldcat
i_save = 'A'
is_print = e_print
tables
t_outtab = i_nifnecesidad
exceptions
program_error = 1
others = 2.
if sy-subrc <> 0.
endif.
- Añadimos los datos de cabecera. Estos datos de cabecera se entrarán en una rutina que no se llamará formalmente ya que la llamada se realizará desde el módulo de funciones 'REUSE_ALV_GRID_DISPLAY'.
wa_heading-typ = 'H'.
wa_heading-info = 'Cabecera'.
append wa_heading to t_heading.
clear wa_heading.
* Cabecera pequeña
wa_heading-typ = 'S'.
wa_heading-info = 'Subcabecera'.
append wa_heading to t_heading.
clear wa_heading.
- Si además queremos añadir un logo a nuestro listado deberemos subir la imagen a SAP (clase 'PICTURES', tipo clase 'OT'). Para ello utilizaremos la transacción OAER. En el siguiente link encontraréis toda la información para hacerlo. Seguidamente habrá que llamar al módulo de funciones 'REUSE_ALV_COMMENTARY_WRITE' con nuestro logo. El inconveniente de este logo es que es visible en SAP, pero no es posible imprimirlo.
exporting
it_list_commentary = t_heading
i_logo = 'LOGO'.
Ejemplo
El siguiente es un ejemplo de listado que nos permite validar números de NIF.
*&---------------------------------------------------------------------*
*& Report ZVALIDANIF
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report zvalidanif.
*********************************************************
*Tablas
*********************************************************
tables: kna1.
*********************************************************
*Type pools
*********************************************************
type-pools: slis.
*********************************************************
*Constantes
*********************************************************
*constants:
*********************************************************
*Variables globales
*********************************************************
data:
g_contador(4) type n,
xrepid like sy-repid.
*********************************************************
*Declaración tablas internas
*********************************************************
data:
begin of i_nif occurs 0,
nif like kna1-stcd1,
error(10),
end of i_nif.
*********************************************************
*Estructuras
*********************************************************
data:
wa_fieldcat type slis_fieldcat_alv,
t_fieldcat type slis_t_fieldcat_alv,
e_layout type slis_layout_alv,
e_print type slis_print_alv,
wa_heading type slis_listheader,
t_heading type slis_t_listheader.
*********************************************************
*Includes
*********************************************************
include
*** SELECTION-SCREEN
*********************************************************
*********************************************************
* Pantalla de selección
*********************************************************
*
select-options s_stcd1 for kna1-stcd1.
* At selection-screen
*********************************************************
*********************************************************
*** START-OF-SELECTION
start-of-selection.
* Funcion validacion nif
perform valida_nif.
* Log: cómo se cargará
perform display_alv.
* Performs Adicionales
*********************************************************
*&---------------------------------------------------------------------*
*& Form display_alv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form display_alv .
xrepid = sy-repid.
perform print_alv.
perform fieldcat_alv.
perform layout_alv.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
i_callback_program = xrepid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
i_callback_top_of_page = 'TOP_OF_PAGE '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
is_layout = e_layout
it_fieldcat = t_fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
i_save = 'A'
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
is_print = e_print
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
tables
t_outtab = i_nif
exceptions
program_error = 1
others = 2.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform. " display_alv
*&---------------------------------------------------------------------*
*& Form print_alv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form print_alv .
clear e_print.
e_print-no_print_selinfos = 'X'.
e_print-no_print_listinfos = 'X'.
endform. " print_alv
*&---------------------------------------------------------------------*
*& Form fieldcat_alv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form fieldcat_alv .
*
refresh t_fieldcat.
wa_fieldcat-fieldname = 'NIF'.
wa_fieldcat-tabname = 'I_NIF'.
wa_fieldcat-seltext_m = 'NIF'.
append wa_fieldcat to t_fieldcat.
clear wa_fieldcat.
wa_fieldcat-fieldname = 'ERROR'.
wa_fieldcat-tabname = 'I_NIF'.
wa_fieldcat-seltext_m = 'ERROR'.
wa_fieldcat-no_zero = 'X'.
append wa_fieldcat to t_fieldcat.
clear wa_fieldcat.
*
endform. " fieldcat_alv
*&---------------------------------------------------------------------*
*& Form layout_alv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form layout_alv .
clear e_layout.
e_layout-zebra = 'X'.
e_layout-colwidth_optimize = 'X'.
endform. " layout_alv
*&---------------------------------------------------------------------*
*& Form VALIDA_NIF
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form valida_nif .
loop at s_stcd1.
move s_stcd1-low to i_nif-nif.
call function 'TAX_NUMBER_CHECK'
exporting
country = 'ES'
* NATURAL_PERSON_FLAG = 'X'
* REGION = ' '
* STKZU = ' '
tax_code_1 = i_nif-nif
* TAX_CODE_2 = ' '
* TYPE_OF_TAX_CODE_1 = ' '
* TAX_CODE_3 = ' '
* TAX_CODE_4 = ' '
exceptions
not_valid = 1
different_fprcd = 2
others = 3
.
if sy-subrc <> 0.
i_nif-error = 'Error'.
else.
i_nif-error = space.
endif.
append i_nif. clear i_nif.
endloop.
endform. " VALIDA_NIF
*
*&---------------------------------------------------------------------*
*& Form top_of_page
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
*& Form top_of_page
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form top_of_page.
* Cabecera grande
wa_heading-typ = 'H'.
wa_heading-info = 'Cabecera'.
APPEND wa_heading TO t_heading.
CLEAR wa_heading.
* Cabecera pequeña
wa_heading-typ = 'S'.
wa_heading-info = 'Subcabecera'.
APPEND wa_heading TO t_heading.
CLEAR wa_heading.
wa_heading-typ = 'H'.
wa_heading-info = 'Cabecera'.
APPEND wa_heading TO t_heading.
CLEAR wa_heading.
* Cabecera pequeña
wa_heading-typ = 'S'.
wa_heading-info = 'Subcabecera'.
APPEND wa_heading TO t_heading.
CLEAR wa_heading.
*
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = t_heading
i_logo = 'LOGO'.
exporting
it_list_commentary = t_heading
i_logo = 'LOGO'.
*
endform. " TOP_OF_PAGE
No hay comentarios:
Publicar un comentario