Hi,
I am reading a PF that gets populated by another system, and all the fields are defined as character fields, even those fields that contain numeric values. (the file originates as a text file)
I read the file and then write the records to a header and a detail file, manipulating the data a little along the way.
The header file has about 40 fields from the input file, and those fields are named the same in the header file as the header fields from the input file, even though some of the field types are different (for example the numeric fields). Similarly, the detail file has the same field names as the detail fields in the input file, even though again some of the field types are different.
An easy way to move fields with the same names from the input file to the header and detail files is using Eval-Corr, so I have defined a data structure for each of the three files. I do Eval-Corr dsHeader = dsInput and Eval-Corr dsDetail = dsInput, and it moves all the fields that are named the same and are compatible types and ignores the rest. Then for the fields where I need to convert the alpha fields to numeric, I do dsHeader.myField = %dec(dsInput.myField:7:2) and dsDetail.myOtherField = %dec(dsInput.myOtherField:7:2). So that approach takes care of all the header and detail fields that didn't get moved with the EVAL-CORR statements.
This all seems great EXCEPT: Since the same field names are defined in the input file and also the header file, and also in the input and detail file, but some of these have different attributes, I get the error:
RNF7406: Data-Format entry does not match the definition of the input field MYFIELD.
Normally, to deal with this I can just use PREFIX on the files in the F-specs to name the fields differently. But if I do that, my EVAL-CORR won't move any of the fields because now the subfields aren't named the same anymore.
How to deal with this? I'd like the convenience of using EVAL-CORR to move the majority of the fields yet need to rename the fields in order for the files to be defined properly. The only way I can think of is to use SQL for all the I/O instead of native I/O so that I wouldn't have to define the files in the F-specs. Any other ideas?
Thanks.
Current code:
I am reading a PF that gets populated by another system, and all the fields are defined as character fields, even those fields that contain numeric values. (the file originates as a text file)
I read the file and then write the records to a header and a detail file, manipulating the data a little along the way.
The header file has about 40 fields from the input file, and those fields are named the same in the header file as the header fields from the input file, even though some of the field types are different (for example the numeric fields). Similarly, the detail file has the same field names as the detail fields in the input file, even though again some of the field types are different.
An easy way to move fields with the same names from the input file to the header and detail files is using Eval-Corr, so I have defined a data structure for each of the three files. I do Eval-Corr dsHeader = dsInput and Eval-Corr dsDetail = dsInput, and it moves all the fields that are named the same and are compatible types and ignores the rest. Then for the fields where I need to convert the alpha fields to numeric, I do dsHeader.myField = %dec(dsInput.myField:7:2) and dsDetail.myOtherField = %dec(dsInput.myOtherField:7:2). So that approach takes care of all the header and detail fields that didn't get moved with the EVAL-CORR statements.
This all seems great EXCEPT: Since the same field names are defined in the input file and also the header file, and also in the input and detail file, but some of these have different attributes, I get the error:
RNF7406: Data-Format entry does not match the definition of the input field MYFIELD.
Normally, to deal with this I can just use PREFIX on the files in the F-specs to name the fields differently. But if I do that, my EVAL-CORR won't move any of the fields because now the subfields aren't named the same anymore.
How to deal with this? I'd like the convenience of using EVAL-CORR to move the majority of the fields yet need to rename the fields in order for the files to be defined properly. The only way I can think of is to use SQL for all the I/O instead of native I/O so that I wouldn't have to define the files in the F-specs. Any other ideas?
Thanks.
Current code:
Code:
FFEC010 IF E K DISK FFEC011 UF A E K DISK FFEC012 UF A E K DISK D ds010 Ds LikeRec(IEC010:*input) D ds011 Ds LikeRec(IEC011:*output) D ds012 Ds LikeRec(IEC012:*output) //-- Variables D saveOrderID s Like(ORDERID) Inz /Free //-- Read through raw order records in FEC010 Setll *start FEC010; Dow not %eof(FEC010); Read FEC010 ds010; If not %eof(FEC010); //-- Write order to order header and detail files If ds010.orderID <> saveOrderID; Exsr WriteHeader; saveOrderID = ds010.orderID; Endif; Exsr WriteDetail; Endif; EndDo; *inLR = *on; Return; //------------------------------------------------------------ // WriteHeader : Write order header record //------------------------------------------------------------ Begsr WriteHeader; Clear IEC011; //-- Move the majority of the header fields straight across Eval-Corr ds011 = ds010; //-- Handle the incompatible fields individually ds011.ORDERTS = %date(%subst(ds010.ORDERDATE:1:10)) + %time(%subst(ds010.ORDERDATE:11:8)); ds011.ORDERSUBT = pToDecimal(ds010.ORDERSUBT); ds011.ORDERTAX = pToDecimal(ds010.ORDERTAX); ds011.ORDERSHIP = pToDecimal(ds010.ORDERSHIP); ds011.ORDERDISC = pToDecimal(ds010.ORDERDISC); ds011.ORDERTOTAL = pToDecimal(ds010.ORDERTOTAL); ds011.ORDERPAID = pToDecimal(ds010.ORDERPAID); ds011.ORDERREF = pToDecimal(ds010.ORDERREF); ds011.ORDERDUE = pToDecimal(ds010.ORDERDUE); ds011.ORDERQTY = pToDecimal(ds010.ORDERQTY); Write IEC011 ds011; Endsr; //------------------------------------------------------------ // WriteDetail : Write order detail records //------------------------------------------------------------ Begsr WriteDetail; Clear IEC012; //-- Move the majority of the detail fields straight across Eval-Corr ds012 = ds010; //-- Handle the incompatible fields individually ds012.ITEMLINE = %int(pToDecimal(ds010.ITEMLINE)); Monitor; ds012.ITEMSKU = %int(ds010.ITEMSKU); On-Error; ds012.ITEMSKU = 0; Endmon; ds012.ITEMPRICEO = pToDecimal(ds010.ITEMPRICEO); ds012.ITEMPRICE = pToDecimal(ds010.ITEMPRICE); ds012.ITEMQTYORD = %int(pToDecimal(ds010.ITEMQTYORD)); ds012.ITEMQTYINV = %int(pToDecimal(ds010.ITEMQTYINV)); ds012.ITEMQTYSHP = %int(pToDecimal(ds010.ITEMQTYSHP)); ds012.ITEMQTYCNC = %int(pToDecimal(ds010.ITEMQTYCNC)); ds012.ITEMQTYREF = %int(pToDecimal(ds010.ITEMQTYREF)); ds012.ITEMTAX = pToDecimal(ds010.ITEMTAX); ds012.ITEMDISC = pToDecimal(ds010.ITEMDISC); ds012.ITEMTOTAL = pToDecimal(ds010.ITEMTOTAL); Write IEC012 ds012; Endsr; /End-Free
Comment