Posted: Sat Jan 26, 2008 5:27 pm Post subject: ALV List - Event Exit to change columns Order
Code:
REPORT z_demo_alv_event_exit_1.
*>*********************************************************************
* This report reads and displays data from table TRDIR, *
* using the FM : REUSE_ALV_LIST_DISPLAY *
* The columns are displayed in the same order than the Sort Order *
* There is an underline if the sort is by UNAM or UDAT *
*---------------------------------------------------------------------*
* Author : Michel PIOUD *
* Email : [email protected] HomePage : http://www.geocities.com/mpioud *
***********************************************************************
SELECTION-SCREEN :
BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max. "#EC NEEDED
PARAMETERS p_max(3) TYPE n DEFAULT '99' OBLIGATORY.
SELECTION-SCREEN END OF LINE.
TYPE-POOLS slis. " ALV Global Types
*---------------------------------------------------------------------*
TYPES:
BEGIN OF ty_trdir,
name TYPE trdir-name, " ABAP program name
cnam TYPE trdir-cnam, " Created by
cdat TYPE trdir-cdat, " Created on
unam TYPE trdir-unam, " Last changed by
udat TYPE trdir-udat, " Last changed on
END OF ty_trdir.
*---------------------------------------------------------------------*
DATA:
gt_trdir TYPE TABLE OF ty_trdir. " Data displayed
*---------------------------------------------------------------------*
* Form f_read_data
*---------------------------------------------------------------------*
FORM f_read_data.
SELECT name cnam cdat unam udat
INTO TABLE gt_trdir
UP TO p_max ROWS
FROM trdir
WHERE name LIKE 'Z%'.
ENDFORM. " F_READ_DATA
*---------------------------------------------------------------------*
* Form f_display_data
*---------------------------------------------------------------------*
FORM f_display_data.
* Macro definition
DEFINE m_fieldcat.
add 1 to ls_fieldcat-col_pos.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = 'TRDIR'.
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.
DATA :
ls_layout TYPE slis_layout_alv,
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv,
lt_event_exit TYPE slis_t_event_exit,
ls_event_exit TYPE slis_event_exit.
ENDFORM. " F_DISPLAY_DATA
*---------------------------------------------------------------------*
* FORM USER_COMMAND *
*---------------------------------------------------------------------*
FORM user_command USING u_ucomm TYPE syucomm
us_selfield TYPE slis_selfield. "#EC CALLED
CASE u_ucomm.
WHEN '&OUP' OR '&ODN'. " Sort
PERFORM f_modif_fieldcat.
us_selfield-refresh = 'X'.
ENDCASE.
ENDFORM. " USER_COMMAND
*---------------------------------------------------------------------*
* Form F_MODIF_FIELDCAT
*---------------------------------------------------------------------*
FORM f_modif_fieldcat.
DATA:
lt_fieldcat TYPE slis_t_fieldcat_alv,
lt_sort TYPE slis_t_sortinfo_alv.
FIELD-SYMBOLS :
<sort> TYPE slis_sortinfo_alv,
<fieldcat> TYPE slis_fieldcat_alv.
* Read current ALV list information
CALL FUNCTION 'REUSE_ALV_LIST_LAYOUT_INFO_GET'
IMPORTING
et_fieldcat = lt_fieldcat
et_sort = lt_sort
EXCEPTIONS
no_infos = 1
program_error = 2
OTHERS = 3.
SORT lt_fieldcat BY col_pos.
LOOP AT lt_fieldcat ASSIGNING <fieldcat>.
<fieldcat>-col_pos = sy-tabix.
ENDLOOP.
* Underline if the sort is by UNAM or UDAT
READ TABLE lt_sort ASSIGNING <sort> INDEX 1.
IF <sort>-fieldname = 'UNAM' OR
<sort>-fieldname = 'UDAT'.
<sort>-group = 'UL'.
ENDIF.
CALL FUNCTION 'REUSE_ALV_LIST_LAYOUT_INFO_SET'
EXPORTING
it_sort = lt_sort
it_fieldcat = lt_fieldcat.
ENDFORM. " F_MODIF_FIELDCAT
******** END OF PROGRAM Z_DEMO_ALV_EVENT_EXIT_1 ***********************
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.