krushna
4th August 2015, 13:47
hello sir,, :)
m trying to make a afs script for insert a record in my table phcus003.
but it not working can u plz check it tht where m I wrong.
here is my code,,



table tphcus003


extern domain tcmcs.str80 file.name
extern domain tcmcs.str1 field.sep
extern domain tcorno line.count

extern domain tcmcs.str100 server.tmp.file,rec
long ret,server_file_ptr,ret.num
string file.scan(9),local.file.name(100)

extern domain tcorno roll
extern domain tcdsca stud
string error.msg,recover.msg
long retval1,retval2

#pragma used dll ottstpapihand
#pragma used dll ottdllbw

function main()
{
line.count = 0
file.name = bse.tmp.dir$() & "/importlist.txt"
local.file.name = "C:\temp\phcus0203m001.txt"
ret = client2server(local.file.name,file.name,true)
if ret = 0 then
server_file_ptr = seq.open(file.name, "r")
if server_file_ptr then
while(not seq.eof(server_file_ptr))
ret = seq.gets(rec, 100, server_file_ptr)
if ret = 0 then
roll = 0
stud = ""
file.scan = "%d"&field.sep&"%s"|&field.sep&"%f"
ret.num = string.scan(rec,file.scan,roll,stud)
line.count = line.count + 1
message("hi")
stpapi.put.field("phcus0203m000", "phcus003.roll", str$(roll))
stpapi.put.field("phcus0203m000", "phcus003.name", stud)
retval1 = stpapi.insert("phcus0203m000", 1, error.msg)
message("hello")
if not retval1 then
message("wrong")
retval2 = stpapi.recover("phcus0203m000", recover.msg)
endif
else
error.msg = "Date format mismatch - "&trim$(rec)
endif
error.msg = "File format mismatch - "&trim$(rec)
endwhile
else
message("ERROR : File Cannot be Opened")
endif
ret = seq.close(server_file_ptr)
ret = seq.unlink(server.tmp.file)
else
message("ERROR : Copy File to Server Failed")
endif
mess("tcgenstring",0,"Process Completed.")

}

benito
4th August 2015, 15:09
looks like your session phcus0203m000 is a custom session. are you sure you don't have access to the program script? if you do, you don't need afs.

frenny
4th August 2015, 15:11
hello,

Use stpapi.end.session("phcus0203m000"), after your insertion process..

mark_h
4th August 2015, 15:18
Actually benito this is a perfect example of how you can test out writing AFS code - sure you don't need it, but you can put your own source code in debug mode to watch what happens as you step thru the AFS code.

So for the above code I would say - what is the error message on the stpapi.insert? I am assuming you confirmed that roll and stud have the values you expect it to have. I am also assuming your custom session only has two input fields - if there are more you might need to put those also. Or if they are set in the custom script - debug it and step thru it. Then, like I said above, make sure the code is executed during the test run. If not that complicated then what does error.msg contain on the insert?

mark_h
4th August 2015, 15:20
hello,

Use stpapi.end.session("phcus0203m000"), after your insertion process..

Actually - that would not prevent the insert. What it would do is leave a session running in the back ground each time you run the session. So it should be added, but would not prevent the insert.


PS - I moved this to the correct forum also.