Thursday 25 July 2013

JULY 25


Studied Data conversion during move statements and effect on length adjustment and the various rules of conversion with an example program.

Data Conversions:

If two variables have different data types or lengths, the data is converted when it is moved. This is called an automatic adjustment. If the lengths of the sending and receiving variables do not match, an automatic lengthadjustment is performed. If the data types do not match, an automatic type adjustment is performed.
If the data types of the sending and receiving fields are the same but the lengths differ, a length adjustment is performed . The effect is shown in the table below where the sending field is the "From" field.

Effect of Length Adjustment Varies with the Data Type

Type
When assigning to a longer field, the 'from' value is:When assigning to a shorter field, the 'from' value is:
c
Right-padded with blanksRight-truncated
x
Right-padded with zerosRight-truncated
n
Left-padded with zerosLeft-truncated
p
Left-padded with zerosAssigned if the numeric value will fit in the 'to' field.
 
If the numeric value is too large for the receiving field, a short dump occurs.

The remaining data types (fid, and t) are all of a fixed length, so the sending and receiving fields will always be the same length if they are of the same data type.
Points to notice are:
  • The peculiar compression performed for type c to n.
  • The capability to assign invalid values to types d and t.
  • The odd treatment of invalid characters during conversion of type c to x.
  • The unexpected usage of the reserved sign byte in p to c conversions.
  • The use of * to indicate overflow in p to c conversions.
  • An entirely blank c field is converted to a p field having a zero value.
Rules for type adjustments are provided in Table below. The conversion rules for type i are the same as for type p. Included are conversions with unusual behaviors.
Rules for Type Adjustments

From Type
To Type
Conversion Rules
c
p
The sending field can only contain numbers, a single decimal point, and an optional sign. The sign can be leading or trailing. Blanks can appear on either side of the value. It is right-justified and padded on the left with zeros. An entirely blank sending field is converted to zero.
c
d
The sending field should contain only a valid date in the format YYYYMMDD. If it does not, an error does not occur; instead, an invalid value is assigned to the receiving field. The results of using this value are undefined.
c
t
The sending field should only have a valid time in the format HHMMSS. If it does not, an error does not occur; instead, an invalid value is assigned to the receiving field. The results of using this value are undefined.
c
n
The sending field is scanned from left to right and only the digits 0-9 are transferred to the receiving field (right-justified) and padded on the left with zeros. All other characters are simply ignored.
c
x
Valid values for the sending field are 0-9 and capital letters A-F. The value is left-justified and padded on the right with zeros or truncated on the right. All characters after the first invalid value in the sending field are ignored.
p
c
The value is right-justified in the receiving field with the right-most byte reserved for a trailing sign. The sign is only displayed if the number is negative; therefore, positive numbers will be right-justified with a single trailing blank. In the event you try to move a positive value that contains as many digits as the receiving field is long, the system will use the entire length of the receiving field to contain the value without reserving the right-most byte for the sign. After considering the above, if the value in the sending field will not fit the receiving field, the number is truncated on the left. If truncation has occurred, the system indicates this by replacing the left-most digit with an asterisk (*). If the value does fit in the receiving field, leading zeros are suppressed. If the sending field is equal to zero, the receiving field receives a single zero.
p
d
The number is interpreted as the number of days since 0001/01/01, converted to a date, and stored internally in YYYYMMDD format.
p
t
The number is interpreted as the number of seconds since midnight, converted to 24-hour clock time, and stored internally in HHMMSS format.
d
p
The date is converted to a number representing the number of days since 0001/01/01.
t
p
The time is converted to a number representing the number of seconds since midnight.



Example below contains a demonstration program that performs sample data conversions.
EXAMPLE:
 1 report ztx0906.
 2 constants >(3) value '==>'.      "defines a constant named '>'
 3 data: fc(10)  type c value '-A1B2C3.4',
 4       fn(10)  type n,
 5       fp      type p,
 6       fd      type d,
7       ft      type t,
 8       fx(4)   type x,
 9       fc1(5)  type c value '-1234',
10       fc2(5)  type c value '1234-',
 11       fp1     type p value 123456789,
12       fp2     type p value '123456789-',
13       fp3     type p value 1234567899,
14       fp4     type p value 12345678901,
15       fp5     type p value 12345,
16       fp6     type p value 0.
17
18 fn = fc.       write: / fc, >, fn, 'non-numeric chars are ignored'.
19 fd = 'ABCDE'.  write: / fd, 'date and time fields are invalid'.
20 ft = 'ABCDE'.  write: / ft, '  when you load them with junk'.
21 fp = sy-datum. write: / sy-datum, >, fp, 'd->p: days since 0001/01/01'.
22 fp = sy-uzeit. write: / sy-uzeit, >, fp, 'd->t: secs since midnight'.
23 fx = 'A4 B4'.  write: / 'A4 B4', >, fx, 'ignore all after invalid char'.
24 fp = fc1.      write: / fc1, >, fp, 'allows leading sign'.
25 fp = fc2.      write: / fc2, >, fp, 'also allows trailing sign'.
26 fc = fp1.      write: / fp1, >, fc, 'rightmost byte reserved for sign'.
27 fc = fp2.      write: / fp2, >, fc, 'only negative numbers use it, but'.
28 fc = fp3.      write: / fp3, >, fc, '+ve nums that need it use it too'.
29 fc = fp4.      write: / fp4, >, fc, 'overflow indicated by leading *'.
30 fc = fp5.      write: / fp5, >, fc, 'leading zeros are suppressed'.
31 fc = fp6.      write: / fp6, >, fc, 'zero in = zero out'.
32 fp = ' '.      write: / ' ', >, fp, 'blanks in = zero out'.
OUTPUT:
-A1B2C3.4  ==> 0000001234 non-numeric chars are ignored
E   ABCD date and time fields are invalid
ABCDE0   when you load them with junk
1998/02/22 ==>         729,443  d->p: days since 0001/01/01
14:57:05 ==>          53,825  d->t: secs since midnight
A4 B4 ==> A4000000 ignore all after invalid char
-1234 ==>           1,234- allows leading sign
1234- ==>           1,234- also allows trailing sign
    123,456,789  ==> 123456789  rightmost byte reserved for sign
    123,456,789- ==> 123456789- only negative numbers use it, but
  1,234,567,899  ==> 1234567899 +ve nums that need it use it too
 12,345,678,901  ==> *345678901 overflow indicated by leading *
         12,345  ==>     12345  leading zeros are suppressed
              0  ==>         0  zero in = zero out
  ==>               0  blanks in = zero out