View previous topic :: View next topic
|
Author |
Message |
Vandana S
New User
Joined: 17 Dec 2007 Posts: 20 Location: Mumbai
|
|
|
|
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 |
|
|
aishwarya_20
New User
Joined: 19 Nov 2008 Posts: 57 Location: pune
|
|
|
|
You can use UNSTRING delemited by Space. and then again STRING. |
|
Back to top |
|
|
Vandana S
New User
Joined: 17 Dec 2007 Posts: 20 Location: Mumbai
|
|
|
|
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 |
|
|
aishwarya_20
New User
Joined: 19 Nov 2008 Posts: 57 Location: pune
|
|
|
|
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 |
|
|
Vandana S
New User
Joined: 17 Dec 2007 Posts: 20 Location: Mumbai
|
|
|
|
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 |
|
|
aishwarya_20
New User
Joined: 19 Nov 2008 Posts: 57 Location: pune
|
|
|
|
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 |
|
|
picus_mf Warnings : 1 New User
Joined: 09 Jun 2006 Posts: 52
|
|
|
|
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 |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
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.
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 |
|
|
aishwarya_20
New User
Joined: 19 Nov 2008 Posts: 57 Location: pune
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
aishwarya_20
New User
Joined: 19 Nov 2008 Posts: 57 Location: pune
|
|
|
|
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 |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
aishwarya_20
New User
Joined: 19 Nov 2008 Posts: 57 Location: pune
|
|
|
|
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 |
|
|
robin ma
New User
Joined: 19 Feb 2009 Posts: 1 Location: China
|
|
|
|
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 |
|
|
aishwarya_20
New User
Joined: 19 Nov 2008 Posts: 57 Location: pune
|
|
|
|
Yes, This is the optimized code...good |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
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 |
|
|
aishwarya_20
New User
Joined: 19 Nov 2008 Posts: 57 Location: pune
|
|
|
|
Thats what i was saying. The solution which i gave is generic and as per thwe requirement. |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
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 |
|
|
aishwarya_20
New User
Joined: 19 Nov 2008 Posts: 57 Location: pune
|
|
|
|
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 |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
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 |
|
|
aishwarya_20
New User
Joined: 19 Nov 2008 Posts: 57 Location: pune
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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. . . 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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
ykishor Currently Banned New User
Joined: 11 Aug 2007 Posts: 24 Location: my pc
|
|
|
|
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 :
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
Back to top |
|
|
|