Hi,
You have to may be enhance the VBAK table to add custom fields and record the T-Code in a custom field. You can code in the USEREXIT_SAVE_DOCUMENT or USEREXIT_SAVE_DOCUMENT_PREPARE exits and perform modifications you need to internal table vbak and xvbap.Standard SAP program will then update the database tables for you.
Cheers,
Arindam