Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Cut leading spaces or others and justify left

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Auryn

New User


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

PostPosted: Fri Oct 25, 2013 7:23 pm    Post subject: Cut leading spaces or others and justify left
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: 8201
Location: Dubuque, Iowa, USA

PostPosted: Fri Oct 25, 2013 7:40 pm    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7314

PostPosted: Fri Oct 25, 2013 8:51 pm    Post subject: Reply to: Cut leading spaces or others and justify left
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: 45
Location: Lower Saxony (DE)

PostPosted: Mon Oct 28, 2013 5:20 pm    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7314

PostPosted: Mon Oct 28, 2013 6:13 pm    Post subject: Reply to: Cut leading spaces or others and justify left
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Inefficient BUILD - VB records paddin... Daniel Prosser SYNCSORT 6 Thu Dec 14, 2017 3:52 pm
No new posts Squeeze record left so that zeroes ar... Vignesh Sid SYNCSORT 5 Fri Nov 10, 2017 1:40 pm
No new posts Remove leading spaces from numeric field rexx77 SYNCSORT 6 Wed Sep 06, 2017 2:15 am
No new posts Format record to remove Leading zeroes Learncoholic DFSORT/ICETOOL 14 Wed Apr 05, 2017 2:43 pm
No new posts Count Trailing Spaces in variable str... Virendra Shambharkar SYNCSORT 10 Thu Feb 02, 2017 12:23 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us