Creating Primary Sub menu's programmatically
You could use the menu views module:


  What Menu Views Does 
  
  Menu Views is a utility module. It provides back
  end support for replacing a standard menu item link with a menu item
  view. Menu items (in any menu) now have the option of toggling between
  two different menu item types: link or view. Depending on which option
  is selected, the appropriate configuration form is displayed on the
  admin side and the appropriate type of item is rendered on the
  front-end.


Once you create a submenu, you can attach a view to it. Your title suggests you're asking to do this programmatically. From what i know, i'm not totally sure if that's possible without a lot of headache.