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



Simpler in free

If you are defining the procedure in the same module you do not need the
prototype defined or the export key word.

This example gives you three procedures. On a Main program, you need the
prototype to define the ExtPgm keyword.

This has not been compiled so might have syntax errors. Let me know if you
have questions.


ctl-opt Option(*Srcstmt:*Nodebugio:*NoUnRef);
ctl-opt Main(ConvertDegreee);

dcl-pr ConvertDegrees) ExtPgm('CVT2F');
PR_InType Char(1) Const;
PR_InDegrees Char(7) Const;
end-pr

//***************************************************************
//* ConvertDegreess
//* Convert From one degrees to another.
//* In - Type Fahrenheit(F) or Celsius(c)
//* Degrees to convert in 5.2 format in alpha.
//* Out - None
//* Returns - None
//****************************************************************
dcl-proc ConvertDegrees;
dcl-pi *N;
InType Char(1) Const;
InDegrees Char(7) Const;
end-pi;

dcl-s Degrees Packed(5:2);
dcl-s Result Packed(5:2);

Degrees = %Dec(InDegrees:5:2);

If InType = 'F';
Result = ConvertToFahrenheit(Degrees);
Else;
Result = ConvertToCelsius(Degrees);
EndIf;

Dsply %Char(Result);

Return;

end-proc;

//***************************************************************
//* ConvertToFahrenheit
//* Convert from Celsius to Fahrenheit
//* In - Degrees
//* Out - None
//* Returns - Result
//****************************************************************
dcl-proc ConverttoFahrenheit;
dcl-pi *N Packed(5:2);
InDegrees Packed(5:2) Value;
end-pi;

Return %Dec(((InDegrees * 1.8) + 32):5:2);

end-proc;
//***************************************************************
//* ConvertToCelsius
//* Convert from Fahrenheit To Celsius
//* In - Degrees
//* Out - None
//* Returns - Result
//****************************************************************
dcl-proc ConverttoCelsius;
dcl-pi *N Packed(5:2);
InDegrees Packed(5:2) Value;
end-pi;

Return %Dec(((InDegrees * 9) / 5)) + 32):5:2);

end-proc;



On Wed, Feb 1, 2017 at 11:47 AM, Scott Williams <scottwill0707@xxxxxxxxx>
wrote:

Been trying to learn procedures, and having some difficulty. After reading
examples online, I've found myself going in circles and even more confused.
I feel like I'm throwing knifes in a dark room...

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.

I can't seem to get my PR and PI sorted out, and/or the positioning of the
P spec decs. Do I create this as a module, or a bound program? Please let
me know what I am doing wrong. I would like to understand how to properly
use a procedure so I can extrapolate this simple example into larger ideas.
(Machine is 7.1 version of the OS)

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);
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

Thanks in advance!

--
Scott Williams
--
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.