Re: Call a C program from RPG with variables & a return
Stephen Mooney <stephenmmooney-/[email protected]>
| Newsgroups | gmane.comp.lang.as400.c |
|---|---|
| Message-ID | <[email protected]> |
Charles,
Thank you for your suggestion. I was using the SQL set function after calculating the total for three months:
$Tot03 = ($AvgH(1) * $AvgH(2) * $AvgH(3))
SET :$Geo03 = :$Tot03 ** (1/:$Root03);
And that works fine. When I try it with 12 month's, the result field is not large enough (set to 63P) and the program errs. Same happens with:
$Tot12 = ($AvgH(1) * $AvgH(2) * $AvgH(3) * $AvgH(4) * $AvgH(5) * $AvgH(6) * $AvgH(7) * $AvgH(8) * $AvgH(9) * $AvgH(10) * $AvgH(11) * $AvgH(12)) ** (1/12);
I think I need to use 'C' because if I declare the result field as "double" I do not have the restriction I do in RPG. Regards, Stephen M. Mooney
From: Charles Wilt <[email protected]>
To: Bare Metal Programming IBM i (AS/400 and iSeries) <[email protected]>
Sent: Wednesday, February 17, 2016 8:49 AM
Subject: Re: [C400-L] Call a C program from RPG with variables & a return
Why bother with C?
RPGLE can do it quite easily.
gMean = (a*b*c*d*e*f*g*h*i*j*k*l) ** (1/12);
Charles
On Tue, Feb 16, 2016 at 5:07 PM, Stephen Mooney <[email protected]>
wrote:
> Greetings,
> I am looking for some example 'C' code that will allow me to pass 12
> numeric variables from an SQLRPGLE program to a 'C' program that will
> calculate the geometric mean for them and return the value to the SQLRPGLE
> program.
> I found an example where an RPG program will pass two character fields to
> a 'C' program which will concatenate and return them, however I know
> nothing of 'C', its syntax, or setting it up with an 'int' or 'void' to get
> my example to do what I want.
> Currently, this is the 'C' code example I am working with:
> #include <stdio.h>
>
> /* Main program. */
>
>
> int main(int argc, char *argv[])
> {
>
> /* Display
> parameters sent to the program. */
> printf("Incoming parameter 1 = %s\n", argv[1]);
> printf("Incoming parameter 2 = %s\n", argv[2]);
>
> /*
> Concatenate the two incoming parameters into the third parameter. */
> strcpy(argv[3],argv[1]);
> strcat(argv[3],argv[2]);
>
> /*
> End of program. Returning with concatenation of parameters 1 and 2 into
> parameter 3. */ return;
>
> }
>
> I have found a 'C' program example that calculates the geometric mean I am
> looking for, but it is set up as follows:
> #include<stdio.h> #include<math.h>
> int main(void)
> { //
> ((X1)(X2)(X3)........(XN))1/N double
> x1=2,x2=4,x3=6,x4=7,x5=6; double x,N=5;
> x=(x1*x2*x3*x4*x5);
> x=pow(x,(1/N)); printf("Geometric Mean for
> Xn: %lf",x); return 0; }
>
> I believe I would need to set up x1=argv[1], x2=argv[2] and so on, but I
> do not believe I am setting up the variables correctly to pass back what I
> am looking for.
> Any suggestions would be greatly appreciated. Thanks. Regards, Stephen
> Mooney
> --
> This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L)
> mailing list
> To post a message email: [email protected]
> To subscribe, unsubscribe, or change list options,
> visit: http://lists.midrange.com/mailman/listinfo/c400-l
> or email: [email protected]
> Before posting, please take a moment to review the archives
> at http://archive.midrange.com/c400-l.
>
>
--
This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L) mailing list
To post a message email: [email protected]
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: [email protected]
Before posting, please take a moment to review the archives
at http://archive.midrange.com/c400-l.
--
This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L) mailing list
To post a message email: [email protected]
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: [email protected]
Before posting, please take a moment to review the archives
at http://archive.midrange.com/c400-l.