Append IFTSTA messages into same interchange.



  • Avatar
    Don Zoeggerle

    Hello Hayo,

    You can write any number of messages to a stream. If you know how to do it with one then you know how to do it with more, just write each message to the stream. In the SDK (download from here), you can find multiple examples on writing EDI messages.

    This one in particularWriteMultipleInvoices() example, shows how to write two transactions.

    using (var stream = new MemoryStream())
    using (var writer = new EdifactWriter(stream))

    // 1. Write the first invoice

    // 2. Write the second invoice

    // 3. Write any subsequent invoices...
    Comment actions Permalink
  • Avatar


    Thank you, in this situation, you write all of them at the same time to a file. 
    What i am looking at is, that at 8am, we start the file with interchange and 1 message
    at 8:05am we append a message to the file.
    At 8:10am we append a message and close the interchange

    Now based on this i could read the file, empty it and rewrite it. But is there another way? that just adds a message to an existing interchange in a file

    Comment actions Permalink
  • Avatar
    Don Zoeggerle (Edited )

    If you need to write messages to the same file at different times, then you can't use the writer as it automatically closes the headers.

    So you'll have to build UNB segment yourself as a string (we can add this feature in the next version) and do:

    1. Create UNB as string and write it to a file, let's say C:\myfile.txt

    string unb = // create it

    File.CreateAllText("C:\myfile.txt", unb);

    2. After some time, create an instance of TSIFTSTA 

    TSIFTSTA iftsta_1 = // create the object

    3. Turn it to a string, set separators, postfixes, etc, if you need to in EdifactWriterSettings

    string edi_1 = iftsta_1.ToEdi(new EdifactWriterSettings());

    4. Append the string to the file

    File.AppendAllText("C:\myfile.txt", edi_1);

    5. After some time create another iftsta and append it to the file:

    TSIFTSTA iftsta_2 = // create it

    string edi_2 = iftsta_2.ToEdi(new EdifactWriterSettings());

    File.AppendAllText("C:\myfile.txt", edi_2);

    6. Append as many IFTSTA as you need...

    7. Manually create a UNZ as a string and write it to the end of the file (either maintain a counter or count the UNH occurrences in the file):

    string unz = // create it

    File.AppendAllText("C:\myfile.txt", unz);
    Comment actions Permalink
  • Avatar

    Thank you, i got it working.

    Comment actions Permalink

Please sign in to leave a comment.