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



Hello Mihael,

> is it possible in rpg to return a value from a program. i don't mean to
> get a return value of a procedure.

Actually, that's not what you're looking for.  Please read on...

> i like to do something in perl like this:
> $myvar = `system myrpgprogram`;


This code does not get the return value of your program.  Instead, what it
does is load $myvar with any data that your program writes to STDOUT.
Again, assuming that you're working with QShell which is a
descriptor-based environment, you can write to STDOUT by writing data to
descriptor #1.

If you're not using QShell then you may have to use the QtmhWrStout to
write to stdout, or else enable descriptor I/O by setting the appropriate
environment variable.  I haven't experimented with the environment
variable, though...

Also the QShell "system" program is for running CL commands, not calling
programs.  You can call a program directly by using it's IFS pathname, you
don't need "system".  For example, to call a program called "MYPGM" in
library "MYLIB" you'd specify:
   /qsys.lib/MYLIB.lib/MYPGM.pgm


> but i don't know how i should define my prototype in the rpg program.
> the rpg program name is BS_SUBS. it tried it like this:
>
> DMain             PR            10A   EXTPGM('BS_SUBS')
> D  subname                      10A
> D  sublib                       10A
>  *
>  *Entry list (parameter)
> DMain             PI            10A
> D  subname                      10A
> D  sublib                       10A
>
> but it says that a return value is not supported with EXTPGM key word.

That's correct.  RPG cannot return a value from a program.  However, the
perl code that you've posted doesn't use the return value anyway, so it
doesn't matter.  It reads data from the program's stdout, as I mentioned
above.

Here's a sample ILE RPG program that writes data using descriptor I/O:

     H DFTACTGRP(*NO)

     DMain             PR                  EXTPGM('BS_SUBS')
     D  subname                      10A
     D  sublib                       10A

      *Entry list (parameter)
     DMain             PI
     D  subname                      10A
     D  sublib                       10A

     D write           PR            10I 0 extproc('write')
     D   fd                          10I 0 value
     D   data                     32767A   options(*varsize) const
     D   len                         10I 0 value

     D mydata          s            100A   varying

      *
      *  QShell null-terminates it's parms.  Here we use the %str()
      *  bif to extract the full parm into a string that we can
      *  write to stdout:

     c                   if        %parms >= 2

     c                   eval      mydata = 'parms were '
     c                                    + %str(%addr(subname)) + ', '
     c                                    + %str(%addr(sublib))
     c                                    + x'0D25'

     c                   else

     c                   eval      mydata = 'no parameters were passed!'
     c                                    + x'0D25'

     c                   endif


      *
      * Write "mydata" to standard output.  It is assumed that we
      * are using descriptor 1 for stdout, for compatibility with
      * Qshell...
      *
     c                   callp     write(1: mydata: %len(mydata))


     c                   eval      *inlr = *on


I tested this program by calling it from the following trivial Perl
script:

    $myvar = `/qsys.lib/MYLIBRARY.lib/bs_subs.pgm testparm1 testparm2`;
    print $myvar


When that perl script is run from QShell, it executes the program called
BS_SUBS in library MYLIBRARY.  It passed two parameters "testparm1" and
"testparm2"

If you run that perl script, the output looks like this:

----------------------------------------------------------------------------
                              QSH Command Entry
  $
> perl test.pl
  parms were testparm1, testparm2
  $


----------------------------------------------------------------------------


Hope that helps...

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.