Clearing Message Queue in AS400?

50 pts.
Tags:
AS/400
Hi All,

Is there a way to clear the Messages from Message Queue datewise, consider i have messages for a 30 days and i want to delete the messages for  first 20 leaving messages for Last 10 days

Kindly let me the is there a possible



Software/Hardware used:
AS400
ASKED: March 10, 2010  7:30 AM
UPDATED: May 18, 2010  10:01 AM

Answer Wiki

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

Hi,

Type

GO CLEANUP

Take option 1.

Regards,
Wilson

========================================================

The CLEANUP option lets you set aging for all user message queues (and other options.) If you are trying to manipulate specific message queues, there is no system-supplied option that I’m aware of. It’s not out of reach for an average CL programmer.

Here’s a command definition and command-processing program that’s a basic variation of a utility that I use. You should be able to copy/paste these into text streamfiles, and then CPYFRMSTMF into source members.

Command definition:<pre>
RMVMSGQMSG: CMD PROMPT(‘Remove *MSGQ Messages’) /* Remove +
given message ID messages from the named +
*msgq… */

/* MSGQ: The qualified name of the *msgq to clean… */

PARM KWD(MSGQ) TYPE(MSGQNAM) MIN(1) CHOICE(‘*Msgq +
name’) PROMPT(‘Message queue’)
MSGQNAM: QUAL TYPE(*NAME) LEN(10) MIN(1)
QUAL TYPE(*NAME) LEN(10) DFT(*LIBL) +
SPCVAL((*CURLIB) (*LIBL)) PROMPT(‘Queue +
library’)

PARM KWD(MSGID) TYPE(*NAME) LEN(7) PASSVAL(*NULL) +
CHOICE(‘Message ID’) PROMPT(‘Message ID’)

PARM KWD(DLTBEFORE) TYPE(*DATE) PASSVAL(*NULL) +
PROMPT(‘Delete prior to (MMDDYY)’)

/* If one is specified, the other must not be… */
DEP CTL(MSGID) PARM((DLTBEFORE)) NBRTRUE(*EQ 0) +
MSGID(SYU5203)

/* But one of the two must be specified… */
DEP CTL(*ALWAYS) PARM((MSGID) (DLTBEFORE)) +
NBRTRUE(*NE 0) MSGID(SYU5204)

/* ADDMSGD MSGID( SYU5203 ) */
/* MSGF( mylib/SYUSRMSG ) */
/* MSG( ‘Both MSGID and DLTBEFORE cannot be specified.’ ) */
/* CCSID( *JOB ) */

/* ADDMSGD MSGID( SYU5204 ) */
/* MSGF( mylib/SYUSRMSG ) */
/* MSG( ‘Either MSGID or DLTBEFORE must be specified.’ ) */
/* CCSID( *JOB ) */

/* CRTCMD CMD( mylib/RMVMSGQMSG ) */
/* PGM( mylib/RMVMSGQMSG ) */
/* SRCFILE( mylib/QCMDSRC ) */
/* SRCMBR( RMVMSGQMSG ) */
/* MSGF( mylib/SYUSRMSG ) */
/* PRDLIB( mylib ) */</pre>

Command-processing program:<pre>
pgm ( +
&QQ +
&cId +
&cDate +
)

dcl &QQ *char 20
dcl &cId *char 7
dcl &cDate *char 7

dcl &Q *char 10
dcl &QLib *char 10

dcl &Id *char 7
dcl &Date *char 7

dcl &MsgId *char 7
dcl &Sender *char 80
dcl &KeyVar *char 4
dcl &cnt_RmvMsg *dec ( 5 0 ) value( 0 )
dcl &Cnt_c *char 5

dcl &MsgDate *char 7

dcl &@ByMsg *lgl
dcl &MsgDate *char 7

/* Extract any supplied parm values… */

chgvar &Q %sst( &QQ 1 10 )
chgvar &QLib %sst( &QQ 11 10 )

chgvar &Id &cId
monmsg ( MCH3601 ) exec( do )
rcvmsg msgtype( *LAST ) rmv( *YES )
monmsg ( cpf0000 cpf9999 mch0000 )
chgvar &@ByMsg ’0′
chgvar &Id ‘*NONE’ /* Not supplied — default */
enddo

chgvar &Date &cDate
monmsg ( MCH3601 ) exec( do )
rcvmsg msgtype( *LAST ) rmv( *YES )
monmsg ( cpf0000 cpf9999 mch0000 )
chgvar &Date ‘*NONE’ /* Not supplied — default */
enddo

/* If we can’t grab the queue, we can’t change it… */

chgmsgq msgq( &QLib/&Q ) reset( *YES )
monmsg ( CPF2408 ) exec( do )
sndpgmmsg msgid( CPF9898 ) msgf( QCPFMSG ) +
msgdta( +
‘Not authorized to *msgq’ *bcat &Q +
) +
msgtype( *COMP )
return
enddo

alcobj obj( (&QLib/&Q *MSGQ *EXCL) ) wait( 0 )

/* Receive initial message to begin looping… */

rcvmsg msgq( &QLib/&Q ) msgtype( *FIRST ) rmv( *NO ) +
keyvar( &KeyVar ) msgid( &MsgId ) sender( &Sender )

Rcv_Msg:

if ( &KeyVar = ‘ ‘ *and &MsgId = ‘ ‘ ) +
goto End_Pgm

/* If selected MsgId, remove that message… */

if ( &Id *eq &MsgId ) do
rmvmsg msgq( &QLib/&Q ) msgkey( &KeyVar )
chgvar &cnt_RmvMsg ( &cnt_RmvMsg + 1 )
enddo

else do

/* If older than selected Date, remove that message… */

chgvar &MsgDate %sst( &Sender 43 7 )

if ( &Date *gt &MsgDate ) do
rmvmsg msgq( &QLib/&Q ) msgkey( &KeyVar )
chgvar &cnt_RmvMsg ( &cnt_RmvMsg + 1 )
enddo

enddo

/* …otherwise move on to next message… */

rcvmsg msgq( &QLib/&Q ) rmv( *NO ) keyvar( &KeyVar ) +
msgid( &MsgId ) sender( &Sender )

goto Rcv_Msg

End_Pgm:

/* Release exclusive lock… */

dlcobj obj( (&QLib/&Q *MSGQ *EXCL) )

/* …and report final stats… */

chgvar &Cnt_c &cnt_RmvMsg

if ( &@BYMSG ) +
sndpgmmsg msgid( CPF9898 ) msgf( QCPFMSG ) +
msgdta( +
&Cnt_c *bcat +
&Id *bcat +
‘messages removed from’ *bcat +
&Q +
) +
msgtype( *COMP )

else +
sndpgmmsg msgid( CPF9898 ) msgf( QCPFMSG ) +
msgdta( +
&Cnt_c *bcat +
‘messages older than’ *bcat +
&Date *bcat +
‘removed from’ *bcat +
&Q +
) +
msgtype( *COMP )

return

endpgm</pre>
I name them both RMVMSGQMSG — Remove Message Queue Messages. The command will remove all occurrences of a particular message identifier or all messages older than a supplied date.

The command could be either of these:<pre>
RMVMSGQMSG MSGQ( mymsgq ) MSGID( CPF9876 )
RMVMSGQMSG MSGQ( mymsgq ) DLTBEFORE(030110)</pre>
The first would remove all CPF9876 messages from MYMSGQ; the second would delete messages older than 3/1/2010.

That version doesn’t have complete error handling, though not a lot would be needed. Nor is it totally commented (but I already know how it works!)

The *CMD definition references a couple of message identifiers — SYU5203 and SYU5204. I have those defined in a message file named SYUSRMSG. You can use any message file that you can make available and change the MsgIds to whatever you want.

It’s easy to use and quick. You can make any changes you might want, e.g., change the DLTBEFORE() to be DAYSOLD() if you really need it or add a DAYSOLD() parm.

Tom

Discuss This Question: 1  Reply

 
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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Msharbudeen
    Thanks Tom helped me a lot.
    50 pointsBadges:
    report

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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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

Following