Lubna
Lubna

Reputation: 5

Char value to decimal data type in RPGLE

Why when I send a char(CL) value to a decimal data type is converted to (-33)? I wrote (move 'CL' NmOfField) and NmOfField is a decimal data type, so I found the value on NmOfField is (-33) I want to know why (-33) specifically?

Upvotes: 0

Views: 525

Answers (1)

nfgl
nfgl

Reputation: 3212

It has to do with the fact that hex representation of 'CL' is X'C3D3' and the fact that NmOfField is a packed decimal type.

Say it's a packed(3:0) and it's value before move is 0. Each pair nibble in 'CL' becomes a digits, so the absolute value is 33, the second to last nibble is considered sign, and in packed decimal D is minus so hexadecimal representation of NmOfField is X'033D' and the numeric value is -33. If NmOfField value had been +123 (X'123F') before move, it would have been -133 after (X'133D') as 'CL' is only two characters long (move works right to left til there is no more room in the result, or no more char in factor 2). If one of the digit nibble had not been a decimal digit, a error would have been raised.

You should avoid using move* operators because of that kind of suprises and some other, and prefer free-form syntax listed here

Upvotes: 2

Related Questions