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

Spaces in between


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Sep 07, 2009 4:44 pm
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
Reply with quote

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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Wed Sep 09, 2009 12:38 am
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Wed Sep 09, 2009 6:45 pm
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
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

Moderator Emeritus


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

PostPosted: Sun Nov 15, 2009 10:48 pm
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Mon Nov 16, 2009 12:46 am
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 -

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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
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
No new posts To Remove spaces (which is in hex for... JCL & VSAM 10
No new posts How to remove spaces in between. SYNCSORT 12
No new posts File transfer from host with filler f... TSO/ISPF 15
Search our Forums:

Back to Top