Translate Method

Translates the specified data.

Syntax

ANSI (Cross Platform)
int Translate();

Unicode (Windows)
INT Translate();
- (void)translate;
#define MID_X12TRANSLATOR_TRANSLATE 14

IPWORKSX12_EXTERNAL int IPWORKSX12_CALL IPWorksX12_X12Translator_Do(void *lpObj, int methid, int cparam, void *param[], int cbparam[], int64 *lpllVal);

Remarks

This method translates the specified data.

The class will convert a document from the format specified by InputFormat to the format specified by OutputFormat. In practice this allows for converting to XML or JSON from EDI and vice versa.

Before translating from EDI to XML or JSON it is recommended to load a schema using the LoadSchema method. This ensures additional information can be included in the XML or JSON document. If a schema is specified the XML or JSON will include types and descriptions as element attributes which are useful for interpreting the data.

EDI elements may optionally be renamed when creating XML. To define how an element is renamed add a renaming rule by calling AddRenamingRule.

After calling Translate the resulting output will contain the EDI, XML or JSON data as defined by OutputFormat. If the output data is XML the ExportXMLSchema method may be called to export a schema (.xsd) defining the structure of a valid XML document. XML documents which adhere to this document may be translated from XML to EDI.

Input and Output Properties

The class will determine the source and destination of the input and output based on which properties are set.

The order in which the input properties are checked is as follows:

When a valid source is found the search stops. The order in which the output properties are checked is as follows:
  • OutputFile
  • OutputData: The output data is written to this property if no other destination is specified.

Example - Translating X12 to XML


X12translator translator = new X12translator();
translator.InputFormat = X12translatorInputFormats.ifX12;
translator.OutputFormat = X12translatorOutputFormats.ofXML;

translator.InputFile = "810.edi";
translator.OutputFile = "X12_810.xml";

translator.UseSchemaName = true;

translator.SchemaFormat = X12translatorSchemaFormats.schemaJSON;
translator.LoadSchema("RSSBus_00401_810.json");

translator.Translate();

The code above creates an XML document with content like:

<Interchange xmlns="http://www.nsoftware.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Meta>
        <ISA01 desc="Authorization Information Qualifier">00</ISA01>
        <ISA02 desc="Authorization Information">          </ISA02>
        <ISA03 desc="Security Information Qualifer">00</ISA03>
        <ISA04 desc="Security Information">          </ISA04>
        <ISA05 desc="Interchange ID Qualifier">14</ISA05>
        <ISA06 desc="Interchange Sender ID">060704780001900</ISA06>
        <ISA07 desc="Interchange ID Qualifier">ZZ</ISA07>
        <ISA08 desc="Interchange Receiver ID">HYNIXEDI       </ISA08>
        <ISA09 desc="Interchange Date">130428</ISA09>
        <ISA10 desc="Interchange Time">2033</ISA10>
        <ISA11 desc="Interchange Control Standards Identifier">U</ISA11>
        <ISA12 desc="Interchange Control Version Number Code">00401</ISA12>
        <ISA13 desc="Inter Control Number">000040161</ISA13>
        <ISA14 desc="Acknowlegment Requested Code">1</ISA14>
        <ISA15 desc="Interchange Usage Indicator Code">T</ISA15>
        <ISA16 desc="Component Element Separator">&gt;</ISA16>
    </Meta>
    <FunctionalGroup>
        <Meta>
            <GS01 desc="Functional Identifier Code">IN</GS01>
            <GS02 desc="Application Sender&apos;s Code">060704780500</GS02>
            <GS03 desc="Application Receiver&apos;s Code">HYNIXEDI</GS03>
            <GS04 desc="Date">20130428</GS04>
            <GS05 desc="Time">2033</GS05>
            <GS06 desc="Group Control Number">000040161</GS06>
            <GS07 desc="Responsible Agency Code">X</GS07>
            <GS08 desc="Version / Release / Industry Identifier Code">004010</GS08>
        </Meta>
        <TransactionSet>
            <TX-00401-810 type="TransactionSet">
                <Meta>
                    <ST01 desc="Transaction Set Identifier Code">810</ST01>
                    <ST02 desc="Transaction Set Control Number">0001</ST02>
                </Meta>
                <BIG type="Segment">
                    <BIG01 desc="Date">20090629</BIG01>
                    <BIG02 desc="Invoice Number">3003014445</BIG02>
                    <BIG03 desc="Date" xsi:nil="true"/>
                    <BIG04 desc="Purchase Order Number">0476553272</BIG04>
                    <BIG05 desc="Release Number" xsi:nil="true"/>
                    <BIG06 desc="Change Order Sequence Number" xsi:nil="true"/>
                    <BIG07 desc="Transaction Type Code">DR</BIG07>
                </BIG>
...                

Example - Translating X12 to JSON


X12translator translator = new X12translator();
translator.InputFormat = X12translatorInputFormats.ifX12;
translator.OutputFormat = X12translatorOutputFormats.ofJSON;

translator.InputFile = "810.edi";
translator.OutputFile = "X12_810.json";

translator.UseSchemaName = true;

translator.SchemaFormat = X12translatorSchemaFormats.schemaJSON;
translator.LoadSchema("RSSBus_00401_810.json");

translator.Translate();

The code above creates a JSON document with content like:

{
	"meta": {
		"type": "Interchange",
		"ISA01": {
			"desc": "Authorization Information Qualifier",
			"value": "00"
		},
		"ISA02": {
			"desc": "Authorization Information",
			"value": "          "
		},
		"ISA03": {
			"desc": "Security Information Qualifer",
			"value": "00"
		},
		"ISA04": {
			"desc": "Security Information",
			"value": "          "
		},
		"ISA05": {
			"desc": "Interchange ID Qualifier",
			"value": "14"
		},
		"ISA06": {
			"desc": "Interchange Sender ID",
			"value": "060704780001900"
		},
		"ISA07": {
			"desc": "Interchange ID Qualifier",
			"value": "ZZ"
		},
		"ISA08": {
			"desc": "Interchange Receiver ID",
			"value": "HYNIXEDI       "
		},
		"ISA09": {
			"desc": "Interchange Date",
			"value": "130428"
		},
		"ISA10": {
			"desc": "Interchange Time",
			"value": "2033"
		},
		"ISA11": {
			"desc": "Interchange Control Standards Identifier",
			"value": "U"
		},
		"ISA12": {
			"desc": "Interchange Control Version Number Code",
			"value": "00401"
		},
		"ISA13": {
			"desc": "Inter Control Number",
			"value": "000040161"
		},
		"ISA14": {
			"desc": "Acknowlegment Requested Code",
			"value": "1"
		},
		"ISA15": {
			"desc": "Interchange Usage Indicator Code",
			"value": "T"
		},
		"ISA16": {
			"desc": "Component Element Separator",
			"value": ">"
		}
	},
	"functionalgroups": [{
		"meta": {
			"type": "FunctionalGroup",
			"GS01": {
				"desc": "Functional Identifier Code",
				"value": "IN"
			},
			"GS02": {
				"desc": "Application Sender's Code",
				"value": "060704780500"
			},
			"GS03": {
				"desc": "Application Receiver's Code",
				"value": "HYNIXEDI"
			},
			"GS04": {
				"desc": "Date",
				"value": "20130428"
			},
			"GS05": {
				"desc": "Time",
				"value": "2033"
			},
			"GS06": {
				"desc": "Group Control Number",
				"value": "000040161"
			},
			"GS07": {
				"desc": "Responsible Agency Code",
				"value": "X"
			},
			"GS08": {
				"desc": "Version \/ Release \/ Industry Identifier Code",
				"value": "004010"
			}
		},
		"transactionsets": [{
			"meta": {
				"type": "TransactionSet",
				"ST01": {
					"desc": "Transaction Set Identifier Code",
					"value": "810"
				},
				"ST02": {
					"desc": "Transaction Set Control Number",
					"value": "0001"
				}
			},
			"segments": [{
				"type": "Segment",
				"name": "BIG",
				"BIG01": {
					"desc": "Date",
					"value": "20090629"
				},
				"BIG02": {
					"desc": "Invoice Number",
					"value": "3003014445"
				},
				"BIG03": {
					"desc": "Date",
					"value": null
				},
				"BIG04": {
					"desc": "Purchase Order Number",
					"value": "0476553272"
				},
				"BIG05": {
					"desc": "Release Number",
					"value": null
				},
				"BIG06": {
					"desc": "Change Order Sequence Number",
					"value": null
				},
				"BIG07": {
					"desc": "Transaction Type Code",
					"value": "DR"
				}
			},
...            

Error Handling (C++)

This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks X12 2020 C++ Edition - Version 20.0 [Build 8155]