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

Need to unstring to write into a file


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

New User


Joined: 22 Nov 2005
Posts: 24

PostPosted: Tue Oct 28, 2008 2:42 pm
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: 6966
Location: porcelain throne

PostPosted: Tue Oct 28, 2008 3:15 pm
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: 24

PostPosted: Tue Oct 28, 2008 3:19 pm
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: 6966
Location: porcelain throne

PostPosted: Tue Oct 28, 2008 3:41 pm
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
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: 24

PostPosted: Wed Oct 29, 2008 11:42 am
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 0
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
Search our Forums:

Back to Top