我想读取表字段的默认值。我目前正在使用以下语法:
DEF VAR iDefaultValue AS INT NO-UNDO。
iDefaultValue = BUFFER MyTable:BUFFER-FIELD(“MyField”):DEFAULT-VALUE。…
您还可以使用缓冲区中的字段编号。如果添加新字段或重新排序字段,则可能会中断。
iDefaultValue = BUFFER u-ort:BUFFER-FIELD(1):DEFAULT-VALUE.
无论您如何操作,都可以在运行时检查此错误,也可以记录它或适合您的应用程序。
DEFINE VARIABLE iDefaultValue AS INTEGER NO-UNDO. DEFINE VARIABLE iErrors AS INTEGER NO-UNDO. iDefaultValue = BUFFER myTable:BUFFER-FIELD("MyField"):DEFAULT-VALUE NO-ERROR. IF ERROR-STATUS:ERROR THEN DO: DO iErrors = 1 TO ERROR-STATUS:NUM-MESSAGES: /* 7351 BUFFER-FIELD <field-name> was not found in buffer <buffer-name>. (7351) You gave a character expression as the argument to the BUFFER-FIELD method of a buffer object, but the character string did not identify any field in that buffer. Check your PROGRESS dictionary for the field names for the table, and do not abbreviate the field name. */ IF ERROR-STATUS:GET-NUMBER(iErrors) = 7351 THEN DO: MESSAGE "Buffer field name was wrong" VIEW-AS ALERT-BOX. END. END. END.
你可以定义变量 like 该领域并使用其价值。
like
DEF VAR iDefaultValue like myTable.MyField NO-UNDO. /* Don't change the variable! */
当然,如果更改了数据库字段的初始值,则需要重新编译,否则将获得旧的初始值。 如果要确保始终获取当前值并在编译时捕获错误,则可以编写
DEF VAR iDefaultValue like myTable.MyField NO-UNDO. iDefaultValue = BUFFER MyTable:BUFFER-FIELD("MyField"):DEFAULT-VALUE.
在这种情况下,当重命名字段但不重新编译代码时,仍会出现运行时错误。 使用以下代码,在后一种情况下启动程序时应该会出错。
DEF VAR iDefaultValue like myTable.MyField NO-UNDO. define frame f_dummy myTable.MyField view-as fill-in skip with side-labels width 255 stream-io. iDefaultValue = BUFFER MyTable:BUFFER-FIELD("MyField"):DEFAULT-VALUE.
我想你必须决定哪种行为更适合你。 所有示例都假定表和字段名称在编译时是已知的。