If u trying to uninstall a package with mainservice and subservice it will execute in the following ways
1.it will execute remove section of subservice
2. After execution of code inside the remove section of subservice it will execute the mainservice remove function.
For example
Main service contain a variable Accountid
myaccount-100
Subservice conatain variables called productid
myproductcut1-200
myproductcut2-201
myproductcut2-202
IF you delete the all subservice there is no need to take procutid using foreachloop . this delete will handle by PA automaticaly
means if u give uninstall it will remove all subservice one by one and after that it will remove main service.