View previous topic :: View next topic
|
Author |
Message |
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
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 |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
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 |
|
Back to top |
|
|
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
Hi,
Thanks........I tried this too but did not work either
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
nowhere in Your code is present a proper invocation of the PL/I datetime function
did You ever hear about manual reading ?
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 |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
ramsri wrote: |
Hi,
Thanks........I tried this too but did not work either
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 |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
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 |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
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 |
|
Back to top |
|
|
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
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
Thanks. |
|
Back to top |
|
|
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
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 |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
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 |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
Back to top |
|
|
Michael Jakob
New User
Joined: 13 Mar 2011 Posts: 17 Location: Switzerland
|
|
|
|
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 |
|
|
|