2006 Feb 03 12:45 PM
I am using the RTTS services to dynamically create a table. However, when I attempt to use the get_components method it does not return all the components for all tables that I am working with.
Cases and End Results
1) Created structure in data dictionary get_components works.
2) Pass PA0001, P0001 or T001P to get_components and I do not receive the correct results. It only returns a small subset of these objects. The components table has all the entries; however, the get_components method only returns about 4 rows.
Can you explain this and point me to the correct logic sequence? I would like the logic to work with all tables.
Code excerpt below:
The logic for the get components works for case 1, but not case 2. When I pass into this method a "Z" custom table or structure name for parameter structure_name and the get_components() method executes and returns the correct results. However, when I pass in any of the objects listed above in case 2, the get_components method does not return the correct number of entries. When I check typ_struct which is populated right before the get_components line, I see the correct number of components in the components table.
method pb_add_column_headings .
constants: c_generic_struct type c length 19 value 'ZXX_COLUMN_HEADINGS'.
data: cnt_lines type sytabix,
rf_data type ref to data,
typ_field type ref to cl_abap_datadescr,
typ_struct type ref to cl_abap_structdescr,
typ_table type ref to cl_abap_tabledescr.
data: wa_col_headings type ddobjname.
data: rf_tbl_creation_exception type ref to
cx_sy_table_creation,
rf_struct_creation_exception type ref to
cx_sy_struct_creation.
data: t_comp_tab type
cl_abap_structdescr=>component_table,
t_comp_tab_new like t_comp_tab,
t_comp_tab_imported like t_comp_tab.
field-symbols: <fs_comp> like line of t_comp_tab,
<fs_col_headings_tbl> type any table.
**Get components of generic structure
wa_col_headings = c_generic_struct.
typ_struct ?= cl_abap_typedescr=>describe_by_name(
wa_col_headings ).
T_COMP_TAB = typ_struct->get_components( ).
**Determine how many components in imported structure.
typ_struct ?= cl_abap_typedescr=>describe_by_name(
structure_name ).
t_comp_tab_imported = typ_struct->get_components( ).
cnt_lines = lines( t_comp_tab_imported[] ).
2006 Feb 03 12:55 PM
Hi Garton,
1. GET_COMPONENT_LIST
Use this FM.
It gives all fieldnames.
2. Use this code (just copy paste)
REPORT abc.
DATA : cmp LIKE TABLE OF rstrucinfo WITH HEADER LINE.
DATA : pa0001 LIKE TABLE OF pa0001 WITH HEADER LINE.
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
program = sy-repid
fieldname = 'PA0001'
TABLES
components = cmp.
LOOP AT cmp.
WRITE 😕 cmp-compname.
ENDLOOP.
regards,
amit m.
2006 Feb 03 12:55 PM
Hi Garton,
1. GET_COMPONENT_LIST
Use this FM.
It gives all fieldnames.
2. Use this code (just copy paste)
REPORT abc.
DATA : cmp LIKE TABLE OF rstrucinfo WITH HEADER LINE.
DATA : pa0001 LIKE TABLE OF pa0001 WITH HEADER LINE.
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
program = sy-repid
fieldname = 'PA0001'
TABLES
components = cmp.
LOOP AT cmp.
WRITE 😕 cmp-compname.
ENDLOOP.
regards,
amit m.
2006 Feb 03 1:37 PM
Thanks for this information. however, I was looking for an answer to why the method get_components in class cl_abap_structdescr is not working with all tables. I am aware of this FM; however, I was looking for a solution in RTTS.
Thanks,
john
2006 Feb 03 1:44 PM
Hi again,
1. The reason could be
.INCLUDE
2. If in se11,
u see PA0001.
3. It has 4 rows. (basic definition)
MANDT
.INCLUDE
.INCLUDE
.INCLUDE
4. May be,
the RTTS does not EXPAND
these .INCLUDE
AND RETURNS ONLY 4 ROWS.
regards,
amit m.
2006 Feb 03 7:04 PM
The answer to my question was right under my nose and I did not see it at first.
There is a method in the same class that does what I wanted. It will traverse multiple levels of include statements to return a table with just the components in it.
Method: get_included_view( )
You pass in an integer value to determine how deep you want to traverse.
Now I check the field HAS_INCLUDE and if its checked, then I call get_included_view otherwise I call get_components().
John