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: 67
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: 8569
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: 7310
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: 67
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: 7310
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 How to fill with zeroes pd intended s... DFSORT/ICETOOL 6
This topic is locked: you cannot edit posts or make replies. Suppressing only leading zeros (not s... DFSORT/ICETOOL 9
No new posts Map a data element to SPACES if it is 0 COBOL Programming 2
No new posts Converting spaces to zeroes DFSORT/ICETOOL 7
No new posts To remove the spaces using SORT Card DFSORT/ICETOOL 1
Search our Forums:

Back to Top