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.
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?
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?
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)
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.
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.