How to generate sales Order number in MSD axapta by code

How to generate sales Order number in axapta by code

NumberSeq           num; 
SalesTable salesTable;
;
num = NumberSeq::newGetNum(SalesParameters::numRefSalesId());
salesTable.SalesId = num.num();
 if (salesTable::exist(salesTable.SalesId))
   {
          num.abort();
         checkFailed("@LIQ1977");
          checkFailed(strfmt("@LIQ1978", salesTable.SalesId));
          throw error("@SYS23020");
        }
                  
        num.used();