View previous topic :: View next topic
|
Author |
Message |
javen777
New User
Joined: 06 Mar 2015 Posts: 31 Location: china
|
|
|
|
i have 2 parameters defined in a PL/I programe
One type is BIN FIXED(63)
the other one's type is CHAR(16)
may i know how to compare the value between them?
thanks |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10888 Location: italy
|
|
|
|
why not run a simple test program and see what happens? |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2141 Location: USA
|
|
|
|
javen777 wrote: |
i have 2 parameters defined in a PL/I programe
One type is BIN FIXED(63)
the other one's type is CHAR(16)
may i know how to compare the value between them?
thanks |
How do you imagine any comparison between those two values:
Code: |
'1010101010101010101010101010101010101010101010101010101010101010'B
and
'ABCDEFGHIJKLMNOP' |
What result do you expect??? |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1315 Location: Vilnius, Lithuania
|
|
|
|
Dumbass, why don't you RTFM:
Code: |
PICSPEC
The PICSPEC built-in function casts data from CHARACTER to PICTURE type.
>>- PICSPEC ( x , y ) -><
x Expression.
y Picture specification.
The expression x must be CHARACTER NONVARYING with a length known at compile time.
y must be a character literal that specifies a valid PICTURE with an external representation that has the same length as the first argument.
The result has the PICTURE type specified by the second argument.
Unlike the EDIT built-in function, no conversion is done and no checks are made to see if the first argument holds data valid for the picture.
Like the UNSPEC built-in function, only the "type" of the data is changed.
So, for example given PICSPEC(x,'(5)9'), x must be CHAR(5) (since while the picture specification '(5)9' was 4 characters in length, its external representation
requires 5 characters), but x will not be checked to see if it actually contains 5 numeric digits.
A statement of the N = N + PICSPEC(X,'(5)9') will not cause x to be converted from CHAR to PIC'(5)9', a conversion that would require a library call, but will cause the contents of x to be treated as if it were declared as PIC'(5)9'. |
And in general PL/I can compare anything with anything, the manual contains a section on how the various datatypes are converted to other ones.
And for what it's worth, a FIXED BIN(63) with a value of 1 will not compare equal (using PICSPEC) with a CHAR(16) containing '1' (whereas directly comparing them may tell you they are actually equal...) |
|
Back to top |
|
|
javen777
New User
Joined: 06 Mar 2015 Posts: 31 Location: china
|
|
|
|
prino wrote: |
Dumbass, why don't you RTFM:
Code: |
PICSPEC
The PICSPEC built-in function casts data from CHARACTER to PICTURE type.
>>- PICSPEC ( x , y ) -><
x Expression.
y Picture specification.
The expression x must be CHARACTER NONVARYING with a length known at compile time.
y must be a character literal that specifies a valid PICTURE with an external representation that has the same length as the first argument.
The result has the PICTURE type specified by the second argument.
Unlike the EDIT built-in function, no conversion is done and no checks are made to see if the first argument holds data valid for the picture.
Like the UNSPEC built-in function, only the "type" of the data is changed.
So, for example given PICSPEC(x,'(5)9'), x must be CHAR(5) (since while the picture specification '(5)9' was 4 characters in length, its external representation
requires 5 characters), but x will not be checked to see if it actually contains 5 numeric digits.
A statement of the N = N + PICSPEC(X,'(5)9') will not cause x to be converted from CHAR to PIC'(5)9', a conversion that would require a library call, but will cause the contents of x to be treated as if it were declared as PIC'(5)9'. |
And in general PL/I can compare anything with anything, the manual contains a section on how the various datatypes are converted to other ones.
And for what it's worth, a FIXED BIN(63) with a value of 1 will not compare equal (using PICSPEC) with a CHAR(16) containing '1' (whereas directly comparing them may tell you they are actually equal...) |
thanks, may i have the manual link plz ? i searched the knowledge center but didn't find anything related |
|
Back to top |
|
|
javen777
New User
Joined: 06 Mar 2015 Posts: 31 Location: china
|
|
|
|
sergeyken wrote: |
javen777 wrote: |
i have 2 parameters defined in a PL/I programe
One type is BIN FIXED(63)
the other one's type is CHAR(16)
may i know how to compare the value between them?
thanks |
How do you imagine any comparison between those two values:
Code: |
'1010101010101010101010101010101010101010101010101010101010101010'B
and
'ABCDEFGHIJKLMNOP' |
What result do you expect??? |
i know , that's why i posted here since i am a new bee. |
|
Back to top |
|
|
dneufarth
Active User
Joined: 27 Apr 2005 Posts: 420 Location: Inside the SPEW (Southwest Ohio, USA)
|
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
There are links to manuals at the top of every page of the forum. Also you can use Google to find the manual that you want . In this case a search for "pl/i language reference manual" would get you a link. You would also need the Programmers Guide. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2141 Location: USA
|
|
|
|
javen777 wrote: |
sergeyken wrote: |
How do you imagine any comparison between those two values:
Code: |
'1010101010101010101010101010101010101010101010101010101010101010'B
and
'ABCDEFGHIJKLMNOP' |
What result do you expect??? |
i know , that's why i posted here since i am a new bee. |
No one except yourself is able to guess: what are your intentions in planned "comparison" of two different entities?
1) PL/I does not allow straightforward comparison of incompatible datatypes (unlike let's say REXX, e.a.)
2) before comparison of incompatible entities they must be converted to compatible types, using either some of 100+ PL/I built-in functions, or a special one.
3) the required type of conversion depends exclusively on the semantics of your application. There are multiple options:
* convert both values to either binary, or hexadecimal strings, and compare them as string values;
* convert binary value to character (printable) string, and compare as string values; then: alignment, leading zeroes, decimal point, plus/minus characters, comma-separators etc. may affect the result of comparison;
* attempt to convert character string to corresponding binary value (if possible?); then compare two numeric values as whole numbers;
* 1000+ others, more sophisticated conversions;
You are the only person at this forum who can clarify these issues. |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1315 Location: Vilnius, Lithuania
|
|
|
|
sergeyken wrote: |
1) PL/I does not allow straightforward comparison of incompatible datatypes (unlike let's say REXX, e.a.) |
It does. You may get a lot of W-type messages about data conversions that will be done by subroutine calls, but as I mentioned before, the manuals (used to?) contain a pretty extensive section on what's converted to what and how! |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2141 Location: USA
|
|
|
|
prino wrote: |
sergeyken wrote: |
1) PL/I does not allow straightforward comparison of incompatible datatypes (unlike let's say REXX, e.a.) |
It does. You may get a lot of W-type messages about data conversions that will be done by subroutine calls, but as I mentioned before, the manuals (used to?) contain a pretty extensive section on what's converted to what and how! |
Default conversion and comparison between BINARY and CHARACTER, provided in PL/I, is useless in real life.
Especially when the author has no idea about his own intentions... |
|
Back to top |
|
|
|