‎2009 Apr 15 5:42 AM
Hi,
I have a requirement that we must have a report with grid display with the number of columns which will be known during the run time ( dynamic).
how to acheive the above.
Regards
‎2009 Apr 15 5:45 AM
Hi,
This can be achieved by using the concept of FIELD SYMBOLS.
Regards,
Surya kiran
‎2009 Apr 15 5:45 AM
Hi,
You can use a dynamic table and display the same in the ALV grid.
Hope it helps,
Rajat
‎2009 Apr 15 5:45 AM
This question answered several times
https://forums.sdn.sap.com/search.jspa?threadID=&q=dynamicANDinternalANDtable&objID=f50&dateRange=all&numResults=15
aRs
‎2009 Apr 15 5:51 AM
Hi,
Here is another sample code which might help you,
&----
*& Report YTEST_R19
*&
&----
*&
*&
&----
report ytest_r19.
tables : mara .
select-options : s_matnr for mara-matnr.
type-pools: slis.
types: begin of ty_makt,
matnr type matnr,
maktx type maktx,
end of ty_makt.
data : wa_makt type ty_makt,
it_makt type table of ty_makt.
data : wa_lvc_cat type lvc_s_fcat,
lt_lvc_cat type lvc_t_fcat.
types : begin of ty_mara,
matnr type matnr,
aenam type aenam,
vpsta type vpsta,
pstat type pstat_d,
end of ty_mara.
data : wa_mara type ty_mara,
it_mara type standard table of ty_mara.
data: l_col type sy-tabix,
l_structure type ref to data,
l_dyntable type ref to data,
lt_fieldcatalogue TYPE slis_t_fieldcat_alv,
wa_fieldcat type slis_fieldcat_alv,
lt_fieldcat type slis_t_fieldcat_alv,
lt_layout type slis_layout_alv.
types : begin of ty_text,
text type string,
end of ty_text.
data: wa_text type ty_text,
it_text type table of ty_text.
wa_text-text = 'MAterial'.
append wa_text to it_text.
wa_text-text = 'Name of Person'.
append wa_text to it_text.
wa_text-text = 'Maintenance status '.
append wa_text to it_text.
wa_text-text = 'Maintenance '.
append wa_text to it_text.
*Field symbols declarations
field-symbols :
<header> type any,
<dynheader> type any,
<dyndata> type any,
<ls_table> type any,
<dynamictable> type standard table,
<it_table> type standard table,
<wa_mara1> type ty_mara.
*Initialization event
initialization.
*Start of selection event
start-of-selection.
select matnr maktx from makt into table it_makt where matnr in s_matnr.
select matnr
aenam
vpsta
pstat
from mara
into table it_mara
for all entries in it_makt
where matnr eq it_makt-matnr.
wa_lvc_cat-fieldname = 'COLUMNTEXT'.
wa_lvc_cat-ref_table = 'LVC_S_DETA'.
append wa_lvc_cat to lt_lvc_cat.
describe table it_makt.
do sy-tfill times.
write sy-index to wa_lvc_cat-fieldname left-justified.
concatenate 'VALUE' wa_lvc_cat-fieldname
into wa_lvc_cat-fieldname.
wa_lvc_cat-ref_field = 'VALUE'.
wa_lvc_cat-ref_table = 'LVC_S_DETA'.
append wa_lvc_cat to lt_lvc_cat.
enddo.
Create dynamic internal table
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = lt_lvc_cat
importing
ep_table = l_dyntable.
assign l_dyntable->* to <dynamictable>.
Create structure as structure of the internal table
create data l_structure like line of <dynamictable>.
assign l_structure->* to <header>.
create data l_structure like line of it_mara.
assign l_structure->* to <wa_mara1>.
describe table it_makt.
Fill the internal to display <dynamictable>
do sy-tfill times.
if sy-index = 1.
read table it_text into wa_text index 1.
endif.
For each field of it_table
assign component 1 of structure <header> to <dynheader>.
if sy-subrc ne 0. exit .endif.
read table it_text into wa_text index sy-index.
Fill 1st column
<dynheader> = wa_text-text.
if <dynheader> is initial.
<dynheader> = wa_text-text.
endif.
*Filling the other columns
loop at it_mara into <wa_mara1>.
l_col = sy-tabix + 1.
assign component sy-index of structure <wa_mara1> to <dyndata>.
if sy-subrc ne 0. exit .endif.
assign component l_col of structure <header> to
<dynheader>.
if sy-subrc ne 0. exit .endif.
write <dyndata> to <dynheader> left-justified.
endloop.
append <header> to <dynamictable>.
enddo.
Regards,
surya kiran
‎2009 Apr 15 5:53 AM
Hi ,
FIELD-SYMBOLS: <L_TABLE> TYPE TABLE,
<L_FIELD> TYPE ANY,
<L_LINE> TYPE ANY.
DATA: NEW_TABLE TYPE REF TO DATA,
NEW_LINE TYPE REF TO DATA.
DATA: IS_LVC_CAT TYPE LVC_S_FCAT,
IT_LVC_CAT TYPE LVC_T_FCAT.
***Assign the structure
IS_LVC_CAT-FIELDNAME = 'NFMAT'.
IS_LVC_CAT-INTLEN = '18'.
APPEND IS_LVC_CAT TO IT_LVC_CAT.
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_LVC_CAT
IMPORTING
EP_TABLE = NEW_TABLE.
ASSIGN NEW_TABLE->* TO <L_TABLE>.
CREATE DATA NEW_LINE LIKE LINE OF <L_TABLE>.
ASSIGN NEW_LINE->* TO <L_LINE>.
CLEAR COUNT.
This way u can create a dynamic table where in u can define ur fields in the fieldcatalog which creates a refrence ponter by referring to which u can create a work area and in turn define the table by using field symbol of type table.....
regards,
ajit.
‎2009 Apr 15 5:54 AM
Dear
Creating a dyanamic column is not a tough task .
at the time of designing the fieldcatalog you can fix the columns and its text on the basis of condition you want to show in the Grid display .
If you are not clear please do reply .
regds ankit
‎2009 Apr 15 7:14 AM
Hi,
I have all the data in a internal table .
The problem is that the Rows must become columns and columns as rows
Thats is I need a Pivot table...
Regards
‎2009 Apr 15 7:17 AM
Hi,
For dynamically displaying the output , build your fieldcatalog in a dynamic way , so when you display with Grid or List it will display according to your fieldcatalog. For Eg.
In FieldCatalog I have declared the field according to there values.
Here I have used Flags in fieldcatalog.
IF socity_interest_flag = 'X'.
htab-fieldname = 'SOCIETY_LOAN'.
htab-seltext_m = 'SOC.LOAN INT.'.
htab-outputlen = '15'.
htab-do_sum = 'X'.
append htab to vtab .
clear htab.
ENDIF.
IF lic_flag = 'X'.
htab-fieldname = 'LIC'.
htab-seltext_m = 'LIC'.
htab-outputlen = '15'.
htab-do_sum = 'X'.
append htab to vtab .
clear htab.
ENDIF.
if socity_interest_flag or lic_flag have values than only there fieldcatalog will built and according to that we will get the dynamic output.
Regards,
Himanshu