3

I am creating ANSI.X12 messages in a java program with the help of smooks. I'm defining the X12 messages myself using xml-files (with their http://www.milyn.org/schema/edi-message-mapping-1.2.xsd). Most of it works well enough, but I do have a problem with the ISA-segment. I have it defined as such:

<?xml version="1.0" encoding="UTF-8"?>
<medi:edimap xmlns:medi="http://www.milyn.org/schema/edi-message-mapping-1.2.xsd">

    <medi:description name="Some X12 Message Definition" version="1.0" />

    <medi:delimiters segment="&#10;" field="*" 
        component="^" sub-component="~" escape="?" />

    <medi:segments xmltag="Segments">

        <medi:segment segcode="ISA" xmltag="InterchangeControlHeader">
            <medi:field xmltag="AuthorizationInformationQualifier" />
            <medi:field xmltag="AuthorizationInformation"/>
            <medi:field xmltag="SecurityInformationQualifier"/>
            <medi:field xmltag="SecurityInformation"/>
            <medi:field xmltag="InterchangeSenderQualifier"/>
            <medi:field xmltag="InterchangeSenderID"/>
            <medi:field xmltag="InterchangeReceiverQualifier"/>
            <medi:field xmltag="InterchangeReceiverID"/>
            <medi:field xmltag="InterchangeDate" type="Date" typeParameters="format=yyMMdd"/>
            <medi:field xmltag="InterchangeTime" type="Date" typeParameters="format=HHmm"/>
            <medi:field xmltag="InterchangeControlStandardsIdentifier"/>
            <medi:field xmltag="InterchangeControlVersionNumber"/>
            <medi:field xmltag="InterchangeControlNumber"/>
            <medi:field xmltag="AcknowledgmentRequested"/>
            <medi:field xmltag="UsageIndicator"/>
            <medi:field xmltag="ComponentElementSeparator"/>
        </medi:segment>
[...]

As long as I insert strings of the correct lengths, this is mainly usable. The problem is with the component separator (^ in this case). The ISA segment defines which chars are special chars used to separate segments, elements, etc. When I put "^" as value into ComponentElementSeparator, it becomes escaped (of course), since it is a special char, and smooks does not know that my ISA segment is the special ISA segment.

I get

ISA*00*          *00*          *01*000000987654321*01*000000123456789*141031*1656*U*00401*000002388*0*T*?^

where it should be

ISA*00*          *00*          *01*000000987654321*01*000000123456789*141031*1656*U*00401*000002388*0*T*^

(note the ? at the end before the ^).

The only workaround that I got so far, is to put some different char into medi:delimiters such as <medi:delimiters segment="&#10;" field="*" component="&lt;" sub-component="~" escape="?" />, but that is bound to create problems as soon as that char appears in the data somewhere. This is specially frustrating, as the message does not even use any components that have to be separated.

I could not find any information on that in the documentation of smooks, but there must be some way somehow to do it. After all, X12 is one of two reasons I know of, that anyone would use smooks in the first place (the other one beeing EDIFACT).

Anyone knows the correct way to insert ISA into my smooks message description?

kratenko
  • 7,354
  • 4
  • 36
  • 61
  • Just a guess but couldn't it be that the `` tag is all you need to specify. My assumption is that the delimiters tag results in an ISA segment for you, without you having to explicitly specify one yourself? – geert3 Dec 04 '14 at 10:38
  • @geert3 That would be all the information needed, yes. But I to fill in the information for that segment (like the `000000987654321` in the example), nor how to make that segment show up in the created message. – kratenko Dec 04 '14 at 15:04
  • What happens if you leave the `?` in there. I see many examples that have some sort of escape in front of the first component end. Besides ISA is a fixed-length segment and it would seem the last char is taken, no matter (I think) if it is escaped or not. So what happens if you leave it there, just make sure the total length is OK. – geert3 Dec 04 '14 at 16:17
  • @kratenko: if all segments are in single line, how are you reading a non formatted EDI file ? Your delimiter configuration will only read if EDI segments are formatted. Are you formatting EDI segments before parsing ? – JToddler Mar 02 '16 at 20:55
  • @JToddler Not sure what you mean by unformatted EDI file, X12 are always formatted, that's kinda the point. If you mean "how to find the delimiters": the ISA has fixed field widths, so you can read the delimiters in specific byte positions before parsing the rest of the file. If I did not get your meaning, I'd be happy to meet you in chat. – kratenko Mar 02 '16 at 21:10
  • @JToddler in chat you could find me here: http://chat.stackoverflow.com/rooms/105197/edi – kratenko Mar 02 '16 at 21:30
  • @kratenko thanks. i posted my question here stackoverflow.com/questions/35780645/unable-to-read-edi-file – JToddler Mar 03 '16 at 19:19

1 Answers1

1

This may be late, but I was running into the issue. I've identified the problem (if you are using EJC to generate) is that it adds the following at the end of each segment output step:

writer.write(EDIUtils.concatAndTruncate(nodeTokens, DelimiterType.FIELD, delimiters));

If the delimiter is last (which the ISA.ComponentElementSeparator is), it will get truncated unless it is defined with an escape, which is not the desired behavior for this specific scenario. Do not have an answer yet, but wanted to raise a source of the issue.

Added the problem definition and possible direction here: https://github.com/smooks/smooks/issues/114

UPDATE: if using EJC, set the following:

 <medi:import truncatableSegments="false" ....
dhartford
  • 1,125
  • 2
  • 12
  • 35