lunes, 4 de abril de 2011

Codigos File Status Cobol/400 (FILE STATUS VALUES)

El codigo File Status nos indica lo que pasa cada vez que operamos con un archivo. Ya sea a la hora de leer, grabar, eliminar o actualizar un registro.
Te recomiendo que si detectas errores al hacer cualquiera de las 4 operaciones anteriores primero verifiques el file status en el momento de hacer el OPEN.

El valor de cada codigo File Status lo conforman 2 caracteres que tiene un significado propio.

Aquí les dejo los valores de código File Status que maneja el Cobol400. Esto lo encontramos en los manuales on-line de IBM. Está en ingles pero como buenos programadores ya estamos familiarizados con este idioma.

COBOL/400 Reference

Left-MeaningRight-Meaning
most Charactermost Character
0Successful Completion0No further information
2The READ statement was successfully executed, but a duplicate key was detected. That is, the key value for the current key of reference was equal to the value of the key in the next record. For information about enabling file status 02 see Table 44 in topic 8.29.6 and the accompanying notes under the READ statement.
4A READ statement was successfully executed, but the length of the record being processed did not conform to the fixed file attributes for that file.
5An OPEN statement is successfully executed, but the referenced optional file is not present at the time the OPEN statement is executed. If the open mode is I-O or EXTEND, the file has been created.
7For a CLOSE statement with the NO REWIND, REEL/UNIT, or FOR REMOVAL phrase or for an OPEN statement with the NO REWIND phrase, the referenced file was on a non-reel/unit medium.
MLast record written to a subfile.CPF5003
PThe file has been opened successfully, but it contains null-capable fields.
QA CLOSE statement for a sequentially-processed relative file was successfully executed. The file was created with the*INZDLT and *NOMAX options, so its boundary has been set to the number of records written. 
1At end conditions0END OF FILE.  A sequential READ statement was attempted and no next logical record existed in the file because the end of the file has been reached (no invites outstanding) CPF4740, CPF5001, CPF5025.  
2No modified subfile record found. CPF5037
4A sequential READ statement was attempted for a relative file and the number of significant digits in the relative record number was larger than the size of the relative key data item described for the file. 
 2Invalid Key1A sequence error exists for a sequentially accessed indexed file. The prime record key value has been changed by the program between the successful execution of a READ statement and the execution of the next REWRITE statement for that file, or the ascending requirements for successive record key values were violated. Alternatively, the program has changed the record key value between a successful READ and subsequent REWRITE or DELETE operation on a randomly or dynamically-accessed file with duplicate keys.
2DUPLICATE KEY.  An attempt was made to write a record that would create a duplicate key in a relative file; or an attempt was made to write or rewrite a record that would create a duplicate prime record key in an indexed file. CPF4759, CPF5008, CPF5026, CPF5034, CPF5084, CPF5085.
3RECORD NOT FOUND.  An attempt was made to randomly access a record that does not exist in the file. CPF5001, CPF5006, CPF5013, CPF5020, CPF5025. 
4An attempt was made to write beyond the externally defined boundaries of a relative or indexed file. Or, a sequential WRITE statement was attempted for a relative file and the number of significant digits in the relative record number was larger than the size of the relative record key data item described for the file. CPF5006, CPF5018, CPF5021, CPF5043, CPF5272.
3Permanent error condition0No further information CPF4192, CPF5101, CPF5102, CPF5129, CPF5030, CPF5143.
4A permanent error exists because of a boundary violation; an attempt was made to write beyond the externally-defined boundaries of a sequential file. CPF5116, CPF5018, CPF5272 if organization is sequential.
FILE NOT FOUND.  An OPEN statement with the INPUT, I-O, or EXTEND phrase was attempted on a non-optional file that was not present. CPF4101, CPF4102, CPF4103, CPF4207, CPF9812. 
7An OPEN statement was attempted on a file that would not support the open mode specified in the OPEN statement. Possible violations are: 1. The EXTEND or OUTPUT phrase was specified but the file would not support writeoperations.2. The I-O phrase was specified but the file would not support the input and output operations permitted.3. The INPUT phrase was specified but the file would not support read operations. CPF4194.
8An OPEN statement was attempted on a file previously closed with lock.
9 The OPEN statement was unsuccessful because a conflict was detected between the fixed file attributes and the attributes specified for that file in the program. Level check error. CPF4131. 
4Logic error condition 1FILE ALREADY OPEN. An OPEN statement was attempted for a file in the open mode.
FILE ALREADY CLOSED.  A CLOSE statement was attempted for a file not in the open mode. 
3For a sequential file in the sequential access mode, the last input-output statement executed for the associated file prior to the execution of a REWRITE statement was not a successfully executed READ statement. For relative and indexed files in the sequential access mode, the last input-output statement executed for the file prior to the execution of a DELETE or REWRITE statement was not a successfully executed READ statement.
4A boundary violation exists because an attempt was made to rewrite a record to a file and the record was not the same size as the record being replaced.
6A sequential READ statement was attempted on a file open in the input or I-O mode and no valid next record had been established because the preceding START statement was unsuccessful, or the preceding READ statement was unsuccessful or caused an at endcondition.CPF5001, CPF5025, CPF5183.
7The execution of a READ or START statement was attempted on a file not open in the input or I-O mode. 
The execution of a WRITE statement was attempted on a sequential file not open in the output, or extend mode. The execution of a WRITE statement was attempted on an indexed or relative file not open in the I-O, output, or extend mode. 
9The execution of a DELETE or REWRITE statement was attempted on a file not open in the I-O mode.
9Other Errors 0° File not found° Member not found° Unexpected I-O exceptions CPF4101, CPF4102, CPF4103 if a USE is applicable for the file (on OPEN OUTPUT, non-optional file). The following exceptions are monitored generically: CPF4101 through CPF4399 CPF4501 through CPF4699 CPF4701 through CPF4899 CPF4901 through CPF4999 CPF5001 through CPF5099 CPF5101 through CPF5399 CPF5501 through CPF5699 These exceptions are caught, and FILE STATUS is set to 90. With Standard Error Handling: If there is an applicable file status clause (but not an applicable USE procedure), the file status is updated, and control returns to the program. In the absence of a file status clause, USE procedure, AT END clause, or INVALID KEY clause to handle the error, a run-time message is issued, giving you the option to end or return to the program. Without Standard Error Handling: If a USE procedure applies, it runs. Otherwise, the program ends and gives the operator the exception and the option to cancel, take a partial dump, or take a full dump. 
1Undefined or unauthorized access type CPF2207, CPF4104, CPF4236,CPF5057, CPF5109, CPF5134,CPF5279. 
2° File locked° File already open° I-O to closed file° READ after end of file° CLOSE on unopened file CPF4106, CPF4132, CPF4740,CPF5013, CPF5067, CPF5070,CPF5119, CPF5145, CPF5146,CPF5149, CPF5176, CPF5209.
4No file position indicator REWRITE/DELETE when not sequential access, and last operation was not a successful READ. 
5Invalid or incomplete file information. The file has been successfully opened, but (1) duplicate keys specified in COBOL program, and indexed database file created with unique key; or (2) Duplicate keys not specified in COBOL program, and indexed database file created allowing duplicate keys.
9 Undefined (display or ICF).
AJob ended in a controlled manner by CL command ENDJOB, PWRDWNSYS, ENDSYS, or ENDSBS CPF4741. Escape message sent during an accept input operation, READ from invited program device (multiple device listings only).
CAcquire failed; session was not started.
DRecord is lockedCPF5027, CPF5032.
GOutput exception to device or session.
HACQUIRE operation failed. Resource owned by another program, or unavailable. (9H is the result when an ACQUIRE operation causes any of the OS/400 exceptions monitored for 90, or 9N to occur.) 
WRITE operation failedCPF4702, CPF4737, CPF5052,CPF5076. 
K Invalid format-name; format not found CPF5022, CPF5023, CPF5053,CPF5054, CPF5121, CPF5152,CPF5153, CPF5186, CPF5187.
MLast record written to subfile.CPF5003. To convert file status 9M to 0M,use PROCESS statement optionFS9MTO0M.
NTemporary (potentially recoverable) hardware I-O error. (Error during communication session.)  Possible cause: Attempting to write bad data to a display file.  CPF4145, CPF4146, CPF4193,CPF4229, CPF4291, CPF4299,CPF4354, CPF4526, CPF4542,CPF4577, CPF4592, CPF4602,CPF4603, CPF4611, CPF4612,CPF4616, CPF4617, CPF4622,CPF4623, CPF4624, CPF4625,CPF4628, CPF4629, CPF4630,CPF4631, CPF4632, CPF4705,CPF5107, CPF5128, CPF5166,CPF5198, CPF5280, CPF5282,CPF5287, CPF5293, CPF5352,CPF5353, CPF5517, CPF5524,CPF5529, CPF5530, CPF5532,CPF5533.
POPEN failed because file cannot be placed under commitment control CPF4293, CPF4326, CPF4327,CPF4328, CPF4329.
QAn OPEN statement for a randomly-or dynamically-accessed relative file failed because its size was*NOMAX. Change the file size (for example, using CHGPF) to the size you expect, and submit the program again.
SREWRITE or DELETE failed because last READ operation specified NO LOCK.
UCannot complete READ PRIOR because records are left in block from READ NEXT, or vice versa.CPF5184. Close the file, then open it again.

viernes, 1 de abril de 2011

Convertir Fecha Juliana en SQL/400 (Convertir a Formato Gregoriano, ISO, EUR)

FECHA_JUL es variable de archivo de tipo NUMERICO de 7 posiciones (7,0)

· YYYYDDD a Formato DD/MM/YY                                            
                                                                  
            DATE(CHAR (FECHA_JUL))
                                                                  
· YYYYDDD a Formato DD.MM.YYYY (EUR)                                    

CHAR(DATE(CHAR (FECHA_JUL)), EUR)

· YYYYDDD a Formato YYYY-MM-DD (ISO)                                     

CHAR(DATE(CHAR (FECHA_JUL)), ISO)


                                                                 
==> SELECT TASA, FEC_JUL, DATE(CHAR( FEC_JUL)) AS GREGORIANO,   
CHAR(DATE(CHAR(FEC_JUL)), ISO) AS FORMATO_ISO,              
CHAR(DATE(CHAR(FEC_JUL)), EUR) AS FORMATO_EUR               
FROM MILIBRERIA/FECHAS