View previous topic :: View next topic
|
Author |
Message |
Auryn
New User
Joined: 11 Jan 2006 Posts: 83 Location: Lower Saxony (DE)
|
|
|
|
Hello everybody,
when writing a log-file in case of errors I'd like to print some numeric values.
It's not a big thing to convert leading zeroes in spaces by using the PIC ZZZ9+ clause.
But I'd like to justify them left without the leading zeroes (or spaces after moveing PIC S9(9) to PIC ++++.+++.++9).
Is it possible to do this with just one command or function?
The INSPECT command is very mighty with several variants and options. But do I have to shift the bytes to the left until the first non-space character is found in first position?
Thank you all for your help |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
One COBOL statement? No.
Two COBOL statements? Yes:
Code: |
INSPECT <edited-numeric variable>
TALLYING <tally-variable>
FOR LEADING SPACES
MOVE <edited-numeric variable> (<tally-variable> + 1 : ) TO <output variable> |
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Code: |
UNSTRING <variable with leading spaces>
DELIMITED BY ALL SPACE
INTO <some field content not relevant, PIC X(1)>
<the field where we want left-justified value> |
|
|
Back to top |
|
|
Auryn
New User
Joined: 11 Jan 2006 Posts: 83 Location: Lower Saxony (DE)
|
|
|
|
Hi Robert, hi Bill,
thank you for your hints.
Sorry, but first try of Bill's hint did not work. Didn't do a second try.
But Robert's hint was helpful.
Btw, when suppressing leading spaces I tried something similar. But I computed and specified the remaining length as well.
Comparing the Assembler equivalent, Robert's hint is less Assembler commands. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
You didn't tyy too hard, then:
Code: |
01 AN-EDITED-NUMBER PIC +(15)9.
01 AN-ALPHA-NUM REDEFINES
AN-EDITED-NUMBER PIC X(16).
01 LEFT-JUST-NUMBER PIC X(16).
01 CONTENT-NOT-REQUIRED PIC X.
...
MOVE 12345 TO AN-EDITED-NUMBER
UNSTRING AN-ALPHA-NUM DELIMITED BY ALL SPACE
INTO CONTENT-NOT-REQUIRED
LEFT-JUST-NUMBER
DISPLAY
">"
LEFT-JUST-NUMBER
"<"
">"
AN-EDITED-NUMBER
"<"
GOBACK
. |
The UNSTRING will use a run-time routine, so you won't be able to count instructions.
A couple of things to note. For the UNSTRING, you need to ensure there is always at least one leading blan (so one more zero-suppress character than you need)k. For the INSPECT, you must set your tallying field to an initial value before the INSPECT.
Further, if you were worried about performance, you'd not do the MOVE to the edited field, you'd just find the first non-zero digit in the number, |
|
Back to top |
|
|
|