Recently, I have been writing reports on the project. I have summarized a set of templates and frameworks, downloaded them, uploaded new reports each time, and implemented some methods to reduce unnecessary repetitive manual work.
How to use:
Implement get_data to complete the fetch logic;
In init_fieldcat, a macro set_fieldcat is defined to set the header. Two parameters are accepted. The first parameter is the field name, and the second parameter is the name displayed in the header;
You need to create a GUI status named z_alv_status.
* & --------------------------------------------------------------------- ** & Report zarv_template * & --------------------------------------------------------------------- ** program name: * Development Date: * Creator: * applicant: * optional ** Change Record ** -------------------------------------------------------------------------- * Report zarv_template message-ID ZCOMM.TYPE-POOLS: slis. types: Begin of ty_tab, fields type C, "display field end of ty_tab.data: it_fieldcat type slis_t_fieldcat_alv, g_layout type slis_layout_alv, g_repid like SY-REPID value SY-REPID.DATA: it_itab type standard table of TY_TAB.SELECTION-SCREEN begin of block BLK with frame title TEXT-001.SELECTION-SCREEN end of block BLK.INITIALIZATION.START-OF-SELECTION. perform get_data. if it_itab is initial. message s000 display like 'E '. else. perform init_fieldcat. perform init_layout. perform output. endif. * & --------------------------------------------------------------------- ** & form get_data * & --------------------------------------------------------------------- ** obtain data ** -------------------------------------------------------------------- * Form get_data.endform. "get_data * & --------------------------------------------------------------------- ** & form init_fieldcat * & --------------------------------------------------------------------- ** initialize the header * -------------------------------------------------------------------------- * Form init_fieldcat. data: lw_fieldcat type slis_fieldcat_alv. define set_fieldcat. clear lw_fieldcat. LW_FIELDCAT-FIELDNAME = & 1. LW_FIELDCAT-SELTEXT_S = & 2. LW_FIELDCAT-SELTEXT_M = LW_FIELDCAT-SELTEXT_S. LW_FIELDCAT-SELTEXT_L = LW_FIELDCAT-SELTEXT_S. append lw_fieldcat to it_fieldcat. END-OF-DEFINITION.ENDFORM. "init_fieldcat * & LAYOUT ** & form init_layout * & LAYOUT ** initialize layout ** -------------------------------------------------------------------------- * Form init_layout. g_LAYOUT-DETAIL_POPUP = 'x '. "double-click to pop up the detail window G_LAYOUT-F2CODE = '& ETA '. g_LAYOUT-ZEBRA = 'x '. "zebra crossing endform. "init_layout * & --------------------------------------------------------------------- ** & form output * & --------------------------------------------------------------------- ** output ALV * ------------------------------------------------------------------------ * Form output. g_repid = SY-REPID. call function 'reuse _ alv_grid_display' exporting condition = g_repid is_layout = g_layout it_fieldcat = it_fieldcat [] I _save = 'A' condition = 'pf _ status_set 'condition = 'user _ command' tables t_tab = it_itab 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. "output * & --------------------------------------------------------------------- ** & form pf_status_set * & --------------------------------------------------------------------- ** set GUI status * ---------------------------------------------------------------------- ** --> tr_extab text * ---------------------------------------------------------------------- * Form pf_status_set using tr_extab type slis_t_extab. set PF-STATUS 'z _ alv_status '. endform. "pf_status_set * & operator ** & form user_command * & operator ** accept user operations and commands * operator ** --> ucomm text * --> selfield text * operator * Form user_command using ucomm like SY-UCOMM selfield type slis_selfield.endform. "user_command