X12Writer Control
Properties Methods Events Config Settings Errors
The X12Writer control generates X12 documents with a clear, straightforward API.
Syntax
X12Writer
Remarks
The control allows you to create an EDI document from scratch, one segment at a time. Here's how a document would normally be created:
- Call LoadSchema to load the necessary schemas for the transactions that will be used.
- Specify where to write the output document by setting the OutputFile, or check the OutputData property after writing.
- 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.
- 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.
- To start a transaction, call the StartTransactionSet method. Once all segments have been added, call EndTransactionSet to add a footer to the transaction.
- 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.
- To write a basic element to the current segment, call the WriteElement method.
- 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 control with short descriptions. Click on the links for further details.
| DelimiterComponent | The delimiter separating controls. |
| DelimiterElement | The delimiter separating elements. |
| DelimiterRepetition | The delimiter separating controls. |
| DelimiterSegment | The delimiter separating segments. |
| FileWriteMode | Determines how the output file is opened for writing. |
| FGroupAppReceiverCode | The name or code of the intended receiver of the transaction set group. |
| FGroupAppSenderCode | Code identifying the sender of FunctionalGroup This is an alphanumeric property with a value between 2 and 15 characters long. |
| FGroupDate | The date that the group of transaction sets was prepared. |
| FGroupFunctionalIdentifierCode | A code identifying the type of transaction sets included in the functional group. |
| FGroupGroupControlNum | An identification number assigned by the sender to uniquely identify the group of transaction sets. |
| FGroupResponsibleAgencyCode | A code identifying the issuer of the standard that the transaction set conforms to. |
| FGroupTime | The time that the group of transaction sets was prepared. |
| FGroupVersion | Code indicating the version of the X12 standard used to construct the transaction set. |
| InterchangeAckRequest | Code indicating whether an interchange acknowledgment is requested. |
| InterchangeAuthorizationInfo | Information used for additional identification or authorization of the interchange sender or the data in the interchange. |
| InterchangeAuthorizationInfoQualifier | A code indicating the type of data supplied in Authorization Information property. |
| InterchangeDate | The date that the Interchange was prepared. |
| InterchangeInterchangeControlNum | A control number assigned by the sender to uniquely identify the interchange. |
| InterchangeInterchangeControlVersionNum | A code specifying the version of the X12 standard used to construct the Interchange. |
| InterchangeReceiverID | The identification code of the receiver of the transaction set. |
| InterchangeReceiverIDQualifier | A code that identifies the format of the receiver ID. |
| InterchangeSecurityInfo | Coded security information associated with the Interchange. |
| InterchangeSecurityInfoQualifier | A code indicating the type of data in the Security Information property. |
| InterchangeSenderID | The identification code of the sender of the transaction set. |
| InterchangeSenderIDQualifier | A code that identifies the format of the sender ID. |
| InterchangeTime | The time that the Interchange sets was prepared. |
| InterchangeUsageIndicator | Code to indicate whether the interchange is a test or production. |
| OutputData | The output data that has been written so far. |
| OutputFile | The name of the output file to which the EDI data will be written. |
| SegmentSuffix | The suffix that is appended to the end of a segment. |
| TransSetImpConventionReference | Reference used to identify the implementation convention. |
| TransSetTransactionSetControlNum | The unique transaction set control number assigned for a transaction set. |
| TransSetTransactionSetIDCode | The identifier code for the transaction set. |
Method List
The following is the full list of the methods of the control with short descriptions. Click on the links for further details.
| Close | Closes the writer. |
| Config | Sets or retrieves a configuration setting. |
| EndCompositeElement | Closes the current composite element. |
| EndFunctionalGroup | Closes the current functional group. |
| EndInterchange | Closes the current interchange. |
| EndSegment | Finish writing the current segment. |
| EndTransactionSet | Closes the current transaction set. |
| Reset | Resets all properties to their default values. |
| StartCompositeElement | Starts a composite element within the current segment. |
| StartFunctionalGroup | Starts a new functional group in the EDI document. |
| StartInterchange | Starts a new interchange in the EDI document. |
| StartSegment | Starts a new segment with the specified tag. |
| StartTransactionSet | Starts a new transaction set in the EDI document. |
| WriteComponent | Writes a control element value to the current composite element. |
| WriteElement | Writes an element value to the current segment. |
Event List
The following is the full list of the events fired by the control with short descriptions. Click on the links for further details.
| Error | Fires when an error occurs during message processing. Normally, the control fails with an error. |
| Output | Fires when output data is written. |
Config Settings
The following is a list of config settings for the control with short descriptions. Click on the links for further details.
DelimiterComponent Property (X12Writer Control)
The delimiter separating controls.
Syntax
x12writercontrol.DelimiterComponent[=string]
Default Value
":"
Remarks
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
This property is not available at design time.
Data Type
String
DelimiterElement Property (X12Writer Control)
The delimiter separating elements.
Syntax
x12writercontrol.DelimiterElement[=string]
Default Value
"*"
Remarks
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
This property is not available at design time.
Data Type
String
DelimiterRepetition Property (X12Writer Control)
The delimiter separating controls.
Syntax
x12writercontrol.DelimiterRepetition[=string]
Default Value
"^"
Remarks
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
This property is not available at design time.
Data Type
String
DelimiterSegment Property (X12Writer Control)
The delimiter separating segments.
Syntax
x12writercontrol.DelimiterSegment[=string]
Default Value
"~"
Remarks
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
This property is not available at design time.
Data Type
String
FileWriteMode Property (X12Writer Control)
Determines how the output file is opened for writing.
Syntax
x12writercontrol.FileWriteMode[=integer]
Possible Values
fwmCreate(0), fwmOverwrite(1), 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. |
| fwmOverwrite | Opens an existing file and overwrites its contents. If the file does not exist, a new file will be created. |
| fwmAppend | Opens 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.
Data Type
Integer
FGroupAppReceiverCode Property (X12Writer Control)
The name or code of the intended receiver of the transaction set group.
Syntax
x12writercontrol.FGroupAppReceiverCode[=string]
Default Value
""
Remarks
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.
This property is not available at design time.
Data Type
String
FGroupAppSenderCode Property (X12Writer Control)
Code identifying the sender of FunctionalGroup This is an alphanumeric property with a value between 2 and 15 characters long.
Syntax
x12writercontrol.FGroupAppSenderCode[=string]
Default Value
""
Remarks
Code identifying the sender of FunctionalGroup
This is an alphanumeric field with a value between 2 and 15 characters long.
This property is not available at design time.
Data Type
String
FGroupDate Property (X12Writer Control)
The date that the group of transaction sets was prepared.
Syntax
x12writercontrol.FGroupDate[=string]
Default Value
""
Remarks
The date that the group of transaction sets was prepared.
This is a numeric field with a value in the format YYMMDD.
This property is not available at design time.
Data Type
String
FGroupFunctionalIdentifierCode Property (X12Writer Control)
A code identifying the type of transaction sets included in the functional group.
Syntax
x12writercontrol.FGroupFunctionalIdentifierCode[=string]
Default Value
""
Remarks
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.
This property is not available at design time.
Data Type
String
FGroupGroupControlNum Property (X12Writer Control)
An identification number assigned by the sender to uniquely identify the group of transaction sets.
Syntax
x12writercontrol.FGroupGroupControlNum[=string]
Default Value
""
Remarks
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.
This property is not available at design time.
Data Type
String
FGroupResponsibleAgencyCode Property (X12Writer Control)
A code identifying the issuer of the standard that the transaction set conforms to.
Syntax
x12writercontrol.FGroupResponsibleAgencyCode[=string]
Default Value
""
Remarks
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.
This property is not available at design time.
Data Type
String
FGroupTime Property (X12Writer Control)
The time that the group of transaction sets was prepared.
Syntax
x12writercontrol.FGroupTime[=string]
Default Value
""
Remarks
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.
This property is not available at design time.
Data Type
String
FGroupVersion Property (X12Writer Control)
Code indicating the version of the X12 standard used to construct the transaction set.
Syntax
x12writercontrol.FGroupVersion[=string]
Default Value
""
Remarks
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.
This property is not available at design time.
Data Type
String
InterchangeAckRequest Property (X12Writer Control)
Code indicating whether an interchange acknowledgment is requested.
Syntax
x12writercontrol.InterchangeAckRequest[=string]
Default Value
""
Remarks
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).
This property is not available at design time.
Data Type
String
InterchangeAuthorizationInfo Property (X12Writer Control)
Information used for additional identification or authorization of the interchange sender or the data in the interchange.
Syntax
x12writercontrol.InterchangeAuthorizationInfo[=string]
Default Value
""
Remarks
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.
This property is not available at design time.
Data Type
String
InterchangeAuthorizationInfoQualifier Property (X12Writer Control)
A code indicating the type of data supplied in Authorization Information property.
Syntax
x12writercontrol.InterchangeAuthorizationInfoQualifier[=string]
Default Value
""
Remarks
A code indicating the type of data supplied in Authorization Information field.
This is an alphanumeric field with a code value of 2 characters.
This property is not available at design time.
Data Type
String
InterchangeDate Property (X12Writer Control)
The date that the Interchange was prepared.
Syntax
x12writercontrol.InterchangeDate[=string]
Default Value
""
Remarks
The date that the Interchange was prepared.
This is a numeric field with a value of 6 digits in the format YYMMDD.
This property is not available at design time.
Data Type
String
InterchangeInterchangeControlNum Property (X12Writer Control)
A control number assigned by the sender to uniquely identify the interchange.
Syntax
x12writercontrol.InterchangeInterchangeControlNum[=string]
Default Value
""
Remarks
A control number assigned by the sender to uniquely identify the interchange.
This is a numeric field with a value of 9 digits.
This property is not available at design time.
Data Type
String
InterchangeInterchangeControlVersionNum Property (X12Writer Control)
A code specifying the version of the X12 standard used to construct the Interchange.
Syntax
x12writercontrol.InterchangeInterchangeControlVersionNum[=string]
Default Value
""
Remarks
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.
This property is not available at design time.
Data Type
String
InterchangeReceiverID Property (X12Writer Control)
The identification code of the receiver of the transaction set.
Syntax
x12writercontrol.InterchangeReceiverID[=string]
Default Value
""
Remarks
The identification code of the receiver of the transaction set.
This is an alphanumeric field with a value of 15 characters.
This property is not available at design time.
Data Type
String
InterchangeReceiverIDQualifier Property (X12Writer Control)
A code that identifies the format of the receiver ID.
Syntax
x12writercontrol.InterchangeReceiverIDQualifier[=string]
Default Value
""
Remarks
A code that identifies the format of the receiver ID.
This is an alphanumeric field with a code value of 2 characters.
This property is not available at design time.
Data Type
String
InterchangeSecurityInfo Property (X12Writer Control)
Coded security information associated with the Interchange.
Syntax
x12writercontrol.InterchangeSecurityInfo[=string]
Default Value
""
Remarks
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.
This property is not available at design time.
Data Type
String
InterchangeSecurityInfoQualifier Property (X12Writer Control)
A code indicating the type of data in the Security Information property.
Syntax
x12writercontrol.InterchangeSecurityInfoQualifier[=string]
Default Value
""
Remarks
A code indicating the type of data in the Security Information field.
This is an alphanumeric field with a code value of 2 characters.
This property is not available at design time.
Data Type
String
InterchangeSenderID Property (X12Writer Control)
The identification code of the sender of the transaction set.
Syntax
x12writercontrol.InterchangeSenderID[=string]
Default Value
""
Remarks
The identification code of the sender of the transaction set.
This is an alphanumeric field with a value of 15 characters.
This property is not available at design time.
Data Type
String
InterchangeSenderIDQualifier Property (X12Writer Control)
A code that identifies the format of the sender ID.
Syntax
x12writercontrol.InterchangeSenderIDQualifier[=string]
Default Value
""
Remarks
A code that identifies the format of the sender ID.
This is an alphanumeric field with a code value of 2 characters.
This property is not available at design time.
Data Type
String
InterchangeTime Property (X12Writer Control)
The time that the Interchange sets was prepared.
Syntax
x12writercontrol.InterchangeTime[=string]
Default Value
""
Remarks
The time that the Interchange sets was prepared.
This is a numeric field with a value in the format HHMM.
This property is not available at design time.
Data Type
String
InterchangeUsageIndicator Property (X12Writer Control)
Code to indicate whether the interchange is a test or production.
Syntax
x12writercontrol.InterchangeUsageIndicator[=string]
Default Value
""
Remarks
Code to indicate whether the interchange is a test or production.
This is an alphanumeric field with a code value of 1 character.
This property is not available at design time.
Data Type
String
OutputData Property (X12Writer Control)
The output data that has been written so far.
Syntax
x12writercontrol.OutputData[=string]
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.
Data Type
String
OutputFile Property (X12Writer Control)
The name of the output file to which the EDI data will be written.
Syntax
x12writercontrol.OutputFile[=string]
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.
Data Type
String
SegmentSuffix Property (X12Writer Control)
The suffix that is appended to the end of a segment.
Syntax
x12writercontrol.SegmentSuffix[=integer]
Possible Values
ssNone(0), ssCR(1), ssLF(2), 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.
Data Type
Integer
TransSetImpConventionReference Property (X12Writer Control)
Reference used to identify the implementation convention.
Syntax
x12writercontrol.TransSetImpConventionReference[=string]
Default Value
""
Remarks
Reference used to identify the implementation convention.
This is an alphanumeric field with a value up to 35 characters long.
This property is not available at design time.
Data Type
String
TransSetTransactionSetControlNum Property (X12Writer Control)
The unique transaction set control number assigned for a transaction set.
Syntax
x12writercontrol.TransSetTransactionSetControlNum[=string]
Default Value
""
Remarks
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.
This property is not available at design time.
Data Type
String
TransSetTransactionSetIDCode Property (X12Writer Control)
The identifier code for the transaction set.
Syntax
x12writercontrol.TransSetTransactionSetIDCode[=string]
Default Value
""
Remarks
The identifier code for the transaction set.
This is an alphanumeric field with a code value of 3 characters long.
This property is not available at design time.
Data Type
String
Close Method (X12Writer Control)
Closes the writer.
Syntax
x12writercontrol.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 Control)
Sets or retrieves a configuration setting.
Syntax
x12writercontrol.Config ConfigurationString
Remarks
Config is a generic method available in every control. It is used to set and retrieve configuration settings for the control.
These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the control, 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 Control)
Closes the current composite element.
Syntax
x12writercontrol.EndCompositeElement
Remarks
Calling EndCompositeElement will close the current composite element. If no composite element is open, an error will be raised.
EndFunctionalGroup Method (X12Writer Control)
Closes the current functional group.
Syntax
x12writercontrol.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 Control)
Closes the current interchange.
Syntax
x12writercontrol.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 Control)
Finish writing the current segment.
Syntax
x12writercontrol.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 Control)
Closes the current transaction set.
Syntax
x12writercontrol.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 Control)
Resets all properties to their default values.
Syntax
x12writercontrol.Reset
Remarks
This method resets all properties of the component to their default values as specified in the property definitions.
StartCompositeElement Method (X12Writer Control)
Starts a composite element within the current segment.
Syntax
x12writercontrol.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 Control)
Starts a new functional group in the EDI document.
Syntax
x12writercontrol.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 Control)
Starts a new interchange in the EDI document.
Syntax
x12writercontrol.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 Control)
Starts a new segment with the specified tag.
Syntax
x12writercontrol.StartSegment 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 Control)
Starts a new transaction set in the EDI document.
Syntax
x12writercontrol.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 Control)
Writes a control element value to the current composite element.
Syntax
x12writercontrol.WriteComponent 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 Control)
Writes an element value to the current segment.
Syntax
x12writercontrol.WriteElement 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 Control)
Fires when an error occurs during message processing. Normally, the control fails with an error.
Syntax
Sub x12writercontrol_Error(ErrorCode As Integer, Description As String)
Remarks
The Error event is fired in case of exceptional conditions during message processing. Normally, the control fails with an error.
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 Control)
Fires when output data is written.
Syntax
Sub x12writercontrol_Output(Data As String)
Remarks
This event is fired when output data is written. The Data parameter contains the segment that was written.
Config Settings (X12Writer Control)
The control 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 control, access to these internal properties is provided through the Config method.Trappable Errors (X12Writer Control)
X12Writer Errors
| 20203 | Invalid argument. |
| 20305 | Cannot write to file. |
| 21100 | Encountered an unexpected segment tag. |
| 21101 | Attempted to perform an action while the component was busy, or close an incomplete interchange. |
| 21206 | Tried to perform an operation in a bad state (such as ending an interchange before starting one). |
| 21207 | Tried to end an interchange with no contents. |