0% found this document useful (0 votes)
302 views

How To Use The Import Templates Programmatically

This document describes how to programmatically use Sage ERP X3 import templates to create documents and records. It provides an example of writing data to a file using 4GL instructions like Openo, Iomode, and Wrseq, and then calling the IMPORTSIL function to run the import template on that file. This allows dynamically generating content for import templates rather than just using the GESAOE function. Additional fields could come from user input to make the imported data dynamic.

Uploaded by

Axl Axl
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
302 views

How To Use The Import Templates Programmatically

This document describes how to programmatically use Sage ERP X3 import templates to create documents and records. It provides an example of writing data to a file using 4GL instructions like Openo, Iomode, and Wrseq, and then calling the IMPORTSIL function to run the import template on that file. This allows dynamically generating content for import templates rather than just using the GESAOE function. Additional fields could come from user input to make the imported data dynamic.

Uploaded by

Axl Axl
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

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.

Local Char WNOMFIC(250)


WNOMFIC="C:\SAGE\SAGEX3V6\X3V6\Folders\DEMO\ZIMPEXP\IMPOR\SMR"

Openo WNOMFIC, 0 Using [ZSMR]

Iomode adxifs "" Using [ZSMR]


Iomode adxirs chr$(13)+chr$(10) Using [ZSMR]
Iomode adxium 50 Using [ZSMR]

Wrseq "E;19;;210;20140911;Misc. receipt;;" Using [ZSMR]


Wrseq "L;1000;BP20;My item;UN;10;UN;10;10" Using [ZSMR]
Wrseq "S;UN;10;;;;C110;A;" Using [ZSMR]

Openo Using [ZSMR]

Call IMPORTSIL("SMR", WNOMFIC) From GIMPOBJ

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

Wrseq "E;19;;"+[M:ZES]FCY+";20140911;Misc. receipt;;" Using [ZSMR]

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

   Wrseq expr_list [ sep ] [ Using class ]

Parameters
Element Description Restrictions

expr_list List of indifferent None.


expressions to write,
separated by ',' or ';'.

sep Separator that can be ',' None.


or ';'.

class Abbreviation describing None


the open file.

Examples

   # Addition of a line to the passwd file in the connection directory


   # (it presents the file structure /etc/passwd)
    Char NAME(20), PASSWORD(20)
    Integer USR_NO, GROUP_NO
    Char COMMENT(50), LOGIN_DIR(50), SHELL_USED(50)
    NAME = "toto"
    USR_NO = 0
    GROUP_NO = 0
    COMMENT = "test"
    LOGIN_DIR = ""
    SHELL_USED = ""
    PASSWORD = ""
    Openo getenv$("HOME")+"/passwd", -1
    adxifs = ':' : adxirs = chr$(10)
    Wrseq NAME, PASSWORD, USR_NO, GROUP_NO,
    Wrseq COMMENT, LOGIN_DIR, SHELL_USED
    Openo

   # Write on 3 sequential files


    Char MOT1(30)
    Char MOT2(30)
    Char MOT3(30)
    adxifs = ':' : adxirs = chr$(10)
    Openo filpath('TRT','ZINSTRUC1','txt') Using [FIC1]
    Openo filpath('TRT','ZINSTRUC2','txt') Using [FIC2]
    Openo filpath('TRT','ZINSTRUC3','txt') Using [FIC3]
    MOT1 = "abcde"
    MOT2 = "fghij"
    MOT3 = "klmno"
    Wrseq MOT1 Using [FIC1]
    Wrseq MOT2 Using [FIC2]
    Wrseq MOT3 Using [FIC3]
    Openo Using [FIC1]
    Openo Using [FIC2]
    Openo Using [FIC3]

Description and comments

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.

Warning ! Wrseqcannot write a file coded in UCS2.

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..

Each written field can contain a maximum of 255 characters.

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

You might also like