Kbase P119062: ADD-NEW-FIELD method fails with error 80 and 5729
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  08/11/2006 |
|
Status: Unverified
FACT(s) (Environment):
OpenEdge 10.1x
SYMPTOM(s):
ADD-NEW-FIELD method fails with error 80 and 5729
Using ADD-NEW-FIELD with a database field that has a different initial value format to the session can raise the runtime error 80 and 5729.
** The month of a date must be from 1 to 12. (80)
Incompatible datatypes during runtime conversion (5729)
Database date field with initial value 12/31/999 and a -d session setting of dmy.
Database field is defined with an initial value in American mdy format, and the client is trying to use ADD-NEW-FIELD with an incompatible date format (e.g dmy).
The problem does not happen in Progress 9.1x
CAUSE:
This is expected behavior. There have been changes in OpenEdge 10.x in the way initial values are processed. There were problems in this area in the past and these have been corrected.
FIX:
The initial value of the filed should not be passed as a string ("_field._initial"), it should always use the native data type of the field. For example:
/*******************************************************/
def var h as handle.
def var hb as handle.
def var hf as handle.
hb = buffer order:handle.
hf = hb:buffer-field("promisedate").
hf:FORMAT = "99/99/9999".
create temp-table h.
h:add-new-field(hf:name, hf:data-type,?, hf:format, hf:initial).
h:temp-table-prepare("mytab").
h:default-buffer-handle:buffer-create.
message "date in dmy" h:default-buffer-handle::promisedate.
/*******************************************************/
But as a work around use the ADD-LIKE-FIELD method. For example:
/*******************************************************/
DEFINE VARIABLE htemp# AS HANDLE NO-UNDO.
DEFINE VARIABLE h_field1 AS HANDLE NO-UNDO.
DEFINE VARIABLE h_field2 AS HANDLE NO-UNDO.
DEFINE VARIABLE h_buffer AS HANDLE NO-UNDO.
CREATE TEMP-TABLE htemp#.
FIND _file WHERE _file._file-name = "order".
FIND _field OF _file WHERE _field._field-name = "promiseDate".
/* Incorrect code */
/* htemp#:ADD-NEW-FIELD(_field._field-name, */
/* _field._data-type, */
/* ?, */
/* _field._format, */
/* _field._initial). */
/* WORK AROUND */
htemp#:ADD-LIKE-FIELD("promiseDate2","order." + _field._field-name).
htemp#:TEMP-TABLE-PREPARE("mytemp").
h_buffer = htemp#:DEFAULT-BUFFER-HANDLE.
h_Field2 = h_buffer:BUFFER-FIELD("promisedate2"),
h_field2:FORMAT = "99/99/9999".
MESSAGE "Finished" SKIP
h_Field2:NAME SKIP
h_Field2:FORMAT SKIP
h_Field2:INITIAL SKIP
VIEW-AS ALERT-BOX.
/*******************************************************/
Alternatively, if the ADD-LIKE-.FIELD method cannot be used, and it is not known at run time what format the initial value will be in, then it is possible to change the session settings in order to avoid the errors when using ADD-NEW-FIELD. For example:
/*******************************************************/
saveDateFormat = session:date-format.
saveNumFormat = session:numeric-format.
session:date-format = "mdy".
session:numeric-format = "A".
create temp-table htab.
htab:add-new-field("mydate","date",0,"99/99/9999","12/31/2003").
htab:temp-table-prepare("mydyn").
session:date-format = saveDateFormat.
session:numeric-format = saveNumFormat.
Then use the INITIAL attribute of the temp table field to get the value in the current session format to assign to the SCREEN-VALUE.
/*******************************************************/
.