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

Cut leading spaces or others and justify left


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Auryn

New User


Joined: 11 Jan 2006
Posts: 83
Location: Lower Saxony (DE)

PostPosted: Fri Oct 25, 2013 7:23 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Oct 25, 2013 7:40 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Oct 25, 2013 8:51 pm
Reply with quote

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
View user's profile Send private message
Auryn

New User


Joined: 11 Jan 2006
Posts: 83
Location: Lower Saxony (DE)

PostPosted: Mon Oct 28, 2013 5:20 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Oct 28, 2013 6:13 pm
Reply with quote

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
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Shift left VB record without x00 endi... DFSORT/ICETOOL 11
No new posts Keep leading zero(s) after convert fl... SYNCSORT 7
No new posts Remove leading zeroes SYNCSORT 4
No new posts leading spaces can be removed in trai... DFSORT/ICETOOL 1
No new posts Cobol program with sequence number ra... COBOL Programming 5
Search our Forums:

Back to Top