Skip to Content

Assigning Type of structure dynamically

parameters: struct_1(30) type c.

In my program I have to assign the name of the structure that I recieve as a parameter as the TYPE of another structure as below:

data: struct_2 type struct_1.

The above statement is actually assigning the TYPE 'C' to struct_2 instead of the name of the structure that I receive via struct_1 parameter.

So, my question is how to assign the name of structure that I receive via struct_1 parameter as the type of the struct_2 instead the "Type" of struct_1 parameter which happens to be C (character)

Thanks for your help.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Aug 11, 2008 at 12:27 AM

    You need to do something like this. You will create the structure dynamically at runtime, and access this via a field symbol, <struct2> will have the structure of the structure of the value of STRUCT1.

    data: oref type ref to data.
    FIELD-SYMBOLS: <struct2> type any.
    
    PARAMETERS: struct1 type char30 default 'T000'.
    
    create data oref type (struct1).
    assign oref->* to <struct2>.
    
    check sy-subrc <> 0.

    Regards,

    Rich Heilman

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.