Advertisement
Guest User

Untitled

a guest
Nov 26th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
COBOL 8.32 KB | None | 0 0
  1. Figure 4b: COBOL version of the code
  2.  
  3. * CRTCBLPGM PGM(XXX/DATEPGMCBL) SRCFILE(XXX/QLBLSRC)
  4. *
  5.  
  6. *========================================================
  7.  
  8. PROCESS XREF MAP QUOTE.
  9. IDENTIFICATION DIVISION.
  10. PROGRAM-ID. DATEPGMCBL.
  11. AUTHOR. MARIO MARTINEZ.
  12. DATE-WRITTEN. 01/21/98.
  13. **
  14.  
  15. * Documentation on how to setup and use this API
  16. * using RPG was printed in the issue of
  17. * Midrange Computing. The article was written by Craig Pelkie.
  18. * In February 1998 another article covering the changes to
  19. * QWCCVTDT was published by MC magazine. The article was written
  20. * by Mario Martinez.
  21.  
  22. *
  23.  
  24. * The example code to the article was written in RPG. This
  25. * program is written in Cobol and functions like it's RPG
  26. * counterpart.
  27.  
  28. *
  29.  
  30. * This OPM COBOL/400 program will call the "QWCCVTDT"
  31. * OS/400 API, which was developed by IBM to change
  32. * dates from one format to another. This API has been
  33. * further enhanced to provide the dates with the
  34. * actual century value.
  35.  
  36. *
  37.  
  38. * After the API is called, the results will be displayed
  39. * on the console.
  40.  
  41. *
  42.  
  43. * The program will retrieve the current date in several
  44. * different formats - using the actual century value.
  45.  
  46. *
  47.  
  48. * After the QWCCVTDT API will be used to change the format
  49. * of the date 02/29/2000, which is a leap year,
  50. * to the long Julian format. The same operation will be performed
  51. * on the invalid date 02/29/2001, which is not a leap year.
  52.  
  53. * This is to demonstrate how invalid date error
  54. * can be trapped using this API.
  55.  
  56. *
  57.  
  58. * Summary of program functions using OPM Cobol/400 :
  59. *
  60.  
  61. * 1.) Retrieve the actual century value in different formats,
  62. * using QWCCVTDT.
  63.  
  64. *
  65.  
  66. * 2.) Convert a date value to another format,
  67. * using QWCCVTDT.
  68.  
  69. *
  70.  
  71. * 3.) Trap an invalid date error
  72. * using a standard OPM OS/400 error data structure.
  73. *
  74.  
  75. * 4.) Use the DOSGetDateTime data structure to retrieve date/time
  76. * information including the Day of the Week numeric value.
  77.  
  78. *
  79.  
  80. * Numeric Value - 0 1 2 3 4 5 6
  81. * Text Value - Sun Mon Tues Wed Thurs Fri Sat
  82. *
  83.  
  84. * 5.) Maintain "Year 2000" compliance at all times.
  85. *========================================================
  86.  
  87. * Program Output :
  88.  
  89. * call datepgmcbl
  90. * The resulting date value is :19980121
  91. * The resulting date value is :1998021
  92. * The resulting date value is :2000060
  93. * Error in Date Conversion, Message ID is :CPF1060
  94. * The resulting date value is :
  95. * DOSGetDateTime values :
  96. * Hours = 0011
  97. * Minutes = 0001
  98. * Seconds = 0042
  99. * Hundreths of Seconds = 0060
  100. * Day of Month = 0021
  101. * Month = 0001
  102. * Year = 1998
  103. * Time Zone = 0360
  104.  
  105. * Day of Week = 0003
  106. *========================================================
  107.  
  108. *
  109.  
  110. *-
  111.  
  112. ENVIRONMENT DIVISION.
  113. DATA DIVISION.
  114. WORKING-STORAGE SECTION.
  115.  
  116. **
  117.  
  118. * These terms are exactly the same as Craig Pelkie
  119. * usedinFig.4ofhisMay1993MCarticle.
  120.  
  121. *
  122.  
  123. * APIERR - Standard OPM OS/400 API error data structure
  124. * AEBYPR - Bytes provided for error information
  125. * AEBYAV - Bytes of error information available
  126. * AEEXID - Exception ID of Error
  127. * AERESV - Reserved
  128. * AEEXDT - Exception Data
  129. *-
  130.  
  131. 01 APIERR.
  132.  
  133. 05 AEBYPR PIC S9(9) COMP-4 VALUE 116.
  134. 05 AEBYAV PIC S9(9) COMP-4.
  135. 05 AEEXID PIC X(7).
  136. 05 AERESV PIC X(1).
  137. 05 AEEXDT PIC X(100).
  138.  
  139. ** Values used to retreive, convert and display date conversion
  140. * results.
  141.  
  142. *
  143.  
  144. 01 date-conversion-values.
  145.  
  146. 05 valid-date PIC X(08) VALUE "02292000".
  147. 05 invalid-date PIC X(08) VALUE "02292001".
  148. 05 error-message PIC X(41)
  149.  
  150. VALUE "Error in Date Conversion, Message ID is :".
  151. 05 result-message PIC X(41)
  152.  
  153. VALUE "The resulting date value is :".
  154.  
  155. 01 API-PARMS.
  156.  
  157. 05 input-date-format PIC X(10) VALUE SPACES.
  158. 05 output-date-format PIC X(10) VALUE SPACES.
  159. 05 input-date-api-info.
  160.  
  161. 10 date-value PIC X(8).
  162. 10 time-hhmmss-value PIC X(6).
  163. 10 milleseconds-value PIC X(3).
  164. 05 output-date-api-info.
  165.  
  166. 10 date-value PIC X(8).
  167. 10 time-hhmmss-value PIC X(6).
  168. 10 milleseconds-value PIC X(3).
  169.  
  170. ** Parameters used when
  171. * the DOSGetDateTime function is executed.
  172. *
  173.  
  174. 01 DOS-api-parms.
  175.  
  176. 05 DOS-input-date-format PIC X(10) VALUE "*CURRENT".
  177. 05 DOS-output-date-format PIC X(10) VALUE "*DOS".
  178. 05 DOS-input-date-filler PIC X(01).
  179.  
  180. ** Under the QWCCVTDT documentation this
  181. * is known as "DOSGetDateTime" structure.
  182. *-
  183.  
  184. 01 DOS-date-time-value.
  185.  
  186. 05 DOS-hours PIC X.
  187. 05 DOS-minutes PIC X.
  188. 05 DOS-seconds PIC X.
  189. 05 DOS-hundredths-of-secs PIC X.
  190. 05 DOS-day PIC X.
  191. 05 DOS-month PIC X.
  192. 05 DOS-year PIC 9(4) BINARY.
  193.  
  194. 05 DOS-time-zone PIC 9(4) BINARY.
  195. 05 DOS-day-of-week PIC X.
  196.  
  197. ** This working storage data structure will be used
  198. * be used to display the retrieved DOSGetDateTime information in
  199. * a usefull fashion.
  200. *-
  201.  
  202. 01 binary-conversion-values.
  203.  
  204. 05 two-binary-bytes-value PIC 9(4) BINARY VALUE ZERO.
  205. 05 binary-conversion-value
  206.  
  207. REDEFINES two-binary-bytes-value.
  208. 10 FILLER PIC X.
  209. 10 one-byte-binary-value PIC X.
  210.  
  211. *-
  212.  
  213. PROCEDURE DIVISION.
  214.  
  215. main-process.
  216.  
  217. PERFORM setup-yyyymmdd-date-format.
  218.  
  219. PERFORM setup-longjul-date-format.
  220.  
  221. PERFORM convert-valid-date-format.
  222.  
  223. PERFORM convert-invalid-date-format.
  224.  
  225. PERFORM retrieve-dsplay-DOSGetDateTime.
  226.  
  227. GOBACK.
  228.  
  229. *-
  230.  
  231. setup-yyyymmdd-date-format.
  232.  
  233. MOVE "*CURRENT" TO input-date-format.
  234. MOVE "*YYMD" TO output-date-format.
  235.  
  236. PERFORM call-date-api-17char.
  237.  
  238. PERFORM display-date-api-output.
  239.  
  240. *-
  241.  
  242. setup-longjul-date-format.
  243.  
  244. MOVE "*CURRENT" TO input-date-format.
  245. MOVE "*LONGJUL" TO output-date-format.
  246.  
  247. PERFORM call-date-api-17char.
  248.  
  249. PERFORM display-date-api-output.
  250.  
  251. *-
  252.  
  253. convert-valid-date-format.
  254.  
  255. INITIALIZE API-PARMS.
  256.  
  257. MOVE valid-date
  258.  
  259. TO date-value OF input-date-api-info.
  260.  
  261. MOVE "*MDYY" TO input-date-format.
  262. MOVE "*LONGJUL" TO output-date-format.
  263.  
  264. PERFORM call-date-api-17char.
  265.  
  266. PERFORM display-date-api-output.
  267.  
  268. *-
  269.  
  270. convert-invalid-date-format.
  271.  
  272. INITIALIZE API-PARMS.
  273.  
  274. MOVE invalid-date
  275.  
  276. TO date-value OF input-date-api-info.
  277.  
  278. MOVE "*MDYY" TO input-date-format.
  279. MOVE "*LONGJUL" TO output-date-format.
  280.  
  281. PERFORM call-date-api-17char.
  282.  
  283. PERFORM display-date-api-output.
  284.  
  285. **
  286.  
  287. * Routine to call the QWCCVTDT API using
  288. * the 17 Character Date and Time Value Structure
  289. *
  290.  
  291. call-date-api-17char.
  292.  
  293. CALL "QWCCVTDT" USING
  294.  
  295. input-date-format,
  296. input-date-api-info,
  297. output-date-format,
  298. output-date-api-info,
  299. APIERR.
  300.  
  301. *-
  302.  
  303. display-date-api-output.
  304. *
  305.  
  306. * IfAEBYAVisnotequaltozerothismeanstherewas
  307. * error when the QWCCVTDT was called. The variable
  308. * AEEXID will contain the OS/400 Message ID of the
  309. * specific error encountered.
  310.  
  311. *
  312.  
  313. *
  314.  
  315. * Code to display other returned information on console
  316. *
  317.  
  318. DISPLAY result-message date-value OF output-date-api-info.
  319.  
  320. retrieve-dsplay-DOSGetDateTime.
  321. ** Code to access and display returned information
  322. * for the DOSGetDateTime data structure.
  323.  
  324. *
  325.  
  326. * Setup and call QWCCVTDT API
  327. *
  328.  
  329. INITIALIZE API-PARMS.
  330.  
  331. CALL "QWCCVTDT" USING DOS-input-date-format
  332. DOS-input-date-filler
  333. DOS-output-date-format
  334. DOS-date-time-value
  335. APIERR.
  336.  
  337. IF (AEBYAV IS NOT EQUAL TO ZERO)
  338.  
  339. DISPLAY error-message AEEXID
  340.  
  341. END-IF.
  342.  
  343. *
  344.  
  345. * Display all DOSGetDateTime values upon console
  346. *
  347.  
  348. DISPLAY "DOSGetDateTime values : "
  349.  
  350. INITIALIZE binary-conversion-values.
  351.  
  352. MOVE DOS-hours TO one-byte-binary-value.
  353. DISPLAY "Hours = " two-binary-bytes-value.
  354.  
  355. INITIALIZE binary-conversion-values.
  356.  
  357. MOVE DOS-minutes TO one-byte-binary-value.
  358.  
  359. DISPLAY "Minutes = " two-binary-bytes-value.
  360.  
  361. INITIALIZE binary-conversion-values.
  362.  
  363. MOVE DOS-seconds TO one-byte-binary-value.
  364. DISPLAY "Seconds = " two-binary-bytes-value.
  365.  
  366. INITIALIZE binary-conversion-values.
  367.  
  368. MOVE DOS-hundredths-of-secs TO one-byte-binary-value.
  369. DISPLAY "Hundreths of Seconds = " two-binary-bytes-value.
  370.  
  371. INITIALIZE binary-conversion-values.
  372.  
  373. MOVE DOS-day TO one-byte-binary-value.
  374. DISPLAY "Day of Month = " two-binary-bytes-value.
  375.  
  376. INITIALIZE binary-conversion-values.
  377.  
  378. MOVE DOS-month TO one-byte-binary-value.
  379. DISPLAY "Month = " two-binary-bytes-value.
  380.  
  381. DISPLAY "Year = " DOS-year.
  382.  
  383. DISPLAY "Time Zone = " DOS-time-zone
  384.  
  385. INITIALIZE binary-conversion-values.
  386.  
  387. MOVE DOS-day-of-week TO one-byte-binary-value.
  388. DISPLAY "Day of Week = " two-binary-bytes-value.
  389.  
  390. DSPLY The resulting date value is : 19971209
  391. DSPLY The resulting date value is : 1997343
  392. DSPLY The resulting date value is : 2000060
  393. DSPLY Error in Date Conversion, Message ID is : CPF1060
  394. DSPLY The resulting date value is :
  395. DSPLY DOSGetDateTime Values :
  396. DSPLY Year = 1997
  397. DSPLY Time Zone = 0360
  398. DSPLY Day of Week = 0002
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement