The short version is that in my version SubsetElementExists only seems to work if you pass it the element's principal name, not an alias. (This is regardless of whether that alias is on the subset.) I've never noticed this before because most of the time I DO only work with the principal name when creating subsets, but today I was using an alias to add the elements. I checked whether the element was in the subset using the same value to make sure I wasn't adding it multiple times as the loops executed. Gee, imagine my surprise when it was added 38 times because it supposedly wasn't already in the subset. Finally I figured out what's going on.
Take the following example; a dimension of countries with principal names in English and an alias of NomeItaliano which shows the names in Italian. OK, now consider this code where I use the NomeItaliano attribute to punch the elements into a subset named ItalianSpeakingCountries. I then check the existence of the elements in the subset using the same aliases that I used to insert them:
Code: Select all
sLogFile = 'NOAlias.txt';
sDimName = 'Countries';
sSubName = 'ItalianSpeakingCountries';
If (SubsetExists(sDimName, sSubName) <> 0);
SubsetDestroy(sDimName, sSubName);
Endif;
SubsetCreate(sDimName, sSubName, 0);
sAlias = '';
# sAlias = 'NomeItaliano';
# In this one, I do NOT assign an alias to the subset.
# SubsetAliasSet(sDimName, sSubName, 'NomeItaliano');
SubsetElementInsert( sDimName, sSubName, 'Italia', 1);
SubsetElementInsert( sDimName, sSubName, 'Svizzera', 2);
SubsetElementInsert( sDimName, sSubName, 'San Marino', 3);
AsciiOutput(sLogFile, Expand('The subset %sSubName% has been created in the dimension %sDimName%, with an alias of "%sAlias%".'));
iElement = 1; iElementMax = 4;
While( iElement <= iElementMax);
If ( iElement = 1 );
sElement = 'Italia';
ElseIf ( iElement = 2 );
sElement = 'Italy';
ElseIf ( iElement = 3 );
sElement = 'Svizzera';
ElseIf ( iElement = 4 );
sElement = 'Switzerland';
EndIf;
iCheck = SubsetElementExists( sDimName, sSubName, sElement);
If( iCheck = 0);
sMsg = Expand('The element %sElement% is NOT in the subset %sSubName%.');
Else;
sMsg = Expand('The element %sElement% IS in the subset %sSubName%.');
EndIf;
AsciiOutput(sLogFile, sMsg );
iElement = iElement + 1;
End;
Code: Select all
"The subset ItalianSpeakingCountries has been created in the dimension Countries, with an alias of ""."
"The element Italia is NOT in the subset ItalianSpeakingCountries."
"The element Italy IS in the subset ItalianSpeakingCountries."
"The element Svizzera is NOT in the subset ItalianSpeakingCountries."
"The element Switzerland IS in the subset ItalianSpeakingCountries."
If I change the code slightly to add the alias to the subset, then:
Code: Select all
sLogFile = 'HASAlias.txt';
sDimName = 'Countries';
sSubName = 'ItalianSpeakingCountries';
If (SubsetExists(sDimName, sSubName) <> 0);
SubsetDestroy(sDimName, sSubName);
Endif;
SubsetCreate(sDimName, sSubName, 0);
#sAlias = '';
sAlias = 'NomeItaliano';
# In this one, I DO assign an alias to the subset.
SubsetAliasSet(sDimName, sSubName, sAlias);
SubsetElementInsert( sDimName, sSubName, 'Italia', 1);
SubsetElementInsert( sDimName, sSubName, 'Svizzera', 2);
SubsetElementInsert( sDimName, sSubName, 'San Marino', 3);
AsciiOutput(sLogFile, Expand('The subset %sSubName% has been created in the dimension %sDimName%, with an alias of "%sAlias%".'));
iElement = 1; iElementMax = 4;
While( iElement <= iElementMax);
If ( iElement = 1 );
sElement = 'Italia';
ElseIf ( iElement = 2 );
sElement = 'Italy';
ElseIf ( iElement = 3 );
sElement = 'Svizzera';
ElseIf ( iElement = 4 );
sElement = 'Switzerland';
EndIf;
iCheck = SubsetElementExists( sDimName, sSubName, sElement);
If( iCheck = 0);
sMsg = Expand('The element %sElement% is NOT in the subset %sSubName%.');
Else;
sMsg = Expand('The element %sElement% IS in the subset %sSubName%.');
EndIf;
AsciiOutput(sLogFile, sMsg );
iElement = iElement + 1;
End;
Code: Select all
"The subset ItalianSpeakingCountries has been created in the dimension Countries, with an alias of "NomeItaliano"."
"The element Italia is NOT in the subset ItalianSpeakingCountries."
"The element Italy IS in the subset ItalianSpeakingCountries."
"The element Svizzera is NOT in the subset ItalianSpeakingCountries."
"The element Switzerland IS in the subset ItalianSpeakingCountries."
Needless to say, the official IBM Reference Page for SubsetElementExists makes absolutely no bloody reference to this, although they will probably claim that "it's because, um, ah, we designed it that way and it's not our stwategy to change it."
Anyway, hopefully this will save someone else the amount of time that I wasted today on this.
I turn it over to you to decide whether I should throw it in as a bug ticket.