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

Retain Leading space


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
passion_sujesh

New User


Joined: 14 Mar 2008
Posts: 74
Location: India,Chennai

PostPosted: Sat Jan 18, 2014 12:30 am
Reply with quote

Hi,

Iam trying to selecta part of a string using SUBSTR function. This works fine if the string has no leding spaces. If the string has leading spaces, its not working as expected. Can any one help me in retaining the leading spaces while using substr.

My input (variable name - ws-xyz):
Code:
"123456"
"234567"
"   4788"  (two leading spaces)
"564786"


ws-new-data = substr(ws-xyz,3,2)

My expected output:
Code:
34
45
47
47


Output i get:
Code:

34
45
88
47


The third record in the o/p is incorrect.
I think the leading space is removed before the substr, is there any way i can retain the leading space.

Thanks.

Code'd
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Sat Jan 18, 2014 1:12 am
Reply with quote

Could you post the trace output within code tags?
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Sat Jan 18, 2014 1:46 am
Reply with quote

First of all, these:

ws-xyz
ws-new-data

are invalid variable names in REXX. Adjusting for that:

ws_new_data = Substr(ws_xyz,3,2)
Say "'"ws_new_data"'"

I get:

'34'
'45'
'47'
'47'

in my output.
Back to top
View user's profile Send private message
Pedro

Global Moderator


Joined: 01 Sep 2006
Posts: 2547
Location: Silicon Valley

PostPosted: Mon Jan 20, 2014 8:00 pm
Reply with quote

You have not shown how the values are assigned to the variable.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jan 31, 2014 6:24 pm
Reply with quote

even though the TS has not returned:
1. REXX is pretty tight. i have not found (in 20 years) any problem
other than my ability to understand the manual.

2. if you think something is not working 'as expected'.
do a little debugging.

use SAY LENGTH(variable)
use SAY variable

use TRACE. I find ?R to be most helpful.
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Fri Jan 31, 2014 6:45 pm
Reply with quote

Use:
Code:
Say '>'variable'<'

the number of times I have found trailing blanks when there "weren't" any using this method!
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: Fri Jan 31, 2014 8:08 pm
Reply with quote

Nic's suggession of using > and < is valuable for COBOL displays also. Leading or trailing unprintable characters are spotted easily this way.
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 -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts Keep leading zero(s) after convert fl... SYNCSORT 7
No new posts Remove leading zeroes SYNCSORT 4
No new posts leading spaces can be removed in trai... DFSORT/ICETOOL 1
No new posts Merge 2 lines based on Space from a S... DFSORT/ICETOOL 5
Search our Forums:

Back to Top