如果行以002代码开头,则文本文件中有两个代码(001和002),应将行数量与下一个001代码行数量相加。对于每个001码行,都应重复该顺序。表示每个001码行的数量应与前002行的数量之和(即每001码行的b / w应与下一个001行的数量相连接)
输入文件中的实际行
001 | 0.00
002 | 10.5
002 | 5.0
001 | 0.00
002 | 15.0
001 | 5
002 | 7
001 | 2
输入文件中预期的输出行
001 | 0.00
002 | 10.5
002 | 5.0
001 | 15.5 ( adding amount with 2nd, 3rd-row amount)
002 | 15.0
001 | 20.0 (adding amount with previous 002 code amount)
002 | 7.0
001 | 9.0 (adding amount with previous 002 code amount)
答案 0 :(得分:-1)
脚本组件(转换): 将Col1标记为只读 将Col2标记为读/写
这里的窍门是,您需要在行处理之外存储信息,因此需要在行处理之外声明变量。
行处理之外
//these are established on the first pass and used on every row moving forward.
decimal first002;
decimal last002;
int ctr=0;
内部行处理:
if(Row.Col1=="001")
{
//Do something with COl2 based on ctr
switch(ctr)
{
case 0:
break; //don't do anything
case 1:
Row.Col2 = first002;
break;
case 2:
Row.Col2 = first002+last002;
break;
default:
Row.Col2 += last002;
break;
}
}
else
{
//this is a 002 and need to update variables.
ctr++
if(ctr==1)
{first002 = Row.Col2;}
else
{last002 = Row.Col2;}
}