-
新建兩個表定義,用於階段的輸入(InTableDef)輸出(OutTableDef)。
(1).InTableDef的定義如下(輸入字段爲:inID):
(2).OutTableDef的定義如下(輸出字段爲vaild):
-
創建一個新的buildstage
-
編輯階段常規屬性(命名階段的名稱爲ID_VER):
-
編輯階段構建->接口->輸入屬性(表名爲:選擇我們剛剛新建的表定義)
-
編輯階段構建->接口->輸出屬性(表名爲:選擇我們剛剛新建的表定義)
-
編輯階段構建->接口->傳輸屬性
-
編輯階段構建->邏輯->定義屬性(也可以在 每條記錄 裏面直接定義)
-
編輯階段構建->邏輯->每條記錄屬性(在這裏編寫功能代碼,這裏是身份證有效性的驗證代碼,來源IBM官網)
源代碼:來源IBM官網
APT_StringaddressNumber[] ={"11","22","35","44","53","12","23","36","45","54","13","31","37","46","61","14","32","41","50","62","15","33","42","51","63","21","34","43","52","64","65","71","81","82","91"};
intiWeight[]={7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
staticchar sVerCode[]="10X98765432";
boolbResult;
bResult=true;
boolb_IsLeapYear=false;
int Days[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inti,length;
intiYear;
intiMonth;
intiDay;
APT_StringID;
APT_StringIdtemp;
intiS = 0;
intiY;
ID= InRec.inID;
ID.trimWhitespace();
length= ID.length();
//lengthverify
if(length!= 15 && length != 18)
{
bResult= false;
}
else
{
//provinceverify
for(i = 0; i<= 34; i++)
{
if(ID.substring(0,2) == addressNumber[i])
break;
elseif (i == 34)
{
bResult= false;
}
}
if(bResult)
{
//Year,Month,Dayverify
intiYear = atoi(ID.substring(6, 4).data());
intiMonth = atoi(ID.substring(10, 2).data());
intiDay = atoi(ID.substring(12, 2).data());
if(iMonth<1|| iMonth>12)
{
bResult= false;
}
else
{
if(iYear%4== 0)
{
b_IsLeapYear= true;
if(!(iYear%100==0 && iYear%400==0)) b_IsLeapYear=false;
}
if(b_IsLeapYear)
Days[1]=29;
else
Days[1]=28;
if(iDay<0 || iDay>Days[iMonth-1])
{
bResult= false;
}
else
{
//verifycheck code
if(ID.length()!= 17)
{
for(i=0;i<17;i++)
{
iS+= (int)(ID[i]-'0') * iWeight[i];
}
intiY = iS%11;
if(sVerCode[iY]!= ID[17])
{
bResult = false;
}
}
}
}
}
}
if(bResult)
vaild= "TRUE";
else
vaild= "FALSE";
-
編寫完成後,點擊下方的生成後,會彈出日誌反饋是否成功,不成功繼續調試。
-
實例驗證stage的正確性:
輸出結果:
-
源表:511**爲正確的身份證
-
目標表,結果是和源表一樣的:
注意事項:1.自定義的stageID_VER的輸入爲inID,所以DSLink1的輸出字段必須定義爲inID
2.filter的屬性編輯:
3.OutputLink的確定是在“鏈接排序”裏邊。