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

INSPECT a string for ?&? or ?/? or ?@?


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Aravind Kumar. S

New User


Joined: 28 Apr 2005
Posts: 26

PostPosted: Fri Jul 01, 2005 3:43 pm
Reply with quote

Hi,

This is my scenario, Could u plz give me the exact syntax for this.

"Inspect whether the IN-STREET ( A FIELD) contains ?&? or ?/? or ?@?.
If it contains any of these characters, I 'm moving some error messages .

if it doesn't contains any of these characters, i' m calling some utility."

Thanks,
Aravind
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Fri Jul 01, 2005 4:58 pm
Reply with quote

Hi Aravind Kumar. S,

Quote:
"Inspect whether the IN-STREET ( A FIELD) contains ?&? or ?/? or ?@?.
If it contains any of these characters, I 'm moving some error messages .

if it doesn't contains any of these characters, i' m calling some utility."


Code:
INSPECT  VARIABLE TALLYING I FOR ALL "@".
IF I >=1                           
   DISPLAY 'ERROR MESSAGE'
ELSE                               
   PERFORM UTILITY.


This code will give you number of occurrences of @ in a counter (I here).
& If that counter is 1 or more....you find that char...

Similarly you can do for "&" and "/" too...

Tell me if it is not working....

Regards,

Priyesh.
Back to top
View user's profile Send private message
Aravind Kumar. S

New User


Joined: 28 Apr 2005
Posts: 26

PostPosted: Fri Jul 01, 2005 5:31 pm
Reply with quote

Hi Priyesh,

Thanks for ur reply.

In a single INSPECT command, is it possible to give '/','@','&' ?

one more query ,

I 've to Identify the position of first valid character (Alphabet, Number or Hash) in IN-STREET (Field).


For eg : If IN-STREET = ? 123 MAPLEFIELD ST. APT#34 ?

Then it shud be converted to


IN-STREET = ?123 MAPLEFIELD ST. APT#34 ?

the spaces shud be deleted.

how i can do this.plz help me

Thanks,
Aravind
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Fri Jul 01, 2005 6:28 pm
Reply with quote

Hi Aravind,

Quote:
In a single INSPECT command, is it possible to give '/','@','&' ?


Yes it is possible.
Code:
 INSPECT IN-STREET  TALLYING I FOR ALL "@"
                                         J FOR ALL "&"
                                         K FOR ALL "/".


This will give number of occurrences of @, &, / to i, j, k respectively.
Then by comparing I, J, K you can do as per your requirement.

Quote:
the spaces shud be deleted.


Acc to your requirement I assume that you wanna delete initial spaces.

So Try this code...

Code:
01 Z PIC 99 VALUE 1.
PERFORM MATCH UNTIL Z=0.
DISPLAY 'IN-STREET' IN-STREET.
 
MATCH.                             
      INITIALIZE IN-STREET.           
      MOVE IN-STREET-WS  TO IN-STREET.
      IF IN-STREET(1:1) = ' '           
            ADD 1 TO P               
            INITIALIZE IN-STREET-WS
            MOVE IN-STREET(P:11) TO IN-STREET-WS
      ELSE                         
            MOVE 0 TO Z.             
     EXIT.   


Let me know ...If remains any thing...

Regards,

Priyesh.
Back to top
View user's profile Send private message
Aravind Kumar. S

New User


Joined: 28 Apr 2005
Posts: 26

PostPosted: Fri Jul 01, 2005 7:08 pm
Reply with quote

Hi Priyesh,

Sorry ! i'm not getting the answer..I make my question more clear...
Consider this Eg.

If IN-STREET =
? ^*%$^#$# 123 MAPLEFIELD ST. APT#34 ?

Then it shud be converted to

IN-STREET = ?123 MAPLEFIELD ST. APT#34 ?

(i.e.) it shud remove leading and embedded sapces and characters other than Alphabet, Number or Hash.


Thanks,
expecting ur reply....

Aravind
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Fri Jul 01, 2005 7:11 pm
Reply with quote

& what is the lengthg of the field ?

Priyesh.
Back to top
View user's profile Send private message
Aravind Kumar. S

New User


Joined: 28 Apr 2005
Posts: 26

PostPosted: Fri Jul 01, 2005 7:13 pm
Reply with quote

Length is 100

aravind.s
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Fri Jul 01, 2005 7:17 pm
Reply with quote

Quote:
If IN-STREET =
? ^*%$^#$# 123 MAPLEFIELD ST. APT#34 ?

Then it shud be converted to

IN-STREET = ?123 MAPLEFIELD ST. APT#34 ?

(i.e.) it shud remove leading and embedded sapces and characters other than Alphabet, Number or Hash.


Then

IN-STREET = ?#$# 123 MAPLEFIELD ST. APT#34 ?

If you remove all initial char except number alpha or hash you will find this string only......Is that fine ?

Because you have given above expected IN-STREET = ?123 MAPLEFIELD ST. APT#34 ?

Priyesh.
Back to top
View user's profile Send private message
Aravind Kumar. S

New User


Joined: 28 Apr 2005
Posts: 26

PostPosted: Fri Jul 01, 2005 7:27 pm
Reply with quote

Hi ,


Sorry Priyesh

IN-STREET = ? @!~)(123 MAPLEFIELD ST. APT#34 ?

IN-STREET = ?123 MAPLEFIELD ST. APT#34 ?

This is the exact thing.

my intention is

it shud remove leading and embedded sapces
or

i can say like this

Identify the position of first valid character (Alphabet, Number or Hash) in IN-STREET. Start extracting characters from this position till no characters are found.

Thanks,
ARavind. S
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Fri Jul 01, 2005 7:47 pm
Reply with quote

Hi Arvind,

I m making it clear, The code below will check each char in the variable IN-STREET and It'll go up till it finds a number, alpha or a hash.

Once it finds any char like that, It'll copy rest of the string.

I hope it was what you wanna do.

Code:
PERFORM MATCH UNTIL Z=0.
DISPLAY 'IN-STREET' IN-STREET.

 MATCH.                                             
       INITIALIZE IN-STREET.                             
       MOVE IN-STREET-WS TO IN-STREET.                         
      IF IN-STREET(1:1) >= 0 AND <=9                     
           MOVE ZERO TO Z                           
      ELSE                                           
           IF IN-STREET(1:1) >= 'A' AND <='Z'           
                     MOVE ZERO TO Z                 
           ELSE                                     
                  IF IN-STREET(1:1) = '#'               
                         MOVE ZERO TO Z             
                  ELSE                               
                     ADD 1 TO P                     
                     INITIALIZE IN-STREET-WS
                     MOVE IN-STREET(P:100) TO IN-STREET-WS.     
      EXIT.


Still If it is not working acc to your req ....let me know the result ...whatever.........

Regards,

Priyesh.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Tue Jul 05, 2005 1:06 am
Reply with quote

Hi Aravind,

Seems like this thread's gotten out of hand icon_biggrin.gif so I'll ans your orig ques:
Quote:
"Inspect whether the IN-STREET ( A FIELD) contains ?&? or ?/? or ?@?.
If it contains any of these characters, I 'm moving some error messages .

if it doesn't contains any of these characters, i' m calling some utility."


Code:
       IDENTIFICATION DIVISION.
       PROGRAM-ID.    XXX.
      *AUTHOR.        XXX.
       ENVIRONMENT DIVISION.
      *
       CONFIGURATION SECTION.
            SOURCE-COMPUTER. S390
            OBJECT-COMPUTER. S390
            SPECIAL-NAMES. CLASS USING-JUNK-CHARS  IS '&' '/' '@'.
      *
       INPUT-OUTPUT SECTION.
      .
      .
      .
      .
       PROCEDURE DIVISION.
       0000-MAIN.
             IF IN-STREET IS USING-JUNK-CHARS
                 DISPLAY 'ERROR MSG'
             ELSE
                 CALL'utilpgm'
             END-IF 


You don't need the src/obj pgm lines or the I/O Sect. I just included them to position the SPEC NAMES pgraph.
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Tue Jul 05, 2005 10:52 am
Reply with quote

Hi mmwife,

Quote:
IF IN-STREET IS USING-JUNK-CHARS
DISPLAY 'ERROR MSG'
ELSE
CALL'utilpgm'
END-IF


It doesn't work for me. My code is going in ELSE part despite having these characters.

Regards,

Priyesh.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Fri Jul 15, 2005 7:08 am
Reply with quote

Hi Priyesh,

Sorry I didn't get back sooner. Didn't have the time to reseach it till now.

Here's the problem w/my solution:

I had it backwards, sort of. The CLASS has to contain ALL the possible chars that the variable (IN-STREET) in the IF can contain. For example, every char except &, /, or @.

I'll rewrite the code:
Code:

       IDENTIFICATION DIVISION.
       PROGRAM-ID.    XXX.
      *AUTHOR.        XXX.
       ENVIRONMENT DIVISION.
      *
       CONFIGURATION SECTION.
            SOURCE-COMPUTER. S390
            OBJECT-COMPUTER. S390
            SPECIAL-NAMES. CLASS VALID-DATA IS 'A' THRU 'Z'
                                               '0' THRU '9'
                                         '!'  ','  '.'  '*'.
                                                           
      *
       INPUT-OUTPUT SECTION.
      .
      .
      .
      .
       PROCEDURE DIVISION.
       0000-MAIN.
             IF IN-STREET IS NOT VALID-DATA
                 DISPLAY 'ERROR MSG'
             ELSE
                 CALL'utilpgm'
             END-IF 

You may have to add other valid chars to the CLASS according to your needs, but that's the basic idea.

I hope this clears it up. Let us know if this works for you.

Thanx and
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Fri Jul 15, 2005 3:20 pm
Reply with quote

Hi mmwife,

Firstly Thanks for your effort....

Concept of special names is being very confusing for me now......I tried your code it worked well for the requirements started in the thread......

But if you just replace any of the character with @ in your SPECIAL NAMES code it starts behaving otherwsie. As I did in the below code.

Code:
SPECIAL-NAMES. CLASS VALID-DATA IS 'A' THRU 'Z'
                                               '0' THRU '9'
                                         '@'  ','  '.'  '*'.


So is there any restrictions on some characters to be defined in special names.....

Here is the code I tried....with output...

Code:
SPECIAL-NAMES. CLASS VALID-DATA IS 'A' THRU 'Z'
                                   '0' THRU '9'
                             '@'  ','  '.'  '*'.

 MOVE SPACES TO WS-XY.   
 MOVE '@' TO WS-XY.       
 DISPLAY WS-XY.           
 IF WS-XY IS VALID-DATA   
 DISPLAY 'NO JUNK'       
 ELSE                     
 DISPLAY '   JUNK'.       
                         
 MOVE SPACES TO WS-XY.   
 MOVE 'ASDFFA' TO  WS-XY.
 DISPLAY WS-XY.           
 IF WS-XY IS VALID-DATA   
 DISPLAY ' NO JUNK'       
 ELSE                     
 DISPLAY '   JUNK'.       


output...
Code:
@       
   JUNK
ASDFFA 
   JUNK


Regards,

Priyesh.
Back to top
View user's profile Send private message
die7nadal

Active User


Joined: 23 Mar 2005
Posts: 156

PostPosted: Fri Jul 15, 2005 11:43 pm
Reply with quote

Priyesh,
The answer lies in the PIC clause that u are defining for WS-XY, if there are extra spaces in WS-XY, then sure the ELSE loop wud execute to display JUNK. If u have
Code:
SPECIAL-NAMES. CLASS VALID-DATA IS 'A' THRU 'Z'
                                   '0' THRU '9'
                             '@'  ','  '.'  '*' ' '.



then NO JUNK wud be displayed.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat Jul 16, 2005 6:18 am
Reply with quote

Hi Priyesh,

You don't say what the size of WS-XY is. If it's larger than 6 bytes that may account for the result, since a space(s) will be contained in WS-XY and space was not included in the CLASS.

On the other hand, you may be right about special chars. I'll check that out and let you know.
Back to top
View user's profile Send private message
somasundaran_k

Active User


Joined: 03 Jun 2003
Posts: 134

PostPosted: Sun Jul 17, 2005 12:02 am
Reply with quote

Hi mmwife
I think the characters A thru Z are not contiguous.There are some printable/non-printable characters in this sequence. So we have to avoid them while checking for the alphabets.

It should be
Code:

SPECIAL-NAMES. CLASS VALID-DATA IS 'A' THRU 'I'
                                                            'J' THRU 'R'
                                                            'S' THRU 'Z'


Regds
-Som
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sun Jul 17, 2005 1:35 am
Reply with quote

Hi Som,

You're right, I got lazy. There are a few printables in there, but with the exception of "\" AND "}" they're rare (only 2 others). To be safe you should code it:
Code:

'A' THRU 'I'   'J' THRU 'R'   'S' THRU 'Z'   
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Mon Jul 18, 2005 8:44 pm
Reply with quote

Hi All,

Thanks for the replies....So called prob was with PIC clause as it was defined more than 6 bytes.....But people dont you think as an string operation It should work for less than full length values too.....

May be another way can to define a SPACE too in Valid List...Is It ?

Quote:
There are a few printables in there,

Can you please more elaborate on this....

Regards,

Priyesh.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Tue Jul 19, 2005 4:36 am
Reply with quote

Hi Priyesh,

You can solve it by entering ' ' in the CLASS list, for example:
Code:
 
SPECIAL-NAMES. CLASS VALID-CHARS  IS '&' '/' '@' ' '. 
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1448
Location: Chicago, IL

PostPosted: Tue Jul 19, 2005 9:55 pm
Reply with quote

Hi mmwife,

That worked perfact.....

Last doubt.....There has been some discussion on printables in the thread above.....Will any one give an idea...what they are......

Thanks & Regards,

Priyesh.
Back to top
View user's profile Send private message
somasundaran_k

Active User


Joined: 03 Jun 2003
Posts: 134

PostPosted: Tue Jul 19, 2005 10:33 pm
Reply with quote

Priyesh
In the EBCDIC collating sequence the alphabets(A-Z) are not contiguous.
Refer this link for more details
publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/IGY3LR10/APPENDIX1.3.1?SHELF=&DT=20020920180651&CASE=

Regds
-Som
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 2
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts file manager is doing string conversion IBM Tools 3
No new posts Search string in job at regular Spool... CLIST & REXX 0
Search our Forums:

Back to Top