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: 
Read only

How to access data from datatype TYPE REF TO DATA?

former_member557553
Participant
26,545

Hello community,

I have a more general question.

In a method I get a parameter that is of type 'TYPE REF TO DATA'.

In this object, there is a list of fieldnames and its values (name-value-pair).

When I debug I see the name and the values.

I implemented following to access the data:

" Define local structure
  TYPES:
    BEGIN OF S_VALUE_PAIR,
      NAME TYPE ANY,
      VALUE TYPE ANY,
    END OF S_VALUE_PAIR.
  
  " Define local table type  
  TYPES T_VALUE_PAIR TYPE S_VALUE_PAIR.
  
    
  FIELD-SYMBOLS <fs_value_pair> TYPE T_VALUE_PAIR.
  
  " (!!) Type conflict  
  ASSIGN IS_DATA TO <fs_value_pair>.

The problem is, that the structure if the data in the parameter is unknown or dynamically created.

So how can I access the data in this case?

Thank you and BR, Christian

1 ACCEPTED SOLUTION
Read only

Former Member
8,213

Try this:

FIELD-SYMBOLS: <FW>.

ASSIGN IS_DATA->* TO <dyn_wa>.

Hello community,

I have a more general question.

In a method I get a parameter that is of type 'TYPE REF TO DATA'.

In this object, there is a list of fieldnames and its values (name-value-pair).

When I debug I see the name and the values.

I implemented following to access the data:

" Define local structure
  TYPES:
    BEGIN OF S_VALUE_PAIR,
      NAME TYPE ANY,
      VALUE TYPE ANY,
    END OF S_VALUE_PAIR.
  
  " Define local table type  
  TYPES T_VALUE_PAIR TYPE S_VALUE_PAIR.
  
    
  FIELD-SYMBOLS <fs_value_pair> TYPE T_VALUE_PAIR.
  
  " (!!) Type conflict  
  ASSIGN IS_DATA TO <fs_value_pair>.

The problem is, that the structure if the data in the parameter is unknown or dynamically created.

So how can I access the data in this case?

Thank you and BR, Christian

6 REPLIES 6
Read only

antony_paul2
Active Participant
0 Likes
8,213

Can you try this statement.

ASSIGN is_data->* TO <fs_value_pair>.

Read only

0 Likes
8,213

Hallo Antony,

thank you for your reply. I have tried it but brings me the same error.

"Type conflict with ASSIGN in program ZCL_HRESS_PER_DETAIL_ADDR_AT==CP "

BR, Christian

Read only

Former Member
8,214

Try this:

FIELD-SYMBOLS: <FW>.

ASSIGN IS_DATA->* TO <dyn_wa>.

Read only

0 Likes
8,213

Hello David,

how do you mean this? Something like this:

" Define local structure
  TYPES:
    BEGIN OF S_VALUE_PAIR,
      NAME TYPE string,
      VALUE TYPE string,
    END OF S_VALUE_PAIR.

  " Define local table type
  TYPES T_VALUE_PAIR TYPE S_VALUE_PAIR.

  " Here I didn't define a TYPE --> but in OO Context, this is not allowed
  FIELD-SYMBOLS <fs_value_pair>. "TYPE T_VALUE_PAIR.

  " (!!) Type conflict
  ASSIGN IS_DATA->* TO <fs_value_pair>.

Brings me the debugger-msg: "Untypisierte Feldsymbole werden im OO- Kontext nicht unterstützt." --> fieldsymbols with no type are not allowed in OO-Context

BR, Christian

Read only

0 Likes
8,213

Hi,

Just declare as

FIELD-SYMBOLS <fs_value_pair> type any

or as

FIELD-SYMBOLS <fs_value_pair> type table

Read only

0 Likes
8,213

hi,

I had a short call with Christian, now here's a working solution:


FIELD-SYMBOLS <ls_data> TYPE DATA.
FIELD-SYMBOLS <lv_field> TYPE fieldtype.

ASSIGN is_data->* to <ls_data>. "dereference into field symbol
ASSIGN COMPONENT 'FIELDNAME' OF STRUCTURE <ls_data> TO <lv_field>.

"error handling might be useful if component FIELDNAME is not available

BTW, this was in an FPM form feeder class. Hope this helps.

Regards

Ole