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

Need Help on variable Trimming


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

New User


Joined: 20 Jun 2005
Posts: 6

PostPosted: Wed Feb 07, 2007 11:28 am
Reply with quote

Hi All,

I have a variable A=a_a______aaaaa(_ = SPACES) i need finally
A or B=a_a_aaaaa how to do this? NOTE:SPACES may not be same all the time it may be 2 or 3 or 4..
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Wed Feb 07, 2007 1:55 pm
Reply with quote

vijaymfdata wrote:
I have a variable A=a_a______aaaaa(_ = SPACES) i need finally A or B=a_a_aaaaa how to do this? NOTE:SPACES may not be same all the time it may be 2 or 3 or 4..
Are you saying that you want to replace multiple spaces with a single space in a string?
Back to top
View user's profile Send private message
vijaymfdata

New User


Joined: 20 Jun 2005
Posts: 6

PostPosted: Wed Feb 07, 2007 3:20 pm
Reply with quote

Yes
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Wed Feb 07, 2007 3:32 pm
Reply with quote

The simplest might be a perform loop with reference modification, increment thru the variable looking for multiple spaces and when found slide the remaining data left to eliminate them.
Back to top
View user's profile Send private message
vijaymfdata

New User


Joined: 20 Jun 2005
Posts: 6

PostPosted: Wed Feb 07, 2007 4:18 pm
Reply with quote

Hi Thompson,

Thank you for your reply.Could you please elaborate your words,I have got broad udestanding and also im facing another problem like i have a variable of x(20) it may contain value like 'a__+.aaa--aaa@@aaa-*'(list of posiible special char i have it on array of size 5). i need final result like 'a_aaa_aaa' that is why i planned to convert all special char to spaces then to multiple spaces to single space is this the right way.

Please ask if you need any clarification on this

Regards
Vijay
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Wed Feb 07, 2007 4:35 pm
Reply with quote

vijaymfdata wrote:
Thank you for your reply.Could you please elaborate your words,I have got broad udestanding and also im facing another problem like i have a variable of x(20) it may contain value like 'a__+.aaa--aaa@@aaa-*'(list of posiible special char i have it on array of size 5). i need final result like 'a_aaa_aaa' that is why i planned to convert all special char to spaces then to multiple spaces to single space is this the right way.
instead of
Code:
if area(i:2) = spaces

you could
Code:
if area(i:1)   = bad(1)
              or bad(2)
              or bad(3)
              or bad(4)
              or bad(5) and
   area(i+1:1) = bad(1)
              or bad(2)
              or bad(3)
              or bad(4)
              or bad(5)
while you increment thru the variable.
Back to top
View user's profile Send private message
Shanu.sukoor

New User


Joined: 31 Jan 2006
Posts: 32
Location: India

PostPosted: Thu Feb 08, 2007 3:23 am
Reply with quote

Another solution

Redefine the string with occurs class having PIC value X(1). Perform a para for each character with the following logic


In the para have an indicator which will indicate whether a space has been written for the previous bad character( _ @ $%^..)

Move valid character to a new string whenever you meet it.

Whenever u meet a bad data move a space and set the indicator. Do not move any space for bad data if you the indicator is already set. Reset the indicator whenever you meet a valid data.

Please let me if you are gonna try this!!
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Thu Feb 08, 2007 3:41 am
Reply with quote

Shanu.sukoor wrote:
Another solution
Redefine the string with occurs class having PIC value X(1). Perform a para for each character with the following logic
Retro, boy, that's what RM freed us from.....
Young'ns, old is new and new is old.....grumble....grumble.... icon_biggrin.gif
Back to top
View user's profile Send private message
vijaymfdata

New User


Joined: 20 Jun 2005
Posts: 6

PostPosted: Thu Feb 08, 2007 10:53 am
Reply with quote

U r logic will work for single char comparision.consider following example
'A=aa++aa___aaPLUSaaMINUSaaBLANKaa' then i need A=aa_aa_aa_aa_aa_aa (here PLUS,MINUS,BLANK,+,_*.... are possible special char.all possible special chars are in an array)
Back to top
View user's profile Send private message
chaudhary1984

New User


Joined: 03 Oct 2006
Posts: 5

PostPosted: Thu Feb 08, 2007 11:50 am
Reply with quote

what is difference between buffer & buffer space?
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: Thu Feb 08, 2007 8:32 pm
Reply with quote

Hello,

I believe this should start a new topic - it does not appear to be related to the current thread.

When you want to ask a new question please do not use "reply" to an existing topic, but rather use "new topic" and you will get more and better replies.

In answer to your buffer question, they are both the "same" thing - some amount of memory typically used to improve i/o performance (there can be other buffers, but i/o is one of the most common). For example, when your program "reads" blocked input, usually it is a transfer from a buffer rather than a physical read of the device. Another way to think of it is that the buffer is where the i/o takes place and buffer space is the memory allocated for the buffer.
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Fri Feb 09, 2007 2:03 am
Reply with quote

vijaymfdata,

Code:

01  WORD-LIST.
    05  FILLER       PIC X(10)  VALUE ?-         ?.
    05  FILLER       PIC X(10)  VALUE ?+         ?.
    05  FILLER       PIC X(10)  VALUE ?PLUS      ?.
    05  FILLER       PIC X(10)  VALUE ?MINUS     ?.
    05  FILLER       PIC X(10)  VALUE ?%         ?.
01  WORD-TABLE RTEDEFINES WORD-LIST.
    05  SPECIAL-WORD PIC X(10)  OCCURS 5 TIMES.


Is this correct?
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Fri Feb 09, 2007 3:17 am
Reply with quote

Kinda funny, I just ran into a situation where I needed to remove certain junk from a buffer area. I whipped this routine up to do just that:
Code:
     MOVE ZERO TO T
     PERFORM TEST AFTER                                   
             VARYING F FROM 1 BY 1                       
               UNTIL F > W00-DATALENGTH                   
         COMPUTE T = T + 1                               
*  CDATA - What they were                                 
         IF W00-MSGBUFFER(F:1) = X'4C' AND               
            W00-MSGBUFFER(F:9) = X'4C4F4AC3C4C1E3C14A'   
             COMPUTE F = F + 9                           
         END-IF                                           
*  CDATA - What they might be                             
         IF W00-MSGBUFFER(F:1) = X'4C' AND               
            W00-MSGBUFFER(F:9) = X'4C5AADC3C4C1E3C1AD'   
             COMPUTE F = F + 9                           
         END-IF                                           
*  CDATA - What they were                                 
         IF W00-MSGBUFFER(F:1) = X'5A' AND               
            W00-MSGBUFFER(F:3) = X'5A5A6E'               
             COMPUTE F = F + 3                           
         END-IF                                           
*  CDATA - What they might be                             
         IF W00-MSGBUFFER(F:1) = X'BD' AND               
            W00-MSGBUFFER(F:3) = X'BDBD6E'               
             COMPUTE F = F + 3                           
         END-IF                                           
* Imbeded leading spaces                                         
         IF W00-MSGBUFFER(F - 1:2) = X'6E40'             
            PERFORM UNTIL W00-MSGBUFFER(F:1) NOT = X'40' 
               COMPUTE F = F + 1                         
            END-PERFORM                                   
         END-IF                                           
*                                                         
         MOVE W00-MSGBUFFER(F:1) TO W00-MSGBUFFER(T:1)   
     END-PERFORM                                         
     MOVE T TO W00-DATALENGTH

Surprisingly it works quite well. The two compares, the first for one byte and the second for the string in question was done because I know the first would produce a CLI (which would be false almost all the time) which will execute faster than the CLC generated by the second.
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 Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Variable Output file name DFSORT/ICETOOL 8
No new posts Moving Or setting POINTER to another ... COBOL Programming 2
No new posts parsing variable length/position data... DFSORT/ICETOOL 5
No new posts Masking variable size field - min 10 ... DFSORT/ICETOOL 4
Search our Forums:

Back to Top