One of the challenges in any data system is how to share data with other systems. There are many times you need to create a data file that can be exported into other systems. This can be anything like from an ACH file that goes to the back, a Skip Trace file or any other kind of data file.
The challenge in building these files is finding a way to convert all the required fields into text data for the flat file. CA 2E provides multiple ways you can do this. The first is to use the built-in function, *CVTVAR, to convert each numeric field type into a text field type then concatenating all the fields together. This works but it takes a while to code.
The process can be greatly simplified if you use an array. Here are the steps:
1. Create an array with all the fields you plan to export. The fields can be both numeric and text fields.
2. Create a CRTOBJ function for the array. The input parameters will be the fields for the array and the output parameter will be the text field for the new flat file you plan to build.
3. In the ‘Processing after Data’ update section of the Action diagram, add a CVTVAR. The input will be the ELM context. This sends in all the elements of the array. The output is the Flat File field that is the output parameter.
4. Now you are ready to build the export file. Build a retrieve that will read though the data that you want to export. In the example, we are reading the customer file. For each record in the customer file:
- Clear the array.
- Call the create object for the array which returns the Flat File Field.
- Create a record in the flat file.
That is all there is to it. There is no need to work with individual fields or concatenate a string of fields together to make a flat text record. The array does the grunt work for you with ease.