![]() |
Comma Delimited File Creating a File with COBOL http://www.simotime.com Copyright © 1987-2010 SimoTime Enterprises All Rights Reserved |
| Table of Contents | Version 09.05.17 |
This suite of sample programs describes how to read a column oriented file of fixed length records and fixed length fields and create a comma-delimited file (filename.CSV, Comma-Separated-Value) of variable length fields with the leading and trailing spaces removed from each of the fields. If a field (or data string) contains a delimiter character then enclose the field in double quotes. The program may be adjusted to create a delimited file using a tab, semicolon or other character as the delimiter.
This example illustrates the following functions.
| 1. | Demonstrate how to read a sequential file (or a Line Sequential file) and create a comma-delimited file using Micro Focus COBOL (Net Express was used for the testing). |
| 2. | Demonstrate how to remove leading spaces from each field. |
| 3. | Demonstrate how to remove trailing spaces from each field. |
| 4. | Demonstrate how to enclose a data string that contains a delimiter character in double quotes. |
| 5. | Describe how to scan the fields to remove the delimiter characters from the data string. |
| 6. | Demonstrate how to omit blank records from the output file. |
| 7. | Provide an example of a Window's CMD file to run the job on Windows using Micro Focus Net Express. |
The following is an example of a file that contains records with predefined, fixed-length fields. This file will be used to create a Comma Delimited file (filename.CSV).The customer number is in positions 1 through 6. Notice that customer numbers 002200, 002300 and 999999 contain examples of fields with leading spaces and fields that contain a comma in the data string. All the records have trailing spaces in the fields.
The following is the record layout for COBOL.
01 SYSTXTT1-RECORD.
05 SYSTXTT1-KEY PIC X(6).
05 FILLER PIC X.
05 SYSTXTT1-LAST-NAME PIC X(20).
05 SYSTXTT1-FIRST-NAME PIC X(10).
05 SYSTXTT1-STREET-ADDRESS PIC X(25).
05 SYSTXTT1-CITY PIC X(16).
05 SYSTXTT1-STATE PIC X(2).
The following is the column-oriented, LINE SEQUENTIAL (ASCII/Text ) file that was used for testing the programs.
000000000100 Anderson Adrian 111 Peachtree Plaza, Suite 111 Atlanta GA 000000000200 Brown Billie 222 Baker Boulevard Baltimore MD 000000000300 Carson Cameron 333 Crenshaw Blvd. Cupertino CA 000000000400 Davidson Dion 444 Main Street Wilmington DE 000000000500 Everest Evan 555 5TH Avenue New york NY 000000000600 Franklin Francis 666 66TH Avenue Bedrock NY 000000000700 Garfunkel Gwen 777 77TH Street New york NY 000000000800 Harrison Hilary 888 88TH Street Pocatello ID 000000000900 Isley Isabel 999 99TH Avenue Indianapolis IN 000000001000 Johnson Jamie 1010 Paradise Drive Larkspur CA 000000001100 Kemper Kelly 1111 Oak Circle Kansas City KS 000000001200 Lemond Lesley 1212 Lockwood Road Mohave Desert AZ 000000001300 Mitchell Marlow 1313 Miller Creek Road Anywhere TX 000000001400 Newman Noel 1414 Park Avenue Santa Monica CA 000000001500 Osborn Owen 1515 Center Stage Rolling Rock PA 000000001600 Powell Pierce 1616 Central Avenue Ventura CA 000000001700 Quigley Quincy 1717 Farm Hill Road Oshkosh WI 000000001800 Ripley Ray 1818 Alien Lane Wayout KS 000000001900 Smith Sammy 1919 Carnoustie Drive Novato CA 000000002000 Tucker Taylor 2020 Sanger Lane St. Paul MN 000000002100 Underwood Ulysses 2121 Wall Street New York NY 000000002200 Victoria Vaughn 2222 Vine Street, #22 Hollywood CA 000000002300 Wilson Wiley 2323 Main Street, #23 Boston MA 000000002400 Xray Xavier 2424 24TH Street Nashville TN 000000002500 Young Yanni 2525 Yonge Street Toronto ON 000000002600 Zenith Zebulon 2626 26TH Street Dallas TX 000000123456 Doe John 123 Main Street Anywhere OR 000000999999 Smith 99 E Street San Rafael CA
The following is an example of a Comma Delimited file that was created from reading the preceding Sequential (or LINE Sequential) file that contains records with predefined, fixed fields. This file was created by a COBOL program running on a PC with Micro Focus COBOL (Net Express, version 4.0).
000000000100,Anderson,Adrian,"111 Peachtree Plaza, Suite 111",Atlanta,GA 000000000200,Brown,Billie,222 Baker Boulevard,Baltimore,MD 000000000300,Carson,Cameron,333 Crenshaw Blvd.,Cupertino,CA 000000000400,Davidson,Dion,444 Main Street,Wilmington,DE 000000000500,Everest,Evan,555 5TH Avenue,New york,NY 000000000600,Franklin,Francis,666 66TH Avenue,Bedrock,NY 000000000700,Garfunkel,Gwen,777 77TH Street,New york,NY 000000000800,Harrison,Hilary,888 88TH Street,Pocatello,ID 000000000900,Isley,Isabel,999 99TH Avenue,Indianapolis,IN 000000001000,Johnson,Jamie,1010 Paradise Drive,Larkspur,CA 000000001100,Kemper,Kelly,1111 Oak Circle,Kansas City,KS 000000001200,Lemond,Lesley,1212 Lockwood Road,Mohave Desert,AZ 000000001300,Mitchell,Marlow,1313 Miller Creek Road,Anywhere,TX 000000001400,Newman,Noel,1414 Park Avenue,Santa Monica,CA 000000001500,Osborn,Owen,1515 Center Stage,Rolling Rock,PA 000000001600,Powell,Pierce,1616 Central Avenue,Ventura,CA 000000001700,Quigley,Quincy,1717 Farm Hill Road,Oshkosh,WI 000000001800,Ripley,Ray,1818 Alien Lane,Wayout,KS 000000001900,Smith,Sammy,1919 Carnoustie Drive,Novato,CA 000000002000,Tucker,Taylor,2020 Sanger Lane,St. Paul,MN 000000002100,Underwood,Ulysses,2121 Wall Street,New York,NY 000000002200,Victoria,Vaughn,"2222 Vine Street, #22",Hollywood,CA 000000002300,Wilson,Wiley,"2323 Main Street, #23",Boston,MA 000000002400,Xray,Xavier,2424 24TH Street,Nashville,TN 000000002500,Young,Yanni,2525 Yonge Street,Toronto,ON 000000002600,Zenith,Zebulon,2626 26TH Street,Dallas,TX 000000123456,Doe,John,123 Main Street,Anywhere,OR 000000999999,Smith,,99 E Street,San Rafael,CA
This suite of samples programs will run on the following platforms.
| 1. | Executes on Windows/2000, Windows/NT and Windows/XP using Micro Focus Net Express and the CMD file provided. |
| 2. | May be ported to run on the UNIX platforms supported by Micro Focus COBOL. |
The following is a flowchart of the job for executing the program to create a Comma Delimited file from a Sequential file of fixed-length fields.
|
Start the Job | ||||||||||
|
|
|||||||||||
|
|
|
|
|
Read a Sequential file and create a comma-delimited file | ||||||
|
|
|||||||||||
|
End-of-Job | ||||||||||
The main program (CBLCSVC1) will read a Sequential file (TXTGETD1) and produce a 128-byte, variable record length Comma-delimited sequential file (CSVPUTD1). The contents of this file will be variable length fields separated by a comma. The leading and trailing spaces will be removed from each field. Embedded spaces will remain. The source code for the CMD file, the JCL member and the COBOL programs is provided and may be modified to fit your environment.
The following (CBLCSVE1.CMD) is a sample of the Windows CMD needed to run this job.
@echo OFF
echo * CblCsvE1 is Starting...
rem * *******************************************************************
rem * This program is provided by: *
rem * SimoTime Enterprises, LLC *
rem * (C) Copyright 1987-2010 All Rights Reserved *
rem * Web Site URL: http://www.simotime.com *
rem * e-mail: helpdesk@simotime.com *
rem * *******************************************************************
rem *
rem * Text - COBOL, read a TXT file and create a CSV file.
rem * Author - SimoTime Enterprises
rem * Date - December 12, 2003
rem * Version - 04.01.20
rem *
rem * This set of programs illustrates the use a COBOL program to read
rem * a column-oriented, ASCII.Text file and create a comma-delimited
rem * file.
rem *
rem * The COBOL program is compiled with the ASSIGN(EXTERNAL) directive.
rem * This provides for external file mapping of the file names.
rem *
rem * This set of programs will run on a Personal Computer with Windows
rem * and Micro Focus Net Express.
rem *
rem * ************
rem * * CblCsvE1 *
rem * ********cmd*
rem * *
rem * *
rem * ************ ************ ************
rem * * SimoEXEC ******* SIMOLOGS ******* CONSOLE *
rem * ********cbl* * ********cbl* * ************
rem * * * *
rem * * * * ************
rem * * * **** SYSLOG *
rem * * * ********txt*
rem * * *
rem * * **************************
rem * * *
rem * * ************ ************ ************
rem * * * TXTGETD1 ******* CblCsvC1 ******* CSVPUTD1 *
rem * * ********txt* ********cbl* ********csv*
rem * *
rem * *
rem * ************
rem * * EOJ *
rem * ************
rem *
rem * ********************************************************************
rem * Step 1 of 2 Set the global environment variables...
rem *
set syslog=d:\simoNXE4\AN01\datawrk1\SYSLOGT1.TXT
rem *
SimoEXEC NOTE *******************************************************CblCsvE1
SimoEXEC NOTE Starting JobName CblCsvE1
rem * *******************************************************************
rem * Step 2 of 2 Execute the program, create a CSV file.
rem *
set TXTGETD1=d:\simoNXE4\AN01\DataAsc1\CustomerTextMaster.txt
set CSVPUTD1=d:\simoNXE4\AN01\DataCsv1\CustomerCommaDelimited.csv
if exist %CSVPUTD1% del %CSVPUTD1%
SimoEXEC EXEC CblCsvC1
if exist %CSVPUTD1% SimoEXEC NOTE Produced DataSet %CSVPUTD1%
SimoEXEC NOTE Finished JobName CblCsvE1
if not "%1" == "nopause" pause
The following (CBLCSVC1.CBL) is a sample of the Micro Focus COBOL demonstration program. This program will not compile or execute on an IBM Mainframe because of the ORGANIZATION IS LINE SEQUENTIAL on the SELECT statement. If the statement was changed to read ORGANIZATION IS SEQUENTIAL it would run on an IBM Mainframe and "read from" and "write to" a sequential file. The program was tested using Micro Focus Net Express, version 4.0 running on Windows/2000.
IDENTIFICATION DIVISION.
PROGRAM-ID. CBLCSVC1.
AUTHOR. SIMOTIME ENTERPRISES.
*****************************************************************
* Copyright (C) 1987-2010 SimoTime Enterprises, LLC. *
* *
* All rights reserved. Unpublished, all rights reserved under *
* copyright law and international treaty. Use of a copyright *
* notice is precautionary only and does not imply publication *
* or disclosure. *
* *
* Permission to use, copy, modify and distribute this software *
* for any non-commercial purpose and without fee is hereby *
* granted, provided the SimoTime copyright notice appear on all *
* copies of the software. The SimoTime name or Logo may not be *
* used in any advertising or publicity pertaining to the use *
* of the software without the written permission of SimoTime *
* Enterprises. *
* *
* Permission to use, copy, modify and distribute this software *
* for any commercial purpose requires a fee to be paid to *
* SimoTime Enterprises. Once the fee is received by SimoTime *
* the latest version of the software will be delivered and a *
* license will be granted for use within an enterprise, *
* provided the SimoTime copyright notice appear on all copies *
* of the software. The SimoTime name or Logo may not be used *
* in any advertising or publicity pertaining to the use of the *
* software without the written permission of SimoTime *
* Enterprises. *
* *
* SimoTime Enterprises makes no warranty or representations *
* about the suitability of the software for any purpose. It is *
* provided "AS IS" without any express or implied warranty, *
* including the implied warranties of merchantability, fitness *
* for a particular purpose and non-infringement. SimoTime *
* Enterprises shall not be liable for any direct, indirect, *
* special or consequential damages resulting from the loss of *
* use, data or projects, whether in an action of contract or *
* tort, arising out of or in connection with the use or *
* performance of this software *
* *
* SimoTime Enterprises *
* 15 Carnoustie Drive *
* Novato, CA 94949-5849 *
* 415.883.6565 *
* *
* RESTRICTED RIGHTS LEGEND *
* Use, duplication, or disclosure by the Government is subject *
* to restrictions as set forth in subparagraph (c)(1)(ii) of *
* the Rights in Technical Data and Computer Software clause at *
* DFARS 52.227-7013 or subparagraphs (c)(1) and (2) of *
* Commercial Computer Software - Restricted Rights at 48 *
* CFR 52.227-19, as applicable. Contact SimoTime Enterprises, *
* 15 Carnoustie Drive, Novato, CA 94949-5849. *
*****************************************************************
* This base program was generated by SimoZAPS *
* A product of SimoTime Enterprises *
* Our e-mail address is: helpdesk@simotime.com *
* Also, visit our Web Site at http://www.simotime.com *
* *
* Record Record Key *
* Function Name Organization Format Max-Min Pos-Len *
* INPUT TXTGETD1 SEQUENTIAL FIXED 00080 *
* OUTPUT CSVPUTD1 ASCII/CRLF VARIABLE 00080 *
* *
*****************************************************************
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
* The LINE SEQUENTIAL file organization is Micro Fcus
* syntax for an ASCII/Text file.
SELECT TXTGETD1-FILE ASSIGN TO TXTGETD1
ORGANIZATION IS LINE SEQUENTIAL
ACCESS MODE IS SEQUENTIAL
FILE STATUS IS TXTGETD1-STATUS.
SELECT CSVPUTD1-FILE ASSIGN TO CSVPUTD1
ORGANIZATION IS LINE SEQUENTIAL
ACCESS MODE IS SEQUENTIAL
FILE STATUS IS CSVPUTD1-STATUS.
*****************************************************************
DATA DIVISION.
FILE SECTION.
FD TXTGETD1-FILE
DATA RECORD IS CUSTTEXT-RECORD.
COPY CUSTTXB1.
FD CSVPUTD1-FILE
DATA RECORD IS CSVPUTD1-RECORD.
01 CSVPUTD1-RECORD.
05 CSVPUTD1-DATA-01 PIC X(00128).
WORKING-STORAGE SECTION.
*****************************************************************
* Data-structure for Title and Copyright...
* ------------------------------------------------------------
01 SIM-TITLE.
05 T1 pic X(11) value '* CBLCSVC1 '.
05 T2 pic X(34) value 'Comma Delimited File, Write Access'.
05 T3 pic X(10) value ' v03.12.15'.
05 T4 pic X(24) value ' http://www.simotime.com'.
01 SIM-COPYRIGHT.
05 C1 pic X(11) value '* CBLCSVC1 '.
05 C2 pic X(20) value 'Copyright 2003-2004 '.
05 C3 pic X(28) value ' SimoTime Enterprises, LLC '.
05 C4 pic X(20) value ' All Rights Reserved'.
01 SIM-THANKS-01.
05 C1 pic X(11) value '* CBLCSVC1 '.
05 C2 pic X(32) value 'Thank you for using this sample '.
05 C3 pic X(32) value 'by SimoTime Enterprises, LLC '.
05 C4 pic X(04) value ' '.
01 SIM-THANKS-02.
05 C1 pic X(11) value '* CBLCSVC1 '.
05 C2 pic X(32) value 'Please send comments or suggesti'.
05 C3 pic X(32) value 'ons to helpdesk@simotime.com '.
05 C4 pic X(04) value ' '.
01 TXTGETD1-STATUS.
05 TXTGETD1-STATUS-L pic X.
05 TXTGETD1-STATUS-R pic X.
01 TXTGETD1-EOF pic X value 'N'.
01 TXTGETD1-OPEN-FLAG pic X value 'C'.
01 CSVPUTD1-STATUS.
05 CSVPUTD1-STATUS-L pic X.
05 CSVPUTD1-STATUS-R pic X.
01 CSVPUTD1-OPEN-FLAG pic X value 'C'.
01 IO-STATUS.
05 IO-STAT1 pic X.
05 IO-STAT2 pic X.
01 TWO-BYTES.
05 TWO-BYTES-LEFT pic X.
05 TWO-BYTES-RIGHT pic X.
01 TWO-BYTES-BINARY redefines TWO-BYTES pic 9(4) comp.
01 IO-STATUS-4 pic 9(4) value 0.
01 IO-STATUS-4A redefines IO-STATUS-4 pic X(4).
*****************************************************************
* Message Buffer used by the Z-DISPLAY-MESSAGE-TEXT routine. *
*****************************************************************
01 MESSAGE-BUFFER.
05 MESSAGE-HEADER pic X(11) value '* CBLCSVC1 '.
05 MESSAGE-TEXT.
10 MESSAGE-TEXT-1 pic X(68) value SPACES.
10 MESSAGE-TEXT-2 pic X(188) value SPACES.
01 MESSAGE-BUFFER-SIZE pic 9(3) value 267.
01 MSG-PTR pic 9(3) value 0.
01 MSG-LEN pic 9(3) value 0.
01 APPL-RESULT pic S9(9) comp.
88 APPL-AOK value 0.
88 APPL-EOF value 16.
01 DOUBLE-QUOTE pic X value '"'.
01 DATA-HAS-DELIMITER pic X value 'N'.
01 DELIMITER-BYTE pic X value ','.
01 WORK-128 pic X(128) value SPACES.
01 WORK-50 pic X(50) value SPACES.
01 SIG-FIRST pic 9(3) value 0.
01 SIG-LAST pic 9(3) value 0.
01 SIG-LENGTH pic 9(3) value 0.
01 IDX-1 pic 9(3) value 0.
01 IDX-STOP pic 9(3) value 0.
01 CSV-X1 pic 9(3) value 0.
*****************************************************************
PROCEDURE DIVISION.
perform Z-POST-COPYRIGHT
perform TXTGETD1-OPEN
perform CSVPUTD1-OPEN
perform until TXTGETD1-STATUS not = '00'
perform TXTGETD1-READ
* If a successful read of the input file and the input
* record is not equal to SPACES then create an output.
if TXTGETD1-STATUS = '00'
and CUSTTEXT-RECORD not = SPACES
display CUSTTEXT-RECORD
perform BUILD-COMMA-DELIMITED-STRING
display WORK-128
perform POST-STRING-WITH-CLEAR-AFTER
end-if
end-perform
perform CSVPUTD1-CLOSE
perform TXTGETD1-CLOSE
perform Z-THANK-YOU
GOBACK.
*****************************************************************
* The following routines are in alphabetical sequence.. *
*****************************************************************
BUILD-COMMA-DELIMITED-STRING.
add 1 to ZERO giving CSV-X1
move CUSTTEXT-KEY to WORK-50
perform PARSE-AND-POST
move CUSTTEXT-LAST-NAME to WORK-50
perform PARSE-AND-POST
move CUSTTEXT-FIRST-NAME to WORK-50
perform PARSE-AND-POST
move CUSTTEXT-STREET-ADDRESS to WORK-50
perform PARSE-AND-POST
move CUSTTEXT-CITY to WORK-50
perform PARSE-AND-POST
move CUSTTEXT-STATE to WORK-50
perform PARSE-AND-POST
* Set CSV-X1 to position of last character in string and
* remove the trailing comma...
subtract 1 from CSV-X1
if WORK-128(CSV-X1:2) = ', '
move ' ' to WORK-128(CSV-X1:2)
subtract 1 from CSV-X1
end-if
exit.
*****************************************************************
PARSE-AND-POST.
perform PARSE-WORK-50
perform POST-WORK-50
exit.
*****************************************************************
* Determine the position within the field of the first and last *
* significant characters within a field. Also, determine the *
* length of the text string within the field. *
*****************************************************************
PARSE-WORK-50.
subtract SIG-FIRST from SIG-FIRST
subtract SIG-LAST from SIG-LAST
subtract SIG-LENGTH from SIG-LENGTH
* The IDX-STOP is used to stop the perform loop by setting the
* number of characters to scan.
add 50 to ZERO giving IDX-STOP
* The following is for performance and will quickly reduce
* the number of times the perform loop executes.
if WORK-50(26:25) = SPACES
if WORK-50(13:13) = SPACES
add 12 to ZERO giving IDX-STOP
else
add 25 to ZERO giving IDX-STOP
end-if
else
if WORK-50(38:13) = SPACES
add 37 to ZERO giving IDX-STOP
else
add 50 to ZERO giving IDX-STOP
end-if
end-if
add 1 to ZERO giving IDX-1
move 'N' to DATA-HAS-DELIMITER
perform until IDX-1 GREATER THAN IDX-STOP
if WORK-50(IDX-1:1) = DELIMITER-BYTE
move 'Y' to DATA-HAS-DELIMITER
end-if
if WORK-50(IDX-1:1) not = SPACE
add IDX-1 to ZERO giving SIG-LAST
if SIG-FIRST = 0
add IDX-1 to ZERO giving SIG-FIRST
end-if
end-if
add 1 to IDX-1
end-perform
if SIG-FIRST GREATER THAN ZERO
compute SIG-LENGTH = SIG-LAST - SIG-FIRST + 1
end-if
exit.
*****************************************************************
* Move the field to the output buffer and insert a trailing *
* delimiter character. *
*****************************************************************
POST-WORK-50.
* The following will insert a leading Double-Quote if the
* data string contains a delimiter character.
if DATA-HAS-DELIMITER = 'Y'
move DOUBLE-QUOTE to WORK-128(CSV-X1:1)
add 1 to CSV-X1
end-if
*
* Remove the delimiter characters from the data string.
* inspect WORK-50(1:IDX-STOP)
* replacing all DELIMITER-BYTE by SPACE
*
if SIG-FIRST GREATER THAN ZERO
move WORK-50(SIG-FIRST:SIG-LENGTH)
to WORK-128(CSV-X1:SIG-LENGTH)
add SIG-LENGTH to CSV-X1
* The following will insert a trailing Double-Quote if
* the data string contains a delimiter character.
if DATA-HAS-DELIMITER = 'Y'
move DOUBLE-QUOTE to WORK-128(CSV-X1:1)
add 1 to CSV-X1
end-if
*
move DELIMITER-BYTE to WORK-128(CSV-X1:1)
add 1 to CSV-X1
else
move DELIMITER-BYTE to WORK-128(CSV-X1:1)
add 1 to CSV-X1
end-if
exit.
*****************************************************************
* Write the comma delimited record to the output file. *
*****************************************************************
POST-STRING-WITH-CLEAR-AFTER.
move WORK-128 to CSVPUTD1-RECORD
perform CSVPUTD1-WRITE
move SPACES to WORK-128
exit.
*****************************************************************
* I/O ROUTINES FOR TXTGETD1... *
*****************************************************************
TXTGETD1-CLOSE.
add 8 to ZERO giving APPL-RESULT.
close TXTGETD1-FILE
if TXTGETD1-STATUS = '00'
subtract APPL-RESULT from APPL-RESULT
else
add 12 to ZERO giving APPL-RESULT
end-if
if APPL-AOK
CONTINUE
else
move 'TXTGETD1-Failure-CLOSE...' to MESSAGE-TEXT
perform Z-DISPLAY-MESSAGE-TEXT
move TXTGETD1-STATUS to IO-STATUS
perform Z-DISPLAY-IO-STATUS
perform Z-ABEND-PROGRAM
end-if
exit.
*---------------------------------------------------------------*
TXTGETD1-READ.
read TXTGETD1-FILE
if TXTGETD1-STATUS = '00'
subtract APPL-RESULT from APPL-RESULT
else
if TXTGETD1-STATUS = '10'
add 16 to ZERO giving APPL-RESULT
else
add 12 to ZERO giving APPL-RESULT
end-if
end-if
if APPL-AOK
CONTINUE
else
if APPL-EOF
move 'Y' to TXTGETD1-EOF
else
move 'TXTGETD1-Failure-GET...' to MESSAGE-TEXT
perform Z-DISPLAY-MESSAGE-TEXT
move TXTGETD1-STATUS to IO-STATUS
perform Z-DISPLAY-IO-STATUS
perform Z-ABEND-PROGRAM
end-if
end-if
exit.
*---------------------------------------------------------------*
TXTGETD1-OPEN.
add 8 to ZERO giving APPL-RESULT.
open input TXTGETD1-FILE
if TXTGETD1-STATUS = '00'
subtract APPL-RESULT from APPL-RESULT
move 'O' to TXTGETD1-OPEN-FLAG
else
add 12 to ZERO giving APPL-RESULT
end-if
if APPL-AOK
CONTINUE
else
move 'TXTGETD1-Failure-OPEN...' to MESSAGE-TEXT
perform Z-DISPLAY-MESSAGE-TEXT
move TXTGETD1-STATUS to IO-STATUS
perform Z-DISPLAY-IO-STATUS
perform Z-ABEND-PROGRAM
end-if
exit.
*****************************************************************
* I/O ROUTINES FOR CSVPUTD1... *
*****************************************************************
CSVPUTD1-WRITE.
if CSVPUTD1-OPEN-FLAG = 'C'
perform CSVPUTD1-OPEN
end-if
write CSVPUTD1-RECORD
if CSVPUTD1-STATUS = '00'
subtract APPL-RESULT from APPL-RESULT
else
if CSVPUTD1-STATUS = '10'
add 16 to ZERO giving APPL-RESULT
else
add 12 to ZERO giving APPL-RESULT
end-if
end-if.
if APPL-AOK
CONTINUE
else
move 'CSVPUTD1-Failure-WRITE...' to MESSAGE-TEXT
perform Z-DISPLAY-MESSAGE-TEXT
move CSVPUTD1-STATUS to IO-STATUS
perform Z-DISPLAY-IO-STATUS
perform Z-ABEND-PROGRAM
end-if
exit.
*---------------------------------------------------------------*
CSVPUTD1-OPEN.
add 8 to ZERO giving APPL-RESULT.
open OUTPUT CSVPUTD1-FILE
if CSVPUTD1-STATUS = '00'
subtract APPL-RESULT from APPL-RESULT
move 'O' to CSVPUTD1-OPEN-FLAG
else
add 12 to ZERO giving APPL-RESULT
end-if
if APPL-AOK
CONTINUE
else
move 'CSVPUTD1-Failure-OPEN...' to MESSAGE-TEXT
perform Z-DISPLAY-MESSAGE-TEXT
move CSVPUTD1-STATUS to IO-STATUS
perform Z-DISPLAY-IO-STATUS
perform Z-ABEND-PROGRAM
end-if
exit.
*---------------------------------------------------------------*
CSVPUTD1-CLOSE.
add 8 to ZERO giving APPL-RESULT.
close CSVPUTD1-FILE
if CSVPUTD1-STATUS = '00'
subtract APPL-RESULT from APPL-RESULT
move 'C' to CSVPUTD1-OPEN-FLAG
else
add 12 to ZERO giving APPL-RESULT
end-if
if APPL-AOK
CONTINUE
else
move 'CSVPUTD1-Failure-CLOSE...' to MESSAGE-TEXT
perform Z-DISPLAY-MESSAGE-TEXT
move CSVPUTD1-STATUS to IO-STATUS
perform Z-DISPLAY-IO-STATUS
perform Z-ABEND-PROGRAM
end-if
exit.
*****************************************************************
* The following Z-ROUTINES provide administrative functions *
* for this program. *
*****************************************************************
*
*****************************************************************
* ABEND the program, post a message to the console and issue *
* a STOP RUN. *
*****************************************************************
Z-ABEND-PROGRAM.
if MESSAGE-TEXT not = SPACES
perform Z-DISPLAY-MESSAGE-TEXT
end-if
move 'PROGRAM-IS-ABENDING...' to MESSAGE-TEXT
perform Z-DISPLAY-MESSAGE-TEXT
add 12 to ZERO giving RETURN-CODE
STOP RUN
exit.
*****************************************************************
* Display CONSOLE messages... *
*****************************************************************
Z-DISPLAY-MESSAGE-TEXT.
display MESSAGE-BUFFER upon console
move all SPACES to MESSAGE-TEXT
exit.
*****************************************************************
* Display the file status bytes. This routine will display as *
* four digits. If the full two byte file status is numeric it *
* will display as 00nn. If the 1st byte is a numeric nine (9) *
* the second byte will be treated as a binary number and will *
* display as 9nnn. *
*****************************************************************
Z-DISPLAY-IO-STATUS.
if IO-STATUS not NUMERIC
or IO-STAT1 = '9'
subtract TWO-BYTES-BINARY from TWO-BYTES-BINARY
move IO-STAT2 to TWO-BYTES-RIGHT
add TWO-BYTES-BINARY to ZERO giving IO-STATUS-4
move IO-STAT1 to IO-STATUS-4A(1:1)
move 'File Status is: nnnn' to MESSAGE-TEXT
move IO-STATUS-4A to MESSAGE-TEXT(17:4)
perform Z-DISPLAY-MESSAGE-TEXT
else
move '0000' to IO-STATUS-4A
move IO-STATUS to IO-STATUS-4A(3:2)
move 'File Status is: nnnn' to MESSAGE-TEXT
move IO-STATUS-4A to MESSAGE-TEXT(17:4)
perform Z-DISPLAY-MESSAGE-TEXT
end-if
exit.
*****************************************************************
Z-POST-COPYRIGHT.
display SIM-TITLE upon console
display SIM-COPYRIGHT upon console
exit.
*****************************************************************
Z-THANK-YOU.
display SIM-THANKS-01 upon console
display SIM-THANKS-02 upon console
exit.
*****************************************************************
* This program was generated by SimoZAPS *
* A product of SimoTime Enterprises *
* Our e-mail address is: helpdesk@simotime.com *
* Also, visit our Web Site at http://www.simotime.com *
* *
* Generation Date: 2003-04-08 Generation Time: 10:46:30:63 *
*****************************************************************
The following (CUSTTXB1.CPY) is the record layout of the column-oriented, fixed-field-length, Customer Master file.
01 CUSTTEXT-RECORD.
05 CUSTTEXT-KEY PIC X(12).
05 FILLER PIC X.
05 CUSTTEXT-LAST-NAME PIC X(28).
05 CUSTTEXT-FIRST-NAME PIC X(20).
05 CUSTTEXT-STREET-ADDRESS PIC X(48).
05 CUSTTEXT-CITY PIC X(16).
05 CUSTTEXT-STATE PIC X(2).
05 FILLER PIC X(385).
The purpose of this program is to provide examples for accessing a column-oriented, fixed-field-length Sequential file and creating a new comma-delimited, sequential file containing variable-length strings.
Permission to use, copy, modify and distribute this software for any commercial purpose requires a fee to be paid to SimoTime Enterprises. Once the fee is received by SimoTime the latest version of the software will be delivered and a license will be granted for use within an enterprise, provided the SimoTime copyright notice appear on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Enterprises.
Permission to use, copy, modify and distribute this software for a non-commercial purpose and without fee is hereby granted, provided the SimoTime copyright notice appear on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Enterprises.
SimoTime Enterprises makes no warranty or representations about the suitability of the software for any purpose. It is provided "AS IS" without any express or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. SimoTime Enterprises shall not be liable for any direct, indirect, special or consequential damages resulting from the loss of use, data or projects, whether in an action of contract or tort, arising out of or in connection with the use or performance of this software.
You may download this example at http://www.simotime.com/sim4dzip.htm#COBOLCommaDelimitedFileCreateNew or view the complete list of SimoTime Examples at http://www.simotime.com/sim4dzip.htm.
Note: You must be attached to the Internet to download a Z-Pack or view the list.
An example of how to Read and Parse an Existing Comma-Delimited file is provided.
The hexadecimal dump of the parameter-buffer uses the same technique as describe in another SimoTime example that describes the dumping of a data string using COBOL. The name of the member that does the actual hexadecimal dump is called SimoDUMP. A copy file (PASSDUMP.CPY) is provided for defining the pass area.
The SimoZAPS Utility Program has the capability of generating a COBOL program that will do the conversion of sequential and VSAM (KSDS) files between EBCDIC and ASCII. SimoZAPS can also read a sequential file in EBCDIC format and create an ASCII/CRLF file or VSAM KSDS file in ASCII format. The conversion tables may be viewed or modified to meet unique requirements. The Hexcess/2 function provides the capability of viewing, finding or patching the contents of a file in hexadecimal.
This item will provide a link to an ASCII or EBCDIC translation table. A column for decimal, hexadecimal and binary is also included.
Check out The VSAM - QSAM Connection for more examples of mainframe VSAM and QSAM accessing techniques and sample code.
This document provides a quick summary of the File Status Key for VSAM data sets and QSAM files.
Check out The SimoTime Library for a wide range of topics for Programmers, Project Managers and Software Developers.
To review all the information available on this site start at The SimoTime Home Page .
Check out The SimoTime Glossary for a list of terms and definitions used in the documents provided by SimoTime.
If you have any questions, suggestions or comments please call or send an e-mail to: helpdesk@simotime.com
We appreciate your comments and feedback.
Founded in 1987, SimoTime Enterprises is a privately owned company. We specialize in the creation and deployment of business applications using new or existing technologies and services. We have a team of individuals that understand the broad range of technologies being used in today's environments. This includes the smallest thin client using the Internet and the very large mainframe systems. There is more to making the Internet work for your company's business than just having a nice looking WEB site. It is about combining the latest technologies and existing technologies with practical business experience. It's about the business of doing business and looking good in the process. Quite often, to reach larger markets or provide a higher level of service to existing customers it requires the newer Internet technologies to work in a complementary manner with existing corporate mainframe systems. Whether you want to use the Internet to expand into new market segments or as a delivery vehicle for existing business functions simply give us a call or check the web site at http://www.simotime.com
| Return-to-Top |
| Copyright © 1987-2010 SimoTime Enterprises All Rights Reserved |
| When technology complements business |
| http://www.simotime.com |