64344757-alv-oops

September 15, 2017 | Author: Ricky Mondal | Category: N/A
Share Embed Donate


Short Description

Download 64344757-alv-oops...

Description

This simple program helps in editing DDIC from ALV on pressing putton on toolbar. Perform action on Hot spot Click. *&---------------------------------------------------------------------* *& Report YKC_ALV_OOPS *& *&---------------------------------------------------------------------* *& This prog will help in understanding ALV OOPS *& EDIT on SAVE *& Tool bar button addition *&---------------------------------------------------------------------* REPORT YKC_ALV_OOPS. tables: MARA. data: begin of it_tab occurs 0, matnr like mara-matnr, ersda like mara-ersda, "creation date ernam like mara-ernam, "person created pstat like mara-pstat, "maint stat lvorm like mara-lvorm, "flg for deletion mtart like mara-mtart, "mat type meins like mara-meins, "uom end of it_tab. data: wa_it_tab like line of it_tab. "making work area data: i_modified TYPE STANDARD TABLE OF mara,"For getting modified rows w_modified TYPE mara. CLASS lcl_events_d0100 DEFINITION DEFERRED. DATA: event_receiver1 TYPE REF TO lcl_events_d0100, i_selected_rows TYPE lvc_t_row, "Selected Rows w_selected_rows TYPE lvc_s_row. *---------------------------------------------------------------------* * CLASS lcl_events_d0100 DEFINITION *---------------------------------------------------------------------* CLASS lcl_events_d0100 DEFINITION. PUBLIC SECTION. METHODS handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid IMPORTING e_row_id e_column_id es_row_no sender. *---code addition for ALV pushbuttons *--for placing buttons METHODS handle_toolbar_set

FOR EVENT toolbar OF cl_gui_alv_grid IMPORTING e_object e_interactive. *---user command on clicking a button METHODS handle_user_command FOR EVENT user_command OF cl_gui_alv_grid IMPORTING e_ucomm. ENDCLASS. "lcl_events_d0100 DEFINITION TYPE-POOLS cndp. DATA ok_code TYPE sy-ucomm. *----------------------------------------------------------------------* * FOR VARIANT *----------------------------------------------------------------------* DATA st_var TYPE disvariant . DATA save TYPE c. st_var-report = 'YKC_ALV_OOPS'. save = 'A'. *----------------------------------------------------------------------* * FOR LAYOUT *----------------------------------------------------------------------* DATA loyo TYPE lvc_s_layo. loyo-zebra = 'X'. loyo-detailinit = 'X'. loyo-info_fname = 'RED'. *----------------------------------------------------------------------* * FOR FIELD CATALOG *----------------------------------------------------------------------* DATA fcat TYPE lvc_t_fcat. DATA wa_fcat LIKE LINE OF fcat. *--Declaration for toolbar buttons DATA : ty_toolbar TYPE stb_button. DATA : e_object TYPE REF TO cl_alv_event_toolbar_set, io_alv_toolbar TYPE REF TO cl_alv_event_toolbar_set. *---custom container DATA container TYPE REF TO cl_gui_custom_container. DATA ref_grid TYPE REF TO cl_gui_alv_grid. CREATE OBJECT container EXPORTING container_name = 'CONTAINER'."name of container in module pool CREATE OBJECT ref_grid EXPORTING i_parent = container. *---------------------------------------------------------------------* * CLASS lcl_events_d0100 IMPLEMENTATION

*---------------------------------------------------------------------* CLASS lcl_events_d0100 IMPLEMENTATION. *---method for hotspot METHOD handle_hotspot_click. DATA:ls_col_id TYPE lvc_s_col. READ TABLE it_tab INTO wa_it_tab INDEX e_row_id-index. IF sy-subrc = 0. CHECK ( wa_it_tab-matnr IS NOT INITIAL ). CASE e_column_id-fieldname. WHEN 'MATNR'. leave program. *---put your own logic as per requirement on hotspot click WHEN OTHERS. * do nothing ENDCASE. CALL METHOD ref_grid->set_current_cell_via_id EXPORTING is_row_id = e_row_id is_column_id = ls_col_id. ENDIF. ENDMETHOD. "handle_hotspot_click **---method for handling toolbar METHOD handle_toolbar_set. CLEAR ty_toolbar. ty_toolbar-function = 'EDIT'. "name of btn to catch click ty_toolbar-butn_type = 0. ty_toolbar-text = 'EDIT'. APPEND ty_toolbar TO e_object->mt_toolbar. ENDMETHOD. "handle_toolbar_set METHOD handle_user_command. DATA: wr_data_changed TYPE REF TO cl_alv_changed_data_protocol. DATA: lt_rows TYPE lvc_t_row, lt_index TYPE lvc_s_row-index. CASE e_ucomm. WHEN 'EDIT'. perform save_database. CALL METHOD ref_GRID->REFRESH_TABLE_DISPLAY. ENDCASE. ENDMETHOD. "handle_user_command ENDCLASS. "lcl_events_d0100 IMPLEMENTATION START-OF-SELECTION. PERFORM get_data. PERFORM field_catalog. *&---------------------------------------------------------------------* *& Form get_data

*&---------------------------------------------------------------------* * text : getting data into internal table *----------------------------------------------------------------------* form get_data . select matnr ersda ernam pstat lvorm mtart meins into table it_tab from mara where matnr GE '000000000000000001'. endform. " get_data *&---------------------------------------------------------------------* *& Form field_catalog *&---------------------------------------------------------------------* * text :setting field cat *----------------------------------------------------------------------* form field_catalog . REFRESH fcat. DATA: lv_pos TYPE i. lv_pos = lv_pos + 1. wa_fcat-fieldname = 'MATNR'. wa_fcat-coltext = 'Material No'. wa_fcat-col_pos = lv_pos. wa_fcat-hotspot = 'X'. wa_fcat-outputlen = 18. APPEND wa_fcat TO fcat. CLEAR wa_fcat. lv_pos = lv_pos + 1. wa_fcat-fieldname = 'ERSDA'. wa_fcat-coltext = 'Creation Date'. wa_fcat-col_pos = lv_pos. wa_fcat-edit = 'X'. wa_fcat-outputlen = 18. APPEND wa_fcat TO fcat. CLEAR wa_fcat. lv_pos = lv_pos + 1. wa_fcat-fieldname = 'ERNAM'. wa_fcat-coltext = 'Person Created'. wa_fcat-col_pos = lv_pos. wa_fcat-outputlen = 18. APPEND wa_fcat TO fcat. CLEAR wa_fcat. lv_pos = lv_pos + 1. wa_fcat-fieldname = 'PSTAT'. wa_fcat-coltext = 'Maint Stat'. wa_fcat-col_pos = lv_pos. wa_fcat-outputlen = 18. APPEND wa_fcat TO fcat.

CLEAR wa_fcat. lv_pos = lv_pos + 1. wa_fcat-fieldname = 'LVORM'. wa_fcat-coltext = 'Flag For Deletion'. wa_fcat-col_pos = lv_pos. wa_fcat-outputlen = 18. APPEND wa_fcat TO fcat. CLEAR wa_fcat. lv_pos = lv_pos + 1. wa_fcat-fieldname = 'MTART'. wa_fcat-coltext = 'Material Type'. wa_fcat-col_pos = lv_pos. wa_fcat-outputlen = 18. APPEND wa_fcat TO fcat. CLEAR wa_fcat. lv_pos = lv_pos + 1. wa_fcat-fieldname = 'MEINS'. wa_fcat-coltext = 'UOM'. wa_fcat-col_pos = lv_pos. wa_fcat-outputlen = 18. APPEND wa_fcat TO fcat. CLEAR wa_fcat. CREATE OBJECT event_receiver1. *---setting event handlers SET HANDLER event_receiver1->handle_toolbar_set FOR ref_grid. SET HANDLER event_receiver1->handle_user_command FOR ref_grid. SET HANDLER event_receiver1->handle_hotspot_click FOR ref_grid. *----------------------------------------------------------------------* * ALV GRID DISPLAY *----------------------------------------------------------------------* CALL METHOD ref_grid->set_table_for_first_display EXPORTING is_variant = st_var i_save = save is_layout = loyo CHANGING it_outtab = it_tab[] it_fieldcatalog = fcat. CALL SCREEN 100. endform. " field_catalog *&---------------------------------------------------------------------* *& Module STATUS_0100 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* module STATUS_0100 output.

* CREATE OBJECT gr_events_d0100. * * SET HANDLER gr_events_d0100->double_click * * FOR ref_grid. CALL METHOD ref_grid->register_edit_event EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_modified. SET PF-STATUS 'S100'. SET TITLEBAR 'XXX'. endmodule. " STATUS_0100 OUTPUT *&---------------------------------------------------------------------* *& Module exit INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* module exit input. CASE ok_code. WHEN 'EXI' . CLEAR ok_code. LEAVE PROGRAM. ENDCASE. endmodule. " exit INPUT *&---------------------------------------------------------------------* *& Form SAVE_DATABASE *&---------------------------------------------------------------------* * text : saving into DDIC from internal table *----------------------------------------------------------------------* * --> p1 text * get_selected_rows IMPORTING et_index_rows = i_selected_rows. *--- Through the index capturing the values of selected rows LOOP AT i_selected_rows INTO w_selected_rows. READ TABLE it_tab INTO wa_it_tab INDEX w_selected_rows-index. IF sy-subrc EQ 0. MOVE-CORRESPONDING wa_it_tab TO w_modified. APPEND w_modified TO i_modified. ENDIF. ENDLOOP. MODIFY mara FROM TABLE i_modified. ENDFORM. " SAVE_DATABASE

ABAP - Developing Interactive ALV Report using OOABAP  

Added by Rajasekhar Dinavahi, last edited by Anirban Bhattacharjee on Oct 31, 2008 (view change) 1. Have a field designated for the color. For eg: TYPES: BEGIN OF tw_xresult, text TYPE zsdtype, vbeln TYPE vbeln, ernam TYPE ernam, persrb TYPE zpers_resp, erdat TYPE erdat, vkorg TYPE vkorg, vtweg TYPE vtweg, spart TYPE spart, vkbur TYPE vkbur, vkgrp TYPE vkgrp, vbtyp TYPE vbtyp, fehler TYPE znumber, netwr TYPE netwr_ak, uvall TYPE uvall, uvvlk TYPE uvvlk, uvfak TYPE uvfak, uvprs TYPE uvprs, t_color TYPE lvc_t_scol, END OF tw_xresult . TYPES:

"For row color

tt_result TYPE STANDARD TABLE OF tw_xresult . 2. Register the events for which you need to act upon. METHOD ALV_SET_EVENTS. DATA: lr_events TYPE REF TO cl_salv_events_table. lr_events = mcn_alv-> get_event(). *- Register the event Double click SET HANDLER me->mt_on_double_click FOR lr_events. *- Register the event User command SET HANDLER me->mt_on_user_command FOR lr_events. ENDMETHOD. 3. Once the required data is fetched into the internal table (say, into internal table mt_result), we

use the following code, to display the records with provision to select multiple records (through the selection pushbutton on the left for each record) METHOD alv_show . DATA : lr_selections TYPE REF TO cl_salv_selections. FIELD-SYMBOLS: TYPE STANDARD TABLE. *- Show ALV on the screen ASSIGN me->mn_data->* TO . CHECK IS ASSIGNED. TRY. cl_salv_table=>factory( EXPORTING list_display = abap_false IMPORTING r_salv_table = mcn_alv CHANGING t_table = ). CATCH cx_salv_msg INTO mcn_alv_exception. MESSAGE mcn_alv_exception TYPE 'E'. EXIT. ENDTRY. me->alv_set_functions( ). me->alv_set_columns( ). me->alv_set_layout( mf_variantname ). me->alv_set_events( ). me->alv_set_headers( ). CALL METHOD alv_modify_settings( ). lr_selections = mcn_alv->get_selections( ). lt_rows = lr_selections->get_selected_rows(). in lt_rows.

" This will get the selected record numbers,

*- Set selection mode lr_selections->set_selection_mode( if_salv_c_selection_mode=>row_column ). mcn_alv->set_screen_status( pfstatus = 'ZREPINCOMP' report = mf_repid set_functions = mcn_alv->c_functions_all ). mcn_alv->display( ). ENDMETHOD. 4. With the above code, you will be able to select multiple records, and then the following code will process the selected records, and set a color for the processed records. DATA lw_row

TYPE i,

lt_color TYPE lvc_t_scol , ls_color TYPE lvc_s_scol . FIELD-SYMBOLS: TYPE tw_xresult.

"#EC NEEDED

LOOP AT lt_rows INTO lw_row. READ TABLE mt_result ASSIGNING INDEX lw_row. IF SY_SUBRC EQ 0.



*- For setting the color to the record CLEAR lt_color. CLEAR ls_color. ls_color-color-col = co_color. ls_color-color-int = 0. ls_color-color-inv = 0. APPEND ls_color TO lt_color. -t_color = lt_color. ENDIF. ENDLOOP.

ABAP-Traffic Signals in ALV using Classes    

Attachments:2 Added by Arunsri, last edited by Arunsri on Nov 13, 2008 (view change) show comment This code explains how to bring traffic signals in an ALV, using classes. Here customer details are displayed, in which INACTIVE (status) customers will get a 'RED' and ACTIVE signals will get a 'GREEN'. The attached ouput screen shot contains only signals, customer id and status. *&---------------------------------------------------------------------* *& Report ZALV_SAMPLE_CLASS *& *&---------------------------------------------------------------------* Report zalv_sample_class. *******************************************************

**Types Declaration ******************************************************* types: begin of ty_cust, custid type zcust_master4-custid, custname type zcust_master4-custname, address type zcust_master4-address, city type zcust_master4-city, state type zcust_master4-state, country type zcust_master4-country, phnum type zcust_master4-phnum, email type zcust_master4-email, fax type zcust_master4-fax, status type zcust_master4-status, lights(1) type c, end of ty_cust. ******************************************************* **Data Declaration ******************************************************* data: alv_container type ref to cl_gui_docking_container. data: alv_grid type ref to cl_gui_alv_grid. data: layout type lvc_s_layo. data: fieldcat type lvc_t_fcat. data: wt_cust type standard table of ty_cust, wa_cust type ty_cust. data: variant type disvariant. data: repid type sy-repid. repid = sy-repid. parameters: p_check. ******************************************************* **Initialization Declaration ******************************************************* initialization. ***To Get data from the database table perform get_details. variant-report = sy-repid. variant-username = sy-uname. ***Perform to design the layout perform layout. *********************************************************

**Create object alv container ********************************************************* check alv_container is initial. create object alv_container exporting repid = sy-repid dynnr = sy-dynnr side = alv_container->dock_at_left extension = 1550 exceptions cntl_error =1 cntl_system_error =2 create_error =3 lifetime_error =4 lifetime_dynpro_dynpro_link = 5 others = 6. if sy-subrc 0. message id sy-msgid type sy-msgty number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. endif. ********************************************************* **Create object alv Grid ********************************************************* create object alv_grid exporting i_parent = alv_container. ***Perform to d3esign field catalog perform fieldcatatalog. ********************************************************* **Call method set table for first display ********************************************************* call method alv_grid->set_table_for_first_display exporting i_structure_name = 'WT_CUST' is_variant = variant i_save = 'U' is_layout = layout changing it_outtab = wt_cust it_fieldcatalog = 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. ******************************************************* **Start-of-selection Declaration ******************************************************* start-of-selection. *&---------------------------------------------------------------------* *& Form GET_DETAILS *&---------------------------------------------------------------------* * To get the data from th database table ZCUST_MASTER4 *----------------------------------------------------------------------* form get_details . select * from zcust_master4 into corresponding fields of table wt_cust. if sy-subrc = 0. sort wt_cust ascending by custid. endif. endform.

" GET_DETAILS

*&---------------------------------------------------------------------* *& Form FIELDCATATALOG *&---------------------------------------------------------------------* * Building Fieldcatlog for ALV *----------------------------------------------------------------------* form fieldcatatalog . data: ls_fcat type lvc_s_fcat. refresh: fieldcat. clear: ls_fcat. ls_fcat-reptext = 'Signal'. ls_fcat-fieldname = 'LIGHTS'. ls_fcat-ref_table = 'WT_CUST'. ls_fcat-outputlen = '20'. ls_fcat-col_pos = '1'. append ls_fcat to fieldcat. clear: ls_fcat.

ls_fcat-reptext = 'Customer Id'. ls_fcat-fieldname = 'CUSTID'. ls_fcat-ref_table = 'WT_CUST'. ls_fcat-outputlen = '10'. ls_fcat-fix_column = 'X'. ls_fcat-key = 'X'. ls_fcat-col_pos = '2'. append ls_fcat to fieldcat. clear: ls_fcat. ls_fcat-reptext = 'CustomerName '. ls_fcat-fieldname = 'CUSTNAME'. ls_fcat-ref_table = 'WT_CUST'. ls_fcat-outputlen = '30'. ls_fcat-fix_column = 'X'. ls_fcat-key = 'X'. ls_fcat-col_pos = '3'. append ls_fcat to fieldcat. clear: ls_fcat. ls_fcat-reptext = 'Address'. ls_fcat-fieldname = 'ADDRESS'. ls_fcat-ref_table = 'WT_CUST'. ls_fcat-outputlen = '40'. ls_fcat-col_pos = '4'. append ls_fcat to fieldcat. clear: ls_fcat. ls_fcat-reptext = 'City'. ls_fcat-fieldname = 'CITY'. ls_fcat-ref_table = 'WT_CUST'. ls_fcat-outputlen = '15'. ls_fcat-col_pos = '5'. append ls_fcat to fieldcat. clear: ls_fcat. ls_fcat-reptext = 'State'. ls_fcat-fieldname = 'STATE'. ls_fcat-ref_table = 'WT_CUST'. ls_fcat-outputlen = '15'. ls_fcat-col_pos = '6'. append ls_fcat to fieldcat. clear: ls_fcat. ls_fcat-reptext

= 'Country'.

ls_fcat-fieldname = 'COUNTRY'. ls_fcat-ref_table = 'WT_CUST'. ls_fcat-outputlen = '15'. ls_fcat-fix_column = 'X'. ls_fcat-key = 'X'. ls_fcat-col_pos = '7'. append ls_fcat to fieldcat. clear: ls_fcat. ls_fcat-reptext = 'Phone number'. ls_fcat-fieldname = 'PHNUM'. ls_fcat-ref_table = 'WT_CUST'. ls_fcat-outputlen = '14'. ls_fcat-fix_column = 'X'. ls_fcat-key = 'X'. ls_fcat-col_pos = '8'. append ls_fcat to fieldcat. clear: ls_fcat. ls_fcat-reptext = 'Email'. ls_fcat-fieldname = 'EMAIL'. ls_fcat-ref_table = 'WT_CUST'. ls_fcat-outputlen = '50'. ls_fcat-col_pos = '9'. append ls_fcat to fieldcat. clear: ls_fcat. ls_fcat-reptext = 'Fax'. ls_fcat-fieldname = 'FAX'. ls_fcat-ref_table = 'WT_CUST'. ls_fcat-outputlen = '15'. ls_fcat-col_pos = '10'. append ls_fcat to fieldcat. clear: ls_fcat. ls_fcat-reptext = 'Status'. ls_fcat-fieldname = 'STATUS'. ls_fcat-ref_table = 'WT_CUST'. ls_fcat-outputlen = '20'. ls_fcat-col_pos = '11'. append ls_fcat to fieldcat. endform. " FIELDCATATALOG *&---------------------------------------------------------------------* *& Form LAYOUT *&---------------------------------------------------------------------*

* Designing of ALV Layout *----------------------------------------------------------------------* form layout . ***If the customer's status is 'Inactive' the traffic signal will be 1 i.e, RED ***If the customer's status is 'Active' the traffic signal will be 3 i.e, GREEN loop at wt_cust into wa_cust. if wa_cust-status = 'INACTIVE'. wa_cust-lights = '1'. elseif wa_cust-status = 'ACTIVE'. wa_cust-lights = '3'. endif. modify wt_cust from wa_cust transporting lights. endloop. layout-excp_fname = 'LIGHTS'. endform.

" LAYOUT

ABAP code snippet to upload Excel file into an internal table & display it in alv format  

Added by Smita Gupta, last edited by Pavan Bhamidipati on Mar 11, 2009 (view change)

              

Following code snippet can be used to upload excel and generate uploaded data status results in a simple ALV List Display, which has the following features: Uploaded Data (Rows and Columns ) from Excel Sheet into an internal table Update Data into DB table. Updated Records Display into alv format Status Information along with each row(Inserted/Deleted/Updated) in alv display. *********Data Declaration**************** Tables: Z82426_GL_MAP. DATA:PROGNAME LIKE SY-REPID, DYNNUM LIKE SY-DYNNR. Data: FilePath TYPE LOCALFILE. DATA : IT_TAB TYPE standard TABLE OF ALSMEX_TABLINE , wa_tab type ALSMEX_TABLINE. *ALV data declarations DATA: GD_REPID LIKE SY-REPID. "Exists TYPE-POOLS: SLIS. "ALV Declarations DATA: FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,

                                             

GD_LAYOUT

TYPE SLIS_LAYOUT_ALV.

******For GL Mappin************************ DATA: Tmp_GLMAP_DATA type standard table of Z82426_GL_MAP, t_GLMAP type standard table of Z82426_GL_MAP, wa_GLMAP_DATA Type Z82426_GL_MAP. TYPES: BEGIN OF str_GLMAP_DATA, L_GL_ACC TYPE Z82426_GL_MAP-L_GL_ACC, DESC_LGL TYPE Z82426_GL_MAP-DESC_LGL, B_UNIT TYPE Z82426_GL_MAP-B_UNIT, SAKNR TYPE Z82426_GL_MAP-SAKNR, DEL_IND(1) TYPE C, MSG(50) TYPE C, END OF str_GLMAP_DATA. data: t_GLMAP_DATA TYPE STANDARD TABLE OF str_GLMAP_DATA, wa_GLMAP TYPE str_GLMAP_DATA. *********END Declaration**************** FORM EXCEL_UPLOAD_LGL_ACC_DATA . REFRESH IT_TAB. CLEAR IT_TAB. CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' EXPORTING filename = FILEPATH i_begin_col =1 i_begin_row =3 i_end_col =5 i_end_row =9 tables intern = IT_TAB * EXCEPTIONS * INCONSISTENT_PARAMETERS =1 * UPLOAD_OLE =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. SORT IT_TAB BY ROW COL. CLEAR wa_GLMAP. CLEAR wa_tab. IF IT_TAB[] IS NOT INITIAL. LOOP AT IT_TAB into wa_tab .

                                             

CASE wa_tab-COL. WHEN '0001'. wa_GLMAP-L_GL_ACC = wa_tab-VALUE. WHEN '0002'. wa_GLMAP-DESC_LGL = wa_tab-VALUE. WHEN '0003'. wa_GLMAP-B_UNIT = wa_tab-VALUE. WHEN '0004'. wa_GLMAP-SAKNR = wa_tab-VALUE. WHEN '0005'. wa_GLMAP-DEL_IND = wa_tab-VALUE. ENDCASE. AT END OF ROW. APPEND wa_GLMAP TO t_GLMAP_DATA. CLEAR wa_GLMAP. ENDAT. ENDLOOP. ELSE. LEAVE LIST-PROCESSING. ENDIF. IF t_GLMAP_DATA IS NOT INITIAL. LOOP AT t_GLMAP_DATA INTO wa_GLMAP. CLEAR wa_GLMAP_DATA. SELECT SINGLE * FROM Z82426_GL_MAP INTO wa_GLMAP_DATA WHERE L_GL_ACC = wa_GLMAP-L_GL_ACC. IF SY-SUBRC = 0. IF wa_GLMAP-DEL_IND = 'X'. DELETE FROM Z82426_GL_MAP WHERE L_GL_ACC = wa_GLMAP-L_GL_ACC. wa_GLMAP-MSG = 'Record Deleted successfully'. ELSE. UPDATE Z82426_GL_MAP SET DESC_LGL = wa_GLMAP-DESC_LGL B_UNIT = wa_GLMAP-B_UNIT SAKNR = wa_GLMAP-SAKNR WHERE L_GL_ACC = wa_GLMAP-L_GL_ACC. wa_GLMAP-MSG = 'Record Updated sucessfully'. ENDIF. ELSE. IF wa_GLMAP-DEL_IND = 'X'. wa_GLMAP-MSG = 'Record Not Found'. ELSE. wa_GLMAP_DATA-L_GL_ACC = wa_GLMAP-L_GL_ACC. wa_GLMAP_DATA-DESC_LGL = wa_GLMAP-DESC_LGL. wa_GLMAP_DATA-B_UNIT = wa_GLMAP-B_UNIT.

                                            

wa_GLMAP_DATA-SAKNR = wa_GLMAP-SAKNR. INSERT INTO Z82426_GL_MAP VALUES wa_GLMAP_DATA. wa_GLMAP-MSG = 'Record Inserted successfully'. ENDIF. ENDIF. MODIFY t_GLMAP_DATA FROM wa_GLMAP. ENDLOOP. ***************Use this line only if you are using Dialog programming********** LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0. SET PF-STATUS 'Z82426_PF_9010' excluding app_but_tab. SET TITLEBAR 'Z82426_TITLE'. ***************Ends********************************************************* *** REFRESH FIELDCATALOG. CLEAR FIELDCATALOG. FIELDCATALOG-FIELDNAME = 'L_GL_ACC'. FIELDCATALOG-SELTEXT_M = 'Legacy GL Acc'. FIELDCATALOG-COL_POS = 1. APPEND FIELDCATALOG. CLEAR FIELDCATALOG. FIELDCATALOG-FIELDNAME = 'DESC_LGL'. FIELDCATALOG-SELTEXT_M = 'Legacy GL Desc'. FIELDCATALOG-COL_POS = 2. APPEND FIELDCATALOG. CLEAR FIELDCATALOG. FIELDCATALOG-FIELDNAME = 'B_UNIT'. FIELDCATALOG-SELTEXT_M = 'Business Unit'. FIELDCATALOG-COL_POS = 3. APPEND FIELDCATALOG. CLEAR FIELDCATALOG. FIELDCATALOG-FIELDNAME = 'SAKNR'. FIELDCATALOG-SELTEXT_M = 'SAP GL Acc'. FIELDCATALOG-COL_POS = 4. APPEND FIELDCATALOG. CLEAR FIELDCATALOG. FIELDCATALOG-FIELDNAME = 'DEL_IND'. FIELDCATALOG-SELTEXT_M = 'Deletion Indicator'. FIELDCATALOG-COL_POS = 5. APPEND FIELDCATALOG. CLEAR FIELDCATALOG. FIELDCATALOG-FIELDNAME = 'MSG'. FIELDCATALOG-SELTEXT_M = 'Result Message'. FIELDCATALOG-COL_POS = 6. APPEND FIELDCATALOG. CLEAR FIELDCATALOG. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

                

EXPORTING I_CALLBACK_PROGRAM = SY-REPID * i_callback_top_of_page = ' ' * I_CALLBACK_PF_STATUS_SET = ' ' * I_CALLBACK_USER_COMMAND = ' ' * i_grid_title ='' IS_LAYOUT = GD_LAYOUT IT_FIELDCAT = FIELDCATALOG[] TABLES T_OUTTAB = t_GLMAP_DATA EXCEPTIONS PROGRAM_ERROR =1 OTHERS = 2. IF SY-SUBRC NE 0. WRITE:/ SY-SUBRC. ENDIF. ENDIF. ENDFORM.

Class & Methods used in the Report Class Name

Parent Class

Method

Descriptio n

CL_SALV_TABLE

FACTORY

To Create the Instance of ALV Table Object

CL_SALV_TABLE

CL_SALV_MODEL_LIST

GET_LAYOUT

Layout Object with Current Settings

CL_SALV_TABLE

GET_FUNCTIONS

Returns Object to Define the functions of the ALV Table

CL_SALV_TABLE

CL_SALV_MODEL_LIST

GET_DISPLAY_SETTINGS

Returns Global Settings for ALV Display

CL_SALV_TABLE

GET_AGGREGATIONS

Return Object to Edit Aggregatio n Functions Settings

CL_SALV_TABLE

GET_SORTS

Return Object to Set all Sort Information

CL_SALV_TABLE

GET_SELECTIONS

Return Object to do Settings for Selection pattern for Row(s) and Column(s)

CL_SALV_TABLE

CL_SALV_MODEL_BASE

SET_TOP_OF_LIST

Set the Contents in Top of List in ALV Display

CL_SALV_TABLE

GET_EVENT

Return the Object to manage existing events

CL_SALV_TABLE

GET_COLUMNS

Return individual column objects of Output table

CL_SALV_LAYOUT

SET_KEY

Set Layout Key for Layouts in Report

CL_SALV_LAYOUT

GET_LAYOUTS

Returns all layouts defined for the report

CL_SALV_LAYOUT

F4_LAYOUTS

F4 Help to Display Existing Layouts of the Report

CL_SALV_LAYOUT

SET_SAVE_RESTRICTION

Restriction Methods while saving the Layout

CL_SALV_LAYOUT

SET_DEFAULT

Activate the Default Layout

CL_SALV_LAYOUT

SET_INITIAL_LAYOUT

Set specific Layout as Initial layout while starting ALV Display

CL_SALV_FUNCTIONS_LIST

CL_SALV_FUNCTIONS

SET_ALL

Activate all Internal Functions of ALV

CL_SALV_DISPLAY_SETTINGS

SET_STRIPPED_PATTERN

Set ALV Display in Stripped Pattern

CL_SALV_DISPLAY_SETTINGS

SET_LIST_HEADER

Set Title of

the ALV Display

CL_SALV_SORTS

ADD_SORT

Define Sort for a Specific Column

CL_SALV_SELECTIONS

SET_SELECTION_MODE

Set the Selection Methods

CL_SALV_AGGREGATIONS

ADD_AGGREGATION

Add Aggregatio n function of a Table column

CL_SALV_FORM_LAYOUT_GR

CREATE_HEADER_INFORMATI

Create

ID

ON

Header Information in the Cell

CL_SALV_FORM_LAYOUT_GR

CL_SALV_FORM_UIE_LAYOUT_GR

ID

ID

ADD_ROW

Add New row in the Grid

CL_SALV_FORM_LAYOUT_GR

CREATE_LABEL

ID

Create Label in Grid Cell

CL_SALV_FORM_LAYOUT_GR

CREATE_TEXT

ID

CL_SALV_FORM_LABEL

Create Text in Grid Cell

CL_SALV_FORM_UIE_TEXT_VIEW

SET_TEXT

Assign Text to the Label in Grid Cell

CL_SALV_COLUMNS_TABLE

CL_SALV_COLUMNS

GET

Get the list of Columns of output table

CL_SALV_COLUMNS_TABLE

CL_SALV_COLUMNS

SET_OPTIMIZE

Optimize the width of

columns

CL_SALV_COLUMNS_TABLE

CL_SALV_COLUMNS

SET_KEY_FIXATION

Fix the Key columns while Vertical Scrolling

CL_SALV_COLUMNS_TABLE

CL_SALV_COLUMNS_LIST

SET_COLOR_COLUMN

Assign colors to the columns in output table

CL_SALV_COLUMNS_TABLE

CL_SALV_COLUMNS

GET_COLUMN

Get Properties of Single Column

CL_SALV_COLUMN_TABLE

CL_SALV_COLUMN

GET_DDIC_DATATYPE

Get data type of Selected column

CL_SALV_COLUMN_TABLE

CL_SALV_COLUMN

SET_TECHNICAL

Set column as Technical (Invisible)

CL_SALV_COLUMN_TABLE

CL_SALV_COLUMN

GET_DDIC_INITTYPE

Returns Internal ABAP Data Type

CL_SALV_COLUMN_TABLE

CL_SALV_COLUMN

GET_DDIC_DOMAIN

Get the Domain Name of Column

CL_SALV_COLUMN_TABLE

CL_SALV_COLUMN_LIST

SET_CELL_TYPE

Set Cell type of Column

CL_SALV_COLUMN_TABLE

CL_SALV_COLUMN_LIST

SET_COLOR

Set the color of

Single Column

CL_SALV_COLUMN_TABLE

CL_SALV_COLUMN_LIST

SET_KEY

Set the column as Key column

Sample Code

001. 002.*&---------------------------------------------------------------------* 003.*& Report

ZVK_CL_SALV

004.*&---------------------------------------------------------------------* 005.*&Report using OOPs with Basic functionalities. 006.*&---------------------------------------------------------------------* 007. 008.REPORT

zvk_cl_salv_1.

009.TABLES : vbak. 010.TYPE-POOLS : abap,rsanm. 011. 012.TYPES : BEGIN OF t_vbak. 013.INCLUDE TYPE vbak. 014.TYPES : t_color TYPE lvc_t_scol, 015.END OF t_vbak. 016. 017.DATA : lt_vbak TYPE STANDARD TABLE OF t_vbak, 018.ls_vbak TYPE t_vbak. 019. 020.FIELD-SYMBOLS : 021.

TYPE t_vbak.

022.DATA : l_rec(5)

TYPE n.

023. 024.** Declaration for ALV Grid ** 025.DATA : gr_table TYPE REF TO cl_salv_table. 026. 027.** Declarations for ALV Functions 028.DATA : gr_functions TYPE REF TO cl_salv_functions_list. 029. 030.** declaration for ALV Columns 031.DATA : gr_columns TYPE REF TO cl_salv_columns_table, 032.gr_column

TYPE REF TO cl_salv_column_table,

033.lt_column_ref TYPE salv_t_column_ref, 034.ls_column_ref TYPE salv_s_column_ref. 035. 036.** declaration for Layout Settings 037.DATA : gr_layout TYPE REF TO cl_salv_layout, 038.gr_layout_key TYPE salv_s_layout_key, 039.ls_layout TYPE salv_s_layout, 040.lt_layout_info TYPE salv_t_layout_info. 041. 042.** Declaration for Global Display Settings 043.DATA : gr_display TYPE REF TO cl_salv_display_settings, 044.lv_title

TYPE lvc_title.

045. 046.** Declaration for Aggregate Function Settings 047.DATA : gr_aggr

TYPE REF TO cl_salv_aggregations.

048. 049.** Declaration for Sort Function Settings

050.DATA : gr_sort

TYPE REF TO cl_salv_sorts.

051. 052.** Declaration for Table Selection settings 053.DATA : gr_select

TYPE REF TO cl_salv_selections.

054. 055.** Declaration for Top of List settings 056.DATA : gr_content TYPE REF TO cl_salv_form_element. 057. 058.** Class for handling Events 059.CLASS : lcl_handle_events DEFINITION DEFERRED. 060.DATA

: gr_events TYPE REF TO lcl_handle_events,

061.lr_events TYPE REF TO cl_salv_events_table. 062. 063.** Coloring of Date columns ** 064.DATA : lt_colo TYPE STANDARD TABLE OF lvc_s_colo, 065.ls_colo TYPE lvc_s_colo. 066. 067.** Color Structure of columns ** 068.DATA : lt_color TYPE lvc_t_scol, 069.ls_color TYPE lvc_s_scol. 070.*----------------------------------------------------------------------* 071.*

CLASS lcl_handle_events DEFINITION

072.*----------------------------------------------------------------------* 073.CLASS lcl_handle_events DEFINITION. 074.PUBLIC SECTION. 075.METHODS : on_double_click FOR EVENT double_click OF cl_salv_events_table 076.IMPORTING row column. 077.METHODS : on_link_click FOR EVENT link_click OF cl_salv_events_table

078.IMPORTING row column. 079.ENDCLASS.

"lcl_handle_events DEFINITION

080.*----------------------------------------------------------------------* 081.*

CLASS lcl_handle_events IMPLEMENTATION

082.*----------------------------------------------------------------------* 083.CLASS lcl_handle_events IMPLEMENTATION. 084.METHOD on_double_click. 085.PERFORM get_ord_info USING row column. 086.ENDMETHOD.

"on_double_click

087.METHOD on_link_click. 088.PERFORM get_ord_info USING row column. 089.ENDMETHOD.

"on_link_click

090.ENDCLASS.

"lcl_handle_events IMPLEMENTATION

091.SELECTION-SCREEN BEGIN OF BLOCK b1. 092.SELECT-OPTIONS : p_erdat FOR vbak-erdat. 093.PARAMETER : p_var TYPE slis_vari. 094.SELECTION-SCREEN END OF BLOCK b1. 095. 096.AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_var. 097.CLEAR : ls_layout. 098.TRY. 099.CALL METHOD cl_salv_table=>factory 100.EXPORTING 101.list_display = if_salv_c_bool_sap=>false 102.IMPORTING 103.r_salv_table = gr_table 104.CHANGING 105.t_table

= lt_vbak.

106.CATCH cx_salv_msg . 107.ENDTRY. 108. 109.IF gr_table IS NOT INITIAL. 110.MOVE sy-repid TO gr_layout_key-report.

"Set Layout Key as Report ID"

111.gr_layout = gr_table->get_layout( ).

"Get Layout of the Table"

112.gr_layout->set_key( gr_layout_key ).

"Set Layout key to Layout"

113.lt_layout_info = gr_layout->get_layouts( )."Get the Layouts of report" 114.IF lt_layout_info[] IS NOT INITIAL. 115.ls_layout = gr_layout->f4_layouts( ).

"Activate F4 Help for Layouts"

116.IF ls_layout IS NOT INITIAL. 117.MOVE ls_layout-layout TO p_var. 118.ENDIF. 119.ENDIF. 120.ENDIF. 121. 122.START-OF-SELECTION. 123.REFRESH : lt_vbak. 124.SELECT * FROM vbak 125.INTO CORRESPONDING FIELDS OF TABLE lt_vbak 126.WHERE erdat IN p_erdat. 127. 128. 129.IF sy-subrc EQ 0. 130.DESCRIBE TABLE lt_vbak LINES l_rec. 131.PERFORM set_color. 132.PERFORM alv_grid_display. 133.ENDIF.

134. 135.*&---------------------------------------------------------------------* 136.*&

Form

alv_grid_display

137.*&---------------------------------------------------------------------* 138.*

text

139.*----------------------------------------------------------------------* 140.FORM alv_grid_display. 141.CLEAR : gr_table. 142.TRY. 143.CALL METHOD cl_salv_table=>factory 144.EXPORTING 145.list_display = if_salv_c_bool_sap=>false 146.IMPORTING 147.r_salv_table = gr_table 148.CHANGING 149.t_table

= lt_vbak.

150.CATCH cx_salv_msg . 151.ENDTRY. 152.IF gr_table IS INITIAL. 153.MESSAGE 'Error Creating ALV Grid ' TYPE 'I' DISPLAY LIKE 'E'. 154.STOP. 155.ENDIF. 156.** Get functions details 157.gr_functions = gr_table->get_functions( ). 158. 159.** Activate All Buttons in Tool Bar 160.gr_functions->set_all( if_salv_c_bool_sap=>true ). 161.

162.******* Layout Settings

*******

163.CLEAR : gr_layout, gr_layout_key. 164.MOVE sy-repid TO gr_layout_keyreport. "Set Report ID as Layout Key" 165. 166.gr_layout = gr_table>get_layout( ).

"Get Layout of Table"

167.gr_layout>set_key( gr_layout_key ).

"Set Report Id to Layout"

168.gr_layout>set_save_restriction( if_salv_c_layout=>restrict_none ). "No Restriction to Save Layout" 169.IF p_var IS INITIAL. 170.gr_layout>set_default( if_salv_c_bool_sap=>true ).

"Set Default Variant"

171.ELSE. 172.gr_layout>set_initial_layout( p_var ). s Initial"

"Set the Selected Variant a

173.ENDIF. 174. 175.******* Global Display Settings

*******

176.CLEAR : gr_display. 177.MOVE 'Sales Order Details' TO lv_title. 178.gr_display = gr_table>get_display_settings( ).

" Global Display settings"

179.gr_display>set_striped_pattern( if_salv_c_bool_sap=>true ).

"Activate Strip Pattern"

180.gr_display>set_list_header( lv_title ).

"Report Header"

181. 182.******* Aggregate Function Settings ******* 183.gr_aggr = gr_table>get_aggregations( ).

"Get Aggregate Functions"

184. 185.******* Sort Functions ******* 186.gr_sort = gr_table->get_sorts( ). 187.IF gr_sort IS NOT INITIAL. 188.TRY. 189.gr_sort->add_sort( columnname = 'ERNAM' 190.position = 1 191.sequence

= if_salv_c_sort=>sort_up

192.subtotal

= if_salv_c_bool_sap=>true

193.group

= if_salv_c_sort=>group_none

194.obligatory = if_salv_c_bool_sap=>false ). 195.CATCH cx_salv_not_found . 196.CATCH cx_salv_existing . 197.CATCH cx_salv_data_error . 198.ENDTRY. 199. 200.TRY. 201.gr_sort->add_sort( columnname = 'ERDAT' 202.position = 2 203.sequence

= if_salv_c_sort=>sort_down

204.subtotal

= if_salv_c_bool_sap=>false

205.group

= if_salv_c_sort=>group_none

206.obligatory = if_salv_c_bool_sap=>false ). 207.CATCH cx_salv_not_found . 208.CATCH cx_salv_existing . 209.CATCH cx_salv_data_error . 210.ENDTRY. 211.ENDIF.

212.******* Table Selection Settings ******* 213.gr_select = gr_table->get_selections( ). 214.IF gr_select IS NOT INITIAL. 215.gr_select>set_selection_mode( if_salv_c_selection_mode=>row_column ). "Allow single ro w Selection" 216.ENDIF. 217. 218.******* Top of List settings ******* 219.PERFORM top_of_page CHANGING gr_content. 220.gr_table->set_top_of_list( gr_content ). 221. 222.******* Event Register settings ******* 223.lr_events = gr_table->get_event( ). 224.CREATE OBJECT gr_events. 225.SET HANDLER gr_events->on_double_click FOR lr_events. 226.SET HANDLER gr_events->on_link_click FOR lr_events. 227. 228.** Get the columns from ALV Table 229.gr_columns = gr_table->get_columns( ). 230.IF gr_columns IS NOT INITIAL. 231.REFRESH : lt_column_ref. 232.CLEAR

: ls_column_ref.

233.lt_column_ref = gr_columns->get( ). 234. 235.** Get columns properties 236.gr_columns->set_optimize( if_salv_c_bool_sap=>true ). 237.gr_columns->set_key_fixation( if_salv_c_bool_sap=>true ). 238.TRY.

239.gr_columns->set_color_column( 'T_COLOR' ). 240.CATCH cx_salv_data_error . 241.ENDTRY. 242.** Individual Column Properties. 243.PERFORM column_settings. 244.ENDIF. 245.CALL METHOD gr_table->display. 246.ENDFORM.

"alv_grid_display

247. 248.*&---------------------------------------------------------------------* 249.*&

Form

column_settings

250.*&---------------------------------------------------------------------* 251.*

text

252.*----------------------------------------------------------------------* 253.FORM column_settings. 254.LOOP AT lt_column_ref INTO ls_column_ref. 255.TRY. 256.gr_column ?= gr_columns->get_column( ls_column_ref-columnname ). 257.CATCH cx_salv_not_found. 258.ENDTRY. 259.IF gr_column IS NOT INITIAL. 260.** Make Mandt column invisible ** 261.IF gr_column->get_ddic_datatype( ) = 'CLNT'. 262.gr_column->set_technical( if_salv_c_bool_sap=>true ). 263.ENDIF. 264.** Create Aggregate function total for All Numeric/Currency Fields ** 265.IF gr_column->get_ddic_inttype( ) EQ 'P' OR 266.gr_column->get_ddic_datatype( ) EQ 'CURR'.

267.IF gr_aggr IS NOT INITIAL. 268.TRY. 269.gr_aggr->add_aggregation( columnname = ls_column_ref-columnname 270.aggregation = if_salv_c_aggregation=>total ). 271.CATCH cx_salv_data_error . 272.CATCH cx_salv_not_found . 273.CATCH cx_salv_existing . 274.ENDTRY. 275.ENDIF. 276.ENDIF. 277.** Create Check box for fields with domain "XFELD" 278.IF gr_column->get_ddic_domain( ) EQ 'XFELD'. 279.gr_column->set_cell_type( if_salv_c_cell_type=>checkbox ). 280.ENDIF. 281. 282.** Set color to Date Columns ** 283.IF gr_column->get_ddic_datatype( ) EQ 'DATS'. 284.CLEAR : ls_colo. 285.MOVE 2 TO ls_colo-col. 286.MOVE 1 TO ls_colo-int. 287.MOVE 1 TO ls_colo-inv. 288.gr_column->set_color( ls_colo ). 289.ENDIF. 290. 291.** Add Hotspot&Hyper Link to the column vbeln 292.IF ls_column_ref-columnname EQ 'VBELN'. 293.gr_column->set_cell_type( if_salv_c_cell_type=>hotspot ). 294.gr_column->set_key( if_salv_c_bool_sap=>true ).

295.ENDIF. 296. 297.ENDIF. 298.ENDLOOP. 299.ENDFORM.

"column_settings

300. 301.*&---------------------------------------------------------------------* 302.*&

Form

top_of_page

303.*&---------------------------------------------------------------------* 304.FORM top_of_page CHANGING lr_content TYPE REF TO cl_salv_form_element. 305.DATA : lr_grid TYPE REF TO cl_salv_form_layout_grid, 306.lr_text

TYPE REF TO cl_salv_form_text,

307.lr_label TYPE REF TO cl_salv_form_label, 308.lr_head

TYPE string.

309. 310.MOVE 'Sales Order List' TO lr_head. 311.CREATE OBJECT lr_grid. 312.** Header of Top of Page ** 313.lr_grid->create_header_information( row 314.column

= 1

315.text

= lr_head

316.tooltip = lr_head ). 317.** Add Row ** 318.lr_grid->add_row( ). 319. 320.** Add Label in Grid ** 321.lr_label = lr_grid->create_label( row = 2 322.column = 1

= 1

323.text = 'No of Records' 324.tooltip = 'No of Records' ). 325. 326.** Add Text in The Grid ** 327.lr_text = lr_grid->create_text( row = 2 328.column = 2 329.text = l_rec 330.tooltip = l_rec ). 331.** Set Label and Text Link ** 332.lr_label->set_text( lr_text ). 333. 334.** Move lr_grid to lr_content ** 335.lr_content = lr_grid. 336.ENDFORM.

"top_of_page

337. 338.*&---------------------------------------------------------------------* 339.*&

Form

340.*&---------------------------------------------------------------------* 341.FORM get_ord_info USING row TYPE salv_de_row 342.column TYPE salv_de_column. 343.IF column EQ 'VBELN'. 344.CLEAR : ls_vbak. 345.READ TABLE lt_vbak INTO ls_vbak INDEX row. 346.IF sy-subrc EQ 0. 347.SET PARAMETER ID 'AUN' FIELD ls_vbak-vbeln. 348.CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN. 349.ENDIF. 350.ENDIF.

351.ENDFORM.

"get_ord_info

352. 353.*&---------------------------------------------------------------------* 354.*&

Form

set_color

355.*&---------------------------------------------------------------------* 356.* Set color to the column VBELN & NETWR for Order Value > 1000 357.*----------------------------------------------------------------------* 358.FORM set_color. 359.LOOP AT lt_vbak ASSIGNING . 360.IF -netwr GT 1000. 361.REFRESH : lt_color. 362. 363.CLEAR : ls_color. 364.MOVE 'VBELN' TO ls_color-fname. 365.MOVE 3

TO ls_color-color-col.

366.MOVE 0

TO ls_color-color-int.

367.MOVE 0

TO ls_color-color-inv.

368.APPEND ls_color TO lt_color. 369. 370.CLEAR : ls_color. 371.MOVE 'NETWR' TO ls_color-fname. 372.MOVE 3

TO ls_color-color-col.

373.MOVE 0

TO ls_color-color-int.

374.MOVE 0

TO ls_color-color-inv.

375.APPEND ls_color TO lt_color. 376. 377.MOVE lt_color TO -t_color. 378.ENDIF.

379.ENDLOOP. 380.ENDFORM.

"set_color

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF