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

Replacing unwanted characters with zeros


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

Active User


Joined: 02 May 2005
Posts: 128
Location: UK

PostPosted: Thu Oct 18, 2007 12:32 pm
Reply with quote

Hello ,


I just want to all other value to Zeroes (except numeric Value) .

For Example ws-var = ! #$%^&88
i want to replace it like 000000088

that means all other characters replaced with zeroes.


can we do it using INSPECT

Regards
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: Thu Oct 18, 2007 12:40 pm
Reply with quote

Hello,

When you have a question, it is usually better to start a new topic for yojr question rather than reply to an almost 2-year-old topic.

What should happen if the value is
Code:
 ws-var = ! #23$%^&88
?

If you merely convert all non-numerals to zeros, you may cause later problems (if the field requires numeric data).
Back to top
View user's profile Send private message
shankar.v

Active User


Joined: 25 Jun 2007
Posts: 196
Location: Bangalore

PostPosted: Thu Oct 18, 2007 1:20 pm
Reply with quote

shr_amar,

Please check with the following code for your requirement.
Code:
       IDENTIFICATION DIVISION.                                   
       PROGRAM-ID. C.                                             
       ENVIRONMENT DIVISION.                                     
       CONFIGURATION SECTION.                                     
       SPECIAL-NAMES.                                             
           CLASS NOTJUNK IS '1' THRU '9' ZERO.                   
       DATA DIVISION.                                             
       WORKING-STORAGE SECTION.                                   
       77 WS-ALPHANUMERIC-IN PIC X(9) VALUE SPACES.               
       77 WS-ALPHANUMERIC-OUT PIC X(9) VALUE SPACES.             
       77 WS-I PIC 99.                                           
       77 WF-JUNK PIC X VALUE 'N'.                               
        88 JUNK-FOUND VALUE 'Y'.                                 
        88 JUNK-NOT-FOUND VALUE 'N'.                             
       PROCEDURE DIVISION.                                       
           ACCEPT WS-ALPHANUMERIC-IN                             
           DISPLAY 'WS-ALPHANUMERIC-IN  ==> ' WS-ALPHANUMERIC-IN 
           PERFORM VARYING WS-I FROM 1 BY 1 UNTIL WS-I > LENGTH OF
                           WS-ALPHANUMERIC-IN                     
            IF WS-ALPHANUMERIC-IN(WS-I:1) IS NOT NOTJUNK         
             SET JUNK-FOUND TO TRUE                               
            END-IF                                               
            IF JUNK-FOUND                                         
             MOVE ZERO TO WS-ALPHANUMERIC-OUT(WS-I:1)             
             SET JUNK-NOT-FOUND TO TRUE                           
            ELSE                                                 
             MOVE WS-ALPHANUMERIC-IN(WS-I:1) TO                   
                 WS-ALPHANUMERIC-OUT(WS-I:1)                     
            END-IF                                               
           END-PERFORM                                           
           DISPLAY 'WS-ALPHANUMERIC-OUT ==> ' WS-ALPHANUMERIC-OUT
           GOBACK.

Input:
Code:
! #$%^&88

Output:
Code:
WS-ALPHANUMERIC-IN  ==> ! #$%^&88
WS-ALPHANUMERIC-OUT ==> 000000088
Back to top
View user's profile Send private message
shankar.v

Active User


Joined: 25 Jun 2007
Posts: 196
Location: Bangalore

PostPosted: Thu Oct 18, 2007 1:34 pm
Reply with quote

shr_amar,

Please check with the following sort jcl for your requirement.
Code:
// EXEC PGM=SORT                                               
//SORTIN DD *                                                   
! #$%^&88                                                       
/*                                                             
//SORTOUT DD SYSOUT=*                                           
//SYSOUT DD SYSOUT=*                                           
//SYSIN DD *                                                   
 OPTION COPY                                                   
 INREC IFTHEN=(WHEN=(1,1,SS,NE,C'0123456789'),OVERLAY=(1:C'0'),
               HIT=NEXT),                                       
       IFTHEN=(WHEN=(2,1,SS,NE,C'0123456789'),OVERLAY=(2:C'0'),
               HIT=NEXT),                                       
       IFTHEN=(WHEN=(3,1,SS,NE,C'0123456789'),OVERLAY=(3:C'0'),
               HIT=NEXT),                                       
       IFTHEN=(WHEN=(4,1,SS,NE,C'0123456789'),OVERLAY=(4:C'0'),
               HIT=NEXT),                                       
       IFTHEN=(WHEN=(5,1,SS,NE,C'0123456789'),OVERLAY=(5:C'0'),
               HIT=NEXT),                                       
       IFTHEN=(WHEN=(6,1,SS,NE,C'0123456789'),OVERLAY=(6:C'0'),
               HIT=NEXT),                                       
       IFTHEN=(WHEN=(7,1,SS,NE,C'0123456789'),OVERLAY=(7:C'0'),
               HIT=NEXT),                                       
       IFTHEN=(WHEN=(8,1,SS,NE,C'0123456789'),OVERLAY=(8:C'0'),
               HIT=NEXT),                                       
       IFTHEN=(WHEN=(9,1,SS,NE,C'0123456789'),OVERLAY=(9:C'0'))
/*                                                             
//                                                             

Output:
Code:
000000088
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Thu Oct 18, 2007 1:59 pm
Reply with quote

Shankar,

You can make use of NUM instead of checking for the digits from 0 - 9

Code:
INREC IFTHEN=(WHEN=(1,1,FS,NE,NUM),OVERLAY=(1:C'0'),
Back to top
View user's profile Send private message
shankar.v

Active User


Joined: 25 Jun 2007
Posts: 196
Location: Bangalore

PostPosted: Thu Oct 18, 2007 2:11 pm
Reply with quote

Aaru,
Quote:
Shankar,

You can make use of NUM instead of checking for the digits from 0 - 9

Code:
INREC IFTHEN=(WHEN=(1,1,FS,NE,NUM),OVERLAY=(1:C'0'),

My site has SYNCSORT FOR Z/OS 1.2.3 and FS and NUM are not available in that version.
Back to top
View user's profile Send private message
shankar.v

Active User


Joined: 25 Jun 2007
Posts: 196
Location: Bangalore

PostPosted: Thu Oct 18, 2007 2:18 pm
Reply with quote

Aaru,

Format FS is available but FS,EQ,NUM and FS,NE,NUM are not available in SYNCSORT FOR Z/OS 1.2.3
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Thu Oct 18, 2007 2:26 pm
Reply with quote

Quote:
My site has SYNCSORT FOR Z/OS 1.2.3 and FS and NUM are not available in that version.


Even my site uses the same version of SYNCSORT and not DFSORT. I posted so that shr_amar can try that option too if DFSORT is installed in his site.
Back to top
View user's profile Send private message
KMV

New User


Joined: 15 May 2007
Posts: 22
Location: Coimbatore

PostPosted: Thu Oct 18, 2007 3:30 pm
Reply with quote

Hi,
Try this one :
Code:

INSPECT WS-DEC-LIC-NO1 REPLACING
CHARACTERS BY ZEROES.           


This will replace all the characters (a-z and special characters)
Back to top
View user's profile Send private message
shankar.v

Active User


Joined: 25 Jun 2007
Posts: 196
Location: Bangalore

PostPosted: Thu Oct 18, 2007 4:09 pm
Reply with quote

KMV,

The requirement is to replace all characters to zero except the numeric(0,1,2,3,4,5,6,7,8,9).

when i tried with your code, it is replacing all alphabets, numeric and special characters to zeros.

Please check with the below cobol code, input and output using INSPECT statement as suggested by you.
Code:
       IDENTIFICATION DIVISION.                           
       PROGRAM-ID. A.                                     
       DATA DIVISION.                                     
       WORKING-STORAGE SECTION.                           
       77 WS-IN PIC X(9) VALUE SPACES.                   
       77 WS-OUT PIC X(9) VALUE SPACES.                   
       PROCEDURE DIVISION.                               
           ACCEPT WS-IN                                   
           DISPLAY 'WS-IN  ==> ' WS-IN                   
           MOVE WS-IN TO WS-OUT                           
           DISPLAY 'WS-OUT ==> ' WS-OUT '  BEFORE INSPECT'
           INSPECT WS-OUT REPLACING CHARACTERS BY ZERO   
           DISPLAY 'WS-OUT ==> ' WS-OUT '  AFTER  INSPECT'
           GOBACK.

Input:
Code:
! #$%^&88

Output:
Code:
WS-IN  ==> ! #$%^&88               
WS-OUT ==> ! #$%^&88  BEFORE INSPECT
WS-OUT ==> 000000000  AFTER  INSPECT

Note that numeric 88 in ! #$%^&88 are also changed to zeros
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: Thu Oct 18, 2007 7:40 pm
Reply with quote

Hello,

To repeat:
Quote:
What should happen if the value is
Code:
 ws-var = ! #23$%^&88

?

If you merely convert all non-numerals to zeros, you may cause later problems (if the field requires numeric data).


Rather than show TS how they might cause problems, i believe it would be good to understand the business requirement that "identified" this "rule".

After the value has been "fixed" how will it be used? If it is a quantity, an amount, or a key to some random read/insert, merely changing all of the not numerals to numerals will likely cause more problems than it solves.
Back to top
View user's profile Send private message
dominickim

New User


Joined: 28 Feb 2007
Posts: 65
Location: NS, CA

PostPosted: Sat Oct 20, 2007 12:17 am
Reply with quote

Code:
Command ===> c all p'-' '0' 1 9                                 Scroll ===> CSR
****** ***************************** Top of Data ******************************
000001 ! #$%ï&88                                                               
****** **************************** Bottom of Data ****************************

Code:
Command ===>                                                    Scroll ===> CSR
****** ***************************** Top of Data ******************************
==CHG> 000000088                                                               
****** **************************** Bottom of Data ****************************
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: Sat Oct 20, 2007 12:23 am
Reply with quote

Hello dominickim and welcome to the fourms,

Quote:
How about TSO command
Probably not as the request was to do this in COBOL. . . This would be especially true if this was going to be part of a regular, scheduled job.
Back to top
View user's profile Send private message
jmreddymca
Warnings : 1

New User


Joined: 14 Oct 2007
Posts: 29
Location: Bangalore

PostPosted: Mon Oct 22, 2007 5:52 pm
Reply with quote

Hello dominickim

the command which you mention is not possible you know.
i don't know how you show the result?????
Back to top
View user's profile Send private message
krisprems

Active Member


Joined: 27 Nov 2006
Posts: 649
Location: India

PostPosted: Mon Oct 22, 2007 7:28 pm
Reply with quote

Hello,
what about using numval-Chttp://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/igy3pg30/1.6.6.3?ACTION=MATCHES&REQUEST=NUMVAL-C&TYPE=FUZZY&SHELF=&DT=20050628164603&CASE=&searchTopic=TOPIC&searchText=TEXT&searchIndex=INDEX&rank=RANK&ScrollTOP=FIRSTHIT#FIRSTHIT
Back to top
View user's profile Send private message
dominickim

New User


Joined: 28 Feb 2007
Posts: 65
Location: NS, CA

PostPosted: Tue Oct 23, 2007 8:50 pm
Reply with quote

Quote:

Hello jmreddymca,
What do you mean NOT POSSIBLE? I know it is not a COBOL program he/she wanted to know and I mentioned TSO command first. These are before and after images.
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 Count the number of characters in a f... CA Products 1
No new posts How to display the leading zeros of a... DB2 7
No new posts Finding record and replacing with val... DFSORT/ICETOOL 3
No new posts Replacing character string in file th... JCL & VSAM 9
No new posts Replacing PDSMAN with PDSFAST JCL & VSAM 10
Search our Forums:

Back to Top