View previous topic :: View next topic
|
Author |
Message |
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
Hi
I have a piece of code which looks like this:
Code: |
DCL CHAR_10 CHAR(10) INIT('') ;
DCL CHAR_04 CHAR(04) INIT('') ;
DCL DEC_07 FIXED DEC(7,3) BASED ADDR(CHAR_04) ;
DCL PIC_07 PIC'(4)9V.999' INIT(0) ;
IF SUBSTR(CHAR_10,1,4) ^= ' ' THEN
DO;
CHAR_04 = SUBSTR(CHAR_10,1,4) ;
PIC_07 = DEC_07 ;
END;
|
Value in CHAR_10 is coming from a input file which is in HEX format.
If there is any space in the CHAR_04, say '40400544' then I'm getting S0C7 else in other cases like '0144769C' it works fine.
Can you please suggest what I'm doing wrong here? |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1315 Location: Vilnius, Lithuania
|
|
|
|
Use the "VALID" builtin |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
All data is in hex format - it is how you interpret that hex format that gives data meaning. You are interpreting char data as numeric - it isn't. If you want leading blanks to be leading '00'x then you need to overlay them. |
|
Back to top |
|
|
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
Hi Nic,
That field is always suppose to have numeric data(of 7 figure with 3 decimal digits) or either spaces. But in some cases the field has partial spaces and partial numeric data. In case of '40400544', the field PIC_07 should get the value 0544.000 after ignoring the two leading spaces. |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1315 Location: Vilnius, Lithuania
|
|
|
|
If it contains partial this, partial that, how do you decide if 40400544 is 0544.000 and not 400.544?
You're working with Shambolic Hopeless Imbecile Trash. |
|
Back to top |
|
|
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
Prino,
I gotta be agree with u !!
thanks for enlightening me
f*** it |
|
Back to top |
|
|
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
I just realized..they are toying with me. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
I just realized..they are toying with me. |
Depends on who you consider as "they". . . Different people have different ways to "teach".
Quote: |
But in some cases the field has partial spaces and partial numeric data. In case of '40400544', the field PIC_07 should get the value 0544.000 after ignoring the two leading spaces. |
The "requirement" you mention is NOT something that is done.
How does it happen that you have a value that may or may not have a sign, and may or may not leading values to ignore (i.e. x'40')? How did such data get created?
Suggest you have much more to do than fix than the 0c7. . . |
|
Back to top |
|
|
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
well..I guess..first I need to understand the requirements clearly..they means my boss...gave me a file and ask to extract the price (the first four character of the variable in question)...just to teach me a lesson in PL\I. |
|
Back to top |
|
|
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
[rant]I think he did it intentionally...putting some junk values..just to annoy me..(there is only one record in the entire file!!!) that field is either supposed to have numeric values or all spaces..[\rant]
Sorry guys...to put you through this.. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Not a problem
Suggest you include a numeric test in the code and when the value is not numeric, print a message saying the record was rejected due to a non-numeric value.
If this is just for learning, i guess you'll need to bite the bullet and deal with it some way.
There is still the problem of knowing when a leading x'40' is to be discarded or part of the value to be retained. My first thought i if the field does not have a valid sign, the entire field is questionable (at best). |
|
Back to top |
|
|
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
It was only for learning purpose and I think i have learnt a things or two about data movements in Pl/I and I have started to like it :-)
Thanks everyone. |
|
Back to top |
|
|
|