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
 

 

Replacing spaces with NULL
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Vandana S

New User


Joined: 17 Dec 2007
Posts: 20
Location: Mumbai

PostPosted: Mon Feb 23, 2009 12:09 pm    Post subject: Replacing spaces with NULL
Reply with quote

Hi,

Please let me know how to replace spaces with null. For Eg. 'Aufgd fdu er' should be coverted to 'Aufgdfduer'. Can we do this using inspect? Also, I know we can do this using arrays using bit by bit comparison. Can anyone suggest a faster and less CPU consuming option?
Back to top
View user's profile Send private message

aishwarya_20

New User


Joined: 19 Nov 2008
Posts: 57
Location: pune

PostPosted: Mon Feb 23, 2009 1:26 pm    Post subject:
Reply with quote

You can use UNSTRING delemited by Space. and then again STRING.
Back to top
View user's profile Send private message
Vandana S

New User


Joined: 17 Dec 2007
Posts: 20
Location: Mumbai

PostPosted: Mon Feb 23, 2009 1:30 pm    Post subject:
Reply with quote

aishwarya_20 wrote:
You can use UNSTRING delemited by Space. and then again STRING.


Can you please elaborate on this? With the correct psuedo code?
Back to top
View user's profile Send private message
aishwarya_20

New User


Joined: 19 Nov 2008
Posts: 57
Location: pune

PostPosted: Mon Feb 23, 2009 1:58 pm    Post subject:
Reply with quote

01 WS-INPUT PIC X(12) VALUE 'Aufgd fdu er'
01 WS-INPUT-1 PIC X(5).
01 WS-INPUT-2 PIC X(3).
01 WS-INPUT-3 PIC X(2).
01 WS-OUTPUT PIC X(10).

.....

PROCEDURE DIVISION.

....
UNSTRING WS-INPUT DELIMITED BY SPACE
INTO WS-INPUT-1
WS-INPUT-2
WS-INPUT-3

STRING WS-INPUT-1 WS-INPUT-2 WS-INPUT-3
INTO WS-OUTPUT
DELIMITED BY SIZE.
Back to top
View user's profile Send private message
Vandana S

New User


Joined: 17 Dec 2007
Posts: 20
Location: Mumbai

PostPosted: Mon Feb 23, 2009 2:07 pm    Post subject:
Reply with quote

aishwarya_20 wrote:
01 WS-INPUT PIC X(12) VALUE 'Aufgd fdu er'
01 WS-INPUT-1 PIC X(5).
01 WS-INPUT-2 PIC X(3).
01 WS-INPUT-3 PIC X(2).
01 WS-OUTPUT PIC X(10).

.....

PROCEDURE DIVISION.

....
UNSTRING WS-INPUT DELIMITED BY SPACE
INTO WS-INPUT-1
WS-INPUT-2
WS-INPUT-3

STRING WS-INPUT-1 WS-INPUT-2 WS-INPUT-3
INTO WS-OUTPUT
DELIMITED BY SIZE.


Thanks but this would work only for this example. I need a generalised code since I do not know where spaces would occur.
Back to top
View user's profile Send private message
aishwarya_20

New User


Joined: 19 Nov 2008
Posts: 57
Location: pune

PostPosted: Mon Feb 23, 2009 2:17 pm    Post subject:
Reply with quote

Then you should use INSPECT verb to count the number of spaces in the string and Use Array to store the different strings delemited by spaces.
Back to top
View user's profile Send private message
picus_mf
Warnings : 1

New User


Joined: 09 Jun 2006
Posts: 51

PostPosted: Mon Feb 23, 2009 2:18 pm    Post subject:
Reply with quote

If your file records contains columns wise details then apply the same SRTING logic for all fields. Its the only way I guess.
else you have to use perform statements on the entire record and move the values to the left when ever you encounter a space which is tediuos and not suggestable one while having STRING verb.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2158
Location: @my desk

PostPosted: Mon Feb 23, 2009 2:37 pm    Post subject:
Reply with quote

Quote:
Then you should use INSPECT verb to count the number of spaces in the string and Use Array to store the different strings delemited by spaces
Can you explain how this works for the OPs requirement. icon_eek.gif

I think this has been discussed here many times. One simple and straight forward approach is to check for each position in your input string for spaces and move the "good" characters to your output string using reference modification.
Back to top
View user's profile Send private message
aishwarya_20

New User


Joined: 19 Nov 2008
Posts: 57
Location: pune

PostPosted: Mon Feb 23, 2009 2:53 pm    Post subject:
Reply with quote

That will be a simple approach but it will use more CPU time. And also we can not use REFERENCE MODIFICATION.

By using Inspect verb we will come to know the number of spaces in between the INPUT string. After that we will use UNSTRING verb to store the strings in ARRAY same number of times as spaces.

Then we can use STRING verb.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Feb 23, 2009 3:12 pm    Post subject:
Reply with quote

aishwarya_20 wrote:
01 WS-INPUT PIC X(12) VALUE 'Aufgd fdu er'
01 WS-INPUT-1 PIC X(5).
01 WS-INPUT-2 PIC X(3).
01 WS-INPUT-3 PIC X(2).
01 WS-OUTPUT PIC X(10).

.....

PROCEDURE DIVISION.

....
UNSTRING WS-INPUT DELIMITED BY SPACE
INTO WS-INPUT-1
WS-INPUT-2
WS-INPUT-3

STRING WS-INPUT-1 WS-INPUT-2 WS-INPUT-3
INTO WS-OUTPUT
DELIMITED BY SIZE.


chg this:
Code:
01 WS-INPUT   PIC X(12) VALUE 'Aufgd fdu er'
01 WS-INPUT-1 PIC X(5).
01 WS-INPUT-2 PIC X(3).
01 WS-INPUT-3 PIC X(2).
01 WS-OUTPUT PIC X(10).


to this:
Code:
01 WS-INPUT   PIC X(30).
01 WS-INPUT-1 PIC X(30).
01 WS-INPUT-2 PIC X(30).
01 WS-INPUT-3 PIC X(30).
01 WS-INPUT-4 PIC X(30).
01 WS-INPUT-5 PIC X(30).
01 WS-INPUT-6 PIC X(30).
01 WS-OUTPUT PIC X(30).


and this:
Code:
UNSTRING WS-INPUT   DELIMITED BY SPACE
INTO WS-INPUT-1
         WS-INPUT-2
         WS-INPUT-3

to this:
Code:
UNSTRING WS-INPUT   DELIMITED BY SPACE
INTO WS-INPUT-1
         WS-INPUT-2
         WS-INPUT-3
         WS-INPUT-4
         WS-INPUT-5
         WS-INPUT-6
END-UNSTRING


and this:
Code:
STRING  WS-INPUT-1 WS-INPUT-2 WS-INPUT-3
             INTO WS-OUTPUT
             DELIMITED BY SIZE.

to this:
Code:
STRING  WS-INPUT-1 WS-INPUT-2 WS-INPUT-3
        WS-INPUT-4 WS-INPUT-5 WS-INPUT-6
             INTO WS-OUTPUT
             DELIMITED BY SPACE END-STRING.


will remove the spaces from any string up to 6 words.
Back to top
View user's profile Send private message
aishwarya_20

New User


Joined: 19 Nov 2008
Posts: 57
Location: pune

PostPosted: Mon Feb 23, 2009 3:14 pm    Post subject:
Reply with quote

This is not the generalised code.. Using array with Depending on will be the only generalised code for this......Suppose the Input string is having more than 100 strings separated by space then what will you do?
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1219
Location: Israel

PostPosted: Mon Feb 23, 2009 3:15 pm    Post subject: Reply to: Replacing spaces with NULL
Reply with quote

CPU time seems to be an issue here.
Quote:
By using Inspect verb we will come to know the number of spaces in between the INPUT string. After that we will use UNSTRING verb to store the strings in ARRAY same number of times as spaces.

Then we can use STRING verb.

At the end, you will need to STRING all the occurences of the ARRAY.
You will need to INITIALIZE the ARRAY each time before the UNSTRING loop.
You should check that you don't have more words than occurs...

I don't think that this method will be faster than a plain byte-by-byte process of the field.
Back to top
View user's profile Send private message
aishwarya_20

New User


Joined: 19 Nov 2008
Posts: 57
Location: pune

PostPosted: Mon Feb 23, 2009 3:18 pm    Post subject:
Reply with quote

You are not getting what i am trying to tell. There is no loop for UNSTRING. There would not be any loop in this program.
Back to top
View user's profile Send private message
robin ma

New User


Joined: 19 Feb 2009
Posts: 1
Location: China

PostPosted: Mon Feb 23, 2009 3:43 pm    Post subject:
Reply with quote

How about this:

Code:
*
 3000-CONVERT-DATA.
*--------------------------
         UNSTRING STR-ORI DELIMITED BY SPACE
                                 INTO  STR-RESULT STR-ORI.
         PERFORM UNTIL WS-END-FLG
                 INITIALIZE          STR-RIGHT
                 UNSTRING STR-ORI DELIMITED BY SPACE
                                           INTO  STR-LEFT STR-RIGHT
                 STRING STR-RESULT STR-LEFT
                                           INTO STR-RESULT
                 MOVE STR-RIGHT TO STR-ORI
                 IF STR-RIGHT = LOW-VALUES OR SPACES
                     SET              WS-END-FLG  TO  TRUE
                     GO  TO      3000-CONVERT-EXIT
                 END-IF
         END-PERFORM.
 3000-CONVERT-EXIT.
         EXIT.

Though it has a loop, but I think it may use less CPU time then bit by bit process.
Back to top
View user's profile Send private message
aishwarya_20

New User


Joined: 19 Nov 2008
Posts: 57
Location: pune

PostPosted: Mon Feb 23, 2009 3:49 pm    Post subject:
Reply with quote

Yes, This is the optimized code...good
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2158
Location: @my desk

PostPosted: Mon Feb 23, 2009 4:05 pm    Post subject:
Reply with quote

aishwarya_20 wrote:
Yes, This is the optimized code...good
Optimized. But I doubt it's going to work as per the requirement. What is the PIC clause definition for STR-RESULT . What if you have trailing spaces in STR-RESULT before the STRING.
Back to top
View user's profile Send private message
aishwarya_20

New User


Joined: 19 Nov 2008
Posts: 57
Location: pune

PostPosted: Mon Feb 23, 2009 4:14 pm    Post subject:
Reply with quote

Thats what i was saying. The solution which i gave is generic and as per thwe requirement.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2158
Location: @my desk

PostPosted: Mon Feb 23, 2009 4:22 pm    Post subject:
Reply with quote

aishwarya_20 wrote:
Thats what i was saying. The solution which i gave is generic and as per thwe requirement.
The same applies to your array element as well. Also how do you know in advance, the number of elements you want to string or unstring, given that the number of spaces can vary for each record.
Back to top
View user's profile Send private message
aishwarya_20

New User


Joined: 19 Nov 2008
Posts: 57
Location: pune

PostPosted: Mon Feb 23, 2009 4:24 pm    Post subject:
Reply with quote

Dear, This is the reason i am using Occurs with Depending on option. Please read Cobol Books and Learn what is Occurs on depending on.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2158
Location: @my desk

PostPosted: Mon Feb 23, 2009 4:38 pm    Post subject:
Reply with quote

aishwarya_20 wrote:
Dear, This is the reason i am using Occurs with Depending on option. Please read Cobol Books and Learn what is Occurs on depending on.
Can you post here your STRING/UNSTRING statements.
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
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts To trim spaces in a pipe delimited da... Nish84 COBOL Programming 16 Mon Oct 10, 2016 1:54 pm
No new posts Syncsort - NULL in Integer field chec... nartcr SYNCSORT 4 Thu Oct 06, 2016 6:47 am
No new posts Removing Extra Spaces in a comma sepa... Puspojit DFSORT/ICETOOL 3 Tue Sep 13, 2016 7:46 am
No new posts Converting NULL column into NOT NULL ... Raghu navaikulam DB2 5 Sat Aug 06, 2016 3:45 pm
No new posts Replacing Start Transid with LINK pkmurali CICS 12 Tue Apr 19, 2016 8:22 pm


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