Cobol Foro

Cobol Foro (https://www.cobolforo.es/index.php)
-   COBOL - General (https://www.cobolforo.es/forumdisplay.php?f=44)
-   -   [Sintaxis] Equivalencia de formato de campos numéricos (https://www.cobolforo.es/showthread.php?t=317)

Galileo 28 de enero de 2016 18:55

Equivalencia de formato de campos numéricos
 
Hola.

Hace un tiempo, en mis añorados foros de ESCOBOL alguien publicó una gran aportación: la equivalencia de los campos numéricos BYTE, SINGLE, DOUBLE, INTEGER, LONG, etc. en COBOL. Si alguien tuvo la precaución de guardar esta información o sabe donde puedo encontrarla, estoy interesado en conseguirla.

Un saludo.

---------- Post añadido : 18:55 ---------- Post anterior : 18:09 ----------

Vale, yo mismo me respondo. Debería de haber consultado primero en Internet. Mea culpa.

En la página http://documentation.microfocus.com/...BBD971DA4.html he encontrado una tabla de conversión.

En el sitio de Microsoft, esta es la información que se puede encontrar:

Supported COBOL Data Types

COMP-1
A 4-byte, single precision, floating-point Real data type that specifies internal floating-point items. The sign is contained in the first bit of the leftmost byte, and the exponent is contained in the remaining seven bits of that byte. The remaining three bytes hold the mantissa.
COMP-2
An 8-byte, double precision, floating-point Real data type that specifies internal floating-point items. The sign is contained in the first bit of the leftmost byte, and the exponent is contained in the remaining seven bits of the first byte. The remaining seven bytes hold the mantissa.
COMP-3 Packed Decimal
A packed decimal data type that specifies internal decimal items stored in packed decimal format. In the packed decimal format, each byte in a field represents two numeric digits except for the rightmost byte. The rightmost byte holds one digit and the sign. In other words, there are two digits in each character position except for the trailing character position that is occupied by the low-order digit and sign. The item can contain any of the digits from 0 through 9, plus a sign, to represent a value not exceeding 18 decimal digits. For example, the decimal value +123 is represented in two bytes as 0001 0010 0011 1100 in packed decimal format. For more information see, Zoned Decimal or Packed Decimal Data Types.
DISPLAY Zoned Decimal
An unpacked decimal data type that specifies internal decimal items stored in zoned decimal format. Zoned decimal format is synonymous with unpacked decimal format, which is a format for representing numbers where each digit is contained in bits 4 through 7 and the sign is contained in bits 0 through 3 of the least significant byte. Bits 0 through 3 of all bytes other than the least significant byte contain 1s (hex F). For example, the decimal value +123 is represented in three bytes as 1111 0001 1111 0010 1100 0011 in zoned decimal format. For more information see, Zoned Decimal or Packed Decimal Data Types.
DATE and TIME
Specifies a date and time by using group item of two PIC 9(7) COMP-3 Packed Decimal value.
TIME only
Specifies a time by using a PIC 9(7) COMP-3 Packed Decimal value.
DATE only
Specifies a date by using a PIC 9(7) COMP-3 Packed Decimal value.
PIC X
Specifies a single character in an Extended Binary Coded Decimal Interchange Code (EBCDIC) character string. EBCDIC is the native representation for character data on mainframes and AS/400s. Unicode is the native representation for character data on Windows-based platforms.
PIC X No Translation
Specifies a single COBOL character in an EBCDIC character string that is handled as if it were binary data. In other words, there is no translation from EBCDIC to Unicode or from Unicode to EBCDIC.
PIC G
Specifies a double-byte EBCDIC string.
PIC S9(4) COMP (Integer 16-bit)
Specifies an integer that is 16 bits, or 2 bytes, in length.
PIC S9(9) COMP (Integer 32-bit)
Specifies an integer that is 32 bits, or 4 bytes, in length.

Kuk 29 de enero de 2016 09:19

A todo esto puedo añadir lo siguiente: COMP y COMP-4 equivalen y son campos binarios independientes de la máquina. Pero hay una diferencia entre los binarios COBOL y el binario "nativo" que es el COMP-5 y sí es dependiente de la máquina. A diferencia de binarios COBOL, el binario "nativo" puede contener cifras superiores al valor PIC.

Por ejemplo, un PIC S9(4) COMP puede contener de -9999 hasta 9999. Sin embargo PIC S9(4) COMP-5 puede contener de -32768 hasta 32767.

Para comunicarnos con el SO u otro software como rutinas C/C++ etc., normalmente se debe usar el binario nativo COMP-5.

Resumiendo:

Código COBOL:
  1. Tipo                COBOL              Tamaño   Valores posibles
  2. -----------------------------------------------------------------------------------------------------------
  3. SHORT               PIC S9(4) COMP-5   2 Bytes  De -32,768                    a 32,767
  4. USHORT              PIC  9(4) COMP-5   2 Bytes  De 0                          a 65,535
  5. INT                 PIC S9(9) COMP-5   4 Bytes  De -2,147,483,648             a 2,147,483,647
  6. UINT                PIC  9(9) COMP-5   4 Bytes  De 0                          a 4,294,967,295
  7. INT64               PIC S9(18) COMP-5  8 Bytes  De –9,223,372,036,854,775,808 a 9,223,372,036,854,775,807
  8. UINT64              PIC  9(18) COMP-5  8 Bytes  De 0                          a 18,446,744,073,709,551,615
  9. LONG  en Windows    INT                4 Bytes  De -2,147,483,648             a 2,147,483,647
  10. ULONG en Windows    UINT               4 Bytes  De 0                          a 4,294,967,295
  11. LONG  en Linux x64  PIC S9(18) COMP-5  8 Bytes  De –9,223,372,036,854,775,808 a 9,223,372,036,854,775,807
  12. ULONG en Linux x64  PIC  9(18) COMP-5  8 Bytes  De 0                          a 18,446,744,073,709,551,615
  13. FLOAT               COMP-1             4 Bytes  De 1.2E-38                    a 3.4E+38  
  14. DOUBLE              COMP-2             8 Bytes  De 2.3E-308                   a 1.7E+308
  15. *     en x86        POINTER            4 Bytes  De -2,147,483,648             a 2,147,483,647
  16. *     en x64        POINTER            8 Bytes  De –9,223,372,036,854,775,808 a 9,223,372,036,854,775,807


La franja horaria es GMT +2. Ahora son las 00:23.

Powered by: vBulletin, Versión 3.8.7
Derechos de Autor ©2000 - 2026, Jelsoft Enterprises Ltd.