2013 Nov 17 10:40 AM
moderator: updated post
Hi Experts,
I have a module function with an Implicit type Table in parameter (not type defined): OUTPUT. And in my MF, I built a FieldSymbol Table. I don't know how to CAST my FieldSymbol Table to my OUTPUT table (Implicit type Table Parameter).
Of course, I am trying to find a generic solution to fix my need because I could have any type of table paramter and any FieldSymbol Table type. Please, check the code out below:
(note: the aim is to move the data table of my <FS> into my OUTPUT table without using loop-fieldname (cause it's generic))
FUNCTION zmy_mf.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(NAME_STRUCTURE) TYPE STRING
*" TABLES
*" OUTPUT
*" EXCEPTIONS
*"----------------------------------------------------------------------
*" ... ... ... CODE
PERFORM buid TABLES output.
ENDFUNCTION.
FORM build TABLES ft_out
*" ... ... ... CODE
ft_out[] = <ft_table>[]
ENDFORM.
DEBUG MOD "FT_OUT" table :
DEBUG MOD "FS_TABLE" table :
To fix my need I think I have 2 solutions:
First,
I move all my table <FT_TABLE> into OUTPUT table with an implicit CAST. (?)
otherwise,
I have the name of the structure in my MF parameter using for casting my OUTPUT : "NAME_STRUCTURE" then: How could I cast my OUTPUT table with the name string structure "NAME_STRUCTURE" (e.g: NAME_STRUCTURE = 'MARA' and it's also the same type of table of my <ft_table> that was at first a TYPE STANDART TABLE and became a Type Table 'MARA' in my example) and only afterwards, I will move easily my table data <ft_table> into my output[] like that :
output[] = <ft_table>[]
To summurize:
1) CAST my OUTPUT table type with the same non explicit table type of <ft_table>
or
2) CAST my OUTPUT table type with the "name_structure" string. Also the same type of my <ft_table>.
Any idea?
Many thx for your help.
Rachid
2013 Nov 17 12:52 PM
I am not sure if have understood you correctly.
Check this logic
Input is the structure name, say mara, it will create a table of that structure and assign it to a field symbol.
FUNCTION ZMY_MF.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(STR_NAME) TYPE STRING
*" TABLES
*" OUT_TAB
*"----------------------------------------------------------------------
FIELD-SYMBOLS : <fs_tab> TYPE STANDARD TABLE , <fs1>.
data gen_table TYPE REF TO data.
*
create data gen_table type TABLE OF (str_name).
ASSIGN gen_table->* to <fs_tab> .
write 😕 .
ENDFUNCTION.
Now <fs_tab> will be a table with the same datatype as the input parameter .
moderator: updated post
Hi Experts,
I have a module function with an Implicit type Table in parameter (not type defined): OUTPUT. And in my MF, I built a FieldSymbol Table. I don't know how to CAST my FieldSymbol Table to my OUTPUT table (Implicit type Table Parameter).
Of course, I am trying to find a generic solution to fix my need because I could have any type of table paramter and any FieldSymbol Table type. Please, check the code out below:
(note: the aim is to move the data table of my <FS> into my OUTPUT table without using loop-fieldname (cause it's generic))
FUNCTION zmy_mf.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(NAME_STRUCTURE) TYPE STRING
*" TABLES
*" OUTPUT
*" EXCEPTIONS
*"----------------------------------------------------------------------
*" ... ... ... CODE
PERFORM buid TABLES output.
ENDFUNCTION.
FORM build TABLES ft_out
*" ... ... ... CODE
ft_out[] = <ft_table>[]
ENDFORM.
DEBUG MOD "FT_OUT" table :
DEBUG MOD "FS_TABLE" table :
To fix my need I think I have 2 solutions:
First,
I move all my table <FT_TABLE> into OUTPUT table with an implicit CAST. (?)
otherwise,
I have the name of the structure in my MF parameter using for casting my OUTPUT : "NAME_STRUCTURE" then: How could I cast my OUTPUT table with the name string structure "NAME_STRUCTURE" (e.g: NAME_STRUCTURE = 'MARA' and it's also the same type of table of my <ft_table> that was at first a TYPE STANDART TABLE and became a Type Table 'MARA' in my example) and only afterwards, I will move easily my table data <ft_table> into my output[] like that :
output[] = <ft_table>[]
To summurize:
1) CAST my OUTPUT table type with the same non explicit table type of <ft_table>
or
2) CAST my OUTPUT table type with the "name_structure" string. Also the same type of my <ft_table>.
Any idea?
Many thx for your help.
Rachid
2013 Nov 17 12:52 PM
I am not sure if have understood you correctly.
Check this logic
Input is the structure name, say mara, it will create a table of that structure and assign it to a field symbol.
FUNCTION ZMY_MF.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(STR_NAME) TYPE STRING
*" TABLES
*" OUT_TAB
*"----------------------------------------------------------------------
FIELD-SYMBOLS : <fs_tab> TYPE STANDARD TABLE , <fs1>.
data gen_table TYPE REF TO data.
*
create data gen_table type TABLE OF (str_name).
ASSIGN gen_table->* to <fs_tab> .
write 😕 .
ENDFUNCTION.
Now <fs_tab> will be a table with the same datatype as the input parameter .
2013 Nov 17 1:11 PM
Sorry,
I repeat again.
Basicly, I have this: <FS_TABLE> (you fix it with me in another topic ).
This <FS> contents:
and I want to move lines of the <F> in this table below:
this statement is not possible:
ft_out[] = <ft_table>[]
because I will have a type conflict.
And need to find a generic way to resolve the MOVE Data of <FS> to FT_OUT, (I have to CAST my FT_OUT type with the same type of my <FS> before).
2013 Nov 17 1:25 PM
This <fs_table> table, is it available in the function module?
2013 Nov 17 1:34 PM
What do you want to mean by "available in the MF" ?
You want to mean: in the parameter of the MF ?
2013 Nov 17 1:58 PM
otherwise, the <FS> in only available in a subroutine of the MF.
2013 Nov 17 1:59 PM
Hi Rachid,
your problem is that the structure ft_out is unknown. I guess Susmitha was trying to explain that to you with her example. Here I put an idea below, may be that helps:
FUNCTION z_sdn_3455548.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(NAME_STRUCTURE) TYPE STRING
*" TABLES
*" OUTPUT TYPE STANDARD TABLE
*"----------------------------------------------------------------------
DATA: lr_t_ref TYPE REF TO data.
FIELD-SYMBOLS: <ft_table> TYPE ANY TABLE.
CREATE DATA lr_t_ref TYPE TABLE OF (name_structure).
PERFORM build USING name_structure
lr_t_ref.
ASSIGN lr_t_ref->* TO <ft_table>.
MOVE <ft_table>[] TO output[].
ENDFUNCTION.
FORM build USING name_structure
r_ref TYPE REF TO data.
DATA: lr_t_ref TYPE REF TO data.
FIELD-SYMBOLS: <ft_table> TYPE ANY TABLE.
CREATE DATA lr_t_ref TYPE TABLE OF (name_structure).
ASSIGN lr_t_ref->* TO <ft_table>.
SELECT * FROM (name_structure) INTO TABLE <ft_table>.
GET REFERENCE OF <ft_table> INTO r_ref.
ENDFORM. "build
2013 Nov 18 4:27 AM
Hi,
The code I had given above creates a table of the structure that you are passing in the parameter.
ie. if you pass structure mara, it will create a table of structure mara, accessed by <fs_tab>.
You just need to move the table contents <ft_table> to <fs_tab> using move statement.
move <ft_table>[] to <fs_tab>[]. will work fine.
Refer the following for the complete code.
FUNCTION ZMY_MF.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(STR_NAME) TYPE STRING
*" REFERENCE(FT_IN)
*" EXPORTING
*" REFERENCE(OUT_TAB) TYPE ANY
*"----------------------------------------------------------------------
FIELD-SYMBOLS : <fs_tab> type STANDARD TABLE,
data gen_table TYPE REF TO data.
* Create a table of whose structure is the input parameter
create data gen_table type TABLE OF (str_name).
ASSIGN gen_table->* to <fs_tab> .
perform build using <fs_tab>.
ENDFUNCTION.
form build using output type standard table .
* Your code for <ft_table>
move <ft_table>[] to output[].
endform.
2013 Nov 18 8:59 AM
Hi Sascha, Susan,
I found also an other way to fix it:
DATA ft_generic TYPE REF TO data.
DATA lo_trex_serializable TYPE REF TO cl_trex_test_table.
FIELD-SYMBOLS <fs_table> TYPE STANDARD TABLE.
" Create object CASTED from Field Symbol STANDARD Type
cl_trex_test_table=>create_test_table(
IMPORTING rval= lo_trex_serializable
CHANGING table = <fs_table>
).
" Get the DATA from a FIELD Symbol to our Generic Explicit Table
ft_generic = lo_trex_serializable->get_itab( ) .
2013 Nov 18 9:01 AM
Hi,
I tried your code but doesn't work for me. I forgot why ... I found an other solution to fix it.
Thx for your help.
Rachid.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |