Académique Documents
Professionnel Documents
Culture Documents
[ALV PROGRAMS]
ALV Programs. REPORT ZTUFI091. *&---------------------------------------------------------------------* *& Report ZDEMO_ALVGRID * *& * *&---------------------------------------------------------------------* *& * *& Example of a simple ALV Grid Report * *& ................................... * *& * *& The basic requirement for this demo is to display a number of * *& fields from the EKKO table. * *&---------------------------------------------------------------------* *REPORT zdemo_alvgrid .
TABLES: ekko.
type-pools: slis. "ALV Declarations *Data Declaration *---------------TYPES: BEGIN OF t_ekko, ebeln TYPE ekpo-ebeln, ebelp TYPE ekpo-ebelp, statu TYPE ekpo-statu,
[ALV PROGRAMS]
aedat TYPE ekpo-aedat, matnr TYPE ekpo-matnr, menge TYPE ekpo-menge, meins TYPE ekpo-meins, netpr TYPE ekpo-netpr, peinh TYPE ekpo-peinh, END OF t_ekko.
DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0, wa_ekko TYPE t_ekko.
*ALV data declarations data: fieldcatalog type slis_t_fieldcat_alv with header line, gd_tab_group type slis_t_sp_group_alv, gd_layout type slis_layout_alv, gd_repid like sy-repid, gt_events type slis_t_event, gd_prntparams type slis_print_alv.
[ALV PROGRAMS]
perform data_retrieval. perform build_fieldcatalog. perform build_layout. perform build_events. perform build_print_params. perform display_alv_report.
*&---------------------------------------------------------------------* *& Form BUILD_FIELDCATALOG *&---------------------------------------------------------------------* * Build Fieldcatalog for ALV Report *----------------------------------------------------------------------* form build_fieldcatalog.
* There are a number of ways to create a fieldcat. * For the purpose of this example i will build the fieldcatalog manualy * by populating the internal table fields individually and then * appending the rows. This method can be the most time consuming but can * also allow you more control of the final product.
* Beware though, you need to ensure that all fields required are * populated. When using some of functionality available via ALV, such as * total. You may need to provide more information than if you were
[ALV PROGRAMS]
* simply displaying the result * I.e. Field type may be required in-order for * the 'TOTAL' function to work.
fieldcatalog-fieldname = 'EBELN'. fieldcatalog-seltext_m = 'Purchase Order'. fieldcatalog-col_pos = 0. fieldcatalog-outputlen = 10. fieldcatalog-emphasize = 'X'. fieldcatalog-key = 'X'. * fieldcatalog-do_sum = 'X'. * fieldcatalog-no_zero = 'X'. append fieldcatalog to fieldcatalog. clear fieldcatalog.
fieldcatalog-fieldname = 'EBELP'. fieldcatalog-seltext_m = 'PO Item'. fieldcatalog-col_pos = 1. append fieldcatalog to fieldcatalog. clear fieldcatalog.
[ALV PROGRAMS]
fieldcatalog-fieldname = 'AEDAT'. fieldcatalog-seltext_m = 'Item change date'. fieldcatalog-col_pos = 3. append fieldcatalog to fieldcatalog. clear fieldcatalog.
fieldcatalog-fieldname = 'MATNR'. fieldcatalog-seltext_m = 'Material Number'. fieldcatalog-col_pos = 4. append fieldcatalog to fieldcatalog. clear fieldcatalog.
fieldcatalog-fieldname = 'MENGE'. fieldcatalog-seltext_m = 'PO quantity'. fieldcatalog-col_pos = 5. append fieldcatalog to fieldcatalog. clear fieldcatalog.
[ALV PROGRAMS]
fieldcatalog-fieldname = 'NETPR'. fieldcatalog-seltext_m = 'Net Price'. fieldcatalog-col_pos = 7. fieldcatalog-outputlen = 15. fieldcatalog-datatype = 'CURR'. append fieldcatalog to fieldcatalog. clear fieldcatalog.
fieldcatalog-fieldname = 'PEINH'. fieldcatalog-seltext_m = 'Price Unit'. fieldcatalog-col_pos = 8. append fieldcatalog to fieldcatalog. clear fieldcatalog. endform. " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------* *& Form BUILD_LAYOUT *&---------------------------------------------------------------------* * Build layout for ALV grid report *----------------------------------------------------------------------*
[ALV PROGRAMS]
form build_layout. gd_layout-no_input = 'X'. gd_layout-colwidth_optimize = 'X'. gd_layout-totals_text = 'Totals'(201). * gd_layout-totals_only = 'X'. * gd_layout-f2code = 'DISP'. "Sets fcode for when double * "click(press f2) * gd_layout-zebra = 'X'. * gd_layout-group_change_edit = 'X'. * gd_layout-header_text = 'helllllo'. endform. " BUILD_LAYOUT
*&---------------------------------------------------------------------* *& Form DISPLAY_ALV_REPORT *&---------------------------------------------------------------------* * Display report using ALV grid *----------------------------------------------------------------------* form display_alv_report. gd_repid = sy-repid. call function 'REUSE_ALV_GRID_DISPLAY' exporting i_callback_program = gd_repid i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
[ALV PROGRAMS]
i_callback_user_command = 'USER_COMMAND' * i_grid_title = outtext is_layout = gd_layout it_fieldcat = fieldcatalog[] * it_special_groups = gd_tabgroup it_events = gt_events is_print = gd_prntparams i_save = 'X' * is_variant = z_template tables t_outtab = it_ekko 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_REPORT
[ALV PROGRAMS]
* Retrieve data form EKPO table and populate itab it_ekko *----------------------------------------------------------------------* form data_retrieval.
select ebeln ebelp statu aedat matnr menge meins netpr peinh up to 10 rows from ekpo into table it_ekko. endform. " DATA_RETRIEVAL
*-------------------------------------------------------------------* * Form TOP-OF-PAGE * *-------------------------------------------------------------------* * ALV Report Header * *-------------------------------------------------------------------* Form top-of-page. *ALV Header declarations data: t_header type slis_t_listheader, wa_header type slis_listheader, t_line like wa_header-info, ld_lines type i, ld_linesc(10) type c.
[ALV PROGRAMS]
* Title wa_header-typ = 'H'. wa_header-info = 'EKKO Table Report'. append wa_header to t_header. clear wa_header.
* Date wa_header-typ = 'S'. wa_header-key = 'Date: '. CONCATENATE sy-datum+6(2) '.' sy-datum+4(2) '.' sy-datum(4) INTO wa_header-info. "todays date append wa_header to t_header. clear: wa_header.
* Total No. of Records Selected describe table it_ekko lines ld_lines. ld_linesc = ld_lines. concatenate 'Total No. of Records Selected: ' ld_linesc into t_line separated by space. wa_header-typ = 'A'. wa_header-info = t_line. append wa_header to t_header. clear: wa_header, t_line.
[ALV PROGRAMS]
*------------------------------------------------------------------* * FORM USER_COMMAND * *------------------------------------------------------------------* * --> R_UCOMM * * --> RS_SELFIELD * *------------------------------------------------------------------* FORM user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield.
* Check function code CASE r_ucomm. WHEN '&IC1'. * Check field clicked on within ALVgrid report IF rs_selfield-fieldname = 'EBELN'. * Read data table, using index of row user clicked on READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
[ALV PROGRAMS]
* Set parameter ID for transaction screen field SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln. * Sxecute transaction ME23N, and skip initial data entry screen CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN. ENDIF. ENDCASE. ENDFORM.
*&---------------------------------------------------------------------* *& Form BUILD_EVENTS *&---------------------------------------------------------------------* * Build events table *----------------------------------------------------------------------* form build_events. data: ls_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET' exporting i_list_type = 0 importing et_events = gt_events[]. read table gt_events with key name = slis_ev_end_of_page into ls_event.
[ALV PROGRAMS]
read table gt_events with key name = slis_ev_end_of_list into ls_event. if sy-subrc = 0. move 'END_OF_LIST' to ls_event-form. append ls_event to gt_events. endif. endform. " BUILD_EVENTS
*&---------------------------------------------------------------------* *& Form BUILD_PRINT_PARAMS *&---------------------------------------------------------------------* * Setup print parameters *----------------------------------------------------------------------* form build_print_params. gd_prntparams-reserve_lines = '3'. "Lines reserved for footer gd_prntparams-no_coverpage = 'X'. endform. " BUILD_PRINT_PARAMS
[ALV PROGRAMS]
*&---------------------------------------------------------------------* *& Form END_OF_PAGE *&---------------------------------------------------------------------* form END_OF_PAGE. data: listwidth type i, ld_pagepos(10) type c, ld_page(10) type c.
*&---------------------------------------------------------------------* *& Form END_OF_LIST *&---------------------------------------------------------------------* form END_OF_LIST. data: listwidth type i, ld_pagepos(10) type c, ld_page(10) type c.
skip.
[ALV PROGRAMS]
*---internal tables DATA: BEGIN OF it_flight OCCURS 0, carrid LIKE sflight-carrid, connid LIKE sflight-connid, fldate LIKE sflight-fldate, seatsmax LIKE sflight-seatsmax, seatsocc LIKE sflight-seatsocc, END OF it_flight,
*--internal tables for alv it_fieldcat TYPE slis_t_fieldcat_alv, wa_fcat LIKE LINE OF it_fieldcat, layout TYPE slis_layout_alv, it_sort type slis_t_sortinfo_alv, wa_sort like line of it_sort.
[ALV PROGRAMS]
*---start-of-selection .
START-OF-SELECTION.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' EXPORTING i_program_name = sy-repid i_internal_tabname = 'IT_FLIGHT' i_inclname = sy-repid CHANGING ct_fieldcat = it_fieldcat EXCEPTIONS inconsistent_interface = 1 program_error = 2.
*----get data SELECT carrid connid fldate seatsmax seatsocc FROM sflight INTO CORRESPONDING FIELDS OF TABLE it_flight
[ALV PROGRAMS]
UP TO 20 ROWS. . wa_fcat-do_sum = 'X'. MODIFY it_fieldcat FROM wa_fcat TRANSPORTING do_sum WHERE fieldname = 'SEATSOCC' .
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY' EXPORTING i_callback_program = sy-repid is_layout = layout it_fieldcat = it_fieldcat it_sort = it_sort TABLES
[ALV PROGRAMS]
This is a Sample Interactive ALV Code that may helps an ABAP developer understand the basic ALV Interactive Programming. /* ABAP Interactive ALV Program*/ *&---------------------------------------------------------------------* *& Report ZZ_22038_22098_002 *& * *
*&---------------------------------------------------------------------* *& This is an Interactive ALV report, where on line slection we can see *& the secondry list *& *& *
*&---------------------------------------------------------------------*
TYPE-POOLS: SLIS. *type declaration for values from ekko TYPES: BEGIN OF I_EKKO, EBELN LIKE EKKO-EBELN, AEDAT LIKE EKKO-AEDAT, BUKRS LIKE EKKO-BUKRS,
[ALV PROGRAMS]
DATA: IT_EKKO TYPE STANDARD TABLE OF I_EKKO INITIAL SIZE 0, WA_EKKO TYPE I_EKKO.
*type declaration for values from ekpo TYPES: BEGIN OF I_EKPO, EBELN LIKE EKPO-EBELN, EBELP LIKE EKPO-EBELP, MATNR LIKE EKPO-MATNR, MENGE LIKE EKPO-MENGE, MEINS LIKE EKPO-MEINS, NETPR LIKE EKPO-NETPR, END OF I_EKPO.
DATA: IT_EKPO TYPE STANDARD TABLE OF I_EKPO INITIAL SIZE 0, WA_EKPO TYPE I_EKPO .
[ALV PROGRAMS]
* declaration for events table where user comand or set PF status will * be defined DATA: V_EVENTS TYPE SLIS_T_EVENT, WA_EVENT TYPE SLIS_ALV_EVENT.
* declaration for variant(type of display we want) DATA: I_VARIANT TYPE DISVARIANT, I_VARIANT1 TYPE DISVARIANT, I_SAVE(1) TYPE C.
*Title displayed when the alv list is displayed DATA: I_TITLE_EKKO TYPE LVC_TITLE VALUE 'FIRST LIST DISPLAYED'. DATA: I_TITLE_EKPO TYPE LVC_TITLE VALUE 'SECONDRY LIST DISPLAYED'.
[ALV PROGRAMS]
*---------------------------------------------------------------------* FORM BUILD_FIELDCATLOG. WA_FIELDCAT-TABNAME = 'IT_EKKO'. WA_FIELDCAT-FIELDNAME = 'EBELN'. WA_FIELDCAT-SELTEXT_M = 'PO NO.'. APPEND WA_FIELDCAT TO I_FIELDCAT. CLEAR WA_FIELDCAT.
[ALV PROGRAMS]
WA_FIELDCAT-TABNAME = 'IT_EKKO'. WA_FIELDCAT-FIELDNAME = 'AEDAT'. WA_FIELDCAT-SELTEXT_M = 'DATE.'. APPEND WA_FIELDCAT TO I_FIELDCAT. CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'IT_EKKO'. WA_FIELDCAT-FIELDNAME = 'BUKRS'. WA_FIELDCAT-SELTEXT_M = 'COMPANY CODE'. APPEND WA_FIELDCAT TO I_FIELDCAT. CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'IT_EKKO'. WA_FIELDCAT-FIELDNAME = 'BUKRS'. WA_FIELDCAT-SELTEXT_M = 'DOCMENT TYPE'. APPEND WA_FIELDCAT TO I_FIELDCAT. CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'IT_EKKO'. WA_FIELDCAT-FIELDNAME = 'LIFNR'. WA_FIELDCAT-NO_OUT = 'X'. WA_FIELDCAT-SELTEXT_M = 'VENDOR CODE'. APPEND WA_FIELDCAT TO I_FIELDCAT. CLEAR WA_FIELDCAT.
[ALV PROGRAMS]
ENDFORM.
"BUILD_FIELDCATLOG
*&--------------------------------------------------------------------* * we get all events - TOP OF PAGE or USER COMMAND in table v_events *---------------------------------------------------------------------* FORM EVENT_CALL. CALL FUNCTION 'REUSE_ALV_EVENTS_GET' EXPORTING I_LIST_TYPE IMPORTING ET_EVENTS . IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. = V_EVENTS =0
[ALV PROGRAMS]
*---------------------------------------------------------------------* FORM POPULATE_EVENT. READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'TOP_OF_PAGE'. IF SY-SUBRC EQ 0. WA_EVENT-FORM = 'TOP_OF_PAGE'. MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME = WA_EVENT-FORM. ENDIF.
READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'USER_COMMAND'. IF SY-SUBRC EQ 0. WA_EVENT-FORM = 'USER_COMMAND'. MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME = WA_EVENT-NAME. ENDIF. ENDFORM. "POPULATE_EVENT
[ALV PROGRAMS]
*---------------------------------------------------------------------* FORM DATA_RETRIEVAL. SELECT EBELN AEDAT BUKRS BSART LIFNR FROM EKKO INTO TABLE IT_EKKO.
ENDFORM.
"data_retrieval
*&--------------------------------------------------------------------* * text
*---------------------------------------------------------------------* * -->I_LISTHEADEtext
*---------------------------------------------------------------------* FORM BUILD_LISTHEADER USING I_LISTHEADER TYPE SLIS_T_LISTHEADER. DATA HLINE TYPE SLIS_LISTHEADER. HLINE-INFO = 'this is my first alv pgm'. HLINE-TYP = 'H'. ENDFORM. "build_listheader
*&--------------------------------------------------------------------* * text
[ALV PROGRAMS]
V_REPID = SY-REPID. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_CALLBACK_PROGRAM I_CALLBACK_USER_COMMAND I_CALLBACK_TOP_OF_PAGE I_GRID_TITLE IT_FIELDCAT I_SAVE IT_EVENTS TABLES T_OUTTAB = IT_EKKO = V_REPID = 'USER_COMMAND' = 'TOP_OF_PAGE'
. IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*&--------------------------------------------------------------------*
[ALV PROGRAMS]
*&
Form TOP_OF_PAGE
*&--------------------------------------------------------------------* * text
ENDFORM.
"TOP_OF_PAGE
*&--------------------------------------------------------------------* * text
-->RS_SLEFIELDtext
*---------------------------------------------------------------------* FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM RS_SELFIELD TYPE SLIS_SELFIELD. CASE R_UCOMM.
[ALV PROGRAMS]
WHEN '&IC1'. READ TABLE IT_EKKO INTO WA_EKKO INDEX RS_SELFIELD-TABINDEX. PERFORM BUILD_FIELDCATLOG_EKPO. PERFORM EVENT_CALL_EKPO. PERFORM POPULATE_EVENT_EKPO. PERFORM DATA_RETRIEVAL_EKPO. PERFORM BUILD_LISTHEADER_EKPO USING IT_LISTHEADER. PERFORM DISPLAY_ALV_EKPO. ENDCASE. ENDFORM. "user_command
*&--------------------------------------------------------------------* * text
WA_FIELDCAT-TABNAME = 'IT_EKPO'. WA_FIELDCAT-FIELDNAME = 'EBELN'. WA_FIELDCAT-SELTEXT_M = 'PO NO.'. APPEND WA_FIELDCAT TO I_FIELDCAT. CLEAR WA_FIELDCAT. WA_FIELDCAT-TABNAME = 'IT_EKPO'. WA_FIELDCAT-FIELDNAME = 'EBELP'.
[ALV PROGRAMS]
WA_FIELDCAT-SELTEXT_M = 'LINE NO'. APPEND WA_FIELDCAT TO I_FIELDCAT. CLEAR WA_FIELDCAT. WA_FIELDCAT-TABNAME = 'I_EKPO'. WA_FIELDCAT-FIELDNAME = 'MATNR'. WA_FIELDCAT-SELTEXT_M = 'MATERIAL NO.'. APPEND WA_FIELDCAT TO I_FIELDCAT. CLEAR WA_FIELDCAT. WA_FIELDCAT-TABNAME = 'I_EKPO'. WA_FIELDCAT-FIELDNAME = 'MENGE'. WA_FIELDCAT-SELTEXT_M = 'QUANTITY'. APPEND WA_FIELDCAT TO I_FIELDCAT. CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'I_EKPO'. WA_FIELDCAT-FIELDNAME = 'MEINS'. WA_FIELDCAT-SELTEXT_M = 'UOM'. APPEND WA_FIELDCAT TO I_FIELDCAT. CLEAR WA_FIELDCAT.
[ALV PROGRAMS]
CLEAR WA_FIELDCAT.
ENDFORM.
"BUILD_FIELDCATLOG_EKPO
*&--------------------------------------------------------------------* * we get all events - TOP OF PAGE or USER COMMAND in table v_events *---------------------------------------------------------------------* FORM EVENT_CALL_EKPO. CALL FUNCTION 'REUSE_ALV_EVENTS_GET' EXPORTING I_LIST_TYPE IMPORTING ET_EVENTS = V_EVENTS =0
. IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
[ALV PROGRAMS]
*---------------------------------------------------------------------* FORM POPULATE_EVENT_EKPO. READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'TOP_OF_PAGE'. IF SY-SUBRC EQ 0. WA_EVENT-FORM = 'TOP_OF_PAGE'. MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME = WA_EVENT-FORM. ENDIF.
ENDFORM.
"POPULATE_EVENT
*&--------------------------------------------------------------------* * text
[ALV PROGRAMS]
IT_LIST_COMMENTARY .
= IT_LISTHEADER
ENDFORM.
"TOP_OF_PAGE
*&--------------------------------------------------------------------* * text
-->RS_SLEFIELDtext
*---------------------------------------------------------------------*
*retreiving values from the database table ekko FORM DATA_RETRIEVAL_EKPO. SELECT EBELN EBELP MATNR MENGE MEINS NETPR FROM EKPO INTO TABLE IT_EKPO. ENDFORM.
FORM BUILD_LISTHEADER_EKPO USING I_LISTHEADER TYPE SLIS_T_LISTHEADER. DATA: HLINE1 TYPE SLIS_LISTHEADER. HLINE1-TYP = 'H'. HLINE1-INFO = 'CHECKING PGM'.
[ALV PROGRAMS]
ENDFORM.
FORM DISPLAY_ALV_EKPO. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_CALLBACK_PROGRAM I_CALLBACK_TOP_OF_PAGE I_GRID_TITLE IT_FIELDCAT I_SAVE IT_EVENTS TABLES T_OUTTAB EXCEPTIONS PROGRAM_ERROR OTHERS . IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. =2 =1 = IT_EKPO = V_REPID = 'TOP_OF_PAGE'
[ALV PROGRAMS]
In order to add a footer which is always displayed on screen to an ALV grid report you need to perform the steps below.
Please note this will not be displayed in the printed output Step 1. Update 'REUSE_ALV_GRID_DISPLAY' FM call to include parameter
'i_callback_html_end_of_list' call function 'REUSE_ALV_GRID_DISPLAY' exporting i_callback_program = gd_repid i_callback_top_of_page = 'TOP-OF-PAGE' i_callback_html_end_of_list = 'END_OF_LIST_HTML' is_layout = gd_layout it_fieldcat = fieldcatalog[] i_save = 'X' tables t_outtab = it_ekko exceptions program_error = 1 others = 2.
[ALV PROGRAMS]
*&------------------------------------------------------------------* *& Form end_of_list_html *&------------------------------------------------------------------* * output at the end of the list - not in printed output * *&------------------------------------------------------------------* FORM end_of_list_html USING end TYPE REF TO cl_dd_document. DATA: ls_text TYPE sdydo_text_element, l_grid TYPE REF TO cl_gui_alv_grid, f(14) TYPE c VALUE 'SET_ROW_HEIGHT'. ls_text = 'Footer title'. * adds and icon (red triangle) CALL METHOD end->add_icon EXPORTING sap_icon = 'ICON_MESSAGE_ERROR_SMALL'. * adds test (via variable) CALL METHOD end->add_text EXPORTING text = ls_text sap_emphasis = 'strong'. * adds new line (start new line) CALL METHOD end->new_line. * display text(bold) CALL METHOD end->add_text EXPORTING
[ALV PROGRAMS]
text = 'Bold text' sap_emphasis = 'strong'. * adds new line (start new line) CALL METHOD end->new_line. * display text(normal) CALL METHOD end->add_text EXPORTING text = 'Normal text'. * adds new line (start new line) CALL METHOD end->new_line. * display text(bold) CALL METHOD end->add_text EXPORTING text = 'Yellow triangle' sap_emphasis = 'strong'. * adds and icon (yellow triangle) CALL METHOD end->add_icon EXPORTING sap_icon = 'ICON_LED_YELLOW'. * display text(normal) CALL METHOD end->add_text EXPORTING text = 'More text'. *set height of this section
[ALV PROGRAMS]
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' IMPORTING e_grid = l_grid. CALL METHOD l_grid->parent->parent->(f) EXPORTING id = 3 height = 14. ENDFORM. "end_of_list_html.
REPORT ZSAMALVCALLBACK. type-pools:slis. data:inttab type standard table of zemptab1 with header line , int_tab type STANDARD TABLE OF zemptabtwo with header line, in_tab type standard table of zemptabtwo with header line. data:fieldcat type slis_t_fieldcat_alv with header line, fieldcat1 type slis_t_fieldcat_alv with header line. select * from zemptab1 into corresponding fields of table inttab. select * from zemptabtwo into corresponding fields of table int_tab. perform buildfieldcat. perform displayfieldcat. FORM buildfieldcat.
[ALV PROGRAMS]
fieldcat-fieldname = 'ID'. fieldcat-seltext_m = 'EMPID'. append fieldcat to fieldcat. fieldcat-fieldname = 'NAME'. fieldcat-seltext_m = 'EMPNAME'. append fieldcat to fieldcat. fieldcat-fieldname = 'QUALIFICATION'. fieldcat-seltext_m = 'QUAL'. append fieldcat to fieldcat. fieldcat-fieldname = 'CITY'. fieldcat-seltext_m = 'CITY'. APPEND fieldcat to fieldcat. fieldcat-fieldname = 'AGE'. fieldcat-seltext_m = 'AGE'. APPEND fieldcat to fieldcat. ENDFORM. "buildfileldcat FORM displayfieldcat . CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_CALLBACK_PROGRAM = sy-repid I_CALLBACK_USER_COMMAND = 'USECOMMAND' IT_FIELDCAT = FIELDCAT[] TABLES t_outtab = int_tab.
[ALV PROGRAMS]
IF sy-subrc <> 0. ENDIF. ENDFORM. "displayfieldcat FORM USECOMMAND USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield . case r_ucomm. WHEN '&IC1'. READ TABLE int_tab INDEX rs_selfield-tabindex. IF sy-subrc EQ 0. "loop at int_tab where id eq rs_selfield. in_tab-id = int_tab-id. in_tab-dcode = int_tab-dcode. in_tab-desig = int_tab-desig. in_tab-exp = int_tab-exp. append in_tab. endif. endcase. " endloop. clear fieldcat. refresh fieldcat. perform build_fieldcat. perform display_fieldcat. ENDFORM. "USECOMMAND FORM build_fieldcat.
[ALV PROGRAMS]
fieldcat-fieldname = 'DCODE'. fieldcat-seltext_m = 'Desigcode'. append fieldcat. fieldcat-fieldname = 'ID'. fieldcat-seltext_m = 'EMPID'. APPEND fieldcat to fieldcat. fieldcat-fieldname = 'DESIG'. fieldcat-seltext_m = 'Designation'. append fieldcat to fieldcat. fieldcat-fieldname = 'EXP'. fieldcat-seltext_m = 'EXPERIENCE'. append fieldcat to fieldcat. ENDFORM. "build_fieldcat FORM display_fieldcat. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_CALLBACK_PROGRAM = sy-repid IT_FIELDCAT = fieldcat[] TABLES t_outtab = in_tab EXCEPTIONS PROGRAM_ERROR = 1 OTHERS = 2. ENDFORM. "display_fieldcat
[ALV PROGRAMS]
---------------------------------------------------------------------------------------------------ABAP - Coloring A Row & Column In ALV Display Using OOPS Concept. Coloring a Row Step 1: Include a field called rowcolor in output internal table. types : begin of ty. include structure MARA. Types : rowcolor(4) TYPE c, end of ty. data : itab type standard table of ty,"Output Internal table wa type ty.
Step 2: Setting the layout accordingly Data w_layout TYPE lvc_s_layo."Layout structure * Setting layout w_layout-info_fname = 'ROWCOLOR'."For row coloring
Step 3: Coloring the specific row * Colouring a row CLEAR wa. READ TABLE itab INTO wa INDEX 3. IF sy-subrc EQ 0. wa-rowcolor = 'C311'. MODIFY itab FROM wa TRANSPORTING rowcolor WHERE matnr = wa-matnr. ENDIF.
[ALV PROGRAMS]
Step4: Pass the layout also in the method set_table_for_first_display * Displaying the output CALL METHOD o_grid->set_table_for_first_display EXPORTING IS_VARIANT = w_variant I_SAVE = 'A' is_layout = w_layout CHANGING it_outtab = itab IT_FIELDCATALOG = i_fieldcat EXCEPTIONS INVALID_PARAMETER_COMBINATION = 1 PROGRAM_ERROR = 2 TOO_MANY_LINES = 3 others = 4. IF sy-subrc <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. ----------------------------------------------------------------------------------------------------------------------------
[ALV PROGRAMS]
types : rowcolor(4) TYPE c, end of ty. data : itab type standard table of ty,"Output Internal table i_fieldcat type standard table of lvc_s_fcat,"Field catalog wa type ty, w_variant type disvariant, w_layout TYPE lvc_s_layo,"Layout structure o_docking type ref to cl_gui_docking_container,"Docking Container o_grid type ref to cl_gui_alv_grid."Grid select * from mara into corresponding fields of table itab up to 10 rows. call screen 9000. &--------------------------------------------------------------------*& Module STATUS_9000 OUTPUT &--------------------------------------------------------------------* text ---------------------------------------------------------------------module STATUS_9000 output. if o_docking is initial. SET PF-STATUS 'ZSTATUS'. "GUI Status SET TITLEBAR 'ZTITLE'. "TitleCreating Docking Container CREATE OBJECT o_docking EXPORTING RATIO = '95'. IF sy-subrc eq 0.Creating Grid CREATE OBJECT o_grid
[ALV PROGRAMS]
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING I_STRUCTURE_NAME = 'MARA' CHANGING ct_fieldcat = i_fieldcat EXCEPTIONS INCONSISTENT_INTERFACE = 1 PROGRAM_ERROR = 2 OTHERS = 3. w_variant-report = sy-repid.Setting layout w_layout-info_fname = 'ROWCOLOR'."For row coloringColouring a row CLEAR wa.
READ TABLE itab INTO wa INDEX 3. IF sy-subrc EQ 0. wa-rowcolor = 'C311'. MODIFY itab FROM wa TRANSPORTING rowcolor WHERE matnr = wa-matnr. ENDIF.Displaying the output CALL METHOD o_grid->set_table_for_first_display EXPORTING
[ALV PROGRAMS]
IS_VARIANT = w_variant I_SAVE = 'A' is_layout = w_layout CHANGING it_outtab = itab IT_FIELDCATALOG = i_fieldcat EXCEPTIONS INVALID_PARAMETER_COMBINATION = 1 PROGRAM_ERROR = 2 TOO_MANY_LINES = 3 others = 4. IF sy-subrc <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. endif. endmodule. " STATUS_9000 OUTPUT
[ALV PROGRAMS]
data lv_ucomm type sy-ucomm. lv_ucomm = sy-ucomm. CASE lv_ucomm. WHEN 'CANCEl' OR 'EXIT'. perform free_objects. LEAVE PROGRAM. when 'BACK'. perform free_objects. set screen '0'. leave screen. ENDCASE. endmodule. " USER_COMMAND_9000 INPUT
&--------------------------------------------------------------------*& Form free_objects &--------------------------------------------------------------------* Free Objects ---------------------------------------------------------------------form free_objects . CALL METHOD o_grid->free EXCEPTIONS CNTL_ERROR = 1 CNTL_SYSTEM_ERROR = 2 others = 3.
[ALV PROGRAMS]
IF sy-subrc <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. CALL METHOD o_docking->free EXCEPTIONS CNTL_ERROR = 1 CNTL_SYSTEM_ERROR = 2 others = 3. 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. " free_objects
Output
[ALV PROGRAMS]
* Make the field as non-key so that color should take effect -key = ' '.
Complete Code for Coloring a Column Screen 9000,GUI Status ZSTATUS and GUI Title ZTITLE should be created and in FLow logic of the screen, PBO and PAI should be uncommented.
[ALV PROGRAMS]
data : itab type standard table of MARA,"Output Internal table i_fieldcat type standard table of lvc_s_fcat,"Field catalog wa type MARA, w_variant type disvariant, w_layout TYPE lvc_s_layo,"Layout structure o_docking type ref to cl_gui_docking_container,"Docking Container o_grid type ref to cl_gui_alv_grid."GridDeclaring field symbols
select * from mara into corresponding fields of table itab up to 10 rows. call screen 9000.
[ALV PROGRAMS]
SET PF-STATUS 'ZSTATUS'. "GUI Status SET TITLEBAR 'ZTITLE'. "TitleCreating Docking Container CREATE OBJECT o_docking EXPORTING RATIO = '95'. IF sy-subrc eq 0.Creating Grid
CREATE OBJECT o_grid EXPORTING i_parent = o_docking. ENDIF.Filling the fieldcatalog table
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING I_STRUCTURE_NAME = 'MARA' CHANGING ct_fieldcat = i_fieldcat EXCEPTIONS INCONSISTENT_INTERFACE = 1 PROGRAM_ERROR = 2 OTHERS = 3. w_variant-report = sy-repid.Modifying the fieldcatalog for coloring a column
[ALV PROGRAMS]
LOOP AT i_fieldcat ASSIGNING . CASE -fieldname. WHEN 'MATNR'. -key = ' '."Make the field as non-key so that color should take effectColoring a column -emphasize = 'C311'. ENDCASE. ENDLOOP.Displaying the output
CALL METHOD o_grid->set_table_for_first_display EXPORTING IS_VARIANT = w_variant I_SAVE = 'A' CHANGING it_outtab = itab IT_FIELDCATALOG = i_fieldcat EXCEPTIONS INVALID_PARAMETER_COMBINATION = 1
[ALV PROGRAMS]
PROGRAM_ERROR = 2 TOO_MANY_LINES = 3 others = 4. IF sy-subrc <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. endif. endmodule. " STATUS_9000 OUTPUT
&--------------------------------------------------------------------*& Module USER_COMMAND_9000 INPUT &--------------------------------------------------------------------* PAI ---------------------------------------------------------------------module USER_COMMAND_9000 input. data lv_ucomm type sy-ucomm. lv_ucomm = sy-ucomm.
CASE lv_ucomm.
[ALV PROGRAMS]
WHEN 'CANCEl' OR 'EXIT'. perform free_objects. LEAVE PROGRAM. when 'BACK'. perform free_objects. set screen '0'. leave screen. ENDCASE.
[ALV PROGRAMS]
EXCEPTIONS CNTL_ERROR = 1 CNTL_SYSTEM_ERROR = 2 others = 3. IF sy-subrc <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.
CALL METHOD o_docking->free EXCEPTIONS CNTL_ERROR = 1 CNTL_SYSTEM_ERROR = 2 others = 3. IF sy-subrc <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. Output
Colorconstants
[ALV PROGRAMS]
Use this Type-Pool to have "speaking constants" for your colorcodes. TYPE-POOL ZCOL .
constants: zcol_greyblue(04) type c value 'C100', zcol_lightgrey(04) type c value 'C200', zcol_yellow(04) type c value 'C300', zcol_bluegreen(04) type c value 'C400', zcol_green(04) type c value 'C500', zcol_red(04) type c value 'C600', zcol_violett(04) type c value 'C700',
zcol_greyblue_int(04) type c value 'C110', zcol_lightgrey_int(04) type c value 'C210', zcol_yellow_int(04) type c value 'C310', zcol_bluegreen_int(04) type c value 'C410', zcol_green_int(04) type c value 'C510', zcol_red_int(04) type c value 'C610', zcol_violett_int(04) type c value 'C710',
zcol_greyblue_inv(04) type c value 'C101', zcol_lightgrey_inv(04) type c value 'C201', zcol_yellow_inv(04) type c value 'C301', zcol_bluegreen_inv(04) type c value 'C401',
[ALV PROGRAMS]
zcol_green_inv(04) type c value 'C501', zcol_red_inv(04) type c value 'C601', zcol_violett_inv(04) type c value 'C701',
zcol_greyblue_int_inv(04) type c value 'C111', zcol_lightgrey_int_inv(04) type c value 'C211', zcol_yellow_int_inv(04) type c value 'C311', zcol_bluegreen_int_inv(04) type c value 'C411', zcol_green_int_inv(04) type c value 'C511', zcol_red_int_inv(04) type c value 'C611', zcol_violett_int_inv(04) type c value 'C711'. Create this Type-Pool with transaction SE11. ------------------------------------------------------------------------------------------------------------
Often, one requires customizing the toolbar that appears in an ALV Tree and taking specific actions on choosing this button by triggering the specific handlers. The following code snippet shows how this can be done in ABAP OO assuming you have a class which requires this handling and the following methods in the same will help you achieve this. The following code snippet assumes that a filter button appears on given conditions only in the ALV tree and requires to be turned off at other times. This is achieved in the following manner: Assume the ALV Tree is created and now we wish to customize the toolbar for the same: p_filter is the flag which decides if the filter button requires to be visible or not.
[ALV PROGRAMS]
****************************************************************** *Create ALV tree prior to this in create_my_tree() method. *Change the toolbar to suit our needs,pass the tree and filter as parameters. ......... method create_toolbar. create_my_tree(). if f_alvtree is not initial. __call_toolbar( tree = f_alvtree filter = p_filter ). endif. endmethod.
****************************************************************** *You could specify the toolbar by passing the instance variable f_toolbar which stores the toolbar instance and the filter options. method __call_toolbar. check tree is not initial. tree->get_toolbar_object( importing er_toolbar = f_toolbar ). f_filter_opt = filter. __customize_toolbar( alvtreebar = f_toolbar refresh = f_filter_opt ). endmethod. ****************************************************************** *Specify the tooltips that you wish for your toolbar items. Here *iconquick is a text icon defined in the dictionary. *It also is optimal to group your icons in an icon package. Raise the event for handling the icon change ,define an event as below in your class. ******************************************************************
[ALV PROGRAMS]
*---------------------------------------------------call method alvtreebar->delete_button exporting fcode = 'SHOW_GRID'. * ---------------------------------------------------if refresh = ''. " Filter is off so add filter off button clear: l_tooltip. l_tooltip = 'Switch on Filter '(add). call method alvtreebar->add_button exporting butn_type = cntb_btype_button quickinfo = l_tooltip icon = icon_filter_undo fcode = 'FILON'. else. * ---------------------------------------------------clear: l_tooltip." Add filter on button l_tooltip = 'Switch off Filter'(fil). call method alvtreebar->add_button exporting
[ALV PROGRAMS]
butn_type = cntb_btype_button quickinfo = l_tooltip icon = icon_filter fcode = 'FILOFF' is_disabled = ''. endif. * ---------------------------------------------------raise event change_tree_toolbar exporting im_toolbar = alvtreebar. * ---------------------------------------------------set handler __handle_filter_selected for alvtreebar. endif. ****************************************************************** * This method actually deals with the change on filter appearing/disappearing. method __handle_filter_selected. case fcode. when 'FILOFF'. check f_toolbar is not initial. f_filter_opt = ''. __handle_filter( ). f_filter_opt = 'X'. when 'FILON' . check f_toolbar is not initial.
[ALV PROGRAMS]
REPORT zalv_dropdowns.
*data declarations for ALV container,ALV grid, Fieldcatalogues & layout DATA: g_grid TYPE REF TO cl_gui_alv_grid, g_custom_container TYPE REF TO cl_gui_custom_container, gt_fieldcat TYPE lvc_t_fcat, gs_layout TYPE lvc_s_layo.
[ALV PROGRAMS]
*INTERNAL TABLE AND WA DECLARATIONS FOR t517 A table DATA: gt_outtab TYPE STANDARD TABLE OF t517a INITIAL SIZE 0, wa_outtab TYPE t517a.
*On this statement double click it takes you to the screen painter SE51.
[ALV PROGRAMS]
*Now a normal screen with number 600 is created which holds the ALV grid. PBO of the actual screen , Here we can give a title and customized menus Here we also call the subroutine for ALV output.
MODULE pbo OUTPUT. * set pf-status 'xxx'. * set titlebar 'MAIN100'. Subroutine to display the output in alv
PERFORM alv_output.
[ALV PROGRAMS]
PAI module of the screen created. In case we use an interactive ALV or *for additional functionalities we can create OK codes and based on the user command we can do the coding.
--------------------------------------------------------------------* MODULE PAI INPUT * --------------------------------------------------------------------MODULE pai INPUT. ENDMODULE. "pai INPUT
&--------------------------------------------------------------------*& Form BUILD_FIELDCAT &--------------------------------------------------------------------FORM build_fieldcat. DATA ls_fcat TYPE lvc_s_fcat. *Build the field catalogue
[ALV PROGRAMS]
CASE ls_fcat-fieldname. WHEN 'SLART'. *drdn-hndl = '1' is the first list box ls_fcat-drdn_hndl = '1'. ls_fcat-outputlen = 15. MODIFY gt_fieldcat FROM ls_fcat.
WHEN 'ABART'. ls_fcat-drdn_hndl = '2'. ls_fcat-outputlen = 15. MODIFY gt_fieldcat FROM ls_fcat.
[ALV PROGRAMS]
FORM alv_output .
*Create object for container CREATE OBJECT g_custom_container EXPORTING container_name = 'CCONT'.
*create object for grid CREATE OBJECT g_grid EXPORTING i_parent = g_custom_container.
[ALV PROGRAMS]
*fetch values from the T517A table SELECT * FROM t517a INTO TABLE gt_outtab.
[ALV PROGRAMS]
&--------------------------------------------------------------------*& Form dropdown_table &--------------------------------------------------------------------* text ---------------------------------------------------------------------* --> p1 text * <-- p2 text ----------------------------------------------------------------------
[ALV PROGRAMS]
[ALV PROGRAMS]
Second ABART listbox (handle '2'). ls_dropdown-handle = '2'. ls_dropdown-value = '10 Primary School certificate'. APPEND ls_dropdown TO lt_dropdown.
ls_dropdown-handle = '2'. ls_dropdown-value = '20 Lower secondary/Junior high'. APPEND ls_dropdown TO lt_dropdown.
[ALV PROGRAMS]
ls_dropdown-handle = '2'. ls_dropdown-value = '30 High school diploma(B-levels)'. APPEND ls_dropdown TO lt_dropdown.
ls_dropdown-handle = '2'. ls_dropdown-value = '40 Specialist vocational certificate'. APPEND ls_dropdown TO lt_dropdown.
ls_dropdown-handle = '2'. ls_dropdown-value = '50 College degree Level1'. APPEND ls_dropdown TO lt_dropdown.
[ALV PROGRAMS]
ls_dropdown-handle = '2'. ls_dropdown-value = '51 College degree Level2'. APPEND ls_dropdown TO lt_dropdown.
ls_dropdown-handle = '2'. ls_dropdown-value = '60 Univ Degree level1'. APPEND ls_dropdown TO lt_dropdown.
[ALV PROGRAMS]
ls_dropdown-handle = '2'. ls_dropdown-value = '64 Doctors Degree Ph.D'. APPEND ls_dropdown TO lt_dropdown.
[ALV PROGRAMS]
&--------------------------------------------------------------------*& Form build_layout &--------------------------------------------------------------------* text ---------------------------------------------------------------------*layout for ALV output FORM build_layout . gs_layout-cwidth_opt = 'X'. gs_layout-grid_title = 'ALV DROPDOWN LISTS'. gs_layout-no_toolbar = 'X'. ENDFORM. " build_layout ABAP - Handling Radio Buttons in SALV Tree Display.
This tutorial will help developers to handle checkboxes in SALV tree. I would be copying some code verbatim from my project work. Following code is to add checkboxes in ALV tree: FORM add_root_request USING _p_ls_data_ TYPE csg_gs_outtab_p_key__l_is_sub_node_ TYPE c
[ALV PROGRAMS]
* ... 0.2 if information should be displayed at * the hierarchy column set the carrid as text for this node text = p_ls_data-object. node->set_text( text ). * ... 0.3 set the data for the nes node node->set_data_row( p_ls_data ). item = node->get_hierarchy_item( ). item = node->get_item( 'FCHECKBOX' ). "FCHECKBOX is my radio button field in internal table which I am using to populate the ALV item->set_type( if_salv_c_item_type=>checkbox ). _p_l_carrid_key = node->get_key( )._
CATCH cx_salv_msg.
ENDFORM_._ Following code is for handling checbox_change event PERFORM application_action_events. FORM application_action_events .
lr_events = gr_tree->get_event( ).
[ALV PROGRAMS]
PUBLIC SECTION.
[ALV PROGRAMS]
METHODS:
check FOR EVENT checkbox_change OF cl_salv_events_tree IMPORTING node_key columnname checked. "Here node_key is the row number
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
METHOD check_._
WRITE 'hello'_._
[ALV PROGRAMS]
if columnname = 'FCHECKBOX'_._
IF checked = 'X'_._
ELSE_._
_l_wa_modify_check->fcheckbox =_ 'X'_._
ENDIF_._
ENDIF_._
if columnname = 'CHECKBOX_READ'_._
IF checked = 'X'_._
[ALV PROGRAMS]
ELSE_._
_l_wa_modify_check->checkbox_read =_ 'X'_._
ENDIF_._
ENDIF_._
ENDMETHOD_._ "check
[ALV PROGRAMS]
I have searched SDN myself for the answer for sometime. All the friends that answered were helpful but there were only example links. So here is a simple code to implement F4 search help for OO ALV grid cells: First we have to define the method and sub programs. In the definition part of our events class, include a code as the following: CLASS lcl_event_handler DEFINITION . PUBLIC SECTION . METHODS: ... .... on_f4 FOR EVENT onf4 OF cl_gui_alv_grid IMPORTING e_fieldname es_row_no er_event_data et_bad_cells e_display. .... ENDCLASS.
For the implementation part, code can be as follows: CLASS lcl_event_handler IMPLEMENTATION . ..... .... METHOD on_f4. PERFORM on_f4 USING e_fieldname
[ALV PROGRAMS]
es_row_no-row_id er_event_data et_bad_cells e_display er_data_changed. er_event_data->m_event_handled = 'X'. ENDMETHOD. "on_f4 ..... ..... ENDCLASS . Within our main program after displaying the table (by method set_table_for_first_display), we have to create the event handler object and set the handlers for these events.
CREATE OBJECT gr_event_handler . *--Registering handler methods to handle ALV Grid events ..... ..... SET HANDLER gr_event_handler->on_f4 FOR gr_alvgrid . PERFORM register_f4_fields. "set cells with search help *3.Optionally register ENTER to raise event DATA_CHANGED. call method gr_alvgrid->register_edit_event EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_modified. ...... ....... ......
[ALV PROGRAMS]
FORM register_f4_fields. "which fields will have F4 search help DATA: lt_f4 TYPE lvc_t_f4 WITH HEADER LINE . DATA: lt_f4_data TYPE lvc_s_f4. lt_f4_data-fieldname = 'CHARG'. lt_f4_data-register = 'X' . * lt_f4_data-getbefore = 'X' . lt_f4_data-CHNGEAFTER ='X'. INSERT lt_f4_data INTO TABLE lt_f4. lt_f4_data-fieldname = 'LGORT'. lt_f4_data-register = 'X' . * lt_f4_data-getbefore = 'X' . lt_f4_data-CHNGEAFTER ='X'. INSERT lt_f4_data INTO TABLE lt_f4. CALL METHOD gr_alvgrid->register_f4_for_fields EXPORTING it_f4 = lt_f4[]. ENDFORM. "register_f4_fields
The main sub program where we handle the changed cell value is as follows: FORM on_f4 USING P_E_FIELDNAME ROW_ID P_ER_EVENT_DATA TYPE REF TO CL_ALV_EVENT_DATA P_ET_BAD_CELLS P_E_DISPLAY
[ALV PROGRAMS]
IR_DATA_CHANGED TYPE REF TO cl_alv_changed_data_protocol. DATA: BEGIN OF value_charg OCCURS 0, "the value table that is passed to F4 fm charg like zpp_kpduzelt-charg, lgort like zpp_kpduzelt-lgort, clabs like mchb-clabs, END OF value_charg. DATA : ls_mod_cell TYPE lvc_s_modi , ls_del_cell TYPE lvc_s_moce , ls_good_cell TYPE lvc_s_modi, lv_value TYPE lvc_value . DATA : ls_mod_row like line of gt_list. ....., .... *5 define fields and field-symbols for data-update field-symbols: type lvc_t_modi. data: ls_modi type lvc_s_modi. create object ir_data_changed. SORT ir_data_changed->mt_mod_cells BY row_id .
[ALV PROGRAMS]
case p_e_fieldname. "read changed cell when 'CHARG'. ...... * here must be the code to fill in the possible values table * and the call to fm F4IF_INT_TABLE_VALUE_REQUEST ......
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST' EXPORTING retfield = 'CHARG' value_org = 'S' * DYNPPROG = SY-REPID * DYNPNR = SY-DYNNR * DYNPROFIELD = 'PRUEFLOS' TABLES value_tab = value_charg * field_tab = field_tab return_tab = return_tab EXCEPTIONS parameter_error = 1 no_values_found = 2 OTHERS = 3.
[ALV PROGRAMS]
move return_tab-fieldval to charg. ls_mod_cell-row_id = row_id. ls_mod_cell-fieldname = 'CHARG'. move charg to lv_value. ls_mod_cell-value = lv_value. append ls_mod_cell to ir_data_changed->mt_mod_cells.
*******************
read table gt_list index row_id into wa_tab. create data lp_wa like line of gt_list. assign lp_wa->* to . = wa_tab. read table lt_fcat
[ALV PROGRAMS]
with key fieldname = ls_mod_cell-fieldname into ls_fieldcat. move ls_fieldcat-ref_table to l_tabname. move ls_fieldcat-fieldname to l_fieldname. assign component ls_fieldcat-fieldname of structure wa_tab to .
**6 assign the cell table fieldsymbol to the dereferenced data table *and * fill the table.
assign p_er_event_data->m_data->* to . append ls_mod_cell to . .... .... ENDIF. .... ..... endcase.
[ALV PROGRAMS]
Description>AS : ALV report with user defined buttons in its toolbar and when clicking the last yellow button(arrow) can display the toolbar and expand it in three steps
*&---------------------------------------------------------------------* *&Report:ZALV_TOOLBAR * *&Author : Swarna.S *&---------------------------------------------------------------------* *& AS : ALV report with user defined buttons in its toolbar *& and when clicking the last yellow button(arrow) can display the *& toolbar and expand it in three steps *---------------------------------------------------------------------* REPORT zalv_toolbar.
*Structure declaration for tcodes TYPES : BEGIN OF ty_table, tcode TYPE tcode, pgmna TYPE progname, END OF ty_table.
[ALV PROGRAMS]
*Structure for tocde text TYPES : BEGIN OF ty_itext, tcode TYPE tcode, ttext TYPE ttext_stct, sprsl TYPE sprsl, END OF ty_itext.
*Structure for output display TYPES : BEGIN OF ty_output, tcode TYPE tcode, pgmna TYPE progname, ttext TYPE ttext_stct, END OF ty_output.
*internal table and work area declarations DATA : it_table TYPE STANDARD TABLE OF ty_table INITIAL SIZE 0, it_output TYPE STANDARD TABLE OF ty_output INITIAL SIZE 0, it_ittext TYPE STANDARD TABLE OF ty_itext INITIAL SIZE 0, wa_table TYPE ty_table, wa_output TYPE ty_output, wa_ittext TYPE ty_itext.
[ALV PROGRAMS]
* Data declarations for ALV DATA: c_ccont TYPE REF TO cl_gui_custom_container, "Custom container object c_alvgd TYPE REF TO cl_gui_alv_grid, "ALV grid object it_fcat TYPE lvc_t_fcat, "Field catalogue it_layout TYPE lvc_s_layo, "Layout c_alv_toolbar TYPE REF TO lcl_alv_toolbar, "Alv toolbar c_alv_toolbarmanager TYPE REF TO cl_alv_grid_toolbar_manager. "Toolbar manager
[ALV PROGRAMS]
CLASS lcl_alv_toolbar DEFINITION. PUBLIC SECTION. *Constructor METHODS: constructor IMPORTING io_alv_grid TYPE REF TO cl_gui_alv_grid, *Event for toolbar on_toolbar
[ALV PROGRAMS]
* Create ALV toolbar manager instance CREATE OBJECT c_alv_toolbarmanager EXPORTING io_alv_grid = io_alv_grid. ENDMETHOD. "constructor
[ALV PROGRAMS]
METHOD on_toolbar. * Add customized toolbar buttons. * variable for Toolbar Button ty_toolbar-icon = icon_generate. ty_toolbar-butn_type = 0. ty_toolbar-text = 'Button1'. APPEND ty_toolbar TO e_object->mt_toolbar. ty_toolbar-icon = icon_voice_output. ty_toolbar-butn_type = 0. ty_toolbar-text = 'Button2'. APPEND ty_toolbar TO e_object->mt_toolbar. ty_toolbar-icon = icon_phone. ty_toolbar-butn_type = 0. ty_toolbar-text = 'Button3'. APPEND ty_toolbar TO e_object->mt_toolbar. ty_toolbar-icon = icon_mail. ty_toolbar-butn_type = 0. ty_toolbar-text = 'Button4'. APPEND ty_toolbar TO e_object->mt_toolbar.
[ALV PROGRAMS]
** Call reorganize method of toolbar manager to ** display the toolbar CALL METHOD c_alv_toolbarmanager->reorganize EXPORTING io_alv_toolbar = e_object. ENDMETHOD. "on_toolbar
ENDCLASS. "lcl_alv_toolbar IMPLEMENTATION *&---------------------------------------------------------------------* *& Form fetch_data *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM fetch_data . * Select the tcodes upto 200 rows from TSTC.
SELECT tcode pgmna FROM tstc INTO CORRESPONDING FIELDS OF TABLE it_table UP TO 200 ROWS WHERE dypno NE '0000'.
[ALV PROGRAMS]
IF it_table[] IS NOT INITIAL. SELECT ttext tcode sprsl FROM tstct INTO CORRESPONDING FIELDS OF TABLE it_ittext FOR ALL ENTRIES IN it_table WHERE tcode = it_table-tcode AND sprsl = 'E'. ENDIF.
* For texts
READ TABLE it_ittext INTO wa_ittext WITH KEY tcode = wa_table-tcode. wa_output-ttext = wa_ittext-ttext. APPEND wa_output TO it_output. CLEAR wa_output. ENDLOOP. ENDFORM. " fetch_data *&---------------------------------------------------------------------* *& Form alv_output *&---------------------------------------------------------------------*
[ALV PROGRAMS]
** Calling the ALV screen with custom container *On this statement double click it takes you to the screen painter SE51.
*Create a Custom container and name it CC_CONT and OK code as OK_CODE. *Save check and Activate the screen painter.
*Now a normal screen with number 600 is created which holds the ALV grid. * PBO of the actual screen , Here we can give a title and *customized menus *&---------------------------------------------------------------------*
[ALV PROGRAMS]
* SET PF-STATUS 'xxxxxxxx'. * SET TITLEBAR 'xxx'. ENDMODULE. " STATUS_0600 OUTPUT
* calling the PBO module ALV_GRID. *&---------------------------------------------------------------------* *& Module ALV_GRID OUTPUT *&------------------------------------------------------------