Customer-Specific Picklist for WBS Element (Example)
You want to replace one of the columns in the standard picklist for WBS elements.
Proceed as follows:
You can access the standard picklist using the object of the
The field for which you are creating the picklist may already contain data entered by the user. You can use the
IRecordReadWrite interface, which is also transferred to the method as a parameter, to set up the picklist in accordance with the existing data.Java Source Code
package com.sap.mycats.customer.examples;
import com.sap.mycats.basics.tools.badi.*;
import com.sap.mycats.customer.businessLogic.ITimeSheetReader;
import com.sap.mycats.customer.application.*;
import com.sap.mycats.basics.customer.userInterface.IPicklistCustomer;
/** The following record must be defined in the customer file
* C:\me\wwwroot\tedb\customer\extensions\ci_records.xml
* <record name="ZPICKLIST_WBS">
* <fields>
* <field name="PERNR" type="T_PERNR_D"/>
* <field name="POSID" type="T_PS_POSID"/>
* <field name="POST1" type="T_PS_POST1"/>
* <field name="POSKI" type="T_PS_POSKI"/>
* <field name="TEXT" type="T_PS_POST1"/>
* </fields>
* </record>
*
*
* The Text-element with fieldname "TEXT" should be defined in R/3 in customizing table
* CATS_MY_TEXTS_C (only DD_TEXT is required) in all required languages
*
*/
public class ZPicklistWbs
implements IPicklistCustomer
{
public final static String WBS_ELEMENT = "POSID";
public final static String ZPICKLIST_WBS = "ZPICKLIST_WBS";
public final static String TEXT = "TEXT";
public ITableReadWrite getPicklistValues (char anApplication,IRecordReadOnly aRecord) {
ITableReadWrite picklistWbs;ITimeSheetReader timeSheetReader=null;
try{
// There is allways only one empNo available
IRecordReadOnly empRec = ApplicationReader.getEmployees().getRecordReadOnly(0);
String empNo = empRec.getFieldAsString(ApplicationReader.FTN_EMPLOYEENUMBER);
// get application profile
String profile = ApplicationReader.getApplicationProfile();
timeSheetReader = ApplicationReader.getTimeSheetReader(empNo,profile);}
catch(Exception e){}
ITableReadOnly sapPicklistTable
= timeSheetReader.getPicklist(WBS_ELEMENT).selectAll();
try {
IRecordReadOnly sapPicklistRecord
= new RecordFactory().createRecord("PICKLIST_POSID");
IRecordReadWrite zRecord
= new RecordFactory().createRecord(ZPICKLIST_WBS);
ITableReadWrite zTable
= new TableFactory().createTable(ZPICKLIST_WBS);
int count = sapPicklistTable.getRowCount();
for (int i = 0; i < count; i++) {
sapPicklistRecord = sapPicklistTable.getRecordReadOnly(i);
zRecord.setCorrespondingFields(sapPicklistRecord);
zRecord.setField(TEXT, "Any text");
zTable.appendRecord(zRecord);
}
picklistWbs = zTable;
} catch (Exception e) {
e.printStackTrace();
picklistWbs = null;
}
return picklistWbs;
}
public String getCoulumnId () {
return WBS_ELEMENT;
}
public String getColumnTitle () {
return TEXT;
}
}