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
 

 

Unstring and String in Cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
kovur

New User


Joined: 15 Nov 2007
Posts: 37
Location: India

PostPosted: Wed Nov 21, 2007 3:42 pm    Post subject: Unstring and String in Cobol
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: 37
Location: India

PostPosted: Wed Nov 21, 2007 4:05 pm    Post subject:
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: 1439
Location: Bangalore,India

PostPosted: Wed Nov 21, 2007 4:14 pm    Post subject:
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: 37
Location: India

PostPosted: Wed Nov 21, 2007 4:23 pm    Post subject:
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: 1439
Location: Bangalore,India

PostPosted: Wed Nov 21, 2007 4:26 pm    Post subject:
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: 37
Location: India

PostPosted: Wed Nov 21, 2007 4:37 pm    Post subject:
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: 37
Location: India

PostPosted: Wed Nov 21, 2007 4:56 pm    Post subject:
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: 2150
Location: At my coffee table

PostPosted: Wed Nov 21, 2007 6:32 pm    Post subject: Re: Unstring and String in Cobol
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: 37
Location: India

PostPosted: Wed Nov 21, 2007 6:40 pm    Post subject:
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    Post subject:
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: 37
Location: India

PostPosted: Wed Nov 21, 2007 6:58 pm    Post subject:
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: 632
Location: Wisconsin

PostPosted: Wed Nov 21, 2007 7:31 pm    Post subject:
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    Post subject:
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: 37
Location: India

PostPosted: Wed Nov 21, 2007 7:56 pm    Post subject:
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: 632
Location: Wisconsin

PostPosted: Wed Nov 21, 2007 7:59 pm    Post subject:
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    Post subject:
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: 1439
Location: Bangalore,India

PostPosted: Thu Nov 22, 2007 11:12 am    Post subject:
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: 37
Location: India

PostPosted: Sat Nov 24, 2007 12:10 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm
No new posts COBOL Version 6.1 Virendra Shambharkar COBOL Programming 5 Tue Nov 01, 2016 11:24 am
No new posts Cobol list of programs being called biswajit.dattagupta COBOL Programming 5 Tue Nov 01, 2016 2:10 am
No new posts Can sending 5 MB data between cobol p... Kevin Vaz CICS 12 Tue Oct 18, 2016 4:50 pm


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