How do I store a array in universal variables?

Document ID : KB000055446
Last Modified Date : 14/02/2018
Show Technical Document Details

Below is a example of writing a array to the universal variable dataset.

//UNIVA1   PROC
//*   SET UID TO ID THIS WILL BE THE MEMBER NAME IN THE UNI. VAR.
//  SET UID = 'CYBRAR1'
//*   THIS WILL ALLOCATE THE UNI. DATASET(THIS MUST BE DONE IN PCL
//*   EVERY TIME.
//  ALLOC PCLUNIVR DSN='CYBRAR1.UNVER' DISP=SHR
//*   DEFINE THE UNIVERSAL VARIABLE THIS WILL CREATE THE MEMBER
//*   CYBRAR1 IN THE UNIVERSAL DATASET. THE VARIABLE CNT IS ALSO
//*   LOADED.
//  DEFINE UNIVERSAL.&UID(CNT)
//*   THE VALUE OF CNT IS CHECKED. IF IT'S NULL THEN THE MEMBER AND CNT
//*   ARE NEW (HAVE NOT BEEN SAVE BEFORE)
//  IF '&CNT' = ''
//    SET CNT = 0
//  ENDIF
//  SET CNT  = &CNT + 1
//*   THE ARRAY VARIABLES
//  DEFINE UNIVERSAL.&UID(DSN(&CNT),TYPE(&CNT))
//*   SET VARIABLES IN ARRAY
//  SET DSN(&CNT) = 'MY.DATASET1'
//  SET TYPE(&CNT) = 'JCL PROC'
//  FREE PCLUNIVR
//  EXIT 0

Below is a example of reading a array from the universal variable dataset.

//UNIVA2   PROC
//*   SET UID TO ID THIS WILL BE THE MEMBER NAME IN THE UNI. VAR.
//  SET UID = 'CYBRAR1'
//*   THIS WILL ALLOCATE THE UNI. DATASET(THIS MUST BE DONE IN PCL
//*   EVERY TIME.
//  ALLOC PCLUNIVR DSN='CYBRAR1.UNVER' DISP=SHR
//*   DEFINE THE UNIVERSAL VARIABLE THIS WILL CREATE THE MEMBER
//*   CYBRAR1 IN THE UNIVERSAL DATASET. THE VARIABLE CNT IS ALSO
//*   LOADED.
//  DEFINE UNIVERSAL.&UID(CNT)
//*   THE VALUE OF CNT IS CHECKED. IF IT'S NULL THEN THE MEMBER AND CNT
//*   ARE NEW (HAVE NOT BEEN SAVE BEFORE)
//  IF '&CNT' = ''
//    DISPLAY 'NO ARRAY VALUES FOR UID=&UID'
//  ENDIF
//  SET CNT2 = &CNT + 1
//*   DEFINE UNI. VAR. IN MEMBER CYBRAR1
//  DEFINE UNIVERSAL.&UID(DSN(&CNT2),TYPE(&CNT2))
//*   loop and display array
//  SET ICNT = 1
//  WHILE &ICNT <= &CNT DO
//    DISPLAY 'DSN: &DSN(&ICNT) TYPE: &TYPE(&ICNT)'
//    SET ICNT = &ICNT + 1
//  ENDWHILE
//  FREE PCLUNIVR
//  EXIT 0

This Frequently Asked Question applies to all supported releases of ESP Alchemist.