Any limitation on size when using Iconv and Oconv with "

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

chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I had problems with MOD() on numbers over a certain size and I didn't see a need to bump up the EXACTNUMERIC value so I wrote an "SMOD" routine that used the string math functions I mentioned earlier to do a proper mod on any big ass number. Worked fine for me.
-craig

"You can never have too many knives" -- Logan Nine Fingers
manuel.gomez
Premium Member
Premium Member
Posts: 291
Joined: Wed Sep 26, 2007 11:23 am
Location: Madrid, Spain

Post by manuel.gomez »

chulett wrote:I had problems with MOD() on numbers over a certain size and I didn't see a need to bump up the EXACTNUMERIC value so I wrote an "SMOD" routine that used the string math functions I mentioned earlier to do a proper mod on any big ass number. Worked fine for me.
No idea on those string math functions.
Are these basic ones? or C routines you wrote for parallel jobs?
If they are pre-written within datastage, can you please recommend any of those so can match my needs for base10-base2 conversions?

Thanks!!!
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

BASIC and all documented in the BASIC manual. So, rather than "div" to divide you would use "sdiv". Same for all of the other operations: sadd, ssub, etc. Build your own mod function that just uses string math.
-craig

"You can never have too many knives" -- Logan Nine Fingers
manuel.gomez
Premium Member
Premium Member
Posts: 291
Joined: Wed Sep 26, 2007 11:23 am
Location: Madrid, Spain

Post by manuel.gomez »

Correct me if I am wrong, there are four string math functions:

sdiv, sadd, smul and ssub

I will build a custom smod function. I hope this works

Thanks very much!!!!
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Those are them. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
manuel.gomez
Premium Member
Premium Member
Posts: 291
Joined: Wed Sep 26, 2007 11:23 am
Location: Madrid, Spain

Post by manuel.gomez »

Hi guys!!!

I got a solutions thanks to chulett indications with string maths functions

The SMOD function I wrote is the following

Code: Select all

cocte = field(sdiv(Arg1,Arg2), '.', 1)

Ans = ssub(Arg1,smul(cocte, Arg2))
I know that the field function is not the more elegant choice, but I wanted the int number, and I could not solve it just with the sdiv function

Now, the "only" problem left is negative numbers to be converted longer than 15 length

When number is negative, to turn it from base10 to base2, you have to convert absolute value into base2, and add 1

But I am not sure to be able to do this add 1 operation once I got the binary value from the first step.

Any suggestions guys?
ray.wurlod
Participant
Posts: 54595
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

chulett wrote:I had problems with MOD() on numbers over a certain size and I didn't see a need to bump up the EXACTNUMERIC value so I wrote an "SMOD" routine that used the string math functions I mentioned earlier to do a proper mod on any big ass number. Worked fine for me.
Would you describe these, therefore, as steatopygous functions?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ray.wurlod
Participant
Posts: 54595
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

It's not really "add one" though, is it? It's more "set the sign bit". This can readily be done with string manipulation.
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 »

ray.wurlod wrote:
chulett wrote:I had problems with MOD() on numbers over a certain size and I didn't see a need to bump up the EXACTNUMERIC value so I wrote an "SMOD" routine that used the string math functions I mentioned earlier to do a proper mod on any big ass number. Worked fine for me.
Would you describe these, therefore, as steatopygous functions?
Why, it seems that one could. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
manuel.gomez
Premium Member
Premium Member
Posts: 291
Joined: Wed Sep 26, 2007 11:23 am
Location: Madrid, Spain

Post by manuel.gomez »

ray.wurlod wrote:It's not really "add one" though, is it? It's more "set the sign bit". This can readily be done with string manipulation.
We can say so, yes

These are the steps I would follow:

- Remove the minus sign from the input value
- Use my function to turn argument into base10
- Change 0's into 1's and 1's into 0's
- Set the sign bit, adding 1 to the previous result (complent two)

For example, lets say we are receiving input value: -12

Step1: 12
Step2: 1100
Step3: 0011
Step4: 0100

But with the code I do have now, I dont know how to do step4

Any ideas please?
Thanks very much!
ray.wurlod
Participant
Posts: 54595
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The one that jumps to mind is to do it in decimal - subtract the next higher power of 2 from the absolute value of the original number then convert to binary. It would probably be easy to create an AddBit function.

Code: Select all

FUNCTION AddBit(BinaryString)
Begin Case
   Case UnAssigned(BinaryString) Or IsNull(BinaryString)
      Ans = @NULL
   Case Len(Convert("01","",BinaryString)) > 0
      Ans = @NULL  ; * argument is not a binary string
   Case @TRUE
      Ans = BinaryString
      RPos = Len(BinaryString)
      Carry = @FALSE
      For BitPos = RPos To 1 Step -1
         If Ans[BitPos,1] = 0
         Then
            Ans[BitPos,1] = "1"
            Exit  ; * exit from loop
         End
         Else
            Ans[BitPos,1] = "0"
            If BitPos = 1 Then Carry = @TRUE
         End
      Next BitPos
      If Carry
      Then
         Ans = "1" : Ans
      End
End Case
RETURN(Ans)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
manuel.gomez
Premium Member
Premium Member
Posts: 291
Joined: Wed Sep 26, 2007 11:23 am
Location: Madrid, Spain

Post by manuel.gomez »

Thanks very much Ray!!

I am almost done!!!

Now I have a doubt on how Oconv function converted a numeric number

I did the following:

Code: Select all

CASE len(Arg1)<=15
     * For numbers shorter than 15, we use Oconv function, that will be faster
     Ans=Oconv(Arg1, "MB")
And returned result for input value: -12 was
11111111111111111111111111110100
Why all this heading 1's? I was expecting 0100 to be returned!
ray.wurlod
Participant
Posts: 54595
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

That's the correct result in a twos-complement setting. A 32-bit signed negative integer is represented as 65536 + (value). In this case, 65536 + (-12) = 65534. Binary representation of 65534 is 11111111111111111111111111110100.

Positive signed integers range from 0 through 32767.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
manuel.gomez
Premium Member
Premium Member
Posts: 291
Joined: Wed Sep 26, 2007 11:23 am
Location: Madrid, Spain

Post by manuel.gomez »

ray.wurlod wrote:That's the correct result in a twos-complement setting. A 32-bit signed negative integer is represented as 65536 + (value). In this case, 65536 + (-12) = 65534. Binary representation of 65534 is 11111111111111111111111111110100.

Positive signed integers range from 0 through 32767.
Great, I think we can consider this as solved

Thanks very much for you help guys!!!
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Yah! :D
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply