When an error occurs on the server, you can return useful information to the client using the ERROR-STRING attribute. This attribute can be set at the row level for a system-related or data-related type of error. It can also be set at the temp-table level to provide error summary information for the temp-table.

Provide before-table and after-table row values for the error

The ERROR-STRING attribute is normally set when an error is encountered during SAVE-ROW-CHANGES. It is a best practice to provide contextual information about the error from the data in the corresponding after-table row. Format error information so that the client code can present the ERROR-STRING directly without modification.

ABL provides two attribute that can be used to match rows in the before-tables and after-tables: These attributes can be used to locate a corresponding record in the other table using the FIND-BY-ROWID( ) method.

For example, if an error occurred in SAVE-ROW-CHANGES for a particular before-table buffer, you can obtain the row values in the corresponding after-table row by setting the buffer (hBuffer) as follows:

hBuffer:FIND-BY-ROWID(hBeforeBuffer:AFTER-ROWID). 
The following example shows how to set the ERROR-STRING after encountering an error during SAVE-ROW-CHANGES.
  • The ERROR attribute is set to TRUE by the system if an error occurs.
  • Using the after-table, find the corresponding record using the FIND-BY-ROWID() method and the AFTER-ROWID for the before-table record.
  • Set the ERROR-STRING attribute with information about the record in the after-table buffer.
hQuery:GET-FIRST.

DO WHILE hQuery:AVAILABLE:
  hBeforeBuffer:SAVE-ROW-CHANGES() NO-ERROR.
  
  /* there was an error with save-row-changes;
  handle row-modified */
  IF hBeforeBuffer:ERROR AND hBeforeBuffer:ROW-STATE = ROW-MODIFIED
  THEN DO:
    hBuffer:FIND-BY-ROWID(hBeforeBuffer:AFTER-ROWID).
    hBuffer:ERROR-STRING = "Cannot modify order for OrderNum = " + 
      STRING(hBuffer::OrderNum).
  END.
  hQuery:GET-NEXT.
END. 

Retrieve the ERROR-STRING value in the client

To retrieve ERROR-STRING values in your client code, you first check if an ERROR was set at the dataset level. If it was set, iterate through the change dataset’s after-table to find specific errors. For each error found, you can display and/or process the error messages found in ERROR-STRING. Recall that attributes set in the server for the before-table and before-table-buffer are automatically set for the corresponding after-table and after-table buffer.

This code example shows the calling procedure’s code on the client.

IF DATASET dsOrderOrderLine:ERROR = TRUE THEN
DO:
  FOR EACH ttOrderLine:
    IF BUFFER ttOrderLine:ERROR = TRUE THEN
    DO:
      MESSAGE BUFFER ttOrderLine:ERROR-STRING.
    END.
  END.
END.

Next steps

This completes the learning track for datasets. For more detailed information on datasets see the Use ProDataSets guide. For additional developer learning paths see the Developer landing page.