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
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
Arun Raj

Moderator


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

PostPosted: Wed Feb 25, 2009 1:59 pm
Reply with quote

Wont threre be any impact in the "SLA" when 50-100 million records are processed twice first thru a SORT and then a program, rather than a single pass thru the program? icon_rolleyes.gif
Back to top
View user's profile Send private message
Arun Raj

Moderator


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

PostPosted: Wed Feb 25, 2009 3:29 pm
Reply with quote

I agree with that. We can talk about the adv/disadvantages of both the approaches, but we never know which one is suitable for the OP unless we have a clear picture of the whole business process. It's upto him to decide icon_smile.gif
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Wed Feb 25, 2009 10:25 pm
Reply with quote

aishwarya_20, I'm also curious to know why, "And also we can not use REFERENCE MODIFICATION." Is it because of an older compiler you are limited to?
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: Sat Feb 28, 2009 2:24 am
Reply with quote

Hello Vandana S,

Do you have a solution that works for you?
Back to top
View user's profile Send private message
Vandana S

New User


Joined: 17 Dec 2007
Posts: 20
Location: Mumbai

PostPosted: Mon Mar 02, 2009 3:42 pm
Reply with quote

dick scherrer wrote:
Hello Vandana S,

Do you have a solution that works for you?


Hi, most of the discussion were fruitful. However, I then came up with a lesser CPU consuming (but perhaps more time consuming) option:

PS-NBR--->X(40)
PS-NBR-TEMP---->X(40)

INITIALIZE PS-NBR-TEMP
MOVE 1 TO L
PERFORM VARYING K FROM 1 BY 1 UNTIL K > 40
IF PS-NBR (K:1) = SPACE
CONTINUE
ELSE
MOVE PS-NBR (K:1) TO PS-NBR-TEMP (L:1)
ADD 1 TO L
END-IF
END-PERFORM

Please let me know if any one has a better solution than this. Pls note that CPU consumption should also be taken in to consideration while solutioning this.
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 Mar 02, 2009 7:15 pm
Reply with quote

I'm puzzled. You had said that you weren't allowed to use reference modification and several members (including myself) were under the impression that your compiler did not support reference modification (OS/VS COBOL). But yet, your most recent positing example uses an in-line PERFORM and the END-IF statement, which were introduced with COBOL2, along with reference modification. So, it seems that you have a compiler which supports reference modification and I'm trying to grasp exactly what the issues were from the onset of this thread.

Was this a shop restriction and/or did management prohibit its use altogether?

Enquiring minds want to know....

Bill
Back to top
View user's profile Send private message
Vandana S

New User


Joined: 17 Dec 2007
Posts: 20
Location: Mumbai

PostPosted: Mon Mar 02, 2009 7:23 pm
Reply with quote

Not sure why the discussion talked about not being able to use reference modification,etc. If you check my post right at the onset, it would just tell you what my requirement is and a quicker and an efficient way to acheive it. I hope this puts to rest all the doubts.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Mon Mar 02, 2009 9:41 pm
Reply with quote

Don't you hate it when somebody gives replies as if he was the original requester?
Very often, there is a small difference in the environment, or in the request itself,
and when this happens, we are just loosing our time!

Back to the subject:
In the end, it is the plain byte-by-byte process of the field that won the race, isn't it ??
Back to top
View user's profile Send private message
Arun Raj

Moderator


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

PostPosted: Tue Mar 03, 2009 12:04 am
Reply with quote

Quote:
In the end, it is the plain byte-by-byte process of the field that won the race, isn't it ??
Guess so . icon_smile.gif
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: Tue Mar 03, 2009 1:26 am
Reply with quote

aishwarya_20 wrote:
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.

I pointed to the wrong member (not the original OP) regarding the inability to use REFERENCE MODIFICATION.

But, this thread did get somewhat convoluted and I lost track of all the players involved. icon_confused.gif

Bill
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Tue Mar 03, 2009 5:51 am
Reply with quote

Guess we beat that horse to death, didn't we? icon_lol.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 Replacing 'YYMMDD' with date, varying... SYNCSORT 3
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
Search our Forums:

Back to Top