Reputation: 222
I have a functionmacro and want to specify the name of a field in the dataset that is returned. I thought I could use #EXPAND and supply a string but when I do that I get an error saying it's an 'unknown identifier'. Here's the start of my functionmacro:
CreateDelta(CurrentDataset, PreviousDataset, ComparisonFields = '', DeltaField = 'delta_value') := FUNCTIONMACRO
InputLayout := RECORDOF(CurrentDataset);
OutputLayout := RECORD
// STRING1 delta_value;
STRING1 #EXPAND(DeltaField);
InputLayout;
END;
I would have expected the #EXPAND to make the effective ECL like the commented-out line but that doesn't happen, why not and what's the right way to do this?
Upvotes: 0
Views: 20
Reputation: 254
I think you are looking for #TEXT instead of #EXPAND. As in #TEXT(DeltaField).
Here is an example where I am using it:
FM_Field_Population(infile,infield,compareval) := FUNCTIONMACRO
c1 := COUNT(infile(infield=compareval));
c2 := COUNT(infile);
RETURN DATASET([{'Total Records',c2},
{'Recs=' + #TEXT(compareval),c1},
{'Population Pct',(INTEGER)((c1/c2)* 100.0)}],
{STRING15 valuetype,INTEGER val});
ENDMACRO;
GenRec := RECORD
STRING1 Gender;
END;
ds1 := DATASET([{'M'},{'M'},{'M'},{''},{''},{'M'},{''},{'M'},{'M'},{''}],GenRec);
ds2 := DATASET([{''},{'M'},{'M'},{'F'},{'F'},{'M'},{''},{''},{'M'},{''}],GenRec);
OUTPUT(FM_Field_Population(ds1,Gender,'M'));
OUTPUT(FM_Field_Population(ds2,Gender,'F'));
Upvotes: 0