Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Date conversion in unload of data from DB2 to flat file

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
rajendraa

New User


Joined: 22 Dec 2006
Posts: 7
Location: Bangalore

PostPosted: Thu May 12, 2011 8:04 pm    Post subject: Date conversion in unload of data from DB2 to flat file
Reply with quote

Hi,

I have a requirement to unload data from DB2 table to flat file using batch db2 unload utility

The file length is 50 bytes

Following are the columns that I will be downloading

Code:
Column Name:   Office_code   Start_Date
-------------------------------------------
Declaration:   CHAR(3)      DATE
-------------------------------------------
row1        :   USA      2010-05-30
row2        :   IND      2010-07-17


Data should be as follows in the flat file.
Code:
Office_code     PIC X(03)
Filler          PIC X(27) VALUE SPACES
Date            PIC X(08) (Format of YYYYMMDD)
Filler          PIC X(12)  VALUES SPAVES

Code:
----+----1----+----2----+----3----+----4----+----5
***************************** Top of Data ********
USA                          20100530             
IND                          20100717           



SELECT office_code
,CHAR(SPACE(27))
,start_date
,CHAR(space(12))
FROM TABLE1


Can someone help me how to convert date from YYYY-MM-DD format to YYYYMMDD format while downloading from DB2 to flat file?

Thank you
Back to top
View user's profile Send private message

haimzeevi

New User


Joined: 01 Mar 2010
Posts: 27
Location: Israel

PostPosted: Thu May 12, 2011 8:26 pm    Post subject: Reply to: Date conversion in unload of data from DB2 to flat
Reply with quote

Hi,
Just add a SORT step, SYNCSORT or DFSORT, according your site, then use OUTREC statement to re-format the date-fields.
Works, fast & efficient.
If you have SYNCSORT, you can issue a direct SELECT from DB2, then use OUTREC to format the date-fields.
Haim Zeevi
Back to top
View user's profile Send private message
rajendraa

New User


Joined: 22 Dec 2006
Posts: 7
Location: Bangalore

PostPosted: Thu May 12, 2011 8:37 pm    Post subject: Reply to: Date conversion in unload of data from DB2 to flat
Reply with quote

Thanks haimzeevi

I wanted to avoid sort step if the date conversion can be handeled in the unload query itself.

We can use replace and trim options in the unload select statement, but wanted to check if there is any better of doing this.
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Thu May 12, 2011 8:48 pm    Post subject:
Reply with quote

If a local date format that suits your needs hasn't been implemented at your installation, I would suggest you look into selecting YYYY, MM, and DD separately with suitable date functions.
Back to top
View user's profile Send private message
rajendraa

New User


Joined: 22 Dec 2006
Posts: 7
Location: Bangalore

PostPosted: Thu May 12, 2011 11:28 pm    Post subject: Reply to: Date conversion in unload of data from DB2 to flat
Reply with quote

Thanks Kjeld.

I tried as per your suggestion, but the zeros is getting replaced with spaces

Below is the query that was used

Select
CAST(YEAR(START_DATE) AS CHAR(4))
CAST(MONTH(START_DATE) AS CHAR(2))
CAST(DAY(START_DATE) AS CHAR(2))
from TABLE1

Value in DB2 table is 2010-05-30

Value in flat files after unload 2010 530

But I am looking for data as 20100530 in the flat file.

For month I am getting ' 5' instead of '05'. Is there a way to handle this.

Please advice.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1771
Location: Bloomington, IL

PostPosted: Fri May 13, 2011 12:07 am    Post subject: Re: Reply to: Date conversion in unload of data from DB2 to
Reply with quote

rajendraa wrote:
I tried as per your suggestion, but the zeros is getting replaced with spaces

Below is the query that was used

Select
CAST(YEAR(START_DATE) AS CHAR(4))
CAST(MONTH(START_DATE) AS CHAR(2))
CAST(DAY(START_DATE) AS CHAR(2))
from TABLE1

Value in DB2 table is 2010-05-30

Value in flat files after unload 2010 530

But I am looking for data as 20100530 in the flat file.

For month I am getting ' 5' instead of '05'. Is there a way to handle this.

Please advice.

Yes.














OK, I'll take pity on one of such limited ability: use the SQL TRANSLATE function. In fact, since you're evidently incapable of using Google, I'll even provide the link for you.
Back to top
View user's profile Send private message
rajendraa

New User


Joined: 22 Dec 2006
Posts: 7
Location: Bangalore

PostPosted: Fri May 13, 2011 1:33 am    Post subject: Reply to: Date conversion in unload of data from DB2 to flat
Reply with quote

I used the below query and it solved my problem. Thanks all.
Select
SUBSTR(CHAR(START_DATE),1,4)
SUBSTR(CHAR(START_DATE),6,2)
SUBSTR(CHAR(START_DATE),9,2)
from TABLE1
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Fri May 13, 2011 12:07 pm    Post subject:
Reply with quote

two other ways to accomplish the same:
Code:
,char(varchar_format(timestamp(current date,'00.00.00'),'YYYYMMDD'),8)
,decimal(year(current date)*10000+month(current date)*100+day(current date),8,0)
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Split file based on comparsion to 2 f... Div Grad DFSORT/ICETOOL 3 Thu Jul 27, 2017 9:16 pm
No new posts Paasing symbolic parameter to instrea... Robert Sample JCL & VSAM 2 Thu Jul 27, 2017 1:22 pm
No new posts Passing data from REXX to C programme... chong.zhou CLIST & REXX 3 Wed Jul 26, 2017 9:11 pm
No new posts Extra character appears in file when ... Balu5491 All Other Mainframe Topics 1 Wed Jul 26, 2017 2:39 pm
No new posts SSH - known_hosts file configuration vasanthz All Other Mainframe Topics 2 Wed Jul 26, 2017 2:10 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us