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

STRING - To space out a word if coming at the end of variabl


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

Active User


Joined: 02 Oct 2008
Posts: 179
Location: India

PostPosted: Wed Aug 25, 2010 9:27 pm
Reply with quote

Hi all,

My reqt is to space out the word 'TRAN' if coming at the end of the WS-DATA variable. The word 'TRAN' if coming in the middle of the data should not be spaced out.

01 WS-DATA PIC X(30).

Input
GEORGE HILA AND ROAD LANE TRAN
GEORGE HILA AND TRAN ROAD LANE TRAN
MORROW MOTORS INC TRAN BENZ
STERLING JEEP COMP INC TRAN

Output
GEORGE HILA AND ROAD LANE
GEORGE HILA AND TRAN ROAD LANE
MORROW MOTORS INC TRAN BENZ
STERLING JEEP COMP INC


Code
Code:
UNSTRING WS-DATA DELIMITED BY 'TRAN' INTO   
         WS-NAME-FIRST, WS-NAME-SECOND         
IF WS-NAME-SECOND = SPACES                     
    INSPECT WS-DATA REPLACING ALL 'TRAN'  BY SPACES .
ELSE
    CONTINUE
END-IF     


The above code will remove the TRAN if it comes in between words too, which is not correct.

Please guide me.

Thanks
Vinu
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Wed Aug 25, 2010 9:51 pm
Reply with quote

Hello,

Code a loop to start at the "end" of the data looking for TRAN is the first 4 non-blank characters. When found, move spaces to those bytes.

Suggest you consider Reference Modification.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Aug 25, 2010 10:51 pm
Reply with quote

thinking
Back to top
View user's profile Send private message
Mickeydusaor

Active User


Joined: 24 May 2006
Posts: 258
Location: Salem, Oregon

PostPosted: Wed Aug 25, 2010 11:05 pm
Reply with quote

What cobol version are you using.???
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Aug 25, 2010 11:18 pm
Reply with quote

1. use END-UNSTRING if your are using END-IF,
apparently you are only using one period . per paragraph/section.

2. you have a period in the middle of your IF statement.

3. change your if statement to:
Code:

IF WS-NAME-SECOND = SPACES                     
    MOVE WS-NAME-FIRST TO WS-DATA
ELSE
    MOVE SPACES TO WS-DATA
    STRING WS-NAME-FIRST
                 DELIMITED BY '  '         <<<<that is two spaces
           ' TRAN '
                 DELIMITED BY SIZE
           WS-NAME-SECOND
                 DELIMITED BY SIZE
        INTO WS-DATA
    END-STRING       
END-IF     


when you UNSTRING was finished either
  • WS-NAME-SECOND = spaces because there was only and 'ending' tran
  • WS-NAME-SECOND > SPACES because there was a 'tran' in the middle

regardless, the ending tran will always be dropped, because that is a delimiter and is dropped - regardless.
and don't argue, your code proves this...
Splitting data items (UNSTRING): Delimiters that, when one of them is encountered in the sending field, cause the
current receiving field to stop receiving and the next, if any, to begin receiving
(DELIMITED BY phrase)


so, your error was in not understanding UNSTRING
and the erroneously unnecessary INSPECT in your backasswards IF statement.
Plus the INSPECT statement put a hole of 4 spaces in your data.
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 179
Location: India

PostPosted: Thu Aug 26, 2010 4:56 am
Reply with quote

Hi Dick Brenholtz,

Thanks for the code.
The only issue with this is that if 'TRAN' comes in the variable mroe than 2 times, we will get wrong results.

GEORGE HILA TRAN AND TRAN ROAD LANE TRAN

is coming as

GEORGE HILA TRAN AND

So whether reference modification is the only solution ?

Rgds
Vinu
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Thu Aug 26, 2010 5:14 am
Reply with quote

Hello,

No, you could write convoluted code that worked on the array one byte at a time using a subscript/index.

What is the concern about reference modification?
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 179
Location: India

PostPosted: Thu Aug 26, 2010 5:49 am
Reply with quote

Hi D.sch,

Yes. I got the desired results with the following code.

Code:
MOVE FUNCTION REVERSE(WS-DATA) TO WS-DATA-REVERSE
INSPECT WS-DATA-REVERSE TALLYING WS-K FOR LEADING SPACES
COMPUTE WS-NAME-LEN = 30 - WS-K
IF WS-NAME-LEN > 0
   IF WS-DATA(WS-NAME-LEN - 4 : 5 ) = ' TRAN'
      MOVE WS-DATA(1: WS-NAME-LEN - 5) TO  WS-OUTPUT
   ELSE
      MOVE WS-DATA TO WS-OUTPUT
   END-IF
ELSE
   MOVE WS-DATA TO WS-OUTPUT
END-IF


Thanks
Vinu
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Aug 26, 2010 5:54 am
Reply with quote

vinu78 wrote:
The only issue with this is that if 'TRAN' comes in the variable mroe (sic) than 2 times, we will get wrong results.


you are correct,
nice solution.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Thu Aug 26, 2010 7:49 am
Reply with quote

Good to hear it is working. Thank you for letting us know and posting your solution icon_smile.gif

d
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Thu Aug 26, 2010 5:16 pm
Reply with quote

Another solution could be to use the funtion REVERSE on the character variable, and if the first non-blank characters are 'NART ' (' TRAN' reversed), then space them out, and reverse the string again.
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 179
Location: India

PostPosted: Thu Aug 26, 2010 6:40 pm
Reply with quote

Thanks Kjeld. I think your solution will be short and good.
I will check that out too.
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 Unable to interpret a hex value to De... COBOL Programming 4
No new posts Copy only TEXT or String from a record SYNCSORT 4
No new posts ICETOOL to SUM String DFSORT/ICETOOL 1
No new posts Mark Previous & next lines when a... DFSORT/ICETOOL 9
No new posts Get RECORD LENGTH, allocated space of... CLIST & REXX 7
Search our Forums:

Back to Top