Question Marcio Mendes · Nov 11, 2021

How to create .dbf file

Hey guys,

I need to create a .dbf file,  

How can I create this type of file?

There is some lib or plugin to do that?

Product version: Caché 2018.1
$ZV: Cache for UNIX (Red Hat Enterprise Linux for x86-64) 2018.1.5

Comments

Eduard Lebedyuk · Nov 11, 2021

Are there really no other options (CSV, JSON, XML)?

I have some code for a DBF reader, if you're interested I can share it and you can create a DBF writer by analogue.

0
Marcio Mendes  Nov 11, 2021 to Eduard Lebedyuk

unfortunately no, I really need to export a .dbf file

If there is no problem, it would be great to see this code.

0
Eduard Lebedyuk  Nov 11, 2021 to Marcio Mendes

Well, enjoy.

UPD: it was missing isc.util.dbf.Field.

Class isc.util.DBF.Field Extends%SerialObject [ ClassType = serial, ProcedureBlock ]
{

Property name As%String(TRUNCATE = 1);Property type As%String(TRUNCATE = 1);Property length As%Integer;Property decimals As%Integer;

}
0
Sergei Shutov · Nov 14, 2021

You can try using DBF utility from my old Cache-based framework:

https://github.com/logist/p6/blob/master/classes/p6/Dbf.xml

It has ReadFile/ReadStream & WriteFile/WriteStream methods

Usage:

set sc=##class(p6.Dbf).WriteFile(file,array)
sc - execution status %Status
file-file name
array - string containing a name of global with data,
 
for example: ^asd("asdf"),
^CacheTemp($job,"dbf")
this array has to provide the following structure
...,"header")=<header>
format $list($list(var1,length1,type1,dec1),...,$list(varN,lengthN,typeN,decN)); type is D for date N for number anything else for string
...,"row",<row number>)=<data>

data format $list(var1,...,varN)

0