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
 
Spaces in between

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

New User


Joined: 21 Apr 2007
Posts: 23
Location: Chennai

PostPosted: Mon Sep 07, 2009 4:25 pm    Post subject: Spaces in between
Reply with quote

Hi all

I have a requirement like this:

I have to validate a field ws-inp pic x(9) in the following way:
'abc def'- invalid
' abcedf' - valid
'abcdef ' - valid

In short i ve to see there is no spaces in mid.
Can you tell me how to do this cobol?
Back to top
View user's profile Send private message

enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10374
Location: italy

PostPosted: Mon Sep 07, 2009 4:44 pm    Post subject: Reply to: Spaces in between
Reply with quote

Loop thru the string using reference modification

no flags, just three loops in sequence

1st loop to skip leading blanks

2nd loop to skip non blanks

3rd loop to check that all the remaining chars are blanks

every loop starting index is the previous loop index at exit + 1

the housekeeping for the three loops has performance wise less impact
than using a single loop checking the flags needed to determine the string status ... ( two needed )
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Wed Sep 09, 2009 12:25 am    Post subject:
Reply with quote

WITHDRAWN BY SENDER. icon_rolleyes.gif
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10374
Location: italy

PostPosted: Wed Sep 09, 2009 12:38 am    Post subject: Reply to: Spaces in between
Reply with quote

Quote:
WITHDRAWN BY SENDER.

now You are making everybody curious icon_biggrin.gif
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Wed Sep 09, 2009 6:08 pm    Post subject:
Reply with quote

Here's another solution. It's tested and looks OK, but test around the edges to be sure.

I wouldn't say this is better than Enrico's solution, but I was curious about some of the restrictions in the use of CLASS and INSPECT (if any) and thought I'd give it a go.

For the curious; I thought i saw an error in the code, so I withdrew the earlier post.
Code:
    .                                                             
    .                                                             
    .                                                             
    .                                                             
ENVIRONMENT DIVISION.                                             
CONFIGURATION SECTION.                                             
SPECIAL-NAMES.                                                     
    CLASS HAS-NO-SPACES X'00' THRU X'3F' X'41' THRU X'FF'.         
    .                                                             
    .                                                             
    .                                                             
    .                                                             
****************************************************************   
WORKING-STORAGE SECTION.                                           
****************************************************************   
01  WS-WORK-AREAS.                                                 
    03  TST-FLD                 PIC  X(08).                       
    03  POS                     PIC S9(02) VALUE 0 COMP.           
    03  LEN                     PIC S9(02) VALUE 0 COMP.           
    .                                                             
    .                                                             
    .                                                             
    .                                                             
****************************************************************   
PROCEDURE    DIVISION.                                             
****************************************************************   
MAIN-LINE.                                                         
    MOVE '  234' TO TST-FLD                                       
    IF TST-FLD   =  SPACES                                         
       PERFORM INVALID-RTN                                         
    ELSE     
       PERFORM CALC-START-N-LEN
       PERFORM TEST-THE-FLD                                       
    END-IF                                                         
    STOP RUN                                                       
    .                 
CALC-START-N-LEN.                                               
    MOVE ZEROS   TO POS                                     
    MOVE ZEROS   TO LEN                                     
    INSPECT TST-FLD TALLYING POS FOR LEADING SPACES         
    ADD POS      TO LEN                                     
    INSPECT FUNCTION REVERSE (TST-FLD)                       
            TALLYING LEN FOR LEADING SPACES                 
    COMPUTE LEN = LENGTH OF TST-FLD - LEN                   
    ADD +1       TO POS 
    . 
TEST-THE-FLD.                                   
    DISPLAY 'TST-FLD >'  TST-FLD(POS:LEN) '< '               
    IF TST-FLD(POS:LEN) HAS-NO-SPACES                       
       PERFORM INVALID-RTN                                   
    ELSE                                                     
       PERFORM VALID-RTN                                     
    END-IF                                                   
    .                                                       
VALID-RTN.                                                   
    DISPLAY 'FLD IS VALID'                                   
    .                                                       
INVALID-RTN.                                                 
    DISPLAY 'FLD IS INVALID'                                 
    .                                                                                                                                           
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10374
Location: italy

PostPosted: Wed Sep 09, 2009 6:45 pm    Post subject: Reply to: Spaces in between
Reply with quote

Quote:
I wouldn't say this is better than Enrico's solution


Hi Jack!
imagine how I could be worried about it icon_biggrin.gif
I do not speak cobolese, and I was just hinting a quick and dirty logic, not the real coding

/pure speculation on
in rexx I would have done somwhere along ..
Code:
if strip(string) = word(strip(string),1) then ... ok
                                    else ... error

in plain words
if the whole string is equal to the first blank delimited string then there are no interspersed blanks
/pure speculation of
Back to top
View user's profile Send private message
rehan

New User


Joined: 13 May 2007
Posts: 6
Location: India

PostPosted: Sun Nov 15, 2009 7:50 pm    Post subject: Re: Spaces in between
Reply with quote

U can use inspect statement to find spaces if u wanna throw error use inspect tally
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sun Nov 15, 2009 10:48 pm    Post subject:
Reply with quote

Hello,

How does a simple inspect/tally determine if there are any embedded spaces (which are invalid) rather than leading or trailing spaces (which are valid)?

This is not a kiddie chat room, so please do not use kiddie chat slang icon_sad.gif
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2504
Location: Atlanta, Georgia, USA

PostPosted: Mon Nov 16, 2009 12:46 am    Post subject: Reply to: Spaces in between
Reply with quote

Although the following post removes all specified unwanted characters from a given string, it may be helpful for future reference, perhaps some of the code is adaptable to your request -

http://ibmmainframes.com/viewtopic.php?p=143786&highlight=#143786

Bill
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 Remove leading spaces from numeric field rexx77 SYNCSORT 6 Wed Sep 06, 2017 2:15 am
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 Remove intermediate spaces Pallavi Vishwanath SYNCSORT 1 Fri Jan 15, 2016 2:45 am

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