2008 Nov 28 7:43 AM
hello!
what i try to do is following
eg:
when i call my function the user has the possibility to check the flag "show_button = 'X', and exports a table
when this flag is checked i want to display an icon in the first row of this table, so i need to extend the table structure which i import and add another attribute.
what i actually tried to achieve is this (but this is not working of course)
function
import:
i_outtab type standard table.
field-symbols:
<itab> type standard table.
assign i_outtab to <itab>.
TYPES: begin of mytyp.
types: i_bt type iconname.
INCLUDE STRUCTURE <itab>
TYPES: end of mytyp.and then i create a table with the type mytyp (which is not working, but i shows what i try to do)
so is there a way to do this genericly?
2008 Nov 28 8:34 AM
Hi,
Since your import parameter is a generic type, you can pass back another table of any type with the icon field included. You can take look at the example BCALV_TABLE_CREATE.
There is a method called create_dynamic_table of the class cl_alv_table_create to which you can pass the fieldcatalog.
Now this field catalog you can prepare by first getting the components of the table that is passed to the function module using the cl_abap_structdescr
Something like this :
DATA : BEGIN OF t_comp OCCURS 0,
comp(5) TYPE c,
END OF t_comp.
DATA : l_struc TYPE REF TO cl_abap_structdescr.
DATA : l_typedesc TYPE REF TO cl_abap_typedescr.
DATA : lt_comp TYPE abap_compdescr_tab,
w_comp LIKE LINE OF lt_comp.
*Call the static method of the structure descriptor describe_by_data
CALL METHOD cl_abap_structdescr=>describe_by_data
EXPORTING
p_data = <itab> " In your case.
RECEIVING
p_descr_ref = l_typedesc.
*The method returns a reference of a type descriptor class therefore we
*need to Cast the type descriptor to a more specific class i.e
*Structure Descriptor.
l_struc ?= l_typedesc.
*Use the Attribute COMPONENTS of the structure Descriptor class to get
*the field names of the structure
lt_comp = l_struc->components.
Then you can build the fieldcatalog based on the components of the input table and adding the icon field as follows :
1. First add the icon field to the fieldcatalog.
2. Then looping at the components populate other fields of the table.
LOOP AT lt_comp INTO w_comp.
ENDLOOP
Then call the cl_alv_table_create method by passing the fieldcatalog.
regards,
Advait
hello!
what i try to do is following
eg:
when i call my function the user has the possibility to check the flag "show_button = 'X', and exports a table
when this flag is checked i want to display an icon in the first row of this table, so i need to extend the table structure which i import and add another attribute.
what i actually tried to achieve is this (but this is not working of course)
function
import:
i_outtab type standard table.
field-symbols:
<itab> type standard table.
assign i_outtab to <itab>.
TYPES: begin of mytyp.
types: i_bt type iconname.
INCLUDE STRUCTURE <itab>
TYPES: end of mytyp.and then i create a table with the type mytyp (which is not working, but i shows what i try to do)
so is there a way to do this genericly?
2008 Nov 28 8:11 AM
Hi Thomas,
Please Follow this link where you have full details about creation of generic types:
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb366d358411d1829f0000e829fbfe/content.htm.
Hope This helps,
Regards,
Rahul Sinha.
2008 Nov 28 8:24 AM
2008 Nov 28 8:34 AM
Hi,
Since your import parameter is a generic type, you can pass back another table of any type with the icon field included. You can take look at the example BCALV_TABLE_CREATE.
There is a method called create_dynamic_table of the class cl_alv_table_create to which you can pass the fieldcatalog.
Now this field catalog you can prepare by first getting the components of the table that is passed to the function module using the cl_abap_structdescr
Something like this :
DATA : BEGIN OF t_comp OCCURS 0,
comp(5) TYPE c,
END OF t_comp.
DATA : l_struc TYPE REF TO cl_abap_structdescr.
DATA : l_typedesc TYPE REF TO cl_abap_typedescr.
DATA : lt_comp TYPE abap_compdescr_tab,
w_comp LIKE LINE OF lt_comp.
*Call the static method of the structure descriptor describe_by_data
CALL METHOD cl_abap_structdescr=>describe_by_data
EXPORTING
p_data = <itab> " In your case.
RECEIVING
p_descr_ref = l_typedesc.
*The method returns a reference of a type descriptor class therefore we
*need to Cast the type descriptor to a more specific class i.e
*Structure Descriptor.
l_struc ?= l_typedesc.
*Use the Attribute COMPONENTS of the structure Descriptor class to get
*the field names of the structure
lt_comp = l_struc->components.
Then you can build the fieldcatalog based on the components of the input table and adding the icon field as follows :
1. First add the icon field to the fieldcatalog.
2. Then looping at the components populate other fields of the table.
LOOP AT lt_comp INTO w_comp.
ENDLOOP
Then call the cl_alv_table_create method by passing the fieldcatalog.
regards,
Advait
2008 Nov 28 8:39 AM
i know this way to create types.
but i want to create a type out of the structure i_outtab (which is the type standard table of)
and then i want to extend this type individually.
...like merging to table structures into one.
2008 Nov 28 11:21 AM
You can do that using the ABAP Run Time Type Services.
Example:
I have a function module Y_TEST with one Importing Parameter:
*"----------------------------------------------------------------------
*" IMPORTING
*" REFERENCE(IP_IT_DATA) TYPE ANY TABLE
*"----------------------------------------------------------------------
I have no idea about the table-structure and I want to add a field X_SELECTED of type XFELD to the end of the table to display it using CL_SALV_TABLE or something - this is how I do it:
FUNCTION y_test.
*"----------------------------------------------------------------------
*" IMPORTING
*" REFERENCE(IP_IT_DATA) TYPE ANY TABLE
*"----------------------------------------------------------------------
DATA:
gr_tabtype TYPE REF TO cl_abap_tabledescr,
gr_struc TYPE REF TO cl_abap_structdescr,
lr_itab TYPE REF TO data,
it_component TYPE cl_abap_structdescr=>component_table,
wa_component LIKE LINE OF it_component.
FIELD-SYMBOLS:
<wa> TYPE ANY.
* Reading 1st line of itab and getting structure ->
LOOP AT ip_it_data ASSIGNING <wa>.
gr_struc ?= cl_abap_typedescr=>describe_by_data( <wa> ).
EXIT.
ENDLOOP. "ip_it_data
* Getting all components ->
CHECK gr_struc IS BOUND.
it_component = gr_struc->get_components( ).
* Adding new field (X_SELECTED) to Component-Table ->
wa_component-name = 'X_SELECTED'.
wa_component-type ?= cl_abap_typedescr=>describe_by_name( 'XFELD ').
INSERT wa_component INTO TABLE it_component.
* Creating new structure-ref ->
CLEAR gr_struc.
CALL METHOD cl_abap_structdescr=>create
EXPORTING
p_components = it_component
RECEIVING
p_result = gr_struc.
* Creating new table-ref ->
CALL METHOD cl_abap_tabledescr=>create
EXPORTING
p_line_type = gr_struc
RECEIVING
p_result = gr_tabtype.
* Creating itab with our table-ref ->
CREATE DATA lr_itab TYPE HANDLE gr_tabtype.
ENDFUNCTION.
Hope that helped ...