View previous topic :: View next topic
|
Author |
Message |
Csongor
New User
Joined: 23 Apr 2015 Posts: 20 Location: Hungary
|
|
|
|
Hello!
I am new to Rexx, I would like to ask for some help. I want to have a simple code to find the pds where a job is located, the first 3 characters of the job indicates in wich pds the job is. But with the select it does not give me the right ansver. Later on I will work with over 60 pds.
My code:
/*REXX */
JOB='JCC6L0ET'
HLQ=DELSTR(JOB,3,5)
PDS.1='XJ26T.AS.CNTL'
PDS.2='XJ26J.AS.CNTL'
PDS.3='XJ26C.AS.CNTL'
SELECT
WHEN HLQ='JCT' THEN SAY PDS.1'('JOB')'
WHEN HLQ='JCJ' THEN SAY PDS.2'('JOB')'
WHEN HLQ='JCC' THEN SAY PDS.3'('JOB')'
END
and the result is:
XJ26T.AS.CNTL(JCC6L0ET)
it schould be XJ26C.AS.CNTL(JCC6L0ET)
Can you tell me where the problem is in my code? Or is there a better solution? |
|
Back to top |
|
|
Csongor
New User
Joined: 23 Apr 2015 Posts: 20 Location: Hungary
|
|
|
|
I found it myself, the delete string should start on the 4-th character. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Next time remember that the functions provided by interpreters, compilers and other things work. It is the way you use them that doesn't, when that happens. |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2593 Location: Silicon Valley
|
|
|
|
A trace statement would help debug the problem. |
|
Back to top |
|
|
daveporcelan
Active Member
Joined: 01 Dec 2006 Posts: 792 Location: Pennsylvania
|
|
|
|
If it were me, I would replace this line:
HLQ=DELSTR(JOB,3,5)
with
HLQ=LEFT(JOB,3)
It is a little easier to understand what you are trying to achieve. |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
And I would use Substr(job,1,3). Whichever floats your boat, as they say. |
|
Back to top |
|
|
guilhermeagb
New User
Joined: 18 Mar 2015 Posts: 2
|
|
|
|
You are missing at the specified position . It must start from the 4th place with length: 5.
You can debug your program by inserting a line: 'trace ?r' before operations.
(Wrong) HLQ=DELSTR(JOB,3,5) => JC C6L0E T
HLQ=DELSTR(JOB,3,5) => JCC 6L0ET |
|
Back to top |
|
|
Garry Carroll
Senior Member
Joined: 08 May 2006 Posts: 1205 Location: Dublin, Ireland
|
|
|
|
3 months on - and surely you mean
HLQ = DELSTR(JOB,4,5) => JCC 6L0ET ?
Garry |
|
Back to top |
|
|
guilhermeagb
New User
Joined: 18 Mar 2015 Posts: 2
|
|
|
|
guilhermeagb wrote: |
You are missing at the specified position . It must start from the 4th place with length: 5.
You can debug your program by inserting a line: 'trace ?r' before operations.
(Wrong) HLQ=DELSTR(JOB,3,5) => JC C6L0E T
HLQ=DELSTR(JOB,4,5) => JCC 6L0ET |
|
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2593 Location: Silicon Valley
|
|
|
|
Quote: |
Whichever floats your boat, as they say.
|
If you have an application that is performance sensitive, you probably should not write in rexx. But some will do anyway.
There is a slight advantage in using LEFT rather than DELSTR or SUBSTR.
Code: |
/* rexx */
JOb='JCC6L0ET'
srv_start = sysvar('syssrv')
Do a= 1 to 5000
HLQ=DELSTR(JOB,4,5)
End
srv_end = sysvar('syssrv')
say 'Diff = 'srv_end-srv_start
srv_start = sysvar('syssrv')
Do a= 1 to 5000
HLQ=LEFT(JOB,3)
End
srv_end = sysvar('syssrv')
say 'Diff = 'srv_end-srv_start
srv_start = sysvar('syssrv')
Do a= 1 to 5000
HLQ=substr(JOB,1,3)
End
srv_end = sysvar('syssrv')
say 'Diff = 'srv_end-srv_start |
(I was curious)
Though the values were different each time I ran it, at times LEFT was 20% faster than SUBSTR, with DELSTR, somewhere in the middle. |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1314 Location: Vilnius, Lithuania
|
|
|
|
Pedro wrote: |
Quote: |
Whichever floats your boat, as they say.
|
If you have an application that is performance sensitive, you probably should not write in rexx. But some will do anyway.
There is a slight advantage in using LEFT rather than DELSTR or SUBSTR.
.
.
.
(I was curious)
Though the values were different each time I ran it, at times LEFT was 20% faster than SUBSTR, with DELSTR, somewhere in the middle |
Have you tried timing "parse"? It's supposed to be even faster. No time to do it now myself, about to hitchhike from Belgium to Lithuania... |
|
Back to top |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
|
|
I am curious too, so I copied Pedro's code and added a "parse var job HLQ +3 rest" statement. Results:
Code: |
Diff = 2971 DELSTR
Diff = 2497 LEFT
Diff = 2949 SUBSTR
Diff = 2313 PARSE |
|
|
Back to top |
|
|
|