SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Double click on a ALV grid and call a new transaction



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ALV Grid / ALV Tree / ALV List
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Sat Sep 22, 2007 7:38 pm    Post subject: Double click on a ALV grid and call a new transaction Reply with quote

Code:
report  sy-repid.

type-pools : slis.

*ALV Formatting tables /structures
data: gt_fieldcat type slis_t_fieldcat_alv.
data: gt_events type slis_t_event.
data: gs_layout type slis_layout_alv.
data: gt_page   type slis_t_listheader.
data: gs_page type slis_listheader.
data: v_repid like sy-repid.

*ALV Formatting work area
data: w_fieldcat type slis_fieldcat_alv.
data: w_events type slis_alv_event.

data: gt_bsid type table of bsid with header line.

initialization.

perform build_events.

*H = Header, S = Selection, A = Action

gs_page-typ = 'H'.
gs_page-key = '001'.
gs_page-info = 'Header 1'.
append gs_page to gt_page.

gs_page-typ = 'H'.
gs_page-key = '002'.
gs_page-info = 'Header 2'.
append gs_page to gt_page.

gs_page-typ = 'S'.
gs_page-key = '001'.
gs_page-info = 'Sel 1'.
append gs_page to gt_page.

start-of-selection.
*perform build_comment.     "top_of_page
*perform build_layout_and_fieldcat.
select * from bsid into table gt_bsid up to 10 rows.

*USING - Row, Column, Field name, display length, table name, heading
*  perform populate_for_fm
*                        using: '1' '3' 'BUKRS' '8' 'I_OUTPUT' 'Whee'.
*OR
perform build_fieldcat.
gs_layout-zebra = 'X'.
*gs_layout-no_keyfix = 'X'.

*top of page event does not work without I_callback_program
v_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
  exporting
    i_callback_program                = v_repid
    i_structure_name                  = 'BSID'
*    i_background_id                   = 'ALV_BACKGROUND'
    i_grid_title                      = 'This is the grid title'
*   I_GRID_SETTINGS                   =
    is_layout                         = gs_layout
    it_fieldcat                       = gt_fieldcat[]
    it_events                         = gt_events[]
  tables
    t_outtab                          = gt_bsid
* 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..............:       populate_for_fm
* Description.......:  Populates fields for function module used in ALV
* Called by.........:       Load_fm
* Calls.............:       N/A
************************************************************************
*Can do the fieldcat this way if you prefer
form populate_for_fm using    p_row
                                    p_col
                                    p_fieldname
                                    p_len
                                    p_table
                                    p_desc.
  w_fieldcat-row_pos = p_row.          "Row Position
  w_fieldcat-col_pos = p_col.          "Column Position
  w_fieldcat-fieldname = p_fieldname.  "Field name
  w_fieldcat-outputlen = p_len.        "Column Lenth
  w_fieldcat-tabname = p_table.        "Table name
  w_fieldcat-reptext_ddic = p_desc.    "Field Description
  w_fieldcat-input = '1'.
  append w_fieldcat to gt_fieldcat.
  clear w_fieldcat.

endform.                    " populate_for_fm
*&---------------------------------------------------------------------*
*&      Form  build_events
*&---------------------------------------------------------------------*
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_user_command
                           into ls_event.
  if sy-subrc = 0.
    move slis_ev_user_command to ls_event-form.
    append ls_event to gt_events.
  endif.
  read table gt_events with key name =  slis_ev_top_of_page
                           into ls_event.
  if sy-subrc = 0.
    move slis_ev_top_of_page to ls_event-form.
    append ls_event to gt_events.
  endif.

endform.                    " build_events
*&---------------------------------------------------------------------*
*&      Form  USER_COMMAND
*&---------------------------------------------------------------------*
form user_command using  r_ucomm      like sy-ucomm
                         rs_selfield type slis_selfield.
* When user command is called it uses the above parameters. The itab
* passed to the ALV is in whatever order it currently is on screen.
* Therefore, you can read table itab index rs_selfield-tabindex to get
* all data from the table. You can also check r_ucomm and code
* accordingly.
read table gt_bsid index rs_selfield-tabindex.
set parameter id 'KUN' field gt_bsid-kunnr.
call transaction 'XD03' and skip first screen.
endform.
*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
form top_of_page.

call function 'REUSE_ALV_COMMENTARY_WRITE'
  exporting
    it_list_commentary       = gt_page
    i_logo                   = 'ENJOY_SAP'.
* Your own company logo can go here if it has been saved (OAOR)
endform.
*&---------------------------------------------------------------------*
*&      Form  build_fieldcat
*&---------------------------------------------------------------------*
form build_fieldcat.
*Many and varied fields are available here. Have a look at documentation
*for FM REUSE_ALV_LIST_DISPLAY and REUSE_ALV_FIELDCATALOG_MERGE

  w_fieldcat-fieldname = 'BUDAT'.
  w_fieldcat-seltext_m = 'Dte pst'.
  w_fieldcat-ddictxt(1) = 'M'.
  w_fieldcat-row_pos = '1'.
  w_fieldcat-col_pos = '10'.
  append w_fieldcat to gt_fieldcat.
  clear w_fieldcat.

endform.                    " build_fieldcat


PS: This example processed all events
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ALV Grid / ALV Tree / ALV List All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.