EXCEL

Este job permite leer desde un documento de texto parseado mediante tabulaciones los campos a leer. Para este ejemplo, se ha utilizado la opción de guardado de MS Excel “Save as Text (Tab Delimited)”.

static void updateInventTable(Args _args)
{
   #file
   InventTable      inventTable;
   InventNumGroupId batchNum;
   ItemId           itemId;

   List             myList = new List(Types::Container);
   str              row;
   str              fileName = @"d:\myText.txt";

   ListEnumerator   listEnum;
   container        myRecord;
   TextIo           myFile;

   int              counterErr = 0;
   int              counterOK  = 0;
   int              counterTot = 0;
   ;

   // Verify if the file exists.
   if (!WinAPI::fileExists(fileName))
   {
      throw error(strfmt("@SYS18678", fileName));
   }

   // Verify if the file can be opened.
   myFile = new TextIo(fileName, #io_read);

   if (!myFile)
   {
      throw error(strfmt("@SYS19312", fileName));
   }

   // Define how the records in the file should be parsed.
   myFile.inFieldDelimiter(#delimiterTab);
   myFile.inRecordDelimiter(#delimiterCRLF);

   // Records will read from the file and be packed into a list.
   while (myFile.status() == IO_Status::Ok)
   {
      myList.addEnd(myFile.read());
      counterTot++;
   }

   listEnum = myList.getEnumerator();

   while(listEnum.moveNext())
   {
      myRecord = listEnum.current();
      itemId   = conpeek(myRecord, 1);
      batchNum = conPeek(myRecord, 2);

      if (itemId && InventTable::exist(itemId))
      {
          inventTable = inventTable::find(itemId, true);
          inventTable.BatchNumGroupId = batchNum;
          inventTable.update();
          counterOk++;
      }
      else
          counterErr++;
   }

   info(strFmt("Total de registros leidos: %1.",counterTot));
   info(strFmt("Se han actualizado: %1 registros.",counterOk));
   info(strFmt("Han dado error: %1 registros.",counterErr));
}

Anuncios