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



Hi Dimitri,

I'm replying to the RPG400-L mailing list, since this is clearly an RPG question.

Is it possible in RPGLE to manage parameters like a array of pointers (like in C)? I need to develop a routine which receive a variable number of parameters like P(s1,s2,s3 ... s100) and have to make same operation with each of them. Can not pass one parameter as array (different length).

Yes and no. You could write code that created an array of pointers, similar to what you'd get with C, by doing something like this:

     D argc            s             10I 0
     D argv            s               *   dim(10)

     C     *Entry        plist
     c                   parm                    p001              1
     c                   parm                    p002              1
     c                   parm                    p003              1
     c                   parm                    p004              1
     c                   parm                    p005              1
     c                   parm                    p006              1

     c                   eval      argc = %parms

     c                   if        argc >= 1
     c                   eval      argv(1) = %addr(p001)
     c                   endif

     c                   if        argc >= 2
     c                   eval      argv(2) = %addr(p002)
     c                   endif

     c                   if        argc >= 3
     c                   eval      argv(3) = %addr(p003)
     c                   endif

     c                   if        argc >= 4
     c                   eval      argv(4) = %addr(p004)
     c                   endif

     c                   if        argc >= 5
     c                   eval      argv(5) = %addr(p005)
     c                   endif

     c                   if        argc >= 6
     c                   eval      argv(6) = %addr(p006)
     c                   endif

Naturally, you'd have to repeat that logic for as many parameters as you'd like to receive.

An alternative would be to write a C wrapper for the program. In other words, have a C program where the main procedure calls an RPG program or subprocedure, and passes only two parameters, argc and argv. The the RPG program would receive things in the format you want:

#pragma linkage (RPGTEST,OS)
void RPGTEST(int *argc, char **argv, int *retval);

int main(int argc, char **argv) {
    int retval;
    RPGTEST(&argc, argv, &retval);
    return retval;
}


     D RPGTEST         PR                  ExtPgm('RPGTEST')
     D   argc                        10I 0
     D   argv                          *   dim(255) options(*varsize)
     D   retval                      10I 0

     D RPGTEST         PI
     D   argc                        10I 0
     D   argv                          *   dim(255) options(*varsize)
     D   retval                      10I 0

      /free

         for x = 1 to argc;

              ... do something with argv(x) here....
              ...  remember that RPG's arrays start with 1, but
                   C's arrays start with 0, so argv(1) in RPG
                   is the same as argv[0] in C....

         endfor;

         retval = 0;
         *inlr = *on;

      /end-free



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.