Reading tape volume

30 pts.
Tags:
AS/400
Is there a way to read and return to a CL program the tape volume of a mounted tape?
ASKED: February 1, 2007  10:33 AM
UPDATED: December 30, 2009  4:16 AM

Answer Wiki

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

The DSPTAP command can be used to dump information about the loaded tape to an output file that you can read in the CL program. Tape volume label is included in this data.

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

CL can access a mounted volume ID with the CHKTAP command. The volume is returned in message ID CPC6778:<pre>
pgm

dcl &DEV *char 10 value( ‘TAP01′ )
dcl &VOLID *char 6

dcl &exitLoop *lgl value( ’0′ )

dcl &MSGID *char 7
dcl &MSGDTA *char 32
dcl &MSGDTALEN *dec ( 5 0 )

sndpgmmsg msgid( CPF9898 ) msgf( QSYS/QCPFMSG ) +
msgdta( ‘Checking for tape volume..’ ) +
msgtype( *STATUS )

chktap dev( &DEV ) endopt( *REWIND )

monmsg ( CPF0000 CPF9999 ) exec( do )
sndpgmmsg msgid( CPF0002 ) msgf( QSYS/QCPFMSG ) msgtype( *ESCAPE )
enddo

dountil ( &exitLoop )

rcvmsg msgtype( *LAST ) msgdta( &MSGDTA ) +
msgdtalen( &MSGDTALEN ) msgid( &MSGID )

monmsg ( CPF0000 CPF9999 ) exec( do )
chgvar &exitLoop ’1′
enddo

select

when ( &MSGID *eq CPC6778 ) do
chgvar &VOLID %sst( &MSGDTA 11 6 )
sndpgmmsg msgid( CPF9898 ) msgf( QSYS/QCPFMSG ) +
msgdta( +
‘Current tape in drive(‘ *cat +
&DEV *tcat ‘) is’ *bcat &VOLID +
) +
msgtype( *COMP )
chgvar &exitLoop ’1′
enddo

when ( &MSGID *eq ‘ ‘ ) do
chgvar &exitLoop ’1′
enddo

endselect

enddo

endpgm
</pre>The device (&DEV) can be passed in as a parm or retrieved from a data area or other sources. If the CHKTAP command doesn’t throw an error, then any messages it might have placed on the program message queue are received and checked. The message we look for is CPC6778.

If you look at the message description for CPC6778, you can see that the volume ID is returned in the message data beginning position 11. (Device is returned beginning in position 1.)

After &VOLID is extracted from the message data, you can do with it whatever you need.

In this code, any error from RCVMSG drops us out of the loop and ends the program. If the returned message ID is blank, we assume that we never found CPC6778 — some useful code should probably be inserted to handle that case. Whether the needed message is found or not, we eventually set the loop terminator on.

You can add as much as you need. Return the &VOLID as a parm or store it wherever needed.

Tom

Discuss This Question:  

 
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

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