ALV USER COMMAND

Hi,
   I am using the following code to change the values in the output and update the database table.
TYPE-POOLS : SLIS.
TABLES : ZVCARE,
         ZHR_VCARE.
DATA: BEGIN OF IT_ZVCARE OCCURS 0,
      PERNR LIKE ZVCARE-PERNR,
      CYEAR LIKE ZVCARE-CYEAR,
      ENAME LIKE ZVCARE-ENAME,
      END OF IT_ZVCARE.
DATA: BEGIN OF IT_ZVCARE1 OCCURS 0,
      PERNR LIKE ZVCARE-PERNR,
      CYEAR LIKE ZVCARE-CYEAR,
      ENAME LIKE ZVCARE-ENAME,
      END OF IT_ZVCARE1.
DATA: IT_FIELDCAT TYPE  SLIS_T_FIELDCAT_ALV.
DATA :  IT_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA : V_REPID LIKE SY-REPID.
DATA : C_ZVCARE TYPE DD02L-TABNAME VALUE 'ZHR_VCARE'.
CONSTANTS:  C_PF_STATUS1  TYPE SLIS_ALV_EVENT-FORM VALUE 'ZHR_MED',
            C_USER_COMMAND TYPE SLIS_FORMNAME        VALUE 'USER_COMMAND'.
        S E L E C T I O N     S C R E E N                           *
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_CLAIM FOR ZVCARE-CLAIM,
                S_PERNR FOR ZVCARE-PERNR,
                S_CDATE FOR ZVCARE-CDATE.
SELECTION-SCREEN END OF BLOCK B1.
            S T A R T    O F     S E L E C T I O N                  *
SET PF-STATUS 'ZHR_MED'.
PERFORM GET_DATA.
              E N D    O F     S E L E C T I O N                    *
PERFORM BUILD_FIELDCATLOG.
PERFORM MODIFY_FIELD_CAT_BUILD.
PERFORM DISPLAY_ALV.
*&      Form  GET_DATA
      text
FORM GET_DATA .
  SELECT PERNR
         CYEAR
         ENAME
         FROM ZVCARE
         INTO TABLE IT_ZVCARE
         WHERE CLAIM IN S_CLAIM
         AND   PERNR IN S_PERNR
         AND   CDATE IN S_CDATE.
  MOVE : IT_ZVCARE[] TO IT_ZVCARE1[].
ENDFORM.                    " GET_DATA
*&      Form  BUILD_FIELDCATLOG
      text
FORM BUILD_FIELDCATLOG .
  V_REPID = SY-REPID.
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      I_STRUCTURE_NAME       = C_ZVCARE
    CHANGING
      CT_FIELDCAT            = IT_FIELDCAT
    EXCEPTIONS
      INCONSISTENT_INTERFACE = 1
      PROGRAM_ERROR          = 2
      OTHERS                 = 3.
ENDFORM.                    " BUILD_FIELDCATLOG
*&      Form  DISPLAY_ALV
      text
FORM DISPLAY_ALV .
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM       = V_REPID
      I_CALLBACK_PF_STATUS_SET = C_PF_STATUS1
      I_CALLBACK_USER_COMMAND  = C_USER_COMMAND
      IS_LAYOUT                = IT_LAYOUT
      IT_FIELDCAT              = IT_FIELDCAT
    TABLES
      T_OUTTAB                 = IT_ZVCARE
    EXCEPTIONS
      PROGRAM_ERROR            = 1
      OTHERS                   = 2.
ENDFORM.                    " DISPLAY_ALV
*&      Form  MODIFY_FIELD_CAT_BUILD
      text
FORM MODIFY_FIELD_CAT_BUILD .
  DATA: X_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
  LOOP AT IT_FIELDCAT INTO X_FIELDCAT.
    CASE X_FIELDCAT-FIELDNAME.
      WHEN 'ENAME'.
        X_FIELDCAT-EDIT  = 'X'.
        X_FIELDCAT-INPUT = 'X'.
    ENDCASE.
    MODIFY IT_FIELDCAT FROM X_FIELDCAT.
  ENDLOOP.
ENDFORM.                    " MODIFY_FIELD_CAT_BUILD
*&      Form  user_command
      EXIT routine for user_command
     -->R_UCOMM      Checks for sy-ucomm for &IC1
     -->RS_SELFIELD  structure to store selected row
FORM USER_COMMAND USING  IV_UCOMM    TYPE SY-UCOMM
                         IV_SELFIELD TYPE SLIS_SELFIELD.    "#EC CALLED
  CASE IV_UCOMM.
    WHEN  'SAVE1'.
      LOOP AT IT_ZVCARE.
        READ TABLE IT_ZVCARE1 INDEX SY-INDEX.
        IF IT_ZVCARE-ENAME <> IT_ZVCARE1-ENAME.
          UPDATE ZVCARE FROM IT_ZVCARE .
        ENDIF.
      ENDLOOP.
    WHEN 'SETT'.
  ENDCASE.
  CLEAR IV_SELFIELD.
ENDFORM.                               "user_command
*&      Form  set_pf_status
this form is called by function module 'REUSE_ALV_GRID_DISPLAY'.
do not delete this form
FORM ZHR_MED USING RT_EXTAB TYPE SLIS_T_EXTAB.              "#EC *
  SET PF-STATUS C_PF_STATUS1 EXCLUDING RT_EXTAB.            "#EC *
ENDFORM.                    " set_pf_status
In the PF-STATUS i have two buttons in the Application Tool Bar 'SAVE' and 'SETT'.
When i make changes in output and click on SAVE or SETT the changes made are not reflecting in the internal table IT_ZVCARE, but when i double click with the mouse changes are reflecting in the internal table.
I want the changes to be reflected when i click on SAVE or SETT.
Thank you,
Ramu N.

HI,
check this program it is saving the data from internal table to database table using SAVE command in standard tool bar.
<b>REPORT ZALV_EDITABLE_FM .
type-pools: slis.
data it_fieldcat type slis_fieldcat_alv occurs 0 with header line.
data: gs_layout type slis_layout_alv.
data v_repid like sy-repid.
DATA: BEGIN OF itab OCCURS 0.
        INCLUDE STRUCTURE CSKT.
DATA: end of itab.
START-OF-SELECTION.
  v_repid = sy-repid.
*--- selection form cost center master table
  SELECT * FROM CSKT
  INTO TABLE itab.
  PERFORM field_catalog.
  gs_layout-edit = 'X'.
  call function 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
            i_callback_program      = v_repid
            i_callback_user_command = 'USER_COMMAND'
            it_fieldcat             = it_fieldcat[]
            is_layout               = gs_layout
       TABLES
            t_outtab                = itab.
*       FORM user_command                                             *
*  -->  R_UCOMM                                                       *
*  -->  RS_SELFIELD                                                   *
form user_command using r_ucomm type sy-ucomm
                        rs_selfield type slis_selfield.
  if r_ucomm = '&DATA_SAVE'.
    message i000(SU) with 'saved'.
    MODIFY CSKT FROM TABLE itab.
    call function 'REUSE_ALV_LIST_DISPLAY'
         EXPORTING
              it_fieldcat = it_fieldcat[]
         TABLES
              t_outtab    = itab.
  endif.
endform.
*&      Form  field_catalog
*       text
*  -->  p1        text
*  <--  p2        text
FORM field_catalog.
  call function 'REUSE_ALV_FIELDCATALOG_MERGE'
       EXPORTING
            i_program_name     = v_repid
            i_internal_tabname = 'ITAB'
            i_inclname         = v_repid
       CHANGING
            ct_fieldcat        = it_fieldcat[].
ENDFORM.                    " field_catalog</b>
Regards,

Similar Messages

  • Alv + user command  plwa_selfield-refresh

    hi can anyone please explain when writing this part of cone on ALV please
    FORM f_user_command USING plv_ucomm LIKE sy-ucomm
                              plwa_selfield TYPE slis_selfield. "#EC CALLED
      plwa_selfield-refresh = c_x.
    What is the meaning of  plwa_selfield-refresh  ???  as per my understanding it is when user do changer on the ALV it is to keep those changes

    this will force the table to refresh the display, so if you changed some cell content in your form routine, the change will be visible

  • Issue in alv user command

    Hi All,
    when i'm trying to update the priority value in the alv grid display for one line item, the same is getting updated for all the remaining line items.
    Pls help...
    Thanks and Regards,
    SriLalitha.

    Hi lalitha,
    check out this sample code if you are passing subroutine in I_callback_usercommand of reuse_alv_grid_display.
    FORM user_command   USING r_ucomm LIKE sy-ucomm
                                                   rs_selfield TYPE slis_selfield.
             READ TABLE gi_final_output INTO gw_final_output INDEX rs_selfield-tabindex.
             modify <database_table> from gw_final_output where <key_filed> = gw_final_output-key_field.
      ENDFORM.         
    Hope it will help.
    Regards,
    Mohammed Quddus.

  • User command is not getting triggered in interactive ALV with LIST display

    Hi experts,
    I have developed an interactive ALV report with LIST display. Here, the issue is, when i double click a record in the primary ALV list, the control must go to the USER COMMAND event which i have written in my report. But the user command event is not getting triggered at all when i double click any record.
    It gives the following information instead.
    "Choose a valid function".
    (My user command name and its respective form name are same.)
    Here is my code..
    START-OF-SELECTION.
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
        EXPORTING
          i_callback_program       = sy-repid
          i_structure_name         = p_table
          i_callback_user_command  = 'TST1'
          i_callback_pf_status_set = 'SET_PF_STATUS'
        TABLES
          t_outtab                 = <dyn_table>
        EXCEPTIONS
          program_error            = 1
          OTHERS                   = 2.
      IF sy-subrc <> 0.
      ENDIF.
    FORM tst1 USING r_ucomm LIKE sy-ucomm
                    rs_selfield TYPE slis_selfield.
    * Local data declaration
      DATA: li_tab TYPE REF TO data,
            l_line TYPE REF TO data.
    * Local field-symbols
      FIELD-SYMBOLS:<l_tab> TYPE table,
                    <l_wa>  TYPE ANY.
    * Create table
      CREATE DATA li_tab TYPE STANDARD TABLE OF (p_table).
      ASSIGN li_tab->* TO <l_tab>.
    * Create workarea
      CREATE DATA l_line LIKE LINE OF <l_tab>.
      ASSIGN l_line->* TO <l_wa>.  CASE r_ucomm.
    *   When a record is selected
        WHEN '&IC1'.
    *     Read the selected record
          READ TABLE <dyn_table> ASSIGNING <dyn_wa> INDEX
          rs_selfield-tabindex.      IF sy-subrc = 0.
    *       Store the record in an internal table
            APPEND <dyn_wa> TO <l_tab>.
    *       Fetch the field catalog info
            CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
              EXPORTING
                i_program_name         = 'Z_DEMO_PDF_JG'
                i_structure_name       = p_table
              CHANGING
                ct_fieldcat            = i_fieldcat
              EXCEPTIONS
                inconsistent_interface = 1
                program_error          = 2
                OTHERS                 = 3.
    Please advice what is the msitake i have done here..

    Read the following code:
    pass the  i_callback_user_command = g_user_command to the ALV function module and write the FORM user_command USING ucomm    LIKE sy-ucomm
                            selfield TYPE slis_selfield.
    as shown below.
    thanx
    Data for ALV display
    DATA  : gt_fieldcat TYPE slis_t_fieldcat_alv,
            gt_events           TYPE slis_t_event,
            g_variant LIKE disvariant,
            g_user_command      TYPE slis_formname VALUE 'USER_COMMAND',
            g_status            TYPE slis_formname VALUE 'SET_PF_STATUS',
            gt_list_top_of_page TYPE slis_t_listheader,
            g_repid LIKE sy-repid,
            gf_pos TYPE i
    Data for ALV display
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
               EXPORTING
              i_callback_program      = g_repid
                 i_callback_program      = sy-repid
                 it_fieldcat             = gt_fieldcat[]
           it_events               = gt_events[]
              i_callback_user_command = g_user_command
                 i_save                  = 'A'
                 is_variant              = g_variant
               TABLES
                 t_outtab                = it_print.
    FORM user_command USING ucomm    LIKE sy-ucomm
                            selfield TYPE slis_selfield.
      CASE ucomm.
        WHEN '&IC1'.
          CASE selfield-sel_tab_field.
            WHEN '1-KUNNR'.
              READ TABLE it_print INTO wa_print INDEX selfield-tabindex.
              IF sy-subrc = 0.
                SET PARAMETER ID 'BPA' FIELD wa_print-kunnr.
                CALL TRANSACTION 'BP'.
              ENDIF.
            WHEN '1-MATNR'.
              READ TABLE it_print INTO wa_print INDEX selfield-tabindex.
              IF sy-subrc = 0.
                SET PARAMETER ID 'JP_ISS' FIELD wa_print-matnr.
                CALL TRANSACTION 'JP29' AND SKIP FIRST SCREEN..
               GET PARAMETER ID 'WRK' FIELD wa_zprint-werks.
               SET PARAMETER ID 'VKO' FIELD wa_zprint-vkorg.
               SET PARAMETER ID 'VTW' FIELD wa_zprint-vtweg.
               CALL TRANSACTION 'JP29' AND SKIP FIRST SCREEN.
              ENDIF.
    Endcase.
    Endform.

  • Problem with User Command in alv report

    Hi
    I have developed a ALV grid report with drill down capability to transaction code for user command. I am having a trouble with this.
    CASE ucomm.
        WHEN '&IC1'.
          CLEAR: wa_import.
          IF selfield-fieldname EQ 'ANLN1'.
            READ TABLE t_import INTO wa_import INDEX selfield-tabindex.
            SET PARAMETER ID 'BUK' FIELD wa_import-bukrs.
            SET PARAMETER ID 'ANl' FIELD wa_import-anln1.
            CALL TRANSACTION 'AW01N'.
          ENDIF.
    here my parameter ids are showing the values but when i call the transaction i am not getting the actual asset numbers.
    Can someone help me out this
    Thanks

    Hi,
    add the AND SKIP FIRST SCREEN...addition..
    CALL TRANSACTION 'AW01N' AND SKIP FIRST SCREEN.
    Thanks
    Naren

  • I have a problem with ALV Grid User Command?

    Hi Experts,
    I have a problem with ALV GRID User Command.
    I am calling TCODE IW33 (Order Display) from the ALV output at first time by selecting an order. But, User command is calling IW33 Initial screen with blank value of order. Even I checked in debugging the value what I selected is passing properly, but once that screen (IW33 Initial) displays, value doesn't appear. Then, Manually, I  created another session and gone to TCODE IW33 and displayed an order. After that I came out from that order. Then again run my ALV program and selected another order, now order is displaying, but not what I selected current order instead of displaying previous order what I just displayed manually. If I selected any other order, system will display the same order what I dislayed manually.
    Here is my code.
    FORM user_command_alv  USING u_ucomm TYPE sy-ucomm
                           us_self_field TYPE slis_selfield.
    CASE u_ucomm.
    WHEN '&IC1'.
    READ TABLE it_final INDEX us_self_field-tabindex INTO wa_final.
            WHEN 'ORDER'.
              IF NOT wa_final-order IS INITIAL.
                SET PARAMETER ID 'COK' FIELD wa_final-order.
                CALL TRANSACTION 'IW33' AND SKIP FIRST SCREEN.
              ENDIF.
    endform.
    PARAMETER ID 'COK'  also the standard one.
    Could you please help me out, Where I did wrong?
    If I select any order, that order only should display.
    Thanks in advance.
    Regards,
    Sarayu.
    Code Formatted by: Alvaro Tejada Galindo on Jan 8, 2009 2:33 PM

    hi,
    Please check it once the Paramater ID is 'ANR' for IW33 order number.
    Hope this may help.
    Regards,
    Sravanthi

  • User command for checkbox in alv grid output

    Hi,
    Does anyone knows the user command for checkbox in alv grid display. My requirement is to have a column for checkbox in alv output. When the user checks the checkbox, a pop-up dialog box will appear. This dialog box was created in screen painter. I can't find the user command for this. Please help.
    Thanks in advance.

    Hi,
    there r two ways for creating checkbox col on the ALV grid.
    1.)  take an extra field in your internal table i.e 
    data:
       checkbox type c.
    loop at internal_table into wa.
    checkbox.
    endloop.
    or
    the fieldcatalog attribute
    2.) wa_fcat-checkbox = 'X'.
    append wa_fcat to t_fcat.
    clear wa_fcat.
    if itab-checkbox = 'X'.
    call screen <dialogbox screen number>.
    endif.
    regards
    ravi

  • How to handle user command method in module ALV Grid

    HI Experts,
                     I have 3 containers grid. 
                     GR_GRID              TYPE REF TO CL_GUI_ALV_GRID,
                     GR_GRID1              TYPE REF TO CL_GUI_ALV_GRID,
                     GR_GRID2              TYPE REF TO CL_GUI_ALV_GRID.
                     Please advise me how can I insert, save, delete 3 Module ALV Grid in method user command. How can i get which grid button (save, insert, delete) is clicked and how can i control those grid.
                    Thks in advance.
    CLASS LCL_EVENT_RECEIVER DEFINITION.
      PUBLIC SECTION.
        METHODS :
            HANDLE_TOOLBAR
                  FOR EVENT TOOLBAR OF CL_GUI_ALV_GRID
                                IMPORTING E_OBJECT E_INTERACTIVE SENDER,
            HANDLE_USER_COMMAND
                  FOR EVENT USER_COMMAND OF CL_GUI_ALV_GRID
                                IMPORTING E_UCOMM,
            HANDLE_DATA_CHANGED
                    FOR EVENT DATA_CHANGED OF CL_GUI_ALV_GRID
                          IMPORTING ER_DATA_CHANGED
                                    E_ONF4
                                    E_ONF4_BEFORE
                                    E_ONF4_AFTER,
            HANDLE_DOUBLE_CLICK
                     FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
                     IMPORTING E_ROW
                               E_COLUMN,
            HANDLE_HOTSPOT_CLICK
                      FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID
                           IMPORTING E_ROW_ID
                                     E_COLUMN_ID
                                     ES_ROW_NO.
    ENDCLASS. "(LCL_EVENT_RECEIVER DEFINITION) 
    METHOD HANDLE_USER_COMMAND.
         CLEAR G_CODE.
        G_CODE = E_UCOMM.
        CASE G_CODE.
          WHEN 'INSERT'.
            MESSAGE 'insert' TYPE 'I'.
           APPEND INITIAL LINE TO GT_MAIN.
          WHEN 'SAVE'.
           MODIFY ZTNBOOK FROM GT_MAIN.
            MESSAGE 'save' TYPE 'I'.
          WHEN 'DELETE'.
           DELETE FROM ZTNBOOK WHERE B_ID EQ GT_ZTBOOK-B_ID.
            MESSAGE 'delete' TYPE 'I'.
        ENDCASE.
        IF NOT G_CODE IS INITIAL.
      PBO, PAI
         CALL METHOD CL_GUI_CFW=>SET_NEW_OK_CODE
           EXPORTING
             NEW_CODE = G_CODE.
         CLEAR G_CODE.
        ENDIF.
      ENDMETHOD.

    Hi,
    Before posting, Search in SDN.
    See the below tread it will help you.
    Re: Get table for cl_gui_alv_grid

  • ALV Grid user command handling

    I am handling user command event of class cl_gui_alv_grid.
    In this , on click of a button , a pop up for selection criterion comes after which
    I have to append some data on alv.
    But I want to append this data only on frontend not on global internal table of alv
    as I want data change event to be called after this and doing some validations on this data.
    How can I upload data only on frontend and how to trigger data_changed method in user command event.
    I tried using check_changed_data of class cl_gui_alv_grid but some dump is coming for an attribute save_allowed of the class.

    Hi Suneel,
    For you requirement, I dont see why you cant include the functionality for the pop up within the USER_COMMAND event itself.
    Algorithm for the USER_COMMAND event:
    Step 1: Check E_UCOMM is 'ADD' or 'DELT'.
    Step 2: If yes, call FM for POPUP_TO_CONFIRM; else continue to other E_UCOMM
    Step 3: If ans is 'No', exit Method - else continue with Add/ Delete as required
    Cheers,
    Aditya

  • User command in ALv

    how to handle user command in alv grid?
    if we want to select only one row, but we get a table from calling method
    get_selected_rows.
    is there any method or way of getting a single row which is selected?

    Hi,
    This method indeed returns the table but only with the selected rows. Therefore when you select only one row, it will contain only one entry. For this use second parameter of the method ET_ROW_NO as the first one is obsolete. It will contain indexes of the selected rows.
    Note!
    You must use one of the these selection modes (A, C, D) in this case. The default one is B, so you have to change it in layout structure.
    layout_structure-sel_mode = 'A'.  "i.e.
    See possible selection modes [here|http://help.sap.com/saphelp_erp2004/helpdata/en/ef/a2e9eff88311d2b48d006094192fe3/frameset.htm]
    Regards
    Marcin

  • At user command in alv's

    how to handle at user commads in alv's?

    Hi Praveen
    Interactive Reports
    As the name suggests, the user can Interact with the report. We can have a drill down into the report data. For example, Column one of the report displays the material numbers, and the user feels that he needs some more specific data about the vendor for that material, he can HIDE that data under those material numbers.
    And when the user clicks the material number, another report (actually sub report/secondary list) which displays the vendor details will be displayed.
    We can have a basic list (number starts from 0) and 20 secondary lists (1 to 21).
    Events associated with Interactive Reports are:
    AT LINE-SELECTION
    AT USER-COMMAND
    AT PF<key>
    TOP-OF-PAGE DURING LINE-SELECTION.
    HIDE statement holds the data to be displayed in the secondary list.
    sy-lisel : contains data of the selected line.
    sy-lsind : contains the level of report (from 0 to 21)
    <u><b>Interactive Report Events:</b></u>
    AT LINE-SELECTION : This Event triggers when we double click a line on the list, when the event is triggered a new sublist is going to be generated. Under this event what ever the statements that are been return will be displayed on newly generated sublist.
    AT PFn: For predefined function keys...
    <u><b>AT USER-COMMAND :</b></u> It provides user functions keys.
    TOP-OF-PAGE DURING LINE-SELECTION :top of page event for secondary list.
    <b>check this sample code</b>
    TYPE-POOLS: slis.                      " ALV Global Types
    DATA :
      gt_user LIKE uinfo OCCURS 0 WITH HEADER LINE. " User info in SM04
    START-OF-SELECTION.
      PERFORM f_read_data.
      PERFORM f_display_data.
    *       Form  F_LIRE_DATA
    FORM f_read_data.
      REFRESH gt_user.
    * Get User's info
      CALL FUNCTION 'THUSRINFO'
           TABLES
                usr_tabl = gt_user.
    * Wait in a task
      PERFORM f_call_rfc_wait.
    ENDFORM.                               " F_READ_DATA
    *      Form  F_DISPLAY_DATA
    FORM f_display_data.
      DEFINE m_sort.
        add 1 to ls_sort-spos.
        ls_sort-fieldname = &1.
        append ls_sort to lt_sort.
      END-OF-DEFINITION.
      DEFINE m_event_exit.
        clear ls_event_exit.
        ls_event_exit-ucomm = &1.
        ls_event_exit-after = 'X'.
        append ls_event_exit to lt_event_exit.
      END-OF-DEFINITION.
      DATA :
        ls_layout     TYPE slis_layout_alv,
        lt_sort       TYPE slis_t_sortinfo_alv,
        ls_sort       TYPE slis_sortinfo_alv,
        lt_event_exit TYPE slis_t_event_exit,
        ls_event_exit TYPE slis_event_exit.
    * Build Sort Table
      m_sort 'ZEIT'.
    * Build Event Exit Table
      m_event_exit '&NTE'.                 " Refresh
      ls_layout-zebra = 'X'.
      ls_layout-colwidth_optimize = 'X'.
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
           EXPORTING
                i_callback_program      = sy-cprog
                i_callback_user_command = 'USER_COMMAND'
                is_layout               = ls_layout
                i_structure_name        = 'UINFO'
                it_sort                 = lt_sort
                it_event_exit           = lt_event_exit
           TABLES
                t_outtab                = gt_user.
    ENDFORM.                               " F_DISPLAY_DATA
    *       FORM USER_COMMAND                                             *
    FORM user_command USING i_ucomm     TYPE syucomm
                            is_selfield TYPE slis_selfield.     "#EC CALLED
      CASE i_ucomm.
        WHEN '&NTE'.
          PERFORM f_read_data.
          is_selfield-refresh = 'X'.
          SET USER-COMMAND '&OPT'.         " Optimize columns width
      ENDCASE.
    ENDFORM.                               " USER_COMMAND
    *      Form  F_CALL_RFC_WAIT
    FORM f_call_rfc_wait.
      DATA lv_mssg(80).                                         "#EC NEEDED
    * Wait in a task
      CALL FUNCTION 'RFC_PING_AND_WAIT' STARTING NEW TASK '001'
        PERFORMING f_task_end ON END OF TASK
        EXPORTING
          seconds               = 5        " Refresh time
          busy_waiting          = space
        EXCEPTIONS
          RESOURCE_FAILURE      = 1
          communication_failure = 2  MESSAGE lv_mssg
          system_failure        = 3  MESSAGE lv_mssg
          OTHERS                = 4.
    ENDFORM.                               " F_CALL_RFC_WAIT
    *      Form  F_TASK_END
    FORM f_task_end USING u_taskname.
      DATA lv_mssg(80).                                         "#EC NEEDED
    * Receiving task results
      RECEIVE RESULTS FROM FUNCTION 'RFC_PING_AND_WAIT'
        EXCEPTIONS
          RESOURCE_FAILURE      = 1
          communication_failure = 2  MESSAGE lv_mssg
          system_failure        = 3  MESSAGE lv_mssg
          OTHERS                = 4.
      CHECK sy-subrc EQ 0.
      SET USER-COMMAND '&NTE'.             " Refresh
    ENDFORM.                               " F_TASK_END
    *************** END OF PROGRAM Z_ALV_AUTO_REFRESH *********************
    check this link too
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/abap-AddUsercommandfunctionalitytoALVgridreport&
    Reward all helpfull answers
    Regards
    Pavan

  • User command in ALV grid

    Hi
    I am displaying the output of a report in the ALV grid.
    I have used REUSE_ALV_LIST_DISPLAY in my code as follows.
    FORM DISPLAY_ALV_LIST.
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
      EXPORTING
      I_CALLBACK_PROGRAM = SYREPID
      IS_LAYOUT = FIELDLAYOUT
      I_CALLBACK_USER_COMMAND  = 'USER-COMMAND'
      IT_FIELDCAT = FIELDCATALOG[]
      I_SAVE = 'X'
      IT_EVENTS = EVENTSTAB[]
      TABLES
      T_OUTTAB = ITAB_1
      EXCEPTIONS
      PROGRAM_ERROR = 1
      OTHERS = 2.
    ENDFORM. " DISPLAY_ALV_LIST
    When I try to call a transaction at the user command with sy-ucomm = &IC1 sys gives a message 'Not valid'.
    FORM USER-COMMAND USING UCOMM LIKE SY-UCOMM
                           SELFIELD TYPE SLIS_SELFIELD.
      READ TABLE ITAB_1 INDEX SELFIELD-TABINDEX.
      CHECK SY-SUBRC = 0.
      CASE UCOMM.
        WHEN '&IC1'.
          CASE SELFIELD-SEL_TAB_FIELD.
            WHEN 'ITAB_1-VBELN'.
              SET PARAMETER ID 'VF' FIELD ITAB_1-VBELN.
              CALL TRANSACTION 'VF03' AND SKIP FIRST SCREEN.
            WHEN 'ITAB_1-MATNR'.
              SET PARAMETER ID 'MAT' FIELD ITAB_1-MATNR.
              CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
          ENDCASE.
      ENDCASE.
    ENDFORM.                    "USER_COMMAND
    Kindly let me know what am I missing in the above code. As this FORM USER-COMMAND is at all called during the user-command.
    Regds
    Priya

    the Code what u are given is WRONG , check this one.
    put like this , it will solve ur probs.
      check r_ucomm = '&IC1'.             "User Double Clicked on Some field
      check not rs_selfield-value is initial.
      case rs_selfield-fieldname.
        when 'AUFNR'.
          if rad4 ne 'X'.
            read table  itab_order index rs_selfield-tabindex.
          else.
            read table  itab_order2 index rs_selfield-tabindex.
            itab_order-aufnr = itab_order2-aufnr.
          endif.
          if sy-subrc eq 0.
            set parameter id 'ANR' field  itab_order-aufnr.
            set parameter id 'VGN' field '10'.
            call transaction 'CO14' and skip first screen.
          endif.                            " IF SY-SUBRC EQ 0
      endcase.
    Regards
    Prabhu
    Message was edited by: Prabhu Peram

  • USER COMMAND FOR INTERACTIVE ALV REPORT

    Hi Frens
    I am making an interactive alv report showing a cost center hierarchy. I could scuccessfully capture the first click event in the user command using  '&IC1'. Now i want to capture the second click event for the third hierarchy.
    When i try to do that, the program flow keeps hitting the same user command time n again. I want to put in a different code for the different click events. What is the way to achieve this?
    I searched ....there is nothing like '&IC2'. It does not work.

    hi,
    You can try this for the first click
    READ TABLE IST_EVENTS INTO WA_EVENT WITH KEY NAME = 'USER_COMMAND'.
      IF SY-SUBRC EQ 0.
        WA_EVENT-FORM = 'USER_COMMAND'.
        MODIFY IST_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME = WA_EVENT-NAME.
      ENDIF.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          I_CALLBACK_PROGRAM       = G_REPID
          I_CALLBACK_PF_STATUS_SET = C_PF         "'SET_PF_STATUS'
          I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'
          I_CALLBACK_TOP_OF_PAGE   = 'TOP_OF_PAGE'
          I_GRID_TITLE             = G_TITLE
          IS_LAYOUT                = IST_LAYOUT
          IT_FIELDCAT              = IST_FIELDCAT[]
          IT_SORT                  = IST_SORT
          I_SAVE                   = 'A'
          IT_EVENTS                = IST_EVENTS
          IS_PRINT                 = IST_PRNT
        IMPORTING
          E_EXIT_CAUSED_BY_CALLER  = G_EXIT
          ES_EXIT_CAUSED_BY_USER   = IST_EXIT
        TABLES
          T_OUTTAB                 = IST_FINAL "sodtl
        EXCEPTIONS
          PROGRAM_ERROR            = 1
          OTHERS                   = 2.
    FORM USER_COMMAND USING R_UCOMM TYPE SY-UCOMM
      RS_SELFIELD TYPE SLIS_SELFIELD.
    your code....
    ENDFORM.
    for second click
    READ TABLE IST_EVENTS INTO WA_EVENT WITH KEY NAME = 'USER_COMMAND1'.
      IF SY-SUBRC EQ 0.
        WA_EVENT-FORM = 'USER_COMMAND1'.
        MODIFY IST_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME = WA_EVENT-NAME.
      ENDIF.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          I_CALLBACK_PROGRAM       = G_REPID
          I_CALLBACK_PF_STATUS_SET = C_PF "'SET_PF_STATUS'
          I_CALLBACK_USER_COMMAND  = 'USER_COMMAND1'
          I_CALLBACK_TOP_OF_PAGE   = 'TOP_OF_PAGE'
          I_GRID_TITLE             = G_TITLE
          IS_LAYOUT                = IST_LAYOUT
          IT_FIELDCAT              = IST_FIELDCAT[]
          I_SAVE                   = 'A'
        TABLES
          T_OUTTAB                 = IST_FINAL1.
    hope this solves.

  • ALV using LVC....User Commands

    Hai All..
    Can anyone explain how can we handle the user commands like single click or a double click in an ALV using LVC type-pool.
    Thanks in Advance,
    rama

    Hi,
    Check the demo programs BCALV_TEST_GRID_EVENTS and BCALV_TEST_FULLSCREEN_EVENTS.
    Regards,
    Sesh

  • ALV Grid Problem - User command Back Cancel Exit

    Hi Guys,
                 I was trying to use the ALV grid and my problem is, on the grid display, when i try to hit the back button or exit or cancel, then a blank screen appears and i need to hit either back or other buttons one more time to go back to the selection screen.
                 Is there any thing I am missing here? Please suggest me the solution.
    Thanks in advance,
    Srinivas.

    hi srinivas,
    we have 2 options in this case.
    1) i think ur using EVENTS_GET function module. If u use sometimes we are facing this kind of problem. i think accroding to my knowliege its bug in SAP....
    2) See in debug mode what is the user command for this back button everty time USERCOMMAND FOR BACK BUTTON not 'BACK' .If it ios correct plaese add the code for back button in user command event.
    if u dont want to face that problem remove that events_get fm and write the code manually. i am not sure abt ur code.
    i hope u got the point what i am saying.
    Thanks,
    Maheedhar

Maybe you are looking for