Hi,

IP := 2797 SPRINGHILL DR ALBANY, OR, 23456

#TEMP := 2797 SPRINGHILL DR ALBANY
OP1 := 2797 SPRINGHILL DR
OP2 := ALBANY

In the samples shown above i want the outputs has shown in in OP1 and OP2.

First step i am using an examine to find ‘,’ and moving that to the #Temp Variable.

From the #Temp variable i want to do an reverse read to find the position of the first space and from that position move that to OP2.

thanks,
TCS

There are several ways to do this;

EXAMINE BACKWARD #TEMP would work

or

MOVE #TEMP (PM=I) TO #TEMP followed by an EXAMINE

or

SEPARATE #TEMP

My guess is that the SEPARATE might be the most efficient, but I have not done a comparison as yet; perhaps later today.

One more possibility, do a SEPARATE on IP and retain the delimiters, then look for the first comma

steve

Okay, here is a PC timing comparison of two approaches

DEFINE DATA LOCAL
1 IP (A50) INIT <‘2797 SPRINGHILL DR ALBANY, OR, 23456’>
1 #PIECES (A15/1:20)
1 OP1 (A50)
1 OP2 (A50)
1 #INDEX (I2)
1 #COMMA (I2)
1 #BLANK (I2)
1 #OP2LENGTH (I2)
1 #LOOP (I4)
1 #CPU-START (I4)
1 #CPU-ELAPSED (I4)
END-DEFINE
*
MOVE CPU-TIME TO #CPU-START
SETA. SETTIME
FOR #LOOP = 1 TO 10000
SEPARATE IP INTO #PIECES (
) WITH RETAINED DELIMITERS
EXAMINE #PIECES (*) FOR ‘,’ GIVING INDEX #INDEX
MOVE #PIECES (#INDEX - 1) TO OP2
COMPRESS #PIECES (1:#INDEX - 2) INTO OP1
END-FOR
COMPUTE #CPU-ELAPSED = *CPU-TIME - #CPU-START
WRITE ‘separate ip’ *TIMD (SETA.) #CPU-ELAPSED

MOVE *CPU-TIME TO #CPU-START
SETB. SETTIME
FOR #LOOP = 1 TO 10000
EXAMINE IP FOR ‘,’ GIVING POSITION #COMMA
EXAMINE DIRECTION BACKWARD SUBSTRING (IP,1,#COMMA) FOR ’ ’ GIVING POSITION #BLANK
MOVE SUBSTRING (IP,1,#BLANK) TO OP1
COMPUTE #OP2LENGTH = #COMMA - #BLANK
MOVE SUBSTRING (IP,#BLANK,#OP2LENGTH) TO OP2
END-FOR
COMPUTE #CPU-ELAPSED = *CPU-TIME - #CPU-START
WRITE ‘examine ip’ *TIMD (SETB.) #CPU-ELAPSED
END

Page 1 07-11-26 08:16:44

separate ip 7 66
examine ip 2 19

On the mainframe I think the second approach will look even better since the SUBSTRING facility there was recently rewritten and is substantially more efficient than on the PC.

steve

Steve Robinson wrote:

But you will get:

``NAT0132 Operand not defined or not of alphanumeric/binary format.``

during catalog.

Even with the current NAT42x

``EXAMINE DIRECTION BACKWARD``

is not supported.

My bad. Difficult to keep track of which options are on which platform.

Here is a rewrite of the second approach:

MOVE *CPU-TIME TO #CPU-START
SETC. SETTIME
FOR #LOOP = 1 TO 10000
EXAMINE IP FOR ‘,’ GIVING POSITION #COMMA
MOVE SUBSTRING (IP,1,#COMMA) (PM=I) TO #WORK
EXAMINE #WORK FOR ’ ’ GIVING POSITION #BLANK
COMPUTE #BLANK = #BLANK - 2
MOVE SUBSTRING (#WORK,2,#BLANK) (PM=I) TO OP1
MOVE SUBSTRING (IP,#BLANK) TO OP2
END-FOR
COMPUTE #CPU-ELAPSED = *CPU-TIME - #CPU-START
WRITE ‘examine no backward ip’ *TIMD (SETC.) #CPU-ELAPSED

Here are the three times on the PC

``````PAGE #   1                    DATE:    Nov 26, 2007
PROGRAM: STRIP03              LIBRARY: INSIDE
``````

separate ip 7 67
examine ip 2 19
examine no backward ip 2 20

So on the PC, the third solution is slightly slower than the second.

On the mainframe, I ran the first and third (second, as noted, will not compile)

separate ip 2 11
examine no backward ip 1 6

So the ratio is about two to one in favor of the last solution.

steve