Friday, September 26, 2014

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.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.