Natural Data Type

I have a few questions

  1. Why does an integer only takes 1, 2 or 4 bytes and not 3 bytes? And how is it different from Numeric data type N?
  2. What is the maximum size (in bytes) for Alphanumeric variable in Nat 4.2.7?
  3. What is the maximum possible index for an elementary array?
  4. What is maximum possible size in bytes for Dynamic variable?
  5. What is the possible max. rec length that a NAT program can write in WORK FILE?

Thanks, Looking for a speedy help!

For question 1 see output below:

DEFINE DATA LOCAL
1 #INTEGER (I4) INIT <123456>
1 #UNPACKED-DECIMAL (N6) INIT <123456>
1 #PACKED-DECIMAL (P6) INIT <123456>
END-DEFINE
*
INCLUDE AASETC
WRITE 5T ‘=’ #INTEGER #INTEGER (EM=HH) /
5T ‘=’ #UNPACKED-DECIMAL #UNPACKED-DECIMAL (EM=HHHHHH) /
5T ‘=’ #PACKED-DECIMAL #PACKED-DECIMAL (EM=HHHH)
END
Page 1 13-02-24 06:34:21

#INTEGER:      123456 40E2
#UNPACKED-DECIMAL:  123456 313233343536
#PACKED-DECIMAL:  123456 0123456C

An integer variable is basically a binary field. Expand 40E2 into binary and add up the powers of two, you will get 123456. N format uses one byte per position. Since I ran this on a PC, the prefix for each digit is 3.
Packed decimal stores two digits in a byte, and has a sign indicator in the low order half byte.

For information on any older version of Natural, start at http://techcommunity.softwareag.com/ecosystem/documentation/
Select “Natural”
Select from the list of mainframes, open systems, etc.
Select 4.2.7 and language from the list.

steve

  1. Because I3 is not supported by the hardware. IBM’s architecture defines integers as half-word and full-word.

2-4. You can define a data structure of up to 1 gigabyte.

Well, actually no hardware / language (I know of) supports an I3 “datatype”, C datatypes are byte (I1) short (I2) and int (I4) respectively, for example.

Plus IBM hardware can’t deal with an I1 in math operations directly.

I have a variable #Bin (B4) and holds the value 31738, how to convert thi s value into a Numeric field?

A simple ASSIGN should do it.

DEFINE DATA LOCAL
1 #B (B4) INIT <31738>
1 #I (I4)
1 #N (N10)
1 #P (P10)
END-DEFINE
ASSIGN #I = #B
ASSIGN #N = #B
ASSIGN #P = #B
WRITE #B
    / #I
    / #N
    / #P
END
Page     1                                                   17-03-13 11:27:23

00007BFA
      31738
      31738
      31738

But you might run into trouble if the value goes beyond 2147483647 (H’7FFFFFFF’), because #B is unsigned.

Page     1                                                   17-03-13 11:33:17

80000000
-2147483648
-2147483648
-2147483648

Thanks Ralph for the Reply

I am confused:) In your example Numeric field is holding same value as the Input Binary value.

Let me put my question more elobrate

I have an adastrip extract that includes the ISN of the record. ISN has been extracted into the output as B4. Now I need to use this ISN to read the record in the file and do some actions.
My extract has ISN has 31738, but in the file the ISN seems to be different it is 202552 and the format of ISN in the peek is N10.

How can we get 202552(N10) from 31738(B4)?

When you display the contents of a B-format field, you see the hexadecimal value. I thought that you were providing the decimal value of #BIN.

Try this:

DEFINE DATA LOCAL  
1 #B (B4) INIT <H'00031738'>
1 #I (I4)  
1 #N (N10)  
1 #P (P10)  
END-DEFINE  
ASSIGN #I = #B  
ASSIGN #N = #B  
ASSIGN #P = #B  
WRITE #B  
    / #I  
    / #N  
    / #P  
END

You will see that hex 31738 translates to decimal 202552.

Page     1                                                   03/13/17  12:43:31
 
00031738
     202552
     202552
     202552

PEEK translates from I4 to N10 for readability. On the mainframe you don’t need to execute an ASSIGN to convert the field, just define (or REDEFINE) it as I4.

Thanks Ralph for the suggestion!