MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Update using DSNUTILB

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
Rama_Prayaga
Beginner


Joined: 20 May 2003
Posts: 45
Topics: 15

PostPosted: Fri Dec 10, 2004 4:07 am    Post subject: Update using DSNUTILB Reply with quote

Hi,

Can Updation of existing Data possible with DSNUTILB,


I have the following request which has to be perform.


1)I have load a table.


If the Row already exists in the table
then
Update the Row
else
insert the Row.

end.

Request your help on this.I want to do this using DSNUTILB
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Fri Dec 10, 2004 5:14 am    Post subject: Reply with quote

Rama_Prayaga,

Yes you can use DSNUTILB to update and insert rows into the table. The easiest way to solve your problem is to delete off the existing rows for the keys you want to update and perform a LOAD RESUME. This will insert all the rows as new rows.

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Rama_Prayaga
Beginner


Joined: 20 May 2003
Posts: 45
Topics: 15

PostPosted: Fri Dec 10, 2004 5:39 am    Post subject: Reply with quote

Hi Kolusu,

Then I have to write a program to check that and delete it.Also there could be some data which will is is not present in the file and present in the table.If i do load resume it will delete the existing data in the table.

Is there any other way without writing a program.
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Fri Dec 10, 2004 8:32 am    Post subject: Reply with quote

Rama_Prayaga,

You don't need a program to delete the data from the table. How do you get the data to be updated or inserted? How do you generate the file to be used as input to DSNUTILB? Let me know the details and then we will show you the way to do it.

Quote:

If i do load resume it will delete the existing data in the table.


Load RESUME does not delete the existing data in the table.

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Rama_Prayaga
Beginner


Joined: 20 May 2003
Posts: 45
Topics: 15

PostPosted: Mon Dec 13, 2004 9:35 am    Post subject: Reply with quote

Hi Kolusu,

Thanks for your reply.I will explain my requirement.The requirement is that I am getting Some data in files.


The files will be my input,

I have extract the data from the file and load it into the table.

The above is the requirement.


What I need to do is the following


DB2 Table existing data

Code:
primary key      Name     Address

11111            rama      india
22222            krishna   india
33333            chirsto   india     
44444            pinto     USA
55555            robert    usa 



I am writing a program to create a load file.

The output will be somewhat Like this

LOad File which will be created by my Program

Code:
primary key      Name     Address
33333            chirsto   germany    
44444            pinto     India
55555            robin     USA
66666            NEWONE    INDIA
77777            ranjit    india


The result in the DB2 Table after the JOb should be

Code:
primary key      Name     Address

11111            rama      india
22222            krishna   india
33333            chirsto   germany    
44444            pinto     India
55555            robin      USA
66666            NEWONE    INDIA
77777            ranjit    india


Can DSNUTILB perform this.
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Mon Dec 13, 2004 10:18 am    Post subject: Reply with quote

Quote:
The files will be my input, I have extract the data from the file and load it into the table.


Rama_Prayaga,

I assmuing that your input file has the following layout.LRECL=80,RECFM=FB

Code:

PRIMARY-KEY    PIC X(05).
FILLER         PIC X(75).


we first will generate the delete statements for all the records in the file. Since we are deleting records we need a commit after every 500 records. The following fileaid steps will create the DELETE control cards for all the records in your file.

Rama
Code:

//************************************************************
//* THE FIRST STEP WILL PUT AN "X" IN POSITION 80 OF THE     *
//* INPUT FILE OF 500TH RECORD.                              *
//************************************************************
//STEP0100 EXEC PGM=FILEAID,REGION=4M                         
//SYSPRINT DD  SYSOUT=*                                       
//SYSLIST  DD  SYSOUT=*                                       
//SYSTOTAL DD  SYSOUT=*                                       
//SYSUDUMP DD  SYSOUT=*                                       
//DD01     DD  DSN=YOUR INPUT FILE,                             
//             DISP=SHR                                       
//SYSIN    DD  *                                             
$$DD01 UPDATE SELECT=500,R=(80,C'X'),OUT=0                     
/*                                       
//************************************************************
//* THE SECOND STEP WILL WRITE OUT EVERY RECORD AND          *
//* IF AN "X" IS FOUND IN POSITION 80, A NEW RECORD WITH     *
//* COMMIT WILL BE WRITTEN AFTER EVERY 500TH RECORD.         *
//************************************************************
//STEP0300 EXEC PGM=FILEAID,REGION=4M                         
//SYSPRINT DD  SYSOUT=*                                       
//SYSLIST  DD  SYSOUT=*                                       
//SYSTOTAL DD  SYSOUT=*                                       
//SYSUDUMP DD  SYSOUT=*                                       
//DD01     DD  DSN=YOUR INPUT FILE,
//             DISP=SHR                                       
//SQLCARDS DD  DSN=YOUR OUTPUT SQL DEL STATEMENT FILE,
//             DISP=(NEW,CATLG,DELETE),                       
//             UNIT=SYSDA,                                     
//             SPACE=(CYL,(15,5),RLSE)                       
//SYSIN    DD  *                                                       
$$DD01 USER IF=(80,NE,C'X'),                       
            MOVE=(1,80C' '),                       
            MOVE=(1,C'DELETE FROM TABLE'),         
            WRITE=SQLCARDS,                       
            MOVE=(1,80C' '),                       
            MOVE=(1,C' WHERE PRIMARY KEY = '),     
            MOVE=(+0,C"'"),                       
            MOVE=(+0,5,1),                         
            MOVE=(+0,C"'"),                       
            WRITE=SQLCARDS,                       
            MOVE=(1,80C' '),                       
            MOVE=(1,C';'),                         
            WRITE=SQLCARDS,                       
            IF=(80,EQ,C'X'),                       
            MOVE=(1,C'DELETE FROM TABLE'),         
            WRITE=SQLCARDS,                       
            MOVE=(1,80C' '),                       
            MOVE=(1,C' WHERE PRIMARY KEY = '),     
            MOVE=(+0,C"'"),                       
            MOVE=(+0,5,1),                         
            MOVE=(+0,C"'"),                       
            WRITE=SQLCARDS,                       
            MOVE=(1,80C' '),                       
            MOVE=(1,C';'),                         
            WRITE=SQLCARDS,                       
            MOVE=(1,80C' '),                       
            MOVE=(1,C'COMMIT;'),                   
            WRITE=SQLCARDS                         
/*                                                 


Once these delete cards are created all you need to do is run them with DSNTIAUL

Code:

//STEP0100 EXEC PGM=IKJEFT01,DYNAMNBR=20 
//SYSTSPRT DD SYSOUT=*,DCB=BLKSIZE=121   
//SYSPRINT DD SYSOUT=*                   
//SYSTSOUT DD SYSOUT=*                   
//SYSTSIN  DD *                           
 DSN SYSTEM(xxxx)                         
 RUN  PROGRAM(DSNTIAUL) -                 
      PLAN(DSNTIAUL)    -                 
      PARMS('SQL')      -                 
      LIB('DB2P.RUNLIB.LOAD')             
//SYSREC00 DD DUMMY                       
//SYSPUNCH DD DUMMY                       
//SYSIN    DD DSN=YOUR OUTPUT SQL DEL STATEMENT FILE,
//            DISP=SHR
/*


once you deleted the rows which you want to update , you can now load the records with load RESUME to achieve the desired results.

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Rama_Prayaga
Beginner


Joined: 20 May 2003
Posts: 45
Topics: 15

PostPosted: Wed Dec 15, 2004 6:37 am    Post subject: Reply with quote

Hi Kolusu,

Thanks for your help.I got it. Razz

Regards,
Rama Prayaga
Back to top
View user's profile Send private message Yahoo Messenger
videlord
Beginner


Joined: 09 Dec 2004
Posts: 147
Topics: 19

PostPosted: Mon Jan 03, 2005 10:02 pm    Post subject: Reply with quote

interesting.

I have one more question:
If I want to update some field of existing record, not delete the old one and insert the new one, How to do?
Unload the table and using SORT to generate the Load input?

Thanks
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Tue Jan 04, 2005 1:51 am    Post subject: Reply with quote

videlord,

Check this topic which explains about updating the table.

http://www.mvsforums.com/helpboards/viewtopic.php?t=2787&highlight=fileaid+unload

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group