ALV ROBOT.

posted under by Antonio Lopez

Este es un reporte que muestra un tipo de ALV sin necesidad de usar dynpro, es solo un simple reporte, en el cual me apoyo de una tabla llamada ZRF_t0002, contiene entre otros campos:
zrf_t0002-id_cliente, zrf_t0002-nombre, zrf_t0002-apellido1, zrf_t0002-apellido2.
es facil de impelementar y le da una vista mas profesional a nuetros reportes, espero sea de utilidad.

REPORT zalv_robot .

TABLES: ddshretval,
zrf_t0002.

TYPE-POOLS: slis.

DATA: BEGIN OF it_cliente OCCURS 0,
cliente LIKE zrf_t0002-id_cliente,
END OF it_cliente.

DATA: BEGIN OF it_match OCCURS 0, " Esta tabla nos devuelve la ayuda
shlpname LIKE ddshretval-shlpname,
fieldname LIKE ddshretval-fieldname,
recordpos LIKE ddshretval-recordpos,
fieldval LIKE ddshretval-fieldval,
retfield LIKE ddshretval-retfield,
END OF it_match.


TYPES: BEGIN OF tp_data,
cliente LIKE zrf_t0002-id_cliente,
nombre LIKE zrf_t0002-nombre,
apellido1 LIKE zrf_t0002-apellido1,
apellido2 LIKE zrf_t0002-apellido2,
END OF tp_data,
tp_tbl_data TYPE STANDARD TABLE OF tp_data.



* Report data to be shown.
DATA: it_data TYPE STANDARD TABLE OF tp_data.

* Heading of the report.
DATA: t_heading TYPE slis_t_listheader.

*======================= Selection Screen ==========================*
DATA: vcliente LIKE zrf_t0002-id_cliente,
vnombre LIKE zrf_t0002-nombre.
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-t01.
SELECT-OPTIONS id_cli FOR zrf_t0002-id_cliente.
SELECTION-SCREEN: END OF BLOCK b1.

*======================== Event Blocks =============================*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR id_cli-low.
SELECT id_cliente
FROM zrf_t0002
INTO TABLE it_cliente
WHERE id_cliente IN id_cli.
SORT it_cliente BY cliente.


CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'CLIENTE'
window_title = 'CLIENTE'
value_org = 'S'
TABLES
value_tab = it_cliente
return_tab = it_match
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.

IF sy-subrc EQ 0.
READ TABLE it_match INDEX 1.
vcliente = it_match-fieldval.
MOVE vcliente TO id_cli-low.
SELECT SINGLE nombre FROM zrf_t0002
INTO vnombre WHERE id_cliente IN id_cli.
ENDIF.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR id_cli-high.
SELECT id_cliente
FROM zrf_t0002
INTO TABLE it_cliente
WHERE id_cliente IN id_cli.
SORT it_cliente BY cliente.


CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'ID_CLIENTE'
window_title = 'CLIENTE'
value_org = 'S'
TABLES
value_tab = it_cliente
return_tab = it_match
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.

IF sy-subrc EQ 0.
READ TABLE it_match INDEX 1.
vcliente = it_match-fieldval.
MOVE vcliente TO id_cli-high.
SELECT SINGLE nombre FROM zrf_t0002
INTO vnombre WHERE id_cliente IN id_cli.

ENDIF.

START-OF-SELECTION.
PERFORM get_data USING it_data.


END-OF-SELECTION.
PERFORM build_alv USING it_data t_heading.

*======================== Subroutines ==============================*

*&------------------------------------------------------------------*
*& Form get_data
*&------------------------------------------------------------------*
* Gets the information to be shown in the report.
*-------------------------------------------------------------------*
FORM get_data USING t_data TYPE tp_tbl_data.

SELECT zrf_t0002~id_cliente
zrf_t0002~nombre
zrf_t0002~apellido1
zrf_t0002~apellido2

INTO TABLE t_data
FROM zrf_t0002
WHERE zrf_t0002~id_cliente IN id_cli.

ENDFORM. " get_data


*&------------------------------------------------------------------*
*& Form build_alv
*&------------------------------------------------------------------*
* Builds and display the ALV Grid.
*-------------------------------------------------------------------*
FORM build_alv USING t_data TYPE tp_tbl_data
t_heading TYPE slis_t_listheader.

* ALV required data objects.
DATA: w_title TYPE lvc_title,
w_repid TYPE syrepid,
w_comm TYPE slis_formname,
w_status TYPE slis_formname,
x_layout TYPE slis_layout_alv,
t_event TYPE slis_t_event,
t_fieldcat TYPE slis_t_fieldcat_alv,
t_sort TYPE slis_t_sortinfo_alv.



REFRESH t_fieldcat.
REFRESH t_event.
REFRESH t_sort.
CLEAR x_layout.
CLEAR w_title.

* Field Catalog
PERFORM set_fieldcat2 USING:
1 'CLIENTE' 'CLIENTE' 'ZRF_T0002' 7 space 'CLIENTE'
'CLIENTE' 'CLIENTE' 'CLIENTE' space space space space space
space t_fieldcat ,
3 'NOMBRE' 'NOMBRE' 'ZRF_T0002' 15 space 'NOMBRE' 'NOMBRE'
'NOMBRE' 'NOMBRE' space space space space space space t_fieldcat ,
4 'APELLIDO1' 'APELLIDO1' 'ZPM_T0004' 25 space 'APELLIDO1'
'APELLIDO1' 'APELLIDO1' 'APELLIDO1' space
space space space space space t_fieldcat ,
5 'APELLIDO2' 'APELLIDO2' 'ZPM_T0004' 25 space 'APELLIDO2'
'APELLIDO2' 'APELLIDO2' 'APELLIDO2' space
space space space space space t_fieldcat .


* Layout
x_layout-zebra = 'X'.

* Top of page heading
PERFORM set_top_page_heading USING t_heading t_event.

* Events
PERFORM set_events USING t_event.

* GUI Status
w_status = ''.
w_repid = sy-repid.

* Title

* User commands
w_comm = 'USER_COMMAND'.


* Displays the ALV grid
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = w_repid
it_fieldcat = t_fieldcat
is_layout = x_layout
it_sort = t_sort
i_callback_pf_status_set = w_status
i_callback_user_command = w_comm
i_save = 'X'
it_events = t_event
i_grid_title = w_title
TABLES
t_outtab = t_data
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. " build_alv.


*&------------------------------------------------------------------*
*& Form set_top_page_heading
*&------------------------------------------------------------------*
* Creates the report headings.
*-------------------------------------------------------------------*
FORM set_top_page_heading USING t_heading TYPE slis_t_listheader
t_events TYPE slis_t_event.

DATA: x_heading TYPE slis_listheader,
x_event TYPE LINE OF slis_t_event.

* Report title
CLEAR t_heading[].
CLEAR x_heading.
x_heading-typ = 'H'.
x_heading-info = ''(001).
APPEND x_heading TO t_heading.

* Date of execution
CLEAR x_heading.
x_heading-typ = 'S'.
x_heading-key = 'Date: '.
WRITE sy-datum TO x_heading-info.
APPEND x_heading TO t_heading.

* Time of execution
CLEAR x_heading.
x_heading-typ = 'S'.
x_heading-key = 'Time: '.
WRITE sy-uzeit TO x_heading-info.
APPEND x_heading TO t_heading.

* Top of page event
x_event-name = slis_ev_top_of_page.
x_event-form = 'TOP_OF_PAGE'.
APPEND x_event TO t_events.

ENDFORM.

*&------------------------------------------------------------------*
*& Form set_events
*&------------------------------------------------------------------*
* Sets the events for ALV.
* The TOP_OF_PAGE event is alredy being registered in
* the set_top_page_heading subroutine.
*-------------------------------------------------------------------*
FORM set_events USING t_events TYPE slis_t_event.

DATA: x_event TYPE LINE OF slis_t_event.

ENDFORM.

*&------------------------------------------------------------------*
*& Form set_order
*&------------------------------------------------------------------*
* Adds an entry to the order table.
*-------------------------------------------------------------------*
FORM set_order USING p_fieldname p_tabname p_up p_down p_subtot
t_sort TYPE slis_t_sortinfo_alv.

DATA: x_sort TYPE slis_sortinfo_alv.

CLEAR x_sort.
x_sort-fieldname = p_fieldname.
x_sort-tabname = p_tabname.
x_sort-up = p_up.
x_sort-down = p_down.
x_sort-subtot = p_subtot.
APPEND x_sort TO t_sort.


ENDFORM. "set_order

*-------------------------------------*
FORM set_fieldcat2 USING
p_colpos p_fieldname p_ref_fieldname p_ref_tabname
p_outputlen p_noout
p_seltext_m p_seltext_l p_seltext_s p_reptext_ddic p_ddictxt
p_hotspot p_showasicon p_checkbox p_edit
p_dosum
t_fieldcat TYPE slis_t_fieldcat_alv.

DATA: wa_fieldcat TYPE slis_fieldcat_alv.

CLEAR wa_fieldcat.

* General settings
wa_fieldcat-fieldname = p_fieldname.
wa_fieldcat-col_pos = p_colpos.
wa_fieldcat-no_out = p_noout.
wa_fieldcat-hotspot = p_hotspot.
wa_fieldcat-checkbox = p_checkbox.
wa_fieldcat-icon = p_showasicon.
wa_fieldcat-do_sum = p_dosum.

IF p_ref_tabname IS INITIAL.
wa_fieldcat-rollname = p_ref_fieldname.
ELSE.
wa_fieldcat-ref_tabname = p_ref_tabname.
IF p_ref_fieldname EQ space.
wa_fieldcat-ref_fieldname = wa_fieldcat-fieldname.
ELSE.
wa_fieldcat-ref_fieldname = p_ref_fieldname.
ENDIF.
ENDIF.

* Set output length.
IF NOT p_outputlen IS INITIAL.
wa_fieldcat-outputlen = p_outputlen.
ENDIF.

* Set text headers.
IF NOT p_seltext_m IS INITIAL.
wa_fieldcat-seltext_m = p_seltext_m.
ENDIF.

IF NOT p_seltext_l IS INITIAL.
wa_fieldcat-seltext_l = p_seltext_l.
ENDIF.

IF NOT p_seltext_s IS INITIAL.
wa_fieldcat-seltext_s = p_seltext_s.
ENDIF.

IF NOT p_reptext_ddic IS INITIAL.
wa_fieldcat-reptext_ddic = p_reptext_ddic.
ENDIF.

IF NOT p_ddictxt IS INITIAL.
wa_fieldcat-ddictxt = p_ddictxt.
ENDIF.

* Set as editable or not.
IF NOT p_edit IS INITIAL.
wa_fieldcat-input = 'X'.
wa_fieldcat-edit = 'X'.
ENDIF.

APPEND wa_fieldcat TO t_fieldcat.

ENDFORM. "set_fieldcat2

*======================== Subroutines called by ALV ================*

*&------------------------------------------------------------------*
*& Form top_of_page
*&------------------------------------------------------------------*
* Called on top_of_page ALV event.
* Prints the heading.
*-------------------------------------------------------------------*
FORM top_of_page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = t_heading.
ENDFORM. " alv_top_of_page

*&------------------------------------------------------------------*
*& Form user_command
*&------------------------------------------------------------------*
* Called on user_command ALV event.
* Executes custom commands.
*-------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.


ENDFORM. "user_command

0 comentarios

Make A Comment
Google
 
top