跳到主要内容 跳到补充内容

ApplyMap - 脚本函数

ApplyMap 脚本函数用于将表达式输出映射至先前加载的映射表。

语法:  

ApplyMap('map_name', expression [ , default_mapping ] )

返回数据类型:

参数:  

参数
参数 说明
map_name

以前通过 mapping loadmapping select 语句创建的映射表的名称。该名称必须用单直引号引起来。

警告注释如果您在宏扩展的变量中使用该函数并引用不存在的映射表格,函数调用会失败并且不会创建字段。
expression 表达式,即将被映射的结果。
default_mapping

如果已指定,即如果映射表不包含与 expression 相匹配的值,则可将此值用作默认值。如果未指定,则 expression 的值将原样返回。

警告注释ApplyMap 的输出字段不应有和其输入字段中的一个相同的名称。这可能导致意外结果。不使用的示例:ApplyMap('Map', A) as A

示例:  

在此例中,我们加载了销售人员和国家代码(表示销售人员所居住的国家)的列表。我们使用表格将国家代码映射到国家,以便将国家代码替换为国家名称。在映射表中仅定义了三个国家,其他国家代码已映射到'Rest of the world'

// Load mapping table of country codes: map1: mapping LOAD * Inline [ CCode, Country Sw, Sweden Dk, Denmark No, Norway ] ; // Load list of salesmen, mapping country code to country // If the country code is not in the mapping table, put Rest of the world Salespersons: LOAD *, ApplyMap('map1', CCode,'Rest of the world') As Country Inline [ CCode, Salesperson Sw, John Sw, Mary Sw, Per Dk, Preben Dk, Olle No, Ole Sf, Risttu ] ; // We don't need the CCode anymore Drop Field 'CCode';

最终生成的表格(销售人员)如下所示:

Resulting table
Salesperson Country
John Sweden
Mary Sweden
Per Sweden
Preben Denmark
Olle Denmark
Ole Norway
Risttu Rest of the world

了解详情

 

本页面有帮助吗?

如果您发现此页面或其内容有任何问题 – 打字错误、遗漏步骤或技术错误 – 请告诉我们如何改进!