‎2007 Feb 28 7:10 AM
Hi,
I want to know how to use USER_COMMAND in alv grid. I want when I click on any field of alv grid columns , it open different screen as a alv grid format.
‎2007 Feb 28 7:20 AM
Hi Rakesh,
Follow the code.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = v_repid
i_callback_user_command = 'USER_COMMAND1' <-------
is_layout = wa_layout
it_fieldcat = i_fcat
i_default = c_chk
i_save = c_save
is_variant = wa_variant
it_events = i_events
is_print = wa_print
TABLES
t_outtab = i_table
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
LEAVE LIST-PROCESSING.
ENDIF.
Form user_command1 using rs_selfield type slis_selfield
u_comm like sy-ucomm.
case '%IC1'.
When '...'.
............
..............
endcase.
‎2007 Feb 28 7:11 AM
Hi rakesh,
1. In alv we cannot use AT LINE Selection
2. For alv, there is a special syntax, so that when we double-click on alv,
our FORM / routine is called and there we display another alv.
3. just copy paste to get a taste of interactive alv.
4.
REPORT abc.
TYPE-POOLS : slis.
*----
Data
DATA : ITAB LIKE T001 OCCURS 0 WITH HEADER LINE.
DATA : alvfc TYPE slis_t_fieldcat_alv.
DATA : STAB LIKE T001 OCCURS 0 WITH HEADER LINE.
*----
Select Data
SELECT * FROM t001 INTO TABLE itab.
*------- Field Catalogue
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_internal_tabname = 'ITAB'
i_inclname = sy-repid
CHANGING
ct_fieldcat = alvfc
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
*----
Display
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = alvfc
i_callback_program = sy-repid "<-------Important
i_callback_user_command = 'ITAB_USER_COMMAND' "<------ Important
TABLES
t_outtab = itab
EXCEPTIONS
program_error = 1
OTHERS = 2.
*----
CALL BACK FORM
*----
FORM itab_user_command USING whatcomm TYPE sy-ucomm whatrow TYPE
slis_selfield.
*----
IMPORTANT.
READ TABLE ITAB INDEX WHATROW-TABINDEX.
*
CLEAR STAB.
SELECT * FROM T001
INTO TABLE STAB
WHERE BUKRS = ITAB-BUKRS.
CLEAR ALVFC.
*------- Field Catalogue
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_internal_tabname = 'STAB'
i_inclname = sy-repid
CHANGING
ct_fieldcat = alvfc
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
*----
Display
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = alvfc
i_callback_program = sy-repid "<-------Important
TABLES
t_outtab = Stab
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. "ITAB_user_command
regards,
amit m.
‎2007 Feb 28 7:14 AM
Refer this
http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_ucomm.htm
http://www.sapdevelopment.co.uk/reporting/alv/alvgrid.htm
Reward if this helps.
‎2007 Feb 28 7:20 AM
Hi Rakesh,
Follow the code.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = v_repid
i_callback_user_command = 'USER_COMMAND1' <-------
is_layout = wa_layout
it_fieldcat = i_fcat
i_default = c_chk
i_save = c_save
is_variant = wa_variant
it_events = i_events
is_print = wa_print
TABLES
t_outtab = i_table
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
LEAVE LIST-PROCESSING.
ENDIF.
Form user_command1 using rs_selfield type slis_selfield
u_comm like sy-ucomm.
case '%IC1'.
When '...'.
............
..............
endcase.
‎2007 Feb 28 7:34 AM
refer code below,
report z_purchase_req_alv no standard page heading message-id zabc_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' "<-User command
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* i_structure_name = ' '
* I_BACKGROUND_ID = ' '
* i_grid_title = ' '
* I_GRID_SETTINGS =
** is_layout = l_i_layout
it_fieldcat = l_i_fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
i_save = 'A'
* IS_VARIANT =
it_events = l_it_events[]
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IT_ALV_GRAPHICS =
* IT_ADD_FIELDCAT =
* IT_HYPERLINK =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
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
reward if useful
‎2007 Feb 28 8:29 AM
hi,
follow this logic:
*Perform at_user_command.
first create form at_user_command and pass this formname to the parameter I_AT_user_command of the FM Reuse_alv_grid_display.
form at_user_command using ucomm1 like sy-ucomm
selfield type slis_selfield.
use the code for capturing the code when clicked on a fieldname or line.
endform.
this should resolve the issue.
regards,
shamim