How to process Line Selection on ALV Table in ABAP WebDynpro

Hi there,
I have a view with an ALV table whose context node retrieves its data from a Service Call for a method.
The method provides certain data of a database table which the ALV displays.
Now I would like to be able to select one row of that ALV table and after pressing a button or doubleclicking on the row or whatever a different view (as for me it is also ok on the same view) should appear to display the details of that selection.
I only need to know how to retrieve the selected data.
Or its index within the internal table.
I am already looking for hours for a useful thread and actually there is one which obviously is about a similar issue apart from the multiple selection part: 
How to process multiple row selection in ALV table in Wendynpro ABAP? Help!
but i am afraid that i don't understand it. Or at least I misunderstand it since it does not work with me.
The system example mentioned in the thread does not help me either because it somehow does not correspond to my needs, does it?
It would be GREAT if somebody could help me with that. Please keep it simple for I am not an expert in webdynpro yet (obviously ^^) and also please explain in detail what I have to do with the context nodes since I am not sure whether the selection is stored in my already existing node or whether I need a special one for that.
Thanks!!
christina

Hi Christina,
If you just want to get one column data of the line that user clicked, use the Web Dynpro Code Wizard to Read Context of attibute you needed, then you will get code as follow:
* Define data for read attribute
    node_alv TYPE REF TO if_wd_context_node,
    elem_alv TYPE REF TO if_wd_context_element,
    stru_alv TYPE if_view_display=>element_alv ,
    item_column_name  LIKE stru_alv-column_name.
* navigate from <CONTEXT> to <ALV> via lead selection
  node_alv = wd_context->get_child_node( name = if_view_display=>wdctx_alv ).
* get element via lead selection
  elem_alv = node_alv->get_element(  ).
* get single attribute
  elem_alv->get_attribute(
    EXPORTING
      name =  `COLUMN_NAME'
    IMPORTING
      value = item_column_name ).
The value of column_name is stored in item_column_name.
If you need the index that the user clicked, try this:
* Definition of field symbol for index
  FIELD-SYMBOLS : <fs_index> TYPE data.
* Get the selected index
  ASSIGN r_param->index->* TO <fs_index>.
The index of clicked line is stored in field symbol <fs_index>.
Hope it will help.
Best Regards,
Stephanie

Similar Messages

  • How to implement line selectability for a table control using table Wizard?

    Hello SDN Community,
    I have created a table control using the Table Wizard.  I found my exact question in this forum, but unfortunately it had not been andsered.  While I cannot paste a screen-print into this plane-text area, here are the steps I followed...
    1) SE51
    2) Create new screen 0100
    3) Click Layout button
    4) Clidk Table Control (with Wizard) and draw box on canvas.
    5) Step is "Start" - click Continue
    6) Step is "Name of Table Control" - provided name
    7) Step is "Table Name" - provided name of dictionary table (AUFK)
    8) Step is "Definition of Columns" - selected order numver and order text
    9) Step is "Table Control Attributes" - Line Selectability is in display mode - cannot set it.
    I would like to have a selectability column for my table.  Would appreciate any insight into how to do this.
    Thank you,
    Dean Atteberry.

    This is a puzzling...
    For the table control wizard, in the Table Control Attributes step, I was able to get line selectability to open up by declaring a char01 data element at the beginning of my type.
    The puzzling is in regards to the "Selection col. fld" entry field.
    If I leave it blank and try to go to the next step, I get message "Enter the name of the selection column if you are using a program table"
    So it looked like it wanted to know the name of my selection column.  So I type in "CHAR1".  and got the message "The field "CHAR1" for the selection column is already contained in the table."
    Hmmmmm.... don't understand............
    Dean Atteberry.

  • Merge of Cells in ALV table in ABAP webdynpro.

    Hi All,
    We have a requirement to merge cells vertically if the consecutive cells have same data.(The merge of cells happens when we click on sort of a column.) This functionality needs to be achived with out sorting the cells.Sorted data is populated in the ALV table.
    I will be greatfull if any one can help us on this issue.
    Thanks in advance
    Regards,
    Sharath

    Hi Sarath,
    Check this..
    http://help.sap.com/saphelp_nw70ehp2/helpdata/en/9b/46bb0d339b42cc8d30636ca0c9f5b6/frameset.htm
    and go through this..
    merging cells in table
    http://forums.sdn.sap.com/click.jspa?searchID=71460300&messageID=9768692
    cheers,
    Kris.
    Edited by: kissnas on Apr 18, 2011 12:10 PM

  • How to keep lead selections in alv table...

    Hi experts.
    I made a alv.
    A logic  in wdmodifyview is following..
    METHOD wddomodifyview .
      IF first_time EQ abap_true.
        wd_comp_controller->set_alv_config( ).
      ENDIF.
      wd_this->set_maktx( ).  "<- for displaying maktx
    ENDMETHOD.
    When I want to select a line, do not selected.
    I know because of "wd_this->set_maktx( )." sentence.
    But I want to select multi lines in above condition...
    How to keep selected lines in alv?
    Help me please.
    Thanks.
    Regards.

    What logic is taking place in wd_this->set_maktx( )?  It is pretty difficult to say what is causing the issue without knowing what code you are executing?  If you are resetting the context bound to the ALV, that would explain why you are losing your selections.

  • At Line-selection in ALV for more than one field.

    How to use At Line-selection in ALV Basic Report where there are more than one field for displaying Secondary Lists.
    Ex: In Basic List there are 3 fields Volume_m Volume_y and Volume_i.When i click on any of the field i need to display the secondary list for that particular field.

    Hi Pavan,
                  Use User-command event of ALV.
    Refer this code :
    form BUILD_EVENTCAT  using    p_i_eventcat TYPE SLIS_T_EVENT.
    DATA: I_EVENT TYPE SLIS_ALV_EVENT.
    CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
       I_LIST_TYPE           = 0
    IMPORTING
       ET_EVENTS             = P_I_EVENTCAT
    EXCEPTIONS
      LIST_TYPE_WRONG       = 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.
      clear I_event.
      read table p_i_eventcat with key name = slis_ev_user_command into I_event.
      if sy-subrc = 0.
        move 'USER_COMMAND' to I_event-form.
        append I_event to p_i_eventcat.
      endif.
    form USER_COMMAND' using p_ucomm type sy-ucomm
                               p_selfield type slis_selfield.
      case p_ucomm.
      WHEN '&IC1'.                       "&IC1 is the Fcode for double click
    Use  P_ELFIELD-VALUE  for further processing . this  will contain the value on which u will double click
    endcase.
    Reward points if helpful.
    Regards,
    Hemant

  • AT line selection in ALV

    Hi Experts,
    How to apply the below logic in ALV. ( how to apply at line selection in ALV )
    AT LINE-SELECTION.
      DATA NO TYPE I.
      DATA F(16).
      DATA G(16).
      CASE SY-LSIND.
        WHEN 1.
          GET CURSOR FIELD F.
          IF F EQ 'IT_FIRST-MATNR'.
            PERFORM DRILL_DOWN.
          ENDIF.
      ENDCASE.
    FORM DRILL_DOWN.
    LOOP AT IT_EBAN WHERE MATNR = IT_FIRST-MATNR
                        AND WERKS = IT_FIRST-WERKS.
    WRITE: /2 IT_EBAN-BANFN,
               15 IT_EBAN-FKZTX,
               35 IT_EBAN-MENGE,
               55 IT_EBAN-MEINS.
      ENDLOOP.
    ENDFORM.

    Hi,
    When an Interactive Report is needed in Classical Display, we go for AT LINE-SELECTION. But when the same is needed in ALV Display, this method won't work. Instead, we need to use other way which is explained below:
    We use REUSE_ALV_GRID_DISPLAY for ALV Display. Now, normally we call that FM in the following way:
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    i_callback_program = 'PROGRAM_NAME'
    it_fieldcat = tb_fieldcat
    TABLES
    t_outtab = tb_output.
    When it is needed to get an Interactive ALV, call the same FM in the following manner:
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    i_callback_program = 'ZTEST75599_1'
    it_fieldcat = tb_fieldcat
    i_callback_user_command = 'USER_COMMAND'
    TABLES
    t_outtab = tb_output.
    Now, in the report, create a subroutine with the name USER_COMMAND as follows:
    FORM user_command USING p_ucomm LIKE sy-ucomm
    p_selfield TYPE slis_selfield.
    CASE p_ucomm.
    WHEN '&IC1'. " &IC1 - SAP standard code for double-clicking
    Based on the requirement, write the logic *
    ENDCASE.
    ENDFORM.
    No need to call the subroutine as PERFORM user_command. This will be takane care by REUSE_ALV_GRID_DISPLAY. We need to just write the subroutine in the report. That suffices.
    Some more useful points for Interactive ALV:
    1. If Hotspot is needed, then that should be done by declaring hotspot (one field in slis_t_fieldcat_alv) as 'X' in tb_fieldcat which is of type slis_t_fieldcat_alv. When hotspot is active, single click will be enough or else you should double click on the output data.
    2. In Classical Display, when it is needed to read the record on which we double clicked, we do that in following way:
    AT LINE-SELECTION.
    GET CURSOR LINE wf_line. " wf_line gives the line number on which it has been clicked
    READ LINE wf_line OF CURRENT PAGE.
    But this won't work for ALV. Instead, the following logic can be used:
    FORM user_command USING p_ucomm LIKE sy-ucomm
    p_selfield TYPE slis_selfield.
    CASE p_ucomm.
    WHEN '&IC1'. " &IC1 - SAP standard code for double-clicking
    READ TABLE tb_output INTO wa_output INDEX p_selfield-tabindex.
    IF sy-subrc EQ 0.
    Based on the requirement, write the logic *
    ENDIF.
    ENDCASE.
    ENDFORM.
    Hope this helps you...

  • CL_GUI_ALV_GRID: Line selection and backend table

    Dear community,
    is there a way to propagate line selection of ALV GRID GUI automagically to the backend data table?
    This is my scenario:
    1) A table containing several records with one column 'SELECTED' for selection status
    2) ALV_GRID to display the table with layout info for line selection
    alv_layo-sel_mode   = 'A'.
    alv_layo-box_fname  = 'SELECTED'.
    3) At PBO methods set_table_for_first_display and refresh_table_display are called with the table containing some records marked as 'SELECTED'.
    First problem here: 'SELECTED' entries are not propagated to the ALV grid (the lines in the GUI are not marked). I know I could use set_selected_rows to force the selection, but is this really necessary?
    4) Then, at PAI method check_changed_data is called (and yes, event mc_evt_modified is registered).
    Second problem: Changes in selection are not propagated automagically to the underlying table. I also know I could use get_selected_rows to force this update manually, but again: is this really necessary?
    Can anyone explain the behavior why sorting etc. is propagated automatically to the underlying table, but not the selection of rows? Am I missing something?
    Hint: Removing box_fname = 'SELECTED' and setting the fieldcatalog to display the column 'SELECTED' as editable checkbox works also. But our users are familiar with the rowmark, so this is no option.
    Any suggestions are welcome.
    Thanks,
    Torsten.
    Here an (almost) complete listing of the code:
    PROCESS BEFORE OUTPUT.
      MODULE SET_STATUS_TITLE_0100.
      MODULE INIT_ALV_GRID_0100.
      MODULE DISPLAY_DATA_0100.
      MODULE SET_GRID_SELECTION_0100.
    PROCESS AFTER INPUT.
      MODULE EXIT_COMMAND_0100 AT EXIT-COMMAND.
      MODULE UPDATE_TABLE_DATA_0100.
      MODULE USER_COMMAND_0100.
    MODULE init_alv_grid_0100 OUTPUT.
      IF NOT gr_container IS BOUND.
    *   Container erzeugen
        CREATE OBJECT gr_container ...
    *   ALV Grid erstellen
        CREATE OBJECT gr_alv_grid ...
    *   ALV für die erste Anzeige vorbereiten
        gs_alv_layo-zebra      = on.         " Gestreifte Anzeige
        gs_alv_layo-no_toolbar = on.         " Keine Toolbar
        gs_alv_layo-no_rowmark = off.        " Keine Zeilenmarkierung
        gs_alv_layo-edit       = off.        " Editieren ermöglichen
        gs_alv_layo-sel_mode   = 'A'.        " Selektionsmodus
        gs_alv_layo-cwidth_opt = off.        " Optimierte Spaltenbreite!
        gs_alv_layo-info_fname = 'LCOLOR'.   " ALV-Control: Feldname mit
                                             " einfacher Farbcodierung für
                                             " Zeile
        gs_alv_layo-ctab_fname = 'CCOLOR'.   " ALV-Control: Feldname mit
                                             " komplexer Farbcodierung
                                             " für Zellen
        gs_alv_layo-box_fname  = 'SELECTED'. " Markierte Zeilen
    *   Feldkatalog für die Anzeige vorbereiten
    *    CLEAR gs_fcat.                       " Mehrfachsel. ermöglichen
    *    gs_fcat-fieldname = 'SELECTED'.      " Dazu muss das Feld für die
    *    gs_fcat-edit      = on.              " Selektion editierbar sein.
    *    gs_fcat-checkbox  = on.              " Ausserdem muss die
    **   gs_fcat-outputlen = '3'.             " Zeilenmark. eingeschaltet
    *    APPEND gs_fcat TO gt_fcat.           " und box_fname gesetzt sein.
    *   Ereignisbehandlung
        SET HANDLER
          lcl_event_handler=>on_click
          lcl_event_handler=>on_hotspot
          lcl_event_handler=>on_double_click
          lcl_event_handler=>on_user_command
          lcl_event_handler=>on_data_changed
        FOR gr_alv_grid.
        CALL METHOD gr_alv_grid->register_edit_event
          EXPORTING
            i_event_id = cl_gui_alv_grid=>mc_evt_modified
          EXCEPTIONS
            error      = 1
            OTHERS     = 2.
      ENDIF.
    ENDMODULE.                 " INIT_ALV_GRID_0100  OUTPUT
    MODULE display_data_0100 OUTPUT.
    * PBO Modul für alle weiteren Anzeigezyklen.
      IF gr_alv_grid IS BOUND.
        CALL METHOD gr_alv_grid->set_table_for_first_display ...
      ENDIF.
    ENDMODULE.                 " DISPLAY_DATA_0100  OUTPUT
    MODULE set_grid_selection_0100 OUTPUT.
      IF gr_alv_grid IS BOUND.
        CALL METHOD gr_alv_grid->refresh_table_display.
      ENDIF.
    * Alterative: Set selected rows manually
    *    CALL METHOD gr_alv_grid->set_selected_rows
    ENDMODULE.                 " SET_GRID_SELECTION_0100 OUTPUT
    MODULE update_table_data_0100 INPUT.
        CALL METHOD gr_alv_grid->check_changed_data.
    * Alternative: Get selected rows and update table manually
    *    CALL METHOD gr_alv_grid->get_selected_rows ...
    ENDMODULE.                 " UPDATE_TABLE_DATA_0100  INPUT

    Hello Torsten
    I may be wrong but I think the field LVC_S_LAYO-BOX_FNAME is a relict from the stone-age SLIS-based ALV programming.
    Using modern OO-based ALV we do not need any kind of "MARK" row but we have the appropriate methods available.
    Regards
      Uwe

  • How to include tool bar in alv table?

    Dear All,
        I want to know how to use tool bar in alv table? Is there any seperate interfaces available for it?
    Thanks,
    Gopi.

    Hi,
    1.To deactivate the Standard buttons:
    Data: lr_config_table TYPE REF TO cl_salv_wd_config_table,
    lo_value = lo_interfacecontroller->get_model( ).
    lr_config_table ?= lo_value .
    Wd_this->lr_config_table  ?= lo_value .
      lr_config_table->if_salv_wd_std_functions~set_edit_append_row_allowed( abap_false ).
      lr_config_table->if_salv_wd_std_functions~set_edit_insert_row_allowed( abap_false ).
      lr_config_table->if_salv_wd_std_functions~set_edit_delete_row_allowed( abap_false ).
    2.To create the customized buttons:
    Create the a method initilaze_buttons.
    Data:lv_function_add_record_sap          TYPE REF TO cl_salv_wd_function,
          lv_button_add_record_sap             TYPE REF TO cl_salv_wd_fe_button,
           R_ALV_TABLE_COMP  type ref to CL_SALV_WD_CONFIG_TABLE.
    r_alv_table_comp = wd_this->lr_config_table.
    Generate Function Objects
    lv_function_add_record_sap = wd_this->lr_config_table->if_salv_wd_function_settings~create_function( 'ADD_RECORD_SAP' ).
    Generate Buttons
      CREATE OBJECT lv_button_add_record_sap.
      lv_button_add_record_sap->set_image_source( 'ICON_INSERT_ROW' ).
    lv_button_add_record_sap->set_text( 'Add Record' ).
    Assign Buttons to Functions
    lv_function_add_record_sap->set_editor( lv_button_add_record_sap ).
    Set positions of the buttons
      lv_function_add_record_sap->set_position( value = 1 ).
    Set Alignment of the buttons
    lv_function_add_record_sap->set_alignment( value = if_salv_wd_c_function_settings=>align_left ).
    Call this method initilaze_buttons in WDDOINIT .
    3.To find out which button is clicked an dhandling that function
    A)Go to methods tab.
    B)give the name of the method as on_button select the method type as Eventhandler.
    In the event coulmn select the event ON_FUNCTION of the ALV comp.
    METHOD on_button .
      DATA index  TYPE i.
      index = wd_this->sort_index .
      CASE r_param->id."r_param->id is importing paramter which comes automatically once u use the event handler
        WHEN 'DELETE_ROW'.  "Delete row
          wd_this->delete_row( )."methods you need to create and call them here.(your own customized button functionality
        WHEN 'ADD_RECORD_SAP'.
          wd_this->add_record_sap( ).
    ENDCASE.
    r_param->id holds the value which button is clicked.
    Priya

  • How to do a SELECT from different tables into an internal table?

    How to do a SELECT from different tables into an internal table?
    I want to select data from MARA, MARC and ZPERSON and populate my ITAB_FINAL
    REPORT  zinternal_table.
    TABLES:
      mara,
      marc,
      zperson.
    TYPES:
    BEGIN OF str_table1,
      v_name LIKE zperson-zname,
      v_matnr LIKE marc-matnr,
      v_emarc LIKE marc-emarc,
      v_werks_d LIKE marc-werks_d,
      v_dstat LIKE marc-dstat,
      END OF str_table,
      i_table1 TYPE STANDARD TABLE OF str_table1.
    DATA:
    BEGIN OF str_table2,
    v_mandt LIKE mara-mandt,
    v_ernam LIKE mara-ernam,
      v_laeda LIKE mara-laeda,
    END OF str_table2,
    itab_final LIKE STANDARD TABLE OF str_table2.

    first find the link between mara , marc and zperson , if u have link to 3 tables then u can jus write a join and populate the table u want ( thats final table with all the fields).
    u defenitely have alink between mara and marc so join them and retrieve all data into one internal table.
    then for all the entries in that internal table retrieve data from zperson into another internal table.
    then loop at one internal table
    read another internal table where key equals in both the tables.
    finally assign fileds if sy-subrc = 0.
    gs_finaltable-matnr = gs_table-matnr
    etc...
    and finally append gs_finaltable to gt_finaltable.
    there u go ur final table has all the data u want.
    regards
    Edited by: BrightSide on Apr 2, 2009 3:49 PM

  • How  to  copy  the  table1selected  records into table 2 in webdynpro java.

    Hi 
           how  to  copy  the  table1selected  records into table 2 in webdynpro java.
    venkat
    Edited by: venkatpvr on Sep 23, 2011 11:53 AM

    Hi Venkat,
    You have 2 Value Nodes one for Table1 and second for Table2.
    Table1 node having one more Value Attribute i.e check Box data type is Boolean. Now you are requirement are select records from Table1 Node and click on One Method that records will moves to Second Table2 Node.
    Create One Method for getting the Records from 1-Table to 2-Table
    CopytoTable2 ()
    In this method you have to write code like this
    If (wdContext.nodeTable1.Checkbox(true))
    If(1. Check the Table1 Value Node Size()>0)
    Get the Table1 records and set to table2 Value node.
    Else
    Please select check box// Error message
    Hope this helps!!
    Regards
    Vijay K

  • Deleting row from table in ABAP webdynpro

    Hi all,
    Can anyone help me regarding deletion of a row from a table in ABAP webdynpro.
    I have written a code like this :
        DATA:
          NODE_STUDINFOSYS                    TYPE REF TO IF_WD_CONTEXT_NODE,
          ELEM_STUDINFOSYS                    TYPE REF TO IF_WD_CONTEXT_ELEMENT,
          STRU_STUDINFOSYS                    TYPE IF_COMPONENTCONTROLLER=>ELEMENT_STUDINFOSYS .
      navigate from <CONTEXT> to <STUDINFOSYS> via lead selection
        NODE_STUDINFOSYS = WD_CONTEXT->GET_CHILD_NODE( NAME = IF_COMPONENTCONTROLLER=>WDCTX_STUDINFOSYS ).
      get element via lead selection
        ELEM_STUDINFOSYS = NODE_STUDINFOSYS->GET_ELEMENT(  ).
    deleting data selected via lead selection
        NODE_STUDINFOSYS->REMOVE_ELEMENT( ELEMENT = ELEM_STUDINFOSYS ).
    *But I am getting an error:*
    Error when processing your request
    What has happened?
    The URL http://hsdnt24s11.hclt.corp.hcl.in:8000/sap/bc/webdynpro/sap/znet310_add_del_sech/ was not called due to an error.
    Note
    The following error text was processed in the system HE6 : The lead selection has not been set. VIEW_ADD_DEL_01
    The error occurred on the application server hsdnt24s11_HE6_00 and in the work process 0 .
    The termination type was: RABAX_STATE
    The ABAP call stack was:
    Method: RAISEELEMENT_NOT_FOUND of program CL_WDR_CONTEXT_NODE===========CP
    Method: PATH_TABLE_GET_ELEMENT2 of program CL_WDR_CONTEXT_NODE===========CP
    Method: GET_BOUND_ELEMENT of program CL_WDR_VIEW_ELEMENT_ADAPTER===CP
    What can I do?
    If the termination type was RABAX_STATE, then you can find more information on the cause of the termination in the system HE6 in transaction ST22.
    If the termination type was ABORT_MESSAGE_STATE, then you can find more information on the cause of the termination on the application server hsdnt24s11_HE6_00 in transaction SM21.
    If the termination type was ERROR_MESSAGE_STATE, then you can search for more information in the trace file for the work process 0 in transaction ST11 on the application server hsdnt24s11_HE6_00 . In some situations, you may also need to analyze the trace files of other work processes.
    If you do not yet have a user ID, contact your system administrator.
    Error code: ICF-IE-http -c: 800 -u: SUMANK -l: E -s: HE6 -i: hsdnt24s11_HE6_00 -w: 0 -d: 20081220 -t: 155832 -v: RABAX_STATE -e: UNCAUGHT_EXCEPTION
    HTTP 500 - Internal Server Error
    Your SAP Internet Communication Framework Team
    Can anyone help me???

    Hi Suman,
    this issue seems to be not specific to the FPM. I would like to suggest you to address this problem in the ABAP forum.
    Best regards,
    Thomas

  • How to disable line selection functionality in ALV.

    Hallo guys,
    I need to disable the ALV functionality to select one(or more) lines.
    How to hide this push button on the right side?
    Thanks.

    hi
    good
    check this
    *& Report  ZDEMO_ALVGRID_SELROW                                        *
    *& Example of a simple ALV Grid Report                                 *
    *& The basic ALV grid, Enhanced to display capture each row a user has *
    *& selected                                                            *
    REPORT  zdemo_alvgrid_selrow                 .
    TABLES:     ekko.
    type-pools: slis.                                 "ALV Declarations
    *Data Declaration
    TYPES: BEGIN OF t_ekko,
      SEl,                         "stores which row user has selected
      ebeln TYPE ekpo-ebeln,
      ebelp TYPE ekpo-ebelp,
      statu TYPE ekpo-statu,
      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.
    *Start-of-selection.
    START-OF-SELECTION.
    perform data_retrieval.
    perform build_fieldcatalog.
    perform build_layout.
    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
    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.
      fieldcatalog-fieldname   = 'STATU'.
      fieldcatalog-seltext_m   = 'Status'.
      fieldcatalog-col_pos     = 2.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      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.
      fieldcatalog-fieldname   = 'MEINS'.
      fieldcatalog-seltext_m   = 'Order Unit'.
      fieldcatalog-col_pos     = 6.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'NETPR'.
      fieldcatalog-seltext_m   = 'Net Price'.
      fieldcatalog-col_pos     = 7.
      fieldcatalog-outputlen   = 15.
      fieldcatalog-do_sum      = 'X'.        "Display column total
      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
    form build_layout.
      gd_layout-box_fieldname     = 'SEL'.
                                     "set field name to store row selection
      gd_layout-edit              = 'X'. "makes whole ALV table editable
      gd_layout-zebra             = 'X'.
    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
                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_XEVENTS
                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
    *&      Form  DATA_RETRIEVAL
          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 corresponding fields of table it_ekko.
    endform.                    " DATA_RETRIEVAL
          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.
        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.
        WHEN '&DATA_SAVE'.  "user presses SAVE
        loop at it_ekko into wa_ekko.
          if wa_ekko-sel EQ 'X'.
          Process records that have been selected
          endif.
        endloop.
      ENDCASE.
    ENDFORM.
    thanks
    mrutyun^

  • How to use at-line selection in ALV

    Can someone help me about how to use at-line selection in an ALV

    u can try in user_command
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
             I_CALLBACK_PROGRAM = G_REPID
             IT_FIELDCAT = GT_FIELDCATALOG
             I_CALLBACK_PF_STATUS_SET = 'PF_STATUS_SET'
             I_CALLBACK_HTML_END_OF_LIST = G_HTML_END_OF_LIST
             I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
             I_GRID_SETTINGS = GS_SETTINGS
             IS_LAYOUT = GS_LAYOUT
             I_SAVE = G_SAVE
             IS_VARIANT = GS_VARIANT
             IT_EVENTS = GT_EVENTS[]
    *      I_SCREEN_START_COLUMN = 0 "Use coordinates for
    *      I_SCREEN_START_LINE = 0 "display as dialog box
    *      I_SCREEN_END_COLUMN = 0
    *      I_SCREEN_END_LINE = 0
        IMPORTING
             E_EXIT_CAUSED_BY_CALLER = G_EXIT_CAUSED_BY_CALLER
             ES_EXIT_CAUSED_BY_USER = GS_EXIT_CAUSED_BY_USER
        TABLES
             T_OUTTAB = I_REP
        EXCEPTIONS
             PROGRAM_ERROR = 1
             OTHERS = 2.
    FORM USER_COMMAND USING R_UCOMM TYPE SY-UCOMM
                            RS_SELFIELD TYPE SLIS_SELFIELD.
    CASE R_UCOMM.
        WHEN '&IC1'.
          CASE RS_SELFIELD-FIELDNAME.
            WHEN 'XXXXX'.
              READ TABLE I_xxx INTO V_xxx
                WITH KEY XXX = RS_SELFIELD-VALUE.
              IF SY-SUBRC = 0.
              ENDIF.
            WHEN OTHERS
          ENDCASE.
      ENDCASE.
    ENDFORM.

  • How do I find an event which is triggered on line selection for ALV grid?

    Hi,
    I'm trying to find an event which is triggered when a user selects a row in the ALV grid. I want to add my own code in to add up the total values of selected lines, but can't find any event which will trigger my method.
    I found CLICK_ROW_COL but it's protected so when I try and add a method for it:
      PROTECTED SECTION.
        METHODS:
        select_row
            FOR EVENT click_row_col OF cl_gui_alv_grid.
    I get the syntax error:
    Access to protected event "CLICK_ROW_COL" is not allowed.
    Am I using the right event? Am I implementing it correctly?
    Any help appreciated. Thanks in advance.
    Gill

    I chose to solve this by removing the line select buttons from the ALV and replacing them with a checkbox defined as a hotspot.  I then used EVENT hotspot_click FROM cl_gui_alv_grid to highlight the line and change my totals on a single click.

  • Multilple line selection in alv

    Hi All,
    I am dispalying a simple alv grid report using function module
    reuse_alv_grid_display.i have used check box for selection but it is only applicable for single selection.Could anybody tell me how to select multiple line items at a time without using control key.if somebody provide the sample code it will be more helpful.
    Regards
    Lalit

    Hi,
    Please refer to the standard demo program.
    BCALV_EDIT_05
    or Search as BCALV_EDIT* and press F4.
    OR
    Please refer to the code below:
    *& Report  ZDEMO_ALVGRID_SELROW                                        *
    *& Example of a simple ALV Grid Report                                 *
    *& The basic ALV grid, Enhanced to display capture each row a user has *
    *& selected                                                            *
    REPORT  zdemo_alvgrid_selrow                 .
    TABLES:     ekko.
    type-pools: slis.                                 "ALV Declarations
    *Data Declaration
    TYPES: BEGIN OF t_ekko,
      SEl,                         "stores which row user has selected
      ebeln TYPE ekpo-ebeln,
      ebelp TYPE ekpo-ebelp,
      statu TYPE ekpo-statu,
      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.
    *Start-of-selection.
    START-OF-SELECTION.
    perform data_retrieval.
    perform build_fieldcatalog.
    perform build_layout.
    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
    * 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.
      fieldcatalog-fieldname   = 'STATU'.
      fieldcatalog-seltext_m   = 'Status'.
      fieldcatalog-col_pos     = 2.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      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.
      fieldcatalog-fieldname   = 'MEINS'.
      fieldcatalog-seltext_m   = 'Order Unit'.
      fieldcatalog-col_pos     = 6.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
      fieldcatalog-fieldname   = 'NETPR'.
      fieldcatalog-seltext_m   = 'Net Price'.
      fieldcatalog-col_pos     = 7.
      fieldcatalog-outputlen   = 15.
      fieldcatalog-do_sum      = 'X'.        "Display column total
      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
    form build_layout.
      gd_layout-box_fieldname     = 'SEL'.
                                     "set field name to store row selection
      gd_layout-edit              = 'X'. "makes whole ALV table editable
      gd_layout-zebra             = 'X'.
    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
                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_XEVENTS
                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
    *&      Form  DATA_RETRIEVAL
    *       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 corresponding fields of table it_ekko.
    endform.                    " DATA_RETRIEVAL
    *       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.
    *     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.
        WHEN '&DATA_SAVE'.  "user presses SAVE
        loop at it_ekko into wa_ekko.
          if wa_ekko-sel EQ 'X'.
    *       Process records that have been selected
          endif.
        endloop.
      ENDCASE.
    ENDFORM.
    Thanks,
    Sriram Ponna
    Edited by: Sriram Ponna on Feb 8, 2008 9:31 PM

Maybe you are looking for