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

using STRING & DELIMITED BY...


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

Active User


Joined: 28 Sep 2005
Posts: 210
Location: St Katherine's Dock London

PostPosted: Fri Dec 19, 2008 5:01 pm
Reply with quote

Hi,

I have following requirement.

WS-VAR1 PIC X(10).
WS-VAR2 PIC X(30).
WS-VAR3 PIC X(42).

Now. WS-VAR1 has multiple words in it like 005 IBD or ENT DEAL etc etc...
WS-VAR2 is something like ENTERPRISE DEAL IBD

I want WS-VAR3 to be something like

005 IBD-ENTERPRISE DEAL IBD

When I write STRING with DELIMITED BY SIZE it comes like

005 IBD -ENTERPRISE DEAL IBD icon_sad.gif

Can anyone please help?
Back to top
View user's profile Send private message
dp33770

New User


Joined: 04 Jul 2007
Posts: 91
Location: Hyderabad

PostPosted: Fri Dec 19, 2008 6:05 pm
Reply with quote

Dear genesis786,
You said,

When I write STRING with DELIMITED BY SIZE it comes like

005 IBD -ENTERPRISE DEAL IBD

is it that U get an extra space after IBD and ENTERPRISE .
Do you use the '-' in STRING
Back to top
View user's profile Send private message
hikaps14

Active User


Joined: 02 Sep 2005
Posts: 189
Location: Noida

PostPosted: Fri Dec 19, 2008 6:10 pm
Reply with quote

Hi,

String statement can be used with 2 verbs :
1)delimited by Size
2)delimitedd by Space

Usually when we concatenate 2 variable contents into 1 variable, we use DELIMITED BY SPACE ( for the type of o/p desired by you).

In your case this doesn't seem to be possible, because space is in between your strings of WS-VAR1. We need some marker to delimit your string, which can tell us the end of your string. If you can somehow insert any marker like '@' or '#', then delimited by '@' or '#' can be used.

Thanks,
-Kapil.
Back to top
View user's profile Send private message
genesis786

Active User


Joined: 28 Sep 2005
Posts: 210
Location: St Katherine's Dock London

PostPosted: Fri Dec 19, 2008 6:17 pm
Reply with quote

dp33770:

this is the STRING instruction:

Code:

MOVE '005 IBD' TO WS-VAR1.             
MOVE 'ENTERPRISE DEAL IBD' TO WS-VAR2.
STRING WS-VAR1 DELIMITED BY SIZE       
       '-' DELIMITED BY SPACE         
       WS-VAR2 DELIMITED BY SIZE       
       INTO WS-VAR3                   
DISPLAY WS-VAR3.                       


hikaps14:

Thanks! will try to find out.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Fri Dec 19, 2008 6:52 pm
Reply with quote

I got this output
Code:
 005 IBD   -ENTERPRISE DEAL IBD           .
 005-ENTERPRISE DEAL IBD                  .
by using this code:
Code:
    MOVE '005 IBD' TO WS-VAR1.
    MOVE 'ENTERPRISE DEAL IBD' TO WS-VAR2.
    STRING WS-VAR1 DELIMITED BY SIZE
           '-'     DELIMITED BY SPACE
           WS-VAR2 DELIMITED BY SIZE
           INTO WS-VAR3
    DISPLAY WS-VAR3.
    STRING WS-VAR1 DELIMITED BY SPACE
           '-'     DELIMITED BY SIZE
           WS-VAR2 DELIMITED BY SIZE
           INTO WS-VAR3
    DISPLAY WS-VAR3.
The second one looks to be what you want.
Back to top
View user's profile Send private message
dp33770

New User


Joined: 04 Jul 2007
Posts: 91
Location: Hyderabad

PostPosted: Fri Dec 19, 2008 6:57 pm
Reply with quote

Robert,
I think genesis786 was looking for somthing like below as o/p
Code:
005 IBD-ENTERPRISE DEAL IBD
Back to top
View user's profile Send private message
genesis786

Active User


Joined: 28 Sep 2005
Posts: 210
Location: St Katherine's Dock London

PostPosted: Fri Dec 19, 2008 7:33 pm
Reply with quote

hi guys, i tried the following piece of code and it worked.

Code:

MOVE '005 IBD' TO WS-VAR1                             
MOVE 'ENTERPRISE DEAL IBD' TO WS-VAR2                 
COMPUTE WS-COUNT1 = LENGTH OF WS-VAR1                 
PERFORM VARYING WS-COUNT1 FROM WS-COUNT1 BY -1 UNTIL   
        WS-VAR1(WS-COUNT1:1) NOT = SPACE               
END-PERFORM                                           
COMPUTE WS-COUNT1 = WS-COUNT1 + 1                     
MOVE '^' TO WS-VAR1(WS-COUNT1:1)                       
STRING WS-VAR1 DELIMITED BY '^'                       
       '-' DELIMITED BY SIZE                           
       WS-VAR2 DELIMITED BY SIZE                       
       INTO WS-VAR3                                   
DISPLAY WS-VAR3.                                       
Back to top
View user's profile Send private message
genesis786

Active User


Joined: 28 Sep 2005
Posts: 210
Location: St Katherine's Dock London

PostPosted: Fri Dec 19, 2008 7:40 pm
Reply with quote

only thing is, how to handle it if my WS-VAR1 was something like 005 IBDXYZ .. occupying all 10 bytes. icon_sad.gif ?
Back to top
View user's profile Send private message
genesis786

Active User


Joined: 28 Sep 2005
Posts: 210
Location: St Katherine's Dock London

PostPosted: Fri Dec 19, 2008 7:51 pm
Reply with quote

now it is working fine icon_smile.gif

Code:

MOVE '005 IBDUUU' TO WS-VAR1                         
MOVE 'ENTERPRISE DEAL IBD' TO WS-VAR2               
COMPUTE WS-COUNT1 = LENGTH OF WS-VAR1               
PERFORM VARYING WS-COUNT1 FROM WS-COUNT1 BY -1 UNTIL
        WS-VAR1(WS-COUNT1:1) NOT = SPACE             
END-PERFORM                                         
COMPUTE WS-COUNT1 = WS-COUNT1 + 1                   
IF WS-COUNT1 < 11                                   
  MOVE '^' TO WS-VAR1(WS-COUNT1:1)                   
END-IF                                               
STRING WS-VAR1 DELIMITED BY '^'                     
       '-' DELIMITED BY SIZE                         
       WS-VAR2 DELIMITED BY SIZE                     
       INTO WS-VAR3                                 
DISPLAY WS-VAR3.                                     
Back to top
View user's profile Send private message
hikaps14

Active User


Joined: 02 Sep 2005
Posts: 189
Location: Noida

PostPosted: Fri Dec 19, 2008 8:07 pm
Reply with quote

Its good, that your solution worked.

I just came accross another piece of code, which looks simpler to me:

1) MOVE WS-VAR1 to WS-RIGHT-JUST ( variable declared as right justified)
2) INSPECT WS-RIGHT-JUST tallying WS-COUNT for leading spaces.
3)WS-COUNT= 10 - WS-COUNT
4) Now use your string statement
STRING WS-VAR1(1: WS-COUNT)
'-'
WS-VAR2 DELIMITED BY SIZE
INTO WS-VAR3

Just a suggestion.

Thanks,
-Kapil.
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Sat Dec 20, 2008 12:28 am
Reply with quote

Move WS-VAR1 to WS-RIGHT-JUST will not right justify the source field if both fields are the same length. It will only right justify the contents of WS-VAR1 into WS-RIGHT-JUST regardless of the presence or absence of spaces.
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts file manager is doing string conversion IBM Tools 3
No new posts Search string in job at regular Spool... CLIST & REXX 0
Search our Forums:

Back to Top