01-30-2007 9:43 AM
hi
In alv,the heading has to be displayed in the center , and the address has to be right aligned,how???
01-30-2007 9:50 AM
Hi,
i assume that u r using ALV grid using dfactory method.
call the form appropriately...
the actual code is given below...
form create_top_of_list_020 changing
co_content type ref to cl_salv_form_element.
data:lo_grid type ref to cl_salv_form_layout_grid, "Grid for top of list
lv_spacer type c value '/'. "separator between sy-title & sy-uname
****Create top_of_list contents.****
create object lo_grid.
****company name****
lo_grid->create_label(
row = 1
column = 1
text = gv_comp_nam ).
****program title****
lo_grid->create_label(
row = 1
column = 33
text = sy-title ).
lo_grid->create_label(
row = 1
column = 43
text = text-z34
colspan = 10 ).
by changing row, column and colspan u can allign ur fields to the place u need.
hope this helps.
bye,
01-30-2007 9:50 AM
for fields you can use
wfieldcat-just = 'R'.
but for col heading i dont know how to do that youmay give like this
wfieldcat-seltext_l = ' Material no'.
it may work but not so sure,
regards
shiba dutta
01-30-2007 10:07 AM
Hi,
We can define the FIELDCATLOG this form
FORM BUILD_FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'ANLN1'.
FIELDCATALOG-SELTEXT_M = 'ASSET MAIN NO'.
FIELDCATALOG-COL_POS = 0.
FIELDCATALOG-OUTPUTLEN = 14.
FIELDCATALOG-EMPHASIZE = 'X'.
FIELDCATALOG-KEY = 'X'.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR FIELDCATALOG.
ENDFORM.
Thanks,
Shankar
01-30-2007 10:11 AM
01-30-2007 10:16 AM
for list display you can do that in top-of-page as per justification.
if you are using reuse_alv_list_display.
data : ievent type slis_t_event,
wevent type slis_alv_event.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = ievent
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 ievent into wevent with key name = 'TOP_OF_PAGE'.
if sy-subrc = 0.
wevent-form = 'TOP_OF_PAGE'.
modify ievent from wevent index sy-tabix.
endif.
call reuse alv list display pass it_event = ievent.
form TOP_OF_PAGE.
write : / 'Material no' centered.
endform.
regards
shiba dutta
01-30-2007 10:21 AM
im using the following fm ,
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = it_lhead[].
im getting all the relevant details in the top ofpage,
but all are left aligned,i need to align the title to center,and the address to be right aligned ....
01-30-2007 10:24 AM
Use
layout-no_colhead = 'X' .
pass this as layout in Reuse_alv_list/grid_display
create top-of-page event.
u will be able to use Write statement in top-of-page event. Do formattiong whatever the way required.
Regards,
Hardik
01-22-2008 5:52 AM
hi.
I am having the same problem as san.
im using the following fm ,
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = it_lhead[].
im getting all the relevant details in the top ofpage,
but all are left aligned,i need to align the title to center,and the address to be right aligned
But if i use layout-no_colhead = 'X' . And
pass this as layout in Reuse_alv_list/grid_display
and create top-of-page event, screen still stay on selection screen with no result coming out.
if without top-of-page event, the alv is displayed but without header. Besides using classes, is there a way to write to solve the alignment? Thank you.
01-30-2007 10:09 AM
sorry it is not reflacted.
in the thread for seltext_l.
wfieldcat-seltext_l = '<some spaces> Material no'.
regards
shiba dutta
01-30-2007 10:17 AM
copy this code and check.
form display_alv1_014 will be to display the alv using factory method.
inside it we r calling form create_top_of_list_020 which will create the top of page.
fix row, column, and colspan as needed....
&----
*& Form display_alv1_014
&----
Displaying the Report in ALV Grid format using factory method *
----
form display_alv1_014.
data: lv_long type scrtext_l, "Long text
lv_medium type scrtext_m, "Medium text
lv_short type scrtext_s, "Short text
lo_table type ref to cl_salv_table, "ALV declaration
lo_columns type ref to cl_salv_columns_table, "ALV Control: Column name
lo_sorts type ref to cl_salv_sorts, "Reference to ALV sort class
lo_aggregations type ref to cl_salv_aggregations, "Reference to set ALV totals
lo_content type ref to cl_salv_form_element, "Reference to set ALV display
lo_salv_msg type ref to cx_salv_msg. "Reference toexception class
constants: lc_pos_1 type i value 1 , "Sort position - 1
lc_pos_2 type i value 2 , "Sort position - 2
lc_pos_3 type i value 3 , "Sort position - 3
lc_pos_4 type i value 4 , "Sort position - 4
lc_pos_5 type i value 5 , "Sort position - 5
lc_pos_6 type i value 6 , "Sort position - 6
lc_seq_1 type salv_de_sort_sequence value '1', "Sort sequence - Ascending
lc_tot type sap_bool value 'X', "Subtotal
lc_grp type salv_de_sort_group value '2', "Group
lc_std_alv type sypfkey value 'STANDARD_ALV'."standard alv
try.
cl_salv_table=>factory(
importing
r_salv_table = lo_table
changing
t_table = gt_so_final ).
catch cx_salv_msg into lo_salv_msg.
message id lo_salv_msg->msgid
type lo_salv_msg->msgty
number lo_salv_msg->msgno.
endtry.
try.
lo_table->set_screen_status(
pfstatus = lc_std_alv
report = sy-repid
set_functions = lo_table->c_functions_all ).
catch cx_salv_msg into lo_salv_msg.
message id lo_salv_msg->msgid
type lo_salv_msg->msgty
number lo_salv_msg->msgno.
endtry.
To set the columns using factory method*****
lo_columns = lo_table->get_columns( ).
lo_columns->set_optimize( abap_true ).
****Form to create a Top of list****
perform create_top_of_list_020 changing lo_content.
lo_table->set_top_of_list( lo_content ).
lo_table->display( ).
endform. "display_alv1_014.
form create_top_of_list_020 changing
co_content type ref to cl_salv_form_element.
data:lo_grid type ref to cl_salv_form_layout_grid, "Grid for top of list
lv_spacer type c value '/'. "separator between sy-title & sy-uname
****Create top_of_list contents.****
create object lo_grid.
****company name****
lo_grid->create_label(
row = 1
column = 1
text = gv_comp_nam ).
****program title****
lo_grid->create_label(
row = 1
column = 33
text = sy-title ).
****date text****
lo_grid->create_label(
row = 1
column = 43
text = text-z34
colspan = 10 ).
co_content = lo_grid.
endform. "create_top_of_list_020
hope this helps.
bye.
01-22-2008 6:10 AM
Have a look at below links. It contains sample code for alv grid.
http://www.erpgenie.com/abap/controls/alvgrid.htm#Complete%20code%20for%20the%20ALV%20grid%20example
http://www.sap-img.com/abap/sample-programs-on-alv-grid.htm
http://sap.niraj.tripod.com/id64.html
Also have a look at below for OO alv grid:
http://help.sap.com/saphelp_erp2004/helpdata/en/0a/b5533cd30911d2b467006094192fe3/frameset.htm
ABAP List Viewer
The common features of report are column alignment, sorting, filtering, subtotals, totals etc. To implement these, a lot of coding and logic is to be put. To avoid that we can use a concept called ABAP List Viewer (ALV).
This helps us to implement all the features mentioned very effectively.
Using ALV, We can have three types of reports:
1. Simple Report
2. Block Report
3. Hierarchical Sequential Report
There are some function modules which will enable to produce the above reports without much effort.
All the definitions of internal tables, structures and constants are declared in a type-pool called SLIS.
1. SIMPLE REPORT.
The important function modules are
a. Reuse_alv_list_display
b. Reuse_alv_fieldcatalog_merge
c. Reuse_alv_events_get
d. Reuse_alv_commentary_write
e. Reuse_alv_grid_display
A. REUSE_ALV_LIST_DISPLAY : This is the function module which prints the data.
The important parameters are :
I. Export :
i. I_callback_program : report id
ii. I_callback_pf_status_set : routine where a user can set his own pf status or change the functionality of the existing pf status
iii. I_callback_user_command : routine where the function codes are handled
iv. I_structure name : name of the dictionary table
v. Is_layout : structure to set the layout of the report
vi. It_fieldcat : internal table with the list of all fields and their attributes which are to be printed (this table can be populated automatically by the function module REUSE_ALV_FIELDCATALOG_MERGE
vii. It_events : internal table with a list of all possible events of ALV and their corresponding form names.
II. Tables :
i. t_outtab : internal table with the data to be output
B. REUSE_ALV_FIELDCATALOG_MERGE : This function module is used to populate a fieldcatalog which is essential to display the data in ALV. If the output data is from a single dictionary table and all the columns are selected, then we need not exclusively create the field catalog. Its enough to mention the table name as a parameter(I_structure name) in the REUSE_ALV_LIST_DISPLAY. But in other cases we need to create it.
The Important Parameters are :
I. Export :
i. I_program_name : report id
ii. I_internal_tabname : the internal output table
iii. I_inclname : include or the report name where all the dynamic forms are handled.
II Changing
ct_fieldcat : an internal table with the type SLIS_T_FIELDCAT_ALV which is
declared in the type pool SLIS.
C. REUSE_ALV_EVENTS_GET : Returns table of possible events for a list type
Parameters :
I. Import :
Et_Events : The event table is returned with all possible CALLBACK events
for the specified list type (column 'NAME'). For events to be processed by Callback, their 'FORM' field must be filled. If the field is initialized, the event is ignored. The entry can be read from the event table, the field 'FORM' filled and the entry modified using constants from the type pool SALV.
II. Export :
I_List_type :
0 = simple list REUSE_ALV_LIST_DISPLAY
1 = hierarchcal-sequential list REUSE_ALV_HIERSEQ_LIST_DISPLAY
2 = simple block list REUSE_ALV_BLOCK_LIST_APPEND
3 = hierarchical-sequential block list
REUSE_ALV_BLOCK_LIST_HS_APPEND
D. REUSE_ALV_COMMENTARY_WRITE : This is used in the Top-of-page event to print the headings and other comments for the list.
Parameters :
I. it_list_commentary : internal table with the headings of the type slis_t_listheader.
This internal table has three fields :
Typ : H header, S selection , A - action
Key : only when typ is S.
Info : the text to be printed
E. REUSE_ALV_GRID_DISPLAY : A new function in 4.6 version, to display the results in grid rather than as a preview.
Parameters : same as reuse_alv_list_display
This is an example for simple list.
2. BLOCK REPORT
This is used to have multiple lists continuously.
The important functions used in this report are:
A. REUSE_ALV_BLOCK_LIST_INIT
B. REUSE_ALV_BLOCK_LIST_APPEND
C. REUSE_ALV_BLOCK_LIST_HS_APPEND
D. REUSE_ALV_BLOCK_LIST_DISPLAY
A. REUSE_ALV_BLOCK_LIST_INIT
Parameters:
I. I_CALLBACK_PROGRAM
II. I_CALLBACK_PF_STATUS_SET
III. I_CALLBACK_USER_COMMAND
This function module is used to set the default gui status etc.
B. REUSE_ALV_BLOCK_LIST_APPEND
Parameters :
Export :
I. is_layout : layout settings for block
II. it_fieldcat : field catalog
III. i_tabname : internal table name with output data
IV. it_events : internal table with all possible events
Tables :
i. t_outtab : internal table with output data.
This function module adds the data to the block.
Repeat this function for all the different blocks to be displayed one after the other.
C. REUSE_ALV_BLOCK_LIST_HS_APPEND
This function module is used for hierarchical sequential blocks.
D. REUSE_ALV_BLOCK_LIST_DISPLAY
Parameters : All the parameters are optional.
This function module display the list with data appended by the above function.
Here the functions REUSE_ALV_FIELDCATALOG_MERGE, REUSE_ALV_EVENTS_GET, REUSE_ALV_COMMENTARY_WRITE can be used.
3. Hierarchical reports :
Hierarchical sequential list output.
The function module is
A. REUSE_ALV_HIERSEQ_LIST_DISPLAY
Parameters:
I. Export:
i. I_CALLBACK_PROGRAM
ii. I_CALLBACK_PF_STATUS_SET
iii. I_CALLBACK_USER_COMMAND
iv. IS_LAYOUT
v. IT_FIELDCAT
vi. IT_EVENTS
vii. i_tabname_header : Name of the internal table in the program containing the
output data of the highest hierarchy level.
viii. i_tabname_item : Name of the internal table in the program containing the
output data of the lowest hierarchy level.
ix. is_keyinfo : This structure contains the header and item table field
names which link the two tables (shared key).
II. Tables
i. t_outtab_header : Header table with data to be output
ii. t_outtab_item : Name of the internal table in the program containing the
output data of the lowest hierarchy level.
slis_t_fieldcat_alv : This internal table contains the field attributes. This internal table can be populated automatically by using REUSE_ALV_FIELDCATALOG_MERGE.
Important Attributes :
A. col_pos : position of the column
B. fieldname : internal fieldname
C. tabname : internal table name
D. ref_fieldname : fieldname (dictionary)
E. ref_tabname : table (dictionary)
F. key(1) : column with key-color
G. icon(1) : icon
H. symbol(1) : symbol
I. checkbox(1) : checkbox
J. just(1) : (R)ight (L)eft (C)ent.
K. do_sum(1) : sum up
L. no_out(1) : (O)blig.(X)no out
M. outputlen : output length
N. seltext_l : long key word
O. seltext_m : middle key word
P. seltext_s : short key word
Q. reptext_ddic : heading (ddic)
R. ddictxt(1) : (S)hort (M)iddle (L)ong
S. datatype : datatype
T. hotspot(1) : hotspot
Simple ALV report
http://www.sapgenie.com/abap/controls/alvgrid.htm
http://wiki.ittoolbox.com/index.php/Code:Ultimate_ALV_table_toolbox
ALV
1. Please give me general info on ALV.
http://www.sapfans.com/forums/viewtopic.php?t=58286
http://www.sapfans.com/forums/viewtopic.php?t=76490
http://www.sapfans.com/forums/viewtopic.php?t=20591
http://www.sapfans.com/forums/viewtopic.php?t=66305 - this one discusses which way should you use - ABAP Objects calls or simple function modules.
2. How do I program double click in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=11601
http://www.sapfans.com/forums/viewtopic.php?t=23010
3. How do I add subtotals (I have problem to add them)...
http://www.sapfans.com/forums/viewtopic.php?t=20386
http://www.sapfans.com/forums/viewtopic.php?t=85191
http://www.sapfans.com/forums/viewtopic.php?t=88401
http://www.sapfans.com/forums/viewtopic.php?t=17335
4. How to add list heading like top-of-page in ABAP lists?
http://www.sapfans.com/forums/viewtopic.php?t=58775
http://www.sapfans.com/forums/viewtopic.php?t=60550
http://www.sapfans.com/forums/viewtopic.php?t=16629
5. How to print page number / total number of pages X/XX in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=29597 (no direct solution)
6. ALV printing problems. The favourite is: The first page shows the number of records selected but I don't need this.
http://www.sapfans.com/forums/viewtopic.php?t=64320
http://www.sapfans.com/forums/viewtopic.php?t=44477
7. How can I set the cell color in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=52107
8. How do I print a logo/graphics in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=81149
http://www.sapfans.com/forums/viewtopic.php?t=35498
http://www.sapfans.com/forums/viewtopic.php?t=5013
9. How do I create and use input-enabled fields in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=84933
http://www.sapfans.com/forums/viewtopic.php?t=69878
10. How can I use ALV for reports that are going to be run in background?
http://www.sapfans.com/forums/viewtopic.php?t=83243
http://www.sapfans.com/forums/viewtopic.php?t=19224
11. How can I display an icon in ALV? (Common requirement is traffic light icon).
http://www.sapfans.com/forums/viewtopic.php?t=79424
http://www.sapfans.com/forums/viewtopic.php?t=24512
12. How can I display a checkbox in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=88376
http://www.sapfans.com/forums/viewtopic.php?t=40968
http://www.sapfans.com/forums/viewtopic.php?t=6919
Go thru these programs they may help u to try on some hands on
ALV Demo program
BCALV_DEMO_HTML
BCALV_FULLSCREEN_DEMO ALV Demo: Fullscreen Mode
BCALV_FULLSCREEN_DEMO_CLASSIC ALV demo: Fullscreen mode
BCALV_GRID_DEMO Simple ALV Control Call Demo Program
BCALV_TREE_DEMO Demo for ALV tree control
BCALV_TREE_SIMPLE_DEMO
BC_ALV_DEMO_HTML_D0100
Reward If useful
04-12-2010 9:20 PM
This thread is pretty old but i thought i would respond since i was looking for the same thing and figured it out. I wanted to center the our company name on our ALV reports. Here is what i did ...
data:
lr_grid type ref to cl_salv_form_layout_grid,
lr_label type ref to cl_salv_form_label,
lr_text type ref to cl_salv_form_text,
lr_layout_grid type ref to cl_salv_form_layout_data_grid,
lr_err type ref to cx_root.
data:
l_company_name type string,
l_message type string.
*-- Create top_of_list container
try.
create object lr_grid.
catch cx_sy_create_object_error into lr_err.
l_message = lr_err->get_text( ).
endtry.
check: lr_grid is bound.
lr_text = lr_grid->create_text(
row = 1
column = 3
text = l_company_name ).
-- Center company name
lr_layout_grid ?= lr_text->get_layout_data( ).
lr_layout_grid->set_h_align( if_salv_form_c_h_align=>center ).
That should do it.
Edited by: Clay Mergen on Apr 12, 2010 2:40 PM
04-12-2010 10:06 PM