× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Ok That's what I meant...but I'm not a great orator...LOL 


Thanks,
Tommy Holden


-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Scott Klement
Sent: Thursday, April 20, 2006 3:41 PM
To: RPG programming on the AS400 / iSeries
Subject: RE: Tool to convert Subroutine to SubProcedure


On Thu, 20 Apr 2006, Holden Tommy wrote:
>
> OK so I'm confused....LOL
>

I think you're confused about the finer points, but not the concept. 
You're right that subroutines that may have previously been used to end 
the program won't work, but it's not because subprocedures have their
own 
LR indicator.

For example, the following program WILL NOT loop indefinitely:

      H DFTACTGRP(*NO)
      D SetLR           PR
       /free
           SetLR();
       /end-free

      P SetLR           B
      D SetLR           PI
       /free
           *INLR = *ON;
       /end-free
      P                 E

The SetLR subprocedure will successfully set on the LR indicator because

it's in the same module with the main procedure, so it shares the same
LR 
indicator.  The program will end when it reaches the end of the cycle, 
because LR will be set on.

On the other hand, there's a style of coding where people would
sometimes 
use the RETURN op-code to end programs.  For example:

      H DFTACTGRP(*NO)

       /free

            dow '1';
               exsr EndNow;
            enddo;

            begsr EndNow;
               *inlr = *on;
               return;
            endsr;

       /end-free

The ENDNOW subroutine ends the program because of the RETURN op-code. 
Further, because *INLR is on, it'll also close files, reset variables, 
etc.

If you converted ENDNOW to a subprocedure, it wouldn't work. For
example:

      H DFTACTGRP(*NO)

      D EndNow          PR

       /free

            // WARNING: This is an infinite loop.

            dow '1';
               EndNow();
            enddo;

       /end-free

      P EndNow          B
      D EndNow          PI
       /free
          *inlr = *on;
          return;
       /end-free
      P                 E

This would NOT work.  It wouldn't end the program because even though 
*INLR was turned on, it never reaches the part of the cycle where the 
program checks LR.  If I hadn't coded the "dow" loop, it'd end when it 
reached that point... but the RETURN op-code in the subprocedure returns

from the subprocedure, not the program, so it goes back to the mainline 
and loops forever.

So, you're right that converting that sort of subroutine to a
subprocdure 
won't work.  The only bit you're wrong about is WHY it didn't work.

There's a workaround if you want to end a program from within a 
subprocedure.  You can call the exit() function from ILE C.  For
example:

      H DFTACTGRP(*NO) BNDDIR('QC2LE')

      D EndNow          PR

       /free

            dow '1';
               EndNow();
            enddo;

       /end-free

      P EndNow          B
      D EndNow          PI

      D exit            PR                  extproc('exit')
      D   status                      10I 0 value

       /free
          *inlr = *on;
          exit(0);
       /end-free
      P                 E

The only problem with this is that it'll end the activation group as
well, 
which might not be desired, depending on your situation.

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.