If the triggering transaction supports customizable NAST messaging, then you can create a NAST message that supports ALE or IDoc. The link between the message and IDoc is defined via the process code in the partner profile WE20. Whenever the NAST message is processed it will make a call to ALE_PROCESSING in program RSNASTED or EDI_PROCESSING in program RSNASTED, which does the job for you and eventually will call the function module that fills the data hive.
If a program does not support messaging via NAST then you need to create the IDocs with your own routine and then call MASTER_IDOC_DISTRIBUTE. You can find more in-depth developer know-how in SAP R/3 Guide to EDI and Interfaces.
This was first published in October 2004