# Extended Member Query

### Code Example

    #include <windows.h>
    #include <essapi.h>
    #include <essotl.h>
    #include <string.h>
    #include <stdio.h>
    #include <stdlib.h>

    #define AD_CHK_PRINTF_1(ARG1, ARG2)
    do
    {
       printf(ARG1, (ARG2) ? (ARG2) : "NullValue");
    }
    while (0)

    void PrintResult(ESS_HCTX_T      hCtx,
                     ESS_HINST_T     hInst,
                     ESS_HOUTLINE_T  hOutline,
                     ESS_HMEMBER_T   hMbr)
    {
       ESS_PMBRINFO_T pMbrInfo = NULL;
       ESS_STS_T      sts;
       int            size;
       ESS_STR_T      pszFormula = NULL;
       ESS_STR_T      pszLastFormula = NULL;
       ESS_STR_T      pszCommentEx = NULL;
       ESS_STR_T      pszAlias = NULL;
       ESS_STR_T      pszAliasCombo = NULL;
       ESS_PMBRNAME_T pUDAList = NULL;
       ESS_USHORT_T   iCount = 0;
       ESS_STR_T      pszPrev = NULL;
       ESS_USHORT_T   iIndex;

       ESS_ULONG_T* pMemNum;
       ESS_ULONG_T* pDimNum;
       ESS_STR_T    pDimName = NULL;
       ESS_STR_T    pAliasName = NULL;
       ESS_STR_T    pNextName = NULL;
       ESS_STR_T    pPrevName = NULL;
       ESS_STR_T    pParentName = NULL;
       ESS_STR_T    pChildName = NULL;
       ESS_BOOL_T*  pCurrConv = NULL;
       ESS_ULONG_T* pStatus = NULL;

       sts = EssOtlGetMemberInfo(hOutline, hMbr, &pMbrInfo);
       if (sts != 0) goto Error;

       size = sizeof(ESS_MBRINFO_T);

       printf("MbrInfo\n");
       AD_CHK_PRINTF_1("    szMember --------------->(%s)\n",  pMbrInfo->szMember);
       printf("    usLevel  --------------->(%hd)\n", pMbrInfo->usLevel);
       printf("    usGen  ----------------->(%hd)\n", pMbrInfo->usGen);
       printf("    usConsolidation  ------->(%hd)\n", pMbrInfo->usConsolidation);
       printf("    fTwoPass  -------------->(%hd)\n", pMbrInfo->fTwoPass);
       printf("    fExpense  -------------->(%hd)\n", pMbrInfo->fExpense);
       printf("    usConversion ----------->(%hd)\n", pMbrInfo->usConversion);
       AD_CHK_PRINTF_1("    szCurMember ------------>(%s)\n",  pMbrInfo->szCurMember);
       printf("    usTimeBalance ---------->(%hd)\n", pMbrInfo->usTimeBalance);
       printf("    usSkip ----------------->(%hd)\n", pMbrInfo->usSkip);
       printf("    usShare ---------------->(%hd)\n", pMbrInfo->usShare);
       printf("    usStorage -------------->(%hd)\n", pMbrInfo->usStorage);
       printf("    usCategory ------------->(%hd)\n", pMbrInfo->usCategory);
       printf("    usStorageCategory ------>(%hd)\n", pMbrInfo->usStorageCategory);
       AD_CHK_PRINTF_1("    szComment -------------->(%s)\n",  pMbrInfo->szComment);
       printf("    ulChildCount ----------->(%ld)\n", pMbrInfo->ulChildCount);

       sts = EssOtlGetMemberFormula(hOutline, hMbr, &pszFormula);
       if (sts) printf("sts=%d ", sts);
       AD_CHK_PRINTF_1("szFormula ------------------>(%s)\n", pszFormula);

       sts = EssOtlGetMemberLastFormula(hOutline, hMbr, &pszLastFormula);
       if (sts) printf("sts=%d ", sts);
       AD_CHK_PRINTF_1("szLastFormula -------------->(%s)\n", pszLastFormula);

       sts = EssOtlGetMemberCommentEx(hOutline, hMbr, &pszCommentEx);
       if (sts) printf("sts=%d ", sts);
       AD_CHK_PRINTF_1("szCommentEx ---------------->(%s)\n", pszCommentEx);

       sts = EssOtlGetMemberAlias(hOutline, hMbr, ESS_NULL, &pszAlias);
       if (sts) printf("sts=%d ", sts);
       AD_CHK_PRINTF_1("szAlias (Default)----------->(%s)\n", pszAlias);

       sts = EssOtlGetNextAliasCombination(hOutline, hMbr, ESS_NULL, "\0", &pszAliasCombo);
       if (sts) printf("sts=%d ", sts);

       printf("szAliasCombo ::\n" );
       pszPrev = pszAliasCombo;
       while (sts && pszAliasCombo)
       {
          AD_CHK_PRINTF_1("\t(%s)\n", pszAliasCombo);
          sts = EssOtlGetNextAliasCombination(hOutline, hMbr, ESS_NULL, pszPrev, &pszAliasCombo);
          EssFree(hInst, pszPrev);
          pszPrev = pszAliasCombo;
       }

       sts = EssOtlGetUserAttributes(hOutline, hMbr, &iCount, &pUDAList);
       if (sts) printf("sts=%d ", sts);

       printf("User Defined Attributes ::\n");
       for(iIndex = 0; iIndex < iCount; iIndex++)
          AD_CHK_PRINTF_1("\t(%s)\n", pUDAList[iIndex]);

       sts = EssOtlGetMemberField(hOutline, hMbr, ESS_OTLQRYMBR_NUMBER, (ESS_PPVOID_T) &pMemNum);
       if (sts)
       {
          printf("sts=%d ", sts);
       }
       else
       {
          printf("Member Number  ------------------>(%ld)\n", *pMemNum);
          EssFree(hInst, pMemNum);
       }

       sts = EssOtlGetMemberField(hOutline, hMbr, ESS_OTLQRYMBR_DIMNUMBER, (ESS_PPVOID_T) &pDimNum);
       if (sts)
       {
          printf("sts=%d ", sts);
       }
       else
       {
          printf("Dimension Number ---------------->(%ld)\n", *pDimNum);
          EssFree(hInst, pDimNum);
       }

       sts = EssOtlGetMemberField(hOutline, hMbr, ESS_OTLQRYMBR_DIMNAME, (ESS_PPVOID_T) &pDimName);
       if (sts)
       {
          printf("sts=%d ", sts);
       }
       else
       {
          AD_CHK_PRINTF_1("Dimension Name ------------------>(%s)\n",  pDimName);
          EssFree(hInst, pDimName);
       }

       sts = EssOtlGetMemberField(hOutline, hMbr, ESS_OTLQRYMBR_ALIASNAME, (ESS_PPVOID_T) &pAliasName);
       if (sts)
       {
          printf("sts=%d ", sts);
       }
       else
       {
          AD_CHK_PRINTF_1("Alias Name     ------------------>(%s)\n",  pAliasName);
          EssFree(hInst, pAliasName);
       }

       sts = EssOtlGetMemberField(hOutline, hMbr, ESS_OTLQRYMBR_NEXTNAME, (ESS_PPVOID_T) &pNextName);
       if (sts)
       {
          printf("sts=%d ", sts);
       }
       else
       {
          AD_CHK_PRINTF_1("Next Mbr  Name ------------------>(%s)\n",  pNextName);
          EssFree(hInst, pNextName);
       }

       sts = EssOtlGetMemberField(hOutline, hMbr, ESS_OTLQRYMBR_PREVNAME, (ESS_PPVOID_T) &pPrevName);
       if (sts)
       {
          printf("sts=%d ", sts);
       }
       else
       {
          AD_CHK_PRINTF_1("Prev Mbr  Name ------------------>(%s)\n",  pPrevName);
          EssFree(hInst, pPrevName);
       }

       sts = EssOtlGetMemberField(hOutline, hMbr, ESS_OTLQRYMBR_PARENTNAME, (ESS_PPVOID_T) &pParentName);
       if (sts)
       {
          printf("sts=%d ", sts);
       }
       else
       {
          AD_CHK_PRINTF_1("Parent MbrName ------------------>(%s)\n",  pParentName);
          EssFree(hInst, pParentName);
       }

       sts = EssOtlGetMemberField(hOutline, hMbr, ESS_OTLQRYMBR_CHILDNAME, (ESS_PPVOID_T) &pChildName);
       if (sts)
       {
          printf("sts=%d ", sts);
       }
       else
       {
          AD_CHK_PRINTF_1("Child Mbr Name ------------------>(%s)\n",  pChildName);
          EssFree(hInst, pChildName);
       }

       sts = EssOtlGetMemberField(hOutline, hMbr, ESS_OTLQRYMBR_CURRENCYCONVDB, (ESS_PPVOID_T) &pCurrConv);
       if (sts)
       {
          printf("sts=%d ", sts); printf("Curr Conv Type ------------------>\n");
       }
       else
       {
          AD_CHK_PRINTF_1("Curr Conv Type ------------------>(%ld)\n", *pCurrConv);
          EssFree(hInst, pCurrConv);
       }

       sts = EssOtlGetMemberField(hOutline, hMbr, ESS_OTLQRYMBR_STATUS, (ESS_PPVOID_T) &pStatus);
       if (sts)
          { printf("sts=%d ", sts); printf("Status    ------------------>\n"); }
       else
       {
          printf("Status       ------------------>(%hd)\n", *pStatus);
          EssFree(hInst, pStatus);
       }

       EssFree(hInst, pMbrInfo);
       EssFree(hInst, pszFormula);
       EssFree(hInst, pszLastFormula);
       EssFree(hInst, pszCommentEx);
       EssFree(hInst, pszAlias);
       EssFree(hInst, pszAliasCombo);
       return;

    Error:
       printf("******************* Error *************************");
    }

    int TestCode_EssOtlQueryMembersEx(ESS_HCTX_T hCtx,
                                      ESS_HINST_T  hInst)
    {
       ESS_STS_T sts = ESS_STS_NOERR;
       ESS_HOUTLINE_T hOutline;
       ESS_OBJDEF_T Object;
       ESS_HMEMBER_T hMember = 0;
       ESS_PHMEMBER_T phMemberArray = ESS_NULL;
       ESS_ULONG_T i;
       unsigned long MaxCount = -1;
       ESS_STR_T   member_fields;
       ESS_STR_T   member_selection;

       /* query string to get level numbers of all markets members */
       member_fields    = "<SelectMbrInfo ( MemberName, MemberLevel,Consolidation, MemberFormula ) ";
       member_selection = "@ichild(Product), @ichild(Market)";
       memset(&Object, '\0', sizeof(Object));
       Object.hCtx      = hCtx;
       Object.ObjType   = ESS_OBJTYPE_OUTLINE;
       Object.AppName   = "Basic";
       Object.DbName    = "Demo";
       Object.FileName  = "Demo";

       sts = EssOtlOpenOutlineQuery(hCtx, &Object, &hOutline);
       if (sts) goto exit;

       if(!sts)
       {
          ESS_POTLQUERYERRORLIST_T pqryErrorList;

          sts = EssOtlQueryMembersEx(hOutline, member_fields, member_selection, &MaxCount, &phMemberArray, &pqryErrorList);
          if (sts) goto exit;

          if (phMemberArray)
             for (i = 0; i< MaxCount; i++)
                PrintResult(hOutline, phMemberArray[i]);
       }

       if(MaxCount && phMemberArray)
       {
          sts = EssOtlFreeMembers(hOutline, MaxCount, phMemberArray);
          if (sts)
             printf("EssOtlFreeMembers   sts = %d\n",sts);
       }

       sts = EssOtlCloseOutline(hOutline);

    exit:
       return sts;
    }

Return to EssOtlQueryMembersEx() or EssOtlGetMemberField().