Sunday, 26 June 2011

how to write select statement with while Loop in X++

Using select statement with while loop is something which has to do on daily bases to get the multiple records from statement. To exercise this statement lets assume we have a Books table which contain more then one record which we want to see. Lets write a job in editor

Static Void getBooksRecord(Args args)
{
   BookTable    bookTable;
   int records;
   ;
   while select bookTable
   {
      info("--------------NEW RECORD--------------");
      info (strfmt("BookId: %1", bookTable.BookId));
      info (strfmt("Title: %1", bookTable.BookTitle));
      info (strfmt("Author: %1", bookTable.Author));
      info (strfmt("ISBN: %1", bookTable.ISBN));
      records++;
   }
      info("------------------END-------------------");
      info(strfmt("%1 records was selected", records));
}

// Executing this Job will result in the writing  output to the Infolog. Note that only
the first records are shown in the Infolog window. When executing it yourself, you
can scroll down to see the other records at the end line