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

Validating COBOL program for space Free


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
rajivtechno

New User


Joined: 05 Apr 2005
Posts: 17
Location: Bangalore

PostPosted: Thu Sep 21, 2006 5:27 pm
Reply with quote

i need to validate fields in a cics cobol programe...

Extraneous spaces are not allowed

Extraneous Spaces will be defined as

 Any spaces at the beginning of a field before the first non-space character
 More than one space in between any two non-space characters within a field

input data need to be parsed and extraneous spaces removed. ..
i e in fields like name , address etc... if any extraneous space is there then it should be parsed
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Thu Sep 21, 2006 7:22 pm
Reply with quote

Hi !

You could use INSPECT and STRING to do this validation.

Regards, UmeySan
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Fri Sep 22, 2006 12:42 am
Reply with quote

rajivtechno,

here is a solution you can probably adapt.

Code:

WORKING-STORAGE SECTION.                                         
                                                                 
01  VAR1                        PIC X(40)      VALUE             
    '  NOW IS  THE   TIME FOR ALL  GOOD MEN T'.                 
01  WS-LEN                      PIC S9(5)      COMP-3 VALUE 0.   
01  WS-SUB-1                    PIC S9(5)      COMP-3 VALUE 0.   
01  WS-SUB-2                    PIC S9(5)      COMP-3 VALUE 0.   
01  WS-SPACE-CNT                PIC S9(5)      COMP-3 VALUE 0.   
                                                                 
LINKAGE SECTION.                                                 
                                                                 
PROCEDURE DIVISION.                                             
                                                                 
PROGRAM-START.                                                   
                                                                 
    MOVE LENGTH OF VAR1         TO WS-LEN.                       
                                                                 
    DISPLAY 'VAR1 >' VAR1 '<'.                                   
                                                                 
    MOVE +1                     TO WS-SPACE-CNT.                   

    PERFORM                                                         
      VARYING WS-SUB-1 FROM 1 BY 1                                 
      UNTIL WS-SUB-1 > WS-LEN                                       
        IF VAR1(WS-SUB-1:1) = ' '                                   
        THEN                                                       
            IF WS-SPACE-CNT > 0                                     
            THEN                                                   
                CONTINUE                                           
            ELSE                                                   
                ADD +1          TO WS-SUB-2                         
                MOVE ' '        TO VAR1(WS-SUB-2:1)                 
                ADD +1          TO WS-SPACE-CNT                     
            END-IF                                                 
        ELSE                                                       
            ADD +1              TO WS-SUB-2                         
            MOVE VAR1(WS-SUB-1:1)                                   
                                TO VAR1(WS-SUB-2:1)                 
            MOVE +0             TO WS-SPACE-CNT             
        END-IF                                               
    END-PERFORM.                                             
                                                             
    ADD +1                      TO WS-SUB-2                 
    IF WS-SUB-2 <= WS-LEN                                   
    THEN                                                     
        COMPUTE WS-LEN = WS-LEN - WS-SUB-2 + 1               
        MOVE ' '                TO VAR1(WS-SUB-2:WS-LEN)     
    END-IF.                                                 
                                                             
    DISPLAY 'VAR1 >' VAR1 '<'.                               


Code:

VAR1 >  NOW IS  THE   TIME FOR ALL  GOOD MEN T<
VAR1 >NOW IS THE TIME FOR ALL GOOD MEN T      <


Dave
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts Using API Gateway from CICS program CICS 0
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
Search our Forums:

Back to Top