Purpose
The purpose of this blog post is to provide an orientation to reading and maintaining equipment partners from customer developed ABAP programs. The post provides a summary of several function modules which are useful in this context.
Reading Equipment Partners
FUNCTION ALM_ME_TOB_PARTNERS
Partners of equipment can be read using the function module ALM_ME_TOB_PARTNERS. Given an equipment object number or functional location object number, the function provides a table of the partners of the technical object and the partner role.
I prefer this function module to the perhaps more commonly known PM_PARTNER_READ because (a) it is RFC enabled and (b) does some external conversions to convert the partners from internal representation to external representation.
Hint: If you need to determine the object number of the piece of equipment, then I suggest function OBJECT_NUMBER_GET_IE. The relative OBJECT_KEY_GET_IE provides the equipment number for an object number.
Hint: Set the parameter I_PARTNER_TPA_KEY to 'X' get the partner type in the key. Experiment with this checked / unchecked to see the difference.
Reading Partner Details
FUNCTION ALM_ME_PARTNER_GETDETAIL
The details of the partners can be read using the function module above. Given a partner key, the function provides details of the partner, including address information, associated SD contract information and contact persons. Partner key? Where did that come from? The partner key is returned when reading the equipment partners using ALM_ME_TOB_PARTNERS.
Maintaining Partner Details
When maintain partner details, a much more care is required. You need to consider issues such as external and internal representations and whether the configuration of the equipment allows the partner you would like to maintain. I've found the function ALM_ME_EQUIPMENT_CHANGE to be a useful guide to the steps involved.
Let assume that you are starting with a table of partners like those returned by ALM_ME_TOB_PARTNERS.
Step 1: Partner role conversion
FUNCTION ALM_ME_PARTNER_INPUT_CONVERSN
Conversion of the partner role from external to internal format
Step 2: Check partners for validity
FUNCTION ALM_ME_EQUI_PARTNER_CHECK
Provides the partners and the equipment category to check whether the partners are permissible. If there are errors here, you need to correct them.
Step 3: Prepare to maintain / update partners
The function to maintain partners requires partner information in the format of the structure BAPI_IHPA.
For every partner in your table of partners, you need to extract the internal partner ID and the partner role. For that, you need to do something along the lines of
DATA ls_ihpa type ihpa.
DATA ls_bapi_ihpa type bapi_ihpa.
DATA lt_bapi_ihpa type standard table of bapi_ihpa.
LOOP AT equipment_partners INTO ls_partner.
CLEAR ls_ihpa.
CLEAR ls_bapi_ihpa.
CALL FUNCTION 'ALM_ME_PARTNER_KEY_SPLIT_TPA'
EXPORTING
partner_key = ls_partner-partner_key
IMPORTING
partner_id = ls_ihpa-parnr.
MOVE ls_partner-partner_role TO ls_bapi_ihpa-partn_role.
MOVE ls_ihpa-parnr TO ls_bapi_ihpa-partner
MOVE ls_equipment_itob-objnr TO ls_bapi_ihpa-object_no.
MOVE '009' TO ls_bapi_ihpa-operation .
APPEND ls_bapi_ihpa TO lt_bapi_ihpa.
ENDLOOP.
The eagle-eyed will have noticed the literal 009 in the code above. What is that? The permitted operations when maintaining partners are defined as below.
delete => '003' " Not supported ALM_ME_PARTNER_MAINTAIN!
change => '004'
insert => '009'
Deletion doesn't work so simply as described. That will be a follow-on blog post - here
https://blogs.sap.com/2020/09/20/equipment-partners-deletion/
Step 4: Maintain partners
FUNCTION ALM_ME_PARTNER_MAINTAIN
Additionally, you need to read the equipment categories of the equipment to fill structure t370t needed to maintain part
ners in step 4. Use function ITOB_CHECK_CATEGORY
FUNCTION ITOB_CHECK_CATEGORY
Step 5: Prepare for Update
FUNCTION PM_PARTNER_CALL_VB
Step 6: Trigger update
COMMIT WORK.
Whether commit work should be called or not is dependent upon your context
Recommendation
To maintain the equipment partners, I'd recommend that the above steps be combined into a class and then wrapped in a function module if needed for remote access.
Don't forget that changing the equipment partners is part of changing a piece of equipment - so you are advised to ensure you have exclusive use of the equipment. Locking etc.
Write unit tests first!
Test thoroughly!
Revisions:
2020-09-18: Addition of functions to determine equipment number from object number and visa-versa in section Reading Equipment Partners
2020-09-18:Note that deletion of existing partners isn't supported by ALM_ME_PARTNER_MAINTAIN. Deletion to be subject of another blog post.
here