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

Unstring and String in Cobol


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

New User


Joined: 15 Nov 2007
Posts: 36
Location: India

PostPosted: Wed Nov 21, 2007 3:42 pm
Reply with quote

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 '&amp'.
After replacing only I want to move it to addr-1.
How can I achieve this?

Thanks in advance.
Back to top
View user's profile Send private message
kovur

New User


Joined: 15 Nov 2007
Posts: 36
Location: India

PostPosted: Wed Nov 21, 2007 4:05 pm
Reply with quote

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 '&amp'

Thanks
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Wed Nov 21, 2007 4:14 pm
Reply with quote

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 '&amp'.
Back to top
View user's profile Send private message
kovur

New User


Joined: 15 Nov 2007
Posts: 36
Location: India

PostPosted: Wed Nov 21, 2007 4:23 pm
Reply with quote

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
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Wed Nov 21, 2007 4:26 pm
Reply with quote

Kovur,

Im confused. icon_confused.gif

How 30 bytes are related to 75 bytes?
Back to top
View user's profile Send private message
kovur

New User


Joined: 15 Nov 2007
Posts: 36
Location: India

PostPosted: Wed Nov 21, 2007 4:37 pm
Reply with quote

In the DB2 table we don't have address greater than 30 bytes. Therefore I think If we change the '&' as '&amp' nothing will be truncated.
Back to top
View user's profile Send private message
kovur

New User


Joined: 15 Nov 2007
Posts: 36
Location: India

PostPosted: Wed Nov 21, 2007 4:56 pm
Reply with 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.
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: Wed Nov 21, 2007 6:32 pm
Reply with quote

kovur wrote:
I want to replace the '&' symbol in the ws-addr1 with the '&amp'.
How many '&' might appear in this string, is it known or not?
Back to top
View user's profile Send private message
kovur

New User


Joined: 15 Nov 2007
Posts: 36
Location: India

PostPosted: Wed Nov 21, 2007 6:40 pm
Reply with quote

we don't know exactly. We need to change every '&' into '&amp'.

Thanks
Back to top
View user's profile Send private message
shankar.v

Active User


Joined: 25 Jun 2007
Posts: 196
Location: Bangalore

PostPosted: Wed Nov 21, 2007 6:50 pm
Reply with quote

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 '&AMP'.

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 '&AMP' 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
View user's profile Send private message
kovur

New User


Joined: 15 Nov 2007
Posts: 36
Location: India

PostPosted: Wed Nov 21, 2007 6:58 pm
Reply with quote

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&ampMumbai&ampKolkata&ampChennai
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 631
Location: Wisconsin

PostPosted: Wed Nov 21, 2007 7:31 pm
Reply with quote

Are you converting this to XML and that is why you need the &amp?

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 '&lt;' Delimited by Size         
            Into XML-O-DOC                       
            With Pointer XML-O-LEN               
      When '&'                                   
        String '&amp;' 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
View user's profile Send private message
shankar.v

Active User


Joined: 25 Jun 2007
Posts: 196
Location: Bangalore

PostPosted: Wed Nov 21, 2007 7:42 pm
Reply with quote

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 '&AMP'?.
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 '&AMP' 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
View user's profile Send private message
kovur

New User


Joined: 15 Nov 2007
Posts: 36
Location: India

PostPosted: Wed Nov 21, 2007 7:56 pm
Reply with quote

If my address line is like this

Delhi & Kolkata & Mumbai & Chennai

then also I need to change the & into &amp.

After changing it, the data will not be truncated.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 631
Location: Wisconsin

PostPosted: Wed Nov 21, 2007 7:59 pm
Reply with quote

Have you tried shankar.v's solution? It appears that it has a high likelihood of working.
Back to top
View user's profile Send private message
shankar.v

Active User


Joined: 25 Jun 2007
Posts: 196
Location: Bangalore

PostPosted: Wed Nov 21, 2007 8:10 pm
Reply with quote

kovur,
Quote:
If my address line is like this

Delhi & Kolkata & Mumbai & Chennai

then also I need to change the & into &amp.

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
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Thu Nov 22, 2007 11:12 am
Reply with quote

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 '&amp' 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
View user's profile Send private message
kovur

New User


Joined: 15 Nov 2007
Posts: 36
Location: India

PostPosted: Sat Nov 24, 2007 12:10 pm
Reply with quote

Hi Friends,

My problem was resolved.
Thank you very much for your suggestions.
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 COBOL sorting, with input GDG base COBOL Programming 7
No new posts Need help with ADABAS query (COBOL-AD... All Other Mainframe Topics 0
No new posts Copy only TEXT or String from a record SYNCSORT 4
No new posts Replacing FILLER with FILLER<SeqNu... DFSORT/ICETOOL 2
No new posts ICETOOL to SUM String DFSORT/ICETOOL 1
Search our Forums:

Back to Top