Automating your Essbase Cube [ 330 ] Essbase nested coding style examples Here is a representative example of the nested coding style and the obvious benets of employing such a method or style. Begin action 1 Begin action 2 Begin action 3 Perform action 3 End action 3 Begin action 4 Perform action 4 End action 4 End action 2 End action 1 This example should illustrate nicely why the nested style is the preferable code writing style. The next example will now put the previous example into Essbase functionality context so it makes sense for you. Most Essbase API functions usually must be started or opened and after completion of the task they must be ended or closed. Initialize the API Login to a server Connect to a database Open a database outline Browse the outline Close the outline Open a report Modify & save the report Close the report Disconnect from a database Logout from the server Terminate the API Typically, the group of Essbase API calls or functions illustrated in the previous example would be embedded in a VB subroutine so that it would actually look more like this: Sub BrowseOutlineAlterReport() Initialize the API Login to a server Connect to a database Open a database outline Browse the outline Close the outline Open a report Modify & save the report This material is copyright and is licensed for the sole use by Paul Corcorran on 5th July 2009 8601 ave. p #1, , lubbock, , 79423 Download at Boykma.Com Chapter 8 [ 331 ] Close the report Disconnect from a database Logout from the server Terminate the API End Sub As you can see each Essbase API call has an ending or terminating call that must be executed when the desired function has completed. Many code editors support the nested coding style by automatically indenting the next line of written code to the same indentation as the previous line making nested code writing even easier. The Visual Basic editor supports nested code writing and Oracle Essbase recommends you use the nested coding style when coding Essbase API functions. Essbase API function declarations For your convenience your Essbase package comes with a VB code module that has all of the Essbase API functions and declarations already coded for you. All you need to do is add the module to your VB/VBA/COM+ project then start coding the API calls and functions. The le's name is esb32.bas and is a wonderful time saver. This material is copyright and is licensed for the sole use by Paul Corcorran on 5th July 2009 8601 ave. p #1, , lubbock, , 79423 Download at Boykma.Com Automating your Essbase Cube [ 332 ] As you can see in the previous screenshot, the Essbase supplied API declaration module includes all of the necessary global variables and other API related structures, as well as all of the API function calls. What a nice thing to have! How to code an API function In the following example, we will code an Essbase API function that returns database information into an Essbase private type structure named DBINFO: Sub GetDataBaseInfo(Appname as String, DBName as String) 'Pass Application name and Database name to VB subroutine Dim sts as ESB_STS_T 'Dimension return code variable Dim hCtx as ESB_HCTX_T 'Dimension API handle context Dim DbInfo as ESB_DBINFO_T 'Dimension DB information variable sts = EsbGetDatabaseInfo (hCtx, Appname, DBName, DbInfo) 'Execute 'API function If sts = ESB_STS_NOERR ' Test API function return code Call DisplayDatabaseInformation 'Branch to new subroutine on 'satisfactory return code End If End Sub After a successful call to the Essbase API EsbGetDatabaseInfo function, the DbInfo structure will be populated with a variety of database information for the database that was passed to the function. The following is an example of the variable structure showing what database information is returned. Type ESB_DBINFO_T ElapsedDbTime As Long 'Elapsed database time DataFileCacheSetting As Long 'Data File Cache size database DataFileCacheSize As Long DataCacheSetting As Long DataCacheSize As Long 'run-time size of the Data cache IndexCacheSetting As Long IndexCacheSize As Long 'size of the Index cache IndexPageSetting As Long IndexPageSize As Long 'run-time size of an Index Page nDims As Long 'number of dimensions This material is copyright and is licensed for the sole use by Paul Corcorran on 5th July 2009 8601 ave. p #1, , lubbock, , 79423 Download at Boykma.Com Chapter 8 [ 333 ] AppName As String * ESB_APPNAMELEN 'application name Name As String * ESB_DBNAMELEN 'database name Country As String * ESB_MBRNAMELEN 'country dimension Time As String * ESB_MBRNAMELEN 'time dimension Category As String * ESB_MBRNAMELEN 'category dimension Type As String * ESB_MBRNAMELEN 'type dimension CrPartition As String * ESB_MBRNAMELEN 'curr partition member DbType As Integer ' Database Type Status As Integer 'database load status nConnects As Integer 'number of users connected nLocks As Integer 'number of blocks locked Data As Integer 'data loaded ag End Type There sure is a lot of information passed back from this call. Now do you remember back a little bit that the variable name used in this API call is DbInfo? Yes, the variable DbInfo, dimensioned using the variable structure above, now contains all of the data that is listed in the ESB_DBINFO_T structure. To read any of the information returned in this structure, the steps are very easy. For instance, if you want to read how many users are connected to the database you returned the information from just code: variable = DbInfo.nConnects and your variable will now contain the number of users connected to the database. You can also use DbInfo.nConnects elsewhere in your program depending on how you dimensioned it. Essbase API code sample blocks It seems that for most good programmers, the only difference between programming languages is the syntax of the code itself. Let's face it, logic is logic, and If means If and End If means End If in all programming languages. The syntax may vary though, as we've all seen End If or End-If or ENDIF. This material is copyright and is licensed for the sole use by Paul Corcorran on 5th July 2009 8601 ave. p #1, , lubbock, , 79423 Download at Boykma.Com Automating your Essbase Cube [ 334 ] You have probably sensed that Oracle has created quite a product with Essbase and you are correct. You have probably also gotten the idea that Oracle is very thorough and has prepared well written and easy to understand system documentation. Well, we'd have to say you are correct once again. The following is a picture of a typical API function reference found in the Oracle Essbase API Reference that can be found online or accessed through the EAS tool. The following example is an exact representation of how the Essbase API Function Reference looks, when accessed through EAS. It also looks very similar when accessed through the Internet. This material is copyright and is licensed for the sole use by Paul Corcorran on 5th July 2009 8601 ave. p #1, , lubbock, , 79423 Download at Boykma.Com . nested code writing and Oracle Essbase recommends you use the nested coding style when coding Essbase API functions. Essbase API function declarations For your convenience your Essbase package comes. 5th July 20 09 8601 ave. p #1, , lubbock, , 794 23 Download at Boykma.Com Automating your Essbase Cube [ 334 ] You have probably sensed that Oracle has created quite a product with Essbase and. Corcorran on 5th July 20 09 8601 ave. p #1, , lubbock, , 794 23 Download at Boykma.Com Automating your Essbase Cube [ 332 ] As you can see in the previous screenshot, the Essbase supplied API declaration