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
 

 

Replace "&" with "AND"

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

New User


Joined: 25 Jun 2008
Posts: 24
Location: Pune

PostPosted: Wed Apr 10, 2013 4:15 am    Post subject: Replace "&" with "AND"
Reply with quote

Hello,

I have to make a replacement of the character "&" with " and " in a cobol program. The result should be :

"You&Me" or "You & Me" should be replaced with "You and Me". Any advice
Back to top
View user's profile Send private message

Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed Apr 10, 2013 4:48 am    Post subject: Reply to: Replace "&" with "AND"
Reply with quote

Have you reviewed the INSPECT verb or use an In-Line PERFORM?
Back to top
View user's profile Send private message
mistah kurtz

Active User


Joined: 28 Jan 2012
Posts: 283
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Wed Apr 10, 2013 11:14 am    Post subject:
Reply with quote

As Bill has correctly pointed out, you can use INSPECT and PERFORM to achieve this.

Please refer to the below for a working code:

Code:
       WORKING-STORAGE SECTION.                                         
          01 WS-STRING              PIC X(40)  VALUE SPACES.           
          01 WS-TEMP-STRING         PIC X(40)  VALUE SPACES.           
          01 WS-REP-STR             PIC X      VALUE '&' .             
          01 WS-CNT                 PIC 9      VALUE ZERO.             
          01 WS-CHAR-CNT-B          PIC 99     VALUE ZERO.             
          01 WS-CHAR-CNT-A          PIC 99     VALUE ZERO.             
          01 WS-CHAR-CNT-P          PIC 99     VALUE ZERO.             
                                                                       
       PROCEDURE DIVISION.                                             
            ACCEPT WS-STRING.                                           
                                                                       
            DISPLAY "VAR BEFORE: " WS-STRING.                           
                                                                       
            INSPECT WS-STRING TALLYING WS-CNT FOR ALL WS-REP-STR       
                                                                       
            PERFORM UNTIL WS-CNT = ZERO                                 
                                                                       
            IF WS-CNT NOT = ZERO                                       
                                                                       
               INSPECT WS-STRING TALLYING WS-CHAR-CNT-B                 
                       FOR CHARACTERS BEFORE INITIAL WS-REP-STR         
                                                                       
               INSPECT WS-STRING TALLYING WS-CHAR-CNT-A                 
                       FOR CHARACTERS AFTER INITIAL WS-REP-STR         
                                                                       
               COMPUTE WS-CHAR-CNT-P = WS-CHAR-CNT-B + 2               
                                                                       
               EVALUATE TRUE                                           
                 WHEN WS-STRING(WS-CHAR-CNT-B:1) = SPACE AND           
                      WS-STRING(WS-CHAR-CNT-P:1) = SPACE               
                   STRING  WS-STRING(1:WS-CHAR-CNT-B) "AND"             
                           WS-STRING(WS-CHAR-CNT-P:WS-CHAR-CNT-A)       
                   DELIMITED BY SIZE INTO WS-TEMP-STRING               
                                                                       
                 WHEN WS-STRING(WS-CHAR-CNT-B:1) = SPACE AND           
                      WS-STRING(WS-CHAR-CNT-P:1) NOT = SPACE           
                   STRING  WS-STRING(1:WS-CHAR-CNT-B) "AND "           
                           WS-STRING(WS-CHAR-CNT-P:WS-CHAR-CNT-A)       
                   DELIMITED BY SIZE INTO WS-TEMP-STRING               
                                                                       
                 WHEN WS-STRING(WS-CHAR-CNT-B:1) NOT = SPACE AND       
                      WS-STRING(WS-CHAR-CNT-P:1) = SPACE               
                   STRING  WS-STRING(1:WS-CHAR-CNT-B) " AND"           
                           WS-STRING(WS-CHAR-CNT-P:WS-CHAR-CNT-A)       
                   DELIMITED BY SIZE INTO WS-TEMP-STRING               
                                                                       
                 WHEN WS-STRING(WS-CHAR-CNT-B:1) NOT = SPACE AND       
                      WS-STRING(WS-CHAR-CNT-P:1) NOT = SPACE           
                   STRING  WS-STRING(1:WS-CHAR-CNT-B) " AND "           
                           WS-STRING(WS-CHAR-CNT-P:WS-CHAR-CNT-A)       
                   DELIMITED BY SIZE INTO WS-TEMP-STRING               
                                                                       
               END-EVALUATE                                             
                                                                       
               MOVE WS-TEMP-STRING TO WS-STRING                         
                                                                       
            END-IF                                                     
                                                                       
            MOVE ZERO   TO WS-CNT                                       
            MOVE ZERO   TO WS-CHAR-CNT-A                               
            MOVE ZERO   TO WS-CHAR-CNT-B                               
            MOVE ZERO   TO WS-CHAR-CNT-P                               
            MOVE SPACES TO WS-TEMP-STRING                               
                                                                       
            INSPECT WS-STRING TALLYING WS-CNT FOR ALL WS-REP-STR       
                                                                       
            END-PERFORM.                                               
                                                                       
            DISPLAY "VAR AFTER: " WS-STRING.                           
              STOP RUN.                                                 


RUN JCL:

Code:
//STEP01  EXEC PGM=PGMXX                     
//STEPLIB   DD DSN=XXXX.YYY.LOAD,DISP=SHR
//SYSOUT    DD SYSOUT=*                     
//SYSIN     DD *                             
YOU& ME &I & US&THEM                         
//*   


Output:
Code:
 VAR BEFORE: YOU& ME &I & US&THEM           
 VAR AFTER: YOU AND ME AND I AND US AND THEM
Back to top
View user's profile Send private message
soumen2255

New User


Joined: 25 Jun 2008
Posts: 24
Location: Pune

PostPosted: Thu Apr 11, 2013 3:38 am    Post subject: Reply to: Replace "&" with "AND"
Reply with quote

Thanks Bill and Mistah, That helped me alot , also helped me to understand more on the string manipulation logic.

Thanks again.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7315

PostPosted: Thu Apr 11, 2013 4:13 am    Post subject: Reply to: Replace "&" with "AND"
Reply with quote

It would be really good if you gave some more detailed examples of what is possible. If the data is entered by a user, and not validated for it, there are going to be examples of && and perhaps even &&&. You'll probably also have some &'s which shouldn't be there.

You show "mixed-case". If that reflects your data, then you should include that as a means of identifying some "suspect" data.

You can't just rip through a big bunch of data without preparation and thought.

Why do you need to change the & anyway?

What type of data is it?

Is it from now on going to be "trapped" at input?

Or are you going to get a new load of them on your data, or is your program going to aimlessly run on everything daily looking for them and potentially garbling something?

&ellow. Oh, look, I just made a typo. Now it's going to be andellow.
Back to top
View user's profile Send private message
mistah kurtz

Active User


Joined: 28 Jan 2012
Posts: 283
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Thu Apr 11, 2013 11:24 am    Post subject:
Reply with quote

Hi Soumen..You are welcome..but I have covered very specific cases..the one you have mentioned in your initial post..you can see in my run example.
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
No new posts Fileaid Update Replace with null string descann Compuware & Other Tools 4 Mon May 15, 2017 3:00 pm
No new posts Replace values in the input data Vikas Maharnawar DFSORT/ICETOOL 10 Thu May 11, 2017 2:18 pm
No new posts READ A PACKED "NEGATIVE" FI... jdesouza CA Products 3 Tue May 02, 2017 11:43 pm
No new posts RC 20 for Address ISPEXEC "ISRED... pkmurali CLIST & REXX 3 Sun Apr 16, 2017 11:30 pm
No new posts Amount field is getting corrupted whe... thesumitk SYNCSORT 5 Tue Oct 18, 2016 8:20 pm


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