Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cobol to Decimal #101

Open
jwg2s opened this issue Jul 16, 2012 · 5 comments
Open

Cobol to Decimal #101

jwg2s opened this issue Jul 16, 2012 · 5 comments

Comments

@jwg2s
Copy link

jwg2s commented Jul 16, 2012

Here's an example of converting Cobol to Decimal if it could be useful.

  class CobolToDecimalTransform < ExtractTransferLoad::Transform
    # Initialize the transformer.
    #
    # Configuration options:
    # * <tt>:significant</tt>: The number of significant decimal digits.
    # * <tt>:places</tt>: The number of implied decimal places.
    def initialize(control, name, configuration={})
      super
      @significant = configuration[:significant] ||= 0
      @places = configuration[:places] ||= 0
    end
    # Transform the value
    def transform(name, value, row)
      return value if value.nil?
      decimal = BigDecimal.new(value.to_s, @significant)
      @places.times do |x|
        decimal = decimal / 10
      end
      decimal
    end
  end
@thbar
Copy link
Member

thbar commented Jul 16, 2012

Hi John! By COBOL, do you mean fixed point arithmetic stored as integers? (can you provide example of input data?)

I think this could go to a contrib area or something.

@jwg2s
Copy link
Author

jwg2s commented Jul 16, 2012

That's exactly what I meant. An exmaple would be:

Format: 9(4)v9(3)
Value: 1249204
After Transform: 1249.204

Example usage:
transform field, :cobol_to_decimal, :significant => 7, :decimal => 3

@thbar
Copy link
Member

thbar commented Jul 16, 2012

Thanks for contributing that!

Although it's too specific for being added to the core, I definitely want to track down this kind of examples.

It makes me remember I have a repo with contributions like this one over there.

I could move the repo to the activewarehouse organization; then you could add this transform over there (with specs maybe?)

What do you think?

@jwg2s
Copy link
Author

jwg2s commented Jul 17, 2012

Sure, I'd be happy to do that.

@thbar
Copy link
Member

thbar commented Jul 17, 2012

Cool! Just moved the etl-goodies repo here:

https://github.com/activewarehouse/etl-goodies

Can you issue a pull-request from there?

If you can add specs too, it would be perfect (otherwise I'll write them!).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants