2016 Jan 26 4:36 PM
Hello,
I have looked at a number of discussions and I don't not find what I am looking for. What I trying to do is parse a field using a table structure dynamically to move data to another corresponding field in another structure.
Here is the code I have...
FIELD-SYMBOLS:
<structure> TYPE ANY,
<structurex> TYPE ANY,
<field> TYPE ANY,
<fieldx> TYPE ANY.
DATA: ls_DFIES TYPE DFIES.
CLEAR: cv_VARKEY.
** - Get Key Structure
READ TABLE it_DFIES INTO ls_DFIES INDEX 1.
** - Assign Structure to FIELD_SYMBOL
ASSIGN ls_DFIES-TABNAME TO <structure>. <structure> = is_MPX_CTL_VARKEY.
ASSIGN ls_DFIES-TABNAME TO <structurex>. <structurex> = cv_VARKEY.
DO iv_INDEX TIMES.
ASSIGN COMPONENT sy-TABIX OF STRUCTURE <structure> TO <field>.
ASSIGN COMPONENT sy-TABIX OF STRUCTURE <structurex> TO <fieldx>.
<fieldx> = <field>.
ENDDO.
I thought the ASSIGN for cause the <structure> to have the structure of the table. Then I could move the value of the field to be parsed. But it is not working. I could use some help.
Thank you in advance.
Best Regards, Dean.
2016 Jan 26 5:02 PM
I assume that ls_DFIES-TABNAME has only the table name for which you want to have structure created and assigned into <structure>.
For your logic to work, you would need to have the proper structure and that needs to be assigned to <structure>. ASSIGN will not create the structure dynamically. To create dynamic structure you would need to use the RTTS (if fields are dynamic) or you can use dynamic type reference if the reference is a DDIC structure.
data: o_data type ref to data.
FIELD-SYMBOLS: <structure> type any.
data: lv_type type char30.
lv_type = 'T001'.
create data o_data type (lv_type).
ASSIGN o_data->* to <structure>.
Once you have <structure> assigned, you can use the DO loop to assign the field.
Thanks,
Naimesh Patel
Hello,
I have looked at a number of discussions and I don't not find what I am looking for. What I trying to do is parse a field using a table structure dynamically to move data to another corresponding field in another structure.
Here is the code I have...
FIELD-SYMBOLS:
<structure> TYPE ANY,
<structurex> TYPE ANY,
<field> TYPE ANY,
<fieldx> TYPE ANY.
DATA: ls_DFIES TYPE DFIES.
CLEAR: cv_VARKEY.
** - Get Key Structure
READ TABLE it_DFIES INTO ls_DFIES INDEX 1.
** - Assign Structure to FIELD_SYMBOL
ASSIGN ls_DFIES-TABNAME TO <structure>. <structure> = is_MPX_CTL_VARKEY.
ASSIGN ls_DFIES-TABNAME TO <structurex>. <structurex> = cv_VARKEY.
DO iv_INDEX TIMES.
ASSIGN COMPONENT sy-TABIX OF STRUCTURE <structure> TO <field>.
ASSIGN COMPONENT sy-TABIX OF STRUCTURE <structurex> TO <fieldx>.
<fieldx> = <field>.
ENDDO.
I thought the ASSIGN for cause the <structure> to have the structure of the table. Then I could move the value of the field to be parsed. But it is not working. I could use some help.
Thank you in advance.
Best Regards, Dean.
2016 Jan 26 4:52 PM
I think I see only two mistakes here:
ASSIGN COMPONENT sy-tabix OF STRUCTURE (<structure>) TO <field>.
ASSIGN COMPONENT sy-tabix OF STRUCTURE (<structurex>) TO <fieldx>.
That should work.
2016 Jan 26 4:57 PM
Hello Juan,
If I do that, the ABAP syntax checker gives me this...
Field "(<STRUCTURE>)" is unknown. It is neither in one of the specified tables nor defined by a "DATA" statement. "DATA" statement.
Thank you for your input.
2016 Jan 26 5:02 PM
I assume that ls_DFIES-TABNAME has only the table name for which you want to have structure created and assigned into <structure>.
For your logic to work, you would need to have the proper structure and that needs to be assigned to <structure>. ASSIGN will not create the structure dynamically. To create dynamic structure you would need to use the RTTS (if fields are dynamic) or you can use dynamic type reference if the reference is a DDIC structure.
data: o_data type ref to data.
FIELD-SYMBOLS: <structure> type any.
data: lv_type type char30.
lv_type = 'T001'.
create data o_data type (lv_type).
ASSIGN o_data->* to <structure>.
Once you have <structure> assigned, you can use the DO loop to assign the field.
Thanks,
Naimesh Patel
2016 Jan 26 5:20 PM
Please don't be offended.... DUDE!... That did it! Thank you.
2016 Jan 26 5:24 PM
To help you understand this, i'll try to explain what your code currently is doing.
To do so, i will assume READ TABLE it_DFIES INTO ls_DFIES INDEX 1. results in:
LS_DFIES-TABNAME = 'EXAMPLE'.
>> ASSIGN ls_DFIES-TABNAME TO <structure>.
<structure> now is pointing to the field TABNAME of the structure LS_DFIES. It therefor has the value 'EXAMPLE'!
>> <structure> = is_MPX_CTL_VARKEY.
Now you have overwritten the field TABNAME of LS_DFIES. Your assignment is equivalent to LS_DFIES-TABNAME = IS_MPX_CTL_VARKEY
>> ASSIGN ls_DFIES-TABNAME TO <structurex>. <structurex> = cv_VARKEY.
<structurex> after the ASSIGN also points the field TABNAME of LS_DFIES, therefor its value is the same as IS_MPX_CTL_VARKEY - but now gets overridden with CV_VARKEY, which was CLEARed before. Therefor LS_DFIES-TABNAME now is empty.
>> ASSIGN COMPONENT sy-TABIX OF STRUCTURE <structure> TO <field>.
This statement fails (sy-subrc gets set to 4), because <structure> is not a structure. It is still pointing to LS_DFIES-TABNAME, so it is of type TABNAME and currently is empty.
The next ASSIGN also fails, and "<fieldx> = <field>" finally dumps because of the failed assignments.
Kind regards,
Thomas
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |