<?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: Call Method from a ABAP Program in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400000#M10178</link>
    <description>&lt;P&gt;If you are going to reuse those methods, all you have to do is move it into its own "real" class - that way both the original program and any other program can access the code the way they are supposed to.&lt;/P&gt;&lt;P&gt;A short cut to make this simple (if you have the correct version of ABAP backend) is that in the Source-Code Based mode in SE24, you should be able to just cut and paste the entire class in there and just change the name of the class in the source code.&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/6681-2016-11-16-08-16-27.jpg" /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 16 Nov 2016 13:18:21 GMT</pubDate>
    <dc:creator>raghug</dc:creator>
    <dc:date>2016-11-16T13:18:21Z</dc:date>
    <item>
      <title>Call Method from a ABAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/399998#M10176</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I wrote two programs. &lt;/P&gt;&lt;P&gt;Program 1&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT ztm_prog1.
TABLES: scarr.


SELECTION-SCREEN BEGIN OF BLOCK 001 WITH FRAME TITLE text-001.
SELECT-OPTIONS: carrid FOR scarr-carrid.
SELECTION-SCREEN END OF BLOCK 001.

CLASS program DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
    CLASS-METHODS initialization.
  PRIVATE SECTION.


ENDCLASS.
CLASS program IMPLEMENTATION.
  METHOD main.


  ENDMETHOD.
  METHOD initialization.
    CLEAR: carrid.
    carrid = VALUE #( low = 'LH' option = 'EQ' sign = 'I' ) .
    APPEND carrid TO carrid.
  ENDMETHOD.
ENDCLASS.


INITIALIZATION.
  program=&amp;gt;initialization( ).


START-OF-SELECTION.
  program=&amp;gt;main( ).

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Program 2&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT ztm_prog2.


**** Call the method from Program 1
(ztm_prog1)program=&amp;gt;main( ). "How is the syntax ????&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How can i call the static method main from program ztm_prog1?&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 12:45:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/399998#M10176</guid>
      <dc:creator>thomas_markert_hf</dc:creator>
      <dc:date>2016-11-16T12:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: Call Method from a ABAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/399999#M10177</link>
      <description>&lt;P&gt;You shouldn't do that but you can by using &lt;A href="http://help.sap.com/abapdocu_751/en/index.htm?file=abentype_names.htm"&gt;absolute type names&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 13:09:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/399999#M10177</guid>
      <dc:creator>retired_member</dc:creator>
      <dc:date>2016-11-16T13:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: Call Method from a ABAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400000#M10178</link>
      <description>&lt;P&gt;If you are going to reuse those methods, all you have to do is move it into its own "real" class - that way both the original program and any other program can access the code the way they are supposed to.&lt;/P&gt;&lt;P&gt;A short cut to make this simple (if you have the correct version of ABAP backend) is that in the Source-Code Based mode in SE24, you should be able to just cut and paste the entire class in there and just change the name of the class in the source code.&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/6681-2016-11-16-08-16-27.jpg" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 13:18:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400000#M10178</guid>
      <dc:creator>raghug</dc:creator>
      <dc:date>2016-11-16T13:18:21Z</dc:date>
    </item>
    <item>
      <title>Re: Call Method from a ABAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400001#M10179</link>
      <description>&lt;P&gt;I agree. It was annoying when people called subroutines this way, but with the methods there should be no reason to do that, especially with two Z programs. It's just bad design. &lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 22:12:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400001#M10179</guid>
      <dc:creator>Jelena_Perfiljeva</dc:creator>
      <dc:date>2016-11-16T22:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: Call Method from a ABAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400002#M10180</link>
      <description>&lt;P&gt;You shouldn't code like that (as already told by the 3 other people)&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 04:59:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400002#M10180</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2016-11-17T04:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: Call Method from a ABAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400003#M10181</link>
      <description>&lt;P&gt;Just thinking about this again from a pointy-haired-boss (Dilbert reference for those who don't know) point of view. They feel threatened by any changes to existing code. So, I can kind of see where the boss will not allow changes to ZTM_PROG1 above. If you follow the boss man and move a copy to the common location, you have two sets of code. I have two suggestions for this...&lt;/P&gt;&lt;P&gt;1) Add a comment in big bold letters to ZTM_PROG1 (I am sure the boss man will allow comments, right?) that if any changes need to be made to the methods, start by pointing to the common code in the Z_MY_CLASS_TM. That will be a good excuse for deprecating the non-common routines when changes are required.&lt;/P&gt;&lt;P&gt;Don't make any actual code changes to keep the boss man happy.  For ZTM_PROG2, point it to a common class Z_MY_CLASS_TM and do it the right way. This way when ZTM_PROG3 comes along, you have good common code for that too.&lt;/P&gt;&lt;P&gt;2) Simpler solution - but harder to execute - fire the pointy-haired-boss &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 13:18:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400003#M10181</guid>
      <dc:creator>raghug</dc:creator>
      <dc:date>2016-11-17T13:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: Call Method from a ABAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400004#M10182</link>
      <description>&lt;P&gt;Just to add to what Raghu has already mentioned.&lt;/P&gt;&lt;P&gt;From SE24, you can easily import the local classes to global classes using:&lt;/P&gt;&lt;P&gt;Menu &amp;gt; Object Type &amp;gt; Import &amp;gt; Local classes in Program&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/6930-class-builder-initial-screen.jpg" /&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/6951-import-from-program.jpg" /&gt;&lt;/P&gt;&lt;P&gt;BR,&lt;/P&gt;&lt;P&gt;Suhas&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 15:01:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400004#M10182</guid>
      <dc:creator>SuhaSaha</dc:creator>
      <dc:date>2016-11-17T15:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: Call Method from a ABAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400005#M10183</link>
      <description>&lt;P&gt;Even better! I couldn't find an equivalent in the ADT environment though.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 15:16:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400005#M10183</guid>
      <dc:creator>raghug</dc:creator>
      <dc:date>2016-11-17T15:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: Call Method from a ABAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400006#M10184</link>
      <description>&lt;P&gt;I don't think one would need such an import function in ADT, where everything is source code based.&lt;/P&gt;&lt;P&gt;Just a simple copy-paste would suffice!&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 15:21:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400006#M10184</guid>
      <dc:creator>SuhaSaha</dc:creator>
      <dc:date>2016-11-17T15:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: Call Method from a ABAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400007#M10185</link>
      <description>&lt;P&gt;As others suggested in this thread, it is not recommended to code this way.&lt;/P&gt;&lt;P&gt;But if you do not have any workaround( in cases like fixing other's code and cannot create a separate class etc), in ZTM_PROG1 have the PROGRAM=&amp;gt;MAIN() in a subroutine for e.g. PERFORM call_method and call this subroutine from ZTM_PROG2.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 16:59:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400007#M10185</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2016-11-17T16:59:16Z</dc:date>
    </item>
    <item>
      <title>Re: Call Method from a ABAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400008#M10186</link>
      <description>&lt;P&gt;Raghu, OP starts with "I wrote two programs". So there should be no pointy-haired boss telling OP how to do their job.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 21:24:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400008#M10186</guid>
      <dc:creator>Jelena_Perfiljeva</dc:creator>
      <dc:date>2016-11-17T21:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: Call Method from a ABAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400009#M10187</link>
      <description>&lt;P&gt;It's kind of not recommended to code this way either...&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2016 21:33:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400009#M10187</guid>
      <dc:creator>Jelena_Perfiljeva</dc:creator>
      <dc:date>2016-11-17T21:33:48Z</dc:date>
    </item>
    <item>
      <title>Re: Call Method from a ABAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400010#M10188</link>
      <description>&lt;P&gt;OP doesn't state timeline of the first program written, it could already be in production. Either way OPer was not thinking ahead that the wonderful code in program 1 could be reused - in that I totally agree with you about OP needing to do their job!&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2016 15:23:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400010#M10188</guid>
      <dc:creator>raghug</dc:creator>
      <dc:date>2016-11-18T15:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: Call Method from a ABAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400011#M10189</link>
      <description>&lt;P&gt;Hello Thomas,&lt;/P&gt;&lt;P&gt;note Horst's proposal does not trigger the INITIALIZATION event:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;CALL METHOD ('\PROGRAM=ZTM_PROG1\CLASS=PROGRAM')=&amp;gt;('MAIN').&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Further options&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;STRONG&gt;extract&lt;/STRONG&gt; the local class logic into a separate include and use it in both programs&lt;/LI&gt;&lt;LI&gt;the simplest thing that could possibly work: &lt;STRONG&gt;SUBMIT&lt;/STRONG&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;PRE&gt;&lt;CODE&gt;SUBMIT ZTM_PROG1 WITH carrid = '?whatever?' AND RETURN.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;JNN&lt;/P&gt;</description>
      <pubDate>Sat, 19 Nov 2016 11:01:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400011#M10189</guid>
      <dc:creator>nomssi</dc:creator>
      <dc:date>2016-11-19T11:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: Call Method from a ABAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400012#M10190</link>
      <description>&lt;P&gt;Generally, you shouldn't program a class with only static methods either.&lt;/P&gt;</description>
      <pubDate>Sat, 19 Nov 2016 20:15:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400012#M10190</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2016-11-19T20:15:07Z</dc:date>
    </item>
    <item>
      <title>Re: Call Method from a ABAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400013#M10191</link>
      <description>&lt;P&gt;1) Initialization in a class is by using a constructor, you don't even have to explicitly call it&lt;/P&gt;&lt;P&gt;2) Why put it in an include when you can just make a class out of it? Includes can not be independently tested, classes can be - just one of many advantages of a class...&lt;/P&gt;&lt;P&gt;3) Submit will run the entire program 1. All the poster wanted to do was explicitly call a routine &lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 03:42:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400013#M10191</guid>
      <dc:creator>raghug</dc:creator>
      <dc:date>2016-11-21T03:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: Call Method from a ABAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400014#M10192</link>
      <description>&lt;P&gt;Thomas' class has no class-constructor. Calling the &lt;EM&gt;main( )&lt;/EM&gt; method directly yields a program context where the CARRID select-option is not initialized. &lt;BR /&gt;OTOH starting the report via SUBMIT first triggers the INITIALIZATION event that explicitly invokes the &lt;EM&gt;initialization( )&lt;/EM&gt; method, then executes the &lt;EM&gt;main( )&lt;/EM&gt; method. Consider this difference in the system behavior while evaluating alternatives.&lt;/P&gt;&lt;P&gt;An include can contain one (or more) local classes with their corresponding ABAP Unit test classes, so I think a discussion on my proposal to extract the class logic to an include should be about &lt;EM&gt;global&lt;/EM&gt; against &lt;EM&gt;local&lt;/EM&gt; classes (cf. &lt;A href="http://martinfowler.com/ieeeSoftware/published.pdf"&gt;public vs published&lt;/A&gt;).  &lt;BR /&gt;&lt;BR /&gt;JNN&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 11:29:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400014#M10192</guid>
      <dc:creator>nomssi</dc:creator>
      <dc:date>2016-11-21T11:29:54Z</dc:date>
    </item>
    <item>
      <title>Re: Call Method from a ABAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400015#M10193</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;Thomas' class has no class-constructor. &lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Yes, and I am suggesting that he do change the initialization to a constructor so that the common initial code does not have to be explicitly called.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;starting the report via SUBMIT &lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You still haven't considered if that is really an option - what if program_1 changes system data that is not wanted at the moment, or is part of a workflow, or worse still sends out a end user document or customer facing document? Would you put in checks in program 1 to prevent that from happening? &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;about global against local classes (cf. public vs published). &lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The author is talking about code ownership and formalities around it, not about the programming mechanisms.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 13:40:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400015#M10193</guid>
      <dc:creator>raghug</dc:creator>
      <dc:date>2016-11-21T13:40:45Z</dc:date>
    </item>
    <item>
      <title>Re: Call Method from a ABAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400016#M10194</link>
      <description>&lt;P&gt;Really? In other OO languages (e.g. Java, C#) it is common to have utility classes which only provide static methods. What's the problem with it in ABAP? Should we preferably continue to use function groups?&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 14:53:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400016#M10194</guid>
      <dc:creator>christian_pfaller</dc:creator>
      <dc:date>2016-11-21T14:53:37Z</dc:date>
    </item>
    <item>
      <title>Re: Call Method from a ABAP Program</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400017#M10195</link>
      <description>&lt;P&gt;Really. Hence the term "Generally". That doesn't mean that there aren't exceptions where it makes sense. E.g. utility classes. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;But bear in mind that over time, it might make sense to extract a bunch of related static methods, and refactor as a class modelling a particular object. E.g. you start off with a static method that checks for userid existence. Then you create another that returns a userid's validity. After a while, it makes sense to create a class to model userids. And that's just a part of keeping your code base clean and efficient.&lt;/P&gt;&lt;P&gt;However, these extracted classes should &lt;I&gt;not&lt;/I&gt; be full of static methods. In the past, I've gone down that route, and then when I've needed to specialise, I can't subclass - so I have to refactor, and retest. My experience is that if I make them instance methods to start with, I save a lot of time and effort later in the game.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 15:44:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/call-method-from-a-abap-program/m-p/400017#M10195</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2016-11-21T15:44:03Z</dc:date>
    </item>
  </channel>
</rss>

