Yes this is possible via script and can be fairly fast with Perform Script on Server and Refresh Portal if you are running FMS 14. It will work with other versions but a little slower.
How are the ingredients B related to product A? I think you really need to start with that question first.
The script will need a key for product A. Depending on the relationship there are various ways to get the keys for ingredients B. You would then loop though adding those to the portal or going to a table for direct entry, in which case you need the main parent record key as well.
Refresh the portal or window and its done.
You might want some sort of number system to sort the potral by so the ingredients always appear just below the product they relate to.