Inserting Multiple Records
The business service method handles multiple records for an insert database operation; however, the generated code inserts one record at a time.
This code sample shows the business service method handling multiple records:
public static E1MessageList insertAddressBookStaging(IContext context, IConnection connection, InternalInsertAddressBookStaging internalVO){ //Call start internal method, passing the context (which was passed //from published business service). startInternalMethod(context, "insertAddressBookZTable", internalVO); //Create new message list for business service processing. E1MessageList messages = new E1MessageList(); long numRowsInserted = 0; if (internalVO.getInsertFields()!=null) { for (int i = 0; i < internalVO.getInsertFields().size(); i++) { //call method (created by the wizard), which then //executes Business Function or Database operation E1MessageList insertMessages = InsertToF0101Z2(context, connection, internalVO.getInsertFields(i)); //add messages returned from E1 processing to business //service message list. messages.addMessages(insertMessages); //if no errors occur while inserting, add to counter. if (!insertMessages.hasErrors()) { numRowsInserted++; } } internalVO.setNumberRowsInserted(numRowsInserted); } //Call finish internal method passing context. finishInternalMethod(context, "insertAddressBookZTable"); //Return E1MessageList containing errors and warnings that //occurred during processing business service. return messages;
This code sample shows the generated code for the database insert:
private static E1MessageList InsertToF0101Z2(IContext context, IConnection connection, InternalInsertAddressBookStagingFields internalVO) { //create return object E1MessageList returnMessages = new E1MessageList(); //specify columns to insert BSSVDBField[] insertFields = {new BSSVDBField("F0101Z2.EDUS"), // String – EdiUserId new BSSVDBField("F0101Z2.EDBT"), // String – EdiBatchNumber new BSSVDBField("F0101Z2.EDTN"), // String – EdiTransactNumber new BSSVDBField("F0101Z2.EDLN"), // Numeric – EdiLineNumber new BSSVDBField("F0101Z2.AN8"), // Numeric – AddressNumber new BSSVDBField("F0101Z2.ALKY"), // String – AlternateAddressKey new BSSVDBField("F0101Z2.TAX"), // String – TaxId new BSSVDBField("F0101Z2.ALPH"), // String – NameAlpha new BSSVDBField("F0101Z2.DC"), // String – DescripCompressed new BSSVDBField("F0101Z2.MCU") // String – CostCenter }; //specify insert values Object[] insertValues = {internalVO.getF0101Z2_EDUS(), internalVO.getF0101Z2_EDBT(), internalVO.getF0101Z2_EDTN(), internalVO.getF0101Z2_EDLN(), internalVO.getF0101Z2_AN8(), internalVO.getF0101Z2_ALKY(), internalVO.getF0101Z2_TAX(), internalVO.getF0101Z2_ALPH(), internalVO.getF0101Z2_DC(), internalVO.getF0101Z2_MCU() }; try { //get dbService from context IDBService dbService = context.getDBService(); //execute db insert operation long numRecordsInserted = dbService.BSSVDBInsert(context, connection, "F0101Z2", IDBService.DB_TABLE, insertFields, insertValues); } catch (DBServiceException e) { //take some action in response to the database exception returnMessages.addMessage(new E1Message(context, "005FIS", TABLE_NAME + E1Message.sLineSeparator+e.getMessage())); } return returnMessages; }