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: 

INTERACTIVE ALV

Former Member
0 Kudos

Hi Experts,

how we call interactive alv?

now the main problem coming to call event user command?

how we call this event?

as i call it buts its not working

like

form user_command r_ucomm like sy-ucomm

rs_selfield type slis_t_selfield_alv

case r_ucomm

when 'IC1'.

likewiseiknow each n everything thing bout tht

but problem arise tht my simple alv i s running but user_command events doed not fire.

so please give me appropriate ALV example so tht i can overcome my problem fot INTERACTIVI ALV.

thanks

rahul

4 REPLIES 4

Former Member
0 Kudos

Hi

see this sample code

report yh645_secndry_alv.

type-pools: slis.

data: fieldcat type slis_t_fieldcat_alv,

fieldcat_ln like line of fieldcat,

fs_layout type slis_layout_alv,

t_layoout like standard table

of fs_layout.

data: begin of fs_spfli,

carrid type spfli-carrid,

connid type spfli-connid,

countryfr type spfli-countryfr,

cityfrom type spfli-cityfrom,

airpfrom type spfli-airpfrom,

countryto type spfli-countryto,

cityto type spfli-cityto,

airpto type spfli-airpto,

fltime type spfli-fltime,

deptime type spfli-deptime,

arrtime type spfli-arrtime,

distance type spfli-distance,

distid type spfli-distid,

fltype type spfli-fltype,

period type spfli-period,

checkbox,

color(3),

end of fs_spfli.

data:

begin of fs_table,

carrid type spfli-carrid,

connid type spfli-connid,

end of fs_table.

data: begin of fs_sflight,

check,

color(3).

include type sflight.

data:end of fs_sflight.

data:

begin of fs_table1,

carrid type sflight-carrid,

connid type sflight-connid,

fldate type sflight-fldate,

end of fs_table1.

data:

t_spfli like standard table

of fs_spfli.

data:

t_table like standard table

of fs_table.

data:

t_table1 like standard table

of fs_table1.

data:

t_sflight like standard table

of fs_sflight.

data:

t_sbook like standard table

of sbook.

data t_layout type slis_layout_alv.

select *

into corresponding fields of table t_spfli

from spfli.

perform start_list_viewer.

perform get_spfli_details.

&----


*& Form SUB1

&----


  • text

----


  • -->RT_EXTAB text

----


form sub1 using rt_extab type slis_t_extab.

data: flight type slis_extab.

flight-fcode = 'SFLIGHT'.

append flight to rt_extab.

set pf-status 'SFLIGHT'. " EXCLUDING RT_EXTAB.

endform. "SUB1

&----


*& Form START_LIST_VIEWER

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form start_list_viewer .

data: pgm like sy-repid.

pgm = sy-repid.

fs_layout-box_fieldname = 'CHECKBOX'.

fs_layout-info_fieldname = 'COLOR'.

call function 'REUSE_ALV_LIST_DISPLAY'

exporting

i_callback_program = pgm

i_callback_pf_status_set = 'SUB1'

i_callback_user_command = 'USER_COMMAND'

i_structure_name = 'SPFLI'

is_layout = fs_layout

tables

t_outtab = t_spfli

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. " START_LIST_VIEWER

*******Process Call Back Events (Begin)**************************

form user_command using ucomm like sy-ucomm

selfield type slis_selfield.

case ucomm.

when 'SFLIGHT'.

selfield-refresh = 'X'.

perform get_spfli_details.

select *

from sflight

into corresponding fields of table t_sflight

for all entries in t_table

where carrid eq t_table-carrid

and connid eq t_table-connid.

perform display_sflight.

when 'SBOOK'.

selfield-refresh = 'X'.

perform get_sflight_details.

select *

from sbook

into corresponding fields of table t_sbook

for all entries in t_table1

where carrid eq t_table1-carrid

and connid eq t_table1-connid

and fldate eq t_table1-fldate.

perform display_sbook.

endcase.

endform. "USER_COMMAND

&----


*& Form SUB2

&----


  • text

----


  • -->RT_EXTAB text

----


form sub2 using rt_extab type slis_t_extab.

data: flight type slis_extab.

flight-fcode = 'SBOOK'.

append flight to rt_extab.

set pf-status 'SBOOK'. " EXCLUDING RT_EXTAB.

endform. "SUB2

&----


*& Form DISPLAY_SFLIGHT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form display_sflight .

data: pgm like sy-repid.

pgm = sy-repid.

clear t_layout.

fs_layout-box_fieldname = 'CHECK'.

fs_layout-info_fieldname = 'COLOR'.

call function 'REUSE_ALV_LIST_DISPLAY'

exporting

i_callback_program = pgm

i_callback_pf_status_set = 'SUB2'

i_callback_user_command = 'USER_COMMAND'

i_structure_name = 'SFLIGHT'

is_layout = fs_layout

tables

t_outtab = t_sflight

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_SFLIGHT

&----


*& Form GET_SPFLI_DETAILS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form get_spfli_details .

loop at t_spfli into fs_spfli.

if fs_spfli-checkbox = 'X'.

fs_spfli-color = 'C51'.

fs_spfli-checkbox = '1'.

fs_table-carrid = fs_spfli-carrid.

fs_table-connid = fs_spfli-connid.

append fs_table to t_table.

modify t_spfli from fs_spfli.

endif.

endloop.

endform. " GET_SFLIGHT_DETAILS

&----


*& Form GET_SFLIGHT_DETAILS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form get_sflight_details .

loop at t_sflight into fs_sflight.

if fs_sflight-check = 'X'.

fs_sflight-color = 'C71'.

fs_sflight-check = '1'.

fs_table1-carrid = fs_sflight-carrid.

fs_table1-connid = fs_sflight-connid.

fs_table1-fldate = fs_sflight-fldate.

append fs_table1 to t_table1.

modify t_sflight from fs_sflight.

endif.

endloop.

endform. " GET_SFLIGHT_DETAILS

&----


*& Form DISPLAY_SBOOK

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form display_sbook .

data: pgm like sy-repid.

pgm = sy-repid.

call function 'REUSE_ALV_LIST_DISPLAY'

exporting

i_callback_program = pgm

i_structure_name = 'SBOOK'

tables

t_outtab = t_sbook

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_SBOOK

also see the links

http://www.sapfans.com/forums/viewtopic.php?t=11601

http://www.sapfans.com/forums/viewtopic.php?t=23010

Regards

Anji

Former Member
0 Kudos

Hi Rahul,

Can you please post your code? It will help to find out the problem.

Regards,

Bharat.

Former Member
0 Kudos

Hi Rahul,

just change this WHEN 'IC1'. TO WHEN '&IC1'.

i think this is the problem.if u want i wl gv an example code.

Former Member
0 Kudos

Hi

you can refer this link

http://www.sapdev.co.uk/reporting/alvhome.htm

refer code below

u will have to make use of 'USER_COMMAND'.....

refer form user_cmd using cmd like sy-ucomm

self type slis_selfield.

report  z_purchase_req_alv no standard page heading message-id z_assg3.
 
include <icon>.
type-pools: slis.
 
tables : eban .
 
type-pools: slis .
 
types : begin of ty_pr                           ,
          icon(9)  type c                        ,
          banfn    like eban-banfn               ,   " Purachase Requisition Number
          txz01    like eban-txz01               ,   " Short Text
          ernam    like eban-ernam               ,   " CREATED BY
       end of ty_pr.
 
data : it_pr type standard table of  ty_pr,
       wa_it_pr like line of it_pr.
 
 
 
select-options s_pr for eban-banfn  no-extension obligatory .
 
data: l_report_id  like sy-repid                                       ,
      l_ws_title   type lvc_title value 'PURCHASE REQUISITION DETAILS' ,
      l_i_layout   type slis_layout_alv                                ,
      l_i_fieldcat type slis_t_fieldcat_alv                            ,
      l_it_events  type slis_t_event with header line                  ,
      l_it_header  type slis_t_listheader with header line             ,
      p_banfn      like eban-banfn                                     ,
      g_formname   type tdsfname value 'ZFM0001'                       ,
      g_fm_name    type rs38l_fnam                                     .
 
 
start-of-selection.
 
  l_report_id = sy-repid.
 
  perform sub_fetch_data   .   "  s_pr
 
  perform f1000_layout_init changing l_i_layout.
 
  perform f2000_fieldcat_init changing l_i_fieldcat.
 
  perform sub_events.
 
  call function 'REUSE_ALV_GRID_DISPLAY'
   exporting
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                =
*   I_BUFFER_ACTIVE                   = ' '
      i_callback_program                = l_report_id
      i_callback_pf_status_set          = 'STATUS1'
      i_callback_user_command           = 'USER_CMD'
     it_fieldcat                        = l_i_fieldcat
     i_save                            = 'A'
     it_events                         = l_it_events[]
    tables
      t_outtab                          = it_pr
   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 status1 using rt_extab type slis_t_extab.
 
  set pf-status 'SCREEN_SMRT_FRM' excluding rt_extab .
 
endform.                              "STATUS
 
form user_cmd using cmd  like sy-ucomm
                    self type slis_selfield.
 
  case cmd.
    when 'PRINT' .
*      PERFORM CALL_SMARTFORM .
      message i022 .
      clear cmd .
    when '&IC1' .    
      read table it_pr into wa_it_pr index self-tabindex.
      if sy-subrc = 0.
        p_banfn = wa_it_pr-banfn .
        message i023 with p_banfn.
      endif.
    when 'EXIT'.
        leave to transaction 'z_man'.
    when 'CANCLE'.
        submit z_purchase_req_alv.
 
*      CLEAR cmd .
    when others .
      clear cmd .
  endcase.
endform.                    "USER_CMD
 
 
form sub_fetch_data      .   " s_pr
 
  clear wa_it_pr .
 
  select  banfn txz01 ernam
     into corresponding fields of wa_it_pr
  from eban
     where banfn in s_pr .
 
  wa_it_pr-icon = icon_paw_pu.
 
  append wa_it_pr to it_pr  .
 
  endselect.
 
  clear wa_it_pr .
 
  sort it_pr by banfn.
 
  delete adjacent duplicates from it_pr comparing banfn.
 
endform.                    " sub_fetch_data
 
 
 
form sub_events.
  call function 'REUSE_ALV_EVENTS_GET'
    exporting
      i_list_type     = 0
    importing
      et_events       = l_it_events[]
    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.
  read table l_it_events with key name = 'TOP_OF_PAGE'.
  if sy-subrc = 0.
    l_it_events-form = 'HANDLE_TOP_OF_PAGE'.
    collect l_it_events.
  endif.
 
  l_it_header-typ  = 'H'.      " H = Header, S = Selection, A = Action
  l_it_header-info = 'LeNatures.'. " 60
  append l_it_header.
  clear  l_it_header.
 
endform.                    " sub_events
 
form f1000_layout_init using l_i_layout type slis_layout_alv.
 
  clear l_i_layout.
  l_i_layout-colwidth_optimize = 'X'.
  l_i_layout-edit = 'X'.
 
endform.                    " F1000_Layout_Init
 
form f2000_fieldcat_init changing l_i_fieldcat type slis_t_fieldcat_alv.
 
  data: l_line_fieldcat type slis_fieldcat_alv.
 
  clear l_line_fieldcat.
  l_line_fieldcat-fieldname    = 'ICON'.
  l_line_fieldcat-tabname      = 'IT_PR'.
  l_line_fieldcat-ddictxt      = 'M'.
  l_line_fieldcat-reptext_ddic = ' '.
  l_line_fieldcat-icon         = 'X'.
  l_line_fieldcat-hotspot      = 'X'.
  l_line_fieldcat-outputlen    =  2.
  append l_line_fieldcat to l_i_fieldcat.
 
 
  clear l_line_fieldcat.
  l_line_fieldcat-fieldname = 'BANFN'.
  l_line_fieldcat-tabname   = 'IT_PR'.
  l_line_fieldcat-seltext_m = 'PURCHASE REQUISITION NUMBER'.
  append l_line_fieldcat to l_i_fieldcat.
 
  clear l_line_fieldcat.
  l_line_fieldcat-fieldname = 'TXZ01'.
  l_line_fieldcat-tabname = 'IT_PR'.
  l_line_fieldcat-seltext_m = 'DESCRIPTION'.
  append l_line_fieldcat to l_i_fieldcat.
 
  clear l_line_fieldcat.
  l_line_fieldcat-fieldname = 'ERNAM'.
  l_line_fieldcat-tabname   = 'IT_PR'.
  l_line_fieldcat-seltext_m = 'CREATED BY'.
  append l_line_fieldcat to l_i_fieldcat.
 
 
endform.                    " f2000_fieldcat_init
 
form handle_top_of_page.
 
  call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
      i_logo             = ''
      it_list_commentary = l_it_header[].
 
endform.                    "handle_top_of_page
 
 
form call_smartform .
 
  call function 'SSF_FUNCTION_MODULE_NAME'
    exporting
      formname                 = g_formname
*   VARIANT                  = ' '
*   DIRECT_CALL              = ' '
    importing
      fm_name                  = g_fm_name
   exceptions
     no_form                  = 1
     no_function_module       = 2
     others                   = 3
            .
  if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.
 
  call function g_fm_name
    exporting
*   ARCHIVE_INDEX              =
*   ARCHIVE_INDEX_TAB          =
*   ARCHIVE_PARAMETERS         =
*   CONTROL_PARAMETERS         =
*   MAIL_APPL_OBJ              =
*   MAIL_RECIPIENT             =
*   MAIL_SENDER                =
*   OUTPUT_OPTIONS             =
*   USER_SETTINGS              = 'X'
      i_eban                     = p_banfn
* IMPORTING
*   DOCUMENT_OUTPUT_INFO       =
*   JOB_OUTPUT_INFO            =
*   JOB_OUTPUT_OPTIONS         =
 
   exceptions
     formatting_error           = 1
     internal_error             = 2
     send_error                 = 3
     user_canceled              = 4
     others                     = 5
            .
  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.                    " CALL_SMARTFORM