RG,
Record the the item addition through SHD0 for BDC then extract the already available BOMs and their items with item numbers from MAST,STPO,STKO to identify the last item number then prepare the template accordingly with correct item number to be added and load the programme.
BR
KK