Important Main ALV Display Flow

We can use usercommand in alv reports.

The main important steps to follows:

1. Create required buttons using menu painter se41.

Call that in your program screen as follows:

form pf_status using rt_extab type slis_t_extab.
   set pf-status 'LIST'.
endform. "PF_STATUS

Here LIST is the menu name.
PF_STATUS  is the form name.

2. Create event using the following function module REUSE_ALV_EVENTS_GET

form event_get_det1.
  call function 'REUSE_ALV_EVENTS_GET'
    exporting
      i_list_type     = 0
    importing
      et_events       = gt_event_d
    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.

  data:begin of it_event,
  name(30),
  form(30),
  end of it_event.

  it_event-form = 'USER_COMMAND'.
  read table gt_event with key name = 'USER_COMMAND' transporting no fields.
  modify gt_event_d from it_event index sy-tabix 
  transporting form.
endform.                    "event_get_det1

 gt_event_d is the event name.
 USERCOMMAND must be in caps

3. Write the coding for USERCOMMAND

form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.

when 'FEED'.
      clear sy-ucomm.
      clear t_fieldalv_uc1[].
      refresh t_fieldalv_uc1[].
      clear i_prps89.
      refresh i_prps89[].
      loop at i_prps87.
        move-corresponding i_prps87 to i_prps89.
        append i_prps89.
        clear i_prps89.
  endloop.

delete i_prps89 where wbs7 <> '80-417' and
wbs7 <> '80-420' and
wbs7 <> '80-421' and
wbs7 <> '80-423' and
wbs7 <> '80-424' and
wbs7 <> '80-425'.
if i_prps89[] is not initial.
perform initial_alv_fieldcat changing t_fieldalv_uc1[].
perform alv-display_uc1.
else.
message 'NO DATA FOUND' type 'I'.
endif.

endcase.
endform.

4. In the main alv display add assign pf-status, usercommane and event

form alv-display .
  call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
      i_callback_program       = sy-repid
      i_callback_pf_status_set = 'PF_STATUS'
      i_callback_user_command  = 'USER_COMMAND'
      is_layout                = layout
      it_fieldcat              = t_fieldalv[]
      it_events                = gt_event_d
      i_save                   = 'A'
    tables
      t_outtab                 = i_prps87.
  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.                    " alv-display

5. Create field catalog for that alv _display  in this initial_alv_fieldcat

6. Call alv_grid isplay function

form alv-display_uc1.
   call function 'REUSE_ALV_GRID_DISPLAY'
   exporting
      i_callback_program = sy-repid
      is_layout = layout
      it_fieldcat = t_fieldalv_uc1[]
      i_save = 'A'
   tables
      t_outtab = i_prps89.
      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. "alv-display_uc2

Sample Example on ALV Tree:
Abap ALV Tree - A Complete Example Code

Get help for your ABAP problems
Do you have a ABAP Question?

ABAP Books
ABAP Certification, BAPI, Java, Web Programming, Smart Forms, Sapscripts Reference Books

More ABAP Tips

Best regards,
SAP Basis, ABAP Programming and Other IMG Stuff
http://www.erpgreat.com

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG. 
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk. 
 The content on this site may not be reproduced or redistributed without the express written permission of 
www.erpgreat.com or the content authors.