X12Writer Component

Properties   Methods   Events   Config Settings   Errors  

The X12Writer component generates X12 documents with a clear, straightforward API.

Syntax

EDISDK.X12Writer

Remarks

The component allows you to create an EDI document from scratch, one segment at a time. Here's how a document would normally be created:

  1. Call LoadSchema to load the necessary schemas for the transactions that will be used.
  2. Specify where to write the output document by setting the OutputFile, or check the OutputData property after writing.
  3. Create a new interchange start segment by setting the fields of the Interchange property and call the StartInterchange method. Once the interchange is complete, call EndInterchange to add the interchange footer.
  4. If you want to create a functional group, set the fields of the FunctionalGroup property and then call the StartFunctionalGroup. Once all the transactions in the group have been created, call EndFunctionalGroup to add a footer for the group.
  5. To start a transaction, call the StartTransactionSet method. Once all segments have been added, call EndTransactionSet to add a footer to the transaction.
  6. To begin a segment, call the StartSegment method and pass in the tag for the segment. Once all the elements in the segment have been added, call EndSegment to add the segment terminator.
  7. To write a basic element to the current segment, call the WriteElement method.
  8. To write a composite element, call the StartCompositeElement method, then call the WriteComponent method for each component, and finally call EndCompositeElement to end the element.

Property List


The following is the full list of the properties of the component with short descriptions. Click on the links for further details.

DelimitersContains the delimiters for the EDI Document.
FileWriteModeDetermines how the output file is opened for writing.
FunctionalGroupContains the current functional group information for the EDI Document.
InterchangeContains the current interchange information for the EDI Document.
OutputDataThe output data that has been written so far.
OutputFileThe name of the output file to which the EDI data will be written.
SegmentSuffixThe suffix that is appended to the end of a segment.
TransactionSetContains the current transaction set information for the EDI Document.

Method List


The following is the full list of the methods of the component with short descriptions. Click on the links for further details.

closeCloses the writer.
configSets or retrieves a configuration setting.
endCompositeElementCloses the current composite element.
endFunctionalGroupCloses the current functional group.
endInterchangeCloses the current interchange.
endSegmentFinish writing the current segment.
endTransactionSetCloses the current transaction set.
resetResets all properties to their default values.
setOutputStreamSets the output stream where the EDI data will be written.
startCompositeElementStarts a composite element within the current segment.
startFunctionalGroupStarts a new functional group in the EDI document.
startInterchangeStarts a new interchange in the EDI document.
startSegmentStarts a new segment with the specified tag.
startTransactionSetStarts a new transaction set in the EDI document.
writeComponentWrites a component element value to the current composite element.
writeElementWrites an element value to the current segment.

Event List


The following is the full list of the events fired by the component with short descriptions. Click on the links for further details.

ErrorFires when an error occurs during message processing. Normally, the component fails with an error.
OutputFires when output data is written.

Config Settings


The following is a list of config settings for the component with short descriptions. Click on the links for further details.

Delimiters Property (X12Writer Component)

Contains the delimiters for the EDI Document.

Syntax

public X12Delimiters getDelimiters();

Remarks

This property contains the delimiters that will be used when writing the EDIFACT document. If the document uses delimiters other than the default, change the properties of this object to write the document correctly.

This property is read-only and not available at design time.

Please refer to the X12Delimiters type for a complete list of fields.

FileWriteMode Property (X12Writer Component)

Determines how the output file is opened for writing.

Syntax

public int getFileWriteMode();
public void setFileWriteMode(int fileWriteMode);
Enumerated values:
  public final static int fwmCreate = 0;

  public final static int fwmOverwrite = 1;

  public final static int fwmAppend = 2;

Default Value

0

Remarks

When OutputFile is set, this property determines how the file will be opened.

fwmCreate (Default)Creates a new file. If the file already exists, the translation will fail.
fwmOverwriteOpens an existing file and overwrites its contents. If the file does not exist, a new file will be created.
fwmAppendOpens an existing file and appends data to the end of the file. If the file does not exist, a new file will be created.

This property is not available at design time.

FunctionalGroup Property (X12Writer Component)

Contains the current functional group information for the EDI Document.

Syntax

public X12FunctionalGroup getFunctionalGroup();

Remarks

The functional group information is used when writing the functional group header (GS) and trailer (GE) segments. The properties of this object must be changed before calling StartFunctionalGroup to write the functional group correctly. After calling StartFunctionalGroup changing the properties of this object will change the values for the next functional group only.

This property is read-only and not available at design time.

Please refer to the X12FunctionalGroup type for a complete list of fields.

Interchange Property (X12Writer Component)

Contains the current interchange information for the EDI Document.

Syntax

public X12Interchange getInterchange();

Remarks

The interchange information is used when writing the interchange header (ISA) and trailer (IEA) segments. The properties of this object must be changed before calling StartInterchange to write the interchange correctly. After calling StartInterchange changing the properties of this object will change the values for the next interchange only.

This property is read-only and not available at design time.

Please refer to the X12Interchange type for a complete list of fields.

OutputData Property (X12Writer Component)

The output data that has been written so far.

Syntax

public String getOutputData();
public void setOutputData(String outputData);

Default Value

""

Remarks

OutputData contains the entire EDI document that has been written so far. If writing to a file or stream, this property will be empty.

This property is not available at design time.

OutputFile Property (X12Writer Component)

The name of the output file to which the EDI data will be written.

Syntax

public String getOutputFile();
public void setOutputFile(String outputFile);

Default Value

""

Remarks

FileWriteMode property determines how the file is opened for writing. If OutputFile is empty, no file will be written and the OutputData property will contain the EDI data instead.

This property is not available at design time.

SegmentSuffix Property (X12Writer Component)

The suffix that is appended to the end of a segment.

Syntax

public int getSegmentSuffix();
public void setSegmentSuffix(int segmentSuffix);
Enumerated values:
  public final static int ssNone = 0;

  public final static int ssCR = 1;

  public final static int ssLF = 2;

  public final static int ssCRLF = 3;

Default Value

0

Remarks

Possible values are:

ssNone (0)No suffix is appended to the segment.
ssCR (1)A carriage return (ASCII 13) is appended to the segment.
ssLF (2)A line feed (ASCII 10) is appended to the segment.
ssCRLF (3)A carriage return followed by a line feed (ASCII 13 and 10) is appended to the segment. This is the default value.

This property is not available at design time.

TransactionSet Property (X12Writer Component)

Contains the current transaction set information for the EDI Document.

Syntax

public X12TransactionSet getTransactionSet();

Remarks

This property holds the current transaction set information for the EDI document. It is used by the StartTransactionSet method to create a new transaction set header. The properties of this object must be changed before calling StartTransactionSet to write the transaction set correctly. After calling StartTransactionSet changing the properties of this object will change the values for the next transaction set only.

This property is read-only and not available at design time.

Please refer to the X12TransactionSet type for a complete list of fields.

Close Method (X12Writer Component)

Closes the writer.

Syntax

public void close();

Remarks

Calling Close will close the writer and release any resources associated with it. After calling Close, the writer cannot be used unless it is re-initialized.

Config Method (X12Writer Component)

Sets or retrieves a configuration setting.

Syntax

public String config(String configurationString);

Remarks

Config is a generic method available in every component. It is used to set and retrieve configuration settings for the component.

These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these internal properties is provided through the Config method.

To set a configuration setting named PROPERTY, you must call Config("PROPERTY=VALUE"), where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).

To read (query) the value of a configuration setting, you must call Config("PROPERTY"). The value will be returned as a string.

EndCompositeElement Method (X12Writer Component)

Closes the current composite element.

Syntax

public void endCompositeElement();

Remarks

Calling EndCompositeElement will close the current composite element. If no composite element is open, an error will be raised.

EndFunctionalGroup Method (X12Writer Component)

Closes the current functional group.

Syntax

public void endFunctionalGroup();

Remarks

Calling EndFunctionalGroup will close the current functional group. If no functional group is open, an error will be raised. This method will also write the required FunctionalGroup Trailer (GE) segment to the output.

EndInterchange Method (X12Writer Component)

Closes the current interchange.

Syntax

public void endInterchange();

Remarks

Calling EndInterchange will close the current interchange. If no interchange is open, an error will be raised. This method will also write the required Interchange Trailer (IEA) segment to the output.

EndSegment Method (X12Writer Component)

Finish writing the current segment.

Syntax

public void endSegment();

Remarks

Calling EndSegment will finish writing the current segment. If no segment is open or if a composite element is still open an error will be raised. This method will also write the segment delimiter and segment suffix to the output.

EndTransactionSet Method (X12Writer Component)

Closes the current transaction set.

Syntax

public void endTransactionSet();

Remarks

Calling this method will close the current transaction set. If no transaction set is open, an error will be raised. This method will also write the required Transaction Set Trailer (SE) segment to the output.

Reset Method (X12Writer Component)

Resets all properties to their default values.

Syntax

public void reset();

Remarks

This method resets all properties of the component to their default values as specified in the property definitions.

SetOutputStream Method (X12Writer Component)

Sets the output stream where the EDI data will be written.

Syntax

public void setOutputStream(java.io.OutputStream outputStream);

Remarks

This method sets the output stream for the component. The output stream must be writable. Calling Close will close the specified output stream. If OutputStream is set, no file will be written and the OutputData property will be null.

StartCompositeElement Method (X12Writer Component)

Starts a composite element within the current segment.

Syntax

public void startCompositeElement();

Remarks

This method starts a composite element within the current segment. The composite element can contain multiple component elements. The composite element is ended by calling the EndCompositeElement method. Component elements within the composite are added by calling the WriteComponent method.

StartFunctionalGroup Method (X12Writer Component)

Starts a new functional group in the EDI document.

Syntax

public void startFunctionalGroup();

Remarks

This method starts a new functional group in the EDI document. The functional group fields must be set using the appropriate properties before calling this method. The functional group is ended by calling the EndFunctionalGroup method. The functional group header segment (GS) is written to the output when this method is called.

StartInterchange Method (X12Writer Component)

Starts a new interchange in the EDI document.

Syntax

public void startInterchange();

Remarks

This method starts a new interchange in the EDI document. The interchange fields must be set using the appropriate properties before calling this method. The interchange is ended by calling the EndInterchange method. The interchange header segment (ISA) is written to the output when this method is called. If opening a new interchange would result in an invalid structure (for example, starting a new interchange before ending the previous one), an error will be raised.

StartSegment Method (X12Writer Component)

Starts a new segment with the specified tag.

Syntax

public void startSegment(String tag);

Remarks

This method starts a new segment with the specified tag. The segment is ended by calling the EndSegment method. Element values within the segment are added by calling the WriteElement method. Composite elements can be added to the segment by calling the StartCompositeElement method. If starting a new segment would result in an invalid structure (for example, starting a new segment before ending the previous one), an error will be raised.

StartTransactionSet Method (X12Writer Component)

Starts a new transaction set in the EDI document.

Syntax

public void startTransactionSet();

Remarks

This method starts a new transaction set in the EDI document. The transaction set fields must be set using the appropriate properties before calling this method. The transaction set is ended by calling the EndTransactionSet method. The transaction set header segment (ST) is written to the output when this method is called. If opening a new transaction set would result in an invalid structure (for example, starting a new transaction set before ending the previous one), an error will be raised.

WriteComponent Method (X12Writer Component)

Writes a component element value to the current composite element.

Syntax

public void writeComponent(String val);

Remarks

This method writes a component element value to the current composite element. The composite element must be started by calling the StartCompositeElement method before calling this method. The composite element is ended by calling the EndCompositeElement method. If this method is called when not within a composite element, an error will be raised.

WriteElement Method (X12Writer Component)

Writes an element value to the current segment.

Syntax

public void writeElement(String val);

Remarks

This method writes an element value to the current segment. The segment must be started by calling the StartSegment method before calling this method. The segment is ended by calling the EndSegment method. If this method is called when not within a segment, an error will be raised.

Error Event (X12Writer Component)

Fires when an error occurs during message processing. Normally, the component fails with an error.

Syntax

public class DefaultX12WriterEventListener implements X12WriterEventListener {
  ...
  public void error(X12WriterErrorEvent e) {}
  ...
}

public class X12WriterErrorEvent {
  public int errorCode;

  public String description;

}

Remarks

The Error event is fired in case of exceptional conditions during message processing. Normally, the component throws an exception.

ConnectionId is the associated client Id, ErrorCode contains an error code, and Description contains a textual description of the error. For a list of valid error codes and their descriptions, please refer to the Error Codes section.

Output Event (X12Writer Component)

Fires when output data is written.

Syntax

public class DefaultX12WriterEventListener implements X12WriterEventListener {
  ...
  public void output(X12WriterOutputEvent e) {}
  ...
}

public class X12WriterOutputEvent {
  public byte[] data;

}

Remarks

This event is fired when output data is written. The Data parameter contains the segment that was written.

X12Delimiters Type

The delimiters used in the X12 document.

Remarks

This type contains fields specifying the various delimiters used within the X12 document.

The following fields are available:

Fields

Component
String

Default Value: ":"

The delimiter separating components.

In X12Reader, this type is used to hold the delimiters found when parsing the component, while in X12Writer the fields can be set to choose the delimiters that will be used when writing

Element
String

Default Value: "*"

The delimiter separating elements.

In X12Reader, this type is used to hold the delimiters found when parsing the element, while in X12Writer the fields can be set to choose the delimiters that will be used when writing

Repetition
String

Default Value: "^"

The delimiter separating components.

In X12Reader, this type is used to hold the delimiters found when parsing the component, while in X12Writer the fields can be set to choose the delimiters that will be used when writing

Segment
String

Default Value: "~"

The delimiter separating segments.

In X12Reader, this type is used to hold the delimiters found when parsing the segment, while in X12Writer the fields can be set to choose the delimiters that will be used when writing

Constructors

public X12Delimiters();

X12FunctionalGroup Type

A functional group of messages.

Remarks

This type represents a functional group of messages, with fields describing the values from the GS segment.

The following fields are available:

Fields

AppReceiverCode
String

Default Value: ""

The name or code of the intended receiver of the transaction set group.

This is an alphanumeric field with a value between 2 and 15 characters.

AppSenderCode
String

Default Value: ""

Code identifying the sender of FunctionalGroup

This is an alphanumeric field with a value between 2 and 15 characters long.

Date
String

Default Value: ""

The date that the group of transaction sets was prepared.

This is a numeric field with a value in the format YYMMDD.

FunctionalIdentifierCode
String

Default Value: ""

A code identifying the type of transaction sets included in the functional group.

This is an alphanumeric field with a code value between of 2 characters.

GroupControlNum
String

Default Value: ""

An identification number assigned by the sender to uniquely identify the group of transaction sets.

This is a numeric field with a value between 1 and 9 digits.

ResponsibleAgencyCode
String

Default Value: ""

A code identifying the issuer of the standard that the transaction set conforms to.

This is an alphanumeric field with a code value of 1 to 2 characters.

Time
String

Default Value: ""

The time that the group of transaction sets was prepared.

This is a numeric field with a value between 4 and 8 digits in the format HHMM, HHMMSS, or HHMMSSDD. Time should be in the 24-hour format.

Version
String

Default Value: ""

Code indicating the version of the X12 standard used to construct the transaction set.

This is an alphanumeric field with a code value between 1 and 12 characters.

Constructors

public X12FunctionalGroup();

X12Interchange Type

An interchange containing functional groups and transaction sets.

Remarks

This type represents an X12 interchange, with fields describing the values from the ISA segment.

The following fields are available:

Fields

AckRequest
String

Default Value: ""

Code indicating whether an interchange acknowledgment is requested.

This is an alphanumeric field with a code value of 1 character, either "0" (no acknowledgment requested) or "1" (acknowledgment requested).

AuthorizationInfo
String

Default Value: ""

Information used for additional identification or authorization of the interchange sender or the data in the interchange.

The type of information is set by the AuthorizationInfoQual field.

AuthorizationInfoQualifier
String

Default Value: ""

A code indicating the type of data supplied in Authorization Information field.

This is an alphanumeric field with a code value of 2 characters.

Date
String

Default Value: ""

The date that the Interchange was prepared.

This is a numeric field with a value of 6 digits in the format YYMMDD.

InterchangeControlNum
String

Default Value: ""

A control number assigned by the sender to uniquely identify the interchange.

This is a numeric field with a value of 9 digits.

InterchangeControlVersionNum
String

Default Value: ""

A code specifying the version of the X12 standard used to construct the Interchange.

This is an alphanumeric field with a code value 5 characters.

ReceiverID
String

Default Value: ""

The identification code of the receiver of the transaction set.

This is an alphanumeric field with a value of 15 characters.

ReceiverIDQualifier
String

Default Value: ""

A code that identifies the format of the receiver ID.

This is an alphanumeric field with a code value of 2 characters.

SecurityInfo
String

Default Value: ""

Coded security information associated with the Interchange.

The type of information is set by the SecurityInfoQualifier.

This is an alphanumeric field with a value between of 10 characters.

SecurityInfoQualifier
String

Default Value: ""

A code indicating the type of data in the Security Information field.

This is an alphanumeric field with a code value of 2 characters.

SenderID
String

Default Value: ""

The identification code of the sender of the transaction set.

This is an alphanumeric field with a value of 15 characters.

SenderIDQualifier
String

Default Value: ""

A code that identifies the format of the sender ID.

This is an alphanumeric field with a code value of 2 characters.

Time
String

Default Value: ""

The time that the Interchange sets was prepared.

This is a numeric field with a value in the format HHMM.

UsageIndicator
String

Default Value: ""

Code to indicate whether the interchange is a test or production.

This is an alphanumeric field with a code value of 1 character.

Constructors

public X12Interchange();

X12TransactionSet Type

An X12 transaction set.

Remarks

This type represents an X12 transaction set, with fields describing the values from the ST segment.

The following fields are available:

Fields

ImpConventionReference
String

Default Value: ""

Reference used to identify the implementation convention.

This is an alphanumeric field with a value up to 35 characters long.

TransactionSetControlNum
String

Default Value: ""

The unique transaction set control number assigned for a transaction set.

This is an alphanumeric field with a value between 4 and 9 characters long.

TransactionSetIDCode
String

Default Value: ""

The identifier code for the transaction set.

This is an alphanumeric field with a code value of 3 characters long.

Constructors

public X12TransactionSet();

Config Settings (X12Writer Component)

The component accepts one or more of the following configuration settings. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these internal properties is provided through the Config method.

Trappable Errors (X12Writer Component)

X12Writer Errors

202   Invalid argument.
304   Cannot write to file.
1099   Encountered an unexpected segment tag.
1100   Attempted to perform an action while the component was busy, or close an incomplete interchange.
1205   Tried to perform an operation in a bad state (such as ending an interchange before starting one).
1206   Tried to end an interchange with no contents.