Em Português - In Portuguese |
COBOL usa números de nível de 01 a 49 para definir uma estrutura de dados em uma hierarquia de partes constituintes - quanto maior o número do nível,
menor o item na hierarquia.
Os próprios números normalmente não têm nenhum significado especial, mas a relação dos números de nível entre si identifica os níveis dentro da hierarquia.
No entanto, ao codificar áreas de dados para uso com SQL, o Nível Número 49 tem um significado especial.
49 é usado para declarar identificadores de itens elementares de comprimento variável - tipicamente variáveis VARCHAR, LONG VARCHAR, VARGRAPHIC e
LONG VARGRAPHIC.
Quando o Nível 49 é usado, o grupo contém um campo Comprimento de 2 bytes seguido pelo nome do campo real (definido como PIC X(##) com ## sendo o
comprimento máximo).
Os dados do campo variam em seu comprimento e quando os dados são colocados no campo, apenas o número de caracteres definido no item de comprimento é
retornado, sem caracteres de preenchimento.
Isso pode causar um problema, pois as informações anteriores armazenadas nesse campo não são apagadas automaticamente e o valor anterior era maior que o
valor atual.
Quando os dados são recuperados, o comprimento e o item de dados são preenchidos.
Um comprimento de 0 indica que a coluna não está preenchida.
Aqui está um exemplo de uso do Nível 49:
----+---10----+---20----+---30----+---40----+---50----+
01 COLUMN-NAME.
49 COLUMN-NAME-LEN PIC S9(04) USAGE COMP.
49 COLUMN-NAME-DATA PIC X(273).
|
Aqui está uma explicação deste layout:
- Column-name é o nome da coluna SQL
- Column-name-len é um campo inteiro de 1-4 que contém o comprimento dos dados em Column-name.
- Column-name-data contêm os dados reais e a cláusula PIC indica o maior valor de variável que pode ser atribuído a essa variável.
COBOL uses level numbers 01 through 49 to define a data structure into a hierarchy of constituent parts - the higher the level
number, the lower the item is in the hierarchy.
The numbers themselves do not typically have any special significance, but the relationship of the level numbers to each other identifies the levels within
the hierarchy.
However, when coding data areas for use with SQL, Level Number 49 has a special significance.
49 is used to declare elementary item identifiers of variable length - typically VARCHAR, LONG VARCHAR, VARGRAPHIC, and LONG VARGRAPHIC variables.
When Level 49 is used, the group contains a 2 byte Length field followed by the actual field name (defined as PIC X(##) with ## being the maximum length).
The field data will vary in its length and when data is placed into the field, only the number of characters defined in the length item is returned, with
no pad characters.
This has the potential to cause a problem since the previous information stored in this field is not automatically cleared and the previous value was
longer than the current value.
When the data is retrieved, both the length and data item are populated.
A length of 0 indicates that the column is not populated.
Here is a sample use of the Level 49:
----+---10----+---20----+---30----+---40----+---50----+
01 COLUMN-NAME.
49 COLUMN-NAME-LEN PIC S9(04) USAGE COMP.
49 COLUMN-NAME-DATA PIC X(273).
|
Here is an explanation of this layout:
- Column-name is the name of the SQL column
- Column-name-len is a 1-4 integer field that holds the length of the data in Column-name.
- Column-name-data holds the actual data, and the PIC clause indicates the largest variable value that can be assigned to
this variable.
Exemplo de DCLGEN com nível 49 - DCLGEN example with level 49
******************************************************************
* DCLGEN TABLE(MYTABLE) *
* LIBRARY('prefix.SRCLIB.DATA(MYTABLE)) *
* LANGUAGE(COBOL) *
* APOST *
* DCLBIT(YES) *
* ... IS THE DCLGEN COMMAND THAT MADE THE FOLLOWING STATEMENTS *
******************************************************************
EXEC SQL DECLARE MYTABLE TABLE
( COL1 CHAR(10) NOT NULL,
COL2 CHAR(10),
COL3 VARCHAR(12) NOT NULL,
COL4 VARCHAR(12) NOT NULL
) END-EXEC.
******************************************************************
* DECLARED VARIABLES FOR 'FOR BIT DATA' COLUMNS *
******************************************************************
EXEC SQL DECLARE
:COL3
,:COL4
VARIABLE FOR BIT DATA END-EXEC.
******************************************************************
* COBOL DECLARATION FOR TABLE MYTABLE *
******************************************************************
01 DCLMYTABLE.
10 COL1 PIC X(10).
10 COL2 PIC X(10).
10 COL3.
49 COL3-LEN PIC S9(4) USAGE COMP.
49 COL3-TEXT PIC X(12).
10 COL4.
49 COL4-LEN PIC S9(4) USAGE COMP.
49 COL4-TEXT PIC X(12).
******************************************************************
* THE NUMBER OF COLUMNS DESCRIBED BY THIS DECLARATION IS 4 *
******************************************************************
|
|