Replace special characters and find Numeric values in string



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Re: Replace special characters and find Numeric values in st

Postby BillyBoyo » Tue Apr 24, 2012 12:01 am

I think it is time for a re-clarification of your data.

123456789
12345678901234567890123456789
1#2#3#4#5#6#7#8#9
1A2A3A4A5A6A7A8A9
1 2 3 4 5 6 7 8 9
12345678#90123456
12345678 90123456
12345678B90123456


With the above, what would be your "match" in each case?
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: Re: Replace special characters and find Numeric values in st

 

Re: Replace special characters and find Numeric values in st

Postby MSURESH309 » Wed Apr 25, 2012 7:23 am

1. 123456789 - found 9 digit number will give an error
2. 12345678901234567890123456789 - found 9 digit number, will give an error(1-9,2-10,3-11..etc)
3. 1#2#3#4#5#6#7#8#9 - it has 9 digits,excluding special characters..so will error out
4. 1A2A3A4A5A6A7A8A9 - it won't error out because it doesn't have 9 numeric bytes
5. 1 2 3 4 5 6 7 8 9 - it has 9 digits,excluding spaces..so will error out
6. 12345678#90123456 - it has 9 digits,excluding special characters(#)..so will error out
7. 12345678 90123456 - it has 9 digits,excluding spaces..so will error out
8. 12345678B90123456 - it won't error out because it doesn't have 9 numeric bytes

In the above records, my logic should check for 9 numeric bytes, except 4 and 8 all others will match the condition.

Thanks,
Suresh
MSURESH309
 
Posts: 17
Joined: Thu Apr 21, 2011 10:04 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Replace special characters and find Numeric values in st

Postby dick scherrer » Wed Apr 25, 2012 7:47 am

Hello,

Possibly i've gotten completely lost, but it appears your clarification is not at all consistent. Actually the "clarification" neither matches the eariler "rules" nor the "rules" mentioned in the clarification.

Maybe i am just reading something incorrectly. . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: Replace special characters and find Numeric values in st

Postby MSURESH309 » Wed Apr 25, 2012 8:06 pm

Sorry for that..let me explain in detail. I have a 30 byte field where I may receive input from another source. If I receive any 9 byte numeric data anyware in the data(excluding spaces,special characters #,'.', '-', '/') then I have to send an error message.

So in the previous example, my program should error-out all the cases except 4 & 8 because,

4. 1A2A3A4A5A6A7A8A9 - it won't error out because it doesn't have 9 numeric bytes(found just 1 byte numeric value)
8. 12345678B90123456 - it won't error out because it doesn't have 9 numeric bytes(it has only 8 bytes of numeric value)

Hope it clarifies..let me know if it still unclear.Thanks
MSURESH309
 
Posts: 17
Joined: Thu Apr 21, 2011 10:04 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Replace special characters and find Numeric values in st

Postby BillyBoyo » Wed Apr 25, 2012 8:48 pm

Ok, I didn't realise that. I suspect it will be a surprise to others... :-)

If you are rejecting for nine (or more) numerics which are not bounded by alpha characters*, then

From character one, count all characters which have a value zero to nine. Restart counting from zero when you get an alpha. Stop when you reach end of data (after looking at 30 characters). Stop counting and reject if you get to nine.

Once you've rejected the ones you don't want, then you can do any other processing you like on the accepted ones.

You can test byte-by-byte for NUMERIC to count, and for ALPHABETIC to re-start the count. If there are other characters than ALPHABETIC which end your criteria, then you include those with the ALPHABETIC test.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: Replace special characters and find Numeric values in st

Postby gokulNmf » Sat May 05, 2012 3:53 pm

MSURESH309,
Just a small hint, I think it ll be useful.
You can move the 30 byte record into an array of element pic x, then you can check every element. You can use "THRU" clause for defining the check variable as it will be easy to define from A to Z and from 0 to 9.
Add counter for finding out which will be the valid and invalid record.
Hope it will be useful.
Cheers,
Gokul
User avatar
gokulNmf
 
Posts: 114
Joined: Sat Mar 28, 2009 6:41 pm
Location: India
Has thanked: 0 time
Been thanked: 0 time

Previous

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post