Currently using transform_list to download a file using the download CSV example. But I need to have the first line be a column heading.
I can write the stream file with the headings first but I there is no option to append for transform_list.
The appendage list option in transform_file looks like it's to make the CSV wider, not taller. IOW, entrys from each list are appended to create one line in the CSV.
Server is IBM i. I guess I could use system_command to append two files before downloading. I could make the list all alpha fields and write the entries to the list using asString. Any other suggestions?
Thanks, Art
Download a CSV with Column Headings
Download a CSV with Column Headings
Art Tostaine
Re: Download a CSV with Column Headings
Hey Art, is this in VLWeb where the CSV is downloaded via a browser?
If so, we do this by using *RESOURCE response.
A few things to note:
Joe
If so, we do this by using *RESOURCE response.
Code: Select all
srvroutine name(Download) response(*RESOURCE #response) session(*REQUIRED)
* write the header
#response.ContentString += ('"Week Ended","Check Number","Days Worked","Hours Worked","Gross Wages"' + #CRLF).AsNativeString
selectlist named(#Checks)
* format values
#lWeekEndDate := #CHDWP.AsDate( CCYYMMDD ).AsDisplayString( MMsDDsCCYY )
#lCheckNumber := #COM_OWNER.FormatCheckNumber( #CKN #CHPMTT )
#lDaysWorked := #TIDW.AsString
#lHoursWorked := #TIHRW.AsString
#lGrossWages := "$" + #CHPG.AsDisplayString( EditCode_N )
#ContentString := ('"&1","&2","&3","&4","&5"').Substitute( #lWeekEndDate #lCheckNumber #lDaysWorked #lHoursWorked #lGrossWages )
* add the string to the response
#response.ContentString += (#ContentString + #CRLF).AsNativeString
endselect
#response.AttachmentFileName := ("&1-&2_CheckHistory.csv").Substitute( #wk_OfficeNumber.AsString #wk_ControlNumber.AsString )
#response.ContentType := "text/csv"
endroutine
- This requires a custom CRLF field that we define as a PRIM_DC.UnicodeString and set the value as #CRLF := (13).AsUnicodeString + (10).AsUnicodeString
- ContentString is a PRIM_ALPH
- When invoking, use target(*NEW) as in define_com class(#ASCCHIFilterModule.Download) name(#Download) target(New). This will force the browser to open a new window to download the file. Typically the window closes after the download is complete.
Joe
Re: Download a CSV with Column Headings
Oh I didn't know you could send strings to the response. The example showed transform_list. This should work for me. Thanks!
Art Tostaine