Blog navigation

Latest posts

Capturing Detailed Errors After a Silent Import in Sage X3

 

You're likely familiar with manually generating CSV files for import through templates in Sage X3. But have you ever wondered how to capture detailed errors after a silent import? We have the solution for you.

There are instances where capturing incoming errors becomes essential, especially when you need to promptly alert end-users about issues like closed periods or incorrect dates. Unfortunately, the standard Sage X3 silent import function doesn't inherently display detailed errors during the import process.

Here's how you can overcome this limitation:

Start by calling the IMPORTSIL function:

Call IMPORTSIL([M:IMP2]MODIMP, [M:IMP2]NOMIMP) From GIMPOBJ

However, the standard ERR_IMPORT function will only provide an overall status of the importation without the specifics of errors. To address this limitation, you can utilize the following techniques:

  1. The IMPORTSIL function captures log data in a trace file to prevent popups on the end-user's screen.

  2. Examine the log file for any potential errors. Sage X3 runtime adheres to the same logging standards as typical shells.

  3. 0001 = Errors output

  4. 0000 = Standard output

This procedure ensures that you have a clear overview of the import process and any errors encountered.

For further clarity, consider the following example:

1) Initiate a silent import call in 4GL:

Code Description
[M:IMP2]MODIMP = YAOENAME Import Template Name
[M:IMP2]NOMIMP = YTMPFILE File Location and Name
[M:IMP2]TYPEXP = 2 Server
Call IMPORTSIL([M:IMP2]MODIMP, [M:IMP2]NOMIMP) From GIMPOBJ Invoke IMPORTSIL function
Call ERR_IMPORT([M:IMP2]STAT, YMESSAGE) From GIMPOBJ Retrieve import status
If [M:IMP2]STAT or GOK < 1 : YRESTA += 1 Handle Import Error
Else : YRESTA = 0 Import Successful
If !GSERVEUR : Call FERME_TRACE From LECFIC Close trace file if needed

2) Log reading process:

Code Description
Openi filpath("TRA", GTRACE, "tra", 0) Using [YTRA] Open trace file
Local Char XLINE(100) Declare variable for line
Repeat Repeat until end of file
Rdseq XLINE Using [YTRA] Read next line
If left$(XLINE, 5) = "<0001" Identify error
Append YMESSAGE(YRESTA), right$(XLINE, 6) : YRESTA += 1 Add error message
Break Exit loop
Elsif find(left$(XLINE, 11), "Création de") Check for successful import
[L]Y2_TSKNUM = right$(XLINE, 13) Retrieve task number
Append YMESSAGE(YRESTA), [L]Y2_TSKNUM : YRESTA += 1 Add success message
Endif End conditional
Until fstat <> 0 Loop until end of file
Openi Using [YTRA] Close trace file

 
Posted in: Sage X3, 4GL