stupidedi icon indicating copy to clipboard operation
stupidedi copied to clipboard

Stupidedi::Exceptions::ParseError: required segment SE is missing from table Table 3 - Summary

Open n4a4 opened this issue 7 years ago • 2 comments

I have a block of code that is writing a purchase order (850). I call builder::CTT to try to write the count of the orders but when the line of code is included, I always get the following error:

Stupidedi::Exceptions::ParseError: required segment SE is missing from table Table 3 - Summary

However, when I remove the CTT line it always works. Am I using this in an incorrect way?

def self.order_edi(output_stream, headers, orders)
  config = Stupidedi::Config.contrib
  b = Stupidedi::Builder::BuilderDsl.build(config)

  isa = headers[:isa]
  gs = headers[:gs]
  st = headers[:st]
  beg = headers[:beg]
  n1 = headers[:n1]

  b.ISA isa[:authorization_information_qualifier],
        isa[:authorization_information],
        isa[:security_information_qualifier],
        isa[:security_information],
        isa[:interchange_id_qualifier],
        isa[:interchange_sender_id],
        isa[:interchange_id_qualifier],
        isa[:interchange_receiver_id],
        isa[:interchange_date],
        isa[:interchange_time],
        isa[:interchange_control_standards_identifier],
        isa[:interchange_control_version_number],
        isa[:interchange_control_number],
        isa[:acknowledgment_requested],
        isa[:interchange_usage_indicator],
        isa[:component_element_separator]

  b.GS gs[:functional_id],
       gs[:application_senders_code],
       gs[:application_receivers_code],
       gs[:date],
       gs[:time],
       gs[:group_control_number],
       gs[:responsible_agency_code],
       gs[:version]

  b.ST st[:transaction_set_id],
       st[:transaction_set_control_number]

  b.BEG beg[:transaction_set_purpose_code],
        beg[:purchase_order_type_code],
        beg[:purchase_order_number],
        beg[:release_number],
        beg[:purchase_order_date]

  b.N1 n1[:entity_identifier_code],
       n1[:name],
       n1[:identification_code_qualifier],
       n1[:identification_code]

  orders.each do |order|
    b.PO1 order[:assigned_identification],
          order[:quantity_ordered],
          order[:unit_or_basis_for_measurement_code],
          order[:unit_price],
          order[:basis_of_unit_price_code],
          order[:product_id_qualifier],
          order[:product_id]
  end

  # having this line would run into the parser exception
  b.CTT orders.size

  number_of_included_segments = 5 + orders.size
  b.SE number_of_included_segments,
       st[:transaction_set_control_number]



  b.GE 1,
       gs[:group_control_number]

  b.IEA 1,
        isa[:interchange_control_number]

  output = b.machine.zipper.tap do |z|
    separators = Stupidedi::Reader::Separators.build segment: "~\n",
      element: '*',
      component: isa[:component_element_separator],
      repetition: '^'

    w = Stupidedi::Writer::Default.new(z.root, separators)
    w.write($stdout)
  end

  p output
end

n4a4 avatar Feb 25 '17 22:02 n4a4

This might be a bug in stupidedi. Can you change your example to include literal values (rather than references to hash values) that I can paste to help me debug? Let me know if you need a quick workaround in the meantime, but I do want to figure this out and hopefully fix it.

kputnam avatar Mar 02 '17 03:03 kputnam

Having the same issue here. Changing CTT in the transaction_set_defs to Mandatory fixes the parse error.

outsmartin avatar Mar 31 '17 11:03 outsmartin