Page 2 of 2

Re: Access VSAM datasets from REXX

PostPosted: Wed Mar 16, 2011 5:19 pm
by kregen
Hi,
when i need a record for a given key, then i do the following..

/* Allocation --> you can do it by the job */
ADDRESS 'TSO'
"ALLOC FI(VSAMCLU) DA('VSAM-CLUSTER') SHR REUSE"

/* filling the key */
FKEY = string some data together

/* reading the record */
/* you must read the data in hex-format. you got in trouble when some non-printable characters in the record */
X=OUTTRAP('VRec.')
"PRINT INFILE(EB2VSAM) FROMKEY('" !! FKEY !! "')" !! ,
" TOKEY('" !! FKEY !! "') HEX"
X=OUTTRAP('off')

/* ey voila... the record(s) are in VRec, */
/* the records starting at VRec.2, when duplicates, the are more the 2 records available /*

Vr = x2c(VRec.v) /* converting the data to character */

/* reformatting to the fields */
FromRVS = STRIP(SUBSTR(Vr, 11, Length(VKey)), 'B', ' ')
SprKz = STRIP(SUBSTR(Vr, 55, 1), 'B', ' ')
TODataset = STRIP(SUBSTR(Vr, 56, 44), 'B', ' ')
TORVS = STRIP(SUBSTR(Vr, 100, 3), 'B', ' ')
TOMail = STRIP(SUBSTR(Vr, 103, 350), 'B', ' ')
CCMail = STRIP(SUBSTR(Vr, 453, 350), 'B', ' ')
TITLE = STRIP(SUBSTR(Vr, LENGTH(Vr) - 69), 'B', ' ')

/* free for dataset */
"FREE FI(INDD)"

so... no additional software is needing.

regards
kregen