‎2009 May 14 10:34 AM
Hi all,
I'm explaining my problem :
I want to create a function with two parameters in entry :
(IMPORT) - structure_name with type DD02L-TABNAME
(TABLES) - t_outtab with empty type
t_outtab will be in structure_name type.
Now, in my source function, I want to retrieve all contain of t_outtab in another internal table or field-symbol. I don't know in advance the used structures in my function entries.
I don't manage to get this contain, cause I can't do :
DATA : internal_table TYPE structure_name*
OR
DATA : internal_table TYPE (structure_name)
OR used field-symbol
DATA : internal_table TYPE <fs>* where <fs> had structure name value.
To do more later :
*DATA : line LIKE LINE OF internal_table. *
*internal_table][ = t_outtab][. *
And work with this table.
_ I tried different solutions like : _
Get the structure of the table.
ref_table_des ?= cl_abap_typedescr=>describe_by_name( I_STRUCTURE_NAME ).
idetails[] = ref_table_des->components[].
Get the first structure table of result table
LOOP AT idetails INTO xdetails.
CLEAR: xfc.
xfc-fieldname = xdetails-name .
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
APPEND xfc TO ifc.
ENDLOOP.
Create dynamic internal table and assign to FS
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO <dyn_table>.
Create dynamic work area and assign to FS
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
and retrieve to <dyn_table>[] = t_outtab[].
the but I don't try the solution. If someone have an idea.
Thanks and regards.
Romain
Edited by: Romain L on May 14, 2009 11:35 AM
‎2009 May 14 10:46 AM
Hi,
Try this if possible.
Data : Y_TABLE type ref to data.
field-symbols: <FS_TABLE?> type any.
Create data Y_TABLE like ( name of your outtab)
Assign Y_TABLE->* to <FS_TABLE>
Regards,
Ankur Parab
‎2009 May 14 10:41 AM
Hi,
We can acheive this using dynamic internal tables.
Please find sample below.
*Creating Dynamic internal table
PARAMETERS : p_table(10) TYPE C.
DATA: w_tabname TYPE w_tabname,
w_dref TYPE REF TO data,
w_grid TYPE REF TO cl_gui_alv_grid.
FIELD-SYMBOLS: <t_itab> TYPE ANY TABLE.
w_tabname = p_table.
CREATE DATA w_dref TYPE TABLE OF (w_tabname).
ASSIGN w_dref->* TO <t_itab>.
* Populating Dynamic internal table
SELECT *
FROM (w_tabname) UP TO 20 ROWS
INTO TABLE <t_itab>.
* Displaying dynamic internal table using Grid.
CREATE OBJECT w_grid
EXPORTING i_parent = cl_gui_container=>screen0.
CALL METHOD w_grid->set_table_for_first_display
EXPORTING
i_structure_name = w_tabname
CHANGING
it_outtab = <t_itab>.
CALL SCREEN 100.
* Scenario 2:
*Create a dynamic internal table with the specified number of columns.
* Creating Dynamic internal table
TYPE-POOLS: slis.
FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE, u201C Dynamic internal table name
<fs_dyntable>, u201C Field symbol to create work area
<fs_fldval> type any. u201C Field symbol to assign values
PARAMETERS: p_cols(5) TYPE c. u201C Input number of columns
DATA: t_newtable TYPE REF TO data,
t_newline TYPE REF TO data,
t_fldcat TYPE slis_t_fldcat_alv,
t_fldcat TYPE lvc_t_fcat,
wa_it_fldcat TYPE lvc_s_fcat,
wa_colno(2) TYPE n,
wa_flname(5) TYPE c.
* Create fields .
DO p_cols TIMES.
CLEAR wa_it_fldcat.
move sy-index to wa_colno.
concatenate 'COL'
wa_colno
into wa_flname.
wa_it_fldcat-fieldname = wa_flname.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 10.
APPEND wa_it_fldcat TO t_fldcat.
ENDDO.
* Create dynamic internal table and assign to FS
CALL METHOD cl_alv_table_create=>create_dynamic_table
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>.
*Populating Dynamic internal table
DATA: fieldname(20) TYPE c.
DATA: fieldvalue(10) TYPE c.
DATA: index(3) TYPE c.
DO p_cols TIMES.
index = sy-index.
MOVE sy-index TO wa_colno.
CONCATENATE 'COL'
wa_colno
INTO wa_flname.
* Set up fieldvalue
CONCATENATE 'VALUE' index INTO
fieldvalue.
CONDENSE fieldvalue NO-GAPS.
ASSIGN COMPONENT wa_flname
OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
<fs_fldval> = fieldvalue.
ENDDO.
* Append to the dynamic internal table
APPEND <fs_dyntable> TO <t_dyntable>.
* Displaying dynamic internal table using Grid.
DATA: wa_cat LIKE LINE OF fs_fldcat.
DO p_cols TIMES.
CLEAR wa_cat.
MOVE sy-index TO wa_colno.
CONCATENATE 'COL'
wa_colno
INTO wa_flname.
wa_cat-fieldname = wa_flname.
wa_cat-seltext_s = wa_flname.
wa_cat-outputlen = '10'.
APPEND wa_cat TO fs_fldcat.
ENDDO.
* Call ABAP List Viewer (ALV)
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = fs_fldcat
TABLES
t_outtab = <t_dyntable>.
Thanks,
Jyothi
Edited by: Jyothi on May 14, 2009 11:42 AM
Edited by: Jyothi on May 14, 2009 11:43 AM
‎2009 May 14 10:46 AM
Hi,
Try this if possible.
Data : Y_TABLE type ref to data.
field-symbols: <FS_TABLE?> type any.
Create data Y_TABLE like ( name of your outtab)
Assign Y_TABLE->* to <FS_TABLE>
Regards,
Ankur Parab
‎2009 May 14 11:01 AM
Thanks for this answers.
I tried your declaration. I can build function without errors.
But now, how can I retrieve data of my t_outtab in <FS_TABLE> ?
For your solution Jyothi, I will look more precisely your program.
Thanks and regards.
Romain
‎2009 May 14 11:07 AM
Hi,
Just use assign statement.
Assign outtab to <FS>.
Regards,
Ankur Parab
‎2009 May 14 11:35 AM
Thanks for,
Data : Y_TABLE type ref to data.
field-symbols: <FS_TABLE> type any.
Create data Y_TABLE like t_outtab.
Assign Y_TABLE->* to <FS_TABLE>.
-
Now I know that for all structure in entry parameter, there is the fieldname "VBELN".
How to loop on <FS_TABLE> and retrieve for each line of <FS_TABLE> the value fieldname of VBELN' please ?
Thanks and regards.
Romain
‎2009 May 14 11:42 AM
Hi,
Do it as follows.
data : y_lv_new_line type ref to data.
field-symbols : <FS_LINE>, <FS_DATA>
CREATE DATA y_lv_new_line LIKE LINE OF <FS_TABLE>.
assign y_lv_new_line->* to <FS_LINE>.
Now your <FS_LINE> will become a work area having the same strcture as <FS_TABLE>.
LOOP at <FS_TABLE> assigning <FS_LINE>.
endloop.
Suppose you want to access the field VBELN of the table
then you will have to wite a statement as follows
ASSIGN component 'VBELN' of structure <FS_LINE> to <FS_DATA>.
<FS_DATA> will now have the value of the field VBELN of the particualr row.
I hope this helps you.
REgards,
Ankur Parab
‎2009 May 14 11:53 AM
Thanks a lot for your help,
Data : Y_TABLE type ref to data.
field-symbols: <FS_TABLE> TYPE ANY.
Create data Y_TABLE like t_outtab.
Assign Y_TABLE->* to <FS_TABLE>.
*CREATE LINE & DATA
data : y_lv_new_line type ref to data.
field-symbols : <FS_LINE>, <FS_DATA>.
CREATE DATA y_lv_new_line LIKE LINE OF <FS_TABLE>.
assign y_lv_new_line->* to <FS_LINE>.
LOOP at <FS_TABLE> assigning <FS_LINE>.
ASSIGN component 'VBELN' of structure <FS_LINE> to <FS_DATA>.
write <FS_DATA>.
endloop.
I have a build error "<FS_TABLE> is not an internal table".
If I tried to change "<FS_TABLE> TYPE ANY" by "<FS_TABLE> TYPE STANDARD TABLE" , I have a dump "Assign_type_conflict".
If you have an idea, I will take it.
Thanks and regards
Romain
‎2009 May 14 12:04 PM
field-symbols: <FS_TABLE> TYPE ANY.
Obviously this is not a table, declare like this:
field-symbols: <FS_TABLE> TYPE STANDARD TABLE or
field-symbols: <FS_TABLE> TYPE ANY TABLE
‎2009 May 14 12:11 PM
Hi,
Please check the following code and you will understand.
TYPES : BEGIN OF itab,
vbeln TYPE vbrk-vbeln,
END OF itab.
DATA : itab TYPE STANDARD TABLE OF itab.
DATA : wa TYPE itab.
DATA : obj1 TYPE REF TO data,
obj2 TYPE REF TO data.
FIELD-SYMBOLS : <fs_table> TYPE ANY TABLE,
<fs_line> TYPE ANY,
<fs_field> TYPE ANY.
wa-vbeln = '123'.
APPEND wa TO itab.
CREATE DATA obj1 LIKE itab.
ASSIGN obj1->* TO <fs_table>.
IF <fs_table> IS ASSIGNED.
<fs_table> = itab[].
CREATE DATA obj2 LIKE LINE OF <fs_table>.
ASSIGN obj2->* TO <fs_line>.
LOOP AT <fs_table> ASSIGNING <fs_line>.
ASSIGN COMPONENT 'VBELN' OF STRUCTURE <fs_line> TO <fs_field>.
IF <fs_field> IS ASSIGNED.
WRITE <fs_field>.
ENDIF.
ENDLOOP.
ENDIF.Regards,
Ankur Parab
‎2009 May 14 1:49 PM
I tested ur code in a program, it's work thanks.... but ... look at that when i uses a function :
REPORT ZmyPgm.
TYPES : BEGIN OF itab,
vbeln TYPE vbrk-vbeln,
END OF itab.
DATA : itab TYPE STANDARD TABLE OF itab.
DATA : wa TYPE itab.
wa-vbeln = '123'.
APPEND wa TO itab.
CALL FUNCTION 'ZmyFunction'
* EXPORTING
* I_STRUCTURE_NAME =
TABLES
t_outtab = itab
.
-
My function
DATA : obj1 TYPE REF TO data,
obj2 TYPE REF TO data.
FIELD-SYMBOLS : <fs_table> TYPE ANY TABLE,
<fs_line> TYPE ANY,
<fs_field> TYPE ANY.
CREATE DATA obj1 LIKE t_outtab.
ASSIGN obj1->* TO <fs_table>.
IF <fs_table> IS ASSIGNED.
<fs_table> = t_outtab[].
CREATE DATA obj2 LIKE LINE OF <fs_table>.
ASSIGN obj2->* TO <fs_line>.
LOOP AT <fs_table> ASSIGNING <fs_line>.
ASSIGN COMPONENT 'VBELN' OF STRUCTURE <fs_line> TO <fs_field>.
IF <fs_field> IS ASSIGNED.
WRITE <fs_field>.
ENDIF.
ENDLOOP.
ENDIF.
-
I've an error at line ("ASSIGN obj1->* TO <fs_table>.") in my function. Error is "ASSIGN_TYPE_CONFLICT". I don't understand, if you have an idea..
Thanks you.
Best regards.
Romain
Edited by: Romain L on May 14, 2009 2:49 PM
‎2009 May 14 1:58 PM
How did you TYPE the import parameter of the internal table in FM?
It should be generic type as well.
IT_ITAB TYPE STANDARD TABLE
‎2009 May 14 2:06 PM
My t_outtab was declared, not in import but in table with an empty type.
I changed my declaration : i declared my t_outtab in import with standard type.
It's works.
Thanks you a lot everybody.
Best regards.
Romain