Monday, July 9, 2018

Data Integration

External data comes in many different formats. This section describes
mechanisms to read and write data in four different, but commonly used, formats.
With all external interaction in X++, code access permission must be asserted.


IO classes

The standard classes that extend the IO class are useful for importing and
exporting data to and from a simple text file format. Most commonly, these are
TXT or CSV files.

The CommaIO and Comma7IO classes are used to import and export comma
separated data.
The TextIO and AsciiIO classes are used to import and export text
-based data.
The BinaryIO class is used to import and export binary data.
The following code is an examp
le of the CommaIO class:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
FileName fileName = 'c:\\test.csv';
FileIoPermission permission;
CommaIO commaIO;
container readCon;
int i;
int level;
str column1;
str column2;
str column3;
;
permission= new FileIoPermission(filename,'r');
permission.assert();
commaIO = new CommaIo(filename, 'r');
commaIO.inFieldDelimiter(';'); // Delimiter...
if (commaIO)
{
  while (commaIO.status() == IO_Status::OK)
  {
    readCon = commaIO.read();
    column1 = conPeek(readCon, 1);
    column2 = conPeek(readCon, 2);
    column3 = conPeek(readCon, 3);
    info(strFmt("%1 - %2 - %3", column1, 
    column2,
    column3));
  }
}

In this example, a specific field delimiter character has been specified. By
default, the field delimiter character for CommaIO is the comma character, but in
this case the code specifies the semi
-colon character as the field delimiter.
The commaIO object is looped over, using a "while" statement, which continues
until the IO_status is no longer OK, which indicates the end of the file.
The CommaIO.read() method returns data from a single record (or row) from the
file, in the form of a container, where each container element is a single field
value. In this example, there are at least three fields per row.


Best Regards,
Hossein Karimi

No comments:

Post a Comment

Configure the Firewall on the Enterprise Portal Server

After you install Enterprise Portal, enable Web Server (HTTP) in Windows Firewall. If you do not enable the web server in Windows Firewall...