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


  • Subject: Re: RPG IV program - comments requested
  • From: "Scott Klement" <infosys@xxxxxxxxxxxx>
  • Date: 27 Sep 1999 00:09:44 -0500

Jim Langston <jlangston@conexfreight.com> wrote:
>
> Okay, if I declare a Prototype and Procedure interface, can I still
>  call my
> RPG program from the command line?  Or would it always have to be
>  called
> from another program?

You can still use the command line, with the same restrictions that
have always existed when calling programs from the command line.

The advantage to using a prototype is that where its available (i.e.
other RPG IV programs) the compiler can ensure that you're passing
the correct data types, and in some instances do some conversions
for you.

> Prototyping I somewhat understand from C and Pascal, when I would
>  prototype
> a subroutine or a function so the compiler wouldn't have to make 2
>  passes.  But
> what is the Procedure Interface for?  Is that just an indicator of m
>  Parm List?
> And
> if so, is the Prototype required?

The prototype should be included wherever your program or procedure
is going to be called FROM...

The procedure interface belongs in the procedure itself.  It works
the same way that it does in C, except that the main procedure needs
a prototype as well -- since its not always the same, as it is in C.

in C you might have:

int count_records(const char *filename);     <--- prototype

... misc other code....

int count_records(const char *filename) {    <--- procedure interface
    FILE *f;
    int ch, count;
    if ((f=fopen(filename,"r"))==NULL) {
         return -1;
    }
    count=0;
    while ((ch=fgetc(f))!=EOF) {
        count++;
    }
    return count;
}


>
> And I see you can declare an input variable as a Constant (CONST)
>  which seems
> somewhat foreign to my concept of a constant, but if that's the way
>  RPG does it,
> I can deal with it.

Declaring it a const means that the procedure that accepts it as a
"const" parameter can't modify it.   This is very useful, because it
allows you to do things like pass expressions or literals, since
the compiler knows it won't change, and therefore you don't need the
result to be returned.

Its useful in C, since strings are actually just pointers to the first
character in the string...   this makes it very difficult to pass it
by value.  So, CONST can be used to get some of the advantages of
passing by value without actually doing it...

Its useful in RPG because whenever you call a seperate program (i.e.
you use the ExtPgm keyword) your data MUST be passed by reference.
(I'm sure that there are other reasons, but thats the one that leaps
to mind)

Does that make any sense?

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