× 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.



Tim,

If you search the archives for "procedure pointer", you'll find a bunch of 
posts on how to do this.

Matt

-----Original Message-----
From: Tim Kredlo [mailto:TKredlo@xxxxxxxxxxxxxxxx]
Sent: Friday, November 07, 2003 3:19 PM
To: RPG400-L@xxxxxxxxxxxx
Subject: Replacing subroutines with subprocedures


Please help a sub-procedure novice!

I currently have a program (call it 'MidPgm') that is
called by many other programs (call them 'TopPgm's).

MidPgm then executes subroutines whose names had
been specified and passed as parameters by 'TopPgm'.
These names are moved into an array (Subr) which is
Looped through and the subroutines are executed.
All these subroutines require the same type of input and
return data of the same format (a record, number, and a code).
 
This is accomplished by using 'when' statements.
For Idx = 1 to 5;
   Select;
        When Subr(Idx) = 'GetMax';
                Exsr GetMax;
        When Subr(Idx) = 'GetMin';
                Exsr GetMin;
        etc....
   EndSl;
EndFor;

Since these subroutines are also included in other 'mid' type
programs, I am hoping to replace them with external subprocedures
(call them 'BotPgm's).

I was hoping for a way to reduce coding lines and make this
procedure more 'reusable', if not generic, with something
along the following lines. 

TopPgm would pass subprocedure names instead of subroutine names.

MidPgm and BotPgms would include a '/copy' member containing a
'generic' prototype for the BotPgms with a 'variable' name, since all
the
subprocedures would have identical input and return parameters.

*********   PROBLEM AREA   **********
(Can't use ExtPgm with a procedure that returns a parameter)
(can't use 'character variable' as parameter for ExtProc)
(can't use 'character variable' as parameter for %PAddr)
(can't have this PR refer to more than 1 ExtProc)
D CalPgm        PR              LikeDs(OutPrmsDs)
                                ExtProc(VarName)
D  InPrms                       LikeDs(InPrmsDs)
(note: OutPrmsDs and InPrmsDs are also declared in the /copy member)

The 'For' loop would be changed to:

For Idx = 1 to 5;
   If Subr(Idx) <> *Blank;

*********   PROBLEM AREA   **********
        VarName = Subr(Idx);
        OutPrms = VarName(InPrms);
   EndIf;

Since I can resolve this in my head ( the program name (in VarNam) is
known,
It's tied it to the prototype 'CalPgm' for parameter resolution) I would
think there
would be a way to code this, but I AM STUCK. Any help would be
appreciated.

Tim Kredlo
(still confused, but not as much as I was a week ago) 

_______________________________________________
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.



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.