• Subject: Re: prototyping
  • From: "Scott Klement" <infosys@xxxxxxxxxxxx>
  • Date: 30 Jul 1999 17:04:07 -0500

Hi Ronald,

"Ronald Nance" <RNANCE@commerceinsurance.com> wrote:
> Hello People,
> I am in the process of evaluating RPGILE with a team of people (8)
> and I have been having a diffacult time creating a subprocedure.  Le
> me lay out what I have and what I want to do leave the rest to you..
> I have a program (pgma) that calls a program (pgmb).  Pgmb receives
> some parms, performs some calculations and returns several values.
> Pgmb contains only calculation specs and definitions.
> So I believe this will make an ideal subprocedure.
> I am not sure if I have to use the /copy to bring pgmb into pgma
> after I add the necessary prototype code and I am not sure how to se
> up the parameters.  The example in the programmers guide is not clea
> enough for me or I am very dense.

Normally when you refer to a "subprocedure" its part of the same
source member (or module) as the "main procedure" thats calling
it.   Since they're within the same source member, you don't use
/COPY to bring them in.

I'm guessing that what you really want to do is create a NOMAIN
service program.   Which is to say a service program without a
"main" procedure, but just sub-procedures.  And then you bind
your programs to the service program to use the procedures....

You could also prototype your programs themselves, instead of using
a sub-procedure, and call your existing pgmb.

Or maybe (for speed?) you want to use two statically bound modules?

And of course, theres probably 10 other ways you could do it :)
So, I'll give you an example of the service program approach, and
if thats not what you wanted, let me know and we'll give you a
different example...

> I have been using the ILE RPG/400 programmers guide and I am not
> haveing any luck completing my task.  So, a simple coding example
> would help me tremendously.
>    code example
>    code example
> Ronald Nance
> Commerce Insurance Group
> Webster, MA. 01570
> (508) 943-9000 Ext: 4078

In this example, PGMB will be a utility for converting a numeric
field to a human-readable character field.  (I'm at V3R2, and
can't use %editc for this!)

There are 3 source members here.  They are:

PGMA  -- the program that you'll call.
PGMB  -- the service program that contains the subprocedure.
PGMB_H -- a "header" file to make it easy to include PGMB's
          functions in other RPG programs.

To compile these, do:

To run:

Source member: PGMB_H:
 ** This is a HEADER for using the NumToChar sub-procedure from
 ** the PGMB service program.
 ** This is simply /COPY-ed into the source of the program that you
 ** want to use it from.
 ** If this were an actual service program, there'd probably be many
 ** different subprocedures (all related to each other) that can be
 ** called in that service program.
D NumToChar       PR            17A
D  pePacked                     15S 5 VALUE

Source member: PGMB:


P*  Sub procedure to format a numeric field into a character
P*   field, so that its easy to read.
P NumToChar       B                   EXPORT
D NumToChar       PI            17A
D  pePacked                     15S 5 VALUE

D wkReturn        S             17A
D wkWhole         S             10A
D wkDec           S              5A
D wkPos           S              5I 0

c                   eval      wkReturn = *blanks

C* handle neg sign
c                   if        pePacked < 0
c                   eval      wkReturn = '-'
c                   eval      pePacked = 0 - pePacked
c                   endif

C* Handle numbers before
C* decimal place
c                   movel     pePacked      wkWhole
c     '0'           check     wkWhole       wkPos
c                   if        wkPos > 0
c                   eval      wkReturn = %trim(wkReturn) +
c                                          %subst(wkWhole:wkPos)
c                   endif

C* Handle numbers after
C* decimal place
c                   move      pePacked      wkDec
c     '0'           checkr    wkDec         wkPos
c                   if        wkPos > 0
c                   eval      wkReturn = %trim(wkReturn) + '.' +
c                                          %subst(wkDec:1:wkPos)
c                   endif

c                   Return    wkReturn
P                 E

Source member: PGMA:

D wkTest1         S              4S 0
D wkTest2         S              7P 2
D wkTest3         S             11S 4
D wkMsg           S             40A

c                   eval      wkTest1 = 4561.144
c                   eval      wkTest2 = 4562.164
c                   eval      wkTest3 = 4563.894

c                   eval      wkMsg = 'Test 1 converts to ' +
c                                %trim(NumToChar(wkTest1))
c                   dsply                   wkMsg

c                   eval      wkMsg = 'Test 2 converts to ' +
c                                %trim(NumToChar(wkTest2))
c                   dsply                   wkMsg

c                   eval      wkMsg = 'Test 3 converts to ' +
c                                %trim(NumToChar(wkTest3))
c                   dsply                   wkMsg

c                   eval      wkMsg = 'Test 1 as negative ' +
c                               %trim(NumToChar(wkTest1*-1))
c                   dsply                   wkMsg

c                   eval      wkMsg = 'Test 2 as negative ' +
c                               %trim(NumToChar(wkTest2*-1))
c                   dsply                   wkMsg

c                   eval      wkMsg = 'Test 3 as negative ' +
c                               %trim(NumToChar(wkTest3*-1))
c                   dsply                   wkMsg

c                   eval      *INLR = *ON
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com

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