Re: UNSTRING performance issue
- From: "Rick Smith" <ricksmith@xxxxxxx>
- Date: Tue, 29 Nov 2005 12:35:18 -0500
"Chris" <ctaliercio@xxxxxxxxx> wrote in message
news:1133276339.806234.154820@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Given a delimited string of variable length (string-variable), suppose
> you are interested in the nth value in the string.
>
> I'm currently using the following solution:
>
> MOVE "," TO delimiter-variable
> MOVE 1 TO string-pointer
>
> PERFORM n TIMES
>
> UNSTRING
> string-variable DELIMITED BY delimiter-variable
> INTO
> string-field
> WITH POINTER
> string-pointer
> ON OVERFLOW
> SET unstring-error TO TRUE
> EXIT PERFORM
> END-UNSTRING
>
> END-PERFORM
>
>
> Obviously, the larger the string, the slower the performance of this
> command.
>
> I'm wondering if there is a faster way to do this that I am as yet
> unaware of?
>
> Any thoughts/ideas are welcome.
I am not sure how you are able to use 'ON OVERFLOW'
as stated, since it occurred on the first use of UNSTRING.
when I tested it. The rule, as I understand it, is that an
overflow condition exists when there are more characters
and no more fields.
Nonetheless, since you seem to want to detect the
condition where the n-th field may not exist, I tested the
following for that condition. That is, it works for any n,
but sets an error condition when the n-th field does not
exist.
Performance may be faster, since neither the
re-initialization of the UNSTRING statement nor its
moves to the receiving field occur.
$set ans85 flag"ans85" flagas"s"
identification division.
program-id. find-nth.
data division.
working-storage section.
01 string-variable.
02 pic x(30) value "0001,0002,0003,0004,0005,0006,".
02 pic x(30) value "0007,0008,0009,0010,0011,0012 ".
02 pic x(20) value " ".
01 string-field pic x(20).
01 delimiter-variable pic x.
01 string-pointer binary pic 9(4).
01 item-to-find binary pic 9(4).
01 delimiters-to-find binary pic 9(4).
01 delimiters-found binary pic 9(4).
01 length-of-string-variable binary pic 9(4).
01 field-flag pic x value "n".
88 field-found value "y".
88 field-not-found value "n".
procedure division.
begin.
move "," to delimiter-variable
move 9 to item-to-find
subtract 1 from item-to-find
giving delimiters-to-find
move 0 to delimiters-found
compute length-of-string-variable
= function length (string-variable)
perform varying string-pointer from 1 by 1
until string-pointer > length-of-string-variable
or delimiters-found = delimiters-to-find
if string-variable (string-pointer:1)
= delimiter-variable
add 1 to delimiters-found
end-if
end-perform
if delimiters-found = delimiters-to-find
*string-pointer points to n-th item
unstring string-variable
delimited by delimiter-variable
into string-field with
pointer string-pointer
end-unstring
set field-found to true
else
set field-not-found to true
end-if
stop run.
end program find-nth.
.
- References:
- UNSTRING performance issue
- From: Chris
- UNSTRING performance issue
- Prev by Date: Re: UNSTRING performance issue
- Next by Date: Re: Next generation COBOL?
- Previous by thread: Re: UNSTRING performance issue
- Next by thread: Re: UNSTRING performance issue
- Index(es):