Convert numeric value to COMP data type

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
svga
Participant
Posts: 73
Joined: Thu Aug 07, 2008 6:31 am
Location: Syracuse

Convert numeric value to COMP data type

Post 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!
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

True... but for converting from those types not to them, from what I recall.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Agreed, but constructing the reverse logic is feasible.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Of course, really meant to mention that in my other post but somehow didn't.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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')
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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:
-craig

"You can never have too many knives" -- Logan Nine Fingers
nagarjuna
Premium Member
Premium Member
Posts: 533
Joined: Fri Jun 27, 2008 9:11 pm
Location: Chicago

Post 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 ??
Nag
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
nagarjuna
Premium Member
Premium Member
Posts: 533
Joined: Fri Jun 27, 2008 9:11 pm
Location: Chicago

Post by nagarjuna »

Thanks craig for clarifying my doubt ...
Nag
Post Reply