Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

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

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 129
Location: India

PostPosted: Wed Aug 25, 2010 9:27 pm    Post subject: STRING - To space out a word if coming at the end of variabl
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

Site Director


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

PostPosted: Wed Aug 25, 2010 9:51 pm    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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: 129
Location: India

PostPosted: Thu Aug 26, 2010 4:56 am    Post subject:
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

Site Director


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

PostPosted: Thu Aug 26, 2010 5:14 am    Post subject:
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: 129
Location: India

PostPosted: Thu Aug 26, 2010 5:49 am    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Thu Aug 26, 2010 7:49 am    Post subject: Reply to: STRING - To space out a word if coming at the end
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    Post subject:
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: 129
Location: India

PostPosted: Thu Aug 26, 2010 6:40 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts Random Password (in string format) ge... ezhavendhan COBOL Programming 10 Mon Aug 29, 2016 3:18 pm
No new posts How to insert a lengthy string havin... vidyaa DB2 7 Thu Aug 25, 2016 5:20 pm
No new posts Which function does the Ampersand (&a... Andi1982 PL/I & Assembler 3 Wed Aug 24, 2016 2:05 pm
No new posts Need a help how to replace a string i... gurunath82 CLIST & REXX 12 Tue Jul 26, 2016 11:43 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us