project QadFinancials > class TFRWTreeView > method GetFRWTreeLevel2Node


Parameters


icTargetChartinputcharacter
icCubeNameinputcharacter
icTreeNodeCodeinputcharacter
icFilterAnCodeinputcharacter
icFromReportPeriodinputcharacter
icToReportPeriodinputcharacter
icFromReportYearinputcharacter
icToReportYearinputcharacter
icViewCurrencyinputcharacter
icViewForUserinputcharacter
icAmountInViewinputcharacter
tNewNodeoutputtemp-table
tErrorTableoutputtemp-table
icCurrentLanguageinputcharacter
bcTempParamsinput-outputcharacter
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


QadFinancials
method TFRWTreeView.GetFRWTreeNodeMainMethod


program code (program1/tfrwtreeview.p)

/* ================================================================= */
/* Reading input parameters                                          */
/* ================================================================= */
define buffer bcube        for frwcube.
define buffer bcubecy      for frwcubecy.
define buffer bcubeperiod  for frwcubeperiod.

/* ================================================================= */
/* Check if data is existing                                         */
/* ================================================================= */
/* lookup the data from the report master and column group */
find first frwtreenode where frwtreenode.frwtreenodecode = icTreeNodeCode and
				  frwtreenode.parentFRWTreeNode_ID = 0 no-lock no-error.
if not available frwtreenode then do:
	/*The report tree specified in the report master is invalid*/
    create tErrorTable.
    assign tErrorTable.tcErrorMessage = trim(#T-33'The Report Tree specified in the report master is invalid.':255(900895412)T-33#)
           oiReturnStatus = -1.
	return.
end.
else do:
	assign viTreeNode_ID = frwtreenode.frwtreenode_id.
end.

find frwancode where frwancode.frwancode_id = frwtreenode.frwancode_id no-lock no-error.
if not available frwancode then do:
	/*the analysis code of the report tree specified in the report master is invalid*/
    create tErrorTable.
    assign tErrorTable.tcErrorMessage = trim(#T-93'The analysis code of the report tree specified in the report master is invalid':255(838472521)T-93#)
           oiReturnStatus = -1.
	return.
end.

empty temp-table tFilterEntities.
if FRWAnCodeAnalyseType = "A" then
do:
	for each FRWAnCodeElem of FRWAnCode where FRWAnCodeElem.FRWAnCodeElemCOAType = "Company" no-lock,
		each FRWAnCodeElemDet of FRWAnCodeElem no-lock:
		create tFilterEntities.
		assign tFilterEntities.tiEntity_ID = FRWAnCodeElemDet.FRWAnCodeElemDetValue.
	end.
end.
assign vcAncode = frwancode.frwancodecode.

assign vccubenames = icCubeName.
find frwcube where frwcube.frwcubecode = vccubenames no-lock no-error.
if not available frwcube then do:
	/*This cube does not exist. */
    create tErrorTable.
    assign tErrorTable.tcErrorMessage = trim(#T-15'This cube does not exist.':255(757983350)T-15#)
           oiReturnStatus = -1.
	return.
end.

find frwchart where frwchart.frwchartcode = frwcube.frwcubefrwchartcode no-lock no-error.
if not available frwchart then do:
	/*This cube has no valid Report Chart. */
    create tErrorTable.
    assign tErrorTable.tcErrorMessage = trim(#T-49'This cube has no valid Report Chart.':255(57381494)T-49#)
           oiReturnStatus = -1.
    return.
end.
assign vcTargetchart = frwchart.frwchartcode.

find frwancode where frwancode.frwancodecode = vcancode and
			   frwancode.frwancodefrwchartcode = vctargetchart no-lock no-error.
if not available frwancode then do:
	/*This Analysis Code belongs to another Report Chart*/
    create tErrorTable.
    assign tErrorTable.tcErrorMessage = trim(#T-60'This Analysis Code belongs to another Report Chart':255(75935415)T-60#)
           oiReturnStatus = -1.
    return.
end.

find frwtreenode where frwtreenode.frwancode_id = frwancode.frwancode_id and
	 frwtreenode.parentfrwtreenode_id = 0 no-lock no-error.
if not available frwtreenode then do:
	/*This Analysis Code is not defined on a Tree.*/
    create tErrorTable.
    assign tErrorTable.tcErrorMessage = trim(#T-11'This Analysis Code is not defined on a Tree.':255(245995331)T-11#)
           oiReturnStatus = -1.
	return.
end.

/* ================================================================= */
/* Validate filter AnCode                                            */
/* ================================================================= */
if icFilterAnCode <> "" then do:
	find first frwancode where frwancode.frwancodecode = icFilterAnCode no-lock no-error.
	if not available frwancode then do:
		/*The filter analysis code entered does not exist.*/
        create tErrorTable.
        assign tErrorTable.tcErrorMessage = trim(#T-39'The filter analysis code entered does not exist.':255(815621422)T-39#)
           oiReturnStatus = -1.
		return.
	end.
	find frwancode where frwancode.frwancodecode = icFilterAnCode and
					 frwancode.frwchart_id = frwchart.frwchart_id no-lock no-error.
	if not available frwancode then do:
		/*The filter analysis code entered belongs to another chart.*/
        create tErrorTable.
        assign tErrorTable.tcErrorMessage = trim(#T-41'The filter analysis code entered belongs to another chart.':255(311222183)T-41#)
           oiReturnStatus = -1.
		return.
	end.
	else
	do:
		if FRWAnCodeAnalyseType <> "A" then
		do:
			/* Analysis Code Type is incorrect.*/
            create tErrorTable.
            assign tErrorTable.tcErrorMessage = trim(#T-27'Analysis Code Type is incorrect.':255(88867738)T-27#)
                oiReturnStatus = -1.
			return.
		end.
	end.
	if not can-find (first tFilterEntities) then
	do:
		for each FRWAnCodeElem of FRWAnCode where FRWAnCodeElem.FRWAnCodeElemCOAType = "Company" no-lock,
		   each FRWAnCodeElemDet of FRWAnCodeElem no-lock:
		   create tFilterEntities.
		   assign tFilterEntities.tiEntity_ID = FRWAnCodeElemDet.FRWAnCodeElemDetValue.
		end.
	end.
	else do:
		/* if the root node AnCode of the tree has already Entity selection and also the Filter AnCode has Entity, then only Entities is both AnCodes will be reported */
		if can-find (first FRWAnCodeElem of FRWAnCode where FRWAnCodeElem.FRWAnCodeElemCOAType = "Company") then do:
			for each FRWAnCodeElem of FRWAnCode where FRWAnCodeElem.FRWAnCodeElemCOAType = "Company" no-lock,
				each FRWAnCodeElemDet of FRWAnCodeElem no-lock:
				find tFilterEntities where tFilterEntities.tiEntity_ID = FRWAnCodeElemDet.FRWAnCodeElemDetValue no-error.
				if available tFilterEntities then assign tFilterEntities.tlIsInBothAnCodes = yes.
			end.
			for each tFilterEntities where tFilterEntities.tlIsInBothAnCodes = no:
				delete tFilterEntities.
			end.
		end.
	end.
end.

/* ================================================================= */
/* Check Security : Report Tree Drill Down                           */
/* ================================================================= */ 
if icViewForUser = "" then assign icViewForUser = "mfg".
empty temp-table trole.
empty temp-table tuserentity.
for each usr where usrlogin = icViewForUser and usrisactive no-lock,
	each usrrolecompany of usr no-lock,
	each qaddb.role of usrrolecompany where roleisactive no-lock,
	each company of usrrolecompany no-lock,
	each resources where resourceuri = "urn:cbf:BFRWTreeView.FRWDrillDown" no-lock,
	each roleresource of resources where roleresource.role_id = role.role_id  no-lock:
		create tuserentity.
		assign tuserentity.tirole_id = qaddb.role.role_id
		   tuserentity.ticompany_id = company.company_id.
		if can-find (first trole) then do:
			find first trole where trole.tirole_id = tuserentity.tirole_id no-error.
			if not available trole then delete tuserentity.
		end.
end.
assign
	vlsecuritypassed = yes
	vcnoaccessentity = "".
for each frwcubecy of frwcube no-lock:
	if can-find (first tFilterEntities) and
	not can-find (first tFilterEntities where tFilterEntities.tiEntity_ID = FRWCubeCy.Company_ID) then next. /* there is a filter excluding this entity */
	find first tuserentity where tuserentity.ticompany_id = frwcubecy.company_id no-error.
	if not available tuserentity then do:
		assign
			vlsecuritypassed = no
			vcnoaccessentity = vcnoaccessentity + frwcubecy.frwcubecycompanycode + ",".
	end.
end.
if vlsecuritypassed = no then do:
	/*security settings do not allow to report cube data of entity.*/
    create tErrorTable.
    assign tErrorTable.tcErrorMessage = trim(#T-29'Security settings do not allow to report cube data of entity.':255(832475149)T-29#)
           oiReturnStatus = -1.
	return.
end.
/* end check security */

/* ================================================================= */
/* Check Language                                                    */
/* ================================================================= */
/* set the language if required */
find syst no-lock no-error.                                                              
if available syst then do:
	find lng of syst no-lock no-error.
	if available lng then do:
		if lng.lngcode <> icCurrentLanguage and
		   icCurrentLanguage <> "" then do:
			find lng where lng.lngcode = icCurrentLanguage no-lock no-error.
			if available lng then
				assign vlNeedTranslation = yes
					viLanguageID = lng.lng_id.
		end.
	end.
end.

/* ================================================================= */
/* Check Saf in FRWChart                                             */
/* ================================================================= */
assign vitargglsetid = frwchart.glsharedset_id
		vitargsubaccountsetid = frwchart.divisionsharedset_id
		vitargcostcentersetid = frwchart.costcentresharedset_id
		vitargprojectsetid = frwchart.projectsharedset_id.

  /* Determine the safconcepts linked to the reporting chart. */

  if frwchart.frwchartsafconcept01 <> "" then do:
	 find safconcept where safconcept.safconceptcode = frwchart.frwchartsafconcept01 no-lock no-error.
	 if not available safconcept then do:
		/*Report chart contains an invalid SAF concept.*/
        create tErrorTable.
        assign tErrorTable.tcErrorMessage = trim(#T-66'Report chart contains an invalid SAF concept '&1'.':255(96818071)T-66#, frwchart.frwchartsafconcept01)
           oiReturnStatus = -1.
		return.
	   end.
	 assign visaf1conceptid = safconcept.safconcept_id.
  end.
  else assign visaf1conceptid = 0.

  if frwchart.frwchartsafconcept02 <> "" then do:
	 find safconcept where safconcept.safconceptcode = frwchart.frwchartsafconcept02 no-lock no-error.
	 if not available safconcept then do:
		/*Report chart contains an invalid SAF concept */
        create tErrorTable.
        assign tErrorTable.tcErrorMessage = trim(#T-95'Report chart contains an invalid SAF concept '&1'.':255(96818071)T-95#, frwchart.frwchartsafconcept02)
           oiReturnStatus = -1.
		return.
	   end.
	 assign visaf2conceptid = safconcept.safconcept_id.
  end.
  else assign visaf2conceptid = 0.

  if frwchart.frwchartsafconcept03 <> "" then do:
	 find safconcept where safconcept.safconceptcode = frwchart.frwchartsafconcept03 no-lock no-error.
	 if not available safconcept then do:
		/*Report chart contains an invalid SAF concept */
        assign tErrorTable.tcErrorMessage = trim(#T-23'Report chart contains an invalid SAF concept '&1'.':255(96818071)T-23#, frwchart.frwchartsafconcept03)
           oiReturnStatus = -1.
		return.
	   end.
	 assign visaf3conceptid = safconcept.safconcept_id.
  end.
  else assign visaf3conceptid = 0.

  if frwchart.frwchartsafconcept04 <> "" then do:
	 find safconcept where safconcept.safconceptcode = frwchart.frwchartsafconcept04 no-lock no-error.
	 if not available safconcept then do:
		/*Report chart contains an invalid SAF concept */
        assign tErrorTable.tcErrorMessage = trim(#T-8'Report chart contains an invalid SAF concept '&1'.':255(96818071)T-8#, frwchart.frwchartsafconcept04)
           oiReturnStatus = -1.
		return.
	   end.
	 assign visaf4conceptid = safconcept.safconcept_id.
  end.
  else assign visaf4conceptid = 0.

  if frwchart.frwchartsafconcept05 <> "" then do:
	 find safconcept where safconcept.safconceptcode = frwchart.frwchartsafconcept05 no-lock no-error.
	 if not available safconcept then do:
		/*Report chart contains an invalid SAF concept */
        assign tErrorTable.tcErrorMessage = trim(#T-77'Report chart contains an invalid SAF concept '&1'.':255(96818071)T-77#, frwchart.frwchartsafconcept05)
           oiReturnStatus = -1.
		return.
	   end.
	 assign visaf5conceptid = safconcept.safconcept_id.
  end.
  else assign visaf5conceptid = 0.

  if frwchart.frwchartsafconcept06 <> "" then do:
	 find safconcept where safconcept.safconceptcode = frwchart.frwchartsafconcept06 no-lock no-error.
	 if not available safconcept then do:
		/*Report chart contains an invalid SAF concept */
        assign tErrorTable.tcErrorMessage = trim(#T-62'Report chart contains an invalid SAF concept '&1'.':255(96818071)T-62#, frwchart.frwchartsafconcept06)
           oiReturnStatus = -1.
		return.
	   end.
	 assign visaf6conceptid = safconcept.safconcept_id.
  end.
  else assign visaf6conceptid = 0.

  if frwchart.frwchartsafconcept07 <> "" then do:
	 find safconcept where safconcept.safconceptcode = frwchart.frwchartsafconcept07 no-lock no-error.
	 if not available safconcept then do:
		/*Report chart contains an invalid SAF concept */
        assign tErrorTable.tcErrorMessage = trim(#T-55'Report chart contains an invalid SAF concept '&1'.':255(96818071)T-55#, frwchart.frwchartsafconcept07)
           oiReturnStatus = -1.
		return.
	   end.
	 assign visaf7conceptid = safconcept.safconcept_id.
  end.
  else assign visaf7conceptid = 0.

  if frwchart.frwchartsafconcept08 <> "" then do:
	 find safconcept where safconcept.safconceptcode = frwchart.frwchartsafconcept08 no-lock no-error.
	 if not available safconcept then do:
		/*Report chart contains an invalid SAF concept */
        assign tErrorTable.tcErrorMessage = trim(#T-81'Report chart contains an invalid SAF concept '&1'.':255(96818071)T-81#, frwchart.frwchartsafconcept08)
           oiReturnStatus = -1.
		return.
	   end.
	 assign visaf8conceptid = safconcept.safconcept_id.
  end.
  else assign visaf8conceptid = 0.

  if frwchart.frwchartsafconcept09 <> "" then do:
	 find safconcept where safconcept.safconceptcode = frwchart.frwchartsafconcept09 no-lock no-error.
	 if not available safconcept then do:
		/*Report chart contains an invalid SAF concept */
        assign tErrorTable.tcErrorMessage = trim(#T-76'Report chart contains an invalid SAF concept '&1'.':255(96818071)T-76#, frwchart.frwchartsafconcept09)
           oiReturnStatus = -1.
		return.
	   end.
	 assign visaf9conceptid = safconcept.safconcept_id.
  end.
  else assign visaf9conceptid = 0.

  if frwchart.frwchartsafconcept10 <> "" then do:
	 find safconcept where safconcept.safconceptcode = frwchart.frwchartsafconcept10 no-lock no-error.
	 if not available safconcept then do:
		/*Report chart contains an invalid SAF concept */
        assign tErrorTable.tcErrorMessage = trim(#T-47'Report chart contains an invalid SAF concept '&1'.':255(96818071)T-47#, frwchart.frwchartsafconcept10)
           oiReturnStatus = -1.
		return.
	   end.
	 assign visaf10conceptid = safconcept.safconcept_id.
  end.
  else assign visaf10conceptid = 0.

/* ================================================================= */
/* Check Period in FRWCube                                           */
/* ================================================================= */
assign viFromReportYear = INTEGER(icFromReportYear)
        viFromReportPeriod = INTEGER(icFromReportPeriod)
        viToReportYear = INTEGER(icToReportYear)
        viToReportPeriod = INTEGER(icToReportPeriod).

find frwcubeperiod where frwcubeperiod.frwcubeperiodfrwcubecode = frwcube.frwcubecode and
					 frwcubeperiod.frwcubeperiodreportyear = viFromReportYear and
					 frwcubeperiod.FRWCubePeriodReportPerInt = viFromReportPeriod no-lock no-error.
if not available frwcubeperiod then do:
	/*This reporting year/period does not exist for this cube*/
    create tErrorTable.
    assign tErrorTable.tcErrorMessage = trim(#T-31'This reporting year/period does not exist for this cube.':255(88236955)T-31#)
           oiReturnStatus = -1.
	return.
end.
find frwcubeperiod where frwcubeperiod.frwcubeperiodfrwcubecode = frwcube.frwcubecode and
					 frwcubeperiod.frwcubeperiodreportyear = vitoreportyear and
					 frwcubeperiod.FRWCubePeriodReportPerInt = vitoreportperiod no-lock no-error.
if not available frwcubeperiod then do:
	/*This reporting year/period does not exist for this cube*/
    create tErrorTable.
    assign tErrorTable.tcErrorMessage = trim(#T-21'This reporting year/period does not exist for this cube.':255(88236955)T-21#)
           oiReturnStatus = -1.
	return.
end.
if vifromreportyear > vitoreportyear then do:
	/*From Year cannot be greater than To Year*/
    create tErrorTable.
    assign tErrorTable.tcErrorMessage = trim(#T-44'From Year cannot be greater than To Year.':255(811004057)T-44#)
           oiReturnStatus = -1.
	return.
end.
if vifromreportyear = vitoreportyear and
   vifromreportperiod > vitoreportperiod then do:
	/*From Period cannot be greater than To Period in the same year*/
    create tErrorTable.
    assign tErrorTable.tcErrorMessage = trim(#T-69'From Period cannot be greater than To Period in the same year.':255(903942717)T-69#)
           oiReturnStatus = -1.
	return.
end.

/* ================================================================= */
/* Check if all reported entities have same base currency.           */
/* If yes, the view can be in base currency, else not.               */
/* ================================================================= */
assign vlSingleCurrency = yes
	   viCurrencyID = 0.
for each frwcubecy where frwcubecy.frwcube_id = frwcube.frwcube_id no-lock:
	 if can-find (first tFilterEntities) and
		not can-find (first tFilterEntities where tFilterEntities.tiEntity_ID = FRWCubeCy.Company_ID) then next. /* there is a filter excluding this entity */
	 find company where company.company_ID = frwcubecy.company_id no-lock.
	 find companyproperty of company no-lock.
     if frwcubecy.frwcubecyfromLCCC = "SC" then do:
		find domains of company no-lock.
		find domainproperty of domains no-lock.
		if viCurrencyID <> domainproperty.StatutoryCurrency_ID and
			viCurrencyID <> 0 then assign vlSingleCurrency = no.
		assign viCurrencyID = domainproperty.StatutoryCurrency_ID.	
	 end.
	 else do:
		if viCurrencyID <> companyproperty.currency_ID and
			viCurrencyID <> 0 then assign vlSingleCurrency = no.
		assign viCurrencyID = companyproperty.currency_ID.
	 end.

/*
	 if viCurrencyID <> companyproperty.currency_ID and
		viCurrencyID <> 0 then assign vlSingleCurrency = no.
	 assign ViCurrencyID = companyproperty.currency_ID.*/
end.
/* ================================================================= */
/* Amount In View check                                              */
/* ================================================================= */
if icAmountinview = 'PRESENTCURR':U then assign viAmountInView = 1.
else assign viAmountInView = 2.

if vlSingleCurrency = no and icAmountinview = 'SRCCURR':U then do:
	assign viAmountInView = 1.
end.

if viAmountInView = 1 then do:
  assign vcViewCurrency = frwcube.FRWCubeCurrencyCode.
end.
else do:
  if viCurrencyID <> 0 then do:
	  find currency where currency.currency_ID = viCurrencyID no-lock.
	assign vcViewCurrency = currency.currencyCode.
  end.
else assign vcViewCurrency = "".
end.

/* ================================================================= */
/* Building the Report Tree balances.                                */
/* ================================================================= */
for each tCols:
  delete tCols.
end.

for each tColPer:
  delete tColPer.
end.

assign vifromyearlength = 0
   vitoyearlength = 0.
for each frwcubeperiod where frwcubeperiod.frwcubeperiodfrwcubecode = frwcube.frwcubecode and
			 frwcubeperiod.frwcubeperiodreportyear = vifromreportyear no-lock:
  if frwcubeperiod.FRWCubePeriodReportPerInt > vifromyearlength then assign vifromyearlength = frwcubeperiod.FRWCubePeriodReportPerInt.
end.
for each frwcubeperiod where frwcubeperiod.frwcubeperiodfrwcubecode = frwcube.frwcubecode and
			 frwcubeperiod.frwcubeperiodreportyear = vitoreportyear no-lock:
  if frwcubeperiod.FRWCubePeriodReportPerInt > vitoyearlength then assign vitoyearlength = frwcubeperiod.FRWCubePeriodReportPerInt.
end.

if vifromyearlength > 10 and
   vifromyearlength < 15 and
   vifromreportperiod <> 0 then do:
		assign vifromquarter = if vifromreportperiod < 4 then 1
						else if vifromreportperiod < 7 then 2
							else if  vifromreportperiod < 10 then 3
								else 4.
end.
else
	if vifromyearlength = 4 and
		vifromreportperiod <> 0 then do:
			assign vifromquarter = vifromreportperiod.
	end.
	else assign vifromquarter = 0.
	
if vitoyearlength > 10 and
   vitoyearlength < 15 and
	vitoreportperiod <> 0 then do:
		assign vitoquarter = if vitoreportperiod < 4 then 1
					else if vitoreportperiod < 7 then 2
						 else if vitoreportperiod < 10 then 3
							else 4.
end.
else
	if vitoyearlength = 4 and
		vitoreportperiod <> 0 then do:
			assign vitoquarter = vitoreportperiod.
	end.
	else assign vitoquarter = 0.

/* ================================================================= */
/* Create temp table tCols,tPerrange                                 */
/* ================================================================= */
<M-30 run CreateTempTableBeforeAddNode  (output viFcReturnSuper (oiReturnStatus)) in TFRWTreeView>

/* ================================================================= */
/* Create temp table tNode                                           */
/* ================================================================= */
<M-58 run GetFRWTreeLevel2NodeCreateNode
   (input  icTargetChart (icTargetChart), 
    input-output tNode (tNode), 
    output viFcReturnSuper (oiReturnStatus)) in TFRWTreeView>

/* ================================================================= */
/* Complete AnCode Data                                              */
/* ================================================================= */
for each tancode:
	delete tancode.
end.

for each tcube:
	delete tcube.
end.

for each tanalelemcubedim:
	delete tanalelemcubedim.
end.

/* The first parameter is passed as a input temp-table tqAnCode  to the procedure CompleteAnCodeElemDet */
/* This procedure can later be reused to update multiple Analysis Codes element details when we need to refresh a complete reporting Tree */
for each tnode where tnode.tcanalysiscodetype = 'a':
	create tancode.
	assign tancode.tcancode = tnode.tcancodecode.
end.

if icfilterancode <> "" then do:
    create tancode.
	assign tancode.tcancode = icfilterancode.
end.
.
/* Complete the data of AnCode */
<M-6 run GetFRWTreeLevel2NodeCompleteAncodeElemdet
   (input-output tAnCode (tAnCode), 
    input  icTargetChart (icTargetChart), 
    output viFcReturnSuper (oiReturnStatus)) in TFRWTreeView>
if viFcReturnSuper <> 0 then do:
    assign oiReturnStatus = viFcReturnSuper.
    return.
end.

for each tancode:
	delete tancode.
end.

assign viLeafCount = 0.
for each tnode where tnode.tcanalysiscodetype = 'a' and
	   tnode.tlisleaf = yes:
	create tancode.
	assign tancode.tcancode = tnode.tcancodecode
			tancode.tileafnodeid = tnode.tinodeid
			vicurrentparentid = tnode.tiparentnodeid
			vimaxloop =  tnode.titreelevel - 1
		    viteller = 0
			viLeafCount = viLeafCount + 1.
	   do while true:
		  assign viteller = viteller + 1.
		  if vicurrentparentid = 0 then do: /* we reached the top - root node */
		      if icfilterancode <> "" then
				  assign  tancode.tcancode = tancode.tcancode + "," + icfilterancode.
		      leave.
		  end.
		  if viteller > vimaxloop then do:
		     /*  {us/bbi/pxmsg.i &MSGNUM=12420 &ERRORLEVEL=1 &MSGARG1=string(timaxloop) &MSGBUFFER=tcErrorMessage}*/
            create tErrorTable.
            assign tErrorTable.tcErrorMessage = trim(#T-64'There's no root node in these node list.':255(887238445)T-64#)
                oiReturnStatus = -1.
			return.
		  end.
		  find bnode where bnode.tinodeid = vicurrentparentid no-error.
		  if not available bnode then do:
		     /*  {us/bbi/pxmsg.i &MSGNUM=12421 &ERRORLEVEL=1 &MSGARG1=string(ticurrentparentid) &MSGBUFFER=tcErrorMessage}*/
            create tErrorTable.
            assign tErrorTable.tcErrorMessage = trim(#T-88'Parent node of current node doesn't exist.':255(670494995)T-88#)
                oiReturnStatus = -1.
			return.
		  end.
		  assign vicurrentparentid = bnode.tiparentnodeid.
          if bnode.tcanalysiscodetype = 'a' then
              assign  tancode.tcancode = tancode.tcancode + "," + bnode.tcancodecode.
	   end. /* do while true */
    /* Save AnCode list of leaf node */
    assign tNode.tcHiddenAnCodeCode = tancode.tcancode.
end.

create tcube.
assign  tcube.tccubename = vccubenames.

/* Retrive Cube Dim */
<M-22 run GetFRWTreeLevel2NodeRetriveCubeDim
   (input  icTargetChart (icTargetChart), 
    output viFcReturnSuper (oiReturnStatus)) in TFRWTreeView>
if viFcReturnSuper <> 0 then do:
    assign oiReturnStatus = viFcReturnSuper.
    return.
end.

/* ================================================================= */
/* Caculate balance/activity                                         */
/* ================================================================= */
<M-40 run GetFRWTreeLevel2NodeCaculateBalanceAndActivity  (output viFcReturnSuper (oiReturnStatus)) in TFRWTreeView>
if viFcReturnSuper <> 0 then do:
    assign oiReturnStatus = viFcReturnSuper.
    return.
end.

/* ================================================================= */
/* Create dummy leaf node for level2 node                            */
/* ================================================================= */
<M-51 run GetFRWTreeLevel2NodeCreateDummyData  (output viFcReturnSuper (oiReturnStatus)) in TFRWTreeView>
if viFcReturnSuper <> 0 then do:
    assign oiReturnStatus = viFcReturnSuper.
    return.
end.