SET PATH *LIBL ; 

CREATE OR REPLACE VARIABLE CISTOOLS.MAPICS_ENV 
	VARCHAR( 2)   
	DEFAULT  ( 
SELECT C . LIDES || C . FIDES 
FROM QGPL . MMLIST C 
JOIN TABLE ( 
SELECT LISTAGG ( DISTINCT ELEMENT ) AS MAPICS_LIBS 
FROM QGPL . MMLIST A , TABLE ( 
SYSTOOLS . SPLIT ( 
A . LBAMA || ',' || A . LBAMF , ',' ) 
) 
JOIN QSYS2 . LIBLIST 
ON QSYS2 . LIBLIST . SCHEMA_NAME = ELEMENT 
) 
ON MAPICS_LIBS = C . LBAMA || C . LBAMF )  ; 

GRANT ALTER , READ , WRITE   
ON VARIABLE CISTOOLS.MAPICS_ENV 
TO AMAPICS WITH GRANT OPTION ; 

GRANT READ , WRITE   
ON VARIABLE CISTOOLS.MAPICS_ENV 
TO PUBLIC ; 

