01-31-2006 7:07 PM
Hello folks,
Can I assign a field symbol to the ALV function modules instead of internal table.
If not possible can any1 suggest how to build a dynamic internal table. I mean the fields from the internal table to be displayed in the ALV list will be varying.
Thanks,
02-03-2006 5:56 PM
Hello folks,
Thanks for the responses. They will be rewarded. I have a problem here though.
I am reading amounts for all months in to an internal table.
For example, the internal table <b>itab</b> has the following entries.
100
200
300
400
500
600
700
800
900
1000
1100
1200
and I am trying to assign these values to a field-symbol <fs> in the following way where I am failing.
100 200 300 400 500 600 700 800 900 1000 1100 1200
I declared <fs> as type table though.
I want to see the ALV grid in the above format (in a single row).
Can any1 help me how to do that?
Thanks,
Message was edited by: Naren Somen
01-31-2006 7:11 PM
Hi Naren,
Please see this code, I think it will exactly match ur requirement.
It covers both ALV and dynamic internal table.
Please reward points if it suits for ur requirement.
<b>&----
*& Report YTST5
*&
&----
*&
*&
&----
REPORT YTST5.
*{PAVAN
*ALV data declarations
TYPE-POOLS: slis ,tstr.
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.
*}PAVAN
Tables
DATA: LT_DATA type ref to DATA.
DATA: LT_FIELDCATALOG type LVC_T_FCAT.
Structure
DATA: LS_FIELDCATALOG type LVC_S_FCAT.
Data References
DATA: NEW_LINE type ref to data.
Field Symbols
FIELD-SYMBOLS: <FS_DATA> type ref to DATA,
<FS_1> type any table,
<FS_2>,
<FS_3>.
selection-screen begin of block b1.
parameters: p_weeks type i.
selection-screen end of block b1.
*Populating the internal table with fieldnames required for our dynamic
*internal table
data: l_Str(10).
data: l_nos type i.
l_nos = 1.
while l_nos le p_weeks.
l_str = 'Week' .
l_str+4(2) = l_nos.
ls_fieldcatalog-fieldname = l_Str.
ls_fieldcatalog-inttype = 'QUAN'.
append LS_FIELDCATALOG to LT_FIELDCATALOG.
l_nos = l_nos + 1.
endwhile.
*LS_FIELDCATALOG-FIELDNAME = 'MANDT'.
*append LS_FIELDCATALOG to LT_FIELDCATALOG.
*
*LS_FIELDCATALOG-FIELDNAME = 'CARRID'. "Fieldname
*LS_FIELDCATALOG-INTTYPE = 'C'. "Internal Type C-> Character
*append LS_FIELDCATALOG to LT_FIELDCATALOG.
*
*LS_FIELDCATALOG-FIELDNAME = 'CONNID'.
*LS_FIELDCATALOG-INTTYPE = 'N'.
*append LS_FIELDCATALOG to LT_FIELDCATALOG.
*
*LS_FIELDCATALOG-FIELDNAME = 'FLDATE'.
*LS_FIELDCATALOG-INTTYPE = 'D'.
*append LS_FIELDCATALOG to LT_FIELDCATALOG.
*
*LS_FIELDCATALOG-FIELDNAME = 'PRICE'.
*LS_FIELDCATALOG-INTTYPE = 'P'.
*append LS_FIELDCATALOG to LT_FIELDCATALOG.
*
*LS_FIELDCATALOG-FIELDNAME = 'CURRENCY'.
*LS_FIELDCATALOG-INTTYPE = 'C'.
*append LS_FIELDCATALOG to LT_FIELDCATALOG.
*
*Assigning Field-Symbol to our dynamic internal table
assign LT_DATA to <FS_DATA>.
*Calling the method CREATE_DYNAMIC_TABLE
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = LT_FIELDCATALOG
importing
ep_table = <FS_DATA>
exceptions
generate_subpool_dir_full = 1
others = 2
.
if sy-subrc <> 0.
endif.
So <FS_1> now points to our dynamic internal table.
assign <FS_DATA>->* to <FS_1>.
Next step is to create a work area for our dynamic internal table.
create data NEW_LINE like line of <FS_1>.
A field-symbol to access that work area
assign NEW_LINE->* to <FS_2>.
assign component 1 of structure <FS_2> to <FS_3>.
<FS_3> = 10.
assign component 2 of structure <FS_2> to <FS_3>.
<FS_3> = 20.
insert <FS_2> into table <FS_1>.
clear <FS_3>.
assign component 1 of structure <FS_2> to <FS_3>.
<FS_3> = 100.
assign component 2 of structure <FS_2> to <FS_3>.
<FS_3> = 200.
insert <FS_2> into table <FS_1>.
And to put the data in the internal table
*select MANDT CARRID CONNID FLDATE PRICE CURRENCY
from SFLIGHT
into corresponding fields of table <FS_1>.
perform build_field_catalog.
field-symbols: <itab> type table.
assign <FS_1> to <itab>.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = gd_repid
it_fieldcat = fieldcatalog[]
i_save = 'X'
TABLES
t_outtab = <itab>
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.
form build_field_catalog.
l_nos = 1.
while l_nos le p_weeks.
l_str = 'WEEK' .
l_str+4(2) = l_nos.
*{FIELD CATALOG
fieldcatalog-fieldname = l_str.
fieldcatalog-seltext_m = l_str.
fieldcatalog-col_pos = l_nos.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
*}FIELD CATALOG
l_nos = l_nos + 1.
endwhile.
fieldcatalog-fieldname = 'WEEK1'.
fieldcatalog-seltext_m = 'Week1'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
*
fieldcatalog-fieldname = 'WEEK2'.
fieldcatalog-seltext_m = 'Week 2'.
fieldcatalog-col_pos = 1.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
endform.</b>
Thanks
Pavan
01-31-2006 7:11 PM
*****DATA DECLARATION****************************
FIELD-SYMBOLS : <it_final> TYPE STANDARD TABLE,
<wa_final> TYPE ANY,
<w_field> TYPE ANY.
**DYNAMIC CREATION OF FIELDCATALOG***************
*FIRST 2 FIELDS FIELDS FIELD1 AND FIELD2 ARE CONSTANT, FIELDS OBTAINED IN THE LOOP ENDLOOP ARE DYNAMIC,
*LIKEWISE DYNAMIC FIELDCATALOG IS CREATED
wa_fieldcatalog-fieldname = 'FIELD1'.
wa_fieldcatalog-ref_table = 'E070'.
wa_fieldcatalog-outputlen = '13'.
wa_fieldcatalog-reptext = 'Created On'.
wa_fieldcatalog-seltext = 'Created On'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'FIELD1'.
wa_fieldcatalog-ref_table = 'E070'.
wa_fieldcatalog-outputlen = '13'.
wa_fieldcatalog-reptext = 'Created On'.
wa_fieldcatalog-seltext = 'Created On'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR wa_fieldcatalog.
LOOP AT it_mandt WHERE mandt IN s_mandt.
CONCATENATE 'CLNT' it_mandt INTO wa_fieldcatalog-fieldname.
wa_fieldcatalog-inttype = 'NUMC'.
wa_fieldcatalog-outputlen = '14'.
wa_fieldcatalog-reptext = it_mandt.
wa_fieldcatalog-seltext = it_mandt.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR :wa_fieldcatalog ,it_mandt.
ENDLOOP.
*******CREATE DYNAMIC TABLE***********************
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcatalog
IMPORTING
ep_table = new_table
EXCEPTIONS
generate_subpool_dir_full = 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.
ASSIGN new_table->* TO <it_final>.
********CREATE WORK AREA***************************
CREATE DATA new_line LIKE LINE OF <it_final>.
ASSIGN new_line->* TO <wa_final>.
********INSERTTING WORK AREAR TO INTERNAL TABLE*****
INSERT <wa_final> INTO TABLE <it_final>.
******POPULATING DATA******************************
LOOP.
ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <wa_final> TO <w_field>.
<w_field> = '12345'.
ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <wa_final> TO <w_field>.
<w_field> = '21453DD'.
FIELD1 AND FIELD2 ARE COMPONENTS OF FIELDCATALOG.
ENDLOOP.
ENDLOOP.
02-03-2006 5:56 PM
Hello folks,
Thanks for the responses. They will be rewarded. I have a problem here though.
I am reading amounts for all months in to an internal table.
For example, the internal table <b>itab</b> has the following entries.
100
200
300
400
500
600
700
800
900
1000
1100
1200
and I am trying to assign these values to a field-symbol <fs> in the following way where I am failing.
100 200 300 400 500 600 700 800 900 1000 1100 1200
I declared <fs> as type table though.
I want to see the ALV grid in the above format (in a single row).
Can any1 help me how to do that?
Thanks,
Message was edited by: Naren Somen
02-03-2006 5:59 PM
Hi
You should create an internal table with many fields than hits you have in ITAB.
DATA: N(3) TYPE N.
DESCRIBE ITAB LINES SY-TABIX.
DO SY-TABIX TIMES.
MOVE SY-INDEX TO N.
CONCATENATE 'FIELD_' N INTO wa_fieldcatalog-fieldname.
......................
APPEND wa_fieldcatalog TO it_fieldcatalog.
ENDDO.
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = LT_FIELDCATALOG
importing
ep_table = <FS_DATA>
exceptions
generate_subpool_dir_full = 1
others = 2
.
if sy-subrc <> 0.
endif.
assign <FS_DATA>->* to <FS_TABLE>.
LOOP AT ITAB.
ASSIGN COMPONENT SY-TABIX OF STRUCTURE <WA_TABLES> TO <FS>.
<FS> = ITAB-FIELD.
ENDLOOP.
IF SY-SUBRC = 0.
APPEND <WA_TABLE> TO <FS_TABLE>.
ENDIF.
max
Message was edited by: max bianchi
02-03-2006 6:11 PM
Max,
What is <wa_table>?? How you have declared it and of what type??
Thanks,
02-03-2006 7:05 PM
HI Naren,
<wa_table> means work area of the internal table. dont consider< > as part of field symbol here.He is asking you to write your defined work area.
02-04-2006 10:02 AM
Hi
Phani is right, <wa_table> is a work area for internal table.
You have to consider that internal created by field-symbol haven't header line.
So you can define the header line in this way:
DATA: WA TYPE REF TO DATA.
FIELD-SYMBOLS: <WA_TABLE> TYPE ANY.
CREATE DATA WA LIKE LINE OF <FS_TABLE>.
ASSIGN WA->* TO <WA_TABLE>.
Max