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

Replacing spaces with NULL


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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
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
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
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
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: 52

PostPosted: Mon Feb 23, 2009 2:18 pm
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: 2481
Location: @my desk

PostPosted: Mon Feb 23, 2009 2:37 pm
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
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
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
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: 1353
Location: Israel

PostPosted: Mon Feb 23, 2009 3:15 pm
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
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
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
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: 2481
Location: @my desk

PostPosted: Mon Feb 23, 2009 4:05 pm
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
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: 2481
Location: @my desk

PostPosted: Mon Feb 23, 2009 4:22 pm
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
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: 2481
Location: @my desk

PostPosted: Mon Feb 23, 2009 4:38 pm
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
aishwarya_20

New User


Joined: 19 Nov 2008
Posts: 57
Location: pune

PostPosted: Mon Feb 23, 2009 4:42 pm
Reply with quote

If I is the count of number of spaces then

COMPUTE I = I +1

UNSTRING WS-INPUT INTO
WS-ARRAY[1]
WS-ARRAY[2]
.......................................
WS-ARRAY[I]
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Feb 23, 2009 9:06 pm
Reply with quote

Hello,

Quote:
Yes, This is the optimized code...good
Clarify optimized. . . Surely not for system resource utilization. The code is very nicely presented, though.

Quote:
we can not use REFERENCE MODIFICATION
And the business reason for this. . . icon_confused.gif The feature has been standard for a long, long time.

Quote:
Please read Cobol Books and Learn what is Occurs on depending on.
Please do not make such suggestions to people who are far senior to your experience level. . .
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Mon Feb 23, 2009 9:35 pm
Reply with quote

If you're on OS/VS COBOL (version previous to COBOL II), then yes, REFERENCE MODIFICATION is not available.

The following will work, regardless of the COBOL version/release -

Code:

03  WS-INPUT PIC X(12) VALUE 'Aufgd fdu er'.
03  WS-INPUT-TBL REDEFINES WS-INPUT OCCURS 12 TIMES PIC X(01).
03  WS-OUTPUT PIC X(12) VALUE SPACES.
03  WS-OUTPUT-TBL REDEFINES WS-OUTPUT OCCURS 12 TIMES PIC X(01).
03  WS-INPUT-SUB PIC 9(04) COMP.
03  WS-OUTPUT-SUB PIC 9(04) COMP VALUE ZERO.

PERFORM 9000-REMOVE-SPACES VARYING WS-INPUT-SUB FROM 1 BY 1                                                   UNTIL WS-INPUT-SUB > 12.

9000-REMOVE-SPACES.
    IF  WS-INPUT-TBL (WS-INPUT-SUB) > SPACE
        ADD  1 TO WS-OUTPUT-SUB
        MOVE WS-INPUT-TBL (WS-INPUT-SUB) TO WS-OUTPUT-TBL (WS-OUTPUT-SUB).

At this point "WS-OUTPUT" equals 'Aufgdfduer' left-justified and padded with low-order spaces.

Regards,
Back to top
View user's profile Send private message
ykishor
Currently Banned

New User


Joined: 11 Aug 2007
Posts: 24
Location: my pc

PostPosted: Tue Feb 24, 2009 9:54 pm
Reply with quote

Hello,
If u r not restricted to COBOL then I suggest DFSORT/ICETOOL and if u r looking for optimization it will difficult to beat this(I guess so icon_smile.gif :

OPTION COPY
INREC OVERLAY=(start,length,SQZ=(SHIFT=LEFT,PREBLANK=C' '))

the SQZ function will squeeze out all the spaces and then left justify all characters seperated by spaces..u can RIGHT justify as well... take care of RECFM and max record length..
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Feb 25, 2009 12:35 am
Reply with quote

Hello,

Quote:
If u r not restricted to COBOL then I suggest DFSORT/ICETOOL and if u r looking for optimization it will difficult to beat this
Only if the entire program logic can cleanly be replaced with sort control statements.

Most requirements have more than this as their only objective. Usually more than one file is processed or there is interaction with database tables and/or vsam files. . .

There have been rather horrible cases where someone wrote code to "do" something that created a large file to be processed by something like SQZ (so they wouldn't have to code) that wrote the modified file into a dataset so yet another program could do the business processing. Utter nonsense icon_neutral.gif
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 Goto page 1, 2  Next

 


Similar Topics
Topic Forum Replies
No new posts leading spaces can be removed in trai... DFSORT/ICETOOL 1
No new posts Null values are considered in Total c... DFSORT/ICETOOL 6
No new posts Cobol program with sequence number ra... COBOL Programming 5
No new posts the system or user abend SF0F R=NULL COBOL Programming 0
No new posts To Remove spaces (which is in hex for... JCL & VSAM 10
Search our Forums:

Back to Top