EDIFACTWriter Component

Properties   Methods   Events   Config Settings   Errors  

The EDIFACTWriter component generates EDIFACT documents with a clear, straightforward API.

Syntax

EDISDK.EDIFACTWriter

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 messages in the group have been created, call EndFunctionalGroup to add a footer for the group.
  5. To start a message, call the StartMessage method. Once all segments have been added, call EndMessage to add a footer to the message.
  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.
MessageContains the current message 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.

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.
endCompositeElementFinish writing the composite element.
endFunctionalGroupWrite the UNE(FunctionalGroup) segment to the output file/data/stream.
endInterchangeWrite the UNZ(Interchange) segment to the output file/data/stream.
endMessageCloses the current message.
endSegmentFinish writing the segment, add SegmentSuffix at the end of the segment.
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.
startMessageStarts a new message in the EDI document.
startSegmentStarts a new segment with the specified tag.
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 (EDIFACTWriter Component)

Contains the delimiters for the EDI Document..

Syntax

public EDIFACTDelimiters 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 EDIFACTDelimiters type for a complete list of fields.

FileWriteMode Property (EDIFACTWriter 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 (EDIFACTWriter Component)

Contains the current functional group information for the EDI Document.

Syntax

public EDIFACTFunctionalGroup 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 EDIFACTFunctionalGroup type for a complete list of fields.

Interchange Property (EDIFACTWriter Component)

Contains the current interchange information for the EDI Document.

Syntax

public EDIFACTInterchange 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 EDIFACTInterchange type for a complete list of fields.

Message Property (EDIFACTWriter Component)

Contains the current message information for the EDI Document.

Syntax

public EDIFACTMessage getMessage();

Remarks

This property holds the current message information for the EDI document. It is used by the StartMessage method to create a new transaction set header. The properties of this object must be changed before calling StartMessage to write the transaction set correctly. After calling StartMessage 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 EDIFACTMessage type for a complete list of fields.

OutputData Property (EDIFACTWriter 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 (EDIFACTWriter 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 (EDIFACTWriter 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

3

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.

Close Method (EDIFACTWriter 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 (EDIFACTWriter 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 (EDIFACTWriter Component)

Finish writing the composite element.

Syntax

public void endCompositeElement();

Remarks

This method is used to close a CompositeElement. This method may only be called after a successful call to StartCompositeElement

EndFunctionalGroup Method (EDIFACTWriter Component)

Write the UNE(FunctionalGroup) segment to the output file/data/stream.

Syntax

public void endFunctionalGroup();

Remarks

This method is used to close a FunctionalGroup. This method may only be called after a successful call to StartFunctionalGroup

EndInterchange Method (EDIFACTWriter Component)

Write the UNZ(Interchange) segment to the output file/data/stream.

Syntax

public void endInterchange();

Remarks

This method is used to close an Interchange. This method may only be called after a successful call to StartInterchange

EndMessage Method (EDIFACTWriter Component)

Closes the current message.

Syntax

public void endMessage();

Remarks

Calling this method will close the current message. If no message is open, an error will be raised. This method will also write the required Message Trailer (UNT) segment to the output.

EndSegment Method (EDIFACTWriter Component)

Finish writing the segment, add SegmentSuffix at the end of the segment.

Syntax

public void endSegment();

Remarks

This method is used to close a Segment. This method may only be called after a successful call to StartSegment

Reset Method (EDIFACTWriter 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 (EDIFACTWriter 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 (EDIFACTWriter 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 (EDIFACTWriter 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 (UNG) is written to the output when this method is called.

StartInterchange Method (EDIFACTWriter 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 (UNB) 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.

StartMessage Method (EDIFACTWriter Component)

Starts a new message in the EDI document.

Syntax

public void startMessage();

Remarks

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

StartSegment Method (EDIFACTWriter 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.

WriteComponent Method (EDIFACTWriter 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 (EDIFACTWriter 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 (EDIFACTWriter Component)

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

Syntax

public class DefaultEDIFACTWriterEventListener implements EDIFACTWriterEventListener {
  ...
  public void error(EDIFACTWriterErrorEvent e) {}
  ...
}

public class EDIFACTWriterErrorEvent {
  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 (EDIFACTWriter Component)

Fires when output data is written.

Syntax

public class DefaultEDIFACTWriterEventListener implements EDIFACTWriterEventListener {
  ...
  public void output(EDIFACTWriterOutputEvent e) {}
  ...
}

public class EDIFACTWriterOutputEvent {
  public byte[] data;

}

Remarks

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

EDIFACTDelimiters Type

The delimiters used in the EDIFACT document.

Remarks

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

The following fields are available:

Fields

Component
String

Default Value: ":"

The character used to separate the components in a composite element.

Decimal
String

Default Value: "."

The character used to separate the integer portion of a numeric value from the fractional portion.

Element
String

Default Value: "+"

The delimiter used to separate elements within a segment.

Release
String

Default Value: "?"

The character used to escape other characters within a field. For example, with the default EDIFACT delimiters, "?+" should be considered "+" character that appears within a field, not an element separator.

Repetition
String

Default Value: "*(syntax 4) or empty(syntax 3)"

The character used to indicate a repeating element or component.

Segment
String

Default Value: "'"

The character used to terminate a segment.

Constructors

public EDIFACTDelimiters();

EDIFACTFunctionalGroup Type

A functional group of messages.

Remarks

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

The following fields are available:

Fields

AppPassword
String

Default Value: ""

The application password as specified in the functional group header.

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

AppRecipientIdentification
String

Default Value: ""

The name or code of the intended recipient of the message group.

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

AppRecipientIDQualifier
String

Default Value: ""

The qualifier for the recipient's identification (if it contains a code value).

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

AppSenderIdentification
String

Default Value: ""

The name or code of the message group's sender.

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

AppSenderIDQualifier
String

Default Value: ""

The qualifier for the sender's identification (if it contains a code value).

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

AssociationAssignedCode
String

Default Value: ""

The assigned code for the message type.

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

ControllingAgency
String

Default Value: ""

A code value that indicates the agency responsible for maintaining the message specifications.

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

Date
String

Default Value: ""

The date that the group of messages was prepared.

GroupIdentification
String

Default Value: ""

The identification value for the functional group.

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

MessageRelease
String

Default Value: ""

The message release number for the message type appearing in the message group.

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

MessageVersion
String

Default Value: ""

The message version number for message type appearing in the functional group.

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

ReferenceNumber
String

Default Value: ""

The reference number for the functional group.

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

Time
String

Default Value: ""

The time that the group of messages was prepared.

Constructors

public EDIFACTFunctionalGroup();

EDIFACTInterchange Type

An interchange containing functional groups and messages.

Remarks

This type represents an EDIFACT interchange, with fields describing the values from the UNB segment.

The following fields are available:

Fields

AckRequest
String

Default Value: ""

If this field is '1', an ACK was requested in response to this interchange.

AgreementIdentifier
String

Default Value: ""

The identifier for the communication agreement used by the interchange.

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

ApplicationReference
String

Default Value: ""

If the interchange contains only one type of message, this can contain the identifier for the type of message.

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

CharacterEncoding
String

Default Value: ""

The character encoding used by the interchange.

This is an alphanumeric field with a value up to 3 characters long, and is only present for EDIFACT syntax 4.

CodeListVersionNumber
String

Default Value: ""

The identifier for the communication agreement used by the interchange.

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

Date
String

Default Value: ""

The date that the interchange was prepared.

ProcessingPriorityCode
String

Default Value: ""

A 1-character code that requests a specific processing priority for the interchange.

RecipientIdentification
String

Default Value: ""

The identification for the interchange's recipient.

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

RecipientIDQualifier
String

Default Value: ""

The qualifier for the recipient identification code.

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

RecipientInternalIdentification
String

Default Value: ""

More specific recipient identification for internal use.

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

RecipientInternalSubIdentification
String

Default Value: ""

A sub-identification string for the receiver for internal use.

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

RecipientPassword
String

Default Value: ""

A password to be verified by the recipient, such as a system or network password.

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

RecipientPasswordQualifier
String

Default Value: ""

A qualifier for the recipient password.

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

ReferenceNumber
String

Default Value: ""

A reference number for the interchange.

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

SenderIdentification
String

Default Value: ""

The identification for the interchange's sender.

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

SenderIDQualifier
String

Default Value: ""

The qualifier for the sender identification code.

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

SenderInternalIdentification
String

Default Value: ""

More specific sender identification for internal use.

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

SenderInternalSubIdentification
String

Default Value: ""

A sub-identification string for the sender for internal use.

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

SyntaxIdentifier
String

Default Value: ""

A identifier specifying the controlling agency and valid character set.

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

SyntaxVersionNumber
String

Default Value: ""

A 1-character numeric value indicating the syntax version.

TestIndicator
String

Default Value: ""

If this field is '1', the interchange is a test interchange.

Time
String

Default Value: ""

The time that the interchange was prepared.

Constructors

public EDIFACTInterchange();

EDIFACTMessage Type

An EDIFACT message.

Remarks

This type represents an EDIFACT message, with fields describing the values from the UNH segment.

The following fields are available:

Fields

AssociationAssignedCode
String

Default Value: ""

A code assigned to the message by the controlling organization.

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

CodeListVersionNumber
String

Default Value: ""

The version number of the code list that should be used.

This is an alphanumeric field with a value up to 6 characters long. This field only appears in EDIFACT syntax version 4.

CommonAccessReference
String

Default Value: ""

A reference value to associate this message with related messages.

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

ControllingAgency
String

Default Value: ""

A code that identifies the controlling agency for this message type.

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

FirstAndLastTransfer
String

Default Value: ""

A single-character field that indicates the first and last messages in a related set.

MessageImplControllingAgency
String

Default Value: ""

A code value that identifies the controlling agency for the message implementation.

This is an alphanumeric field with a value up to 3 characters long. This field only appears in EDIFACT syntax version 4.

MessageImplIdentification
String

Default Value: ""

Identifies the message implementation.

This is an alphanumeric field with a value up to 14 characters long. This field only appears in EDIFACT syntax version 4.

MessageImplRelease
String

Default Value: ""

Identifies the release number for the message implementation.

This is an alphanumeric field with a value up to 3 characters long. This field only appears in EDIFACT syntax version 4.

MessageImplVersion
String

Default Value: ""

Identifies the version number for the message implementation.

This is an alphanumeric field with a value up to 3 characters long. This field only appears in EDIFACT syntax version 4.

MessageRelease
String

Default Value: ""

Identifies the release number for the message.

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

MessageSubsetControllingAgency
String

Default Value: ""

A code value that identifies the controlling agency for the message subset.

This is an alphanumeric field with a value up to 3 characters long. This field only appears in EDIFACT syntax version 4.

MessageSubsetIdentification
String

Default Value: ""

Identifies the message subset.

This is an alphanumeric field with a value up to 14 characters long. This field only appears in EDIFACT syntax version 4.

MessageSubsetRelease
String

Default Value: ""

Identifies the release number for the message subset.

This is an alphanumeric field with a value up to 3 characters long. This field only appears in EDIFACT syntax version 4.

MessageSubsetVersion
String

Default Value: ""

Identifies the version number for the message subset.

This is an alphanumeric field with a value up to 3 characters long. This field only appears in EDIFACT syntax version 4.

MessageType
String

Default Value: ""

A code identifying the message's type.

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

MessageTypeSubFunctionIdentification
String

Default Value: ""

A code identifying the sub-function of the message's type.

This is an alphanumeric field with a value up to 6 characters long. This field only appears in EDIFACT syntax version 4.

MessageVersion
String

Default Value: ""

Identifies the version number for the message.

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

ReferenceNumber
String

Default Value: ""

A unique reference number for the message.

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

ScenarioControllingAgency
String

Default Value: ""

Identifies the controlling agency for the message scenario.

This is an alphanumeric field with a value up to 3 characters long. This field only appears in EDIFACT syntax version 4.

ScenarioIdentification
String

Default Value: ""

The identifier for the message scenario.

This is an alphanumeric field with a value up to 14 characters long. This field only appears in EDIFACT syntax version 4.

ScenarioRelease
String

Default Value: ""

The message scenario's release number.

This is an alphanumeric field with a value up to 3 characters long. This field only appears in EDIFACT syntax version 4.

ScenarioVersion
String

Default Value: ""

The message scenario's version number.

This is an alphanumeric field with a value up to 3 characters long. This field only appears in EDIFACT syntax version 4.

SequenceOfTransfers
String

Default Value: ""

Specifies the message's position in a sequence.

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

Constructors

public EDIFACTMessage();

Config Settings (EDIFACTWriter 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 (EDIFACTWriter Component)

EDIFACTWriter 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.