‎2004 Oct 29 2:57 AM
Hi all,
I searched through the forums and found a few topics on how to create an dynamic table, but the provided solutions were creating dynamic tables from a database table. I was wondering if it would be possible to do the same from an internal table.
Here is the scenario I have an internal table
DATA: BEGIN OF INTERNAL_TABLE OCCURS 10,
LName TYPE P0002-NACHN,
FNAME TYPE P0002-VORNA,
SALARY TYPE P decimals 2,
....
....
END OF INTERNAL_TABLE.
After the table is filled - based on the user's selection (let's say user selected LName and Salary) I need to create a NEW internal table with only two fields LName and Salary .
Thank you
‎2004 Oct 29 4:49 AM
‎2004 Oct 29 10:06 AM
‎2004 Oct 30 6:00 AM
Subramanian and Serdar thank you for your responces.
Subramanian, I've looked through the topic of the link you provided, the method discussed on that topic is exactly what I am having problem with. The problem is they are using TABLES: mara, makt in the provided example.
I don't have ABAP tables, I only have an internal table.
Serdar,
Your sample looks like something I might be able to use, however I don't seem to get what I am trying to get .. when this part is executed
zz_tabletype = cl_abap_tabledescr=>create (.....)
the zz_tabletype looks like this:
Name
-
Field1
Field2
.....
While I need more like this.
Field1 Field2
-
-
‎2004 Oct 30 6:33 AM
If you just want to refer to you itab type then you have to manullay build the fieldcat passing the following values.
is_fieldcat-fieldname = <file name u wanted to have>.
is_fieldcat-outputlen = '25' .
is_fieldcat-datatype = <data type char, int, numc etc>.
is_fieldcat-scrtext_l = <text>.
Regards
Raja
‎2004 Nov 01 5:48 AM
I am not sure, Naoki, if you saw the code correctly, but the code <b>does not use TABLES</b> as you mention it.
The code creates a <b>Field Catalog</b>, and while creating a field catalog you just need to put in the <b>names of the fields you require</b>. The additional '<b>tabname</b>' field provided is not required, but helps in finding the characteristics of the field like domain name etc..
In case you need an internal table with <b>"your" fields</b>, all you need to do is:
1) Build a fieldcatalog (like its done in ALV) i.e. put all the fieldnames that you require in your internal table and create a fieldcatalog.
2) Call the cl_alv_table_create=>create_dynamic_table method as shown below.
CALL METHOD cl_alv_table_create=>create_dynamic_table EXPORTING it_fieldcatalog = it_fieldcat IMPORTING ep_table = new_table.
The new_table has the fields that you require.
If this does not work...
Either I have not understood your problem correctly or you have not understood my answer correctly.
Regards,
Subramanian V.
‎2004 Nov 03 9:12 PM
Subramanian,
Thank you for your response, I realized what my problem was, I specified ls_alv_cat-ref_table and ls_alv_cat-ref_field fields and that's what gave me issues even if I omit ls_alv_cat-ref_table. But If I omit both of these fields my issue is solved.
The only problem I am still having is when I don't specify the above-mentioned fields, the data type for all fields gets automatically assigned to 'C'.
‎2004 Nov 04 3:31 AM
Hi Naoki,
I am glad , I could be of help to you.
Can you brief, what problem you are facing , if all fields gets automatically assigned to 'C'(character) ?
Any particular conversion problems ?
Not able to add ?
or anything similar to that.
Regards,
Subramanian V.
‎2004 Nov 09 5:06 PM
Subramanian,
It was essential for me to create a dynamic table that would take the exact attributes (particularly datatypes) of the original table (for selected field).
To do that I used INTTYPE field in the fieldcatalog to pass corresponding datatype (P,C,N,I etc.) It was done in a somewhat brute-force way but it worked.
Thank you.
‎2004 Nov 10 3:17 AM
There is no need to hardcode.
You could have used the DESCRIBE FIELD <FIELDNAME> TYPE <FIELDTYPE>.
Regards,
Subramanian V.
‎2004 Nov 10 8:52 AM
Hi,
here is the 6.40-way to create an dynmaic internal table. You can create dynamic type objects of RTTS (Run Time Type Services). RTTS is well known RTTI enhanced with methods for RTTC (Run Time Type Creation).
<b>DATA: struc_type TYPE REF TO cl_abap_structdescr,
table_type TYPE REF TO cl_abap_tabledescr,
comp_tab TYPE cl_abap_structdescr=>component_table,
comp LIKE LINE OF comp_tab,
sref TYPE REF TO data,
tref TYPE REF TO data.
FIELD-SYMBOLS: <struc> TYPE ANY,
<table> TYPE ANY TABLE.
comp-name = 'column1'.
comp-type = cl_abap_elemdescr=>get_c( 40 ).
APPEND comp TO comp_tab.
comp-name = 'column2'.
comp-type = cl_abap_elemdescr=>get_i( ).
APPEND comp TO comp_tab.
struc_type = cl_abap_structdescr=>create( comp_tab ).
table_type = cl_abap_tabledescr=>create( struc_type ).
CREATE DATA: sref TYPE HANDLE struc_type,
tref TYPE HANDLE table_type.
ASSIGN: sref->* TO <struc>,
tref->* TO <table>.
...
LOOP AT <table> ASSIGNING <struc>.
...
ENDLOOP.</b>
‎2009 Apr 24 4:44 AM
Hi All,
I have somehow a related scenario here.
For example I have internal table t_output containing 11 columns, how can I create dynamically a new internal table from t_output?