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
 

 

Need to unstring to write into a file

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

New User


Joined: 22 Nov 2005
Posts: 23

PostPosted: Tue Oct 28, 2008 2:42 pm    Post subject: Need to unstring to write into a file
Reply with quote

Hi,

I have a string which is defined as x(5000).

This string could be like this

'name1 address1 address2' etc..

The number of spaces between the words is not fixed. I would like to write this as a trailer record in my file with only one space in between each word.

Please let me know how can we achieve this.

Regards,
Nimi
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Oct 28, 2008 3:15 pm    Post subject:
Reply with quote

Code:

String <field-1>
     delimited by all spaces
         ' '
      <field-2> 
     delimited by all spaces
 into <destination field>
end-string
Back to top
View user's profile Send private message
nimisanand

New User


Joined: 22 Nov 2005
Posts: 23

PostPosted: Tue Oct 28, 2008 3:19 pm    Post subject: Reply to: Need to unstring to write into a file
Reply with quote

there is only variable whoes value is 'name1 address1 address2' with no fixed spaces between them.


I didnt understand field-1 field-2
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Oct 28, 2008 3:41 pm    Post subject:
Reply with quote

first you will have to unstring this variable into howevermany field-s there can be and then restring with the string logic i previously provided.

or
  • loop thru the variable with a subscript
    and only move char > space
  • and when you find a space, don't move it, but set a flag that you found a space,
  • and then when you find a non-space
    • and the flag is set, move a space, set the flag off, and move the non-space char
    • when the flag is not set, move the non-space char
  • loop
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Tue Oct 28, 2008 6:24 pm    Post subject:
Reply with quote

nimisanand wrote:

The number of spaces between the words is not fixed. I would like to write this as a trailer record in my file with only one space in between each word.

From what you wrote above it seems you want to write name and addresses in output file as one record and you want to strip-out spaces if it is more than two.
If i have understood you correctly below code will solve your requirement.
Code:
 
*WS
01 VINTEMP.                                                   
   02 VIN PIC X(40) VALUE 'NAME   ADR1   ADR2      ADR3   '. 
   02 VIN1 REDEFINES VIN PIC X OCCURS 40 TIMES.               
01 VOUT PIC X(40).     
01 VTEMP PIC X(40).   
01 PTR1 PIC 99.       
01 PTR2 PIC 99.       
 
*PD
MOVE 1 TO PTR1 PTR2.                 
MOVE SPACES TO VOUT VTEMP.           
PERFORM UNTIL PTR1 > 40               
UNSTRING VIN DELIMITED BY ALL SPACES 
  INTO VTEMP  POINTER PTR1           
STRING VTEMP DELIMITED BY SPACES     
  INTO VOUT POINTER PTR2             
ADD 1 TO PTR2                         
END-PERFORM.                         
DISPLAY "INPUT :" VIN.               
DISPLAY "OUTPUT:" VOUT.               

Output will be
Code:
 
INPUT :NAME   ADR1   ADR2      ADR3 
OUTPUT:NAME ADR1 ADR2 ADR3           


Post back again if anything else than this you wanted..
icon_smile.gif
Back to top
View user's profile Send private message
nimisanand

New User


Joined: 22 Nov 2005
Posts: 23

PostPosted: Wed Oct 29, 2008 11:42 am    Post subject: Reply to: Need to unstring to write into a file
Reply with quote

unstring with pointer and string with pointer worked..thanks a lot...
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Wed Oct 29, 2008 12:41 pm    Post subject:
Reply with quote

Quote:
unstring with pointer and string with pointer worked..
Thanks for letting us know icon_wink.gif
Quote:

thanks a lot...

U R Welcome icon_smile.gif icon_smile.gif icon_smile.gif
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. Fetching data from BAI File arunsoods JCL & VSAM 1 Wed Jul 19, 2017 4:28 pm
No new posts Write out NODUPS but just from one file Jay Villaverde DFSORT/ICETOOL 8 Fri Jul 14, 2017 12:44 am
No new posts How to add header with Date(YYMMDD) i... Rajan Moorthy DFSORT/ICETOOL 2 Thu Jul 06, 2017 11:44 pm
No new posts How to write Specific Fields from Mul... Padhu SYNCSORT 6 Thu Jul 06, 2017 10:26 am
No new posts How to generate a new unique Input fi... for1ranjith CLIST & REXX 11 Sat Jul 01, 2017 12:09 pm


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