Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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: 42
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: 7990
Location: Bellevue, IA

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: 7306

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: 42
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: 7306

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 Count Trailing Spaces in variable str... Virendra Shambharkar SYNCSORT 10 Thu Feb 02, 2017 12:23 pm
No new posts To trim spaces in a pipe delimited da... Nish84 COBOL Programming 16 Mon Oct 10, 2016 1:54 pm
No new posts Removing Extra Spaces in a comma sepa... Puspojit DFSORT/ICETOOL 3 Tue Sep 13, 2016 7:46 am
No new posts Coverting PD to FS and also left just... Atul Banke DFSORT/ICETOOL 6 Wed Aug 24, 2016 4:31 pm
No new posts How do I right justify a string in an... rakesh17684 DB2 1 Wed Jun 08, 2016 8:01 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us