An exported EDI file can contain one or more documents. The transaction is at file level: you can either export all of them or none.
Note: In the case of export, the chances for errors are very small, the most frequent errors can appear on the side of communication with the FTP or SMTP server.
The processing of documents:
The first step is to identify the EDI processor and the export format you are working with. These information can be obtained from the EDI BPartner window depending on the parameters selected in the process, the business partner and the document type. This way you can configure different export formats for separate business partners and documents.
Establish the name of the exported file which is made up of the Subject field from the processor, to which you add the current date written in the format "yyyyMMddHHmmSS".
It is mandatory for the format to have defined all the special characters used, otherwise there will be exceptions. Based on the defined special characters fill in the first segment in the file (UNA).
Based on the table (or view) and on the WHERE clause specified in the format, make a select in the database to obtain a "Result Set" from which you will extract the values that will be sent to the EDI document. You will export as many documents as lines returned in the result set. Note: the table (or view) and the real table behind the exported document must contain the "IsEDISubmitted" column, which indicates whether a document has been exported or not, so as to not have it exported multiple times. If you wish to reprocess a document it is sufficient to remove the checkbox and run the process.
Go through the export format and write the EDI file. The most important elements here are the constants that go into the file as defined and the Field type constants which draw their data from the selected view/table in the format via the created result set.
The class specified in the EDI Processor Type window responsible with sending the files via FTP or SMTP is loaded through the use of the processor. You must try to send the file and, if unsuccessful, save the log, roll back and exit the error process. Otherwise, save the information in the log and leave the process.