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

PL/I builtin function DATETIME


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
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
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: 1788
Location: Bloomington, IL

PostPosted: Wed Feb 08, 2012 11:47 pm
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Feb 09, 2012 12:25 am
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
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: 1788
Location: Bloomington, IL

PostPosted: Thu Feb 09, 2012 12:27 am
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

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Thu Feb 09, 2012 3:39 am
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: 1788
Location: Bloomington, IL

PostPosted: Thu Feb 09, 2012 3:49 am
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Feb 09, 2012 4:08 am
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
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
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: 2455
Location: Hampshire, UK

PostPosted: Thu Feb 09, 2012 11:05 am
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

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Thu Feb 09, 2012 3:13 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Feb 09, 2012 3:18 pm
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts Calling an Open C library function in... CICS 1
No new posts DATE2 function SYNCSORT 15
No new posts Help on PL/I jsonPutValue function PL/I & Assembler 8
No new posts how to use Tso outtrap external function All Other Mainframe Topics 8
No new posts INSYNC option with same function as I... JCL & VSAM 0
Search our Forums:

Back to Top