X12RecordWriter Class (Extends EDIRecordWriter)

Overview

The X12RecordWriter is derived from the EDIRecordWriter. It handles the specialized requirements of writing X12 control segments.

Attributes:

  • DOM Element TP Element for trading partner information

  • String Interchange Control Number

  • String Group Control Number

  • Integer Transaction Set Count

  • String Date

  • String Time

Methods:

  • Constructor

  • writeGE

  • writeGS

  • writeIEA

  • writeISA

  • writeSE

  • writeST

Methods

As with the case of the X12RecordReader class, only a few of these methods are very significant. The constructor method doesn't do anything except call the base class constructor. The methods that write transaction set and group trailer segments, writeGE and writeSE, are simple methods that write the number of included components, followed by the control number that was written in the header segment. The methods that write the header segments and the interchange trailer are worthy of a bit more discussion. I'll discuss them below, starting with the outer control segments of the interchange, moving inward.

writeISA

Based on trading partner information in the file description document, this method looks up the last used interchange control number from the EDIControl.xml data store. The method increments the control number, updates the value in EDIControl, and calls language and system dependent functions to get the current date and time for the ISA and GS segments. The method then populates the rest of the ISA segment from other Elements in the file description document and writes the ISA segment.

Logic for the X12RecordWriter writeISA Method
Arguments:
  None

Returns:
  Status or throws exception

ISA Info <- Call File Description Document's
    GetElementsByTagName for "ISAInformation"
ISA ReceiverID <- Call ISAInfo's getElementsByTagName for
    "ReceiverID", then getAttribute for "value"
X12 Control <- Call EDI Control document's getElementsByTagName
    for "X12OutboundControl"
TP NodeList <- Call X12 Control's getElementsByTagName for
    "TradingPartner"
DO for all entries in TP NodeList or until
    Control Receiver ID = ISA Receiver ID
  Control Receiver ID <- call TP NodeList item's getAttribute
    for "ReceiverID"
ENDDO
IF no match found
  TP Element <- call EDI Control's createElement method using
      Element name of "TradingPartner"
  X12 Control <- call X12 Control's appendChild to attach
      TP Element
  Interchange Number <- 1
  Call TP Element's setAttribute for "ReceiverID", passing
      ISA Receiver ID as value to set
ELSE
  Interchange Number <- Call TP Element's getAttribute for
      "LastInterchangeNumber"
  Increment Interchange Number
ENDIF
Call TP Element's setAttribute for "LastInterchangeNumber",
    passing Interchange Number as value to set
Date <- Get date from system, and reformat to YYMMDD
Time <- Get time from system, and reformat to HHMM
Get remaining values from ISA Info Element and pad to required
    Lengths
Initialize Record Buffer
Build ISA Segment in Record Buffer with "ISA" segment tag, values
    from ISA Info Element, Date, Time, and Delimiters from base
    class members, appending Record Terminator1 as segment
    terminator
Write Record Buffer using language-specific methods
Return success

We could, perhaps, use a more sophisticated method for looking up the trading partner in EDIControl than the algorithm in this method. However, I don't see significant performance gains in using something like XQuery for the number of entries likely to exist in this document. Also, we would be complicating the code by adding yet another type of technology.

writeGS

This method retrieves the last group control number used from the EDIControl file and populates the remainder of the segment from values from the GSInformation Element in the file description document. It also initializes the transaction set count.

Logic for the X12RecordWriter writeGS Method
Arguments:
  None

Returns:
  Status or throws exception

Transaction Set Count <- 0
GSInfo <- Call File Description Document's getElementsByTagName
    for "GSInformation"
GSReceiverID <- Call GSInfo's getElementsByTagName for
    "ApplicationReceiversCode", then getAttribute for "value"
GSType <- Call GSInfo's getElementsByTagName for
    "FunctionalIDCode", then getAttribute for "value"
GroupNodeList <- Call TP Element's getElementsByTagName for
    "FunctionalGroup"
DO for all entries in GroupNodeList or until
    ControlReceiverID = GSReceiverID and
    ControlType = GSType
  ControlReceiverID <- call GroupNodeList item's getAttribute
      for "ReceiverID"
  ControlType <- call GroupNodeList item's getAttribute
      for "FunctionalIDCode"
ENDDO
IF no match found
  GroupElement <- call EDI Control's createElement method using
      Element name of "FunctionalGroup"
  TP Element <- call TP Element's appendChild to attach
      GroupElement
  Group Number <- 1
  Call GroupElement's setAttribute for "ReceiverID", passing
      GSReceiverID as value to set
  Call GroupElement's setAttribute for "FunctionalIDCode",
      passing GSType as value to set
ELSE
  Group Number <- Call Group Element's getAttribute for
      "LastGroupNumber"
  Increment Group Number
ENDIF
Call Group Element's setAttribute for "LastGroupNumber",
    passing Group Number as value to set
Get remaining values from GSInfo Element
Initialize Record Buffer
Build GS Segment in Record Buffer with "GS" segment tag, values
    from GSInfo Element, Date, Time, and Delimiters from base
    class members, appending RecordTerminator1 as segment
    terminator
Write Record Buffer using language-specific methods
Return success

writeST

This method is quite a bit simpler that the writeISA and writeGS methods since we start a new sequence of transaction set control numbers with each new functional group we write. We need to retrieve only one value from the file description document.

Logic for the X12RecordWriter writeST Method
Arguments:
  None

Returns:
  Status or throws exception

Increment Transaction Set Count
Pad Transaction Set Count to four digits with leading zeroes
   if required
STInfo <- Call File Description Document's getElementsByTagName
    for "STInformation"
STType <- Call STInfo's getAttribute for "TransactionSetIDCode"
Initialize Record Buffer
Build ST Segment in Record Buffer with "ST" segment tag, STType,
    and Transaction Set Count, using Element Separator from
    base class members and appending RecordTerminator1 as segment
    terminator
Write Record Buffer using language-specific methods
Segment Count <- 1
Return success

writeIEA

Writing the trailer segment is pretty simple since we write only two values. However, for control number integrity we don't save the EDIControl document until after the interchange trailer is successfully written.

Logic for the X12RecordWriter writeIEA Method
Arguments:
  None

Returns:
  Status or throws exception

Initialize Record Buffer
Build IEA Segment in Record Buffer with "IEA" segment tag,
    "1" included functional group, and Interchange Control
    Number, using Element Separator from base class members
    and appending Record Terminator1 as segment terminator
Write Record Buffer using language-specific methods
Save EDI Control Document to EDI Control File Path
Return success

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset