Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

INSPECT a string for ?&? or ?/? or ?@?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: INSPECT a string for ?&? or ?/? or ?@?
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: 1452
Location: Chicago, IL

PostPosted: Fri Jul 01, 2005 4:58 pm    Post subject: Re: INSPECT
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    Post subject:
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: 1452
Location: Chicago, IL

PostPosted: Fri Jul 01, 2005 6:28 pm    Post subject: Re: INSPECT
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    Post subject:
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: 1452
Location: Chicago, IL

PostPosted: Fri Jul 01, 2005 7:11 pm    Post subject: Re: INSPECT
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    Post subject:
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: 1452
Location: Chicago, IL

PostPosted: Fri Jul 01, 2005 7:17 pm    Post subject: Re: INSPECT
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    Post subject:
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: 1452
Location: Chicago, IL

PostPosted: Fri Jul 01, 2005 7:47 pm    Post subject: Re: INSPECT
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    Post subject:
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: 1452
Location: Chicago, IL

PostPosted: Tue Jul 05, 2005 10:52 am    Post subject: Re: INSPECT a string for ?&? or ?/? or ?@?
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    Post subject:
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: 1452
Location: Chicago, IL

PostPosted: Fri Jul 15, 2005 3:20 pm    Post subject: Re: INSPECT a string for ?&? or ?/? or ?@?
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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: 1452
Location: Chicago, IL

PostPosted: Mon Jul 18, 2005 8:44 pm    Post subject: Re: INSPECT a string for ?&? or ?/? or ?@?
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    Post subject:
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
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts Random Password (in string format) ge... ezhavendhan COBOL Programming 10 Mon Aug 29, 2016 3:18 pm
No new posts How to insert a lengthy string havin... vidyaa DB2 7 Thu Aug 25, 2016 5:20 pm
No new posts Which function does the Ampersand (&a... Andi1982 PL/I & Assembler 3 Wed Aug 24, 2016 2:05 pm
No new posts Need a help how to replace a string i... gurunath82 CLIST & REXX 12 Tue Jul 26, 2016 11:43 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us