Create Header in XMLPORT CSV file

Hello every one!
I’m new here and i’m new dev in AL.
So, need to export CSV file from DB and i need have header for each column
This is my xmlport
Thx for your help

xmlport 50027 LepExportPricesCSV
{
    Direction = Export;
    Format = VariableText;
    TextEncoding = UTF8;
    FileName = 'ARTICLES_TARIFS.csv';
    Caption = 'Export des tarifs';
    UseRequestPage = false;
    FieldDelimiter = '';
    FieldSeparator = ';';
    RecordSeparator = ';<CR><LF>';

    schema
    {
        textelement(Root)
        {

            tableelement("SalesPriceWorksheet";"Sales Price Worksheet")
            {
                fieldelement(campage; SalesPriceWorksheet."Campaign No.") {}
                fieldelement(codeArticle; SalesPriceWorksheet."Item No.") {}
                fieldelement(startingDate; SalesPriceWorksheet."Starting Date") {}
                fieldelement(endingDate; SalesPriceWorksheet."Ending Date") {}
                fieldelement(price; SalesPriceWorksheet."Current Unit Price") {}
            }
        }
    }
    
}```

Hi @GD276,

You cannot add column names in a XmlPort… try to use CSV Buffer table.

Thank you for your prompt reply.
Have you got an example, please ?
I will give it a try.

Doing some searching, I’ve found some usefull links:

This is an example from last link:

// Code to Export data in CSV file
 
    procedure ExportCustomersToCSV()
    var
        LineNo: Integer;
        TempCSVBuffer: Record "CSV Buffer" temporary;
        Customer: Record Customer;
        filePath: Text;
    begin
        LineNo := 1;
        TempCSVBuffer.InsertEntry(LineNo, 1, 'Customer No.');
        TempCSVBuffer.InsertEntry(LineNo, 2, 'Customer Name');
        TempCSVBuffer.InsertEntry(LineNo, 3, 'Customer Address');
        if Customer.FindSet() then
            repeat
                LineNo += 1;               
                TempCSVBuffer.InsertEntry(LineNo, 1, Customer."No.");
                TempCSVBuffer.InsertEntry(LineNo, 2, Customer.Name);
                TempCSVBuffer.InsertEntry(LineNo, 3, Customer.Address);
            until Customer.Next() = 0;
        TempCSVBuffer.SaveData('C:\ExportedCSV\Customer.csv', ',');
    end;

You have to change the last line to save data and use “SaveDataToBlob” or others that allows you to use in SaaS environment.

THX, I found it too. I’m working on it.
Thx for the tip on the method.

If it helps anyone:
EXPORT CSV file with headers

procedure ExportCSV();
var
    salesPrice: Record "Sales Price Worksheet";
    TempBlobVar: Record TempBlob;
    OutStream: OutStream;
    InStream: InStream;
    CSVFieldSeparator: Text;
    FileName: Text;
    CR: Char;
    LF: Char;
    currentYear: Integer;
    lastYear: Integer;
    nextYear: Integer;
    formatCurrentYear: Text;
    formatLastYear: Text;
    formatNextYear: Text;

begin
    CSVFieldSeparator := ';';
    FileName := ' nameOfFile.csv';
    CR := 13;
    LF := 10;
    currentYear := DATE2DMY(Today, 3);
    lastYear := currentYear - 1;
    nextYear:= currentYear + 1;

    formatCurrentYear := Format(currentYear);
    formatLastYear := Format(lastYear);  
    formatNextYear := Format(nextYear); 

    TempBlobVar.blob.CREATEOUTSTREAM(OutStream, TextEncoding::UTF8);
    
    OutStream.WRITETEXT('CAMPAiGN');
    OutStream.WRITETEXT(CSVFieldSeparator);
    OutStream.WRITETEXT('CODE ITEM');
    OutStream.WRITETEXT(CSVFieldSeparator);
    OutStream.WRITETEXT('STARTING DATE);
    OutStream.WRITETEXT(CSVFieldSeparator);
    OutStream.WRITETEXT('ENDING DATE');
    OutStream.WRITETEXT(CSVFieldSeparator);
    OutStream.WRITETEXT('UNIT PRICE');
    OutStream.WRITETEXT(Format(CR) + Format(LF));
    
    salesPrice.SetFilter("Campaign No.",'=' + formatLastYear + '|' + '=' + formatCurrentYear + '|' + '=' + formatNextYear);

    IF salesPrice.FINDSET THEN BEGIN
        REPEAT

            OutStream.WRITETEXT(salesPrice."Campaign No.");
            OutStream.WRITETEXT(CSVFieldSeparator);
            OutStream.WRITETEXT(salesPrice."Item No.");
            OutStream.WRITETEXT(CSVFieldSeparator);
            OutStream.WRITETEXT(FORMAT(salesPrice."Starting Date"));
            OutStream.WRITETEXT(CSVFieldSeparator);
            OutStream.WRITETEXT(FORMAT(salesPrice."Ending Date"));
            OutStream.WRITETEXT(CSVFieldSeparator);
            OutStream.WRITETEXT(FORMAT(salesPrice."Current Unit Price"));
            OutStream.WRITETEXT(Format(CR) + Format(LF));
        UNTIL salesPrice.NEXT = 0;
        TempBlobVar.blob.CREATEINSTREAM(InStream, TextEncoding::UTF8);
    END;
    DownloadFromStream(InStream, '', '', '', FileName);
    
end;