zOs/SQL/CATALIAS

with alias as
(
  select a.*,
       case when a.location <> '' then 'remote'
            when t.name is null then  'missing' else 'existing' end sta
    from sysibm.systables a
         left join sysibm.systables t
         on a.tbCreator = t.creator and a.tbName = t.name
    where a.type = 'A'
           and   a.name like '_PT%'
)
select 'create alias '
       || strip(a.creator) || '.' || strip(a.name)
       || ' for ' || case when a.location = '' then ''
                     else  strip(a.location) || '.' end
       || strip(a.tbCreator) || '.' ||strip(a.tbname) || ';'
       || ' -- ' || sta
    from alias a
union select 'drop alias '
       || strip(a.creator) || '.' || strip(a.name) || ';'
       || ' -- ' || sta
    from alias a
;