Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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: 6970
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: 6970
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
No new posts ISSUE IN copying Sequential file reco... thesumitk JCL & VSAM 2 Wed Dec 13, 2017 3:07 pm
No new posts File Tailoring -- Temporary dataset i... samzee71 CLIST & REXX 3 Fri Dec 01, 2017 3:12 am
No new posts Rexx - File tailoring samzee71 CLIST & REXX 10 Thu Nov 30, 2017 10:47 pm
No new posts Moving a PS file as body of a mail! Vignesh Sid JCL & VSAM 4 Tue Nov 21, 2017 9:23 pm
No new posts unable to set RC = 4 when empty file migusd SYNCSORT 1 Tue Nov 21, 2017 1:21 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us