The first step in the process is to obtain the file or the set of files to be imported. When running the process you can specify an EDI file or an EDI processor. If you have selected a file, its import will be run directly, otherwise the class specified in the EDI Processor Type window is instanced via the selected processor.
The instanced class must return a list of temporary files that will be imported one by one.
An imported file can contain one or more documents. The transactions are managed at file level. If a file is not successfully imported, the information will be saved in the log, and you can roll back to the transaction and continue with the next file (without the file being partially imported, if it contains multiple documents). If the file is successfully imported, the information will be saved in the log (where you can specify the number of processed documents) and you will commit to the current transaction. If the import is done from a mail box, then the read message will be moved into a folder called "Processed" (only if it's been successfully imported, otherwise it will remain in the "Inbox". If the folder does not exist, then it will be created). Move to the next file.
The actual processing of an EDI file:
You must identify the special characters that are found in the file ("segment separator", "field separator", "composite separator", "release indicator"). These can be specified in the UNA segment, which can be found in the first line of the file, or can be sent by the EDI processor, via the parameters.
You must identify the UNH segment where you will extract the code of the import format that must have already been defined, otherwise an error will be generated. In other words, the UNH segment specifies which import format must be used.
Via the listener specified in the import format you will try to identify the document in the database for update. If it cannot be found, a new document will be created. In principal, the search will be done by the document number that comes from the EDI file on a certain position, which will differ from a format to another.
You must load a PO for the table specified in the format (either a new record will be created or an existing one will be updated, depending on the previous step: if the document has been found or not in the database). You must set, for the PO, the tenant, organization and warehouse specified in the import parameters and the default values defined at import format level (by running the callouts if there are any in these fields).
Start to effectively go through the file line by line. Note: the number of lines it contains must be greater or equal to the number of segments defined in the format, for the document. The mandatory segments are considered control keys and they must always land on the same position as the segment in the file. The most important elements in the format are the "Field" type ones, used to make the mapping between a piece of information in the file and the value of the field in SocrateCloud, otherwise the document in SocrateCloud will be filled in with values. Errors can appear here if the mapping cannot be completed (for example, we receive a product code that cannot be found in the database). In this case, the error is generated (saved in EDI Log) and you must move to the next file.
The end of the document is reached when meeting the UNT segment. UNT is a mandatory element used to verify the precision of the import. When going through the segments in the format you must land on the UNT, otherwise an error will be generated.
After going through all the segments, you must save the PO (the record in the database). You must call on the listener set on the print format with parameters indicating the actions "before save", "after save", in order to bring in possible additions before and after saving. If the PO cannot be successfully saved in the database, an error will be generated (this will be saved in the EDI Log) and you must move to the next file.
If the following segment in the file is UNH (Message Header) then the next document in the file will be imported by following the same steps until the end of the file has been reached