Quick off my head.
run idcams list on the high level of the dataset name, example DSN=FIRST.SECOND.THIRD.FOURTH ,
then just use FIRST.SECOND.THIRD and don''t put the last level of the dataset name on the idcam statment card. THEN look in the SYSPRINT dd output file and parse for the work CREATION.
The output will have every dataset name with those high level prefixes, so you will have to first search for the specific dataset in the ouput, then the word CREATION
code below:
000004 //STEP00B EXEC PGM=IDCAMS
000005 //SYSUT2 DD SYSOUT=*
000006 //SYSPRINT DD DSN=FIRST.IDCAMLST.OUTPUT,
000007 // DISP=(,CATLG,DELETE),
000008 // UNIT=DISK,
000009 // SPACE=(CYL,(25,25),RLSE)
000010 //SYSIN DD *
000011 LISTCAT -
000012 LVL(FIRST.SECOND.THIRD) ALL
000013 /*
000014 //