Character and XML data (data type XML) directly to the IFS with SQL
This tool includes:
Program Type | Program/ Procedure Name | Description |
---|---|---|
Service Program | SNDMSG | contains the (RPG) prodecures for sending escape messages |
SQLRPGLE Program | WRT2IFS | for writing any character data to the IFS |
SQLRPGLE Program | WRTXML2IFS | for writing XML data (Data type XML) to the IFS |
SQL Stored Procedures | WRT2IFSxxxx | for writing any character data into the IFS. xxxx = File Operation i.e. Create/CreateReplace/Append |
SQL Stored Procedures | WRTXML2IFSxxxx | for writing XML data (data type XML) into the IFS. xxxx = File Operation i.e. Create/CreateReplace/Append |
Birgitta Hauser is Software and Database Engineer, focusing on RPG, SQL and Web development on IBM i at Toolmaker Advanced Efficiency GmbH in Germany. She also works in consulting with regard to modernizaing legacy IBM i applications IBM i as well as in education as a trainer for RPG and SQL developers.
Since 2002 she has frequently spoken at the COMMON User Groups and other IBM i and Power Conferences in Germany, other European Countries, USA and Canada.
In addition, she is co-author of two IBM Redbooks and also the author of several articles and papers focusing on RPG and SQL for a German publisher, IBM DeveloperWorks and IT Jungle.
Minimum IBM i Release: 7.2 TR7 (or 7.3 TR3)
- Create a module with the same name using the CRTRPGMOD CL command
CRTRPGMOD MODULE(YOURSCHEMA/SNDMSG) SRCFILE(YOURSCHEMA/QSRVPGMSRC) SRCMBR(SNDMSG)
- Create the service Program with the CRTSRVPGM
CRTSRVPGM SRVPGM(YOURSCHEMA/SNDMSG) MODULE(SNDMSG) SRCFILE(YOURSCHEMA/QSRVSRC) SRCMBR(SNDMSG)
- Delete the module after having successfully created the service program.
If you create a binder directory with the name HSBNDDIR in your schema and add the SNDMSG service program to this binder directory, the RPG programs can be compiled with the the CRTSQLRPGI command.
CRTSQLRPGI OBJ(YOURSCHEMA/WRTUT82IFS) SRCFILE(YOURSCHEMA/QRPGLESRC) SRCMBR(WRTUT82IFS) OBJTYPE(*PGM)
The SQL Scripts containing the source code for the stored procedures, can be run with the RUNSQLSTM command:
RUNSQLSTM SRCFILE(YOURSCHEMA/QSQLSRC) SRCMBR(WRT2IFS) COMMIT(*NONE) NAMING(*SYS) MARGINS(132) DFTRDBCOL(YOURSCHEMA)
It is also possible to run the SQL scripts from the b>RUN SQL SCRIPTING facility in Client Access or (even better) ACS (Access Client Solution).
Attention: | The database objects are not qualified in the SQL script, so you need to add YOURSCHEMA to the script by yourself. |
Function Name | Description |
---|---|
SndEscMsg | Send Escape message from within an RPG internal or exported procedure. |
SndEscMsgLinMain | Send Escape message from within an RPG linear main procedure |
Both procedures are needed for signaling errors in the WRT2IFS and WRTXML2IFS RPG Programs.
Parameter:
Parameter Name | Data Type/Length | Description | |
---|---|---|---|
ParText | VarChar(16000000) | Text to be written into the IFS | |
ParIFSFile | VarChar(1024) | IFS File to be written, replaced or appended | |
ParOperation | Integer | 8=Create / 16=Replace / 32=Append |
With the WRT2IFS program any character data can be written to the IFS into the passed IFS file. Depening on the file operation a new file will be created, or replaced or the data is added to an existing IFS file. The program WRT2IFS is registered as SQL Stored Procedure.
Parameter:
Parameter Name | Data Type/Length | Description |
---|---|---|
ParXML | VarChar(16000000) | Serialized XML data to be written into the IFS |
ParIFSFile | VarChar(1024) | IFS File to be written, replaced or appended |
ParOperation | Integer | 8=Create / 16=Replace / 32=Append |
With the WRTXML2IFS program wellformed XML data can be written to the IFS. epening on the file operation a new file will be created, or replaced or the data is added to an existing IFS file. The program WRTXML2IFS is registered as SQL Stored Procedure.
Parameter:
Parameter Name | Data Type/Length | Description |
---|---|---|
ParText | CLOB(16 M) | Text to be written into the IFS |
ParIFSFile | VarChar(1024) | IFS File to be written, replaced or appended |
ParOperation | Integer | 8=Create / 16=Replace / 32=Append |
The WRT2IFS stored procedure is a wrapper around the WRT2IFS RPG Program. The WRT2IFSxxxxx stored procedures call the WRTIFS stored procedure with a specific File Operation.
Example:
Call wrt2IFS('This is a test for checking whether data is written to the IFS', '/home/Hauser/Test20180224', 8);
Parameter:
Parameter Name | Data Type/Length | Description |
---|---|---|
ParText | CLOB(16 M) | Text to be written into the IFS |
ParIFSFile | VarChar(1024) | IFS File to be written, replaced or appended |
Calls the WRT2IFS Procedure, the File Operation is passed fix with 8. A new IFS file will be created. If the file already exists an error will be returned.
Example:
Call Wrt2IFS_Create(Cast('{"root": {"Name": "Hauser", "FirstName": "Birgitta"}' as VarChar(256) CCSID 1208), '/home/Hauser/Tst20180224');
Parameter:
Parameter Name | Data Type/Length | Description |
---|---|---|
ParText | CLOB(16 M) | Text to be written into the IFS |
ParIFSFile | VarChar(1024) | IFS File to be written, replaced or appended |
Calls the WRT2IFS Procedure, the File Operation is passed fix with 16. A new IFS file will be created. If the file already exists the existing one is replaced.
Example:
Call Wrt2IFS_CreateReplace(Cast('{"root": {"Name": "Hauser", "FirstName": "Birgitta", "City": "Kaufering"}' as VarChar(256) CCSID 1208), '/home/Hauser/Tst20180224');
Parameter:
Parameter Name | Data Type/Length | Description |
---|---|---|
ParText | CLOB(16 M) | Text to be written into the IFS |
ParIFSFile | VarChar(1024) | IFS File to be written, replaced or appended |
Calls the WRT2IFS Procedure, the File Operation is passed fix with 32 A new IFS file will be created. If the file already exists the text is appended at the end.
Example:
Call Wrt2IFS_Append(Cast(', {"Street": "Dr.-Gerbl-Str.", "HausNr": 20}}' as VarChar(256) CCSID 1208), '/home/Hauser/Tst20180224');
Parameter:
Parameter Name | Data Type/Length | Description |
---|---|---|
ParText | XML | XML data to be written into the IFS |
ParIFSFile | VarChar(1024) | IFS File to be written, replaced or appended |
ParOperation | Integer | 8=Create / 16=Replace / 32=Append |
The WRTXML2IFS stored procedure is a Wrapper around the WRTXML2IFS RPG Program. The WRTXML2IFSxxxxx stored procedure call the WRTXML2IFS stored procedure with a specific File Operation.
Example:
Call WrtXML2IFS(XMLElement(Name "root", XMLElement(Name "Name", 'Hauser')), '/home/Hauser/TstXML20180224.xml', 16);
Parameter:
Parameter Name | Data Type/Length | Description |
---|---|---|
ParText | XML | XML Data to be written into the IFS |
ParIFSFile | VarChar(1024) | IFS File to be written, replaced or appended |
Calls the WRTXML2IFS Procedure, the File Operation is passed fix with 8 A new IFS file will be created. If the file already exists an error will be returned
Example:
Call WrtXML2IFS_Create(XMLElement(Name "root", XMLElement(Name "Name", 'Hauser')), '/home/Hauser/TstXML20180224.xml');
Parameter:
Parameter Name | Data Type/Length | Description |
---|---|---|
ParText | XML | XML Data to be written into the IFS |
ParIFSFile | VarChar(1024) | IFS File to be written, replaced or appended |
Calls the WRTXML2IFS Procedure, the File Operation is passed fix with 16 A new IFS file will be created. If the file already exists the existing one is replaced.
Example:
Call WrtXML2IFS_CreateReplace(XMLElement(Name "root", XMLElement(Name "Name", 'Hauser'), XMLElement(Name "FirstName", 'Birgitta')), '/home/Hauser/TstXML20180224.xml');```
Parameter:
Parameter Name | Data Type/Length | Description |
---|---|---|
ParText | XML | XML Data to be written into the IFS |
ParIFSFile | VarChar(1024) | IFS File to be written, replaced or appended |
Calls the WRTXML2IFS Procedure, the File Operation is passed fix with 32 A new IFS file will be created. If the file already exists the text is appended at the end.