<?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: ABAP OOP constant declaration best practice in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375389#M8759</link>
    <description>&lt;P&gt;If a bit of extra effort is made to make the code readable, I don't mind if a developer has to do a lot of redeclaration. &lt;/P&gt;&lt;P&gt;btw - I'd alias as c_sun, c_moon. Here using prefixes to indicate usage, not type.&lt;/P&gt;</description>
    <pubDate>Wed, 01 Mar 2017 08:11:57 GMT</pubDate>
    <dc:creator>matt</dc:creator>
    <dc:date>2017-03-01T08:11:57Z</dc:date>
    <item>
      <title>ABAP OOP constant declaration best practice</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375367#M8737</link>
      <description>&lt;P&gt;We have about a dozen function groups and 30-40 function modules which all need to commonly reference upwards of 100 constants.&lt;/P&gt;&lt;P&gt;We currently do this:&lt;/P&gt;&lt;P&gt;include /namespace/constants&lt;/P&gt;&lt;P&gt;But, the extended code check tells me it is bad practice to have an include used in more than one function group.&lt;/P&gt;&lt;P&gt;We're not going to rewrite all of our code to sit in a single function group, like it proposes.&lt;/P&gt;&lt;P&gt;As we move to object oriented development, we face the same question.&lt;/P&gt;&lt;P&gt;Is it best to put all of the constants into a single class and then reference it in our code like this:&lt;/P&gt;&lt;P&gt;if ls_knvp-parvw = /namespace/cl_constant=&amp;gt;gc_soldto_function&lt;/P&gt;&lt;P&gt;That feels cumbersome, but manageable. Maybe we can alias it or something?&lt;/P&gt;&lt;P&gt;I'd like to use a type group, but we can't put it in a namespace and the usage seems to be deprecated?&lt;/P&gt;&lt;P&gt;Basically, I want something easy to use that can be referenced from multiple classes or function groups. Shorter naming is preferable. Passing the extended syntax check is very important.&lt;/P&gt;&lt;P&gt;Thanks for your suggestions!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 13:39:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375367#M8737</guid>
      <dc:creator>ray_mannion</dc:creator>
      <dc:date>2017-02-24T13:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OOP constant declaration best practice</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375368#M8738</link>
      <description>&lt;P&gt;Having all your constants in one place, no matter whether you're writing something for Finance or for HR, is not good practice. The idea should be to be as specific as possible. Personally, I don't see anything wrong with having e.g.&lt;/P&gt;&lt;P&gt;CONSTANTS c_end_of_time TYPE d VALUE '99991231'&lt;/P&gt;&lt;P&gt;defined multiple times. If I didn't do it in a class, then I'd do it in an interface - but one constants interface per application. Having your constants defined in one or a few different places, used by many applications, to my mind is close to defining a global variable v_count for all your integer needs. I.e. not a good idea. &lt;/P&gt;&lt;P&gt;Group your constants into related groups, define them in interfaces, then use aliases in the class definitions. &lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 15:37:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375368#M8738</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2017-02-24T15:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OOP constant declaration best practice</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375369#M8739</link>
      <description>&lt;P&gt;You can create instance of your "constant class". And it will shorten code for usage &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA: lo_cs1 TYPE REF TO /namespace/cl_long_class_name.
CREATE OBJECT lo_cs1.

IF l_variable = lo_cs1=&amp;gt;c_constant.
  "TRUE
ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Feb 2017 15:42:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375369#M8739</guid>
      <dc:creator>Tomas_Buryanek</dc:creator>
      <dc:date>2017-02-24T15:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OOP constant declaration best practice</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375370#M8740</link>
      <description>&lt;P&gt;The ABAP programming guidelines say: put'em to a class or interface. And hey, since 7.51 we have enumerations ...&lt;/P&gt;&lt;P&gt;&lt;A href="https://help.sap.com/http.svc/rc/abapdocu_751_index_htm/7.51/en-US/index.htm?file=abendeclaration_dtypes_const_guidl.htm" target="test_blank"&gt;https://help.sap.com/http.svc/rc/abapdocu_751_index_htm/7.51/en-US/index.htm?file=abendeclaration_dtypes_const_guidl.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 17:45:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375370#M8740</guid>
      <dc:creator>retired_member</dc:creator>
      <dc:date>2017-02-24T17:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OOP constant declaration best practice</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375371#M8741</link>
      <description>&lt;P&gt;Thank you - that is a good, simple suggestion&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2017 12:59:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375371#M8741</guid>
      <dc:creator>ray_mannion</dc:creator>
      <dc:date>2017-02-27T12:59:04Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OOP constant declaration best practice</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375372#M8742</link>
      <description>&lt;P&gt;oooo - enumerations. Lovely. &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2017 15:50:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375372#M8742</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2017-02-27T15:50:35Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OOP constant declaration best practice</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375373#M8743</link>
      <description>&lt;P&gt;I dislike it. An instantiation without reason. What if the constructor is resource intensive? You're relying on the developer checking/knowing. No - I don't think it is a good idea. It could be used to make the code more readable, but at the expense of meaning.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2017 15:52:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375373#M8743</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2017-02-27T15:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OOP constant declaration best practice</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375374#M8744</link>
      <description>&lt;P&gt;I like your blog better &lt;A href="https://blogs.sap.com/2016/10/10/abap-news-release-7.51-enumerations/" target="test_blank"&gt;https://blogs.sap.com/2016/10/10/abap-news-release-7.51-enumerations/&lt;/A&gt; I guess I didn't dig hard enough on the help site &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2017 19:42:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375374#M8744</guid>
      <dc:creator>raghug</dc:creator>
      <dc:date>2017-02-27T19:42:25Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OOP constant declaration best practice</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375375#M8745</link>
      <description>&lt;P&gt;I do agree with your statement that having all the constants in one place is a bad idea. But, I don't like the idea of having an interface per application, declaring constants for just that application. At that point you are just moving the program constants to a class (or interface) for no real gain and just another element to deal with.&lt;/P&gt;&lt;P&gt;Reading &lt;A rel="user" href="https://answers.sap.com/users/3970/horstkeller.html" nodeid="3970"&gt;Horst Keller&lt;/A&gt;'s blog about enumeration, in that example, the shirt sizes are something that I would like declared in one place for the entire project / dev class / package. First that would be the definition of code reuse. Second, think about refactoring, in his example if a size XS is added, it has to be done in one place only instead of trying to find every place it was declared. Third, if the XS wasn't supposed to be there, you don't want another developer accidentally adding it to just one application.&lt;/P&gt;&lt;P&gt;Personally I like keeping reusable ones in a properly marked globally accessible place for the dev class (as a class or interface) and application specific ones within the program. If my program is primarily class based, then it is an attribute - and if I don't anticipate any one else using it for the same purpose, I bury it in the Private section, so that any future refactoring won't impact inadvertent use in another program.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2017 19:59:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375375#M8745</guid>
      <dc:creator>raghug</dc:creator>
      <dc:date>2017-02-27T19:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OOP constant declaration best practice</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375376#M8746</link>
      <description>&lt;P&gt;How about an interface? You aren't dealing with a constructor then.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA: lo_cs1 TYPE REF TO /namespace/if_long_interface_name.
CREATE OBJECT lo_cs1.

... lo_cs1=&amp;gt;constant.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Feb 2017 20:03:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375376#M8746</guid>
      <dc:creator>raghug</dc:creator>
      <dc:date>2017-02-27T20:03:40Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OOP constant declaration best practice</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375377#M8747</link>
      <description>&lt;P&gt;You can't instantiate an interface.  You won't get past the syntax check.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 06:18:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375377#M8747</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2017-02-28T06:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OOP constant declaration best practice</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375378#M8748</link>
      <description>&lt;P&gt;I was using the word application deliberately to mean "connected group of programs". If that's your entire project than fine. The point that if you have a program for shirts, and another for coal mining, they shouldn't share the constants interface. Depending on your package regime, it might make sense to have one interface per package. Or it might not. It all depends on the granularity. I'd hate to see a constants interface for, e.g. FI applications. &lt;/P&gt;&lt;P&gt;At some point "reusable" becomes "global" and global is &lt;EM&gt;&lt;STRONG&gt;bad!&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Burying single use constants in private is what I do also. However, if the class is like an API, and will be used by many other classes, then obviously there will be public constants. And if the class has many subclasses, there will be protected ones as well. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 06:23:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375378#M8748</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2017-02-28T06:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OOP constant declaration best practice</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375379#M8749</link>
      <description>&lt;P&gt;It was intended only for "constant class". But nevertheless I agree. It can be confusing or problem making&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 06:37:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375379#M8749</guid>
      <dc:creator>Tomas_Buryanek</dc:creator>
      <dc:date>2017-02-28T06:37:31Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OOP constant declaration best practice</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375380#M8750</link>
      <description>&lt;P&gt;It must be&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;... lo_cs1-&amp;gt;c_constant ...&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; n'est-ce pas ?&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 28 Feb 2017 06:49:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375380#M8750</guid>
      <dc:creator>retired_member</dc:creator>
      <dc:date>2017-02-28T06:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OOP constant declaration best practice</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375381#M8751</link>
      <description>&lt;P&gt;C'est. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 07:20:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375381#M8751</guid>
      <dc:creator>Tomas_Buryanek</dc:creator>
      <dc:date>2017-02-28T07:20:50Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OOP constant declaration best practice</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375382#M8752</link>
      <description>&lt;P&gt;Hello Ray,&lt;/P&gt;&lt;P&gt;as a constant is constant, so you are free to define both a global constant à la &lt;STRONG&gt;/namespace/cl_constant=&amp;gt;gc_soldto_function &lt;/STRONG&gt;and a local scope redefinition: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;CONSTANTS c_soldto_function TYPE ... VALUE /namespace/cl_constant=&amp;gt;gc_soldto_function.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;JNN&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 13:05:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375382#M8752</guid>
      <dc:creator>nomssi</dc:creator>
      <dc:date>2017-02-28T13:05:21Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OOP constant declaration best practice</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375383#M8753</link>
      <description>&lt;P&gt;Sorry, my mistake... what caught me off guard was it did pass syntax check without the instantiation - but that doesn't work either!&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 14:52:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375383#M8753</guid>
      <dc:creator>raghug</dc:creator>
      <dc:date>2017-02-28T14:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OOP constant declaration best practice</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375384#M8754</link>
      <description>&lt;P&gt;Thanks for the clarification of "application" - you seem to follow the dictionary meaning &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; In that case, we are both on the same page.&lt;/P&gt;&lt;P&gt;And really bad, while we are commenting on it - is carrying around an include with every alphabet declared c_a = 'A', c_b = 'B', etc.... I have been in situations where I was forced to toe that line just so that I don't use...&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;IF my_var = 'X'.&lt;BR /&gt;  OR &lt;BR /&gt;IF my_var = c_sun_is_shining. &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;they want me to use &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;IF my_var = c_x.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Feb 2017 14:59:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375384#M8754</guid>
      <dc:creator>raghug</dc:creator>
      <dc:date>2017-02-28T14:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OOP constant declaration best practice</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375385#M8755</link>
      <description>&lt;P&gt;You've seen the same code as I have.  I always say a constant should describe it's meaning and not it's content.  And anyway - what's wrong with Abap_True ? &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Rich &lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 15:20:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375385#M8755</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2017-02-28T15:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP OOP constant declaration best practice</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375386#M8756</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;a constant should describe it's meaning and not it's content.&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you, I hope you don't mind me stealing this phrase!&lt;/P&gt;&lt;P&gt;I tend to forgive not using ABAP_TRUE because in past versions of ABAP, it was available only if you explicitly declared the type-pool. I guess that is not an excuse any more!&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 15:58:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-oop-constant-declaration-best-practice/m-p/375386#M8756</guid>
      <dc:creator>raghug</dc:creator>
      <dc:date>2017-02-28T15:58:17Z</dc:date>
    </item>
  </channel>
</rss>

