Mon Aug 15, 2022 9:47 am
Login Register Lost Password? Contact Us

Please Note: The HPCC Systems forums are moving to Stack Overflow. We invite you to post your questions on Stack Overflow utilizing the tag hpcc-ecl ( This legacy forum will be active and monitored during our transition to Stack Overflow but will become read only beginning September 1, 2022.

How to receive a string parameter from stored() to a macro

Comments and questions related to the Enterprise Control Language

Wed Oct 06, 2021 2:40 pm Change Time Zone

I'm working on a query to calculate a frequency of a field inside a dataset. So first of all I coded a simple function that works for one hard coded field and then and made a function macro that should receive a string parameter containing the field name and calculate its frequency.

Code: Select all
  Layout := RECORD
    UNSIGNED1 PersonID;
    STRING15  FirstName;
    STRING25  LastName;

  students := DATASET(

  r := RECORD
    UNSIGNED Frequency := COUNT(GROUP);

  final_result := TABLE(students, r, Field);
  sort_result := SORT(final_result, Field);
  RETURN OUTPUT(sort_result);

For running it on thor works normally calling test('LastName'). But I'm trying to receive this string value from the user using a STORED() call as the following example:

Code: Select all
IMPORT ^.functions AS F;

  STRING Field := 'LastName' : STORED('Field'); // Receive LastName, FirstName or PersonID

  result := F.test(Field);

  RETURN result;

In this way, I stucked on this following error in the line with #EXPAND():
2071: Constant expression expected

In short, is there a way to receive this field as a string parameter and send it to a function macro (or any other way with template language, for example), performing and publishing this query based on the parameter field sent by the user?

While the development of this code I was thinking about the possibility of being able to perform a query only adding a new field inside the record structure, without the need to change the roxie query logic, in order to work dinamically based on the parameter/field sent by the user. Keep in mind that the real RECORD has more than 50 fields avaiable that I'd group and calculate its frequency.
Posts: 3
Joined: Thu Apr 18, 2019 2:17 pm

Fri Oct 08, 2021 7:30 pm Change Time Zone


Unfortunately, I have no good answer for you. The Template Language (which #EXPAND is part of) was originally designed to receive an XML string from an external app (like a website), generate ECL code from that XML input, run it, and return the results. That means it is expecting a string constant and you're trying to pass in a variable-value parameter.

I've been trying for years to figure out a good workaround to do all that within the HPCC Systems environment (you are not the first to ask). The best solution I've had so far has been to make it a two-step manual process: first step to generate the XML, then copy that and paste it into the code to run the actual job. Even if I use the "drilldown" mechanism in the ECL IDE, it's still a two-step manual process.

Contact me directly on Teams if you want to have a discussion about all the possible ways I've already tried (many) and your specific requirements for this task.


Community Advisory Board Member
Community Advisory Board Member
Posts: 1619
Joined: Wed Oct 26, 2011 7:40 pm

Return to ECL

Who is online

Users browsing this forum: Google [Bot] and 1 guest