pjohns
20th April 2012, 18:31
Hello,

I looking at AFS for the first time and I'm after some help on a couple of points. Below is the code I'm working with, which has been given to me by another party.


function main()
{
file.id = seq.open("${BSE}\exchange\seq\tffbs101.S", "r")
while not seq.eof(file.id) and not seq.gets(v_rows, 256, file.id)
year.i = shiftl$(strip$(v_rows(1;4)))
budg.i = shiftl$(strip$(v_rows(5;3)))
leac.i = shiftl$(strip$(v_rows(8;12)))
dim1.i = shiftl$(strip$(v_rows(20;6)))
dim2.i = shiftl$(strip$(v_rows(26;6)))
dim3.i = shiftl$(strip$(v_rows(32;6)))
dim4.i = shiftl$(strip$(v_rows(38;6)))
dim5.i = shiftl$(strip$(v_rows(44;6)))
dbcr.i = shiftl$(strip$(v_rows(50;3)))
disb.i = shiftl$(strip$(v_rows(115;3)))
year.budg.amnt.i = shiftl$(strip$(v_rows(61;1)))
Create.tffbs101()
endwhile
seq.close(file.id)
}



My questions are:-

1. How would I specify the process to use a delimited file?
2. What does the second line of this function do? The one that starts "while not"

Thanks in advance.

PJ

mark_h
20th April 2012, 22:19
Basically what the while not is doing is checking for end of file and also getting the next record. So seq.gets checks for a record and returns 0 if success and -1 for error or end of file. The seq.eof returns 0 if not set and >0 for end of file or -1 for error. That is why both have not in front of them.

Here is a routine we use to load a table for processing through an AFS session - granted you do not need a lot of the code below just easier to cut and paste. In your case you would just need to use string.scan and maybe a little error checking. Hope this helps.

seq.gets(buff,1024,inputfile) | Read header row.
nrscan.err = 0 |20090109
nrread = 0 |20090109
tdudi020.logn = baan.user
tdudi020.seqn = get.next.tdudi020.seqn()
tdudi020.line = 0
while seq.gets(buff,1024,inputfile)=0
read.cref = "" |20090109.st
read.ival = ""
nrread = nrread + 1 |20090109.end
scan.ret = string.scan(buff,
"%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s",
read.item,
read.qty,
read.cwar,
read.loca,
read.date,
read.clot,
read.cprj,
read.cspa,
read.butm,
read.sbtm,
read.prog,
read.eser,
read.eseq,
read.irea,
read.frea,
read.prea,
read.cref, |20070817
read.ival) |20070817
| read.cref and read.ival are optional
if(scan.ret < 16) then |20090109
| title("string scan error")
nrscan.err = nrscan.err + 1
continue
endif
| Check Item.
tdudi020.line = tdudi020.line + 1
rc = tt.align.according.domain(shiftl$(shiftr$(toupper$(read.cprj))),tdudi020.cprj,"tppdm.cprj")
rc = tt.align.according.domain(shiftl$(shiftr$(toupper$(read.cspa))),tdudi020.cspa,"tppdm.cspa")
rc = tt.align.according.domain(shiftl$(shiftr$(toupper$(read.butm))),tdudi020.butm,"tipgc.butm")
rc = tt.align.according.domain(shiftl$(shiftr$(toupper$(read.sbtm))),tdudi020.sbtm,"tipgc.butm")
rc = tt.align.according.domain(shiftl$(shiftr$(toupper$(read.prog))),tdudi020.prog,"tiprog.a")
rc = tt.align.according.domain(shiftl$(shiftr$(toupper$(read.eser))),tdudi020.eser,"tieser.a")
rc = tt.align.according.domain(shiftl$(shiftr$(toupper$(read.item))),tdudi020.item,"tcitem")
tdudi020.eseq = val(read.eseq)
tdudi020.quan = val(read.qty)
rc = tt.align.according.domain(shiftl$(shiftr$(toupper$(read.cwar))),tdudi020.cwar,"tccwar")
rc = tt.align.according.domain(shiftl$(shiftr$(toupper$(read.loca))),tdudi020.loca,"tdilc.loca")
if isspace(read.clot) then
tdudi020.clot = ""
tdudi020.date = 0
else
rc = tt.align.according.domain(shiftl$(shiftr$(toupper$(read.clot))),tdudi020.clot,"tdltc.clot")
if isspace(read.date) then
tdudi020.date = 0
else
num.day = val(read.date(4;2))
num.month = val(read.date(1;2))
num.year = val(read.date(7;4))
tdudi020.date = date.to.num(num.year, num.month, num.day)
endif
endif
rc = tt.align.according.domain(shiftl$(shiftr$(toupper$(read.irea))),tdudi020.irea,"tdinv.recd")
rc = tt.align.according.domain(shiftl$(shiftr$(toupper$(read.frea))),tdudi020.frea,"tdinv.recd")
rc = tt.align.according.domain(shiftl$(shiftr$(toupper$(read.prea))),tdudi020.prea,"tdinv.recd")
| 20090109.st - Making read.cref and read.ival optional for the load file
if isspace(read.cref) then
tdudi020.cref = ""
else
rc = tt.align.according.domain(shiftl$(shiftr$(toupper$(read.cref))),tdudi020.cref,"tppdm.gcid.a")
endif
if isspace(read.ival) then
tdudi020.ival = 0
else
tdudi020.ival = val(read.ival)
endif
| 20090109.end
db.insert(ttdudi020)
commit.transaction()
endwhile

binoy000
22nd April 2012, 14:57
Suggest to use
return( stpapi.insert( "session code", do.update, error ) ) for AFS instead of db.insert.