Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Move field symbols of type any to internal table type standard

stefan_kolev4
Participant
0 Kudos
7,547

Hi,

I have a field symbols as a work area declared as of type ANY.

E.g

<fs> TYPE ANY.

Also I have an internal table declared as of TYPE STANDARD TABLE OF char32.

How can I MOVE/APPEND the contents of that work area (  <fs> ) to the internal table.

Please advise !

Stefan

1 ACCEPTED SOLUTION

yang_aiolos
Active Participant
0 Kudos
3,368

please use below code you will get what you want.

FIELD-SYMBOLS <fs_line> type any.

data ls_tab type ref to data.

data it_tab type standard TABLE OF char32 with header line.

create data ls_tab like line of it_tab.

ASSIGN ls_tab->* to <fs_line>.

<fs_line> = 'fs'.

append <fs_line> to it_tab.

loop at it_tab.

  write it_tab.

endloop.

i also want to tell u something.

1. you should create line type of your internal table.

create data ls_tab like line of it_tab.

2.assign it to 1 field symbol. then you can operate this work area.

ASSIGN ls_tab->* to <fs_line>.

15 REPLIES 15

JackGraus
Active Contributor
0 Kudos
3,368

First you need to assign the field-symbol to an exiting variable with: ASSIGN field TO <fs>

Then you can move the field symbol value into a table line variable: char32 = <fs>

Then you can append the table line into your table: INSERT char32 into table char32_table

Regards Jack

0 Kudos
3,368

Hi Jack,

Thank you for your reply. Let me clarify.

The following is a part of my code.

DATA: lt_string TYPE STANDARD TABLE OF char32. 

FIELD-SYMBOLS: <t_itab> TYPE ANY TABLE,
<fs_err_tab>
,
<fld>
,
<fs_string>
TYPE STANDARD TABLE.

ASSIGN <fs_stepid> TO <t_itab>.

<fs_stepid> has been declared as global field symbols and everytime it contains different table records.

Then I have...

 

LOOP AT <t_itab> ASSIGNING <fs_err_tab>.

* here I want to move/append <fs_err_tab> TO lt_string

ENDLOOP.

The system returns short dump, because of the different types.

Please advise !

Stefan

0 Kudos
3,368

Hi Stefan,

since lt_string is a standard table, you have the choice

  • APPEND <FS_ERR_TAB> TO LT_STRING, or
  • INSERT <FS_ERR_TAB> INTO TABLE LT_STRING.

If you work with "APPEND <fs_err_tab> TO lt_string.", your program should work as expected, with no dump, as long as the first 32 places of <fs_err_tab> can be moved to the target field which is of type CHAR32, i.e. as long as these 32 places belong to components of type CHAR, NUMC or similar. 

I tested it in my system (SAP_BASIS 702), with several types for <fs_err_tab> (and for the data object to which "<fs_err_tab> type any" is assigned at run time, but this makes no difference):

  • C LENGTH 100 (the remainder will be cut off - MOVE logic!)
  • C LENGTH 10,
  • T000,
  • VBAP (which isn't even CLIKE, but its first 32 places are of character type).

It worked with all these types. But it doesn't work with types like this one:

types: begin of ty_line,

  c type c,

  f type f,

end of ty_line.

The second option, "INSERT ... INTO TABLE ...", is much more restrictive. When working with "INSERT <fs_err_tab> into table lt_string.", you will get an error unless the type of <fs_err_tab> is a precise match of the line type of lt_string.

INSERT ... INTO TABLE is the better option for a robust programmer, since it protects your program against the unexpected. In order to use it, you will need an auxiliary variable (not field-symbol) of type char32 and have to fill it yourself in the loop. You can't avoid the MOVE anyway, APPEND would perform it implicitly. So don't worry.

Regards,

Rüdiger

Remark: In your code, I see the obsolete statement "field-symbols with no explicit type"

FIELD-SYMBOLS <FS_ERR_TAB>.

gives the field-symbol the generic type ANY - contrary to all other declarations in ABAP which default to CHAR1. To make it even weirder: In this case, the field-symbol will by default be assigned to the constant SPACE, even if no ASSIGN statement has been performed.

0 Kudos
3,368

Hi Rüdiger,

Unfortunately the statement APPEND <FS_ERR_TAB> TO LT_STRING returns the following error as a short dump:

You attempted to move one data object to another.

This is not possible here because the conversion of a data object

of type "ZRSP_PROPOSAL" to type "C" is not supported.

Basically ZRSP_PROPOSAL is our <FS_ERR_TAB>.

Your thoughts ?

Stefan

0 Kudos
3,368

My thoughts?

  • Please analyse the first 32 places of ZRSP_PROPOSAL. Do they contain non-character components?
  • Append internally makes a move. Try to move a normal variable of type ZRSP_PROPOSAL to a variable of type CHAR32, like this: "data: ls_prop type zrsp_proposal, lv_char32 type char32. move ls_prop to lv_char32." Is this possible?

Regards,

Rüdiger

0 Kudos
3,368

Hi Rüdiger,

I have tried your last suggestion, but it doesn't work.

The compilier returns: The type of lv_prop cannot be converted to the type of lv_char32.

Please advise !

Regards,

Stefan

0 Kudos
3,368

What type of field is lv_prop? It appears to be a type that cant be converted to characters. Since lv_char32 is a character type field, there needs to be logic to convert lv_prop to characters. First thing I would try is the WRITE lv_prop INTO lv_char32 statement. It converts lv_prop to characters in external format.

0 Kudos
3,368

Stefan,

so the simple "MOVE" test shows, your problem has nothing to do with field-symbols at all. It's about moving something into type c which can't be moved to type c.

Until now, you make a secret of the root cause of your problem: The type of zrsp_proposal. I have explained you in detail the conditions, when it is possible to move something to a type c field - and when not.

Now it's up to you to apply these conditions to your problem. We can't help you further, unless you are willing to unveil the components of zrsp_proposal.

Regards,

Rüdiger

raymond_giuseppi
Active Contributor
0 Kudos
3,368

In Unicode you must append a char 32 type field to your internal table. So the problem is assigning the value of your <fs> TYPE ANY.to a character 32 field then appending this field to internal table.

Look for the option CASTING of the ASSIGN statement, to find the solution.

Regards,

Raymond

yang_aiolos
Active Participant
0 Kudos
3,369

please use below code you will get what you want.

FIELD-SYMBOLS <fs_line> type any.

data ls_tab type ref to data.

data it_tab type standard TABLE OF char32 with header line.

create data ls_tab like line of it_tab.

ASSIGN ls_tab->* to <fs_line>.

<fs_line> = 'fs'.

append <fs_line> to it_tab.

loop at it_tab.

  write it_tab.

endloop.

i also want to tell u something.

1. you should create line type of your internal table.

create data ls_tab like line of it_tab.

2.assign it to 1 field symbol. then you can operate this work area.

ASSIGN ls_tab->* to <fs_line>.

0 Kudos
3,368

This proposal will only shift the problem to the MOVE statement: The line

<fs_line> = 'fs'. 

will very likely result in the same error he got all the time.

He doesn't have a field-symbol problem, he has a move problem. Not everything can be moved into a type C field.

My guess: The leading part of his source  structure contains a counter field of type integer (since it's the data structure of an error log).

0 Kudos
3,368

Guys,

Everytime the structure/table will be different. Let me clarify the scenario.

I have screen showing the errors of DB tables update. On that screen I have a hotspot against evry single table. When the user clicks on that hotspot the system opens an additional screen where I have custom control ( text edit box ) where I have to display the records which hasn't been inserted because of some problems. That's why the table passed to the PBO of the second screen could be different every time. I am able to pass dynamically the table name and it's contents, but I am not able to pass it to the import parameter of the function module:

 

CALL METHOD

text_editor->

set_textstream

that should display so called 'wrong table records'.

And that's my code ( again )

 

ASSIGN <fs_stepid> TO <t_itab>.

* <t_itab> is declared as TYPE ANY TABLE

* <fs_stepid> is declared in the Global definitions as TYPE STANDARD TABLE. It passes the table contents from the first screen to the second screen.

So I have the following code:

LOOP AT <t_itab> ASSINING <fs_err_tab>." <fs_err_tab> is of type any

APPEND <fs_err_tab> TO lt_text_stream. "lt_text_stream TYPE STANDARD TABLE OF char32.

CONCATENATE LINES OF lt_text_stream INTO lv_string.

CALL METHOD text_edit->set_textstream

     EXPORTING

          text = lv_string.

ENDLOOP.

0 Kudos
3,368

Hi

before appending the record you need to move it to string

LOOP AT <t_itab> ASSINING <fs_err_tab>." <fs_err_tab>.

    DO.

       CLEAR: X, Y, W, L_CHAR32.

       ASSIGN COMPONENT SY-INDEX OF STRUCTURE <FS_ERR_TAB> TO <FS_ERR_FIELD>.

       IF SY-SUBRC <> 0. EXIT. ENDIF.

       DESCRIBE FIELD <FS_ERR_FIRLD> LENGTH Y IN CHARACTER MODE

      W = X + Y.

      IF W > 32. EXIT. ENDIF,

      MOVE <FS_ERR_FIELD> TO L_CHAR32+X(Y).

       X   = X + Y.

       W = X.

    ENDDO.

    APPEND L_CHAR32 TO IT_TEXTSTREAM.

ENDLOOP.

Max

0 Kudos
3,368

Thanks Max,

That is going to work

Cheers,

Stefan

0 Kudos
2,807

Above solution did not work for me since I just need to move from field symbol to deep structure.

Specify the type with the corresponding:

  FIELD-SYMBOLS <lfs_any> TYPE any & IM_DATA_CONTAINER TYPE REF TO DATA

    ASSIGN im_data_container->TO <lfs_any>.
    IF <lfs_any> IS ASSIGNED.
   ex_form_data CORRESPONDING YLC_SD_ORDER_CONFIRMATIONDEEP EXACT <lfs_any> ).