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: 

PLZ Send me each steps of Interactive ALV

Former Member
0 Kudos

Dear freindz,

I need each steps of interacive alv with examples.

pls help me its urgent.

Thanks

Shakti Mishra

5 REPLIES 5

Former Member
0 Kudos

hi,

In se38, give BCALV* and search.

There are lots of demo programs available on ALV which will be very useful.

Thanks,

Arun

Former Member
0 Kudos

Former Member
0 Kudos

Hi,

welcome to SDN yaar

Try This yaar.

REPORT z_demo_3_alv_list.
*---------------------------------------------------------------------*
* This program is an example with 3 ALV Grid lists                    *
* The customers are displayed in the first list                       *
* When a line is selected, the customer's orders are displayed in     *
* the second list                                                     *
* When a line is selected in the second list, the items orders are    *
* displayed in the second list                                        *
*---------------------------------------------------------------------*
* Author : Michel PIOUD - Updated 16-Nov-07                           *
* HomePage : http://www.geocities.com/mpioud                          *
*---------------------------------------------------------------------*
* Macro definition
DEFINE m_fieldcat.
  add 1 to ls_fieldcat-col_pos.
  ls_fieldcat-fieldname   = &1.
  ls_fieldcat-ref_tabname = &2.
  append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.

TYPE-POOLS: slis.                      " ALV Global types

SELECTION-SCREEN :
  SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max.    "#EC NEEDED
PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.
SELECTION-SCREEN END OF LINE.

TYPES:
* Data displayed in the first list
  BEGIN OF ty_kna1,
    kunnr TYPE kna1-kunnr,             " Customer number
    name1 TYPE kna1-name1,             " Customer name
    ort01 TYPE kna1-ort01,             " Customer city
  END OF ty_kna1,

* Data displayed in the second list
  BEGIN OF ty_vbak,
    vkorg TYPE vbak-vkorg,             " Sales organization
    kunnr TYPE vbak-kunnr,             " Sold-to party
    vbeln TYPE vbak-vbeln,             " Sales document
    netwr TYPE vbak-netwr,             " Net Value of the Sales Order
  END OF ty_vbak,

* Data displayed in the third list
  BEGIN OF ty_vbap,
    vbeln  TYPE vbap-vbeln,            " Sales document
    posnr  TYPE vbap-posnr,            " Sales document item
    matnr  TYPE vbap-matnr,            " Material number
    arktx  TYPE vbap-arktx,            " Short text for sales order item
    kwmeng TYPE vbap-kwmeng,           " Order quantity
    netwr  TYPE vbap-netwr,            " Net value of the order item
  END OF ty_vbap.

DATA:
  gs_kna1 TYPE ty_kna1,
  gt_kna1 TYPE TABLE OF ty_kna1,
  gs_vbak TYPE ty_vbak,
  gt_vbak TYPE TABLE OF ty_vbak,
  gt_vbap TYPE TABLE OF ty_vbap.

*---------------------------------------------------------------------*
INITIALIZATION.

  v_1 = 'Maximum of records to read'.

*---------------------------------------------------------------------*
START-OF-SELECTION.

  PERFORM f_read_data_kna1.

*---------------------------------------------------------------------*
END-OF-SELECTION.

  PERFORM f_display_data_kna1.

*---------------------------------------------------------------------*
*      Form  f_read_data_kna1
*---------------------------------------------------------------------*
FORM f_read_data_kna1.

* Read customer data with a least one order
  SELECT kunnr name1 ort01 INTO TABLE gt_kna1
           FROM kna1 AS k
             UP TO p_max ROWS
          WHERE EXISTS
       ( SELECT kunnr FROM vbak WHERE kunnr = k~kunnr ).

ENDFORM.                               " F_READ_DATA_KNA1
*---------------------------------------------------------------------*
*      Form  f_display_data_kna1
*---------------------------------------------------------------------*
FORM f_display_data_kna1.

  DATA:
    ls_fieldcat TYPE slis_fieldcat_alv,
    lt_fieldcat TYPE slis_t_fieldcat_alv.

* Build the field catalog
  m_fieldcat 'KUNNR' 'KNA1'.
  m_fieldcat 'NAME1' 'KNA1'.
  m_fieldcat 'ORT01' 'KNA1'.

* Display the first list
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program      = sy-cprog
      i_callback_user_command = 'USER_COMMAND_KNA1'
      it_fieldcat             = lt_fieldcat
    TABLES
      t_outtab                = gt_kna1.

ENDFORM.                               " F_DISPLAY_DATA_KNA1
*---------------------------------------------------------------------*
*       FORM USER_COMMAND_KNA1                                        *
*---------------------------------------------------------------------*
FORM user_command_kna1 USING u_ucomm     TYPE sy-ucomm
                             us_selfield TYPE slis_selfield."#EC CALLED

  CASE u_ucomm.
    WHEN '&IC1'.
      READ TABLE gt_kna1 INDEX us_selfield-tabindex INTO gs_kna1.
      CHECK sy-subrc EQ 0.
      PERFORM f_read_data_vbak.        " Read data from VBAK
      PERFORM f_display_data_vbak.     " Display orders
  ENDCASE.

ENDFORM.                               " USER_COMMAND_KNA1
*---------------------------------------------------------------------*
*      Form  f_read_data_vbak
*---------------------------------------------------------------------*
FORM f_read_data_vbak.

  SELECT vkorg kunnr vbeln netwr
    INTO TABLE gt_vbak
    FROM vbak
      UP TO p_max ROWS
   WHERE kunnr = gs_kna1-kunnr.

ENDFORM.                               " F_READ_DATA_VBAK
*---------------------------------------------------------------------*
*      Form  f_display_data_vbak
*---------------------------------------------------------------------*
FORM f_display_data_vbak.

  DATA:
    ls_fieldcat TYPE slis_fieldcat_alv,
    lt_fieldcat TYPE slis_t_fieldcat_alv.

* Build the field catalog
  m_fieldcat 'VKORG' 'VBAK'.
  m_fieldcat 'KUNNR' 'VBAK'.
  m_fieldcat 'VBELN' 'VBAK'.
  m_fieldcat 'NETWR' 'VBAK'.

* Display the second list
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program      = sy-cprog
      i_callback_user_command = 'USER_COMMAND_VBAK'
      it_fieldcat             = lt_fieldcat
    TABLES
      t_outtab                = gt_vbak.

ENDFORM.                               " F_DISPLAY_DATA_VBAK
*---------------------------------------------------------------------*
*       FORM USER_COMMAND_VBAK                                        *
*---------------------------------------------------------------------*
FORM user_command_vbak USING u_ucomm     TYPE sy-ucomm
                             us_selfield TYPE slis_selfield."#EC CALLED

  CASE u_ucomm.
    WHEN '&IC1'.
      READ TABLE gt_vbak INDEX us_selfield-tabindex INTO gs_vbak.
      CHECK sy-subrc EQ 0.
      PERFORM f_read_data_vbap.        " Read data from VBAP
      PERFORM f_display_data_vbap.     " Display items
  ENDCASE.

ENDFORM.                               " USER_COMMAND_VBAK
*---------------------------------------------------------------------*
*      Form  f_read_data_vbap
*---------------------------------------------------------------------*
FORM f_read_data_vbap.

  SELECT vbeln posnr matnr arktx kwmeng netwr
    INTO TABLE gt_vbap
    FROM vbap
   WHERE vbeln = gs_vbak-vbeln.

ENDFORM.                               " F_READ_DATA_VBAP
*---------------------------------------------------------------------*
*      Form  f_display_data_vbap
*---------------------------------------------------------------------*
FORM f_display_data_vbap.

  DATA:
    ls_fieldcat TYPE slis_fieldcat_alv,
    lt_fieldcat TYPE slis_t_fieldcat_alv.

* Build the field catalog
  m_fieldcat 'VBELN'  'VBAP'.
  m_fieldcat 'POSNR'  'VBAP'.
  m_fieldcat 'MATNR'  'VBAP'.
  m_fieldcat 'ARKTX'  'VBAP'.
  m_fieldcat 'KWMENG' 'VBAP'.
  m_fieldcat 'NETWR'  'VBAP'.

* Display the third list
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      it_fieldcat = lt_fieldcat
    TABLES
      t_outtab    = gt_vbap.

ENDFORM.                               " F_DISPLAY_DATA_VBAP

reward if helpful

raam

venkat_o
Active Contributor
0 Kudos

Hi Sakti Mishra, Here is the procedure to handle Interactive ALV. 1. declare events table like this.

data :
      i_events  type slis_t_event,
      w_events  like line of i_events.
2. Build events table .

w_events-name = 'USER_COMMAND' .
w_events-form = 'USER_COMMAND' .
append w_events to i_events.
clear w_events.
 
w_events-name = 'PF_STATUS_SET' .
w_events-form = 'PF_STATUS_SET' .
append w_events to i_events.
clear w_events.
3. pass this events table through REUSE_ALV_GRID_DISPLAY. 4. USER_COMMAND and PF_STATUS_SET call back subroutines should be like this in your case. These are nowhere called using PERFORM statement in ur program. 5. USER_COMMAND subroutine should be like this.
*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
form user_command using ucomm like sy-ucomm
                  selfield type slis_selfield.
  case ucomm .
    when '&IC1'. This is for double click on ALV output.
      skip 10.
      position 10.
      write 'Double click was executed'.
  endcase.
 
endform.                    "user_command
selfield structure You can also handle Interactive ALV using this structure.

types: begin of slis_selfield,
         tabname              type slis_tabname,
         tabindex             like sy-tabix,
         sumindex             like sy-tabix,
         endsum(1)            type c,
         sel_tab_field        type slis_sel_tab_field,
         value                type slis_entry,
         before_action(1)     type c,
         after_action(1)      type c,
         refresh(1)           type c,
         col_stable(1)        type c,
         row_stable(1)        type c,
*        colwidth_optimize(1) type c,
         exit(1)              type c,
         fieldname            type slis_fieldname,
         grouplevel           type i,
         collect_from         type i,
         collect_to           type i,
       end of slis_selfield.
6. PF_STATUS_SET' subroutine should be like this.
*&---------------------------------------------------------------------*
*&      Form  pf_status_set
*&---------------------------------------------------------------------*
form pf_status_set    using extab type slis_t_extab.
set pf-status 'STATUS1' excluding g_extab.
 
endform.                    "pf_status_set
Check this example as well.

REPORT  zalv_tcoderefresh.*type pools for alv declarations
TYPE-POOLS: slis.*structure declaration for tstc table
TYPES : BEGIN OF ty_tstc,
        tcode TYPE tcode,
        pgmna TYPE program_id,
        dypno TYPE dynpronr,
        END OF ty_tstc.* Internal table and workarea declarations for tstc
DATA: it_tstc TYPE STANDARD TABLE OF ty_tstc,
      wa_tstc TYPE ty_tstc.*data declarations for ALV
DATA: it_layout TYPE slis_layout_alv,
      wa_fieldcat TYPE slis_fieldcat_alv,
      it_fieldcat TYPE slis_t_fieldcat_alv,
      it_eventexit TYPE slis_t_event_exit,
      wa_eventexit TYPE slis_event_exit.*initialisation event
INITIALIZATION.*start of selection event
START-OF-SELECTION.*subroutine to fetch data from the db table
  PERFORM fetch_data.*subroutine for output display
  PERFORM alv_output.*&---------------------------------------------------------------------*
*&      Form  fetch_data
*&---------------------------------------------------------------------*
*       *subroutine to fetch data from the db table
*----------------------------------------------------------------------*
FORM fetch_data.*Internal table and work area declaratin for TSTC (local tables)
  DATA : lt_tstc TYPE STANDARD TABLE OF ty_tstc,
         ls_tstc TYPE ty_tstc.*Static field definition
*Reads the last tcode and stores it in l_tstc that on refresh further data
*beyond this value is fetched
  STATICS l_tstc TYPE tcode.
* Selection from the tstc table
*we select till 25 rows and on further refresh next 25 are selected
*we select transactions having screen numbers only
  SELECT tcode
         pgmna
         dypno
         FROM tstc
         INTO CORRESPONDING FIELDS OF TABLE lt_tstc
         UP TO 25 ROWS
         WHERE tcode GT l_tstc
         AND dypno NE '0000'.* Code for transferring the values of local table to output table
* for 25 rows as sy-tfill is 25.
*In case there are no records a message pops up.
  IF sy-subrc EQ 0.
    DESCRIBE TABLE it_tstc.
    READ TABLE lt_tstc INTO ls_tstc INDEX sy-tfill.
    l_tstc = ls_tstc-tcode.
    it_tstc[] = lt_tstc[].
  ELSE.
    MESSAGE 'No Records found ' TYPE 'i'.
  ENDIF.
ENDFORM.                    "read_data*&---------------------------------------------------------------------*
*&      Form  alv_output
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM alv_output.*subroutine to refresh alv
  PERFORM event_exits.
*field catalogue
  PERFORM build_fieldcat.
*Layout for alv
  PERFORM build_layout.
*output display
  PERFORM alv_display.ENDFORM.                    "alv_output*&---------------------------------------------------------------------*
*&      Form  event_exits
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*subroutine to refresh alvFORM event_exits.  CLEAR wa_eventexit.
  wa_eventexit-ucomm = '&REFRESH'.    " Refresh
  wa_eventexit-after = 'X'.
  APPEND wa_eventexit TO it_eventexit.ENDFORM.                     "event_exits*&---------------------------------------------------------------------*
*&      Form  build_fieldcat
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*Field catalogue
FORM build_fieldcat.  CLEAR wa_fieldcat.
  wa_fieldcat-row_pos   = '1'.
  wa_fieldcat-col_pos   = '1'.
  wa_fieldcat-fieldname = 'TCODE'.
  wa_fieldcat-tabname   = 'it_tstc'.
  wa_fieldcat-seltext_m = 'TRANSACTION'.
  APPEND wa_fieldcat TO it_fieldcat.  CLEAR wa_fieldcat.
  wa_fieldcat-row_pos   = '1'.
  wa_fieldcat-col_pos   = '2'.
  wa_fieldcat-fieldname = 'PGMNA'.
  wa_fieldcat-tabname   = 'it_tstc'.
  wa_fieldcat-seltext_m = 'PROGRAM'.
  APPEND wa_fieldcat TO it_fieldcat.  CLEAR wa_fieldcat.
  wa_fieldcat-row_pos   = '1'.
  wa_fieldcat-col_pos   = '3'.
  wa_fieldcat-fieldname = 'DYPNO'.
  wa_fieldcat-tabname   = 'it_tstc'.
  wa_fieldcat-seltext_m = 'SCREEN'.
  APPEND wa_fieldcat TO it_fieldcat.ENDFORM.                     "build_fieldcat*&---------------------------------------------------------------------*
*&      Form  build_layout
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*Layout
FORM build_layout.  it_layout-zebra = 'X'.
  it_layout-colwidth_optimize = 'X'.ENDFORM.                     "build_layout*&---------------------------------------------------------------------*
*&      Form  alv_display
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*ALV output
FORM alv_display.  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program       = sy-repid
      i_callback_user_command  = 'USER_COMMAND'
      i_callback_pf_status_set = 'PFSTATUS'
      it_fieldcat              = it_fieldcat
      is_layout                = it_layout
      it_event_exit            = it_eventexit
      i_screen_start_column    = 10
      i_screen_start_line      = 20
      i_screen_end_column      = 70
      i_screen_end_line        = 45
      i_grid_title             = 'Call Tcode Refresh ALV'
    TABLES
      t_outtab                 = it_tstc.ENDFORM.                    "alv_display
*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*User actions on ALV
FORM user_command USING r_ucomm TYPE sy-ucomm
                        rs_selfield TYPE slis_selfield.  CASE r_ucomm.*User clicks a transaction code and that tcode is called from ALV
    WHEN '&IC1'.
      READ TABLE it_tstc INDEX rs_selfield-tabindex INTO wa_tstc.
      IF sy-subrc = 0.
        CALL TRANSACTION wa_tstc-tcode.
      ENDIF.*user clicks the refresh button and the next 25 records are displayed
    WHEN '&REFRESH'.
      PERFORM fetch_data.
      rs_selfield-refresh    = 'X'.
      rs_selfield-col_stable = 'X' .
      rs_selfield-row_stable = 'X' .
  ENDCASE.ENDFORM.                    "user_command*---------------------------------------------------------------------*
*       FORM PFSTATUS                                            *
*---------------------------------------------------------------------*
*Form for settings the pf status to the alv
FORM pfstatus USING ut_extab TYPE slis_t_extab.  SET PF-STATUS 'STANDARD_FULLSCREEN' OF PROGRAM 'SAPLKKBL'.ENDFORM.                               " PF_STATUS_SET
Regards, Venkat.O

Former Member
0 Kudos

Hi,

Please refer the codee below:



*&---------------------------------------------------------------------*
*& Report  Z_DEMO_ALVGRID                                               *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*& Example of a simple ALV Grid Report                                 *
*& ...................................                                 *
*&                                                                     *
*& The basic requirement for this demo is to display a number of       *
*& fields from the EKKO table.                                         *
*&---------------------------------------------------------------------*
REPORT  z_demo_alvgrid                 .

TABLES:     ekko.

type-pools: slis.                                 "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF t_ekko,
  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,
      gt_events     type slis_t_event,
      gd_prntparams type slis_print_alv.


************************************************************************
*Start-of-selection.
START-OF-SELECTION.

perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform build_events.
perform build_print_params.
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'.
  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-no_input          = 'X'.
  gd_layout-colwidth_optimize = 'X'.
  gd_layout-totals_text       = 'Totals'(201).
*  gd_layout-totals_only        = 'X'.
*  gd_layout-f2code            = 'DISP'.  "Sets fcode for when double
*                                         "click(press f2)
*  gd_layout-zebra             = 'X'.
*  gd_layout-group_change_edit = 'X'.
*  gd_layout-header_text       = 'helllllo'.
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_events
            is_print                = gd_prntparams
            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 table it_ekko.
endform.                    " DATA_RETRIEVAL


*-------------------------------------------------------------------*
* Form  TOP-OF-PAGE                                                 *
*-------------------------------------------------------------------*
* ALV Report Header                                                 *
*-------------------------------------------------------------------*
Form top-of-page.
*ALV Header declarations
data: t_header type slis_t_listheader,
      wa_header type slis_listheader,
      t_line like wa_header-info,
      ld_lines type i,
      ld_linesc(10) type c.

* Title
  wa_header-typ  = 'H'.
  wa_header-info = 'EKKO Table Report'.
  append wa_header to t_header.
  clear wa_header.

* Date
  wa_header-typ  = 'S'.
  wa_header-key = 'Date: '.
  CONCATENATE  sy-datum+6(2) '.'
               sy-datum+4(2) '.'
               sy-datum(4) INTO wa_header-info.   "todays date
  append wa_header to t_header.
  clear: wa_header.

* Total No. of Records Selected
  describe table it_ekko lines ld_lines.
  ld_linesc = ld_lines.
  concatenate 'Total No. of Records Selected: ' ld_linesc
                    into t_line separated by space.
  wa_header-typ  = 'A'.
  wa_header-info = t_line.
  append wa_header to t_header.
  clear: wa_header, t_line.

  call function 'REUSE_ALV_COMMENTARY_WRITE'
       exporting
            it_list_commentary = t_header.
*            i_logo             = 'Z_LOGO'.
endform.


*------------------------------------------------------------------*
*       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.
  ENDCASE.
ENDFORM.


*&---------------------------------------------------------------------*
*&      Form  BUILD_EVENTS
*&---------------------------------------------------------------------*
*       Build events table
*----------------------------------------------------------------------*
form build_events.
  data: ls_event type slis_alv_event.

  call function 'REUSE_ALV_EVENTS_GET'
       exporting
            i_list_type = 0
       importing
            et_events   = gt_events[].
  read table gt_events with key name =  slis_ev_end_of_page
                           into ls_event.
  if sy-subrc = 0.
    move 'END_OF_PAGE' to ls_event-form.
    append ls_event to gt_events.
  endif.

    read table gt_events with key name =  slis_ev_end_of_list
                           into ls_event.
  if sy-subrc = 0.
    move 'END_OF_LIST' to ls_event-form.
    append ls_event to gt_events.
  endif.
endform.                    " BUILD_EVENTS


*&---------------------------------------------------------------------*
*&      Form  BUILD_PRINT_PARAMS
*&---------------------------------------------------------------------*
*       Setup print parameters
*----------------------------------------------------------------------*
form build_print_params.
  gd_prntparams-reserve_lines = '3'.   "Lines reserved for footer
  gd_prntparams-no_coverpage = 'X'.
endform.                    " BUILD_PRINT_PARAMS


*&---------------------------------------------------------------------*
*&      Form  END_OF_PAGE
*&---------------------------------------------------------------------*
form END_OF_PAGE.
  data: listwidth type i,
        ld_pagepos(10) type c,
        ld_page(10)    type c.

  write: sy-uline(50).
  skip.
  write:/40 'Page:', sy-pagno .
endform.


*&---------------------------------------------------------------------*
*&      Form  END_OF_LIST
*&---------------------------------------------------------------------*
form END_OF_LIST.
  data: listwidth type i,
        ld_pagepos(10) type c,
        ld_page(10)    type c.

  skip.
  write:/40 'Page:', sy-pagno .
endform.

Thanks,