Unconfigured Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

Tips and Techniques: Converting Subroutines to Subprocedures

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tips and Techniques: Converting Subroutines to Subprocedures

    ** This thread discusses the article: Tips and Techniques: Converting Subroutines to Subprocedures **
    ** This thread discusses the Content article: Tips and Techniques: Converting Subroutines to Subprocedures **
    0

  • #2
    Tips and Techniques: Converting Subroutines to Subprocedures

    ** This thread discusses the article: Tips and Techniques: Converting Subroutines to Subprocedures **
    I agree that converting subroutines to subprocedures is a good place to start and the center routine is a good example of a routine that may be used repeatedly. Once I had converted mine and become more familiar with subprocedures, I took it a step further and passed the length of the field I wanted it centered into and returned the centered field as a return value on the call to the subprocedure. This let me code the calls as: eval title1 = center(MyCompanyName:%len(title1)) eval title2 = center(MyReportName:%len(title2)) eval title3 = center('From ' + FromDate + ' To ' + ToDate:%len(title3) This flexibility gave me a much greater incentive to use the subprocedure over a subroutine!

    Comment


    • #3
      Tips and Techniques: Converting Subroutines to Subprocedures

      ** This thread discusses the article: Tips and Techniques: Converting Subroutines to Subprocedures **
      Yep, that's one of the best things about Subprocs--reusability!

      Comment


      • #4
        Tips and Techniques: Converting Subroutines to Subprocedures

        ** This thread discusses the article: Tips and Techniques: Converting Subroutines to Subprocedures **
        I recieved the follow message when I tried this method on a SQLRPGLE program.[*]RNF3788 Keyword EXTPGM must be specified when DFTACTGRP(*YES) is specified on the CRTBNDRPG command. If there a way to use a subprocedure with SQLRPGLE programs or is something else wrong? Thanks Joe

        Comment


        • #5
          Tips and Techniques: Converting Subroutines to Subprocedures

          ** This thread discusses the article: Tips and Techniques: Converting Subroutines to Subprocedures **
          I'' answer my own question. I needed to create a module then CRTPGM to specify an activation group.

          Comment


          • #6
            Tips and Techniques: Converting Subroutines to Subprocedures

            ** This thread discusses the article: Tips and Techniques: Converting Subroutines to Subprocedures **
            I don't mean to nitpick, but it's not that easy. You don't automatically get reusability just by converting a subroutine to a procedure. Here are some other things to think about: First, you need to be very clear on the interface to the procedure. There's no reusability if information is passed in and out using all global variables. A first step is to reduce or eliminate references to globals. Globals may be fine if a procedure has little applicability outside your application. But if you'd like wider usage for your code, tightly bound interfaces are a no-no. You also need to look at the functionality provided by the procedure, and see if you can combine different procs together. There's nothing as annoying as finding an existing procedure that works almost like what you need, but not quite. Also, you need a way of letting others know about the procedures you write. As annoying as the previous point is having to choose from several different procedures with similar functionality written by different developers. With the previous points in mind, you should also avoid the temptation to put too much functionality into a procedure. Best to follow the KISS rule: Keep It Sweet and Simple. Oh yeah, you also need to balance the ease of use of calling a procedure with any performance penalty associated with CONST and VALUE parameters, or with long character varying return values. My point is that, although reusability is a worthy goal, it takes a bit of experience to get it right. Cheers! Hans

            Comment


            • #7
              Tips and Techniques: Converting Subroutines to Subprocedures

              ** This thread discusses the article: Tips and Techniques: Converting Subroutines to Subprocedures **
              In my last note, I wrote: Oh yeah, you also need to balance the ease of use of calling a procedure with any performance penalty associated with CONST and VALUE parameters, or with long character varying return values. I was thinking about this particular point, and the issue is even less straight-forward. Considering the performance issue, there may well be good reason not to convert subroutines into procedures. Note that when you have inexpensive commodity-level boxes (running, say, Windows or Linux), the biggest expense is for the programmers. In those environments, programmer productivity is extremely important, and any techique that will help productivity is a major boon. At the extreme, languages like Perl and Python are popular because they allow programmers to develop apps very quickly, even though interpreted programs are normally much slower than compiled programs. In contrast, when you have boxes costing seven figures (like some iSeries and zSeries boxes), performance is critical. For the very high-end boxes, running at 95% of CPU capacity is not unusual. Thus, anything that would reduce the performance of an application is anathema. Hiring additional programmers to maintain a tightly-coupled, monolithic application might just be more cost-effective than modularizing the app to make it more maintainable with fewer programmers if the modularization ends up slowing down the app too much. Anyways, I got no answers. Just more things to think about when thinking about converting subroutines to procedures. Cheers! Hans

              Comment


              • #8
                Tips and Techniques: Converting Subroutines to Subprocedures

                ** This thread discusses the article: Tips and Techniques: Converting Subroutines to Subprocedures **
                Don't you add an entry to the call stack every time the procedure is called? Maybe there should have been a note about that in the fine print.

                Comment


                • #9
                  Tips and Techniques: Converting Subroutines to Subprocedures

                  ** This thread discusses the article: Tips and Techniques: Converting Subroutines to Subprocedures **
                  Rather than creating a module then creating a program, put an H spec at the top of your program. Hdftactgrp(*NO) actgrp('YOURACTGRP') Then you can use the CRTBNDRPG command.

                  Comment

                  Working...
                  X