Advertisement
Guest User

AWK Script - failing to run on AS400

a guest
Jul 20th, 2016
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.79 KB | None | 0 0
  1. BEGIN {
  2. if (ARGC > 2) {
  3. InputFile = ARGV[1];
  4. OutputFile = ARGV[2];
  5. ARGV[2] = "";
  6. } else {
  7. print("Output file name not specified.");
  8. OutputFile = "Nul";
  9. }
  10. if (ARGC > 3) {
  11. sep = ARGV[3];
  12. RS = sep "|" sep "\n|" sep "\r\n";
  13. ARGV[3] = "";
  14. } else {
  15. RS = "~|~\n|~\r\n|\n|\r\n|\32+"; # Input Record Separator
  16. }
  17. False = 0;
  18. True = 1;
  19. HaveError = False;
  20. HaveTA1 = False;
  21. WroteHeader = False;
  22. Loop = "";
  23. TransactionSetSegments = 0;
  24. TestDocument = False;
  25. rejectedBatch = False;
  26. AckStatus["A"] = "The Transmitted Interchange Control Structure Header and Trailer Have Been Received and Have No Errors.";
  27. AckStatus["E"] = "The Transmitted Interchange Control Structure Header and Trailer Have Been Received and Are Accepted But Errors Are Noted.\n This Means the Sender Must Not Resend This data.";
  28. AckStatus["R"] = "The Transmitted Interchange Control Structure Header and Trailer are Rejected Because of Errors.";
  29. InterchangeCode[0] = "No Error";
  30. InterchangeCode[1] = "The Interchange Control Number in the Header and Trailer Do Not Match. The value From the Header is Used in the Acknowledgement";
  31. InterchangeCode[2] = "This Standard as Noted in the Control Standards Identifier is Not Supported.";
  32. InterchangeCode[3] = "This Version of the Controls is Not Supported";
  33. InterchangeCode[4] = "The Segment Terminator is Invalid";
  34. InterchangeCode[5] = "Invalid Interchange ID Qualifier for Sender";
  35. InterchangeCode[6] = "Invalid Interchange Sender ID";
  36. InterchangeCode[7] = "Invalid Interchange ID Qualifier for Receiver";
  37. InterchangeCode[8] = "Invalid Interchange Receiver ID";
  38. InterchangeCode[9] = "Unknown Interchange Receiver ID";
  39. InterchangeCode[10] = "Invalid Authorization Information Qualifier Value";
  40. InterchangeCode[11] = "Invalid Authorization Information Value";
  41. InterchangeCode[12] = "Invalid Security Information Qualifier Value";
  42. InterchangeCode[13] = "Invalid Security Information Value";
  43. InterchangeCode[14] = "Invalid Interchange Date Value";
  44. InterchangeCode[15] = "Invalid Interchange Time Value";
  45. InterchangeCode[16] = "Invalid Interchange Standards Identifier Value";
  46. InterchangeCode[17] = "Invalid Interchange Version ID Value";
  47. InterchangeCode[18] = "Invalid Interchange Control Number Value";
  48. InterchangeCode[19] = "Invalid Acknowledgment Requested Value";
  49. InterchangeCode[20] = "Invalid Test Indicator Value";
  50. InterchangeCode[21] = "Invalid Number of Included Groups Value";
  51. InterchangeCode[22] = "Invalid Control Structure";
  52. InterchangeCode[23] = "Improper (Premature) End-of-File (Transmission)";
  53. InterchangeCode[24] = "Invalid Interchange Content (e.g., Invalid GS Segment)";
  54. InterchangeCode[25] = "Duplicate Interchange Control Number";
  55. InterchangeCode[26] = "Invalid Data Element Separator";
  56. InterchangeCode[27] = "Invalid Component Element Separator";
  57. InterchangeCode[28] = "Invalid Delivery Date in Deferred Delivery Request";
  58. InterchangeCode[29] = "Invalid Delivery Time in Deferred Delivery Request";
  59. InterchangeCode[30] = "Invalid Delivery Time Code in Deferred Delivery Request";
  60. InterchangeCode[31] = "Invalid Grade of Service Code";
  61. SegmentSyntaxError["1"] = "Unrecognized segment ID";
  62. SegmentSyntaxError["2"] = "Unexpected segment";
  63. SegmentSyntaxError["3"] = "Required segment missing";
  64. SegmentSyntaxError["4"] = "Loop Occurs Over Maximum Times";
  65. SegmentSyntaxError["5"] = "Segment Exceeds Maximum Use";
  66. SegmentSyntaxError["6"] = "Segment Not in Defined Transaction Set";
  67. SegmentSyntaxError["7"] = "Segment Not in Proper Sequence";
  68. SegmentSyntaxError["8"] = "Segment Has Data Element Errors";
  69. SegmentSyntaxError["I4"] = "Implementation \"Not Used\" Segment Present";
  70. SegmentSyntaxError["I6"] = "Implementation Dependent Segment Missing";
  71. SegmentSyntaxError["I7"] = "Implementation Loop Occurs Under Minimum Times";
  72. SegmentSyntaxError["I8"] = "Implementation Segment Below Minimum Use";
  73. SegmentSyntaxError["I9"] = "Implementation Dependent \"Not Used\" Segment Present";
  74.  
  75. ElementError["1"] = "Required Data Element Missing";
  76. ElementError["2"] = "Conditional Required Data Element Missing";
  77. ElementError["3"] = "Too Many Data Elements";
  78. ElementError["4"] = "Data Element Too Short";
  79. ElementError["5"] = "Data Element Too Long.";
  80. ElementError["6"] = "Invalid Character In Data Element";
  81. ElementError["7"] = "Invalid Code Value";
  82. ElementError["8"] = "Invalid Date";
  83. ElementError["9"] = "Invalid Time";
  84. ElementError["12"] = "Too Many Repetitions";
  85. ElementError["13"] = "Too Many Components";
  86. ElementError["I10"] = "Implementation \"Not Used\" Data Element Present";
  87. ElementError["I11"] = "Implementation Too Few Repetitions";
  88. ElementError["I12"] = "Implementation Pattern Match Failure";
  89. ElementError["I13"] = "Implementation Dependent \"Not Used\" Data Element Present";
  90. ElementError["I6"] = "Code Value Not Used in Implementation";
  91. ElementError["I9"] = "Implementation Dependent Data Element Missing";
  92. SetStatus["A"] = "Accepted";
  93. SetStatus["E"] = "Accepted But Errors Were Noted\rThe transaction set indicated in this AK2 loop contained errors, but was forwarded for further processing.";
  94. SetStatus["M"] = "Rejected, Message Authentication Code (MAC) Failed";
  95. SetStatus["R"] = "Rejected\rThe transaction set indicated in this AK2 loop contained errors, and was NOT forwarded for further processing. It will need to be corrected and resubmitted.";
  96. SetStatus["W"] = "Rejected, Assurance Failed Validity Tests";
  97. SetStatus["X"] = "Rejected, Content After Decryption Could Not Be Analyzed";
  98. SetSyntaxErr["1"] = "Transaction Set Not Supported";
  99. SetSyntaxErr["2"] = "Transaction Set Trailer Missing";
  100. SetSyntaxErr["3"] = "Transaction Set Control Number in Header and Trailer Do Not Match";
  101. SetSyntaxErr["4"] = "Number of Included Segments Does Not Match Actual Count";
  102. SetSyntaxErr["5"] = "One or More Segments in Error";
  103. SetSyntaxErr["6"] = "Missing or Invalid Transaction Set Identifier";
  104. SetSyntaxErr["7"] = "Missing or Invalid Transaction Set Control Number";
  105. SetSyntaxErr["8"] = "Authentication Key Name Unknown";
  106. SetSyntaxErr["9"] = "Encryption Key Name Unknown";
  107. SetSyntaxErr["10"] = "Requested service (Authentication or Encrypted) Not Available";
  108. SetSyntaxErr["11"] = "Unknown Security Recipient";
  109. SetSyntaxErr["12"] = "Incorrect Message Length (Encryption Only)";
  110. SetSyntaxErr["13"] = "Message Authentication Code Failed";
  111. SetSyntaxErr["15"] = "Unknown Security Originator";
  112. SetSyntaxErr["16"] = "Syntax Error in Decrypted Text";
  113. SetSyntaxErr["17"] = "Security Not Supported";
  114. SetSyntaxErr["18"] = "Transaction Set not in Functional Group";
  115. SetSyntaxErr["19"] = "Invalid Transaction Set Implementation Convention Reference";
  116. SetSyntaxErr["23"] = "Transaction Set Control Number Not Unique within the Functional Group";
  117. SetSyntaxErr["24"] = "S3E Security End Segment Missing for S3S Security Start Segment";
  118. SetSyntaxErr["25"] = "S3S Security Start Segment Missing for S3E Security End Segment";
  119. SetSyntaxErr["26"] = "S4E Security End Segment Missing for S4S Security Start Segment";
  120. SetSyntaxErr["27"] = "S4S Security Start Segment Missing for S4E Security End Segment";
  121. SetSyntaxErr["I5"] = "Implementation One or More Segments in Error";
  122. SetSyntaxErr["I6"] = "Implementation Convention Not Supported";
  123. GroupStatus["A"] = "Accepted";
  124. GroupStatus["E"] = "Accepted But Errors Were Noted\rThe functional group indicated in this 999 contained errors, but was forwarded for further processing.";
  125. GroupStatus["M"] = "Rejected, Message Authentication Code (MAC) Failed";
  126. GroupStatus["P"] = "Partially Accepted, At least One Transaction Set Was Rejected";
  127. GroupStatus["R"] = "Rejected\rThe functional group indicated in this 999 contained errors, and was NOT forwarded for further processing. It will need to be corrected and resubmitted.";
  128. GroupStatus["W"] = "Rejected, Assurance Failed Validity Tests";
  129. GroupStatus["X"] = "Rejected, Content After Decryption Could Not Be Analyzed";
  130. GroupError["1"] = "Functional Group Not Supported";
  131. GroupError["2"] = "Functional Group Version Not Supported";
  132. GroupError["3"] = "Functional Group Trailer Missing";
  133. GroupError["4"] = "Group Control Number in the Functional Group Header and Trailer Do Not Agree";
  134. GroupError["5"] = "Number of Included Transaction Sets Does Not Match Actual Count";
  135. GroupError["6"] = "Group Control Number Violates Syntax";
  136. GroupError["10"] = "Authentication Key Name Unknown";
  137. GroupError["11"] = "Encryption Key Name Unknown";
  138. GroupError["12"] = "Requested Service (Authentication or Encryption) Not Available";
  139. GroupError["13"] = "Unknown Security Recipient";
  140. GroupError["14"] = "Unknown Security Originator";
  141. GroupError["15"] = "Syntax Error in Decrypted Text";
  142. GroupError["16"] = "Security Not Supported";
  143. GroupError["17"] = "Incorrect Message Length (Encryption Only)";
  144. GroupError["18"] = "Message Authentication Code Failed";
  145. GroupError["19"] = "Functional Group Control Number not Unique within Interchange";
  146. GroupError["23"] = "S3E Security End Segment Missing for S3S Security Start Segment";
  147. GroupError["24"] = "S3S Security Start Segment Missing for S3E End Segment";
  148. GroupError["25"] = "S4E Security End Segment Missing for S4S Security Start Segment";
  149. GroupError["26"] = "S4S Security Start Segment Missing for S4E Security End Segment";
  150. SenderName["00332"] = "National Government Services (AdminaStar)";
  151. SenderName["00363"] = "Veritus";
  152. SenderName["00390"] = "BCBS TN"
  153. SenderName["00450"] = "National Government Services (UGS)";
  154. SenderName["06001"] = "National Government Services (J6)";
  155. SenderName["10301"] = "Cahaba GBA";
  156. SenderName["12001"] = "Highmark Medicare Services rollup contractor";
  157. SenderName["12401"] = "Highmark Medicare Services";
  158. SenderName["15201"] = "CIGNA Government Services (CGS)";
  159. SenderName["52280"] = "WPS";
  160. SenderName["IHCP"] = "Indiana Health Coverage Programs"
  161. SenderName["KYMEDICAID"] = "Kentucky Medicaid";
  162. SenderName["41-1674742"] = "MN Department of Human Services";
  163. SenderName["345529167"] = "Pennsylvania Department of Public Welfare";
  164. SenderName["WISC_DHFS"] = "Wisconsin Medicaid"
  165. SenderName["MMISODJFS"] = "Ohio Dept of Job and Family Services";
  166. SenderName["D00111"] = "Michigan Department of Community Health";
  167. SenderName["ORDHS"] = "Oregon Department of Human Services"
  168. SenderName["77045"] = "Washington DSHS ProviderOne";
  169. SenderName["ID_MMIS_4MOLINA"] = "Idaho Medicaid";
  170. PayerName["00000"] = "Unknown";
  171. }
  172. /^ISA/ {
  173. FS = substr($0,4,1);
  174. SenderID = trim(substr($0,36,15));
  175. ReceiverID = trim(substr($0,55,15));
  176. InterchgCtlNbr = trim(substr($0,91,9));
  177. SUBSEP = substr($0,105,1);
  178. if (substr($0,103,1) == "T") {
  179. TestDocument = True;
  180. }
  181. WroteHeader = False;
  182. }
  183. /^TA1/ {
  184. HaveTA1 = True;
  185. TA101 = $2;
  186. TA102 = $3;
  187. TA103 = $4;
  188. TA104 = $5;
  189. TA104Desc = AckStatus[$5];
  190. TA105 = $6;
  191. TA105Desc = InterchangeCode[$6 + 0];
  192. }
  193. /^GS/ {
  194. PayerID = $3;
  195. ProcessDate = substr($5,5,2) "/" substr($5,7,2) "/" substr($5,1,4);
  196. ProcessTime = substr($6,1,2) ":" substr($6,3,2)
  197. if (length($6) > 4) {
  198. ProcessTime = ProcessTime ":" substr($6,5,2);
  199. }
  200. AckGroupCtlNbr = $7;
  201. WroteHeader = False;
  202. FunctionalGroupCount += 1;
  203. }
  204. /^ST/ {
  205. DocType = $2;
  206. AckCtlNbr = $3;
  207. TransactionSetCount += 1;
  208. # if ((DocType == "999") && (!WroteHeader)) {
  209. # print("Sender: . . . . . . . . . . " SenderID "\t" SenderName[SenderID]) >> OutputFile;
  210. # if (TestDocument) {
  211. # print("Document Usage: . . . . . . TEST") >> OutputFile;
  212. # }
  213. # print("Receiver: . . . . . . . . . " ReceiverID) >> OutputFile;
  214. # print("Interchange Number: . . . . " InterchgCtlNbr) >> OutputFile;
  215. # print("Payer: . . . . . . . . . . . " PayerID "\t" PayerName[PayerID]) >> OutputFile;
  216. # print("Process Date: . . . . . . . " ProcessDate) >> OutputFile;
  217. # print("Process Time: . . . . . . . " ProcessTime) >> OutputFile;
  218. # print("Acknowledgement") >> OutputFile;
  219. # print(" Group Control Number: . . " AckGroupCtlNbr) >> OutputFile;
  220. # WroteHeader = True;
  221. # }
  222. if ((DocType = "999") && (!WroteHeader)) {
  223. WriteHeader();
  224. }
  225. if (HaveTA1) {
  226. WriteTA1Data(TA101, TA102, TA103, TA104, TA104Desc, TA105, TA105Desc);
  227. }
  228. print("----------------------------------------------") >> OutputFile;
  229. haveST = True;
  230. }
  231. /^AK1/ {
  232. if (DocType == "999") {
  233. print("Acknowledging Functional Group") >> OutputFile;
  234. print(" Control Number: . . . . . " $3) >> OutputFile;
  235. PrevDocType = "";
  236. }
  237. }
  238. /^AK2/ {
  239. if (DocType == "999") {
  240. Loop = "2000";
  241. if (PrevDocType == $2) {
  242. print("") >> OutputFile;
  243. } else {
  244. print(" Document Type: . . . . . " $2) >> OutputFile;
  245. print("\n----------------------------------------------\n") >> OutputFile;
  246. PrevDocType = $2;
  247. }
  248. print("Acknowledging Transaction") >> OutputFile;
  249. print(" Set Control Number: . . . " $3) >> OutputFile;
  250. }
  251. }
  252. /^IK3/ {
  253. if (DocType == "999") {
  254. Loop = "2100";
  255. HaveError = True;
  256. print("\n********** ERROR **********") >> OutputFile;
  257. SegmentName = $2;
  258. if (SegmentName !="") {
  259. print("Segment Name . . . . . . . . " SegmentName) >> OutputFile;
  260. }
  261. if ($3 != "") {
  262. print("Position in Txn Set: . . . . " $3) >> OutputFile;
  263. }
  264. if ($4 != "") {
  265. print("Loop Identifier Code: . . . " $4) >> OutputFile;
  266. }
  267. if ($5 != "") {
  268. print("Error Description: . . . . . " SegmentSyntaxError[$5]) >> OutputFile;
  269. }
  270. }
  271. }
  272. /^CTX/ {
  273. if (DocType = "999") {
  274. if (Loop == "2100") {
  275. if ($2 == "SITUATIONAL TRIGGER") {
  276. if ($3 != "") {
  277. print("Segment: . . . . . . . . . . " $3) >> OutputFile;
  278. }
  279. if ($4 != "") {
  280. print("Position in Txn Set: . . . . " $4) >> OutputFile;
  281. }
  282. if ($5 != "") {
  283. print("Loop Identifier: . . . . . . " $5) >> OutputFile;
  284. }
  285. if ($6 != "") {
  286. print("Position in Segment: . . . . " $6) >> OutputFile;
  287. }
  288.  
  289. if ((NF > 6) && ($7 != "")) {
  290. print("Data Element Reference . . " $7) >> OutputFile;
  291. }
  292. } else {
  293. if ($2 == "CLM01") {
  294. if ($3 != "") {
  295. print("Claim ID (PCN): . . . . . . . " $3) >> OutputFile;
  296. }
  297. } else {
  298. if ($2 != "") {
  299. print("Context Identifier: . . . . " $2) >> OutputFile;
  300. }
  301. if ($3 != "") {
  302. print("Context Reference: . . . . . . " $3) >> OutputFile;
  303. }
  304. }
  305. }
  306. }
  307. }
  308. }
  309. /^IK4/ {
  310. if (DocType == "999") {
  311. Loop = "2110";
  312. print("Implementation Information") >> OutputFile;
  313. if ($2 != "") {
  314. print(" Position in Segment: . . . " $2) >> OutputFile;
  315. }
  316. if ($3 != "") {
  317. print(" Element Dictionary: . . . " $3) >> OutputFile;
  318. }
  319. if ($4 != "") {
  320. print(" Element Error Description: ") >> OutputFile;
  321. print(" " ElementError[$4]) >> OutputFile;
  322. }
  323. if ((NF > 4) && ($5 != "")) {
  324. SegCopy = $5;
  325. for (i=6; i<=NF; i++) {
  326. SegCopy = SegCopy "*" $i;
  327. }
  328. SegCopy = "\"" SegCopy "\"";
  329. print("\n Copy of Bad Data Element:") >> OutputFile;
  330. print(" " SegCopy "\n") >> OutputFile;
  331. }
  332. }
  333. }
  334. /^CTX/ {
  335. if (DocType = "999") {
  336. if (Loop == "2110") {
  337. if ($2 == "SITUATIONAL TRIGGER") {
  338. if ($3 != "") {
  339. print(" Segment: . . . . . . . . . " $3) >> OutputFile;
  340. }
  341. if ($4 != "") {
  342. print(" Position in Txn Set: . . . " $4) >> OutputFile;
  343. }
  344. if ($5 != "") {
  345. print(" Loop Identifier: . . . . . " $5) >> OutputFile;
  346. }
  347. if ($6 != "") {
  348. print(" Position in Segment: . . . " $6) >> OutputFile;
  349. }
  350.  
  351. if ((NF > 6) && ($7 != "")) {
  352. print(" Data Elem Reference: . . " $7) >> OutputFile;
  353. }
  354. }
  355. }
  356. }
  357. }
  358. /^IK5/ {
  359. if (DocType == "999") {
  360. Loop = "2100";
  361. if (HaveError) {
  362. print("********** ERROR **********\n") >> OutputFile;
  363. }
  364. HaveError = False;
  365. if ($2 != "") {
  366. print("Transaction Set Status: . . " SetStatus[$2]) >> OutputFile;
  367. }
  368. if (NF > 2) {
  369. print("\nTransaction Set Syntax Errors:") >> OutputFile;
  370. print(" " SetSyntaxErr[$3]) >> OutputFile;
  371. }
  372. if (NF > 3) {
  373. print(" " SetSyntaxErr[$4]) >> OutputFile;
  374. }
  375. if (NF > 4) {
  376. print(" " SetSyntaxErr[$5]) >> OutputFile;
  377. }
  378. if (NF > 5) {
  379. print(" " SetSyntaxErr[$6]) >> OutputFile;
  380. }
  381. if (NF > 6) {
  382. print(" " SetSyntaxErr[$7]) >> OutputFile;
  383. }
  384. if (NF > 2) {
  385. print("") >> OutputFile;
  386. }
  387. }
  388. }
  389. /^AK9/ {
  390. if (DocType == "999") {
  391. Loop = "";
  392. print("") >> OutputFile;
  393. print("Functional Group Status: . . " GroupStatus[$2]) >> OutputFile;
  394. print("Number of Sets: . . . . . . Included " $3 " Received " $4 " Accepted " $5) >> OutputFile;
  395. if (NF > 5) {
  396. print("\nFunctional Group Syntax Errors:") >> OutputFile;
  397. print(" " GroupError[$6]) >> OutputFile;
  398. }
  399. if (NF > 6) {
  400. print(" " GroupError[$7]) >> OutputFile;
  401. }
  402. if (NF > 7) {
  403. print(" " GroupError[$8]) >> OutputFile;
  404. }
  405. if (NF > 8) {
  406. print(" " GroupError[$9]) >> OutputFile;
  407. }
  408. if (NF > 9) {
  409. print(" " GroupError[$10]) >> OutputFile;
  410. }
  411. print("\n") >> OutputFile;
  412. }
  413. }
  414. /^SE/ {
  415. TSError = False;
  416. ErrorMsg = "";
  417. TSSegs = TransactionSetSegments + 1;
  418. if ($3 != AckCtlNbr) {
  419. TSError = True;
  420. ErrorMsg = "The transaction set control number in SE02 is " $3 ", but the value in ST02 is " AckCtlNbr ".";
  421. }
  422. if (TSSegs != $2) {
  423. if (TSError) {
  424. ErrorMsg = ErrorMsg "\n";
  425. }
  426. TSError = True;
  427. ErrorMsg = ErrorMsg "The actual number of segments in transaction set " AckCtlNbr " does not match the value in SE01.";
  428. }
  429. if (TSError) {
  430. print("********* WARNING *********") >> OutputFile;
  431. print(ErrorMsg) >> OutputFile;
  432. print("This may indicate that the 999 document is corrupt.") >> OutputFile;
  433. print("********* WARNING *********") >> OutputFile;
  434. }
  435. AckCtlNbr = "";
  436. TSError = False;
  437. ErrorMsg = "";
  438. TSSegs = 0;
  439. haveST = False;
  440. }
  441. /./ {
  442. if (haveST) {
  443. TransactionSetSegments += 1;
  444. } else {
  445. TransactionSetSegments = 0;
  446. }
  447. }
  448. /^GE/ {
  449. FGError = False;
  450. ErrorMsg = "";
  451. if (AckGroupCtlNbr != $3) {
  452. FGError = True;
  453. ErrorMsg = "The functional group control number in GE02 is " $3 ", but the value in GS06 is " AckGroupCtlNbr ".";
  454. }
  455. if (TransactionSetCount != $2) {
  456. if (FGError) {
  457. ErrorMsg = ErrorMsg "\n";
  458. }
  459. FGError = True;
  460. ErrorMsg = ErrorMsg "The actual number of transaction sets in functional group " AckGroupCtlNbr " does not match the value in GE01.";
  461. }
  462. if (FGError) {
  463. print("********* WARNING *********") >> OutputFile;
  464. print(ErrorMsg) >> OutputFile;
  465. print("This may indicate that the 999 document is corrupt.") >> OutputFile;
  466. print("********* WARNING *********") >> OutputFile;
  467. }
  468. FGError = False;
  469. ErrorMsg = "";
  470. AckGroupCtlNbr = "";
  471. TransactionSetCount = 0;
  472. }
  473. /^IEA/ {
  474. if (HaveTA1) {
  475. WriteTA1Data(TA101, TA102, TA103, TA104, TA104Desc, TA105, TA105Desc);
  476. }
  477. ICError = False;
  478. ErrorMsg = "";
  479. if (InterchgCtlNbr != $3) {
  480. ICError = True;
  481. ErrorMsg = "The interchange control number in IEA02 is " $3 ", but the value in ISA13 is " InterchgCtlNbr ".";
  482. }
  483. if (FunctionalGroupCount != $2) {
  484. if (ICError) {
  485. ErrorMsg = ErrorMsg "\n";
  486. }
  487. ICError = True;
  488. ErrorMsg = ErrorMsg "The actual number of functional groups in interchange " InterchgCtlNbr " does not match the value in IEA01.";
  489. }
  490. if (ICError) {
  491. if ((FunctionalGroupCount != 0) || ($2 != 1) || (!rejectedBatch)) {
  492. print("********* WARNING *********") >> OutputFile;
  493. print(ErrorMsg) >> OutputFile;
  494. print("This may indicate that the 999 or TA1 document is corrupt.") >> OutputFile;
  495. print("********* WARNING *********") >> OutputFile;
  496. }
  497. }
  498. ICError = False;
  499. ErrorMsg = "";
  500. InterchgCtlNbr = "";
  501. FunctionalGroupCount = 0;
  502. rejectedBatch = False;
  503. }
  504. function WriteTA1Data(TA101, TA102, TA103, TA104, TA104Desc, TA105, TA105Desc) {
  505. if (FunctionalGroupCount > 0) {
  506. print("----------------------------------------------") >> OutputFile;
  507. } else {
  508. WriteHeader();
  509. }
  510. if (TA104 == "R") {
  511. RejectWarning = " ** BATCH WAS REJECTED **";
  512. rejectedBatch = True;
  513. } else {
  514. RejectWarning = "";
  515. }
  516. print("Acknowledging Interchange") >> OutputFile;
  517. print(" Control Number: . . . . . " TA101) >> OutputFile;
  518. print(" Interchange Date: . . . . " substr(TA102,3,2) "/" substr(TA102,5,2) "/20" substr(TA102,1,2)) >> OutputFile;
  519. print(" Interchange Time: . . . . " substr(TA103,1,2) ":" substr(TA103,3,2)) >> OutputFile;
  520. print("\n Interchange Status:" RejectWarning) >> OutputFile;
  521. print(" " TA104Desc) >> OutputFile;
  522. if (TA105 != "") {
  523. print("\n Interchange Note:") >> OutputFile;
  524. print(" " TA105Desc) >> OutputFile;
  525. }
  526. HaveTA1 = False;
  527. }
  528. function WriteHeader() {
  529. if (!WroteHeader) {
  530. print("Sender: . . . . . . . . . . " SenderID "\t" SenderName[SenderID]) >> OutputFile;
  531. if (TestDocument) {
  532. print("Document Usage: . . . . . . TEST") >> OutputFile;
  533. }
  534. print("Receiver: . . . . . . . . . " ReceiverID) >> OutputFile;
  535. print("Interchange Number: . . . . " InterchgCtlNbr) >> OutputFile;
  536. if (PayerID > "") {
  537. print("Payer: . . . . . . . . . . . " PayerID "\t" PayerName[PayerID]) >> OutputFile;
  538. print("Process Date: . . . . . . . " ProcessDate) >> OutputFile;
  539. print("Process Time: . . . . . . . " ProcessTime) >> OutputFile;
  540. print("Acknowledgement") >> OutputFile;
  541. print(" Group Control Number: . . " AckGroupCtlNbr) >> OutputFile;
  542. }
  543. WroteHeader = True;
  544. }
  545. }
  546.  
  547. function trim(InString) {
  548. gsub(/^ */, "", InString);
  549. gsub(/ *$/, "", InString);
  550. return InString;
  551. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement