Chapter Contents

Previous

Next
SAS/CONNECT User's Guide

Example 1 - Create a Remote Instance

This example creates a remote instance of the SASHELP.FSP.DATAST_M class. After the remote instance is created, the methods _SET_DATASET_ and _GET_DATASET_NAME_ are invoked remotely, and the results are returned for local processing.

main:
   r_string = '';
   c_string = '';
   rc=0;

      /************************************/
      /* Load class ROBJECT then create an*/
      /* instance of that class locally.  */
      /************************************/
   remote_c = 
      loadclass('sashelp.connect.robject');
   rid = instance(remote_c);

      /************************************/
      /* Define the remote host and the   */
      /* location of the class on which   */
      /* method would be used.            */
      /************************************/
   remval = optgetc('REMOTE');
   c_string = 'sashelp.fsp.datast_m';
   r_string = 'remote//' || remval;

      /************************************/
      /* Create remote instance of the    */
      /* class.                           */
      /************************************/
   call send(rid, '_createRemoteInstance', 
             r_string, c_string, rc);

      /************************************/
      /* Begin with method "_SET_DATASET_"*/
      /************************************/
   call send(rid, '_beginMethod', 
             "_SET_DATASET_", rc);
   put ' ';
   put '_beginMethod of _SET_DATASET_ 
        was successful ... ';

      /************************************/
      /* Begin sending information to the */
      /* method. Send name of class;      */
      /* mode INPUT. Be sure the data     */
      /* set itself exists.               */
      /************************************/
   dsname = 'work.a';
   c_mode = "I";
   c_name = "remote dataset name";
   put ' ';
   put "submitting the name of the remote 
        dataset " dsname c_mode c_name;
   call send(rid, '_addMethodArgC', dsname, 
             c_mode, rc, c_name);

      /************************************/
      /* After all required information   */
      /* has been sent to the method,     */
      /* invoke _SET_DATASET_.            */
      /************************************/
   put ' ';
   put 'Invoking _SET_DATASET_ method...';
   r_list = makelist();
   call send(rid, '_invokeMethod', r_list,rc);
   put 'Invoke method _SET_DATASET_ 
        was successful ... ';

      /************************************/
      /* Begin method                     */
      /* "_GET_DATASET_NAME_".            */
      /************************************/
   call send(rid, '_beginMethod', 
             "_GET_DATASET_NAME_", rc);
   put ' ';
   put '_beginMethod of _GET_DATASET_NAME_ 
           was successful ... ';

      /************************************/
      /* Begin sending information to the */
      /* method; mode OUTPUT because      */
      /* results are expected now.        */
      /************************************/
   dsname = '';
   c_mode = "O";
   c_name = "return the dataset name";
   put "expecting a result variable back " 
      dsname c_mode c_name;
   call send(rid, '_addMethodArgC', dsname, 
             c_mode, rc, c_name);

      /************************************/
      /* After all required information   */
      /* has been sent to the method,     */
      /* invoke _GET_DATASET_NAME_.       */
      /************************************/
   put ' ';
   put 'Invoking _GET_DATASET_NAME_ method...';
   r_list = makelist();
   call send(rid, '_invokeMethod', r_list,rc);
   put 'Invoke method was successful...';

   if (rc eq 0) then
      do;
         mrc = getnitemn(r_list, '_mrc', 
                         1, 1, 0);
         put ' ';
         put "method return code= " mrc;
         put "now we need to fetch the result 
              from the result list";

         /**********************************/
         /* After the method is invoked,   */
         /* a list is created that holds   */
         /* the result. Fetch the results  */
         /* from the list and display them.*/
         /**********************************/
        if (mrc = 0) then
           do index = 1 to listlen(r_list);
              select(itemtype(r_list, index));
              when('C')
                 do;
                    rem_varc = 
                       getitemc(r_list, index);
                    c_name='';
                    c_name = 
                       nameitem(r_list, index);
                    put '_GET_DATASET_NAME_ 
                         when character: ' 
                         rem_varc c_name;
                 end;
              when('N')
                 do;
                    rem_varn = 
                       getitemn(r_list, index);
                    c_name='';
                    c_name = 
                       nameitem(r_list, index);
                    put '_GET_DATASET_NAME_ 
                         when numeric: ' 
                         rem_varn c_name;
                 end;
              when('L')
                 do;
                    rem_varl = 
                       getiteml(r_list, index);
                    c_name='';
                    c_name = 
                       nameitem(r_list, index);
                    put '_GET_DATASET_NAME_ 
                         when list: ' 
                         rem_varl c_name;
                end;
             end;
          end;
      end;

      /**************************************/
      /* For clean-up purposes, destroy the */
      /* remote instance.                   */
      /**************************************/
   put ' ';
   put 'Destroying remote instance ... ';
   call send(rid, '_destroyRemoteInstance',rc);
   put 'remote instance destroyed successful';
return;


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.