Optimize code in code unit

kenneth73kenneth73 Member Posts: 59
edited 2014-10-27 in NAV Three Tier
Hi

Is it possible to optimize this code in a code unit :


varXmlFile.CREATE('D:\Support_NAV\PROGRAMMERING\REPORTS\CD_FieldsSalesInvoice.csv');
varXmlFile.CREATEOUTSTREAM(varOutputStream);
XMLPORT.EXPORT(XMLPORT::CD_FieldsSalesInvoice, varOutputStream);
varXmlFile.CLOSE;

varXmlFile.CREATE('D:\Support_NAV\PROGRAMMERING\REPORTS\CD_FieldsSalesCrMemo.csv');
varXmlFile.CREATEOUTSTREAM(varOutputStream);
XMLPORT.EXPORT(XMLPORT::CD_FieldsSalesCrMemo, varOutputStream);
varXmlFile.CLOSE;

varXmlFile.CREATE('D:\Support_NAV\PROGRAMMERING\REPORTS\CD_FieldsSalesShipment.csv');
varXmlFile.CREATEOUTSTREAM(varOutputStream);
XMLPORT.EXPORT(XMLPORT::CD_FieldsSalesShipment, varOutputStream);
varXmlFile.CLOSE;

LIKE THIS :

#Export(CD_FieldsSalesInvoice)
#Export(CD_FieldsSalesCrMemo)
#Export(CD_FieldsSalesShipment)

Answers

  • lyngelynge Member Posts: 85
    Hi Kenneth

    I guess you mean optimize the code for maintenance and not for performance?

    You don't have macros (like in XAL) in C/AL. But you should declare a new function - probably with two parameters:
    XMLPortToRun: Integer
    Filename: Text

    The function (Lets call it XMLExport) should contain something like:
    ---
    varXmlFile.CREATE(Filename);
    varXmlFile.CREATEOUTSTREAM(varOutputStream);
    XMLPORT.EXPORT(XMLPortToRun, varOutputStream);
    varXmlFile.CLOSE;
    ---
    ...and should have varXmlFile declared as a local variable...

    And you could call it this way:
    XMLExport('D:\Support_NAV\PROGRAMMERING\REPORTS\CD_FieldsSalesInvoice.csv', XMLPORT::CD_FieldsSalesInvoice);
    XMLExport('D:\Support_NAV\PROGRAMMERING\REPORTS\CD_FieldsSalesCrMemo.csv', XMLPORT::CD_FieldsSalesCrMemo);
    XMLExport('D:\Support_NAV\PROGRAMMERING\REPORTS\CD_FieldsSalesShipment.csv', XMLPORT::CD_FieldsSalesShipment);
Sign In or Register to comment.