Convert numeric value to COMP data type
Moderators: chulett, rschirm, roy
Convert numeric value to COMP data type
Hi,
Can anyone help to convert numeric value to mainframe COMP field.
The target datatype is S9(4) COMP.
It would be great if anyone could share the logic to implement this in datastage routine.
Thanks!
Can anyone help to convert numeric value to mainframe COMP field.
The target datatype is S9(4) COMP.
It would be great if anyone could share the logic to implement this in datastage routine.
Thanks!
"COMP" is usually, but not necessarily, the same as COMP-3 but each COBOL implementation may choose to use another representation. What system is this COMP field for?
Going from a DataStage number to COMP-3 is not complicated, but does require a short piece of BASIC code to implement. Basically for each character in the DataStage number you add that number's representation in 4 bits (nibble) and append that to a string. Then add the nibble for the sign and left-pad to a 8-bit boundary.
Going from a DataStage number to COMP-3 is not complicated, but does require a short piece of BASIC code to implement. Basically for each character in the DataStage number you add that number's representation in 4 bits (nibble) and append that to a string. Then add the nibble for the sign and left-pad to a 8-bit boundary.
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Since the CFF stage is only for reading and that original SDK cobol routines come from me, I'll supply a COMP-3 conversion routine. I wrote it this morning and used the binary conversion, I could have done it using just the CHAR() and SEQ() functions and a bit of math, but I prefer it this way even though it might not be the most efficient.
Code: Select all
********************************************************************************
** Convert an integer into a COMP-3 representation. Each digit is stored in **
** 4 bits, the sign is the rightmost 4 bits as 0xC for positive and 0xD for **
** negative numbers. **
** **
** Vers. Author Date Comments **
** ===== ============ ========== ============================================ **
** 1.0.0 Arnd Wussing 03-07-2009 Initial Coding **
** **
********************************************************************************
** Declare Constants and Include files **
*****************************************
EQUATE ProgramName TO 'IntToComp3'
*******************
** Begin Program **
*******************
Ans = '' ;** return an empty result on error
IF NOT(NUM(InInteger)) THEN CALL DSLogWarn('The value "':InInteger:'" is not a number, skipping',ProgramName)
ELSE
IF NOT(INT(InInteger)=InInteger) THEN CALL DSLogWarn('The value "':InInteger:'" is not an integer, skipping',ProgramName)
ELSE
IF InInteger < 0 THEN IsNegative = 1 ELSE IsNegative = 0
WorkInteger = ABS(InInteger)
WorkIntegerLen = LEN(WorkInteger)
IF MOD(WorkIntegerLen,2)=0 THEN Ans = '0000' ;** left pad with zeroes if an even number of characters due to sign nibble
FOR i = 1 TO WorkIntegerLen
print WorkInteger[i,1]:' ':RIGHT('0000':OCONV(WorkInteger[i,1],"MB"),4)
Ans := RIGHT('0000':OCONV(WorkInteger[i,1],"MB"),4)
NEXT i
IF IsNegative THEN Ans := '1101' ELSE Ans := '1100' ;** append the sign
END ;** of if-then-else not a valid
END ;** of if-then-else not a valid number
Ans = ICONV(Ans,'MB0C')
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>