How as change a file csv?

hugoistihugoisti Member Posts: 26
Hello experts, I am creating a file from sql with a SP, once created this file I have to add a row to the file.
Was reading and I add the line, the problem is that no moves the lines that were already, the writes on.
The code that use is the following

IF EXISTS(Path + 'Compel_stg.csv') THEN
BEGIN
g_fileCompel.TEXTMODE := TRUE;
g_fileCompel.WRITEMODE := TRUE;
IF (g_fileCompel.OPEN(Path + 'Compel_stg.csv')) THEN
BEGIN

g_fileCompel.CREATEOUTSTREAM(oStream);

oStream.WRITETEXT('Date,SalesCode,SalesTeam,RevenueCategory,RevenueType,Amount,');
oStream.WRITETEXT('order_date,order_no,invoice_no,year,quarter,month,salesrep,ori_salesteam,');
oStream.WRITETEXT('region,enduser_name,enduser_state,enduser_zipcode,area_code,item_code,item_desc,number_of_users,');
oStream.WRITETEXT('product_code,order_type_code,sales_type_code,reseller_name,dist_name,account_id,channel_type,');
oStream.WRITETEXT('order_source,gl_account_no,product_group_code,license_start_date,license_end_date,prod_start_date,');
oStream.WRITETEXT('prod_end_date,TransCode');
oStream.WRITETEXT();

g_fileCompel.CLOSE();

already proven of everything and is not that passes, someone known as I can fix this, since thanks
best regards.
Hugo

Comments

  • hugoistihugoisti Member Posts: 26
    thanks, but is not the result that I need, I have to insert the line above the because it is the header of Report
    some other idea?

    best regard
  • kapamaroukapamarou Member Posts: 1,152
    How about creating a 2nd file, writing the headers and then copying to it the contents of the 1st file?
  • SavatageSavatage Member Posts: 7,142
    just to be clear - you want to create a datafile & THEN add the column Headers??
  • hugoistihugoisti Member Posts: 26
    Exact, I have a SP that generates a file, then I must add the headers to columns that contains the file.
    In regard to the function to copy, exist? I do not know any,
    read in Navision and not find any you copy files. the other that remains is to generate a new file add the headers and then read from a file I have insert in the other. but it is not very efficient.
  • XypherXypher Member Posts: 297
    This code might be a little crude but I do believe it will help you find a solution...
    Name        DataType        Subtype        Length
    TmpBlob     Record          TempBlob	                   (Temporary := YES!; Dimensions := 2)
    fPath       Text                           1024
    oStream     OutStream		
    iStream     InStream
    
    fPath := 'C:\Documents And Settings\jwalker\Desktop\myfile.csv';
    
    TmpBlob[1].Blob.IMPORT(fPath);
    TmpBlob[1].Blob.CREATEINSTREAM(iStream);
    TmpBlob[2].Blob.CREATEOUTSTREAM(oStream);
    
    oStream.WRITETEXT('Date,SalesCode,SalesTeam,RevenueCategory,RevenueType,Amount,');
    oStream.WRITETEXT('order_date,order_no,invoice_no,year,quarter,month,salesrep,ori_salesteam,');
    oStream.WRITETEXT('region,enduser_name,enduser_state,enduser_zipcode,area_code,item_code,item_desc,number_of_users,');
    oStream.WRITETEXT('product_code,order_type_code,sales_type_code,reseller_name,dist_name,account_id,channel_type,');
    oStream.WRITETEXT('order_source,gl_account_no,product_group_code,license_start_date,license_end_date,prod_start_date,');
    oStream.WRITETEXT('prod_end_date,TransCode');
    oStream.WRITETEXT();
    
    COPYSTREAM(oStream,iStream);
    
    TmpBlob[2].Blob.EXPORT(fPath);
    

    Cheers! :wink:
  • hugoistihugoisti Member Posts: 26
    Fantastic!!!, walked very well, many many thanks!!!
    Best Regards
  • XypherXypher Member Posts: 297
    You are most welcome :D
Sign In or Register to comment.