其实关于这个函数的用法是在修改一个session的时候详细了解的,这个session用在盘点(BaaN里面称为Cycle counting)时,用来要upload盘点表文件。我们发现当item的库存数量含有小数点时session报错“Error file format!”
问题出在哪里?文件有问题?库存数量不能为double类型?程序有问题?为了弄明白这些问题,只好逐个排除:
1、库存的盘点表文件格式没问题,库存数量也没有问题,可以存在小数点后4位的数量(就是double类型)。
143030;;MOT06SW-970B18;12/06/2003 12:00:34;EA;15000;LOT000152;4000
2、程序代码中的报错处的代码有问题?看了一下源代码如下,使用方法没有问题。
err=string.scan(sss,”%s;%s;%s;%s;%s;%d;%s;%d”,imp.cwar,imp.loca,imp.item,idat,imp.stun,imp.strs,imp.clot,imp.pqua)
if err <> 8 then
message(“Error in Record Format”)|Error In Record Format
execute(end.program)
endif
可是仔细观察才发现问题,数量这种类型应该是double类型,而不应该是long。
err=string.scan(sss,”%s;%s;%s;%s;%s;%f;%s;%f“,imp.cwar,imp.loca,imp.item,idat,imp.stun,imp.strs,imp.clot,imp.pqua)
那么按照如下的函数使用说明,应该把两处的%d修改为%f,重新编译,上传文件,正常了。
<br/>string.scan()<br/>Syntax<br/>long string.scan( str_expr, string format(.) [, variable, ...] )<br/><br/>Description<br/>This scans an input string (str_expr) for one or more fields and stores each individual field found in the first available variable argument. The format argument contains conversion symbols that the function uses to interpret the input string and retrieve the individual field values. The conversion symbols indicate the types of values expected:<br/><br/>%s expects a single-byte or multibyte string<br/><br/>%f expects a double<br/><br/>%d expects a long<br/><br/>An input field is defined as all characters up to the next separator character or up to the next character that does not match the type of the corresponding conversion symbol. <br/><br/>A separator character is a single character used to separate individual values in the input string. It can be a space character, or any other character that is not used within individual fields in the input string. You cannot use multibyte characters as separators. <br/><br/>The string.scan() function scans the input string using each conversion symbol in the format argument in turn. For each conversion symbol, it scans the input string for characters that match the specified format. It stops scanning when it meets a separator character or a character that does match the expected type. <br/><br/>For example, consider the following function call:<br/><br/>string.scan( input_string, "%d|%f",long,double )<br/><br/>In this case, the function expects input_string to contain two separate numeric values. It reads the input string until it meets a pipe [|] character (this is the separator specified in the format argument). It then converts the characters read (excluding the separator) to a long value and stores that value in the long variable. The function then continues scanning the input string using the next conversion symbol in the format argument. <br/><br/>Note that if two conversion symbols are separated by more than one separator character, the function ignores those characters unless they match the input. <br/><br/>Return values<br/>The function returns the number of scanned fields. <br/><br/>
最后说明,其实这是一个非常简单的fix bug的case,我们借此了解了string.scan的函数用法,这个函数用来上传一些文件批量的更新baan ERP 数据库的内容。
版权所有,转载请注明出处:[URL=http://www.cuiwenyuan.com/baan]http://www.cuiwenyuan.com/baan/[/URL],本文同时发在[URL=http://www.xihome.com]西山之家[/URL]