10-23-2007 6:34 AM
hi friends,
i am using factory method to display my alv. now some of the fields in my internal table i have declared them as char fields, i want certain type of headings for these fields,so where can i give heading to these fields.
where exactly do we create a field catalog for factory method.
pls advice me on this
10-23-2007 6:54 AM
Hi
We can change some of the attributes of a specific column in the ALV grid. In this example we change the Heading Text of a column as well as the color of a column. Create the object reference variable and receive the object using the GET_COLUMNS method of the GR_TABLE object. This will pass you the object for all columns of the ALV grid. To access just one column, call the method GET_COLUMN from the GR_COLUMNS object. In this example, we are accessing the CITYTO column and the CITYFROM column.
Refer to the foloowing code:
report zalvom_demo1.
data: ispfli type table of spfli.
data: gr_table type ref to cl_salv_table.
data: gr_functions type ref to cl_salv_functions.
data: gr_display type ref to cl_salv_display_settings.
data: gr_columns type ref to cl_salv_columns_table. data: gr_column type ref to cl_salv_column_table.
data: color type lvc_s_colo.
start-of-selection.
select * into table ispfli from spfli.
cl_salv_table=>factory
( importing r_salv_table = gr_table changing t_table = ispfli ).
gr_functions = gr_table->get_functions( ).
gr_functions->set_all( abap_true ).
gr_display = gr_table->get_display_settings( ).
gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
gr_display->set_list_header( 'This is the heading' ).
gr_columns = gr_table->get_columns( ).
gr_column ?= gr_columns->get_column( 'CITYTO' ).
gr_column->set_long_text( 'This is long text' ). gr_column->set_medium_text( 'This is med text' ).
gr_column->set_short_text( 'This is sh' ).
gr_column ?= gr_columns->get_column( 'CITYFROM' ).
color-col = '6'.
color-int = '1'.
color-inv = '0'.
gr_column->set_color( color ).
gr_table->display( ).
Thanks,
Vasudha L
Message was edited by:
Vasudha L
Message was edited by:
Vasudha L
Message was edited by:
Vasudha L
Message was edited by:
Vasudha L
10-23-2007 7:24 AM
hi
good
go throgh this code
&----
*& Report Z_ALV_OOPS
*&
&----
*&
*&
&----
REPORT Z_ALV_OOPS.
*Event class Definition "Event handler class
class event_handle definition.
public section.
methods: handle_user
for event user_command of cl_gui_alv_grid
importing e_ucomm.
endclass.
*Event class Implementation
class event_handle implementation.
method handle_user.
write:/ ''.
endmethod.
endclass.
Data: t_alv type ref to cl_gui_alv_grid, "ALV control
t_cont type ref to cl_gui_custom_container, "Cust Container
t_alv2 type ref to cl_gui_alv_grid, "ALV control
t_cont2 type ref to cl_gui_custom_container, "Cust Container
t_fieldcat type lvc_t_fcat with header line, "Field Cat
t_fieldcat2 type lvc_t_fcat with header line, "Field Cat
t_layout type lvc_s_layo, "Layout
t_event type ref to event_handle, "Event handler
t_sort type LVC_T_SORT with header line, "Sort
t_toolbar type ui_functions with header line. "Toolbar xclude
Types: begin of g_vbak, "Header Table
vbeln like vbak-vbeln,
auart like vbak-auart,
vkorg like vbak-vkorg,
vtweg like vbak-vtweg,
spart like vbak-spart,
kunnr like vbak-kunnr,
bstnk like vbak-bstnk,
seltab,
end of g_vbak.
Types: begin of g_vbap, "Item Table
vbeln like vbap-vbeln,
posnr(6) type c,
posrn like vbap-posnr,
matnr like vbap-matnr,
netwr like vbap-netwr,
waerk like vbap-waerk,
end of g_vbap.
Data: t_vbak type g_vbak occurs 0,
t_vbap type g_vbap occurs 0.
Start-Of-Selection.
*Fetch data from DB Table
select vbeln auart vkorg vtweg spart kunnr bstnk
from vbak into table t_vbak up to 20 rows.
End-Of-Selection.
*Call ALV screen
call screen 100.
&----
*& Module STATUS_0100 OUTPUT
&----
text
----
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'ALV'.
SET TITLEBAR 'VBAK'.
if t_cont is initial.
create object t_cont
exporting
container_name = 'ALV'.
create object t_alv
exporting
i_parent = t_cont.
*Create event handlers
create object t_event.
set handler t_event->handle_user for t_alv.
perform build_fieldcatlog.
perform build_layout.
perform xclude_toolbar.
CALL METHOD t_alv->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_BUFFER_ACTIVE =
I_BYPASSING_BUFFER =
I_CONSISTENCY_CHECK =
I_STRUCTURE_NAME =
IS_VARIANT =
I_SAVE =
I_DEFAULT = 'X'
IS_LAYOUT = t_layout
IS_PRINT =
IT_SPECIAL_GROUPS =
IT_TOOLBAR_EXCLUDING = t_toolbar[]
IT_HYPERLINK =
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
CHANGING
IT_OUTTAB = t_vbak[]
IT_FIELDCATALOG = t_fieldcat[]
IT_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.
endif.
ENDMODULE. " STATUS_0100 OUTPUT
&----
*& Module USER_COMMAND_0100 INPUT
&----
text
----
MODULE USER_COMMAND_0100 INPUT.
Data: lt_rows type lvc_t_row,
wa_rows type line of lvc_t_row,
wa_vbak type g_vbak,
l_lines type i.
refresh: t_vbap.
case sy-ucomm.
when 'DET'. "Item details
Get selected rows from ALV
call method t_alv->get_selected_rows
importing
et_index_rows = lt_rows.
Fetch corresponding Item details from VBAP
loop at lt_rows into wa_rows.
read table t_vbak into wa_vbak index wa_rows-index transporting
vbeln.
select vbeln posnr matnr netwr waerk from vbap
appending corresponding fields of table t_vbap
where vbeln = wa_vbak-vbeln.
endloop.
Prepare fieldcatlog
Display Item details in ALV
call screen 200 starting at 8 5.
when 'SHOW'. "Display order
call method t_alv->get_selected_rows
importing
et_index_rows = lt_rows.
Describe table lt_rows lines l_lines.
if l_lines > 1.
message e999(z_error).
else.
read table lt_rows into wa_rows index 1.
read table t_vbak into wa_vbak index wa_rows-index transporting
vbeln.
set parameter id 'AUN' field wa_vbak-vbeln.
call transaction 'VA03' and skip first screen.
endif.
endcase.
ENDMODULE. " USER_COMMAND_0100 INPUT
&----
*& Form build_fieldcatlog
&----
text
----
----
form build_fieldcatlog .
clear t_fieldcat.
t_fieldcat-col_pos = '1'.
t_fieldcat-fieldname = 'VBELN'.
t_fieldcat-ref_table = 'VBAK'.
t_fieldcat-ref_field = 'VBELN'.
append t_fieldcat.
t_fieldcat-col_pos = '2'.
t_fieldcat-fieldname = 'AUART'.
t_fieldcat-ref_table = 'VBAK'.
t_fieldcat-ref_field = 'AUART'.
append t_fieldcat.
t_fieldcat-col_pos = '3'.
t_fieldcat-fieldname = 'VKORG'.
t_fieldcat-ref_table = 'VBAK'.
t_fieldcat-ref_field = 'VKORG'.
append t_fieldcat.
t_fieldcat-col_pos = '4'.
t_fieldcat-fieldname = 'VTWEG'.
t_fieldcat-ref_table = 'VBAK'.
t_fieldcat-ref_field = 'VTWEG'.
append t_fieldcat.
t_fieldcat-col_pos = '5'.
t_fieldcat-fieldname = 'SPART'.
t_fieldcat-ref_table = 'VBAK'.
t_fieldcat-ref_field = 'SPART'.
append t_fieldcat.
t_fieldcat-col_pos = '6'.
t_fieldcat-fieldname = 'KUNNR'.
t_fieldcat-ref_table = 'VBAK'.
t_fieldcat-ref_field = 'KUNNR'.
append t_fieldcat.
t_fieldcat-col_pos = '7'.
t_fieldcat-fieldname = 'BSTNK'.
t_fieldcat-ref_table = 'VBAK'.
t_fieldcat-ref_field = 'BSTNK'.
append t_fieldcat.
endform. " build_fieldcatlog
&----
*& Module LEAVE INPUT
&----
text
----
module LEAVE input.
case sy-ucomm.
when 'BACK' or 'EXIT' or 'CANCEL'.
leave program.
endcase.
endmodule. " LEAVE INPUT
&----
*& Form build_layout
&----
text
----
--> p1 text
<-- p2 text
----
form build_layout .
t_layout-zebra = 'X'.
t_layout-sel_mode = 'A'.
t_layout-grid_title = 'Header Details'.
endform. " build_layout
&----
*& Form build_fcat_vbap
&----
text
----
----
form build_fcat_vbap .
clear t_fieldcat2.
t_fieldcat2-scrtext_m = 'Sales Doc'.
t_fieldcat2-col_pos = 1.
t_fieldcat2-fieldname = 'VBELN'.
t_fieldcat2-tabname = 'T_VBAP'.
t_fieldcat2-no_zero = 'X'.
t_fieldcat2-ref_table = 'VBAP'.
t_fieldcat2-ref_field = 'VBELN'.
append t_fieldcat2.
clear t_fieldcat2.
t_fieldcat2-col_pos = 2.
t_fieldcat2-scrtext_m = 'Item'.
t_fieldcat2-fieldname = 'POSNR'.
t_fieldcat2-tabname = 'T_VBAP'.
t_fieldcat2-intlen = '6'.
t_fieldcat2-inttype = 'C'.
t_fieldcat2-no_zero = 'X'.
t_fieldcat2-ref_table = 'VBAP'.
t_fieldcat2-ref_field = 'POSNR'.
append t_fieldcat2.
clear t_fieldcat2.
t_fieldcat2-col_pos = 3.
t_fieldcat2-fieldname = 'MATNR'.
t_fieldcat2-ref_table = 'VBAP'.
t_fieldcat2-ref_field = 'MATNR'.
append t_fieldcat2.
clear t_fieldcat2.
t_fieldcat2-col_pos = 4.
t_fieldcat2-fieldname = 'NETWR'.
t_fieldcat2-ref_table = 'VBAP'.
t_fieldcat2-ref_field = 'NETWR'.
t_fieldcat2-do_sum = 'X'.
append t_fieldcat2.
clear t_fieldcat2.
t_fieldcat2-col_pos = 5.
t_fieldcat2-fieldname = 'WAERK'.
t_fieldcat2-ref_table = 'VBAP'.
t_fieldcat2-ref_field = 'WAERK'.
append t_fieldcat2.
endform. " build_fcat_vbap
&----
*& Module STATUS_0200 OUTPUT
&----
text
----
module STATUS_0200 output.
SET PF-STATUS 'ITEM1'.
SET TITLEBAR 'VBAP'.
perform build_fcat_vbap.
perform sort_alv2.
if t_cont2 is initial.
create object t_cont2
exporting
container_name = 'ITEM'.
create object t_alv2
exporting
i_parent = t_cont2.
t_layout-grid_title = 'Item Details'.
CALL METHOD t_alv2->set_table_for_first_display
EXPORTING
I_BUFFER_ACTIVE =
I_BYPASSING_BUFFER =
I_CONSISTENCY_CHECK =
I_STRUCTURE_NAME =
IS_VARIANT =
I_SAVE =
I_DEFAULT = 'X'
IS_LAYOUT = t_layout
IS_PRINT =
IT_SPECIAL_GROUPS =
IT_TOOLBAR_EXCLUDING = t_toolbar[]
IT_HYPERLINK =
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
IR_SALV_ADAPTER =
CHANGING
it_outtab = t_vbap[]
IT_FIELDCATALOG = t_fieldcat2[]
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.
else.
CALL METHOD t_alv2->refresh_table_display
EXPORTING
IS_STABLE =
I_SOFT_REFRESH =
EXCEPTIONS
FINISHED = 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.
endif.
endmodule. " STATUS_0200 OUTPUT
&----
*& Module USER_COMMAND_0200 INPUT
&----
text
----
module USER_COMMAND_0200 input.
case sy-ucomm.
when 'GOBACK'.
leave to screen 0.
endcase.
endmodule. " USER_COMMAND_0200 INPUT
&----
*& Form sort_alv2
&----
text
----
--> p1 text
<-- p2 text
----
form sort_alv2 .
clear t_sort.
t_sort-spos = '1'.
t_sort-fieldname = 'VBELN'.
t_sort-up = 'X'.
t_sort-subtot = 'X'.
append t_sort.
endform. " sort_alv2
&----
*& Form xclude_toolbar
&----
text
----
--> p1 text
<-- p2 text
----
form xclude_toolbar .
t_toolbar = '&DETAIL'.
append t_toolbar.
t_toolbar = '&&SEP00'.
append t_toolbar.
t_toolbar = '&&SEP01'.
append t_toolbar.
t_toolbar = '&&SEP02'.
append t_toolbar.
t_toolbar = '&SORT_ASC'.
append t_toolbar.
t_toolbar = '&SORT_DSC'.
append t_toolbar.
t_toolbar = '&FIND'.
append t_toolbar.
t_toolbar = '&MB_FILTER'.
append t_toolbar.
t_toolbar = '&&SEP04'.
append t_toolbar.
t_toolbar = '&MB_SUM'.
append t_toolbar.
t_toolbar = '&MB_SUB_TOTAL'.
append t_toolbar.
t_toolbar = '&PRINT_BACK'.
append t_toolbar.
t_toolbar = '&MB_VIEW'.
append t_toolbar.
t_toolbar = '&MB_EXPORT'.
append t_toolbar.
t_toolbar = '&GRAPH'.
append t_toolbar.
t_toolbar = '&COLO'.
append t_toolbar.
t_toolbar = '&&SEP06'.
append t_toolbar.
t_toolbar = '&&SEP07'.
append t_toolbar.
t_toolbar = '&INFO'.
append t_toolbar.
t_toolbar = '&&SEP03'.
append t_toolbar.
endform. " xclude_toolbar
reward point if helpful.
thanks
mrutyun^