Passing DICTIONARY Parameters

Passing a DICTIONARY as a parameter may be accomplished using the following syntax:

DefinitionName( DICTIONARY( structure ) AliasName ) := expression;

The required structure parameter is the RECORD structure that defines the layout of fields in the passed DICTIONARY parameter (usually defined inline). The required AliasName names the DICTIONARY for use in the function and is used in the Definition's expression to indicate where in the operation the passed parameter is to be used. See the DICTIONARY as a Value Type discussion in the DICTIONARY documentation.

rec := RECORD
  STRING10  color;
  UNSIGNED1 code; 
  STRING10  name;
END;
Ds := DATASET([{'Black' ,0 , 'Fred'},
               {'Brown' ,1 , 'Seth'},
               {'Red'   ,2 , 'Sue'},
               {'White' ,3 , 'Jo'}], rec);

DsDCT := DICTIONARY(DS,{color => DS});

DCTrec := RECORD 
  STRING10 color => 
  UNSIGNED1 code,
  STRING10 name,
END;
InlineDCT := DICTIONARY([{'Black' => 0 , 'Fred'},
                         {'Brown' => 1 , 'Sam'},
                         {'Red'   => 2 , 'Sue'},
                         {'White' => 3 , 'Jo'} ], 
                        DCTrec);

MyDCTfunc(DICTIONARY(DCTrec) DCT,STRING10 key) := DCT[key].name;

MyDCTfunc(InlineDCT,'White');  //Jo
MyDCTfunc(DsDCT,'Brown');      //Seth