Hi all:
Let's start with "known"
<1> *a9999 provides the size of an item
<2> Similarly the u7000 user exit returns the size of an item.
<3> LEN(My_Variable) returns the length of My_Variable
I need to prevent overflow so I need to defensively check for a certain "overflow" value (to be determined).
ByteSize = function{variable}
If ByteSize > {a predetermined value} then {defensive code}
Else {variable := {continue to build variable }
I searched for some function to do this but alas.
Does anyone out there have an elegant solution?
Thanks
Stefano
Hi Stefano,
Based on what you are saying; the first two methods will not work since you are building something in memory; which leaves LEN().
If you want a function to do this; then that would be a custom sub-routine something like:
CHECKSIZE
SUBROUTINE CHECKSIZE(itemtocheck, maxsize, error)
error = 0 ;* Assume the best [can reverse this if you want, personal preference?]
if LEN(itemtockeck) > maxsize then
error = 1
end
*
return
********************************************
You would then use this in your code as:
.......
error = 0
call checksize(variablename, 9999999)
if error then
<defensive code>
end else
<build variable>
end
........
I'm sure there are other ways to do this; perhaps using Python; but the above is the only way I can think of quickly that is standard across all flavours of mv.
Given the simplicity of the subroutine; and the overhead such calls; it seems to me hardly worth the effort as the code to simply use LEN without a subroutine is similar. So why bother? Perhaps build more of the logic on the variable-build into the subroutine? Maybe that is what you are really seeking?
Let's see what others come up with.
David Knight
PS: Just saw your reply: Was not aware from your OP that you were considering UTF8 characters, too.
I've seen a lot of discussion about mv and UTF8 encoding and storage; and do not wish to delve into THAT minefield! Without really knowing; I would suspect the route would have to be a Python subroutine; but have no idea if such a beast exists. If not, one would have to be created; I guess.
Which of course would limit use to those mv flavours which support Python.
Of if you are in the jbase world, any compatible c routine can be used.
Hi all:
Let's start with "known"
<1> *a9999 provides the size of an item
<2> Similarly the u7000 user exit returns the size of an item.
<3> LEN(My_Variable) returns the length of My_Variable
I need to prevent overflow so I need to defensively check for a certain "overflow" value (to be determined).
ByteSize = function{variable}
If ByteSize > {a predetermined value} then {defensive code}
Else {variable := {continue to build variable }
I searched for some function to do this but alas.
Does anyone out there have an elegant solution?
Thanks
Stefano
Thanks @David Knight
I was looking for something that OpenInsight has called GetByteSize, rather than Len, which always returns the cached byte-count regardless of ANSI or UTF8-mode.
Thanks
Stefano
Hi all:
Let's start with "known"
<1> *a9999 provides the size of an item
<2> Similarly the u7000 user exit returns the size of an item.
<3> LEN(My_Variable) returns the length of My_Variable
I need to prevent overflow so I need to defensively check for a certain "overflow" value (to be determined).
ByteSize = function{variable}
If ByteSize > {a predetermined value} then {defensive code}
Else {variable := {continue to build variable }
I searched for some function to do this but alas.
Does anyone out there have an elegant solution?
Thanks
Stefano
Give us more details about why you are trying to prevent "overflow" which is an ambiguous term in mvBase since the system proactively adds space when in the runtime engine. And under what circumstances you are getting overflow.
Bytesize is not a thing that is simple to determine for an arbitrary variable in runtime.
Strings are Len(string), plus two by the way
However other variables like file pointers or numerics are not len deteremined in that way.
So give us more information
Hi all:
Let's start with "known"
<1> *a9999 provides the size of an item
<2> Similarly the u7000 user exit returns the size of an item.
<3> LEN(My_Variable) returns the length of My_Variable
I need to prevent overflow so I need to defensively check for a certain "overflow" value (to be determined).
ByteSize = function{variable}
If ByteSize > {a predetermined value} then {defensive code}
Else {variable := {continue to build variable }
I searched for some function to do this but alas.
Does anyone out there have an elegant solution?
Thanks
Stefano
Hi @Will Johnson
OK,so don't judge but I'm "hacking" into old (> 30 yr) D3 coe that does a "screen grab" off a print (of a report) and writes it to a CSV file to produce a spreadsheet.
So the existing code does all the "heavy lifting" and all I need to do is produce the spreadsheet in a more elegant manner/way.
My "challenge" is that I will have a rather large variable when collecting this output - hence the defensive code to split this up iff the variable reaches a "predetermined" value.
I did some testing with Len() and get an appreciable result, but my question (to the group) was more on a possible "upgrade" to D3 which meets the GetByteSize() of OpenInsight.
Thanks
Stefano
Hi all:
Let's start with "known"
<1> *a9999 provides the size of an item
<2> Similarly the u7000 user exit returns the size of an item.
<3> LEN(My_Variable) returns the length of My_Variable
I need to prevent overflow so I need to defensively check for a certain "overflow" value (to be determined).
ByteSize = function{variable}
If ByteSize > {a predetermined value} then {defensive code}
Else {variable := {continue to build variable }
I searched for some function to do this but alas.
Does anyone out there have an elegant solution?
Thanks
Stefano
In this case where you are do a screen grab, the LEN and the Bytesize are the exact same value. A screen grab is character based only (strings), and each character is exactly one byte. So a screen grab of say 1000 characters, is 1000 bytes.