Inicio del área de contenido

Este gráfico es explicado en el texto respectivo Checking the Number of Hours Recorded (Example) Localizar documento en árbol de navegación

You want to prevent more than eight hours of working time being recorded for any one day for any employee.

Atención

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 CATS0006 SAP enhancement (Validate Entire Time Sheet). Note also that data can be supplemented in SAP R/3 only. To supplement data, use the CATS0002 SAP enhancement (Supplement Recorded Data).

Proceed as follows:

  1. Define a separate class, ZTimeSheetChecker. This class must implement the ITimeSheetChecker interface.
  2. Implement the checkRecord method. Use this method to define all customer-specific checks.
  3. Create an instance of the MessageContainer class.
  4. Read the Date (WORKDATE) of the data record being checked.
  5. Read all remaining data records with this date (WORKDATE) from the database. Use the selectCurrentRecordVersion method of object aTimeSheetReader.
  6. Read the Hours (CATSHOURS) of the data record being checked.
  7. Form a total from the hours of the data record being checked and the hours of the other data records that you read from the database in step 5. Use the Record Key (TRANSKEY) to ensure that the set of other data records does not contain any outdated versions of the data record being checked.
  8. Check whether more than eight hours of working time have been recorded for any one day for any employee. If this is the case, use the AddMessage method to generate an appropriate message and to transfer it to the MessageContainer.

Java Source Code

package com.sap.mycats.customer.examples;

 

import com.sap.mycats.basics.tools.badi.*;

import com.sap.mycats.customer.businessLogic.*;

 

public class ZTimeSheetChecker2

    implements ITimeSheetChecker

{

    private final static String FIELD_NAME_ZACTIVITY = "ZACTIVITY";

    private final static String FIELD_NAME_ZACTIVITY_SOME_FLAG = "MYFLAG";

 

    private final static String ZMSGID = "ZZ";

    private final static String MSG_NO_8_HOURS_EXCEEDED = "002";

 

 

    private final static String FIELD_NAME_WORKDATE = "WORKDATE";

    private final static String FIELD_NAME_CATSHOURS = "CATSHOURS";

    private final static String FIELD_NAME_TRANSKEY = "TRANSKEY";

 

 

    public IMessageContainer checkRecord (String anOperation,

                  IRecordReadOnly aRecord,

                  ITimeSheetReader aTimeSheetReader) {

        IMessageContainer result

           = MessageContainerFactory.createIMessageContainer();

        try {

            result.addMessages(checkZAcitivity(anOperation, aRecord,

                                               aTimeSheetReader));

        } catch (MessageNotDefinedException e) {

            e.printStackTrace();

            throw new Error(e.toString());

        }

        return result;

    }

 

 

    private IMessageContainer checkZAcitivity (String anOperation,

                   IRecordReadOnly aRecord,

                   ITimeSheetReader aTimeSheetReader)

        throws MessageNotDefinedException {

        IFieldDate workdate

           = aRecord.getFieldAsDate(FIELD_NAME_WORKDATE);

        String currentRecordId

           = aRecord.getFieldAsString(FIELD_NAME_TRANSKEY);

        IMessageContainer result

           = MessageContainerFactory.createIMessageContainer();

        ITableReadOnly records

           = aTimeSheetReader.selectCurrentRecordVersions(workdate,

                                                          workdate);

        float hours = aRecord.getFieldAsFloat(FIELD_NAME_CATSHOURS);

        for (int i = 0; i < records.getRowCount(); i++) {

            IRecordReadOnly record = records.getRecordReadOnly(i);

            String recordId

              = record.getFieldAsString(FIELD_NAME_TRANSKEY);

            if (!currentRecordId.equals(recordId)) {

                hours += record.getFieldAsFloat(FIELD_NAME_CATSHOURS);

            }

        }

        if (hours > 8) {

            result.addMessage(ZMSGID, IMessageContainer.TYPE_ERROR,

                               MSG_NO_8_HOURS_EXCEEDED);

        }

        return result;

    }

}

 

 

Fin del área de contenido