Understanding the C++ Template

The C++ template can be used as a starting point for your C++ program. This section contains a skeleton of the generated C++ template for a component interface named SDK_BUS_EXP, which is part of the component interface SDK. The template has been edited for length.

Include all the required header files.

#ifdef PS_WIN32
#include "stdafx.h"
#endif
 
#include "cidef.h"
#include "apiadapterdef.h"
#include "PSApiAdapterInter.h"
#include "PSApiExternalLib.h"
#include "peoplesoft_peoplesoft_i.h"
#include <stdio.h>
#include <iostream.h>
#include <wchar.h>
 
HPSAPI_SESSION hSession;
TCHAR tmpValue[1024];
 
.....
 
void main(int argc, char* argv[])
{
   //***** Set Connect Parameters *****
   TCHAR strServerName[40], strServerPort[10], strAppServerPath[80];
   TCHAR strUserID[80], strPassword[80];
   .....
 
   //Build Application Server Path
   _stprintf(strAppServerPath, _T("%s:%s"), strServerName, strServerPort);

Note: To enable Jolt failover and load balancing in the PeopleSoft Internet Architecture, you can supply multiple application server domains for the strAppServerPath variable. Separate the domain names with a comma, and make sure that no spaces are included, for example, strAppServerPath = //APPSRVR1:8000,//APPSRVR2:9000.

Create the PeopleSoft Session object to enable access to the PeopleSoft system.

The Session object controls the environment and enables you to perform error handling for all APIs from a central location.

   //***** Create PeopleSoft Session *****
   PSAPIVARBLOB ExternalAuth;
   memset(&ExternalAuth, 0, sizeof(PSAPIVARBLOB));
   hSession = PSApiCreateSession();
   if (!hSession)
   {
      wprintf(L"\nUnable to Create Session\n");
      return;
   }

Connect to the Application server by using the Session_Connect() function.

   //***** Connect to the App Server *****
   if (!Session_Connect(hSession, 1, strAppServerPath, strUserID,  
     strPassword,ExternalAuth))
   {
      wprintf(L"\nUnable to Connect to Application Server\n");
      ErrorHandler();
      return;
   }

Get a reference to the component interface providing its name. (A runtime error occurs if the component interface does not exist.)

   //***** Get Component Interface *****
   HPSAPI_SDK_BUS_EXP hSdkBusExp;
   TCHAR ciName[30];
   _tcscpy(ciName, _T("SDK_BUS_EXP"));
   hSdkBusExp = (HPSAPI_SDK_BUS_EXP) Session_GetCompIntfc(hSession, 
      ciName);
   if (!hSdkBusExp)
   {
      wprintf(L"\nUnable to Get Component Interface %s\n", ciName);
      ErrorHandler();
      return;
   }
 
   //***** Set the Component Interface Mode *****
   SdkBusExp_SetInteractiveMode(hSdkBusExp, false);
   SdkBusExp_SetGetHistoryItems(hSdkBusExp, true);
   SdkBusExp_SetEditHistoryItems(hSdkBusExp, false);

Set the keys for the component interface. In this example, SDK_EMPLID is the Get key.

   //***** Set Component Interface Get/Create Keys *****
   TCHAR strSdkEmplid[80];
   wprintf(L"\nEnter SdkEmplid: ");
   _getts(strSdkEmplid);
   SdkBusExp_SetSdkEmplid(hSdkBusExp, strSdkEmplid);

The <CI_NAME>_Get() function retrieves data from the database associated with the key values.

   //***** Execute Get *****
   if (!SdkBusExp_Get(hSdkBusExp))
   {
      wprintf(L"\nUnable to Get Component for the Search keys provided.\n");
      ErrorHandler();
      return;
   }

Get and print properties at level 0.

   wprintf(L"SdkBusExp.SdkName: %s\n", 
      printProperty(SdkBusExp_GetSdkName(hSdkBusExp), tmpValue));

Similar code is generated for the properties SDK_BIRTHDATE and SDK_DEPTID.

Get collection at level 1 (SDK_BUS_EXP_PER).

   HPSAPI_SDK_BUS_EXP_SDK_BUS_EXP_PERCOLLECTION 
      hSdkBusExpSdkBusExpPerCollection;
   HPSAPI_SDK_BUS_EXP_SDK_BUS_EXP_PER hSdkBusExpSdkBusExpPer;
   hSdkBusExpSdkBusExpPerCollection = 
       SdkBusExp_GetSdkBusExpPer(hSdkBusExp);

Get and print properties at level 1.

   for (int i17 = 0; i17 < SdkBusExpSdkBusExpPerCollection_GetCount
                         (hSdkBusExpSdkBusExpPerCollection); i17++)
   {
      hSdkBusExpSdkBusExpPer = SdkBusExpSdkBusExpPerCollection_Item
                          (hSdkBusExpSdkBusExpPerCollection, i17);
      wprintf(L"oSdkBusExpSdkBusExpPer.SdkExpPerDt: %s\n", 
         printProperty
      (SdkBusExpSdkBusExpPer_GetSdkExpPerDt(hSdkBusExpSdkBusExpPer), 
         tmpValue));

Similar code is generated for the properties SDK_EMPLID and SDK_BUS_EXP_SUM in the SDK_BUS_EXP_PER collection.

Get collection at level 2 (SDK_BUS_EXP_DTL).

      HPSAPI_SDK_BUS_EXP_SDK_BUS_EXP_PER_SDK_BUS_EXP_DTLCOLLECTION 
         hSdkBusExpSdkBusExpPerSdkBusExpDtlCollection;
      HPSAPI_SDK_BUS_EXP_SDK_BUS_EXP_PER_SDK_BUS_EXP_DTL 
         hSdkBusExpSdkBusExpPerSdkBusExpDtl;
      hSdkBusExpSdkBusExpPerSdkBusExpDtlCollection = 
      SdkBusExpSdkBusExpPer_GetSdkBusExpDtl(hSdkBusExpSdkBusExpPer);

Get and print properties at level 2.

      for (int i211 = 0; i211 < 
          SdkBusExpSdkBusExpPerSdkBusExpDtlCollection_GetCount
         (hSdkBusExpSdkBusExpPerSdkBusExpDtlCollection); i211++)
      {
         hSdkBusExpSdkBusExpPerSdkBusExpDtl = 
            SdkBusExpSdkBusExpPerSdkBusExpDtlCollection_Item
            (hSdkBusExpSdkBusExpPerSdkBusExpDtlCollection, i211);
 
         wprintf(L"oSdkBusExpSdkBusExpPerSdkBusExpDtl.SdkChargeDt: 
            %s\n", printProperty
            (SdkBusExpSdkBusExpPerSdkBusExpDtl_GetSdkChargeDt
           (hSdkBusExpSdkBusExpPerSdkBusExpDtl), tmpValue));

Similar code is generated for the properties SDK_EMPID, SDK_EXP_PER_DT, SDK_EXPENSE_CD, SDK_EXPENSE_AMT, SDK_CURRENCY_CD, SDK_BUS_PURPOSE, and SDK_DEPTID.

      }
   }

Disconnect from the Application server by using the disconnect method of the Session object. This method clears the buffers and releases the memory.

   //***** Disconnect from the App Server *****
   Session_Disconnect(hSession);
 
   return;
}