fthiella / icread

Quick and dirty ICobol .XD file reader
Apache License 2.0
1 stars 0 forks source link

Some UNSIGNED DISPLAY are not working #1

Closed neimanpinchas closed 6 years ago

neimanpinchas commented 6 years ago

Before i've found your project, i started by myself the same idea using node js I managed to make all alphanumeric work however some UNSIGNED DISPLAY fields (with odd precision and scales) did'nt worked. I guessed its some funny BCD decoding but was unable to figure it out.

I would say that the xdt is wrong but it is working with the ODBC driver from icobol

than i've found your perl code, and i see that you are reading it as 8 bit ###, and finding the decimal placement from the precision, which doesnt work too with my fields.

I also tested your tool as is and got the same results

any idea?

Here is my code BTW i found the javascript ini parser to be more forgivable then the perl Config:INI

var fs=require("fs"),ini = require('ini')
var template=ini.parse(fs.readFileSync("inventory.xdt")+'')
//console.log(template)
var buf=fs.readFileSync("./INVFILE.XD")
var records=[]
var headerlength=521
var recordlength=266
var recordcount=((buf.length-headerlength)/recordlength)-1
for (i=0;i<recordcount;i++){
    var record={}
    var raw=buf.slice(headerlength+(i*recordlength),headerlength+(i*recordlength)+recordlength)
    for (key in template.Columns)
    {
            var fld=template[key]
            if (fld.Type=='ALPHANUMERIC'){
                record[key]=raw.slice(parseInt(fld.Position),parseInt(fld.Position)+parseInt(fld.Length)).toString()
            } else if (fld.Type=='UNSIGNED DISPLAY'){
                //record[key]=raw.readUIntBE(parseInt(fld.Position),parseInt(fld.Length))/parseInt("1"+("0").repeat(parseInt(fld.Scale)))
                record[key+"src"]=raw.slice(parseInt(fld.Position),parseInt(fld.Position)+parseInt(fld.Length))
                //record[key+"srcdec"]=[...record[key+"src"]]
                record[key]=raw.slice(parseInt(fld.Position),parseInt(fld.Position)+parseInt(fld.Length)).toString()
            } else {
                console.log(fld,key)
            }           
    }
    records.push(record)
    //console.log(raw.toString())
    //console.log("Prodline",raw.slice(2,3).toString())

}

console.log(records
//.filter(v=>v.IVendorId.includes("BX")).length)
.filter(v=>v.InventoryKey.trim()=="BXWPF")
//.filter(v=>v.ILastRecvdQty.includes("BXBP12"))

)
neimanpinchas commented 6 years ago

Sorry I managed to cntact the original cobol developer, and he checked the source code with his .xdt and it was a COMP field, so i am doing now readIntBE(positio,lentgh)/(Math.pow(10,scale)