View previous topic :: View next topic
|
Author |
Message |
i413678 Currently Banned Active User
Joined: 19 Feb 2005 Posts: 112 Location: chennai
|
|
|
|
Hi,
I have a requirement to concatenate the two strings....
string1 is name of 20 characters and the values can be
"sangeetha"
"sangeetha nityanandam"
"vijay prabhi thinagaran"
string2 is just a character A
now I have to concate these two strings in such a way that string1 should be padded with the string2 i.e. A and need to give new string with
string1+'A'
Please advise how it can be done.....
Note : tested with STRING with DELIMITED BY SPACE and not getting the result what I want...
thx in advance.....
pavan |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
pavan,
Can you give a specific example of what you want the resuilt to look like?
string1 PIC X(20) VALUE "sangeetha"
string2 = "A"
result = "sangeethaA" or "sangeethaAAAAAAAAAAA" or other?
Please clarify.
Thanks,
Dave |
|
Back to top |
|
|
i413678 Currently Banned Active User
Joined: 19 Feb 2005 Posts: 112 Location: chennai
|
|
|
|
Hi,
the result should be "sangeetha nityanandamA"
if string1 is "sangeetha nityanandam" and
not some thing like "sangeethaAAAAAAAAAAA" or other
I hope it is clear
thx in adv.....
pavan |
|
Back to top |
|
|
ranjitbhingare
New User
Joined: 30 Nov 2005 Posts: 94 Location: PUNE
|
|
|
|
Hi ,
To get the desired result, you can use STRING DELIMITED BY SIZE instead of space.
Correct me if I am wrong!
Regards,
Ranjit.... |
|
Back to top |
|
|
i413678 Currently Banned Active User
Joined: 19 Feb 2005 Posts: 112 Location: chennai
|
|
|
|
Hi
I used STRING DELIMITED BY SIZE also but I am not getting the exact result I want.......
pavan |
|
Back to top |
|
|
hncs
New User
Joined: 01 Mar 2006 Posts: 11
|
|
|
|
Try it out*********************
----------------------------------------------------------------
01 WS-STR1 PIC X(10) VALUE 'ABCDEF'.
01 WS-STR2 PIC X(10) VALUE 'A'.
01 WS-STR3 PIC X(20) VALUE SPACES.
PROCEDURE DIVISION.
MAIN-PARA.
STRING WS-STR1 DELIMITED BY SIZE
WS-STR2 DELIMITED BY SIZE
INTO WS-STR3
END-STRING
STOP RUN. |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
hncs,
The code you supplied produces the following result
|
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
pavan,
The code below functions as I think you want. You can also accomplish this by using INSPECT statement to find the length of the literals in the strings.
Code: |
01 WS-STR1 PIC X(10) VALUE 'DAVE AT K'
01 WS-STR2 PIC X(10) VALUE 'A'.
01 WS-STR3 PIC X(20) VALUE SPACES.
01 SUB PIC S9(3) COMP-3 VALUE +0.
01 LEN-STR1 PIC S9(3) COMP-3 VALUE +0.
01 LEN-STR2 PIC S9(3) COMP-3 VALUE +0.
COMPUTE LEN-STR1 = LENGTH OF WS-STR1 - 1.
PERFORM
VARYING SUB FROM LEN-STR1 BY -1
UNTIL SUB < 1
OR WS-STR1(SUB:1) NOT = ' '
END-PERFORM.
MOVE SUB TO LEN-STR1.
COMPUTE LEN-STR2 = LENGTH OF WS-STR2 - 1.
PERFORM
VARYING SUB FROM LEN-STR2 BY -1
UNTIL SUB < 1
OR WS-STR2(SUB:1) NOT = ' '
END-PERFORM.
MOVE SUB TO LEN-STR2.
STRING WS-STR1(1:LEN-STR1) DELIMITED BY SIZE
WS-STR2(1:LEN-STR2) DELIMITED BY SIZE
INTO WS-STR3
END-STRING.
DISPLAY WS-STR3.
|
Results in the string:
Dave |
|
Back to top |
|
|
i413678 Currently Banned Active User
Joined: 19 Feb 2005 Posts: 112 Location: chennai
|
|
|
|
Hi,
Thank you one and all who are involved in this forum.........
pavan |
|
Back to top |
|
|
|