Midrange News for the IBM i Community


Posted by: renojim
Generate custom message to return to calling Java
has no ratings.
Published: 07 Dec 2014
Revised: 09 Dec 2014 - 3284 days ago
Last viewed on: 05 Dec 2023 (3967 views) 

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

Generate custom message to return to calling Java Published by: renojim on 07 Dec 2014 view comments(5)

I'm calling a CL pgm from java, using ProgramCall. I want to create my own message in the CL and return it to the calling java pgm, receiving it using ProgramCall.getMessageList(). I thought I could use SNDPGMMSG but I haven't been able to find a way to make it work. Is there a way to do this?

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS

(Sign in to Post a Comment)
Posted by: starbuck5250
Premium member *
Comment on: Generate custom message to return to calling Java
Posted: 8 years 11 months 29 days 13 hours 15 minutes ago

What did you try?  Could you post the Java that you're using to try to get the messages?  Could you post the CL that you're using to send the messages? 

Posted by: renojim
Premium member *
Comment on: Generate custom message to return to calling Java
Posted: 8 years 11 months 29 days 26 minutes ago

Sure, and thanks for the response.

In java, I'm calling a CL:

AS400Message[] messagelist = new AS400Message[5];

pgm = new ProgramCall(sys, "/QSYS.LIB/" + mylibname
+ ".lib/" + "MYPGMNAME" + ".PGM", parmList);
                
 if(pgm.run()==true){
    messagelist = pgm.getMessageList();
    return messagelist;
    }

Which works - the CL that's called then calls an RPG pgm, and I can put a division by zero in the RPG and get back a fail message in messagelist.

So I try to get my own message returned in the CL, which obviously doesn't work:

CHGVAR     VAR(&MSGTXT) VALUE('THIS IS A TEST')    
SNDPGMMSG  MSG(&MSGTXT) TOPGMQ(*EXT) MSGTYPE(*COMP)

Posted by: DaleB
Premium member *
Reading, PA
Comment on: Generate custom message to return to calling Java
Posted: 8 years 11 months 28 days 20 hours 9 minutes ago

Haven't run into this particular situation, but I think the TOPGMQ(*EXT) could be the problem. See http://techtipsjava.blogspot.com/2013/04/calling-as400-cl-commands-from-java.html. The sample SNGPDMMSG (near the bottom) doesn't specify a TOPGMQ(), so it's using the default of *PRV.

Posted by: starbuck5250
Premium member *
Comment on: Generate custom message to return to calling Java
Posted: 8 years 11 months 28 days 17 hours 46 minutes ago

I think you want an escape message, so:

chgvar &msgtxt 'CCCNNNNEmulated failure'                  
SNDPGMMSG  MSGID(CPF9999) MSGF(QCPFMSG) MSGDTA(&MSGTXT) +
           MSGTYPE(*ESCAPE)                              

The bit about CCCNNNN is because AS400Message seems to expect an actual message ID as the first 7 characters.  I didn't experiment very far though.

Posted by: renojim
Premium member *
Comment on: Generate custom message to return to calling Java
Posted: 8 years 11 months 27 days 23 hours 13 minutes ago

Bingo! Thanks much!