Consultor Eletrônico



Kbase P118702: Error: "Invalid source for IMPORT of LONGCHAR variable." IMPORTing a file into a LONGCHAR.
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   13/09/2006
Status: Unverified

SYMPTOM(s):

Error: "Invalid source for IMPORT of LONGCHAR variable." Importing a file into a LONGCHAR.

Executing code similar to:
DEFINE VARIABLE lchLine AS LONGCHAR NO-UNDO.
INPUT FROM VALUE('Customer.xml').
OUTPUT TO VALUE('testread.txt').
REPEAT ON ERROR UNDO, LEAVE:
IMPORT lchLine.
IF lchLine = ? OR lchLine = '' THEN
NEXT.
EXPORT lchLine.
END.
INPUT CLOSE.
OUTPUT CLOSE.

The output file "testread.txt" contains one line only. Namely, the error: Invalid source for IMPORT of LONGCHAR variable.

CAUSE:

The input file is not properly formatted to be a valid source for the IMPORT statement when the target is a LONGCHAR. The IMPORT statement expects to see the code page marker at the beginning of the source file.

FIX:

When importing a LONGCHAR variable, Progress uses the code page information in the file header to determine the variable?s code page. This information would already be in the file if there if the file is the result of a previously executed EXPORT statement of a long LONGCHAR variable. The above code may be corrected by either manually or programmatically inserting a code page header like "!ISO8859-1!" at the very top of the file or by first exporting it into an intermediate file and then importing that intermediate file into the LONGCHAR:
DEFINE VARIABLE lchLine AS LONGCHAR NO-UNDO.
/* EXPORT the file into an intermediate file */
OUTPUT TO VALUE('temp.txt').
COPY-LOB FROM FILE "Customer.xml" TO lchLine.
EXPORT lchLine.
OUTPUT CLOSE.
/* IMPORT from the intermediate file */
INPUT FROM VALUE('temp.txt').
OUTPUT TO VALUE('testread.txt').
REPEAT ON ERROR UNDO, LEAVE:
IMPORT lchLine.
IF lchLine = ? OR lchLine = '' THEN
NEXT.
EXPORT lchLine.
END.
INPUT CLOSE.
OUTPUT CLOSE.

If you were to examine the contents of the intermediate file temp.txt, you will notice that it is the same as the original plus a code page indicator inserted at the very beginning of the file. An LONGCHAR variable EXPORT or IMPORT statement code page indicator, also referred to as code page information or header or marker, is made of a starting exclamation mark + the code page name + an ending exclamation mark. For example !ISO8859-1!.