Write a java method using the SAP API that connects to the SAP system and reserves numbers.
Call this new java method from the Windchill Object Initialization Rule (OIR) for the object.
There's really only these two steps. Once step 1 is completed, step 2 only involves changing one line in the OOTB OIR.
See the attached java code for an example of the method required for step 1. It uses the SAP Java Connector (JCo) version 2.1.8 which is a middleware component that enables the development of SAP-compatible applications in Java. Version 2.1.8 is not the latest and the programming methods have changed considerably from version 2 to 3, so some reworking would be required. First, the SAP JCo class files must be imported to this custom class, e.g. com.sap.mw.jco.*. A jar file can be copied to the Windchill server under the codebase. Then, the method reads property values for connecting to SAP and connects. After connecting and creating a repository for information, the standard SAP BAPI_MATERIAL_GETINTNUMBER BAPI is called to reserve the next available material number. A few required parameter values are passed with the BAPI_MATERIAL_GETINTNUMBER function. Note that this function does not create a material in SAP. It only reserves the number so no one else can use it. We later use additional SAP functions (like BAPI_MATERIAL_SAVEDATA) to create and maintain the material.
Now, the wtpart OIR can be modified to use this custom method. Change the OOTB Windchill numbering algorithm <AttrValue id="number" algorithm="com.ptc.windchill.enterprise.revisionControlled.server.impl.NumberGenerator"> to <VarDef id="gennum" algorithm="SAPESI.MyNumberGenerator"> where SAPESI is the package name and MyNumberGenerator is the class. We also use the VarDef xml tag instead of the AttrValue tag. Once the modified OIR is uploaded and new parts are created in Windchill, the number is populated with values from SAP.
One potential headache with doing this is that as your external system is upgraded, the API may change forcing you to update your custom method. That's something that must be considered with any upgrade, so it probably isn't new to you. Also, we use an SAP service account to create the parts. The password is stored in clear text in a property file on the server. To prevent misuse, this service user is configured so that it can't be used to login through the SAP client.
Note that this can be used with any object in Windchill using the OIR for that object and the appropriate API for the external system. We use a similar method to use an SAP change notice number for our Windchill change notices.