View previous topic :: View next topic
|
Author |
Message |
kovur
New User
Joined: 15 Nov 2007 Posts: 36 Location: India
|
|
|
|
I have the following code in my programme.
MOVE WS-ADDR1 TO ADDR-1
In ws-addr1 record we have symbols like '@', ',', '&'.
I want to replace the '&' symbol in the ws-addr1 with the '&'.
After replacing only I want to move it to addr-1.
How can I achieve this?
Thanks in advance. |
|
Back to top |
|
|
kovur
New User
Joined: 15 Nov 2007 Posts: 36 Location: India
|
|
|
|
I ahve tried this with the INSPECT verb. But this verb will replace the the characters which have the same length.
In my case I want to replace '&' with '&'
Thanks |
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
Kovur,
Please show your var declaration along with examples. If you expect your i/p and o/p should be of same length, there is a possiblility you may loose some data because of change from '&' to '&'. |
|
Back to top |
|
|
kovur
New User
Joined: 15 Nov 2007 Posts: 36 Location: India
|
|
|
|
My variable declarations are like this.
01 ws-addr1 pic x(75)
01 addr1 pic x(75)
But in the DB2 table we don't have address lines greater than 30 bytes. |
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
Kovur,
Im confused.
How 30 bytes are related to 75 bytes? |
|
Back to top |
|
|
kovur
New User
Joined: 15 Nov 2007 Posts: 36 Location: India
|
|
|
|
In the DB2 table we don't have address greater than 30 bytes. Therefore I think If we change the '&' as '&' nothing will be truncated. |
|
Back to top |
|
|
kovur
New User
Joined: 15 Nov 2007 Posts: 36 Location: India
|
|
|
|
we are fetching the data from a DB2 table to ws-addr1 and moving it to addr1. Addr-1 is the field in output file. |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
kovur wrote: |
I want to replace the '&' symbol in the ws-addr1 with the '&'. |
How many '&' might appear in this string, is it known or not? |
|
Back to top |
|
|
kovur
New User
Joined: 15 Nov 2007 Posts: 36 Location: India
|
|
|
|
we don't know exactly. We need to change every '&' into '&'.
Thanks |
|
Back to top |
|
|
shankar.v
Active User
Joined: 25 Jun 2007 Posts: 196 Location: Bangalore
|
|
|
|
kovur,
Whether the address column data type in your DB2 is CHAR or VARCHAR and what is its length?.
While getting value from DB2 column into cobol variable, we have to use proper variables with proper length suitable to DB2 column datatypes.
Let us assume your DB2 address column data type is CHAR(75).
In this case, suppose if all the 75 bytes are filled with '&' then we need a 75 + (75 X 3) = 300 (75 '&' and 75 'AMP') PIC X(300) so that it will accomodate all '&' to be replace with '&'.
Please check with the following sample cobol code for your requirement.
Code: |
IDENTIFICATION DIVISION.
PROGRAM-ID. PGM.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 WS-A PIC X(75) VALUE ALL '&'.
77 WS-B PIC X(300) VALUE SPACE.
77 I PIC 9(2) VALUE ZERO.
77 J PIC 9(3) VALUE 1.
PROCEDURE DIVISION.
DISPLAY 'INITIAL VALUE OF WS-A : ' WS-A
DISPLAY 'INITIAL VALUE OF WS-B : ' WS-B
PERFORM VARYING I FROM 1 BY 1 UNTIL I > LENGTH OF WS-A
EVALUATE WS-A(I:1)
WHEN '&'
MOVE '&' TO WS-B(J:)
ADD +4 TO J
WHEN OTHER
MOVE WS-A(I:1) TO WS-B(J:)
ADD +1 TO J
END-EVALUATE
END-PERFORM
DISPLAY 'FINAL VALUE OF WS-B : ' WS-B
GOBACK. |
|
|
Back to top |
|
|
kovur
New User
Joined: 15 Nov 2007 Posts: 36 Location: India
|
|
|
|
In my case the address line is like this:
Delhi&Mumbai&Kolkata&Chennai.
In some cases there is a space before and after the '&'.
In the output file the address should be
Delhi&Mumbai&Kolkata&Chennai |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 631 Location: Wisconsin
|
|
|
|
Are you converting this to XML and that is why you need the &?
I have used the following code after using the XML GENERATE in Cobol. This is just a snip of the code I found at IBM.com and modified for my needs.
Code: |
When 'CONTENT-CHARACTER'
Evaluate xml-text
When '<'
String '<' Delimited by Size
Into XML-O-DOC
With Pointer XML-O-LEN
When '&'
String '&' Delimited by Size
Into XML-O-DOC
With Pointer XML-O-LEN
When other
String xml-text Delimited by Size
Into XML-O-DOC
With Pointer XML-O-LEN
End-Evaluate
|
|
|
Back to top |
|
|
shankar.v
Active User
Joined: 25 Jun 2007 Posts: 196 Location: Bangalore
|
|
|
|
Quote: |
In some cases there is a space before and after the '&'. |
Do you want to replace those '&' with a space before and after to '&'?.
If the answer is no, then how those '&' with a space before and after to be handled?
Do you want to keep the declaration of the cobol variable which gets the values from DB2 column(address column) and declaration of the variable which is used for writing in to file to be same?.
If yes, are you sure that the values going to replace '&' with '&' will not get truncated?
Quote: |
we are fetching the data from a DB2 table to ws-addr1 and moving it to addr1. Addr-1 is the field in output file. |
Can you please post the address column datatype and its length? |
|
Back to top |
|
|
kovur
New User
Joined: 15 Nov 2007 Posts: 36 Location: India
|
|
|
|
If my address line is like this
Delhi & Kolkata & Mumbai & Chennai
then also I need to change the & into &.
After changing it, the data will not be truncated. |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 631 Location: Wisconsin
|
|
|
|
Have you tried shankar.v's solution? It appears that it has a high likelihood of working. |
|
Back to top |
|
|
shankar.v
Active User
Joined: 25 Jun 2007 Posts: 196 Location: Bangalore
|
|
|
|
kovur,
Quote: |
If my address line is like this
Delhi & Kolkata & Mumbai & Chennai
then also I need to change the & into &.
After changing it, the data will not be truncated. |
Please check with the logic in the sample cobol code which i was posted earlier for your requirement. |
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
To all who provided solution,
Quote: |
01 ws-addr1 pic x(75) |
Quote: |
In the DB2 table we don't have address greater than 30 bytes. Therefore I think If we change the '&' as '&' nothing will be truncated. |
Quote: |
we are fetching the data from a DB2 table to ws-addr1 and moving it to addr1. Addr-1 is the field in output file. |
Dont you think this is the best example for 'bad design of a program' by any standards? |
|
Back to top |
|
|
kovur
New User
Joined: 15 Nov 2007 Posts: 36 Location: India
|
|
|
|
Hi Friends,
My problem was resolved.
Thank you very much for your suggestions. |
|
Back to top |
|
|
|