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

Concatenate two fields including trailing spaces.


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
AjmalMohammed

New User


Joined: 02 Jun 2010
Posts: 10
Location: My Cubicle, Hyderabad, India

PostPosted: Thu Jun 17, 2010 2:11 pm
Reply with quote

Hi,

How can i concatenate two strings such that trailing spaces(if any) are also included in the end result ?

Code:

Exec SQL
Select Field1 || Field2 into :Host-Var From TableName where <condition>
from TableName
End-Exec.


This query ignores trailing spaces.

Assume Field1 is defined as char(20) holding value 'abc' and Field2 is defined as char(20) with value 'def'. I want host-var to have value of field1 plus 17 blanks then field2 plus 17 blanks.

I think the Substr function might work. I cant experiment as i dont have access to mainframes right now.

Thank you,
Ajmal.
Back to top
View user's profile Send private message
anshul_gugnani

New User


Joined: 02 Nov 2009
Posts: 73
Location: Mumbai

PostPosted: Thu Jun 17, 2010 3:10 pm
Reply with quote

Hello Ajmal,

You can cast each column to fixed length column and then concatenate them -
Trying using somthing like -

Code:

SELECT CAST (Field1 AS CHAR(20)) ||
            CAST (Field2 AS CHAR(20))     
FROM table                 
WHERE ....         


Hope this helps.....
Back to top
View user's profile Send private message
AjmalMohammed

New User


Joined: 02 Jun 2010
Posts: 10
Location: My Cubicle, Hyderabad, India

PostPosted: Thu Jun 17, 2010 3:53 pm
Reply with quote

Will this work?

Code:

SELECT SUBSTR(FIELD1,1,20) || SUBSTR (FIELD2,1,20) FROM TABLE
WHERE <CONDITION>
Back to top
View user's profile Send private message
anshul_gugnani

New User


Joined: 02 Nov 2009
Posts: 73
Location: Mumbai

PostPosted: Thu Jun 17, 2010 3:59 pm
Reply with quote

Hello,

Yes this will also work.Will give the same result as above example of CAST.
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 -> DB2

 


Similar Topics
Topic Forum Replies
No new posts leading spaces can be removed in trai... DFSORT/ICETOOL 1
No new posts Cobol program with sequence number ra... COBOL Programming 5
No new posts To Remove spaces (which is in hex for... JCL & VSAM 10
No new posts How to remove spaces in between. SYNCSORT 12
No new posts Concatenate 2 fields (usage national)... COBOL Programming 2
Search our Forums:

Back to Top