View previous topic :: View next topic
|
Author |
Message |
bshkris
New User
Joined: 21 Mar 2005 Posts: 41 Location: pune
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10886 Location: italy
|
|
|
|
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 |
|
|
bshkris
New User
Joined: 21 Mar 2005 Posts: 41 Location: pune
|
|
|
|
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 |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
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 |
|
|
Pravesh
New User
Joined: 30 Jul 2009 Posts: 32 Location: Gurgaon
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Pravesh
New User
Joined: 30 Jul 2009 Posts: 32 Location: Gurgaon
|
|
|
|
yeah that is the reason I specified
'You can try something like this:- '
in my post.....
Regards,
Pravesh[/quote] |
|
Back to top |
|
|
bshkris
New User
Joined: 21 Mar 2005 Posts: 41 Location: pune
|
|
|
|
Thank you all for timely suggestions.
Today i will do this and let you know about tjhe results. |
|
Back to top |
|
|
bshkris
New User
Joined: 21 Mar 2005 Posts: 41 Location: pune
|
|
|
|
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 |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
bshkris wrote: |
this peice of code worked at last |
Looks good, kind of fun, wasn't it? |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1248 Location: Richfield, MN, USA
|
|
|
|
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." |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
|