Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

at user command in alv's

Former Member
0 Kudos

how to handle at user commads in alv's?

2 REPLIES 2

Former Member
0 Kudos

hi,

YOu need to pass the name of a subrotine to the parameter:

<b>I_CALLBACK_USER_COMMAND</b> and you should write the code iin that subroutine:

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

.

.

.

.

<b>I_CALLBACK_USER_COMMAND = 'USER_COMMAND'</b>

.

form user_command using ucomm like sy-ucomm

selfield type slis_selfield.

  • Write your code to handle the user commands.

It depends, if you are using the Function module REUSE_ALV_GRID_DISPLAY, then the user command is implemented in a FORM routine. So when passing the name of the form routine to the function call, you must also have the FORM routine defined.

report zrich_0001.
 
 
* Global ALV Data Declarations
type-pools: slis.
 
* Internal Tables
data: begin of itab occurs 0,
      matnr type mara-matnr,
      maktx type makt-maktx,
      end of itab.
 
start-of-selection.
 
  perform get_data.
  perform call_alv.
 
*********************************************************************
*      Form  GET_DATA
*********************************************************************
form get_data.
 
  select mara~matnr makt~maktx
          into corresponding fields of table itab
               from mara
                 inner join makt
                  on mara~matnr = makt~matnr
                             up to 20 rows.
 
endform.
 
************************************************************************
*  CALL_ALV
************************************************************************
form call_alv.
 
  data: ifc type slis_t_fieldcat_alv.
  data: xfc type slis_fieldcat_alv.
  data: repid type sy-repid.
 
  repid = sy-repid.
 
  clear xfc. refresh ifc.
 
  clear xfc.
  xfc-reptext_ddic = 'Material Number'.
  xfc-fieldname    = 'MATNR'.
  xfc-tabname      = 'ITAB'.
  xfc-outputlen    = '18'.
  append xfc to ifc.
 
  clear xfc.
  xfc-reptext_ddic = 'Material Description'.
  xfc-fieldname    = 'MAKTX'.
  xfc-tabname      = 'ITAB'.
  xfc-outputlen    = '40'.
  append xfc to ifc.
 
* Call ABAP List Viewer (ALV)
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            i_callback_program      = repid
            i_callback_user_command = 'HANDLE_USER_COMMAND'
            it_fieldcat             = ifc
       tables
            t_outtab                = itab.
 
endform.
 
***********************************************************************
*       FORM handle_User_Command                                      *
***********************************************************************
form handle_user_command using r_ucomm     like sy-ucomm
                               rs_selfield type slis_selfield.
 
  case r_ucomm.
    when '&IC1'.
 
    case rs_selfield-FIELDNAME.
      when 'MATNR'.
         set parameter id 'MAT' field rs_selfield-value.
         call transaction 'MD04' and skip first screen.
 
 
      endcase.
 
 
  endcase.
 
endform.

regards,

Ashok reddy

Former Member
0 Kudos

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