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

How to concatenate two fileds with AND in middle


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

Active User


Joined: 01 Feb 2007
Posts: 123
Location: Hyderabad

PostPosted: Sat Oct 20, 2007 11:11 am
Reply with quote

Hi,

My requirement is I had two fileds. Say
WS-FIELD1 PIC X(20).
WS-FILED2 PIC X(20).

If my WS-FILED1 has 'TULASI BHASKAR' and my WS-FIELD2 has 'SUNIL KUMAR'.
My output should be TULASI BHASKAR AND SUNIL KUMAR.
How can i achieve this. If i use delimited by space in string, after TULASI it is deleting. Can anyone tell me how can i achieve this.
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Sat Oct 20, 2007 12:34 pm
Reply with quote

Bhaskar,

A simple search in the forum might have yielded this link to you -

ibmmainframes.com/archive/o_t__t_16964__start_0__index.html
Back to top
View user's profile Send private message
HARLEEN SINGH MANN
Warnings : 2

New User


Joined: 03 Aug 2007
Posts: 17
Location: Pune

PostPosted: Sat Oct 20, 2007 11:54 pm
Reply with quote

Mr Bhaskar.

Its quiet simple use : STRING WS-FIELD1 'AND' WS-FIELD2
INTO WS-FIELD3
DELIMITED BY SIZE

hope u read more about the string and gain ur experiance.

Regards,
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sun Oct 21, 2007 1:48 am
Reply with quote

Hello Harleen,

Code:
Its quiet simple use : STRING WS-FIELD1 'AND' WS-FIELD2
INTO WS-FIELD3
DELIMITED BY SIZE
Please try this on your machine. It is not syntactically correct. Also, it will not give the exact same result as the requirement asks for when the syntax is corrected. . . . It will be similar, but will not work for the requirement.

If you have questions about the result when you try it, post your code and any questions about it here.

Someone will be able to offer suggestions.
Back to top
View user's profile Send private message
bhaskar_kanteti

Active User


Joined: 01 Feb 2007
Posts: 123
Location: Hyderabad

PostPosted: Mon Oct 22, 2007 8:53 am
Reply with quote

Hi murmohk,

Thanks for providing the link. It worked for me.
I search in forum before posting it. But i didnt find it.
Any way thanks for you reply.
Back to top
View user's profile Send private message
HARLEEN SINGH MANN
Warnings : 2

New User


Joined: 03 Aug 2007
Posts: 17
Location: Pune

PostPosted: Mon Oct 22, 2007 10:15 pm
Reply with quote

scherrer,

It came to my notice that you are right I put it in a wrong way. Feel ashamed but wel this should work:

STRING WW-F1 DELIMITED BY 'AND' WW-F2 INTO WW-F3.
DISPLAY C.

sorry for the wrong info previously.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Oct 22, 2007 10:21 pm
Reply with quote

Hello Harleen,

Quote:
sorry for the wrong info previously.
Not to worry icon_smile.gif

Code:
STRING WW-F1 DELIMITED BY 'AND' WW-F2 INTO WW-F3.
Do note that a space is needed on both sides of the "AND" also. Otherwise, the values will "run together".
Back to top
View user's profile Send private message
sandy_venkat

New User


Joined: 16 May 2007
Posts: 35
Location: India

PostPosted: Tue Oct 23, 2007 10:17 am
Reply with quote

Hi dick,

the code posted above by harleen would not work either. I tried it out. It just displays the two names with spaces in between. This works.

Code:


STRING  WW-F1 DELIMITED BY SIZE
       ' AND ' DELIMITED BY SIZE
       WW-F2 DELIMITED BY SIZE
            INTO WW-F3.
Back to top
View user's profile Send private message
sandy_venkat

New User


Joined: 16 May 2007
Posts: 35
Location: India

PostPosted: Tue Oct 23, 2007 10:18 am
Reply with quote

The code posted b4 also gave an error MAX CC = 12

'EXPECTED DELIMITED BUT FOUND INTO'
Back to top
View user's profile Send private message
balakrishna reddy

Active User


Joined: 13 Jul 2007
Posts: 128
Location: Guntur

PostPosted: Tue Oct 23, 2007 11:19 am
Reply with quote

Hi guys,

I think we are going in a wrong way because if you put delimited by size then we will be remained with the trailing spaces as below

Code:

01 ws-fld1  pic  x(20) value "balakrishna".
01 ws-fld2  pic x(20) value "reddy".
01 ws-fld3  pic x(40).

if we put string ws-fld1 ' AND ' ws-fld2 delimited by size into ws-fld3

output will be like below:
balakrishna          AND reddy

 


but the requirement is "balakrishna and reddy" as i believe

i think you might have understood what i am trying to say.

Please correct me if i am wrong.
Back to top
View user's profile Send private message
sandy_venkat

New User


Joined: 16 May 2007
Posts: 35
Location: India

PostPosted: Tue Oct 23, 2007 4:37 pm
Reply with quote

I got what you are trying to say bala. I guess instead of using DELIMITED BY SIZE we can use DELIMITED BY SPACE and give extra spaces in the ' AND '. This way, we can acheive 'balakrishna and reddy'.
Back to top
View user's profile Send private message
balakrishna reddy

Active User


Joined: 13 Jul 2007
Posts: 128
Location: Guntur

PostPosted: Tue Oct 23, 2007 5:05 pm
Reply with quote

Hi Venkat,

As you have said we can use delimited by space instead of size, But it will work only for the string i have taken but what about the string which have space in between it like "bala krishna"

but what i am trying to say is if the string length is less than what we have given in the declaration then we will get trailing spaces when we use string function to concatenate.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Oct 23, 2007 8:29 pm
Reply with quote

Hello,

I misread the earlier post when i suggested putting spaces on both sides of the AND - i didn't recognize the code was in error icon_redface.gif

If the "names" fields will only have one space between the name components, the delimiter could be a double-space.

On a COBOL Enterprise system, this

Code:
*                                     
 01  WS-T PIC X(9) VALUE 'AA BBB  '.   
 01  WS-U PIC X(9) VALUE 'XXX YY  '.   
 01  WS-V PIC X(19) VALUE SPACES.     

    STRING WS-T ' AND ' WS-U DELIMITED BY '  '       
      INTO WS-V.                                     
    DISPLAY WS-V.             

gives
Code:
AA BBB AND XXX YY
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 Want to mask Middle 8 Digits of Debit... COBOL Programming 3
No new posts Concatenate 2 fields (usage national)... COBOL Programming 2
No new posts concatenate sysin to dsn JCL & VSAM 7
No new posts Need help to concatenate files with w... All Other Mainframe Topics 3
No new posts Concatenate two files of variable rec... DFSORT/ICETOOL 3
Search our Forums:

Back to Top