home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / calldll.zip / ASCVARBL.CMD < prev    next >
OS/2 REXX Batch file  |  1996-02-04  |  17KB  |  431 lines

  1. /**************************************************************************/
  2. /* This REXX command file contains examples of I/O on a variable, ASCII   */
  3. /* Micro Focus indexed (VSAM) file.  It does several different types of   */
  4. /* I/O, including:                                                        */
  5. /*                                                                        */
  6. /*     1.  Open for input                                                 */
  7. /*         Read sequentially through a file                               */
  8. /*         Close                                                          */
  9. /*                                                                        */
  10. /*     2.  Open for input                                                 */
  11. /*         Position on a record                                           */
  12. /*         Read sequentially through the remainder of the file            */
  13. /*         Close                                                          */
  14. /*                                                                        */
  15. /*     3.  Open for I/O                                                   */
  16. /*         Write a new record                                             */
  17. /*         Close                                                          */
  18. /*                                                                        */
  19. /*     4.  Open for input                                                 */
  20. /*         Do a random read                                               */
  21. /*         Close                                                          */
  22. /*                                                                        */
  23. /*     5.  Open for I/O                                                   */
  24. /*         Rewrite an existing record                                     */
  25. /*         Close                                                          */
  26. /*                                                                        */
  27. /*     6.  Open for input                                                 */
  28. /*         Do a random read                                               */
  29. /*         Close                                                          */
  30. /*                                                                        */
  31. /*     7.  Open for I/O                                                   */
  32. /*         Delete an existing record                                      */
  33. /*         Close                                                          */
  34. /*                                                                        */
  35. /* Notes:  When you read a variable record, the 5 byte record length is   */
  36. /*         appended to the beginning of the returned record. For example: */
  37. /*                                                                        */
  38. /*           00090Taunya  9876 3rd St.    Dallas      TX                  */
  39. /*                                                                        */
  40. /*         When you write or rewrite a variable record, the first 5 bytes */
  41. /*         of the record must be the length of the record.  For example:  */
  42. /*                                                                        */
  43. /*           VSAMRecord = 'Taunya  9876 3rd St.    Dallas      TX'        */
  44. /*           VSAMRecord = right(length(VSAMRecord), 5, '0') || VSAMRecord */
  45. /*                                                                        */
  46. /*         This command file is ready to run.  It does I/O on             */
  47. /*         ASCVARBL.DAT, which is an ASCII, variable block, Micro Focus   */
  48. /*         indexed file.  This file is included in the INDEXIO.ZIP file.  */
  49. /*         If this file is not in the current directory, change the       */
  50. /*         VSAMFileName variable below to include the path.  For example: */
  51. /*                                                                        */
  52. /*             VSAMFileName = 'C:\FILES\ASCVARBL.DAT'                     */
  53. /*                                                                        */
  54. /*         This program opens the file, does the I/O, then closes the     */
  55. /*         file for each example.  This is done for illustrative purposes */
  56. /*         only.  Normally, you would open the file once, do all of the   */
  57. /*         I/O, then close the file.  Opening the file once would be much */
  58. /*         faster since the open operation takes a lot longer than any of */
  59. /*         the other I/O operations.                                      */
  60. /*                                                                        */
  61. /*         The examples in this command file set the ComArea prior to     */
  62. /*         performing I/O.  The ComArea tells the I/O program what type   */
  63. /*         of I/O you want to perform (open, read sequential, read        */
  64. /*         random, etc).  Here is an explanation of the ComArea fields:   */
  65. /*                                                                        */
  66. /*             Byte 1 - Call Code                                         */
  67. /*               0 - Open for input                                       */
  68. /*               Q - Open for I/O                                         */
  69. /*               2 - Random read                                          */
  70. /*               4 - Write or Rewrite                                     */
  71. /*               5 - Rewrite or Write                                     */
  72. /*               E - Erase                                                */
  73. /*               P - Position (greater than or equal to key)              */
  74. /*               1 - Read sequential (from beginning of file or last pos) */
  75. /*               9 - Close                                                */
  76. /*                                                                        */
  77. /*             Byte 2 - Return Code                                       */
  78. /*               0 - Request successfully processed                       */
  79. /*               9 - Attempting to read past end of file on seq read      */
  80. /*               B - Key definition block for the file is too big         */
  81. /*               F - File name not found                                  */
  82. /*               G - Error reading file header                            */
  83. /*               I - Invalid info passed in the ComArea                   */
  84. /*               N - Record not found on random read or erase             */
  85. /*               O - Error opening file name                              */
  86. /*               E - Other error                                          */
  87. /*                                                                        */
  88. /*             Bytes 3 through 102 (100 bytes total) - File Name          */
  89. /*                                                                        */
  90. /*             Byte 103 - F for fixed, or V for variable                  */
  91. /*                                                                        */
  92. /*             Bytes 104 through 203 (100 bytes total) - Record Key       */
  93. /*                                                                        */
  94. /*             Byte 204 - Y for EBCDIC file, anything else is ASCII file  */
  95. /*                                                                        */
  96. /*         The 4 call code (write new) and 5 (rewrite) are almost         */
  97. /*         interchangeable.  You can use either one to write a new record */
  98. /*         or to rewrite a record.  The 4 call code will first try to     */
  99. /*         write a new record.  If it fails, it will rewrite the record.  */
  100. /*         The 5 call code will first try to rewrite the record.  If it   */
  101. /*         fails, it will write a new record.  So you can use either      */
  102. /*         call code to write or rewrite, however, performance will be    */
  103. /*         a little better if you know whether the record already exists  */
  104. /*         and use the appropriate call code.                             */
  105. /*                                                                        */
  106. /*         The P call code positions on the record that is greater than   */
  107. /*         or equal to the key that you pass in.  Not only does it        */
  108. /*         position on the record, it also returns the record.  A         */
  109. /*         position changes the sequential pointer within the file.       */
  110. /*         After doing a position, sequential reads return the records    */
  111. /*         that come after the record that was positioned on.             */
  112. /**************************************************************************/
  113.  
  114. '@ECHO OFF'
  115.  
  116. VSAMFileName = 'ASCVARBL.DAT'
  117. VSAMFileName = LEFT(VSAMFileName, 100)
  118.  
  119. CALL L2_INIT_AND_LOAD_CALLDLL
  120.  
  121. CALL L2_READ_SEQUENTIAL
  122.  
  123. CALL L2_POSITION_AND_READ_SEQUENTIAL
  124.  
  125. CALL L2_WRITE
  126.  
  127. CALL L2_READ_RANDOM
  128.  
  129. CALL L2_REWRITE
  130.  
  131. CALL L2_READ_RANDOM
  132.  
  133. CALL L2_ERASE
  134.  
  135. CALL L2_UNLOAD_CALLDLL
  136.  
  137. EXIT 0
  138.  
  139. /********************************LEVEL 2 CODE********************************/
  140.  
  141. L2_INIT_AND_LOAD_CALLDLL:
  142.     CALL L3_LOAD_REXXUTIL
  143.  
  144.     CALL L3_CHECK_IF_ASCVARBL_FILE_EXISTS
  145.  
  146.     CALL L3_LOAD_CALLDLL
  147. L2_INIT_AND_LOAD_CALLDLL_EXIT:
  148.     RETURN
  149.  
  150. L2_READ_SEQUENTIAL:
  151.     CALL L3_DISPLAY_READ_SEQUENTIAL_MESSAGE
  152.  
  153.     CALL L3_OPEN_VSAM_FILE_FOR_INPUT
  154.  
  155.     CALL L3_READ_SEQUENTIALLY_THROUGH_VSAM_FILE
  156.  
  157.     CALL L3_CLOSE_FILE
  158. L2_READ_SEQUENTIAL_EXIT:
  159.     RETURN
  160.  
  161. L2_POSITION_AND_READ_SEQUENTIAL:
  162.     CALL L3_DISPLAY_POSITION_AND_READ_MESSAGE
  163.  
  164.     CALL L3_OPEN_VSAM_FILE_FOR_INPUT
  165.  
  166.     CALL L3_POSITION_ON_JOHN
  167.  
  168.     CALL L3_READ_SEQUENTIALLY_THROUGH_VSAM_FILE
  169.  
  170.     CALL L3_CLOSE_FILE
  171. L2_POSITION_AND_READ_SEQUENTIAL_EXIT:
  172.     RETURN
  173.  
  174. L2_WRITE:
  175.     CALL L3_DISPLAY_WRITE_MESSAGE
  176.  
  177.     CALL L3_OPEN_VSAM_FILE_FOR_INPUT_OUTPUT
  178.  
  179.     CALL L3_WRITE_A_RECORD_TO_VSAM_FILE
  180.  
  181.     CALL L3_CLOSE_FILE
  182. L2_WRITE_EXIT:
  183.     RETURN
  184.  
  185. L2_READ_RANDOM:
  186.     CALL L3_DISPLAY_READ_RANDOM_MESSAGE
  187.  
  188.     CALL L3_OPEN_VSAM_FILE_FOR_INPUT
  189.  
  190.     CALL L3_READ_A_RECORD_FROM_VSAM_FILE
  191.  
  192.     CALL L3_CLOSE_FILE
  193. L2_READ_RANDOM_EXIT:
  194.     RETURN
  195.  
  196. L2_REWRITE:
  197.     CALL L3_DISPLAY_REWRITE_MESSAGE
  198.  
  199.     CALL L3_OPEN_VSAM_FILE_FOR_INPUT_OUTPUT
  200.  
  201.     CALL L3_REWRITE_A_RECORD_TO_VSAM_FILE
  202.  
  203.     CALL L3_CLOSE_FILE
  204. L2_REWRITE_EXIT:
  205.     RETURN
  206.  
  207. L2_ERASE:
  208.     CALL L3_DISPLAY_ERASE_RANDOM_MESSAGE
  209.  
  210.     CALL L3_OPEN_VSAM_FILE_FOR_INPUT_OUTPUT
  211.  
  212.     CALL L3_ERASE_A_RECORD_FROM_VSAM_FILE
  213.  
  214.     CALL L3_CLOSE_FILE
  215. L2_ERASE_EXIT:
  216.     RETURN
  217.  
  218. L2_UNLOAD_CALLDLL:
  219.     call CallDLLDropFuncs
  220. L2_UNLOAD_CALLDLL_EXIT:
  221.     RETURN
  222.  
  223. /********************************LEVEL 3 CODE********************************/
  224.  
  225. L3_LOAD_REXXUTIL:
  226.     IF RXFUNCQUERY('SYSLOADFUNCS') THEN DO
  227.         CALL RXFUNCADD 'SYSLOADFUNCS', 'REXXUTIL', 'SYSLOADFUNCS'
  228.         CALL SYSLOADFUNCS
  229.     END
  230. L3_LOAD_REXXUTIL_EXIT:
  231.     RETURN
  232.  
  233. L3_CHECK_IF_ASCVARBL_FILE_EXISTS:
  234.     call sysfiletree VSAMFileName,'file','f'
  235.     if file.0 = 0 then do
  236.         say
  237.         say strip(VSAMFileName) 'does not exits.  This file is included in'
  238.         say 'INDEXIO.ZIP.' strip(VSAMFileName) 'must be in the current directory,'
  239.         say 'or you can change the "VSAMFileName" variable in this command'
  240.         say 'file to include the path where' strip(VSAMFileName) 'resides.  For'
  241.         say 'example:'
  242.         say
  243.         say '    VSAMFileName = C:\FILES\ASCFILXED.DAT'
  244.         exit 9
  245.     end
  246. L3_CHECK_IF_ASCVARBL_FILE_EXISTS_EXIT:
  247.     RETURN
  248.  
  249. L3_LOAD_CALLDLL:
  250.     if RXFUNCQUERY('CallDLLLoadFuncs') then do
  251.         call RXFUNCADD 'CallDLLLoadFuncs', 'CALLDLL', 'CallDLLLoadFuncs'
  252.         call CallDLLLoadFuncs
  253.     end
  254. L3_LOAD_CALLDLL_EXIT:
  255.     RETURN
  256.  
  257. L3_DISPLAY_READ_SEQUENTIAL_MESSAGE:
  258.     say
  259.     say 'Hit enter to read' strip(VSAMFileName) 'sequentially.'
  260.  
  261.     parse pull junk
  262. L3_DISPLAY_READ_SEQUENTIAL_MESSAGE_EXIT:
  263.     RETURN
  264.  
  265. L3_OPEN_VSAM_FILE_FOR_INPUT:
  266.     ComArea = '00'VSAMFileName'V'
  267.     call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  268.  
  269.     ReturnCode = substr(ComArea, 2, 1)
  270.     if ReturnCode <> 0 then do
  271.         say 'There was an error opening' strip(VSAMFileName)'.  Aborting...'
  272.         exit 9
  273.     end
  274. L3_OPEN_VSAM_FILE_FOR_INPUT_EXIT:
  275.     RETURN
  276.  
  277. L3_READ_SEQUENTIALLY_THROUGH_VSAM_FILE:
  278.     ComArea = '10'VSAMFileName'V'
  279.     VSAMRecord = left('', 99)
  280.  
  281.     do while ReturnCode = 0
  282.         call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  283.  
  284.         ReturnCode = substr(ComArea, 2, 1)
  285.         if ReturnCode = 0 then
  286.             say strip(VSAMRecord)
  287.     end
  288. L3_READ_SEQUENTIALLY_THROUGH_VSAM_FILE_EXIT:
  289.     RETURN
  290.  
  291. L3_READ_A_RECORD_FROM_VSAM_FILE:
  292.     key = left('Taunya', 100)
  293.     ComArea = '20'VSAMFileName'V'key
  294.     VSAMRecord = left('', 99)
  295.  
  296.     call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  297.     ReturnCode = substr(ComArea, 2, 1)
  298.     if ReturnCode = 0 then
  299.         say strip(VSAMRecord)
  300. L3_READ_A_RECORD_FROM_VSAM_FILE_EXIT:
  301.     RETURN
  302.  
  303. L3_CLOSE_FILE:
  304.     ComArea = '90'VSAMFileName'V'
  305.     call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  306.  
  307.     ReturnCode = substr(ComArea, 2, 1)
  308.  
  309.     if ReturnCode <> 0 then do
  310.         SAY 'There was an error closing' strip(VSAMFileName)'.  Aborting...'
  311.         exit 9
  312.     end
  313. L3_CLOSE_FILE_EXIT:
  314.     RETURN
  315.  
  316. L3_DISPLAY_POSITION_AND_READ_MESSAGE:
  317.     say
  318.     say 'Hit enter to read' strip(VSAMFileName) 'sequentially, starting with John.'
  319.  
  320.     parse pull junk
  321. L3_DISPLAY_POSITION_AND_READ_MESSAGE_EXIT:
  322.     RETURN
  323.  
  324. L3_POSITION_ON_JOHN:
  325.     key = left('John', 100)
  326.     ComArea = 'P0'VSAMFileName'V'key
  327.     VSAMRecord = left('', 99)
  328.  
  329.     call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  330.     ReturnCode = substr(ComArea, 2, 1)
  331.     if ReturnCode = 0 then
  332.         say strip(VSAMRecord)
  333. L3_POSITION_ON_JOHN_EXIT:
  334.     RETURN
  335.  
  336. L3_DISPLAY_WRITE_MESSAGE:
  337.     say
  338.     say 'Hit enter to add Taunya to' strip(VSAMFileName)
  339.  
  340.     parse pull junk
  341. L3_DISPLAY_WRITE_MESSAGE_EXIT:
  342.     RETURN
  343.  
  344. L3_OPEN_VSAM_FILE_FOR_INPUT_OUTPUT:
  345.     ComArea = 'Q0'VSAMFileName'V'
  346.     call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  347.  
  348.     ReturnCode = substr(ComArea, 2, 1)
  349.     if ReturnCode <> 0 then do
  350.         say 'There was an error opening' strip(VSAMFileName)'.  Aborting...'
  351.         exit 9
  352.     end
  353. L3_OPEN_VSAM_FILE_FOR_INPUT_OUTPUT_EXIT:
  354.     RETURN
  355.  
  356. L3_WRITE_A_RECORD_TO_VSAM_FILE:
  357.     key = left('Taunya', 100)
  358.     ComArea = '40'VSAMFileName'V'key
  359.     VSAMRecord = 'Taunya  9876 3rd St.    Dallas      TX'
  360.     VSAMRecord = right(length(VSAMRecord), 5, '0') || VSAMRecord
  361.  
  362.     call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  363.     ReturnCode = substr(ComArea, 2, 1)
  364.     if ReturnCode = 0 then
  365.         say 'Taunya was successfully added to' strip(VSAMFileName)
  366.     else do
  367.         say 'There was an error writing to' VSAMFile'.  Aborting...'
  368.         exit 9
  369.     end
  370. L3_WRITE_A_RECORD_TO_VSAM_FILE_EXIT:
  371.     RETURN
  372.  
  373. L3_DISPLAY_READ_RANDOM_MESSAGE:
  374.     say
  375.     say 'Hit enter to read the record for Taunya from' strip(VSAMFileName)
  376.  
  377.     parse pull junk
  378. L3_DISPLAY_READ_RANDOM_MESSAGE_EXIT:
  379.     RETURN
  380.  
  381. L3_DISPLAY_REWRITE_MESSAGE:
  382.     say
  383.     say 'Hit enter to update Taunya in' strip(VSAMFileName)
  384.  
  385.     parse pull junk
  386. L3_DISPLAY_REWRITE_MESSAGE_EXIT:
  387.     RETURN
  388.  
  389. L3_REWRITE_A_RECORD_TO_VSAM_FILE:
  390.     key = left('Taunya', 100)
  391.     ComArea = '50'VSAMFileName'V'key
  392.     VSAMRecord = 'Taunya  1234 Rosemont   Baltimore   MD'
  393.     VSAMRecord = right(length(VSAMRecord), 5, '0') || VSAMRecord
  394.  
  395.     call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  396.     ReturnCode = substr(ComArea, 2, 1)
  397.     if ReturnCode = 0 then
  398.         say 'Taunya was successfully updated in' strip(VSAMFileName)
  399.     else do
  400.         say 'There was an error rewriting to' strip(VSAMFile)'.  Aborting...'
  401.         exit 9
  402.     end
  403. L3_REWRITE_A_RECORD_TO_VSAM_FILE_EXIT:
  404.     RETURN
  405.  
  406. L3_DISPLAY_ERASE_RANDOM_MESSAGE:
  407.     say
  408.     say 'Hit enter to erase the record for Taunya from' strip(VSAMFileName)
  409.  
  410.     parse pull junk
  411. L3_DISPLAY_ERASE_RANDOM_MESSAGE_EXIT:
  412.     RETURN
  413.  
  414. L3_ERASE_A_RECORD_FROM_VSAM_FILE:
  415.     key = left('Taunya', 100)
  416.     ComArea = 'E0'VSAMFileName'V'key
  417.     VSAMRecord = left('', 99)
  418.  
  419.     call CallDLL 'INDEXIO', 'ComArea', 'VSAMRecord'
  420.     ReturnCode = substr(ComArea, 2, 1)
  421.     if ReturnCode = 0 then
  422.         say 'Taunya was successfully erased from' strip(VSAMFileName)
  423.     else do
  424.         say 'There was an error erasing Taunya from' strip(VSAMFile)'.  Aborting...'
  425.         exit 9
  426.     end
  427. L3_ERASE_A_RECORD_FROM_VSAM_FILE_EXIT:
  428.     RETURN
  429.  
  430.  
  431.