How Can I pass multiple USER ID’s to QEZSNDMG

50 pts.
AS/400 API
IBM iSeries
Does anyone have an example of passing multple user id's to the API QEZSNDMG?  I have a CL that calls QEZSNDMG and it works fine with one user or *ALLACT.  I need to supply a list of multiple users that I can pass to it.  Anyone have an example of that?

Software/Hardware used:
CLP on iSeries

Answer Wiki

Thanks. We'll let you know when a new response is added.

Here is a link to an article explaining how to do what you want.
On the page there is a link to display the source code.

Thanks for the link, and I did read tha article. However it really did not give me what am looking for. I have a front end CL program that will gather groups of user id’s and pass then to QEZSNDMG. Each time this program is run it may have different user id’s and a different amount of them. Specifically, how do I pass this to the &listusers and &listnumber parameter?

The whole example program should be rewritten, but I’ll put some snippets here to see if I can make sense of it for you.
VALUE( ‘ ‘ ) /* This will be filled with +
user profiles as they become known */

VALUE(X’00000000’) /* This specifies that +
the number is currently zero */

/* These will become elements of the “Array of Char(10)”… */

dcl &usr1 *char 10 value( ‘USER1’ )
dcl &usr2 *char 10 value( ‘USER2’ )
dcl &usr3 *char 10 value( ‘USER3’ )

/* Simply concatenate all users at once… */

chgvar &LISTUSERS ( &usr1 *cat &usr2 *cat &usr3 )
chgvar %bin( &LISTNUMB ) ( 3 )

/* or */

/* Put first element in place… */
chgvar %sst( &LISTUSERS 1 10 ) &usr1
/* Increment the counter… */
chgvar %bin( &LISTNUMB ) ( %bin( &LISTNUMB ) + 1 )

/* Put second element in place… */
chgvar %sst( &LISTUSERS 11 10 ) &usr2
/* Increment the counter… */
chgvar %bin( &LISTNUMB ) ( %bin( &LISTNUMB ) + 1 )

/* Put second element in place… */
chgvar %sst( &LISTUSERS 21 10 ) &usr3
/* Increment the counter… */
chgvar %bin( &LISTNUMB ) ( %bin( &LISTNUMB ) + 1 )

call QEZSNDMG ( +
I initialized &LISTUSERS to blanks and &LISTNUMB to zero. And I declared three new variables — &usr1, &usr2 and &usr3. The three new variables are declared as *CHAR(10) because the API documents the list of users as an “Array of Char(10)”. I then show two possible ways to get those three values into the list.

First, I simply concatenate all three together. The result of the concatenation is assigned directly to the list variable. Also, when that’s done, the number of list values needs to set to [3] to indicate how many elements are in the array. By using the %BIN() builtin function, I don’t need to use hexadecimal notation — I can simply assign [3] as the value.

Alternatively, each user can be added to the list one at a time. In order to do that, you have to be careful in case a user identifier is less than 10 characters long. Trailing blanks will mess up concatenation because the list variable has to start with a blank value. If you try to *CAT the first user to the list, it will get placed at the end, beyond the 3000 character size. If you try to use *TCAT, then users will get placed in wrong positions whenever the previous user is less the 10 non-blank characters. A similar problem would happen with *BCAT.

So, concatenation is out. Instead, each user needs to be inserted into consecutive substring positions, using the %SST() builtin function. The first goes into the substring at position 1 for a length of 10. The second one goes into position 11 for a length of 10. The third one goes into position 21, and so forth. Each time a user is added to the list, the counter is incremented by [1].

Naturally, that lends itself to processing in a loop. Use a variable for the position and increment it by [10] whenever another user is added.

This isn’t a good format for demonstrating code, but maybe it’ll give you ideas. Post back if clarification is wanted.

Discuss This Question: 4  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • GaryT
    This was very helpful and I believe will solve my issue. I will test it out and see if i need further assistance. Thank you.
    50 pointsBadges:
  • GaryT
    Tom, Ok, I think I am getting closer on this. In your example above, it appears that you are receiving &USER1, &USER2, &USER3 as individual parms and then adding them to the array &LISTUSERS. My frontend program wll pass the users as an array in one PARM. Let's call it &USERS. I suppose I will have to %sst &USERS into &USER1, &USER2, &USER3, etc. and the rebuild &LISTUSERS parm as you have shown above. Is this a correct assumption?
    50 pointsBadges:
  • TomLiotta
    Gary, sorry for slow response... Yes, that would seem to be a correct assumption. You'd have an "offset" variable that you incremented for each user. dcl &ofs *int value( 1 ) dowhile ...whatever chgvar %sst( &LISTUSERS &ofs 10 ) %sst( &USERS &ofs 10 ) chgvar &ofs ( &ofs + 10 ) enddo Something like that. However, if you're coding for V5R4 or later, you might use the DEFVAR() attribute to define &USER1, &USER2, etc., directly over your array. Or you could step through by incrementing a pointer. Regardless, you'll need to be careful how many users you try to pull out of your array. You should test trying to extract one beyond the end to get some experience with what happens and how to handle it. Tom
    125,585 pointsBadges:
  • GaryT
    Tom, Thanks for the info. Based on the info you provided me previously, I was able to tweak a couple of things and get this to work how I needed it. I appreciate the example you provided me, it really helped. Thanks
    50 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: