IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Create view statement from SYSIBM.SYSVIEWS


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
andrea

New User


Joined: 08 Jun 2012
Posts: 9
Location: Italia

PostPosted: Thu Aug 02, 2018 8:51 pm
Reply with quote

Hi all.
I have a similar need for views.

I need to extract the whole create view statement (with all where condition: both on join colums and in data) to recreate some views in a new environment.

Since STATEMENT column in SYSIBM.SYSVIEWS is a CLOB, I actually got a rough result with the following query:
SELECT NAME, CAST(STATEMENT AS VARCHAR (32000) )
FROM SYSIBM.SYSVIEWS
WHERE NAME = view_name

but that way I just obtain a very long row which has to be manually splitted.

Do you have some suggestion?

Thanks in advance.

P.S.: DB2 version is 11.1

EDIT : Topic split from ibmmainframes.com/viewtopic.php?t=32427 .
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Sun Aug 05, 2018 8:57 pm
Reply with quote

I have tried this:
Code:
//*---------------------------------------------------
//* LIST SYSVIEWS
//*---------------------------------------------------
//SELECT   EXEC PGM=SORT,PARM='DB2=DSN'                               
//SYSOUT   DD   SYSOUT=*                                               
//SORTDBIN DD   *                                                       
SELECT CAST( '*** ' || NAME AS CHAR(78) ),
       CAST( STATEMENT AS VARCHAR (32000) )
FROM SYSIBM.SYSVIEWS
WHERE NAME LIKE 'SYS%'
//SORTOUT  DD   DSN=&&VIEWS,DISP=(NEW,PASS),
//  SPACE=(TRK,(25,15),RLSE),DCB=(RECFM=FB,LRECL=32080)
//SYSIN    DD   *
  SORT FIELDS=COPY
//*---------------------------------------------------
//* REFORMAT VIEWS
//*---------------------------------------------------
//FORMAT   EXEC PGM=SYNCTOOL
//TOOLMSG  DD   SYSOUT=*
//SSMSG    DD   SYSOUT=*
//INPUT    DD   DISP=(OLD,DELETE),DSN=&&VIEWS
//OUTPUT   DD   SYSOUT=*
//TOOLIN   DD   *
  RESIZE FROM(INPUT) TO(OUTPUT) TOLEN(80) USING(CTL1)
//CTL1CNTL DD   *
  OUTFIL FNAMES=OUTPUT,
  OMIT=(1,5,CH,EQ,X'0000000000')

Notes:
  • Use any available utility at your site to fetch the rows.
  • NAME defined with a length of 78 so the length of the VARCHAR field becomes part of the 1st 80 characters.

When I ran this job, my output was:
Code:
*** SYSTABLES                                                                 .Ï
CREATE VIEW RUNSTATS.SYSTABLES AS SELECT * FROM SYSIBM.SYSTABLES WHERE CREATOR I
N(CURRENT SQLID,USER) WITH CHECK OPTION.........................................
*** SYSTABLESPACE                                                             ."
CREATE VIEW RUNSTATS.SYSTABLESPACE AS SELECT * FROM SYSIBM.SYSTABLESPACE WHERE C
REATOR IN(CURRENT SQLID,USER) WITH CHECK OPTION.................................
*** SYSTABSTATS                                                               .`
CREATE VIEW RUNSTATS.SYSTABSTATS AS SELECT * FROM SYSIBM.SYSTABSTATS WHERE OWNER
 IN(CURRENT SQLID,USER) WITH CHECK OPTION.......................................
*** SYSCHECKDEP                                                               .¢
CREATE VIEW SMTDB#IQ.SYSCHECKDEP AS ( SELECT * FROM SYSIBM . SYSCHECKDEP )......
*** SYSCHECKS                                                                 .ã
CREATE VIEW SMTDB#IQ.SYSCHECKS AS ( SELECT * FROM SYSIBM . SYSCHECKS )..........

Notes:
  • Lines starting with '***' contain the name of the view.
    To the right we can see the length of the VARCHAR. Should be no trouble removing it.
  • Other lines are the view definition. They are cut at a length of 80.
  • Last line is padded with low-values. Should be easy to replace with spaces.


Not perfect but it is a start...
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Mon Aug 06, 2018 6:13 pm
Reply with quote

I have replaced SORT by DSNTIAUL and got the same result (just in case you don't have SYNCSORT):
Code:
//*---------------------------------------------------
//* LIST SYSVIEWS
//*---------------------------------------------------
//SELECT2  EXEC DSNTIAUL,SYSTEM=DSN,SQLPARM=SQL
//SYSREC00 DD   DSN=&&VIEWS,DISP=(NEW,PASS),
//  SPACE=(TRK,(25,15),RLSE)
//SYSPUNCH DD   SYSOUT=*
//SYSIN    DD   *
SELECT CAST( '*** ' || NAME AS CHAR(78) ),
       CAST( STATEMENT AS VARCHAR (32000) )
FROM SYSIBM.SYSVIEWS
WHERE NAME LIKE 'SYS%';
//*---------------------------------------------------
//* REFORMAT VIEWS
//*---------------------------------------------------
//FORMAT   EXEC PGM=SYNCTOOL
//TOOLMSG  DD   SYSOUT=*
//SSMSG    DD   SYSOUT=*
//INPUT    DD   DISP=(OLD,DELETE),DSN=&&VIEWS
//OUTPUT   DD   SYSOUT=*
//TOOLIN   DD   *
  RESIZE FROM(INPUT) TO(OUTPUT) TOLEN(80) USING(CTL1)
//CTL1CNTL DD   *
  OUTFIL FNAMES=OUTPUT,
  OMIT=(1,5,CH,EQ,X'0000000000')
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Thu Aug 09, 2018 8:10 pm
Reply with quote

Did that help ?
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Thu Aug 09, 2018 10:30 pm
Reply with quote

Some people just get the data and vanish..

Marso,

Definitely you did a great job and that will be useful at least for me icon_smile.gif
Back to top
View user's profile Send private message
andrea

New User


Joined: 08 Jun 2012
Posts: 9
Location: Italia

PostPosted: Fri Aug 10, 2018 4:40 am
Reply with quote

Marso wrote:
Did that help ?

Sorry, I didn't saw your reply because I'm on holiday this week and I can't check your last suggestion for the next two weeks.

Anyway it seems to me that the last outcome of your job is the create view written as plain text and with new lines at the end of the 80 characters written in the TOLEN parameter, regardless of the content of the text.

In this case a better result can be obtained tuning the "EDIT" field in the FORM.MAIN of QMF.

In both cases (your suggestion as it seems to me and my QMF test) I have to manually split each line to get the original DDL (or something very similar to it).
And (I didn't wrote it) I need to do this work for many views.


What I need as outcome is something similar to:

CREATE VIEW MYPROJECT.VIEWTEST AS
SELECT A.col1,
a.col2,
a.col3,
b.col4,
.......
c.col5
FROM ( SELECT E.col1,
F.col2
G.col3
...
A.col5 FROM ( SELECT H.colx,
...
FROM MYPROJECT.TAB1 EE
, MYPROJECT.TAB2 FF
...
WHERE EE.key1 = FF.key2
AND
.....

(this is a little example from a 275 statement CREATE VIEW I got in QMF, with high use of "select from select", inner, outer and left joins) icon_confused.gif
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Thu Nov 22, 2018 10:31 am
Reply with quote

WOW Marso ... I just luv your solution...
Back to top
View user's profile Send private message
andrea

New User


Joined: 08 Jun 2012
Posts: 9
Location: Italia

PostPosted: Thu Nov 22, 2018 1:08 pm
Reply with quote

Thanks again for your suggestions, but I coundn't use them because I need an SQL-only solution: I need something I can insert into a QMF proc I use to retrieve the DDLs to recreate a DB on another DB2 instance when I don't have the original DDLs.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts How to create a list of SAR jobs with... CA Products 3
No new posts SET PATH in View DDL DB2 2
No new posts REXX code to expand copybook in a cob... CLIST & REXX 2
No new posts Issues with VIEW DATASET Command CLIST & REXX 2
No new posts Difference when accessing dataset in ... JCL & VSAM 7
Search our Forums:

Back to Top