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



Buck,
Good catch.
I missed that he did not have the $C variable defined outside the prototype.

Jeff Young
Sr. Programmer Analyst

On Wed, Feb 1, 2017 at 4:25 PM, Buck Calabro <kc2hiz@xxxxxxxxx> wrote:

On 2/1/2017 2:47 PM, Scott Williams wrote:

I'm attempting to create a very simple procedure that converts a given
numeric value into another. In this case, a value in Celsius to be
converted to Fahrenheit.

The RPG manual is your 'go-to' reference, but you can also check out the
old but still very useful ILE 'Sorcerer's' Redbook.

I can't seem to get my PR and PI sorted out, and/or the positioning of
the
P spec decs.

You have it right.

The 'PR' indicates a prototype. The prototype is a way to tell the
compiler about a procedure; what its name is, what sort of variable (if
any) it returns, what parameters (if any) it takes as input.

The P-specs enclose the actual procedure.

HDFTACTGRP(*NO)
HMAIN(C2F)
D CVT2F PR 5S 2 EXTPROC('C2F')
D
D $C 5S 2 VALUE

D$F S 5S 2

/FREE
$F = C2F($C);

Guessing you have a '$C undefined' error here. That's because the
parameter names on the PR specs aren't actually defining variables -
they are... documentation. So there is no $C defined in the mainline of
this program. Just like the code defines $F, it needs to define $C.
More interestingly, the names in the mainline don't need to be the same
as those in the sub-procedure.

Once you define $C (try something like input_c) you'll need to assign a
value to it. You can do that in the D specs or in the calcs, but either
way, in order to get Fahrenheit out, you'll need to send Celsius in.

Because the code specifies 'VALUE' on the parameter, you can pass in a
literal; the compiler will handle the conversion from literal to 5s 2
for you. So you could skip defining $C altogether and do this:

$f = c2f(25);

DSPLY $F;
*INLR = *ON;
/END-FREE

PC2F B EXPORT
DC2F PI 5S 2
D $C 5S 2 VALUE
D$F S 5S 2
/FREE
$F = (($C * 1.8) + 32);
RETURN $F;
/END-FREE
P E

Do I create this as a module, or a bound program?

I'd create it with CRTBNDRPG. As-written, the EXPORT is extraneous.
EXPORT means that you want other programs to be able to execute this
sub-procedure. Generally speaking, I'd advise that if you want to do
that, you put it into a service program rather than a program.

But for starting out, what you have is the perfect vehicle for
experimentation. Once you become comfortable with the infrastructure of
PI/PR, etc it's another very useful exercise to move those
sub-procedures into a service program. But for now, one step at a time :-)

--
--buck

Try wiki.midrange.com!

--
This is the RPG programming on the IBM i (AS/400 and 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.

Please contact support@xxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: http://amzn.to/2dEadiD


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

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.