XMLport (export) problem with temp table

clockworktoyclockworktoy Member Posts: 5
would like to know if XML Port (with Export Direction) can work with temporary table?

I have a XMLItem called "Item" in my xml port with Source Table = Item (table 27), Temporary = YES

Then I pass the Temp table record "l_recItem" to the xmlport in my Codeunit as below :

XMLPORT.EXPORT(XMLPORT::"Export Item",l_strTestStream,l_recItem);

Then I got the following error:
The Export Item XMLport does not have a XMLItem that uses the table(Table 27 Item) specified
in the function SetTableView


If I change back to Temporary = NO for both variable "l_recItem" & XMLItem "Item" , no error occur & xml file are generated.

But somehow I need to make it as temporary table ... any idea or workaround?

(my version is 5.0sp1 SQL db)

Thanks

Answers

  • clockworktoyclockworktoy Member Posts: 5
    problem solved by passing the temp table to the XML port with a seperate function rather than pass it as the paramater of the "Export".
    Thanks anyway. :P
  • Benno67Benno67 Member Posts: 39
    Hi ClockWorkToy,

    How did you manage to pass the temp table to the xmlport?
    After reading Vjeko's blog on temp table's:

    http://vjeko.com/blog/some-tips-and-hin ... #more-1264

    my conclusion was: no possibility to use temp tables on a xmlport.export

    Regards
    Benno
  • @Benno67 , in fact it is possible to use a temp table on an xmlport in the export direction. Just do what follows:
    1. Open the properties of the desired record node in your XMLPort and set it as TEMPORARY.
    2. Create a function which accepts as parameter a record of the same type with the signature VAR and TEMPORARY
    3. Take advantage of the Rec.COPY function to transfer data across the temporary tables. What is really important is to call it with the optional parameter ShareTable set to TRUE!
      SetTempRecord(VAR SourceTempRecord : TEMPORARY Record "Record_Type"){
          TempRecordUsedInXML.COPY(SourceTempRecord, TRUE);
      }
      
      In this way, you are not really copying data across tables, but you are making both tables sharing the same information, and this lets you achieve the same result.
    4. Set the function as non-local, so that it is callable from outside.
    5. In a Codeunit or wherever you need to call such export procedure, create a variable of type XMLPort and having as subtype the XMLPort you created.
    6. Call your function as
      XMLPort.SetTempRecord(RecordYouWantToExport)
      
      and then run your export with
      XMLPort.RUN
      
      .

    Note: what is explained on the article @Benno67 shared is true and important. Whenever you pass a variable by reference using the VAR keyword, the TEMPORARY keyword has no effect in setting the record passed as parameter as temporary. The record will remain so as it is: if you pass a temporary record it will be temporary, if you pass a "physical" record it will be physical, no matter what the TEMPORARY keyword says. Despite this, it is a good practice to put the TEMPORARY keyword anyway wherever you expect a temporary record to be passed as parameter, because it represent a nice hint to whoever will use the function in future o:)
Sign In or Register to comment.