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
 

 

PL/I builtin function DATETIME

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler
View previous topic :: :: View next topic  
Author Message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Wed Feb 08, 2012 11:43 pm    Post subject: PL/I builtin function DATETIME
Reply with quote

Hi,

I tried to use PL/I builtin function "DATETIME" to get year part alone but it shows some junk.

Code:

 PGMSAM01: PROC OPTIONS(MAIN) REORDER;
                                       
    DCL W_MY     PIC '9999';           
    W_MY = SUBSTR(W_MY,1,4);           
                                       
    PUT SKIP LIST('YEAR = ',W_MY);     
                                       
    END;                               


Please let me know where I am going wrong and how to get year part alone.

Thanks.
Back to top
View user's profile Send private message

Akatsukami

Global Moderator


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

PostPosted: Wed Feb 08, 2012 11:47 pm    Post subject: Re: PL/I builtin function DATETIME
Reply with quote

ramsri wrote:
Hi,

I tried to use PL/I builtin function "DATETIME" to get year part alone but it shows some junk.

Code:

 PGMSAM01: PROC OPTIONS(MAIN) REORDER;
                                       
    DCL W_MY     PIC '9999';           
    W_MY = SUBSTR(W_MY,1,4);           
                                       
    PUT SKIP LIST('YEAR = ',W_MY);     
                                       
    END;                               


Please let me know where I am going wrong and how to get year part alone.

Thanks.

Try invoking the DATETIME function icon_rolleyes.gif
Back to top
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Thu Feb 09, 2012 12:09 am    Post subject: Oops....sorry
Reply with quote

Hi,

Thanks........I tried this too but did not work either icon_sad.gif

Code:

 PGMSAM01: PROC OPTIONS(MAIN) REORDER;
                                       
    DCL W_MY     PIC '9999';           
    W_MY = SUBSTR(DATETIME,1,4);           
                                       
    PUT SKIP LIST('YEAR = ',W_MY);     
                                       
    END;       


Result:
Quote:

YEAR = 000000+0.0E


Please help.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10203
Location: italy

PostPosted: Thu Feb 09, 2012 12:25 am    Post subject: Reply to: PL/I builtin function DATETIME
Reply with quote

nowhere in Your code is present a proper invocation of the PL/I datetime function
did You ever hear about manual reading ? icon_evil.gif
start her to meditate on the PL/I manuals relevant for Your PL/I version
http://www-03.ibm.com/systems/z/os/zos/bkserv/zappls2.html

and here is a tested snippet

Code:
 ****** ***************************** Top of Data ******************************
 000001  zmf05:                                                                 
 000002      Proc Options(Main);                                               
 000003      dcl date   char(17);                                               
 000004      dcl year   char(4);                                               
 000005      put  skip list('ZMF05   Started');                                 
 000006      date = datetime();                                                 
 000007      year = substr(date,1,4)                                           
 000008      put  skip list('date =',date ); ;                                 
 000009      put  skip list('year =',year ); ;                                 
 000010      put  skip list('ZMF05   Ended');                                   
 000011      End  ;                                                             
 ****** **************************** Bottom of Data ****************************

to produce as per manual

Code:
********************************* TOP OF DATA **********************************
ZMF05   Started                                                                 
date =                  20120208205001481                                       
year =                  2012                                                   
ZMF05   Ended                                                                   
******************************** BOTTOM OF DATA ********************************
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


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

PostPosted: Thu Feb 09, 2012 12:27 am    Post subject: Re: Oops....sorry
Reply with quote

ramsri wrote:
Hi,

Thanks........I tried this too but did not work either icon_sad.gif

Code:

 PGMSAM01: PROC OPTIONS(MAIN) REORDER;
                                       
    DCL W_MY     PIC '9999';           
    W_MY = SUBSTR(DATETIME,1,4);           
                                       
    PUT SKIP LIST('YEAR = ',W_MY);     
                                       
    END;       

And you got RC=4 or RC=8 from the compile, depending if you had RULES(LAXDCL) or RULES(NOLAXDCL), didn't you?

A built-in function that is not declared BUILTIN must be invoked with an argument list -- even if that list is empty -- or the compiler interprets it as an AUTOMATIC variable. Look at the Attribute Table; I'll bet you see DATETIME as an implicitly-declared DEC FLOAT (6).

Try this:
Code:

 PGMSAM01: PROC OPTIONS(MAIN) REORDER;
                                       
    DCL W_MY     PIC '9999';           
    W_MY = SUBSTR(DATETIME(),1,4);           
                                       
    PUT SKIP LIST('YEAR = ',W_MY);     
                                       
    END;       
Back to top
View user's profile Send private message
prino

Active Member


Joined: 07 Feb 2009
Posts: 984
Location: Oostende, Belgium

PostPosted: Thu Feb 09, 2012 3:39 am    Post subject:
Reply with quote

Gentlemen,

Even is DATETIME is treated as a FLOAT(6) due to using "rules(laxdcl)", it is assigned to a PIC '9999' and the latter will never ever be printed in a float format using "put list'...

The OP has clearly not provided us with a true copy of the failing code. (Oh, what a surprise...)
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


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

PostPosted: Thu Feb 09, 2012 3:49 am    Post subject:
Reply with quote

prino wrote:
Gentlemen,

Even is DATETIME is treated as a FLOAT(6) due to using "rules(laxdcl)", it is assigned to a PIC '9999' and the latter will never ever be printed in a float format using "put list'...

The OP has clearly not provided us with a true copy of the failing code. (Oh, what a surprise...)

Oh, to be sure the TS is talking out of his nether orifice. However, between you and Dr. Sorichetti -- and I do myself the honor of suggesting that I may write a word worth reading now and again -- I believe that there is enough PL/I expertise on this board to point out how a sotfware engineer baked the dog and what he should have done instead, despite his best efforts to obfuscate the issue.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10203
Location: italy

PostPosted: Thu Feb 09, 2012 4:08 am    Post subject: Reply to: PL/I builtin function DATETIME
Reply with quote

just checked ( yep... curiosity killed the cat )

Code:
 ****** ***************************** Top of Data ******************************
 000001  zmf05:                                                                 
 000002      Proc Options(Main);                                               
 000003      dcl w_my   pic '9999' ;                                           
 000004      w_my = substr(datetime,1,4) ;                                     
 000005      put  skip list('w_my =',w_my ); ;                                 
 000006      End  ;                                                             
 ****** **************************** Bottom of Data ****************************


the results ( the interesting part at least )

Code:
...
       RULES(IBM BYNAME NODECSIZE EVENDEC ELSEIF GOTO NOLAXBIF NOLAXCTL         
             LAXDCL NOLAXDEF LAXIF LAXINOUT LAXLINK LAXMARGINS                 
             LAXPUNC LAXQUAL LAXSEMI LAXSTG NOLAXSTRZ MULTICLOSE UNREF)         
...
 Compiler Messages                                                             
 Message       Line.File Message Description                                   
 IBM1218I W       4.0    First argument to SUBSTR built-in should have string   
                         type.                                                 
 IBM1085I W       4.0    DATETIME may be uninitialized when used.               
 File Reference Table                                                           
   File    Included From  Name                                                 
      0                   ENRICO.TEST.PLI(ZMF05X)                               
 Component    Return Code    Messages (Total/Suppressed)    Time               
 Compiler         4                6  /  4                   1 secs             
 End of compilation of ZMF05                                                   
...
********************************* TOP OF DATA **********************************
w_my =                  0000                                                   
******************************** BOTTOM OF DATA ********************************


sometimes I wonder icon_cool.gif
Back to top
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Thu Feb 09, 2012 9:29 am    Post subject: Reply to: PL/I builtin function DATETIME
Reply with quote

Hi Akatsukami, thanks it worked and I got expected results.

Dr. Enrico, thanks for pointing me to some good PL/I stuff......I searched internet for hours but found nothing on DATETIME function icon_sad.gif

Thanks.
Back to top
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Thu Feb 09, 2012 9:33 am    Post subject: to continue
Reply with quote

Hi,

Code:

********************************* TOP OF DATA **********************************
YEAR =                  2012                                                   
******************************** BOTTOM OF DATA ********************************


May I know why value "2012" appears at far end than near "YEAR"? If I want to use this value against a year field in my embedded SQL in my PL/I program, can I use it?

Thanks.
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1715
Location: UK

PostPosted: Thu Feb 09, 2012 11:05 am    Post subject:
Reply with quote

You searched the internet for hours? Why? The information is in the language reference nanual for PL/1 -which is readily accessible from the links aty the top of each page in the forum. Suggest you look there (or the user guide) for the answer to why your date is TABbed over to the right.
Back to top
View user's profile Send private message
prino

Active Member


Joined: 07 Feb 2009
Posts: 984
Location: Oostende, Belgium

PostPosted: Thu Feb 09, 2012 3:13 pm    Post subject: Re: to continue
Reply with quote

ramsri wrote:

Code:

********************************* TOP OF DATA **********************************
YEAR =                  2012                                                   
******************************** BOTTOM OF DATA ********************************


May I know why value "2012" appears at far end than near "YEAR"?

RTFM (again!)
ramsri wrote:
If I want to use this value against a year field in my embedded SQL in my PL/I program, can I use it?
Why the flucking 'ell don't you try it?
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10203
Location: italy

PostPosted: Thu Feb 09, 2012 3:18 pm    Post subject: Reply to: PL/I builtin function DATETIME
Reply with quote

Quote:
If I want to use this value against a year field in my embedded SQL in my PL/I program, can I use it?

36_2_18.gif


output spacing in PUT statements is governed by the tab settings as described here
http://publib.boulder.ibm.com/infocenter/ratdevz/v7r5/index.jsp?topic=%2Fcom.ibm.ent.pl1.zos.doc%2Ftopics%2Fprtfi.htm
Back to top
View user's profile Send private message
Michael Jakob

New User


Joined: 13 Mar 2011
Posts: 17
Location: Switzerland

PostPosted: Sat Mar 10, 2012 3:22 am    Post subject: Specify directly the format of DATETIME
Reply with quote

You can specify the format of the result with DATETIME.

DCL YEAR CHAR(04);
DCL DATETIME BUILTIN;
YEAR = DATETIME('YYYY');

Either declare builtin functions or use parenthesis. WIth parenthesis DATETIME will be recognized as Builtin Function.

DCL PIC4 PIC'9999';
PIC4 = DATETIME('YYYY');
To convert character value directly to picture variable is not an recommendet programming style. It will produce an library call for conversion.
If you need the year as numeric value better specify
PIC4 = PICSPEC(DATETIME('YYYY'),'9999');
This should be done by inline conversion.

With kind regards

Michael
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 -> PL/I & Assembler All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Check System time(Minute) Using TIME1... balaji81_k DFSORT/ICETOOL 5 Fri Nov 11, 2016 10:53 am
No new posts Strange EXEC function call in z/VM Willy Jensen CLIST & REXX 3 Wed Oct 05, 2016 2:07 pm
No new posts Replace function abdulrafi COBOL Programming 13 Mon Sep 12, 2016 10:12 am
No new posts Which function does the Ampersand (&a... Andi1982 PL/I & Assembler 3 Wed Aug 24, 2016 2:05 pm


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