in Drupal

Creating views programmatically in Drupal 7

When you need to deploy your views to server instances

1. Create your view the regular way.

2.  Define your views api version and path for files that include views hooks.

* Implementation of hook_views_api().
function HOOK_views_api() {
  return array(
    'api' => 3.0,
    'path' => drupal_get_path('module', 'HOOK')

3.Views export creates code that you have to paste in this function.

function HOOK_views_default_views() {
  // Paste code form views export.
  $views[$view->name] = $view;
  return $views;

4. Delete your view and clear all caches, view from your code should appear. When you change the view don’t forget to add the changes to code.