11/07/2016

Axapta : Run ตัวเลข และใส่ 0 ข้างหน้าตัวเลขที่ต้องการ

Axapta : Run ตัวเลข และใส่ 0 ข้างหน้าตัวเลขที่ต้องการ
Code แบบ Check เอา
  1.   loopBatch = dlfBatchId.value();
  2.             countBatch = strlen(loopBatch);
  3.             if(countBatch == 10){
  4.                 //Split String
  5.                 findStrBatch = StrFind(loopBatch, "-", 1 , 10);
  6.                 subStrFirstBatch = SubStr(loopBatch, findStrBatch - 1, -6);
  7.                 subStrLastBatch = SubStr(loopBatch, findStrBatch + 1, 3);
  8.                 for(loop = 0; loop < dlfRun.value(); loop++){
  9.                     //insert into InventBatch table.
  10.                     SELECT * FROM inventBatch;
  11.                     inventBatch.inventBatchId = strfmt("%1-%2", subStrFirstBatch, subStrLastBatch);
  12.                     inventBatch.itemId = dlfItemNo.value();
  13.                     inventBatch.insert();
  14.                 //Conver Format Number.
  15.                     loopBatchConvert = Str2Num(subStrLastBatch);
  16.                     if(loopBatchConvert < 10){
  17.                         subStrLastBatch =  strfmt("00%1",Int2Str(Str2Num(subStrLastBatch) + 1));
  18.                     } else {
  19.                         if(loopBatchConvert > 10 &&  loopBatchConvert < 100){
  20.                             subStrLastBatch = strfmt("0%1",Int2Str(Str2Num(subStrLastBatch) + 1));
  21.                         } else {
  22.                             subStrLastBatch = Int2Str(Str2Num(subStrLastBatch) + 1);
  23.                         }
  24.                     }
  25.                 }
  26.             }


แบบที่ 2 ใช้ Function StrRfix
  1. str strRfix(str _str, int _length [, char _char])

  1.                for(loop = 0; loop < dlfRun.value(); loop++){
  2.                     //insert into InventBatch table.
  3.                     SELECT * FROM inventBatch;
  4.                     inventBatch.inventBatchId = strfmt("%1-%2", subStrFirstBatch, subStrLastBatch);
  5.                     inventBatch.itemId = dlfItemNo.value();
  6.                     inventBatch.insert();
  7.                 //Conver Format Number.
  8.                 subStrLastBatch = StrRfix(Int2Str(Str2Num(subStrLastBatch)+ 1), 3, "0");
  9.                 }


http://www.axaptapedia.com/StrRfix

No comments:

Post a Comment