BPM ABL query output to CSV file - Example

If you ever want to export an entire TABLE to a .CSV, Progress makes this simple to do. But exporting column headings for 100 or so fields is a PITA. This is a routine I wrote to generate the headings from the data dictionary metaschema.

I put this into an include file {pny/expHeadings.i} which I include wherever I need it.

def var vcHeading as char format "x(12)" extent 300 no-undo.
def var i as int no-undo.

procedure exp_headings.ip:
def input param pFile as char no-undo.

assign vcHeading = "" i = 0.

find _file where _file._file-name = pFile no-lock no-error.
if not avail _file then return error "Invalid filename: " + pFile.

for each _field no-lock of _file by _Order:
i = i + 1.
vcHeading[i] =
(if trim(_field._col-label) > "" then _field._col-label else
if trim(_field._label) > "" then _field._label else
_field._field-name).
if i >= 300 then leave.
end.

end procedure.


Syntax to export a table, e.g. customer ... I like to use named streams for exports to keep that data separate from the standard output:

DEF STREAM s-exp.
OUTPUT STREAM s-exp to "chris.csv".
RUN exp_headings.ip ("CUSTOMER").
/* write out the column headings */
EXPORT STREAM s-exp DELIMITER ",'" vcHeading.
/* export the corresponding data. Progress exports table fields in _order sequence */
FOR EACH customer NO-LOCK:
EXPORT STREAM s-exp DELIMITER "," CUSTOMER.
END.
OUTPUT STREAM s-exp CLOSE.

Note that if exporting a temp-table the DBRowIdent ROWID field cannot be exported directly (need STRING(DbRowIdent) to do this but then you would have to name every field. Progress makes this easy to do ...

EXPORT STREAM s-exp DELIMITER "," ttCustomer EXCEPT dbRowIdent.

You could list other fields to exclude too.

I often export temp-tables while testing to verify that the ROWMOD field has what I expect in a data or method directive, to see what the GetNew method populated, compare vs. a trace, etc.

I am working on a similar routine which will generate the column-headings for a temp-table by "walking the widget tree". Not ready for prime time yet. Most temp-tables are defined LIKE the DB table with some added fields. So to export ttCustomer RUN exp_headings.ip ("customer") and you'll have all but the extra fields. You can find out what they are if necessary by examining server/bo/customer/customer_ds.i.

One last little trick. By using preprocessor definition you can easily make the code above reusable for multiple tables, e.g. orderhed, orderdtl, orderrel. Like this:

&scoped-define dumpfile ShipHead
run exp_headings.ip ("{&DumpFile}").
output stream s-exp to value (vcEpiData + "{&DumpFile}.csv").
export stream s-exp delimiter "," vcHeading.
for each {&DumpFile} no-lock: export stream s-exp delimiter "," {&DumpFile}. end.
output stream s-exp close.

&scoped-define dumpfile ShipDtl
run exp_headings.ip ("{&DumpFile}").
output stream s-exp to value (vcEpiData + "{&DumpFile}.csv").
export stream s-exp delimiter "," vcHeading.
for each {&DumpFile} no-lock: export stream s-exp delimiter "," {&DumpFile}. end.
output stream s-exp close.

vcEpiData is defined in my standard.i include file (every program gets this) :

/* directives */
&global-define epidata \\erp-app1\EPICORDATA<file:///\\erp-app1\EPICORDATA>
&global-define epienv pilot
&global-define default_company PNY01

/* standard vars */
def var vcEpiData as char no-undo initial "{&epidata}\{&epienv}\".

So by changing the epienv definition vcEpiData will point to ..\pilot\, ..\prod\, ..\test\, etc. without changing any code.

Cheers!

Christopher Heins
Sr. Progress Programmer/Analyst
[cid:image001.png@01CC97B6.65916050]
Desk# 973-560-5370
Cell# 908-256-3662
Skype: cheins.nj
cheins@...<mailto:cheins@...>


________________________________
NOT INTENDED AS A SUBSTITUTE FOR A WRITING
NOTHING IN THIS E-MAIL, IN ANY E-MAIL THREAD OF WHICH IT MAY BE A PART, OR IN ANY ATTACHMENTS THERETO, SHALL CONSTITUTE A BINDING CONTRACT, OR ANY CONTRACTUAL OBLIGATION BY PNY, OR ANY INTENT TO ENTER INTO ANY BINDING OBLIGATIONS, NOTWITHSTANDING ANY ENACTMENT OF THE UNIFORM ELECTRONIC TRANSACTIONS ACT, THE FEDERAL E-SIGN ACT, OR ANY OTHER STATE OR FEDERAL LAW OF SIMILAR SUBSTANCE OR EFFECT. THIS EMAIL MESSAGE, ITS CONTENTS AND ATTACHMENTS ARE NOT INTENDED TO REPRESENT AN OFFER OR ACCEPTANCE OF AN OFFER TO ENTER INTO A CONTRACT. NOTHING IN THIS E-MAIL, IN ANY E-MAIL THREAD OF WHICH IT MAY BE A PART, OR IN ANY ATTACHMENTS THERETO SHALL ALTER THIS DISCLAIMER.

This e-mail message from PNY Technologies, Inc. is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.


[Non-text portions of this message have been removed]
I am attempting to output information from an ABL query to a csv file. It is creating the .csv file with the correct data, but the output inside is the exact same as the .txt output. Anyone ever tried this before and succeeded?

Thanks,
Ted
I tried to do this as well. I eventrually used a third party spreadsheet dll. I didn't have the time to workout the issues. The third party spreadsheet dll allowed me to use excel spreadsheets, reading and writing .

________________________________
From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of tkoch77
Sent: Thursday, October 27, 2011 1:38 PM
To: vantage@yahoogroups.com
Subject: [Vantage] BPM ABL query output to CSV file



I am attempting to output information from an ABL query to a csv file. It is creating the .csv file with the correct data, but the output inside is the exact same as the .txt output. Anyone ever tried this before and succeeded?

Thanks,
Ted





[Non-text portions of this message have been removed]
Example of outputting to an Excel .csv file:

Find first company no-lock no-error.

DEF VAR ct AS INTE NO-UNDO.

Output to c:\temp\part-purchased.csv.

Export delimiter ","
"Part Number"
"Description"
"Type Code"
"Cost Method".

For each part no-lock where part.company = company.company (use CUR-COMP
if using from a BPM)
and part.typecode = "P".
ct = ct + 1.
export delimiter ","
part.partnum
part.partdescription
part.typecode
part.costmethod.
end.

Output close.

MESSAGE "Purchased Parts: " ct
VIEW-AS ALERT-BOX.


Open Microsoft Excel and then open a file - type csv - once opened, you can
adjust the columns and save the file as a regular Excel File - .XLS or .XLX

Carl Peterson, CPIM
Plymouth, Michigan
Nexus Software, Inc.
734-812-9532

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of
Dan Godfrey
Sent: Thursday, October 27, 2011 5:40 PM
To: vantage@yahoogroups.com
Subject: RE: [Vantage] BPM ABL query output to CSV file


I tried to do this as well. I eventrually used a third party spreadsheet
dll. I didn't have the time to workout the issues. The third party
spreadsheet dll allowed me to use excel spreadsheets, reading and writing .

________________________________
From: vantage@yahoogroups.com <mailto:vantage%40yahoogroups.com>
[mailto:vantage@yahoogroups.com <mailto:vantage%40yahoogroups.com> ] On
Behalf Of tkoch77
Sent: Thursday, October 27, 2011 1:38 PM
To: vantage@yahoogroups.com <mailto:vantage%40yahoogroups.com>
Subject: [Vantage] BPM ABL query output to CSV file

I am attempting to output information from an ABL query to a csv file. It is
creating the .csv file with the correct data, but the output inside is the
exact same as the .txt output. Anyone ever tried this before and succeeded?

Thanks,
Ted

[Non-text portions of this message have been removed]

_____

No virus found in this message.
Checked by AVG - www.avg.com
Version: 2012.0.1834 / Virus Database: 2092/4578 - Release Date: 10/27/11


[Non-text portions of this message have been removed]
Thank you Carl, that worked great.



________________________________
From: Carl Peterson <cpeterson@...>
To: vantage@yahoogroups.com
Sent: Thursday, October 27, 2011 8:05 PM
Subject: RE: [Vantage] BPM ABL query output to CSV file - Example

Example of outputting to an Excel .csv file:

Find first company no-lock no-error.

DEF VAR ct AS INTEÂ Â Â Â Â NO-UNDO.

Output to c:\temp\part-purchased.csv.

Export delimiter ","
       "Part Number"
       "Description"  Â
       "Type Code"
       "Cost Method".
      Â
For each part no-lock where part.company = company.company (use CUR-COMP
if using from a BPM)
       and part.typecode = "P".
       ct = ct + 1.
       export delimiter ","
       part.partnum
       part.partdescription
       part.typecode
       part.costmethod.
end.

Output close.

MESSAGE "Purchased Parts: " ct
  VIEW-AS ALERT-BOX.


Open Microsoft Excel and then open a file - type csv - once opened, you can
adjust the columns and save the file as a regular Excel File - .XLS or .XLX

Carl Peterson, CPIM
Plymouth, Michigan
Nexus Software, Inc.
734-812-9532

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of
Dan Godfrey
Sent: Thursday, October 27, 2011 5:40 PM
To: vantage@yahoogroups.com
Subject: RE: [Vantage] BPM ABL query output to CSV file

Â
I tried to do this as well. I eventrually used a third party spreadsheet
dll. I didn't have the time to workout the issues. The third party
spreadsheet dll allowed me to use excel spreadsheets, reading and writing .

________________________________
From: vantage@yahoogroups.com <mailto:vantage%40yahoogroups.com>
[mailto:vantage@yahoogroups.com <mailto:vantage%40yahoogroups.com> ] On
Behalf Of tkoch77
Sent: Thursday, October 27, 2011 1:38 PM
To: vantage@yahoogroups.com <mailto:vantage%40yahoogroups.com>
Subject: [Vantage] BPM ABL query output to CSV file

I am attempting to output information from an ABL query to a csv file. It is
creating the .csv file with the correct data, but the output inside is the
exact same as the .txt output. Anyone ever tried this before and succeeded?

Thanks,
Ted

[Non-text portions of this message have been removed]

 _____Â

No virus found in this message.
Checked by AVG - www.avg.com
Version: 2012.0.1834 / Virus Database: 2092/4578 - Release Date: 10/27/11


[Non-text portions of this message have been removed]



------------------------------------

Useful links for the Yahoo!Groups Vantage Board are: ( Note:Â You must have already linked your email address to a yahoo id to enable access. )
(1) To access the Files Section of our Yahoo!Group for Report Builder and Crystal Reports and other 'goodies', please goto: http://groups.yahoo.com/group/vantage/files/.%c2%a0
(2) To search through old msg's goto: http://groups.yahoo.com/group/vantage/messages
(3) To view links to Vendors that provide Vantage services goto: http://groups.yahoo.com/group/vantage/linksYahoo! Groups Links



[Non-text portions of this message have been removed]