CICS WRITE provides record writing capabilities in CICS environments. It enables programs to write records, manage file operations, and handle record writing for data storage and file management purposes.
123456789EXEC CICS WRITE [FILE(file-name)] [FROM(data-area)] [LENGTH(data-length)] [RIDFLD(record-id)] [KEYLENGTH(key-length)] [RESP(response-code)] [RESP2(response-code-2)] END-EXEC.
Specifies the name of the file to which the record will be written. This parameter identifies the target file for write operations.
Specifies the data area containing the record data to be written. This parameter provides the source data for write operations.
Specifies the length of the record data to be written. This parameter controls the amount of data written to the file.
Specifies the record identifier field containing the key of the record to be written. This parameter identifies the record for write operations.
Specifies the length of the key field used to identify the record. This parameter controls the key matching for record identification.
Specifies the response code variable to receive the operation result. This parameter provides error handling and status information.
Specifies the secondary response code variable for additional error information. This parameter provides extended error details when available.
WRITE creates new records in files, enabling programs to add new data to existing files for data expansion and growth.
The command supports key-based writing for creating records with specific key values and maintaining file organization.
Sequential writing enables creation of records in key order for maintaining sorted file structures and efficient data access.
Batch writing supports creation of multiple records efficiently in data loading and bulk insert operations.
123456789101112131415161718192021222324252627WORKING-STORAGE SECTION. 01 FILE-NAME PIC X(8) VALUE 'CUSTOMER'. 01 RECORD-DATA PIC X(100) VALUE 'Customer data here'. 01 DATA-LENGTH PIC S9(8) COMP VALUE 100. 01 RECORD-KEY PIC X(10) VALUE 'CUST001'. 01 KEY-LENGTH PIC S9(8) COMP VALUE 10. 01 RESPONSE-CODE PIC S9(8) COMP. 01 RESPONSE-CODE-2 PIC S9(8) COMP. PROCEDURE DIVISION. EXEC CICS WRITE FILE(FILE-NAME) FROM(RECORD-DATA) LENGTH(DATA-LENGTH) RIDFLD(RECORD-KEY) KEYLENGTH(KEY-LENGTH) RESP(RESPONSE-CODE) RESP2(RESPONSE-CODE-2) END-EXEC IF RESPONSE-CODE = 0 DISPLAY 'Record written successfully' DISPLAY 'File: ' FILE-NAME DISPLAY 'Key: ' RECORD-KEY ELSE DISPLAY 'Error writing record: ' RESPONSE-CODE END-IF.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465WORKING-STORAGE SECTION. 01 FILE-NAME PIC X(8) VALUE 'CUSTOMER'. 01 RECORD-DATA PIC X(100). 01 DATA-LENGTH PIC S9(8) COMP VALUE 100. 01 RECORD-KEY PIC X(10). 01 KEY-LENGTH PIC S9(8) COMP VALUE 10. 01 RESPONSE-CODE PIC S9(8) COMP. 01 RESPONSE-CODE-2 PIC S9(8) COMP. 01 WRITE-COUNT PIC S9(8) COMP VALUE 0. PROCEDURE DIVISION. PERFORM WRITE-CUSTOMER-001 PERFORM WRITE-CUSTOMER-002 PERFORM WRITE-CUSTOMER-003. WRITE-CUSTOMER-001. MOVE 'Customer 001 data' TO RECORD-DATA MOVE 'CUST001' TO RECORD-KEY EXEC CICS WRITE FILE(FILE-NAME) FROM(RECORD-DATA) LENGTH(DATA-LENGTH) RIDFLD(RECORD-KEY) KEYLENGTH(KEY-LENGTH) RESP(RESPONSE-CODE) RESP2(RESPONSE-CODE-2) END-EXEC IF RESPONSE-CODE = 0 ADD 1 TO WRITE-COUNT DISPLAY 'Customer 001 written' END-IF. WRITE-CUSTOMER-002. MOVE 'Customer 002 data' TO RECORD-DATA MOVE 'CUST002' TO RECORD-KEY EXEC CICS WRITE FILE(FILE-NAME) FROM(RECORD-DATA) LENGTH(DATA-LENGTH) RIDFLD(RECORD-KEY) KEYLENGTH(KEY-LENGTH) RESP(RESPONSE-CODE) RESP2(RESPONSE-CODE-2) END-EXEC IF RESPONSE-CODE = 0 ADD 1 TO WRITE-COUNT DISPLAY 'Customer 002 written' END-IF. WRITE-CUSTOMER-003. MOVE 'Customer 003 data' TO RECORD-DATA MOVE 'CUST003' TO RECORD-KEY EXEC CICS WRITE FILE(FILE-NAME) FROM(RECORD-DATA) LENGTH(DATA-LENGTH) RIDFLD(RECORD-KEY) KEYLENGTH(KEY-LENGTH) RESP(RESPONSE-CODE) RESP2(RESPONSE-CODE-2) END-EXEC IF RESPONSE-CODE = 0 ADD 1 TO WRITE-COUNT DISPLAY 'Customer 003 written' END-IF.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647WORKING-STORAGE SECTION. 01 FILE-NAME PIC X(8) VALUE 'CUSTOMER'. 01 RECORD-DATA PIC X(200). 01 DATA-LENGTH PIC S9(8) COMP. 01 RECORD-KEY PIC X(10). 01 KEY-LENGTH PIC S9(8) COMP VALUE 10. 01 RESPONSE-CODE PIC S9(8) COMP. 01 RESPONSE-CODE-2 PIC S9(8) COMP. 01 PROCESSING-COUNT PIC S9(8) COMP VALUE 0. PROCEDURE DIVISION. PERFORM VARYING PROCESSING-COUNT FROM 1 BY 1 UNTIL PROCESSING-COUNT > 5 PERFORM BUILD-RECORD-DATA PERFORM BUILD-RECORD-KEY PERFORM WRITE-RECORD END-PERFORM. BUILD-RECORD-DATA. STRING 'Customer ' DELIMITED BY SIZE PROCESSING-COUNT DELIMITED BY SIZE ' data created at ' DELIMITED BY SIZE FUNCTION CURRENT-DATE DELIMITED BY SIZE INTO RECORD-DATA. MOVE FUNCTION LENGTH(RECORD-DATA) TO DATA-LENGTH. BUILD-RECORD-KEY. STRING 'CUST' DELIMITED BY SIZE PROCESSING-COUNT DELIMITED BY SIZE INTO RECORD-KEY. WRITE-RECORD. EXEC CICS WRITE FILE(FILE-NAME) FROM(RECORD-DATA) LENGTH(DATA-LENGTH) RIDFLD(RECORD-KEY) KEYLENGTH(KEY-LENGTH) RESP(RESPONSE-CODE) RESP2(RESPONSE-CODE-2) END-EXEC IF RESPONSE-CODE = 0 DISPLAY 'Record ' RECORD-KEY ' written successfully' ELSE DISPLAY 'Error writing record ' RECORD-KEY ': ' RESPONSE-CODE END-IF.
Successful record writing. The record has been successfully written to the file.
Invalid file name. The specified file name is invalid or not supported.
Record already exists. A record with the specified key already exists in the file.
Invalid data length. The specified data length is invalid or exceeds maximum allowed length.
Write operation failed. The record writing operation failed due to system conditions.
WRITE efficiently creates records, but large write operations may impact system performance temporarily.
Proper file management ensures efficient write operations and prevents file corruption and resource issues.
Data validation ensures that write operations create valid records and maintain data integrity.
Always check response codes and handle errors appropriately, especially for record existence and data validation.
Validate record data before writing to ensure data integrity and prevent invalid records from being created.
Implement proper key management to ensure unique record identification and prevent duplicate key errors.
Optimize write operations by using appropriate data lengths and implementing efficient write strategies.
Imagine you have a notebook and you want to write something new in it. CICS WRITE is like writing a new page in your notebook with a specific title.
The file name is like the name of your notebook, the record data is like what you want to write on the page, and the record key is like the title of the page. When you write it, the new page is added to your notebook.
Just like you need to make sure you don't write the same title twice in your notebook, the program needs to make sure it doesn't create records with the same key.
Write a program that uses WRITE to create a new record with specific data and verify the writing was successful.
Create a program that writes multiple records with different keys and validates each write operation.
Implement a data writing system that dynamically creates records based on business data and requirements.