Reputation: 2527
... updating some old code and ran into interesting behavior of data structure containing signed and packed values:
D #SIGNED S 5S 0 INZ
D #PACKED S 5P 0 INZ
D*---
D #AS_1 DS
D #AS1 LIKE(#SIGNED) INZ
D #AS2 LIKE(#SIGNED) INZ
D #AS3 LIKE(#SIGNED) INZ
D #AP_1 DS
D #AP1 LIKE(#PACKED) INZ
D #AP2 LIKE(#PACKED) INZ
D #AP3 LIKE(#PACKED) INZ
C
C* for single signed, this is true
C #AS1 IFEQ *ZEROS
C EXSR MYSR
C ENDIF
C
C* for single packed, this is true
C #AP1 IFEQ *ZEROS
C EXSR MYSR
C ENDIF
C* for DS of signed, this is true
C #AS_1 IFEQ *ZEROS
C EXSR MYSR
C ENDIF
C
C* however for DS of packed, this is false
C #AP_1 IFEQ *ZEROS
C EXSR MYSR
C ENDIF
C
C Eval *INLR = *ON
C Return
*****************************************************************
C MYSR BEGSR
C ENDSR
I assume this is because of how packed is stored internally...
Upvotes: 0
Views: 646
Reputation: 23783
It's a combination of things...
A DS is just a collection of BYTES, since RPG doesn't have a BYTE type, it basically treats it as a collection SBCS characters.
*ZEROS is a Symbolic name that translate to a repeating x'F0' for the length of the compared/assigned to variable.
The character '0' is x'F0', the zoned decimal digit 0 is also 'F0'
A single-digit packed 0 is x'0F'
However,
zoned(5,0) is x'F0F0F0F0F0'
packed(5,0) is x'00000F'
So AS_1 is treated as char(15) x'F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0'
AP_1 is treated as char(9) x'00000F00000F00000F'
So it is easy to see that AS_1 == *ZEROS but AP_1 <> *ZEROS
Upvotes: 4