For Outbound IDOC ( Delivery) :
You can use the Tables SRRELROLES and IDOCREL outbound use LIKP
Steps :
(i) First get the ROLEID using the Delivery number as Objectkey and object type LIKP from the table SRRELROLES
(ii) Then pass the ROLEID to the table IDOCREL to ROLE_A , get the ROLE_B.
(iii) Use this ROLE_B supply to ROLEID of SRRELROLES table and put object type IDOC and get the objkey which is nothing But IDOC.
Inbound IDOC :
If it is inbound delivery the use the business object type BUS2015.
For Outbound IDOC ( Invoice ) :
You can use the Tables SRRELROLES and IDOCREL outbound use VBRK
Steps :
(i) First get the ROLEID using the Delivery number as Object key and object type VBRK from the table SRRELROLES
(ii) Then pass the ROLEID to the table IDOCREL to ROLE_A , get the ROLE_B.
(iii) Use this ROLE_B supply to ROLEID of SRRELROLES table and put object type IDOC and get the objkey which is nothing But IDOC. Inbound IDOC :
If it is inbound delivery the use the business object type BUS2015.