<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Defining complex types in ABAP in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/defining-complex-types-in-abap/m-p/7738648#M1581602</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I think you should use the dynamic data reference .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
TYPES BEGIN OF mytype1.
    TYPES: 
          .......
          .......
    TYPES END OF mytype1.
 
TYPES BEGIN OF mytype2.
    TYPES: 
          .......
          .......
    TYPES END OF mytype2.

data: dref_complex type ref to data.
field-sumbols:&amp;lt;fs_any&amp;gt; type any.

if type eq mytype1.
l_type = 'MY_TYPE1'.
elseif type eq mytype2.
l_type = 'MY_TYPE2'.
endif.

create data dref_complex type (l_type).

"In order to access the components of  dref_complex , you should assign the same to field symbol
assing dref-&amp;gt;*  to &amp;lt;fs_any&amp;gt;.

"then u can use  ASSIGN COMPONENT to get individual components

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Arshad&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 07 Apr 2011 08:12:22 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2011-04-07T08:12:22Z</dc:date>
    <item>
      <title>Defining complex types in ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/defining-complex-types-in-abap/m-p/7738644#M1581598</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Folks, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am new to the ABAP world and has started programming in it for about two weeks now (therefore, two weeks of experience so far &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt; ). I have a question regarding definition of complex types in ABAP. Basically what I want to achieve is to define a type which is either mytype1 or mytype2. During the runtime, it should be decided whether complextype is of mytype1 or of mytype2. Maybe to put some more concrete context: I will call a method with an object of type "complextype". Depending how I set this object, this will be of mytype1 or mytype2. Please see the code schema below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; 

TYPES BEGIN OF mytype1.
    TYPES: 
          .......
          .......
    TYPES END OF mytype1.

TYPES BEGIN OF mytype2.
    TYPES: 
          .......
          .......
    TYPES END OF mytype2.

TYPES BEGIN OF complextype.
    TYPES: 
          mytype_name TYPE mytype1,
          mytype_name TYPE mytype2.

    TYPES END OF complextype.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is this a correct way to approach? If yes, how can I express this (either mytype1 or mytype2 but only one of them at a certain time) in ABAP types correctly?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will appreciate any kind of help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a million,&lt;/P&gt;&lt;P&gt;Boldbaatar&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Boldbaatar Tsend-Ayush on Apr 6, 2011 8:24 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Apr 2011 18:17:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/defining-complex-types-in-abap/m-p/7738644#M1581598</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-04-06T18:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: Defining complex types in ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/defining-complex-types-in-abap/m-p/7738645#M1581599</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As for the complex &lt;STRONG&gt;dynamic&lt;/STRONG&gt; types (available at runtime) you will have to define such type also dynamically. For this you can refer my blog [Do you really know everything about typing? - part 2|http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/20887] &lt;B&gt;[original link is broken]&lt;/B&gt; &lt;B&gt;[original link is broken]&lt;/B&gt; &lt;B&gt;[original link is broken]&lt;/B&gt;;. Here you get the explanation how to define such types during runtime. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The second issue I can see here is&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;During the runtime, it should be decided whether complextype is of mytype1 or of mytype2 (...) I will call a method with an object of type "complextype".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You can only work with dynamic structures and/or define them, but you can't actually type the parameter of dynamic structure. Even you tell the system that you want to use &lt;EM&gt;complex&lt;/EM&gt; type as parameter type, system will statically (during syntax check) check whether it actual parameter passed to it really comply this type (can't be either mytype1 or mytyp2). So there is no way to do that. An alternative, and the only way I can think of, is &lt;STRONG&gt;generic&lt;/STRONG&gt; or &lt;STRONG&gt;semi generic&lt;/STRONG&gt; parameter typing. For details refer next blog from the series [Do you really know everything about typing? - part 4|http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/21128] &lt;B&gt;[original link is broken]&lt;/B&gt; &lt;B&gt;[original link is broken]&lt;/B&gt; &lt;B&gt;[original link is broken]&lt;/B&gt;;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you still have questions in this regard, don't hesitate to ask.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Marcin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Apr 2011 19:15:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/defining-complex-types-in-abap/m-p/7738645#M1581599</guid>
      <dc:creator>MarcinPciak</dc:creator>
      <dc:date>2011-04-06T19:15:33Z</dc:date>
    </item>
    <item>
      <title>Re: Defining complex types in ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/defining-complex-types-in-abap/m-p/7738646#M1581600</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Marcin, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks for the prompt response. I will read your blog and may come up with new questions. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Boldbaatar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Apr 2011 19:23:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/defining-complex-types-in-abap/m-p/7738646#M1581600</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-04-06T19:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: Defining complex types in ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/defining-complex-types-in-abap/m-p/7738647#M1581601</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you explain in some more details what do you want to achieve with your design?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Maybe defining two optional parameters and checking them with&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;IS SUPPLIED&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;would be enough for your method.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I could also think about defining a class with two subclasses and passing reference to the parent but it all depends on your particular requirements.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Apr 2011 06:53:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/defining-complex-types-in-abap/m-p/7738647#M1581601</guid>
      <dc:creator>former_member182670</dc:creator>
      <dc:date>2011-04-07T06:53:53Z</dc:date>
    </item>
    <item>
      <title>Re: Defining complex types in ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/defining-complex-types-in-abap/m-p/7738648#M1581602</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I think you should use the dynamic data reference .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
TYPES BEGIN OF mytype1.
    TYPES: 
          .......
          .......
    TYPES END OF mytype1.
 
TYPES BEGIN OF mytype2.
    TYPES: 
          .......
          .......
    TYPES END OF mytype2.

data: dref_complex type ref to data.
field-sumbols:&amp;lt;fs_any&amp;gt; type any.

if type eq mytype1.
l_type = 'MY_TYPE1'.
elseif type eq mytype2.
l_type = 'MY_TYPE2'.
endif.

create data dref_complex type (l_type).

"In order to access the components of  dref_complex , you should assign the same to field symbol
assing dref-&amp;gt;*  to &amp;lt;fs_any&amp;gt;.

"then u can use  ASSIGN COMPONENT to get individual components

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Arshad&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Apr 2011 08:12:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/defining-complex-types-in-abap/m-p/7738648#M1581602</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-04-07T08:12:22Z</dc:date>
    </item>
    <item>
      <title>Re: Defining complex types in ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/defining-complex-types-in-abap/m-p/7738649#M1581603</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Arshad,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your code will give a runtime error! &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN __default_attr="red" __jive_macro_name="color"&gt;&lt;STRONG&gt;One cannot create dynamic data objects using local types.&lt;/STRONG&gt;&lt;/SPAN&gt; (I mean the way you've mentioned in your code snippet). Read the documentation on CREATE DATA &amp;amp; get your basics clear.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BR,&lt;/P&gt;&lt;P&gt;Suhas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Apr 2011 08:33:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/defining-complex-types-in-abap/m-p/7738649#M1581603</guid>
      <dc:creator>SuhaSaha</dc:creator>
      <dc:date>2011-04-07T08:33:51Z</dc:date>
    </item>
    <item>
      <title>Re: Defining complex types in ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/defining-complex-types-in-abap/m-p/7738650#M1581604</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; Arshad,&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; Your code will give a runtime error! &lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; &lt;SPAN __default_attr="red" __jive_macro_name="color"&gt;&lt;STRONG&gt;One cannot create dynamic data objects using local types.&lt;/STRONG&gt;&lt;/SPAN&gt; (I mean the way you've mentioned in your code snippet). Read the documentation on CREATE DATA &amp;amp; get your basics clear.&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; BR,&lt;/P&gt;&lt;P&gt;&amp;gt; Suhas&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hi Suhas,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I must disagree. Typing of data references is the same as you would be typing local data objects, only data representation differs (in first case it is data object of some type, in the second it is a reference to such data object of some type). So you are able to type it both with DDIC and local types. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Marcin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Apr 2011 09:33:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/defining-complex-types-in-abap/m-p/7738650#M1581604</guid>
      <dc:creator>MarcinPciak</dc:creator>
      <dc:date>2011-04-07T09:33:57Z</dc:date>
    </item>
    <item>
      <title>Re: Defining complex types in ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/defining-complex-types-in-abap/m-p/7738651#M1581605</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Marcin &amp;amp; Arshad,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt; ... type can be any data type from the ABAP Dictionary - especially the structure of a database table, a public data type of a global class, or any data type of the same program that has already been defined with TYPES ... &lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My Bad !!! &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Suhas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Apr 2011 09:53:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/defining-complex-types-in-abap/m-p/7738651#M1581605</guid>
      <dc:creator>SuhaSaha</dc:creator>
      <dc:date>2011-04-07T09:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: Defining complex types in ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/defining-complex-types-in-abap/m-p/7738652#M1581606</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks for the response. At the moment, your solution is doing the job for me. I just pass the objects of different types together when I call the method. Depending on which type to be used, I just look whether it is supplied or not. For my situation of having only two different types, I find your solution good and simple. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Boldbaatar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Apr 2011 17:53:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/defining-complex-types-in-abap/m-p/7738652#M1581606</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-04-11T17:53:49Z</dc:date>
    </item>
  </channel>
</rss>

