2006 Sep 29 7:31 AM
can any one please hv a look at the code and tell me why the data in the grid is not sorted.
Regards
report ztst_chin_alv3.
----
tables : lfb1.
----
Declarations *
----
selection-screen begin of block a with frame title text-001.
select-options : bukrs for lfb1-bukrs.
select-options : lifnr for lfb1-lifnr.
selection-screen end of block a.
data: r_container type ref to cl_gui_custom_container.
data: r_grid type ref to cl_gui_alv_grid.
data: g_fieldcat type lvc_t_fcat.
data: w_fieldcat like line of g_fieldcat.
data: g_layout type lvc_s_layo.
data: ok_code like sy-ucomm.
data: gs_variant type disvariant.
data: t_selected type lvc_t_row.
data wa_selected like line of t_selected.
data: it_items like eban occurs 0.
data: t_sort type lvc_t_sort.
data: s_sort type lvc_s_sort.
data: begin of it_lfb1 occurs 0,
lifnr like lfb1-lifnr,
bukrs like lfb1-bukrs,
akont like lfb1-akont,
fdgrv like lfb1-fdgrv,
end of it_lfb1.
s_sort-spos = '1'.
s_sort-fieldname = 'FGDRV'.
s_sort-up = 'X'.
append s_sort to t_sort.
clear s_sort.
----
Initialization *
----
initialization.
at selection-screen.
ok_code = sy-ucomm.
case ok_code.
when 'BACK'.
leave program.
when 'CANCEL'.
leave program.
when 'EXIT'.
leave program.
when 'ONLI' or 'CRET'.
call screen 100.
when others.
endcase.
----
GetData *
----
module getdata output.
if sy-ucomm <> 'STOP'.
*refresh control container_1 from screen scr.
refresh it_lfb1.
clear bukrs.
clear lifnr.
select lifnr bukrs akont fdgrv
into corresponding fields of table it_lfb1
from lfb1
where
bukrs in bukrs
and lifnr in lifnr.
endif.
refresh bukrs.
refresh lifnr.
endmodule.
----
Create ALV *
----
module create_alv output.
gs_variant-report = sy-repid.
if r_container is initial.
create object r_container
exporting container_name = 'CONTAINER_1'.
create object r_grid
exporting i_parent = r_container.
endif.
*modify the headings in the field catalogue
call function 'LVC_FIELDCATALOG_MERGE'
exporting
i_structure_name = 'ztest_alv'
changing
ct_fieldcat = g_fieldcat[].
loop at g_fieldcat into w_fieldcat.
case w_fieldcat-fieldname.
when 'ZCURSTAT'.
w_fieldcat-scrtext_l = 'Prev.RelCode'.
w_fieldcat-scrtext_m = 'Prev.RelCode'.
w_fieldcat-scrtext_s = 'Prev.RelCode'.
w_fieldcat-reptext = 'Prev.RelCode'.
endcase.
modify g_fieldcat from w_fieldcat.
endloop.
call method r_grid->set_table_for_first_display
exporting
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE =
I_CONSISTENCY_CHECK =
i_structure_name = 'ztest_alv'
is_variant = gs_variant
i_save = 'A'
I_DEFAULT = 'X'
is_layout = g_layout
IS_PRINT =
IT_SPECIAL_GROUPS =
IT_TOOLBAR_EXCLUDING =
IT_HYPERLINK =
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
changing
it_outtab = it_lfb1[]
it_fieldcatalog = g_fieldcat[]
it_sort = t_sort[]
IT_FILTER =
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
TOO_MANY_LINES = 3
others = 4.
.
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 method r_grid->set_table_for_first_display
exporting i_structure_name = 'ztest_alv'
is_layout = g_layout
is_variant = gs_variant
i_save = 'A'
changing it_outtab = it_lfb1[]
it_fieldcatalog = g_fieldcat[].
*
*ELSE.
*
CALL METHOD r_grid->refresh_table_display
EXPORTING i_soft_refresh = ' '.
*
endmodule.
----
STATUS *
----
module status output.
set pf-status '0100'.
endmodule.
----
User Commands *
----
module user_command input.
ok_code = sy-ucomm.
case ok_code.
when 'BACK'.
call screen '1000'.
when 'CANCEL'.
leave program.
when 'EXIT'.
leave program.
endcase.
endmodule.
----
ALV Layout *
----
module layout output.
g_layout-zebra = 'X'.
g_layout-sel_mode = 'A'.
g_layout-grid_title = ''.
g_layout-detailtitl = ''.
endmodule.
----
Select Rows *
----
form get_selected_rows.
call method r_grid->get_selected_rows
importing et_index_rows = t_selected.
if t_selected is initial.
call function 'WS_MSG'
exporting
msg_type = 'E'
text = 'Select Line'
titl = 'Select Line'.
sy-ucomm = 'STOP'.
endif.
endform.
2006 Sep 29 8:45 AM
i am not clear.
In the given code u gave it before initialization.
give after building the fieldcat.
2006 Sep 29 7:42 AM
give after start-of-selection before set_table_for_first_display
2006 Sep 29 7:58 AM
2006 Sep 29 8:17 AM
Give this code after creating the value in Itab and getnerating the fieldcat.
Perform Get_data.
Perform Build_Fieldcat.
after this...
perform Sort_Itab.
Form Sort_Itab.
data s_Sort type lvc_s_sort.
s_sort-spos = '1'.
s_sort-fieldname = 'FGDRV'.
s_sort-up = 'X'.
append s_sort to t_sort.
clear s_sort.
Endform.
2006 Sep 29 8:27 AM
2006 Sep 29 8:45 AM
i am not clear.
In the given code u gave it before initialization.
give after building the fieldcat.
2006 Sep 29 9:16 AM
Hi,
are you sure t_sort has the real values.
set a break-point directly before
SET_TABLE_FOR_FIRST_DISPLAY and look
via the debugger in the table t_sort.
I think its better to fill t_sort
in module create_alv output
Regards, dieter