Fri Feb 22, 2019 4:21 am
Login Register Lost Password? Contact Us


#EXPAND IN FunctionMacro gives Error

Comments and questions related to the Enterprise Control Language

Wed Sep 26, 2012 12:03 pm Change Time Zone

Hi
We are trying to read a string Value from XML but when we Provide that String Value to the FunctionMacro it gives the below given Error:

Error: Constant expression expected (4, 42), 2071, C:\Users\Public\Documents\HPCC Systems\ECL\AccuRUSI_try\AglonConf_Macro2.ecl

My XML Looks like:
Code: Select all
<configuration>
   <add Key='RiskAge,RiskSICCode,RiskValue'/>
         
</configuration>


My Macro Code is:
Code: Select all
EXPORT AglonConf_Macro2(datasetToTable,TableFormat) :=FUNCTIONMACRO


RequiredDS:=TABLE(datasetToTable,{#EXPAND(TableFormat)});


RETURN RequiredDS;
ENDMACRO;



and the code where i'm calling this macro contains:
Code: Select all
PolicyData := DATASET($.common.constants.AccuRUSI_PolicyData_OUTPUT,$.common.Layout_policyDataRec,THOR);

ConfigData := DATASET('~file::172.20.15.168::home::hpcc::lz_data::apurv::config.xml',
                                 {STRING Read_XMLasSTRING {XPATH('<>')}},XML('configuration/add'));// Here {XPATH('<>')} reads the whole XML in a single STRING i.e. in Read_XMLasSTRING

outrec :=record
String Key := xmltext('@Key');
end;

parsedXML := parse(ConfigData,Read_XMLasSTRING,outrec,XML('add'));

str:=(STRING)parsedXML[1].Key;

$.AglonConf_Macro2(PolicyData,str);



Please can you help us with this issue.We need to develop something on Urgent Basis.
Apurv.Khare
 
Posts: 30
Joined: Fri Jan 06, 2012 1:30 pm

Wed Sep 26, 2012 12:16 pm Change Time Zone

I think #EXPAND requires the use of LOADXML. From the docs:

LOADXML opens an active XML scope for Template language statements or symbols to act on. LOADXML must be the first line of code to function correctly.

A valid XML scope is required for most Template Language statements to work. This is also used in "drilldown" MACRO code.


Regards,

Bob
bforeman
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 978
Joined: Wed Jun 29, 2011 7:13 pm

Wed Sep 26, 2012 6:24 pm Change Time Zone

Apurv,

The "Constant expression expected" error is indicating that TABLE requires a constant expression as its RECORD structure and you're trying to build it "on the fly" and the compiler won't let you. IOW, it's telling you that you can't do what you want to do in the way you're trying to do it.

So, what are you trying to accomplish here?

Richard
rtaylor
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 1409
Joined: Wed Oct 26, 2011 7:40 pm

Thu Sep 27, 2012 9:53 am Change Time Zone

Hi Richard,

If I use Any hard Coded String in Macro, it works fine and gives me a Desired Output
Code: Select all
PolicyData := DATASET($.common.constants.AccuRUSI_PolicyData_OUTPUT,$.common.Layout_policyDataRec,THOR);

fieldStr:='RiskAge,RiskSICCode,RiskValue';
$.AglonConf_Macro2(PolicyData,fieldStr);


But if use the Same string to be read from an XML file and then pass the Value to the Macro,it gives me the

Error: Constant expression expected (4, 42), 2071, C:\Users\Public\Documents\HPCC Systems\ECL\AccuRUSI_try\AglonConf_Macro2.ecl

I have already pasted the XML and The Macro Code in the above post thread.
Apurv.Khare
 
Posts: 30
Joined: Fri Jan 06, 2012 1:30 pm

Thu Sep 27, 2012 6:20 pm Change Time Zone

Apurv,
If I use Any hard Coded String in Macro, it works fine and gives me a Desired Output...

But if use the Same string to be read from an XML file and then pass the Value to the Macro,it gives me the

Error: Constant expression expected...
Yes, that's exactly what I was saying -- you cannot do it this way.

So, again, what exactly are you trying to accomplish? Why are you writing this FUNCTIONMACRO to define a simple TABLE function? Perhaps there is another approach that will work better to get you where you want to go.

Richard
rtaylor
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 1409
Joined: Wed Oct 26, 2011 7:40 pm


Return to ECL

Who is online

Users browsing this forum: No registered users and 1 guest