Kbase P110020: 4GL application stops unexpectedly.
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/16/2008 |
|
Status: Unverified
SYMPTOM(s):
4GL application stops unexpectedly.
4GL program imports ASCII data via the IMPORT statement.
IMPORT statement raises the STOP condition.
The ASCII file being imported contains corrupted lines.
IMPORT statement uses the NO-ERROR clause.
CAUSE:
This is a known issue.
If IMPORT with the NO-ERROR clause reads a malformed line, which does trigger the ERROR condition, then any subsequent attempt to IMPORT data from the same stream will consistently raise the STOP condition, whether the data being IMPORT'd is well- or malformed. Closing and re-opening the same stream for input will not be enough to work around the problem.
FIX:
The workaround implies exiting the procedure where IMPORT NO-ERROR is, so that the 4GL engine will destroy the stream from which the data is being read. The following sample code can give an idea of how to implement it.
/* outer.p
This is the main program to launch. */
DEFINE VARIABLE iOffset AS INTEGER NO-UNDO.
DEFINE VARIABLE lRetry AS LOGICAL NO-UNDO.
ASSIGN iOffset = 0.
REPEAT:
RUN importCustomer.p ("customer.d",
INPUT-OUTPUT iOffset,
OUTPUT lRetry).
IF NOT lRetry THEN
LEAVE.
END.
/* importCustomer.p */
DEFINE INPUT PARAMETER pcFileName AS CHARACTER NO-UNDO.
DEFINE INPUT-OUTPUT PARAMETER piOffset AS INTEGER NO-UNDO.
DEFINE OUTPUT PARAMETER plRetry AS LOGICAL NO-UNDO.
DEFINE STREAM strIn.
DEFINE TEMP-TABLE tmpCust NO-UNDO LIKE customer.
DEFINE VARIABLE iLine AS INTEGER NO-UNDO.
CREATE tmpCust.
ASSIGN plRetry = FALSE.
INPUT STREAM strIn FROM VALUE("customer.d":U) BINARY NO-MAP.
IF piOffset <> 0 THEN
SEEK STREAM strIn TO piOffset.
lbImport:
REPEAT ON ERROR UNDO, LEAVE
ON ENDKEY UNDO, LEAVE
ON STOP UNDO, RETRY:
IF RETRY THEN DO:
/* We know that we are here only if a STOP condition was raised,
because ERROR and ENDKEY conditions will cause the REPEAT
loop to exit (as per ON ERROR and ON ENDKEY phrases). */
ASSIGN plRetry = TRUE.
LEAVE.
END.
ASSIGN piOffset = SEEK(strIn).
IMPORT STREAM strIn tmpCust NO-ERROR.
IF ERROR-STATUS:ERROR THEN DO:
/* Handle the corrupted record here.
Usually, you will simply want to
go to the next record. */
UNDO lbImport, NEXT lbImport.
END.
END.
INPUT STREAM strIn CLOSE.