Hello,
There is no need to write code to achieve this task. As suggested in this post Creating filter for outbound IDOC CREMAS
add a filter object to BD95 then assign the object to the message type within BD59
Review the link and post here if you have any questions.
Thank you,
Joseph