How To Use The Import Templates Programmatically
How To Use The Import Templates Programmatically
Sage ERP X3 provides a great number of import templates (function GESAOE) that can be used
when performing data migration from another application. But another option is to use the
import templates programmatically in order to create documents and records on the fly. Here
is how.
In the above example, we first create a local char variable WNOMFIC and assign to it the path
where we are going to save the temporary file that will be used by the import template
(C:\SAGE\SAGEX3V6\X3V6\Folders\DEMO\ZIMPEXP\IMPOR\), as well as the file name (SMR).
Both can be different from what is shown in the example. Also, the file could have an
extension (SMR.dat, SMR.txt, etc.), but this is not mandatory.
Then we write to the file using standard 4GL instructions (Openo, Iomode, Wrseq). What we
write is the actual content of the import template, as specified in the GESAOE function. In
this case it is the SMR template for miscellaneous receipts.
Finally, we run the import template with the IMPORTSIL function. This function is located in
the GIMPOBJ file and takes two parameters - the import template code and the name of the
file to be used by the import template.
With this technique we can create all kinds of documents and records programmatically -
orders, invoices, products, customers, accounting entries, etc. And, of course, the data can
be dynamic. For instance, in the above case we could have a screen where the user selects
product, quantity, storage site and location. The values of the corresponding fields in the
import template file would then be supplied by the user entries (for example, the first string
written to the above file could be
supposing [M:ZES]FCY is the screen field where the user enters the site code). This would give
us a neat and quick functionality for adding stock to our storage sites.
Aditional
WRSEQ Contents
Wrseq is used to write data on a text file opened by Openo or Openio.
Syntax
Parameters
Element Description Restrictions
Examples
Wrseq is used to write in a text file recordings separated by a recording separator containing an
indifferent number of fields, themselves being separated by a field separator.
Wrseq is used jointly with the adxirs Adonix system variable to define the recording separator,
the adxifs Adonix system variable to define the field separator and the adxium Adonix system variable
to define the coding of the character string:
adxifs is of character string type with a maximum length of 1, assigned with the corresponding
character. By default, it is the empty string. This corresponds to a read until the end of the
recording, without any separator,
adxirs is of character string type with a maximum of 2 characters. By default, its value is "line
feed" (chr$(10)).
adxium is of numerical type. value = 50 for an ASCII coding, value<>50 & value <>122 for an
UTF8 coding. By default, Adxium is set for a coding in UTF8.
These three variables can be impacted for each file for the Iomode instruction.
If the Wrseq order does not end with ',' or ';', the recording separator (adxirs value) is written on the
file.
The numerical or date-type variables are automatically converted to character strings in the file, as if
the num$ Adonix function had been used..
The Using clause is used to specify the class of the sequential file that is being written. It is now
possible to process several sequential files at the same time.
It is possible to write an image file (or Clob) to a sequential file to the format defined by adxium using
the Wrseq instruction. The file will then have the number of characters of the image file (or Clob).
Remarks
The adxseek(1) or adxseek(class) function (for a file open with a class) indicates the current position in
the file (in number of bytes) with respect to the beginning of the file. This variable is equal to -1 if no
file has been openend in writing mode by Openo or Openio.
Since the writes in a file are buffered, they are only effective after said file has been closed by the
Openo or Openio instructions. It means that, before the operation, the size of the file on the disk can be
unchanged after Wrseq.
"Seek 0" makes it possible to force the write of a file that has been opened by Openio.
Associated errors
Error Description
ERDIM
Variable with more than one dimension
(55)
ERULIM
ulimit problem (the file is too big).
(65)
ERGFIC
File not open .
(24)
ERMDISK
No space available any longer on the disk.
(44)
Associated keywords
OPENO - OPENIO - ADXSEEK - SEEK - ADXIFS - ADXIRS - ADXIUM - IOMODE
CONTENTS