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

INSPECT with REPLACING problem


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

New User


Joined: 21 Mar 2005
Posts: 41
Location: pune

PostPosted: Wed May 05, 2010 9:27 pm
Reply with quote

I have one problem in removing the space and replacing with one string.

The total length of the variable is X(30).

so, the varaible may contains data, for ex: I AM BAD PERSON
the space may occur at any place in the length of 30.
I need to replace the space with "%20".
When i tried with INSPECT with REPLACING, it throws compilation error since, the space is like i char, and trying to fill with larger data item of 3 chars.
so i need to implement some tricky logic to convert the spaces into "%20".
But not able to do.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8651
Location: Dubuque, Iowa, USA

PostPosted: Wed May 05, 2010 9:33 pm
Reply with quote

Quote:
If some has any idea, please share it ASAP.
If you have to have an answer quickly, you've picked the worst possible way to get one. You should talk to your coworkers, team leader, or site support group if you need a quick answer. We are a help forum and we don't do fast.

Second, why are you doing this -- %20 is an HTML way of identifying a space, which would not work on any EBCDIC based mainframe since spaces on the mainframe are hex '40' not hex '20' as in ASCII.

Third, why are you doing this? Typically such transformations are handled by the web services and not your application.

Finally, you can define a 90-byte variable (to allow for all 30 characters of your input variable to be spaces and use reference modification to check each byte and move it or the replacement into the output variable.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10833
Location: italy

PostPosted: Wed May 05, 2010 9:33 pm
Reply with quote

Quote:
If some has any idea, please share it ASAP.

sorry but we do not do ASAP
answering is on voluntary effort, time, benevolence factor towards the requesting

using terms like ASAP or URGENT lowers dramatically the benevolence factor
Back to top
View user's profile Send private message
bshkris

New User


Joined: 21 Mar 2005
Posts: 41
Location: pune

PostPosted: Thu May 06, 2010 1:03 pm
Reply with quote

Robert Sample wrote:
Quote:
If some has any idea, please share it ASAP.
If you have to have an answer quickly, you've picked the worst possible way to get one. You should talk to your coworkers, team leader, or site support group if you need a quick answer. We are a help forum and we don't do fast.

Second, why are you doing this -- %20 is an HTML way of identifying a space, which would not work on any EBCDIC based mainframe since spaces on the mainframe are hex '40' not hex '20' as in ASCII.

Third, why are you doing this? Typically such transformations are handled by the web services and not your application.

Finally, you can define a 90-byte variable (to allow for all 30 characters of your input variable to be spaces and use reference modification to check each byte and move it or the replacement into the output variable.



Thanks for acknowledging,
I am adding the sentence to URL which hardcoded in working storage section variables.
as like
"http://www.xxxx.usernotification/expiry/date?quryName: I%20BAD%20NAME

Updo quryName in URL, we did in working storage value.
The last value is redriving from db2 table where it has some group of words having spaces.

we are generating the URL with dynamic values and putting in output dataset for the client reference.

I have tried in many ways, like using arrays, using INSPECT...but none of them is working out. ofcourse bit interesting and same time time brain storming thing.

Thanks.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Thu May 06, 2010 1:29 pm
Reply with quote

OK, this is in the COBOL forum.
You want to replace one character with more than one character.
Define an area larger than the original area and using a perform to loop scan and move, one byte at a time from the original to the destination area, replacing the one byte with the multiple bytes as needed.
This is a fifteen minute exercise and you should have fun doing it.
If you get stuck, please post what you have and we all can advise.
Back to top
View user's profile Send private message
Pravesh

New User


Joined: 30 Jul 2009
Posts: 32
Location: Gurgaon

PostPosted: Thu May 06, 2010 3:17 pm
Reply with quote

You can try something like this:-

Code:
01 VAR-A      PIC X(30).
01  VAR-B     PIC  X(90).
01  m            PIC 99 value zero.
01  n             PIC 99.

Perform varying n from 1 by 1 until n<30
  If VAR-A(n:1) = ' '
      MOVE '%20'  to VAR-B(m : 3)
      m=m+3
   Else
     MOVE  VAR(n:1)    TO   VAR-B(m : 1)
     m= m+1
  End-if


Regards,
Pravesh
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu May 06, 2010 4:47 pm
Reply with quote

Code:
Perform varying n from 1 by 1 until n<30


Pravesh,
you need to double check you code when you post a solution.
Howmany characters do you think the above perform will move?

VAR-B should also be INITIALIZED.
Back to top
View user's profile Send private message
Pravesh

New User


Joined: 30 Jul 2009
Posts: 32
Location: Gurgaon

PostPosted: Thu May 06, 2010 5:29 pm
Reply with quote

yeah that is the reason I specified

'You can try something like this:- '

in my post.....



Regards,
Pravesh[/quote]
Back to top
View user's profile Send private message
bshkris

New User


Joined: 21 Mar 2005
Posts: 41
Location: pune

PostPosted: Fri May 07, 2010 1:58 pm
Reply with quote

Thank you all for timely suggestions.
Today i will do this and let you know about tjhe results.
Back to top
View user's profile Send private message
bshkris

New User


Joined: 21 Mar 2005
Posts: 41
Location: pune

PostPosted: Fri May 07, 2010 5:53 pm
Reply with quote

hi all,
this peice of code worked at last.

Code:
 MOVE    0            TO WS-CNT1                           
 move   +1            TO WS-CNT2                           
                                                           
 PERFORM VARYING WS-CNT1 FROM 1 BY 1 UNTIL WS-CNT1 > 30   
   IF WS-TEXT1(WS-CNT1:1) = ' '                           
      MOVE '%20'      TO WS-TEXT2(WS-CNT2:3)               
      COMPUTE WS-CNT2 = WS-CNT2 + 3                       
   ELSE                                                   
      MOVE WS-TEXT1(WS-CNT1:1)      TO WS-TEXT2(WS-CNT2:1)
      COMPUTE WS-CNT2 = WS-CNT2 + 1                       
   END-IF                                                 
 END-PERFORM                                           



Thank you very much.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Fri May 07, 2010 7:14 pm
Reply with quote

bshkris wrote:
this peice of code worked at last
Looks good, kind of fun, wasn't it?
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Tue May 11, 2010 6:00 am
Reply with quote

Quote:
We are a help forum and we don't do fast.
Kind of reminds me of, "You can have it cheap, you can have it fast, you can have it good -- pick any two." icon_lol.gif
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Tue May 11, 2010 9:32 am
Reply with quote

bshkris wrote:
this piece of code worked at last.
What do you mean by "at last"? It shouldn't have been too difficult, following Pravesh pseudo-code.
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 z/vm installation problem All Other Mainframe Topics 0
No new posts Job scheduling problem. JCL & VSAM 9
No new posts Problem with IFTHEN=(WHEN=GROUP,BEGIN... DFSORT/ICETOOL 5
No new posts Need to add field to copybook, proble... COBOL Programming 14
No new posts z/vm ipl problem All Other Mainframe Topics 5
Search our Forums:

Back to Top