Tuesday, December 29, 2009

LISTCAT command

To check if the PS file exists or not

You can check the existence of a file by LISTCAT cmd
//STEP005 EXEC PGM=IKJEFT01,DYNAMNBR=40,REGION=6144K
//ISPLOG DD DUMMY
//SYSTSPRT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSTSIN DD *
LISTCAT ENTRIES ('File name')
/*
//COND01 IF STEP005.RC=0 THEN
****steps to be executed when the flat file exists****
// ENDIF
The JCL step STEP005 returns 0 if the file exists and 4 if not.

*******************************************************************
To check the availability of GDG versions

LISTCAT NONVSAM GDG LEVEL ('GDG base name')

Tuesday, September 15, 2009

Sort JCL - to replace 1st 2 characters

JCL to replace 1st 2 characters of all the records with 'YY'
//STEP010 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DISP=SHR,DSN=Input file
//SORTOUT DD DISP=OLD,DSN=Output file
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
OUTREC FIELDS=(1:C'YY',3:3,319)

Note: LRECL of Input file is 321.

Tuesday, July 21, 2009

REXX: Parsing a stream with a delimiter

PARSE VAR DSNAM QF1'.' QF2'.' QF3'.' QF4'.' QF5
Where DSNAM is a string with delimiter say 'ABCDE.DHIAH.KKKAL.ASAL.VVVV'
The delimiter here is '.' It could be '/' '-' etc
O/p:
QF1='ABCDE'
QF2='DHIAH'
QF3='KKKAL'
QF4='ASAL'
QF5='VVVV'

Listing datasets - ISPF command

Initialises the list of datasets for a criterion:
"ISPEXEC LMDINIT LISTID(IDVAR) LEVEL("LEVELVAR")"
Where IDVAR is a variable to be used by the system to assign a name to the list initialised. LEVELVAR is a variable which holds the selection criteria. Ex: NFSK00.ABC*.KQLFR
Retrieve the list initialised:
"ISPEXEC LMDLIST LISTID("IDVAR") OPTION(LIST) DATASET(DSVAR)"
Where DSVAR is a variable which holds the current dataset in the list
After retrieving the ID variable IDVAR has to be freed:
"ISPEXEC LMDLIST LISTID("IDVAR") OPTION(FREE)"

If the ID variable is used so many times, say in a loop, it is advisable to initialise the variables IDVAR and DSVAR.
DROP IDVAR
DROP DSVAR

REXX builtin function - WORDPOS

Returns the word position in a given string
WORDPOS(srch-str, str-srched,)
where
srch-str -> String to be searched
Str-srched -> String in which srch-str is searched for
Start pos -> start of search. This is optional and by default it is 0 i.e beginning of str-srched
Example:
WORDPOS('dog', 'barking dogs seldom bite')
--returns 2
WORDPOS('tide', 'time waits for none')
--returns 0
WORDPOS('be', 'To be or not to be',3)
--returns 6 since the search starts at 3rd word 'or'