Variable part in a JCL variable name



JES, JES2, JCL utilities, IDCAMS, Compile & Run JCLs, PROCs etc...

Variable part in a JCL variable name

Postby RalphEagle » Wed Jun 16, 2021 3:01 pm

Hi,

I am defining variable names inside a JCL, such as:
//V1   SET SELO='WORK.JOHN.SHEET'
//V2   SET SELRFMT='WORK.JOHN.OUTPUT.CODE'


I would like to introduce a variable part in these, so that the name JOHN above can be customized as well:
//V0   SET NAME='MARY'
//V1   SET SELO='WORK.&NAME..SHEET'
//V2   SET SELRFMT='WORK.&NAME..OUTPUT.CODE'


I get an error from improper use of ampersand in the DSN field, I suppose because double substitution is not recognized?
6 IEFC627I INCORRECT USE OF AMPERSAND IN THE DSN FIELD


Is there a way to do this?

Thank you,
RalphEagle
 
Posts: 24
Joined: Mon Apr 23, 2018 2:51 pm
Has thanked: 17 times
Been thanked: 0 time

Re: Variable part in a JCL variable name

Postby sergeyken » Wed Jun 16, 2021 5:08 pm

Do not use quotes when combining new value including other SET-variables.
This way you’ll be on safe side.
//V0   SET NAME='MARY'
//V1   SET SELO=WORK.&NAME..SHEET
//V2   SET SELRFMT=WORK.&NAME..OUTPUT.CODE
Javas and Pythons come and go, but JCL and SORT stay forever.

These users thanked the author sergeyken for the post:
RalphEagle (Wed Jun 16, 2021 5:48 pm)
User avatar
sergeyken
 
Posts: 408
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 6 times
Been thanked: 40 times

Re: Variable part in a JCL variable name

Postby willy jensen » Wed Jun 16, 2021 5:34 pm

Actually, don't use quotes unless absolutely necessary
//V0   SET NAME=MARY                        
//V1   SET SELO=WORK.&NAME..SHEET          
//V2   SET SELRFMT=WORK.&NAME..OUTPUT.CODE

These users thanked the author willy jensen for the post:
RalphEagle (Wed Jun 16, 2021 5:48 pm)
willy jensen
 
Posts: 455
Joined: Thu Mar 10, 2016 5:03 pm
Has thanked: 0 time
Been thanked: 69 times

Re: Variable part in a JCL variable name

Postby RalphEagle » Wed Jun 16, 2021 5:49 pm

Thanks, it worked like a charm!
RalphEagle
 
Posts: 24
Joined: Mon Apr 23, 2018 2:51 pm
Has thanked: 17 times
Been thanked: 0 time

Re: Variable part in a JCL variable name

Postby sergeyken » Wed Jun 16, 2021 6:05 pm

The problem with quotes, and parameters has been created by IBM itself, long time ago.

Parameters are substituted within quotes in PARM field:
// EXEC PGM=xxxx,PARM=‘&START,&END’ - this works fine


The same parameters are NOT substituted in most of other situations with quotes:
// SET ALLPARM=‘&START,&END’     - ampersands are not resolved
// EXEC PGM=xxxx,PARM=‘&ALLPARM’ - this does not work
// EXEC PGM=yyyy,PARM=&ALLPARM   - this does not work as well


We need to blame IBM for this mess they have created!
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 408
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 6 times
Been thanked: 40 times

Re: Variable part in a JCL variable name

Postby sergeyken » Wed Jun 16, 2021 6:23 pm

But there is one secret trick
// SET QUOTE=’’’’
// SET COMMA=’,’
// SET ALLPARM=&QUOTE&START&COMMA&END&QUOTE
// EXEC PGM=yyyy,PARM=&ALLPARM   - this works! But is ugly…
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 408
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 6 times
Been thanked: 40 times


Return to JCL

 


  • Related topics
    Replies
    Views
    Last post