width of a db field

davidvilla

Member
Hi all,
How to get the width of a character field. If the format is "X(10)", then I can get t easily. But I have fields like ph num with the format ~(9(3)~)9(3)-9(4) ~e~x~t X(4). Is there any inbuilt mechanism to get the max length of the field that it can accommodate within the format?
 
i use following code for this task

Code:
PROCEDURE CalcFieldWidth:
  define input parameter dt as character.
  define input parameter fformat as character.
  define output parameter fwidth as integer.

  fformat = trim(fformat).
  if fformat = "" then
  do:
    if dt = "integer" or dt = "recid" or dt = "date" then fwidth = 10.
    if dt = "decimal" then fwidth = 15.
    if dt = "character" then fwidth = 30.
    if dt = "logical" then fwidth = 5.
    if dt = "datetime" or dt = "datetime-tz" then fwidth = 20.
  end.
  else do:
   if dt = "character" or dt = "logical" then
   do:
     if dt = "logical" then fwidth = 5.
     if fformat begins "X(" then fwidth = integer(entry(1,substring(fformat,3), ")")).
   end.
   else fwidth = length(fformat).
  end.
  if fwidth = 0 then fwidth = 15.
end.
 
hope this won't work for the format like ~(9(3)~)9(3)-9(4) ~e~x~t X(4)

How abt this?
define variable ctest as character format "~(9(3)~)9(3)-9(4) e~~xt X(4)".
define frame ctestfrm ctest with no-box.
message frame ctestfrm:WIDTH-CHARS.


i hope this will work for any kind of RE in the format
 
Define variable cFormat as character no-undo.
cFormat = "~(9(3)~)9(3)-9(4) e~~xt X(4)".
define variable ctest as character no-undo.
Assign ctest:Format = cFormat.
define frame ctestfrm ctest with no-box.
message frame ctest:WIDTH-CHARS.
 
You must realize that the format description of a character field is the default input/output format. That description does not limit the number of bytes you can store on a character field. The limit is determined by the limit of a character data type ( 3'200 bytes ) and / or the max. size of a database record ( AFAIK 32'000 bytes ).

Heavy Regards, RealHeavyDude.
 
Back
Top