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

Remove the hyphens from the input


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

New User


Joined: 14 Mar 2012
Posts: 81
Location: India

PostPosted: Tue May 26, 2015 5:42 pm
Reply with quote

I have an input field IN1 PIC X(12)
which might contain any numbers of hyphens. I want to remove the hyphens like:
asd--kjk-1-- should be replaced as asdkjk1
-----------i should be replaced as i

i am thinking of below options:
1) use INSPECT
2) Run a loop using perform
3) use Reference modification

Can someone please tell me which is the best and efficient one

If possible, please give me the sample code
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue May 26, 2015 5:52 pm
Reply with quote

How many input records do you have? Since Enterprise COBOL on z/OS executes hundreds of millions of COBOL statements per second of CPU time, worrying about performance (ESPECIALLY when you have no indications of a performance issue) is pointless. Just pick a method, code it up, and try it.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue May 26, 2015 6:03 pm
Reply with quote

Well, you can't do it with INSPECT. Doing it with reference-modification without a loop would be possible but an unrealistic amount of code for you to write and to have maintained.

So you do it in a loop.

Code:
MOVE SPACE TO output-filed

set your subscript items to initial values

PERFORM LENGTH OF input-field TIMES
  IF current-byte-of-input-is-hyphen ( input-subscript-item )
    increment  output-subscript-item
    MOVE current-byte-of-input ( input-subscript-item )
                                        TO current-byte-of-output
                                             ( output-subscript-item )
  END-IF
  increment  input-subscript-item
END-PERFORM


If you need it to go faster, you need to know about your data, like how many times zero, one or more than one hyphen.
Back to top
View user's profile Send private message
sandeep kumar302

New User


Joined: 14 Mar 2012
Posts: 81
Location: India

PostPosted: Wed May 27, 2015 10:22 am
Reply with quote

Quote:

How many input records do you have? Since Enterprise COBOL on z/OS executes hundreds of millions of COBOL statements per second of CPU time, worrying about performance (ESPECIALLY when you have no indications of a performance issue) is pointless. Just pick a method, code it up, and try it.


We have only 1 input record which contains hyphens and we have to remove all those hyphens.
Back to top
View user's profile Send private message
sandeep kumar302

New User


Joined: 14 Mar 2012
Posts: 81
Location: India

PostPosted: Wed May 27, 2015 10:24 am
Reply with quote

Thanks Bill

I will try your suggestions and post the solution here.
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 TRIM everything from input, output co... DFSORT/ICETOOL 1
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts force tablespace using LISTDEF input DB2 1
No new posts Two input files & writing counter... DFSORT/ICETOOL 12
Search our Forums:

Back to Top