Locking a Cost Center (Example)
You want to prevent times being recorded for the receiver cost center 0000000777 for the employee with the EmployeeId 00004711. You want the system to issue an error message if the user records times for this cost center.
If you want to add the customer-specific check described below to CATS notebook, you must implement the check with equal thoroughness in SAP R/3. To do so, use the
Proceed as follows (for technical details, see the source code below):
Java Source Code
package com.sap.mycats.customer.examples;
import com.sap.mycats.customer.businessLogic.*;
import com.sap.mycats.basics.tools.badi.IRecordReadOnly;
public class ZTimeSheetChecker
implements ITimeSheetChecker
{
private final static String ZMSGID = "ZZ";
private final static String MSG_NO_WRONG_COST_CENTER = "001";
private final static String FIELD_NAME_COST_CENTER = "RKOSTL";
private final static String FIELD_NAME_EMPLOYEE_ID = "PERNR";
public IMessageContainer checkRecord (String anOperation,
IRecordReadOnly aRecord,
ITimeSheetReader aTimeSheetReader) {
IMessageContainer result
= MessageContainerFactory.createIMessageContainer();
try {
result.addMessages(checkCostCenter(anOperation,
aRecord, aTimeSheetReader));
// insert further checks here
} catch (MessageNotDefinedException e) {
e.printStackTrace();
throw new Error(e.toString());
}
return result;
}
private IMessageContainer checkCostCenter (String anOperation,
IRecordReadOnly aRecord,
ITimeSheetReader aTimeSheetReader)
throws MessageNotDefinedException {
String costCenter =
aRecord.getFieldAsString(FIELD_NAME_COST_CENTER);
String employeeId =
aRecord.getFieldAsString(FIELD_NAME_EMPLOYEE_ID);
if (costCenter.equals("0000000777") &
employeeId.equals("00004711")) {
IMessageContainer result
= MessageContainerFactory.createIMessageContainer();
result.addMessage(ZMSGID, IMessageContainer.TYPE_ERROR,
MSG_NO_WRONG_COST_CENTER);
return result;
}
return null;
}
}