View previous topic :: View next topic
|
Author |
Message |
genesis786
Active User
Joined: 28 Sep 2005 Posts: 210 Location: St Katherine's Dock London
|
|
|
|
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
Can anyone please help? |
|
Back to top |
|
|
dp33770
New User
Joined: 04 Jul 2007 Posts: 91 Location: Hyderabad
|
|
|
|
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 |
|
|
hikaps14
Active User
Joined: 02 Sep 2005 Posts: 189 Location: Noida
|
|
|
|
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 |
|
|
genesis786
Active User
Joined: 28 Sep 2005 Posts: 210 Location: St Katherine's Dock London
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
dp33770
New User
Joined: 04 Jul 2007 Posts: 91 Location: Hyderabad
|
|
|
|
Robert,
I think genesis786 was looking for somthing like below as o/p
Code: |
005 IBD-ENTERPRISE DEAL IBD |
|
|
Back to top |
|
|
genesis786
Active User
Joined: 28 Sep 2005 Posts: 210 Location: St Katherine's Dock London
|
|
|
|
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 |
|
|
genesis786
Active User
Joined: 28 Sep 2005 Posts: 210 Location: St Katherine's Dock London
|
|
|
|
only thing is, how to handle it if my WS-VAR1 was something like 005 IBDXYZ .. occupying all 10 bytes. ? |
|
Back to top |
|
|
genesis786
Active User
Joined: 28 Sep 2005 Posts: 210 Location: St Katherine's Dock London
|
|
|
|
now it is working fine
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 |
|
|
hikaps14
Active User
Joined: 02 Sep 2005 Posts: 189 Location: Noida
|
|
|
|
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 |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
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 |
|
|
|