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




jakemorkel@xxxxxxxxxxxxxxxx, michaelsparks@xxxxxxxxxxxxxxxx,...so I want to
give multiple email addresses.

I guess what I'm struggling with is whether these are supposed to all be in one big variable that has a varying size, or whether they're supposed to be in an array of variables with a varying number of elements. In other words, is this one variable or many variables? If you answered that question in your clarification, then I missed it.

I'm not familiar with the "accptargs4" Java class. Specifically, I'm not familiar with what it's main method is expecting for parameters. Does it expect all of the e-mail addresses to be in args[0] (on the Java side, which is args(1) on the RPG side) or, does it expect jakemorkel@xxxxxx to be in args(1), and michaelsparks@xxxxxx to be in args(2), etc?

If you want them to be all in one variable, you'd do something like this. This is the source code for the *CMD object:

  CMD  PROMPT('Send E-mail')

  PARM KWD(RECLST) +
       TYPE(*CHAR) LEN(5000) VARY(*YES *INT2) CASE(*MIXED) +
       INLPMTLEN(32) +
       MIN(1) MAX(1) +
       CHOICE('E-mail Address') +
       PROMPT('Recipient List')

  PARM KWD(SUBJECT) +
       TYPE(*CHAR) LEN(256) VARY(*YES *INT2) CASE(*MIXED) +
       MIN(1) MAX(1) +
       PROMPT('Subject')

  PARM KWD(MESSAGE) +
       TYPE(*CHAR) LEN(5000) VARY(*YES *INT2) CASE(*MIXED) +
       MIN(1) MAX(1) +
       PROMPT('Message')

On the RPG side, you'd receive the parameters like this:

     H DFTACTGRP(*NO) ACTGRP(*NEW) THREAD(*SERIALIZE)

     D SWR991TEST      PR                  ExtPgm('SWR991TEST')
     D   reclst                    5000A   varying const
     D   subj                       256A   varying const
     D   msg                       5000A   varying const
     D SWR991TEST      PI
     D   reclst                    5000A   varying const
     D   subj                       256A   varying const
     D   msg                       5000A   varying const

      /free

         args(1) = String$new(reclst);
         args(2) = String$new(subj);
         args(3) = String$new(msg);

Note the following:

a) The VARY(*YES *INT2) option on the command changes the *CHAR field into one that's compatible with RPG's VARYING data type.

b) Because the command interface specifies 5000 for the char length, you won't have problems with lengths larger than 32A like you typically would with the CALL command.

c) I added THREAD(*SERIALIZE) to the H-spec. You should always do this when calling Java from RPG (or vice-versa)

The command source would typically be placed in a file called QCMDSRC (though, your shop may do that differently, I don't know) and would have a source member type of CMD.

You compile the command source with:

    CRTCMD CMD(SWR991) SRCFILE(xxx/QCMDSRC) PGM(*LIBL/SWR991TEST)

Now when you run the command, it'll run the program named SWR991TEST. You can prompt the command by typing SWR991 (or whatever you called it) and pressing F4, just as you would with an OS/400 command.

To run the program, you'd do this:

    SWR991 RECLST('jake@xxxxxx,michael@xxxxxx,scott@xxxxxxxxxxx')
           SUBJECT('Oh, Happy day!')
           MESSAGE('I love cabbage.')

If, on the other hand, you want to make it like a normal OS/400 command where the e-mail addresses aren't all in one string, but rather are separate, you'd change the command definition for reclst to be something like this:

  PARM KWD(RECLST) +
       TYPE(*CHAR) LEN(256) VARY(*YES *INT2) CASE(*MIXED) +
       INLPMTLEN(32) +
       MIN(1) MAX(10) +
       CHOICE('E-mail Address') +
       PROMPT('Recipient List')

What I've done is set LEN(256) and MAX(10). Now instead of one big long variable that's 5000 chars max, I have 10 smaller variables at 256 max. This is actually going to be passed to your program as an array. The array will be prefxied with a "5U 0" field that tells you how many addresses were entered.

If you compile and prompt the command, you'll see one of those lists where you put a + in the field to enter more values, just like many of the operating system commands have.

if you want to set the values from the command line, you could do this:

    SWR991 RECLST('jake@xxxxxx' 'michael@xxxxxxx' 'scott@xxxxxxx')
           SUBJECT('Oh, Happy day!')
           MESSAGE('I love cabbage.')

That's what people would typically expect from an OS/400 command, so it'll be more familiar to the next guy who needs to understand what you're doing.

To code that up in RPG, I'll make a data structure that contains the count (number of addresses passed) at the start, followed by an array of up to 10 variables, each 256 VARYING.

     D RecLst_t        ds                  based(Template)
     D   count                        5U 0
     D   addr                       256A   varying dim(10)

     D SWR991TEST      PR                  ExtPgm('SWR991TEST')
     D   reclst                            likeds(RecLst_t) const
     D   subj                       256A   varying const
     D   msg                       5000A   varying const
     D SWR991TEST      PI
     D   reclst                            likeds(RecLst_t) const
     D   subj                       256A   varying const
     D   msg                       5000A   varying const

Now, to load each one into a separate "args" element, you could do this:

       argc = 0;

       for x = 1 to reclst.count;
          argc = argc + 1;
          args(argc) = String$new(reclst.addr(x));
       endfor;

       argc = argc + 1;
       args(argc) = String$new(subj);

       argc = argc + 1;
       args(argc) = String$new(msg);

What that does is loop through all of the addresses passed (each one is in it's own array element) and assign each one to the next element in the args array. That way, each one is passed as a separate parameter to the Java method.

Of course, if the Java program does expect them to all be in a single parameter, you could still do it that way with this second approach, you'd just have to concatenate them in the RPG code. For example:

     D alladdr         s           5000A   varying
       .
       .
       for x = 1 to reclst.count;
           if (x = 1);
              alladdr = reclst.addr(x);
           else;
              alladdr = alladdr + ',' + reclst.addr(x);
           endif;
       endfor;

       args(1) = String$new(alladdr);

Again, I don't know how the Java method works, so I don't know if this is desired or not. Also, please remember to change your String$new() prototype to allow for strings that are as long as 5000 chars.

You might also consider replacing the $ in the name String$new with an underscore so you have String_new(). That's much nicer to read, plus it isn't good to use a dollar sign in a variable name (see the recent thread on this topic.)

Anyway, hope that helps.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
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.