Page 1 of 1

Convert numeric value to COMP data type

Posted: Thu Jul 02, 2009 8:34 am
by svga
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!

Posted: Thu Jul 02, 2009 8:44 am
by ArndW
"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.

Posted: Thu Jul 02, 2009 5:22 pm
by ray.wurlod
The logic is supplied with the product, in the Routines branch of the repository. There are SDK routines for converting COBOL data types.

Posted: Thu Jul 02, 2009 6:02 pm
by chulett
True... but for converting from those types not to them, from what I recall.

Posted: Thu Jul 02, 2009 7:49 pm
by ray.wurlod
Agreed, but constructing the reverse logic is feasible.

Posted: Thu Jul 02, 2009 9:36 pm
by chulett
Of course, really meant to mention that in my other post but somehow didn't.

Posted: Fri Jul 03, 2009 2:51 am
by ArndW
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')

Posted: Fri Jul 03, 2009 6:22 am
by chulett
ArndW wrote: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.
Nice! Not sure I knew that... but I do now. :wink:

Posted: Fri Jul 03, 2009 6:26 am
by nagarjuna
In the same way as we read EBCDIC mainframe's files using sequential stage as input , Is it not possible to convert inthose format using it as an o/p ??

Posted: Fri Jul 03, 2009 6:37 am
by chulett
If you're asking if the Server Sequential File stage can automatically write EBCDIC and/or COMP fields, the answer is no. From what I recall, the PX stage can, however.

Posted: Fri Jul 03, 2009 6:43 am
by nagarjuna
Thanks craig for clarifying my doubt ...