Aisha Ishrat
Registered user
Global user
Registered: 02-2007
Posts: 5
Karma: 0 (+0/-0)
|
|
Reply | Quote
|
|
Problem in ALV Grid
This is my first program using ALV.The problem is that ALV Grid appears but it does not show any value , just a wrong value appears in last column.The output internal table is TAB_2.
Kindly do tell me what is the issue.
Thanks.
*&---------------------------------------------------------------------*
*& Report ZDEMO_ALVGRID *
*& *
*&---------------------------------------------------------------------*
*& *
*& Example of a simple ALV Grid Report *
*& ................................... *
*& *
*& The basic requirement for this demo is to display a number of *
*& fields from the ZSTATS_CUML2 table.
*&---------------------------------------------------------------------*
REPORT zdemo_alvgrid .
TABLES: ZSTATS_CUML2.
type-pools: slis. "ALV Declarations
*Data Declaration
*----------------
Parameters: p_date like ZSTATS_CUML2-zdate ,
p_user like ZSTATS_CUML2-account,
p_tcode like ZSTATS_CUML2-tcode.
Data: Begin of tab_1 occurs 100,
tcode(12) type c,
logindate type d,
username(25) type c,
responsetime type i,
end of tab_1,
Begin of tab_2 occurs 100,
tcode(12) type c,
logindate type d,
username(25) type c,
avg_responsetime type p,
SD type p,
end of tab_2,
tcode(12) type c,
logindate type d,
username(25) type c,
avgresponsetime type p,
no_of_entries type i,
check type i,
Begin of sd_table occurs 100,
x type p,
end of sd_table.
*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.
************************************************************************
*Start-of-selection.
START-OF-SELECTION.
perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
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 = 'tcode'.
fieldcatalog-seltext_m = 'T-Code'.
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 = 'logindate'.
fieldcatalog-seltext_m = 'Login Date'.
fieldcatalog-col_pos = 1.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'username'.
fieldcatalog-seltext_m = 'SAP ID'.
fieldcatalog-col_pos = 2.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'avg_responsetime'.
fieldcatalog-seltext_m = 'Response Time'.
fieldcatalog-col_pos = 3.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'SD'.
fieldcatalog-seltext_m = 'standard deviation'.
fieldcatalog-col_pos = 4.
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_XEVENTS
i_save = 'X'
* is_variant = z_template
tables
t_outtab = tab_2
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 * from ZSTATS_CUML2 where Not tcode = ''and tcode = p_tcode and
zdate = p_date and account = p_user.
tab_1-tcode = ZSTATS_CUML2-tcode.
tab_1-logindate = ZSTATS_CUML2-zdate.
tab_1-username = ZSTATS_CUML2-account.
tab_1-responsetime = ZSTATS_CUML2-respti.
append tab_1 to tab_1.
endselect.
Loop at tab_1.
*write:/ tab_1-tcode,tab_1-logindate,tab_1-username,tab_1-responsetime.
endloop.
loop at tab_1.
no_of_entries = 0.
avgresponsetime = 0.
check = 0.
* put one entry
tcode = tab_1-tcode.
logindate = tab_1-logindate.
username = tab_1-username.
* check tab_2
loop at tab_2.
if tab_2-tcode = tcode.
if tab_2-logindate = logindate.
if tab_2-username = username.
check = 1.
endif.
endif.
endif.
endloop.
* check tab_1 for similar entries
if check = 0.
loop at tab_1.
if tab_1-tcode = tcode.
if tab_1-logindate = logindate .
if tab_1-username = username.
no_of_entries = no_of_entries + 1.
avgresponsetime = avgresponsetime + tab_1-responsetime.
sd_table-x = tab_1-responsetime.
append sd_table to sd_table.
endif.
endif.
endif.
endloop.
tab_2-tcode = tcode.
tab_2-logindate = logindate.
tab_2-username = username.
tab_2-avg_responsetime = avgresponsetime / no_of_entries.
tab_2-SD = SQRT( sd_table-x ).
append tab_2 to tab_2.
endif.
*refresh sd_table.
endloop.
*write contents of tab_2 that contains limited entries.
loop at tab_2.
*write: / tab_2-tcode, tab_2-logindate , tab_2-username,
*tab_2-avg_responsetime.
endloop.
endform. " DATA_RETRIEVAL
|
|
2/1/2007, 10:18 am
|
Send Email to Aisha Ishrat
Send PM to Aisha Ishrat
|
sapdev
Head Administrator
Global user
Registered: 07-2004
Posts: 56
Karma: 0 (+0/-0)
|
|
Reply | Quote
|
|
Re: Problem in ALV Grid
Hi there,
try putting your alv fieldname declarations in upper case:
i.e.
fieldcatalog-fieldname = 'tcode'.
should be
fieldcatalog-fieldname = 'TCODE'.
fieldcatalog-fieldname = 'logindate'.
should be
fieldcatalog-fieldname = 'LOGINDATE'.
etc etc..
Regards
Martin
|
|
2/1/2007, 3:46 pm
|
Send Email to sapdev
Send PM to sapdev
Blog
|
Aisha Ishrat
Registered user
Global user
Registered: 02-2007
Posts: 5
Karma: 0 (+0/-0)
|
|
Reply | Quote
|
|
Re: Problem in ALV Grid
Yes , it works.
Thanks.
|
|
2/2/2007, 3:50 am
|
Send Email to Aisha Ishrat
Send PM to Aisha Ishrat
|