Application Development and Automation 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: 
Read only

Regarding ALV

Former Member
0 Likes
1,014

Hi experts!

Where we define USER COMMAND in ALV?

Thanks in advance

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
885

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,

RIch HEilman

Hi experts!

Where we define USER COMMAND in ALV?

Thanks in advance

6 REPLIES 6
Read only

Former Member
0 Likes
885

Hi experts!

I have some doubts

Where we define USER COMMAND in ALV?

How we find Business objects?

How we find a bapi for particular screen?

Is there any other way of finding an error in Call transaction except checking in BDCMSGCOLL?

Thanks in advance

jawad

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
886

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,

RIch HEilman

Read only

Former Member
0 Likes
885

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

I_CALLBACK_USER_COMMAND and you should write the code iin that subroutine:

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

.

.

.

.

I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

.

.

.

.

form user_command using ucomm like sy-ucomm

selfield type slis_selfield. "#EC CALLED

  • Write your code to handle the user commands.

endform.

Regards,

Ravi

Read only

Former Member
0 Likes
885

Hi Jawad,

You should register the event USER COMMAND for the particular grid instance you have created. After this you can create a class which would handle this event, an event handler.

You can go through the sample programs provided by SAP.

Goto SE38 and type BCALV and hit F4. You'll find a variety of programs related to ALV, event-handling etc.

Hope this helps you.

Regards

Anil Madhavan

Read only

Former Member
0 Likes
885

Hi

here sending u the sample code....where nd how to use USER COMMAND

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'

EXPORTING

i_callback_program = sy-repid

i_grid_title = l_title

i_callback_user_command = 'USER_COMMAND'

i_callback_pf_status_set = 'SET_PF_STATUS'

is_layout_lvc = x_layout

it_fieldcat_lvc = it_fieldcat

TABLES

t_outtab = gt_grid[]

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.

FORM user_command USING p_ucomm TYPE sy-ucomm

p_selfld TYPE slis_selfield.

DATA: ref_grid TYPE REF TO cl_gui_alv_grid. "new

IF ref_grid IS INITIAL.

CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'

IMPORTING

e_grid = ref_grid.

ENDIF.

IF NOT ref_grid IS INITIAL.

CALL METHOD ref_grid->check_changed_data

.

ENDIF.

CASE p_ucomm.

  • WHEN '&REFRESH'.

*

  • PERFORM get_imrg_data. " Refresh data

  • p_selfld-refresh = 'X'.

  • p_selfld-col_stable = 'X' .

  • p_selfld-row_stable = 'X' .

  • Call tansaction IK12 via BDC for all checked value of ALV Grid

  • PERFORM tran_bdc.

WHEN '&SAVE_DATA'.

  • Look for all changed records.

LOOP AT gt_grid.

READ TABLE ori_gt_grid INDEX sy-tabix.

*VB001 Start Editing

  • Check for '90 Days Revist' document

IF gt_grid <> ori_gt_grid AND

***********************************************************

If you have futher query plz reply.....

the use is also similar for

1. REUSE_ALV_GRID_DISPLAY

Thank-You.

award points if helpful.

Regards

vinsee

Read only

Former Member
0 Likes
885

Hi

here sending u the sample code....where nd how to use USER COMMAND

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'

EXPORTING

i_callback_program = sy-repid

i_grid_title = l_title

i_callback_user_command = 'USER_COMMAND'

i_callback_pf_status_set = 'SET_PF_STATUS'

is_layout_lvc = x_layout

it_fieldcat_lvc = it_fieldcat

TABLES

t_outtab = gt_grid[]

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.

FORM user_command USING p_ucomm TYPE sy-ucomm

p_selfld TYPE slis_selfield.

DATA: ref_grid TYPE REF TO cl_gui_alv_grid. "new

IF ref_grid IS INITIAL.

CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'

IMPORTING

e_grid = ref_grid.

ENDIF.

IF NOT ref_grid IS INITIAL.

CALL METHOD ref_grid->check_changed_data

.

ENDIF.

CASE p_ucomm.

  • WHEN '&REFRESH'.

*

  • PERFORM get_imrg_data. " Refresh data

  • p_selfld-refresh = 'X'.

  • p_selfld-col_stable = 'X' .

  • p_selfld-row_stable = 'X' .

  • Call tansaction IK12 via BDC for all checked value of ALV Grid

  • PERFORM tran_bdc.

WHEN '&SAVE_DATA'.

  • Look for all changed records.

LOOP AT gt_grid.

READ TABLE ori_gt_grid INDEX sy-tabix.

*VB001 Start Editing

  • Check for '90 Days Revist' document

IF gt_grid <> ori_gt_grid AND

***********************************************************

If you have futher query plz reply.....

the use is also similar for

1. REUSE_ALV_GRID_DISPLAY

Thank-You.

award points if helpful.

Regards

vinsee