His solution works great, and I've been using this method as a template for all of my files that need to be created in this manner. However, I've run into a new situation with a txt file where I can't quite make this method work.
Namely, I have to include a calculated total in my trailer record (TRAIL2 and TRAIL3 in my example below), and I can't quite figure out how to do that without breaking the append. I can get the header and content to append just fine, and I can get the trailer to append when I'm not trying to do any summing on numerical fields.
I've tried several different methods with no success, here is my latest failed attempt:
-DEFAULT &R_YR = 2015; SET HOLDLIST = PRINTONLY FILEDEF EOYFILE DISK 111111_test_file.txt (LRECL 21 RECFM V APPEND -RUN DEFINE FILE CAR HEAD1/A4 = '&R_YR'; HEAD2/A7 = 'BBBBBBB'; HEAD3/A7 = 'CCCCCCC'; HEAD4/A3 = 'DDD'; HEADER/A21 = HEAD1|HEAD2|HEAD3|HEAD4; CON1/A2 = 'EE'; CON2/A2 = 'FF'; CON3/A17 = 'GGGGGGGGGGGGGGGGG'; CONTENT/A21 = CON1|CON2|CON3; TRAIL1/A2 = 'HH'; TRAIL2/I5L = 3; TRAIL3/I9L = 1600; TRAIL4/A5 = 'IIIII'; END -* Getting the header record TABLE FILE CAR SUM HEADER BY HIGHEST 1 COUNTRY NOPRINT ON TABLE HOLD AS EOYFILE FORMAT ALPHA END
-RUN -* Appending the data TABLE FILE CAR PRINT CONTENT BY COUNTRY NOPRINT ON TABLE HOLD AS EOYFILE FORMAT ALPHA END -RUN -* Calculating the sum of TRAIL2 and TRAIL3 TABLE FILE CAR SUM FST.TRAIL1 TRAIL2 TRAIL3 FST.TRAIL4 ON TABLE HOLD AS HOLD1 END -* Appending the footer record TABLE FILE HOLD1 SUM COMPUTE TRAILER/A21 = TRAIL1|FPRINT(TRAIL2,'I5L','A5')|FPRINT(TRAIL3,'I9L','A9')|TRAIL4; ON TABLE HOLD AS EOYFILE FORMAT ALPHA END -RUN TABLE FILE EOYFILE PRINT * ON TABLE PCHOLD FORMAT ALPHA END -RUN
Does anyone have any idea what I could do to get the desired results.This message has been edited. Last edited by: rray9895,
WebFOCUS 8.105M, Windows 10, App Studio
September 24, 2015, 10:20 AM
Francis Mariani
I added MAX.COUNTRY NOPRINT to include a real column in the request - this is to avoid the message "(FOC493) NO ACCESSIBLE FIELDS ARE MENTIONED IN THE REQUEST". The fex then completes without error. This may solve the problem...
-DEFAULT &R_YR = 2015;
SET HOLDLIST = PRINTONLY
FILEDEF EOYFILE DISK 111111_test_file.txt (LRECL 21 RECFM V APPEND
-RUN
DEFINE FILE CAR
HEAD1/A4 = '&R_YR';
HEAD2/A7 = 'BBBBBBB';
HEAD3/A7 = 'CCCCCCC';
HEAD4/A3 = 'DDD';
HEADER/A21 = HEAD1|HEAD2|HEAD3|HEAD4;
CON1/A2 = 'EE';
CON2/A2 = 'FF';
CON3/A17 = 'GGGGGGGGGGGGGGGGG';
CONTENT/A21 = CON1|CON2|CON3;
TRAIL1/A2 = 'HH';
TRAIL2/I5L = 3;
TRAIL3/I9L = 1600;
TRAIL4/A5 = 'IIIII';
END
-* Getting the header record
TABLE FILE CAR
SUM HEADER
BY HIGHEST 1 COUNTRY NOPRINT
ON TABLE HOLD AS EOYFILE FORMAT ALPHA
END
-RUN
-* Appending the data
TABLE FILE CAR
PRINT CONTENT
BY COUNTRY NOPRINT
ON TABLE HOLD AS EOYFILE FORMAT ALPHA
END
-RUN
-* Calculating the sum of TRAIL2 and TRAIL3
TABLE FILE CAR
SUM
MAX.COUNTRY NOPRINT
FST.TRAIL1
TRAIL2
TRAIL3
FST.TRAIL4
ON TABLE HOLD AS HOLD1
END
-* Appending the footer record
TABLE FILE HOLD1
SUM COMPUTE TRAILER/A21 = TRAIL1|FPRINT(TRAIL2,'I5L','A5')|FPRINT(TRAIL3,'I9L','A9')|TRAIL4;
ON TABLE HOLD AS EOYFILE FORMAT ALPHA
END
-RUN
TABLE FILE EOYFILE
PRINT *
ON TABLE HOLD FORMAT ALPHA
END
-RUN
Francis
Give me code, or give me retirement. In FOCUS since 1991
Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
September 24, 2015, 10:29 AM
rray9895
Of course!
Every time I've tried testing it, I always assumed that it was a field length issue,or a BY statement problem or that I wasn't using the FPRINT function correctly.
I didn't even think about isolating the calculated hold to see if there was an issue there. I guess it is very rare for me to deal with ONLY define files that I didn't even consider that. Thank you so much!
WebFOCUS 8.105M, Windows 10, App Studio
September 24, 2015, 10:56 AM
rray9895
Actually, this method didn't fully work in my real data. It worked fine with the CAR file, but when I mirrored the logic in my actual file, it was a no-go, I'm not sure why. However, I made a small adjustment to it, and I got it to work this way:
-DEFAULT &R_YR = 2015; SET HOLDLIST = PRINTONLY FILEDEF EOYFILE DISK 111111_test_file.txt (LRECL 21 RECFM V APPEND -RUN DEFINE FILE CAR HEAD1/A4 = '&R_YR'; HEAD2/A7 = 'BBBBBBB'; HEAD3/A7 = 'CCCCCCC'; HEAD4/A3 = 'DDD'; HEADER/A21 = HEAD1|HEAD2|HEAD3|HEAD4; CON1/A2 = 'EE'; CON2/A2 = 'FF'; CON3/A17 = 'GGGGGGGGGGGGGGGGG'; CONTENT/A21 = CON1|CON2|CON3; TRAIL1/A2 = 'HH'; TRAIL2/I5L = 3; TRAIL3/I9L = 1600; TRAIL4/A5 = 'IIIII'; END -* Getting the header record TABLE FILE CAR SUM HEADER AS '' BY HIGHEST 1 COUNTRY NOPRINT ON TABLE HOLD AS EOYFILE FORMAT ALPHA END -RUN -* Appending the data TABLE FILE CAR PRINT CONTENT AS '' BY COUNTRY NOPRINT ON TABLE HOLD AS EOYFILE FORMAT ALPHA END -RUN -* Calculating the sum of TRAIL2 and TRAIL3 TABLE FILE CAR SUM MAX.COUNTRY FST.TRAIL1 TRAIL2 TRAIL3 FST.TRAIL4 ON TABLE HOLD AS HOLD1 END
DEFINE FILE HOLD1 TRAILER/A21 = TRAIL1|FPRINT(TRAIL2,'I5L','A5')|FPRINT(TRAIL3,'I9L','A9')|TRAIL4; END -* Appending the footer record TABLE FILE HOLD1 PRINT TRAILER AS '' BY COUNTRY NOPRINT ON TABLE HOLD AS EOYFILE FORMAT ALPHA END -RUN TABLE FILE EOYFILE PRINT * ON TABLE PCHOLD FORMAT ALPHA END -RUN
WebFOCUS 8.105M, Windows 10, App Studio
September 24, 2015, 11:31 AM
RSquared
I also had the same issue with appending a footer but I added the following line to limit time,
/* WHERE READLIMIT EQ 1 /*
WF 7.6.11 Oracle WebSphere Windows NT-5.2 x86 32bit
September 27, 2015, 05:57 PM
Waz
FYI
When using this technique, FILEDEF APPEND and HOLD, HOLD, ETC, each time the HOLD happens, the master file will be replaced.