Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write data to CSV file in ABL coding

I populated a temp from a query, and the temp table looks like,

ttcomp.inum
ttcomp.iname
ttcomp.iadd

There are 5000 records in this temp table and now i wanted to write in a CSV file. I think it could be done with output stream but i don't know how to implement this. Please someone help me in getting this.

like image 298
user3427690 Avatar asked Dec 18 '25 04:12

user3427690


2 Answers

Export does the trick:

/* Define a stream */
DEFINE STREAM str.

/* Define the temp-table. I did some guessing according datatypes... */
DEFINE TEMP-TABLE ttcomp
    FIELD inum  AS INTEGER
    FIELD iname AS CHARACTER
    FIELD iadd  AS INTEGER.

/* Fake logic that populates your temp-table is here */
DEFINE VARIABLE i AS INTEGER     NO-UNDO.
DO i = 1 TO 5000:
    CREATE ttComp.
    ASSIGN 
        ttComp.inum  = i
        ttComp.iname = "ABC123"
        ttComp.iadd  = 3.

END.
/* Fake logic done... */

/* Output the temp-table */
OUTPUT STREAM str TO VALUE("c:\temp\file.csv").
FOR EACH ttComp NO-LOCK:
    /* Delimiter can be set to anything you like, comma, semi-colon etc */
    EXPORT STREAM str DELIMITER "," ttComp.
END.
OUTPUT STREAM str CLOSE.
/* Done */
like image 97
Jensd Avatar answered Dec 21 '25 02:12

Jensd


Here is an alternative without stream.

/* Using the temp-table. of Jensd*/
DEFINE TEMP-TABLE ttcomp
    FIELD inum  AS INTEGER
    FIELD iname AS CHARACTER
    FIELD iadd  AS INTEGER.

OUTPUT TO somefile.csv APPEND.

    FOR EACH ttcomp:
                DISPLAY 
                    ttcomp.inum + ",":U  
                    ttcomp.iname + ",":U
                    ttcomp..iadd  SKIP. 
    END.

OUTPUT CLOSE.
like image 31
AD - Stop Putin - Avatar answered Dec 21 '25 03:12

AD - Stop Putin -



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!