07-25-2005 10:04 AM
I want to control the columns order in the alvgrid.
for example ,
In the internal table , the fields order is
a1, a2, a3
but i want the alvgird display it following the new order
a3,a1,a2.
how can i implement it.
thanks in advance.
07-25-2005 10:11 AM
Use the field col_pos in the field catalog table for giving the order of columns.
CLEAR w_fcat.
w_fcat-fieldname = 'ID'.
w_fcat-tabname = 'I_OUTTAB'.
w_fcat-col_pos = 1.
APPEND w_fcat TO fcat.
CLEAR w_fcat.
CLEAR w_fcat.
w_fcat-fieldname = 'NAME'.
w_fcat-tabname = 'I_OUTTAB'.
w_fcat-col_pos = 2.
APPEND w_fcat TO fcat.
CLEAR w_fcat.
Thanks
Vinod
07-25-2005 10:11 AM
Use the field col_pos in the field catalog table for giving the order of columns.
CLEAR w_fcat.
w_fcat-fieldname = 'ID'.
w_fcat-tabname = 'I_OUTTAB'.
w_fcat-col_pos = 1.
APPEND w_fcat TO fcat.
CLEAR w_fcat.
CLEAR w_fcat.
w_fcat-fieldname = 'NAME'.
w_fcat-tabname = 'I_OUTTAB'.
w_fcat-col_pos = 2.
APPEND w_fcat TO fcat.
CLEAR w_fcat.
Thanks
Vinod
07-25-2005 10:12 AM
Hi,
Use the col_pos to set the position of the column.
col_pos = 1 or 2 etc.
Cheers,
Sam
07-25-2005 10:16 AM
U can change the order in the fieldcatalog.
Or Define the output table structure in the order as u wish and then move corresponding entries from the internal table to the output table structure.
07-25-2005 10:17 AM
Hey,
While creating the field catalog just specify the column name in desired order. it will work fine.
Eg.
FORM f2000_fieldcat_init CHANGING i_fieldcat TYPE slis_t_fieldcat_alv.
DATA: line_fieldcat TYPE slis_fieldcat_alv.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'A3'.
line_fieldcat-ref_tabname = '<internal table>'. line_fieldcat-key = 'X'.
line_fieldcat-seltext_m = 'Notification No.'
APPEND line_fieldcat TO i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'A2'.
line_fieldcat-ref_tabname = '<internal table>'.
line_fieldcat-hotspot = 'X'.
line_fieldcat-seltext_m = 'XXXXXXXX.
APPEND line_fieldcat TO i_fieldcat.
CLEAR line_fieldcat.
line_fieldcat-fieldname = 'A1'
line_fieldcat-ref_tabname = '<internal table>'. line_fieldcat-seltext_m = 'Description'.
APPEND line_fieldcat TO i_fieldcat.
ENDFORM.
Regs,
Venkat
07-25-2005 10:34 AM
I have defined the col_pos, but it's isn't work.
my code.
gs_fieldcat-fieldname = 'VRT'.
gs_fieldcat-ref_table =.
gs_fieldcat-outputlen = '3'.
gs_fieldcat-edit = 'X'.
gs_fieldcat-key = 'X'.
gs_fieldcat-coltext = 'VRT'.
gs_fieldcat-col_pos = 6.
append gs_fieldcat to gt_fieldcat.
clear gs_fieldcat.
gs_fieldcat-fieldname = 'QTY'.
gs_fieldcat-datatype = 'FLTP'.
gs_fieldcat-outputlen = '12'.
gs_fieldcat-DECIMALS = '3'.
gs_fieldcat-coltext = 'QTY'.
gs_fieldcat-edit = 'X'.
gs_fieldcat-col_pos = 7.
append gs_fieldcat to gt_fieldcat.
clear gs_fieldcat.
gs_fieldcat-fieldname = 'SALTYP'.
gs_fieldcat-ref_table =.
gs_fieldcat-outputlen = '2'.
gs_fieldcat-edit = 'X'.
gs_fieldcat-key = 'X'.
gs_fieldcat-coltext = 'SALTYP'.
gs_fieldcat-NO_OUT = 'X'.
append gs_fieldcat to gt_fieldcat.
clear gs_fieldcat.
gs_fieldcat-fieldname = 'LOCATN'.
gs_fieldcat-ref_table =
gs_fieldcat-outputlen = '3'.
gs_fieldcat-edit = 'X'.
gs_fieldcat-key = 'X'.
gs_fieldcat-coltext = 'LOCATN'.
gs_fieldcat-NO_OUT = 'X'.
append gs_fieldcat to gt_fieldcat.
call method grid1->set_table_for_first_display
exporting " i_buffer_active = 'X'
i_save = 'A'
changing
it_fieldcatalog = gt_fieldcat
it_outtab = ittmp_basisOri.
07-25-2005 10:41 AM
Hi,
Here you have defined the col_pos for only 2 fields.Define it for others also.Then you will get the required output.
Did you tried this?
Message was edited by: Jayanthi Jayaraman
07-25-2005 10:43 AM
Hi Define the column position for all the ffields as per the order u want to display, if u specify for two alone it wont work.
So define it in the order and then check it out.
Or else u can try out in the way i have mentioned above.
07-25-2005 11:01 AM
Hi mei
instead of using append use modify.
i hope this might help you.
gs_fieldcat-fieldname = 'VRT'.
* gs_fieldcat-ref_table =.
gs_fieldcat-outputlen = '3'.
gs_fieldcat-edit = 'X'.
gs_fieldcat-key = 'X'.
gs_fieldcat-coltext = 'VRT'.
gs_fieldcat-col_pos = 6.
<b>*append gs_fieldcat to gt_fieldcat.
modify gt_fieldcat from gs_fieldcat.</b>
clear gs_fieldcat.
gs_fieldcat-fieldname = 'QTY'.
gs_fieldcat-datatype = 'FLTP'.
gs_fieldcat-outputlen = '12'.
gs_fieldcat-DECIMALS = '3'.
gs_fieldcat-coltext = 'QTY'.
gs_fieldcat-edit = 'X'.
gs_fieldcat-col_pos = 7.
<b>*append gs_fieldcat to gt_fieldcat.
modify gt_fieldcat from gs_fieldcat.</b>
or u can also try this way.
form build_fieldcat changing gt_fieldcat type lvc_t_fcat.
data gs_fcat type lvc_s_fcat.
call function 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'TABLE NAME'
CHANGING
ct_fieldcat = gt_fieldcat.
clear gs_fcat.
loop at gt_fieldcat into gs_fcat.
if gs_fcat-fieldname EQ 'VRT'.
gs_fcat-scrtext_s = 'VARIETY'.
gs_fcat-scrtext_m = 'VARIETY'.
gs_fcat-scrtext_l = 'VARIETY'.
gs_fcat-reptext = 'VARIETY'.
gs_fcat-seltext = 'VARIETY'.
gs_fieldcat-outputlen = '3'.
gs_fieldcat-edit = 'X'.
gs_fieldcat-key = 'X'.
gs_fieldcat-col_pos = 6.
modify gt_fieldcat from gs_fieldcat.
endif.
if gs_fcat-fieldname EQ 'QTY'.
gs_fcat-scrtext_s = 'QUANTITY'.
gs_fcat-scrtext_m = 'QUANTITY'.
gs_fcat-scrtext_l = 'QUANTITY'.
gs_fcat-reptext = 'QUANTITY'.
gs_fcat-seltext = 'QUANTITY'.
gs_fieldcat-outputlen = '3'.
gs_fieldcat-edit = 'X'.
gs_fieldcat-key = 'X'.
gs_fieldcat-col_pos = 7.
modify gt_fieldcat from gs_fieldcat.
endif.
and so on.....
endloop.
regards,
venu.
07-25-2005 11:11 AM
07-25-2005 11:12 AM
07-25-2005 11:20 AM
Hi,
Declare a type of ur reuired format:
TYPES: Begin of ty_outab,
a2 like tabname-a2,
a3 like tabname-a3,
a1 like tabname-a1,
end of ty_outab.
Data: i_outab type standard table of ty_outab,
w_outab type ty_outab.
Use this internal table to populate the values of the output and pass it ALV display function.
Regards,
Anjali.
07-25-2005 11:14 AM
Hello,
A better approach is using the layout and creating different layouts and setting a default one.
Regards,
Shekhar Kulkarni
07-25-2005 11:35 AM
you can use the following structure for alv.
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv
, BEGIN OF itab OCCURS 0
, a1
, a2
, a3
, END OF itab.
For alv display.
DATA: lt_repid LIKE sy-repid.
PERFORM fill_fcat_structure USING: 'a3' 'dict table'
, 'a2' 'dict table'
, 'a1' 'dict table'
.
lt_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = lt_repid
it_fieldcat = gt_fieldcat
TABLES
t_outtab = itab
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
Filling alv data.
FORM fill_fcat_structure USING lp_field lp_reftab.
--- lokale Variable -
DATA: ls_fieldcat LIKE LINE OF gt_fieldcat.
ls_fieldcat-fieldname = lp_field.
ls_fieldcat-tabname = 'ITAB'.
ls_fieldcat-ref_fieldname = lp_field.
ls_fieldcat-ref_tabname = lp_reftab.
APPEND ls_fieldcat TO gt_fieldcat.
ENDFORM. " fill_fcat_structure
07-25-2005 11:38 AM
Hi,
Did u check my code. It will work fine.
hey also in your piece of code try giving the col-pos inside the single quotes. it may work.
Cheers,
Venkat
07-25-2005 11:42 AM
Hi,
Did u check my code. It will work fine.
hey also in your piece of code try giving the col-pos inside the single quotes. it may work.
Cheers,
Venkat
07-26-2005 2:27 AM
i have find the real reason that the col_pos can't work.
I have defined defined some key fields, that when i move some columns to the front of the key fields, the order isn't changed.
If i remove the key fields defining, all works well.
thanks every one.