03-21-2011 3:46 AM
Hi Experts,
I would like to ask some help with regards to my requirement.
The requirement is to make the ALV output dynamic, I had already the idea but my problem is how to make the structure or internal table dynamic instead of declaring manually a maximum number of fields. Currently I used the function module 'REUSE_ALV_FIELDCATALOG_MERGE' which is to build the field catalog. I created a structure which contains all the fields I need to display in the ALV but I need to change it now to make it dynamic because there are columns which will only display depends of the data inputted on the selection-screen which is of data type a988-kschl. Do you have any idea? Your suggestions is very much appreciated and especially sample code is provided.
This is how I declare may parameters:
SELECT-OPTIONS: s_kschl FOR a988-kschl.
Regards,
Ekitzv
03-21-2011 4:16 AM
i think instead of using funtion module to build field catalog, fill field catalog manually.
i guess that would solve your probelm??
03-21-2011 5:33 AM
Hi,
No, because they don't want to modify the program everytime a nec KSCHL is created. If you will create a manual build of field catalog you need to fix the field.
03-21-2011 5:52 AM
Hi
Please find the below code Here first it will create fields dynamically.But How many fields u want to create first the number of records and pass that record number to LV_COUNT variable
DO lv_count TIMES.
count = count + 1.
CONCATENATE 'SGPA' count INTO v_var. "Colum name
CONCATENATE 'ADM_PERID' count INTO l_name. "Here we can mention the fields
wa_flname = l_name.
wa_it_fldcat-fieldname = wa_flname.
wa_it_fldcat-seltext = v_var.
wa_it_fldcat-intlen = 10.
APPEND wa_it_fldcat TO t_fldcat.
CLEAR v_var.
ENDLOOP.
ENDDO.
CALL METHOD cl_alv_table_create=>create_dynamic_table "Here creates the internal table dynamcally
EXPORTING
it_fieldcatalog = t_fldcat
IMPORTING
ep_table = t_newtable.
ASSIGN t_newtable->* TO <t_dyntable>.
Create dynamic work area and assign to FS
CREATE DATA t_newline LIKE LINE OF <t_dyntable>.
ASSIGN t_newline->* TO <fs_dyntable>.
Regards,
Muralii
03-21-2011 10:15 AM
Hi Muralii,
Thanks for your idea. I have a follow-up question. On the code below you have an importing table which is t_newtable may I know how did you declare this?
CALL METHOD cl_alv_table_create=>create_dynamic_table "Here creates the internal table dynamcally
EXPORTING
it_fieldcatalog = t_fldcat
IMPORTING
ep_table = t_newtable.
03-21-2011 1:20 PM
Hi
You can declare the internal table and fieldcatlog like this
DATA: t_newtable TYPE REF TO data,
t_newline TYPE REF TO data,
fs_fldcat TYPE slis_t_fieldcat_alv,
t_fldcat TYPE lvc_t_fcat,
DATA: t_newtable TYPE REF TO data,
t_newline TYPE REF TO data,
fs_fldcat TYPE slis_t_fieldcat_alv,
t_fldcat TYPE lvc_t_fcat,
03-21-2011 4:29 PM
Thanks again Muralii,
I got an error in this code => CALL METHOD cl_alv_table_create=>create_dynamic_table "Here creates the internal table dynamcally
EXPORTING
it_fieldcatalog = t_fldcat
IMPORTING
ep_table = t_newtable.
The error is 'The field string "LT_GENTAB" contains no fields. 4 LT_GENTAB' Do you have any idea of why i have this kind or error?
This is my code below.
DATA: lv_vtext TYPE t685t-vtext,
v_text(50) TYPE c,
v_field TYPE a988-kschl.
DO v_count TIMES.
v_counter = v_counter + 1.
LOOP AT i_kschl INTO wa_kschl.
SELECT SINGLE vtext
FROM t685t
INTO lv_vtext
WHERE spras = 'S'
AND kschl = wa_kschl.
IF sy-subrc IS INITIAL.
ENDIF.
CONCATENATE lv_vtext v_counter INTO v_text. "Colum name
ls_fieldcat-key = ' '.
ls_fieldcat-fieldname = 'KSCHL'.
ls_fieldcat-seltext_m = v_text.
ls_fieldcat-edit = ' '.
ls_fieldcat-no_out = ' '.
APPEND ls_fieldcat TO gt_fieldcat.
ENDLOOP.
ENDDO.
04-04-2011 8:29 AM
Hi All,
Thanks for all your ideas..I am now closing this thread..
03-21-2011 6:16 AM
Hi Ekitzv ,
Below is the sample code to demonstrate dynamic creation of table. Check the code as it may help you solve your problem. But to display the table in an ALV using the standard funtion module , the Tables parametre will not accept the field-symbol of type any table. it has to be assigned to either importing, exporting or changing parametrs. so, i have used cl_salv_table factory method to display the ALV Data and i also think that even you have to follow this way to solve your problem.
* This program display the data of the table name that you have
* entered on the selection-screen.
PARAMETERS: tab_name TYPE dd02l-tabname.
DATA: gr_table TYPE REF TO cl_salv_table.
DATA: dref TYPE REF TO data.
FIELD-SYMBOLS : <fs> TYPE ANY TABLE.
START-OF-SELECTION.
* To achieve the required funtionality internal table should be created
* dynamically as it is not static.
CREATE DATA dref TYPE TABLE OF (tab_name).
* dereference it so that the contents in the address dref are transferrd to field symbol <fs>
* which is of type table and assign it
ASSIGN dref->* TO <fs>.
* select the data from the database table
SELECT * FROM (tab_name) INTO TABLE <fs>.
* Display the data
* TRY.
CALL METHOD cl_salv_table=>factory
* EXPORTING
* LIST_DISPLAY = IF_SALV_C_BOOL_SAP=>FALSE
* R_CONTAINER =
* CONTAINER_NAME =
IMPORTING
r_salv_table = gr_table
CHANGING
t_table = <fs>
.
* CATCH CX_SALV_MSG .
* ENDTRY.
gr_table->display( ).
Cheers,
Ravi.
03-21-2011 6:37 AM
Hi Ekitzv,
I think you could solve this problem by setting the filedcatlog property " NO_OUT ". By setting this property to 'X' this could be achived. But in this case you need to modify the fieldcatlog after creating the fieldcatlog using 'REUSE_ALV_FIELDCATALOG_MERGE' .
Sample code :
WHEN c_total .
<fs_fieldcat>-no_out = c_x.
Thanks and Regards,
Sri Hari Anand Kumar
03-21-2011 6:41 AM
Hello
The following Wiki coding
[Creating Flat and Complex Internal Tables Dynamically using RTTI|http://wiki.sdn.sap.com/wiki/display/Snippets/CreatingFlatandComplexInternalTablesDynamicallyusingRTTI]
demonstrates the use of dynamic itabs (even complex ones) for the new fieldcatalog structure (LVC_S_FCAT).
Regards
Uwe
03-21-2011 6:51 AM
hi,
Please Refer the code in following link
Hope this will help you.
Regards,
Renuka S.
03-21-2011 6:56 AM
type-pools: slis.
DATA : lv_repid TYPE sy-repid,
i_structure_name TYPE dd02l-tabname VALUE 'Z_your_structure',
ct_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat LIKE LINE OF ct_fieldcat.
lv_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = lv_repid
i_structure_name = i_structure_name
CHANGING
ct_fieldcat = ct_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT ct_fieldcat INTO wa_fieldcat.
IF wa_fieldcat-fieldname = ' FIELD_1'. "Suppose you don't want to output FIELD_1
wa_fieldcat-no_out = 'X'.
MODIFY ct_fieldcat FROM wa_fieldcat INDEX sy-tabix.
ELSEIF wa_fieldcat-fieldname = ' FIELD_2'.
.....
.....
ENDIF.
ENDLOOP.
03-21-2011 9:04 AM
Hi
As per my understanding you are getting the data in your internal table for the whole structure you have declared for your ALV.
Now after field-catalog merge you can loop through your fieldcat table and put conditions and set no_out as X or Not X.
and modify your fieldcatlog table.
and pass this to your ALV grid Display.
I hope this will help you.
or
what you can check after getting data in your final table.
check particular field is not in your select option
like
suppose I have a table ITAB
and there are fields matnr and werks
also I have select options for matnr and werks as S_MATNR and S_WERKS
so check if itab-matnr not in s_matnr or
itab-werks not in s_werks.
clear itab or rfresh itab.
endif.
this must be something like this.
Thanks
LG