利用fnd_flex_keyval包轻松获取关键性弹性域组合描述字段
在Oracle Forms客户化开发中,如果遇到有在Form上提供关键性弹性域(以下简称“键弹性域”)功能支持的时候,我们可以利用FND_KEY_FLEX.DEFINE函数来轻松完成所有的初始化工作。其中也包括键弹性域的组合描述字段的显示的初始化:只要在FND_KEY_FLEX.DEFINE调用时指定了DESCRIPTION参数即可。然而有时我们仅是想要显示这个描述组合字段,仅此而已。并不需要提供完整的键弹性域功能。那么我们有什么快速而有效的方法来得到这个描述组合字段呢?试试下面的fnd_flex_keyval包里的方法吧~
实例:获取库存物料的物料类别集中的类别组合“描述”字段
需要用到的方法:
- fnd_flex_keyval.validate_segs()
- fnd_flex_keyval.concatenated_descriptions()
fnd_flex_keyval.validate_segs 的参数很多,对于获取物料类别组合字段我们仅需要其中的五个参数,如下:
- fnd_flex_keyval.validate_segs(
- operation => <OPERATIONS>
- , appl_short_name => <Application Short Name>
- , key_flex_code => <Key Flex Code>
- , structure_number => <ID_FLEX_NUM>
- , concat_segments => <CONCATENATED_SEGMENTS>
- );
fnd_flex_keyval.validate_segs( operation => <OPERATIONS> , appl_short_name => <Application Short Name> , key_flex_code => <Key Flex Code> , structure_number => <ID_FLEX_NUM> , concat_segments => <CONCATENATED_SEGMENTS> );
参数说明:
- operation 可选值有:
- FIND_COMBINATION - 所给定的组合字段必须在系统中已经被定义
- CREATE_COMBINATION - 如果组合字段不存在,则在系统中创建该组合
- CREATE_COMB_NO_AT - 功能和CREATE_COMBINATION相同,只是不像前者要使用相对独立的子事务autonomous transaction
- CHECK_COMBINATION - 只是检查一下给定的组合字段是否合法,不管检查结果如何,都不创建新的组合
- DEFAULT_COMBINATION - 返回默认的最小组合(这个参数值我也没太搞懂,呵呵)
- CHECK_SEGMENTS - 分别验证字段(这个也很糊涂~)
- appl_short_name 应用程序简称,例如库存模块对应的应用简称为INV
- key_flex_code 键弹性域代码,可以在键弹性域定义界面找到,例如MCAT, GL#等等
- structure_number 指定键弹性域下的某个结构NUM,可以在键弹性域定义界面找到,对应字段为ID_FLEX_NUM
- concat_segments 要获取组合描述字段的对应的“值“组合字段,例如: A.000.MISC
一旦初始化验证字段成功,那么描述组合字段便可以通过调用fnd_flex_keyval.concatenated_descriptions()来得到了。
完整代码如下:
- <PRE>FUNCTION get_concat_descriptions(p_concat_segs IN VARCHAR2) RETURN VARCHAR2
- IS
- BEGIN
- IF fnd_flex_keyval.validate_segs(
- operation => 'FIND_COMBINATION' -- 请根据情况自行修改
- , appl_short_name => 'INV' -- 请根据情况自行修改
- , key_flex_code => 'MCAT' -- 请根据情况自行修改
- , structure_number => 101 -- 请根据情况自行修改
- , concat_segments => p_concat_segs) THEN
- RETURN (fnd_flex_keyval.concatenated_descriptions());
- ELSE
- RETURN '';
- END IF;
- END;
- </PRE>
- <PRE></PRE>
- <PRE></PRE>
FUNCTION get_concat_descriptions(p_concat_segs IN VARCHAR2) RETURN VARCHAR2 IS BEGIN IF fnd_flex_keyval.validate_segs( operation => 'FIND_COMBINATION' -- 请根据情况自行修改 , appl_short_name => 'INV' -- 请根据情况自行修改 , key_flex_code => 'MCAT' -- 请根据情况自行修改 , structure_number => 101 -- 请根据情况自行修改 , concat_segments => p_concat_segs) THEN RETURN (fnd_flex_keyval.concatenated_descriptions()); ELSE RETURN ''; END IF; END;
获取货位的描述:
- --Get Stock Locators(MTLL) 库存货位的组合与描述
- --SELECT cux_flex_pkg.get_mtll_flexfields(p_locator_id => 3950, p_organization_id => 7890, p_return => 'S') locator_name FROM dual;
- FUNCTION get_mtll_flexfields(p_locator_id NUMBER,
- p_organization_id NUMBER,
- p_return VARCHAR2 DEFAULT 'S') RETURN VARCHAR2 IS
- l_concatenated_descriptions VARCHAR2(2000);
- l_success BOOLEAN;
- l_concatenated_segments VARCHAR2(2000);
- c_structure_number NUMBER;
- c_key_flex_code VARCHAR2(20);
- c_appl_short_name VARCHAR2(20);
- l_application_id NUMBER;
- -- Keeps track of the current delimiter
- l_delim VARCHAR2(1) := '';
- l_error_message VARCHAR2(1000);
- BEGIN
- --
- --Bug: Value &VALUE for the flexfield segment Subinventory does not exist in the value set @VALUE_SET.
- --如果在健弹性域定义的值集中使用了PROFILE,需要初始化赋值之后才行,否则会出现以上错误
- --SELECT FND_PROFILE.VALUE_WNPS('MFG_ORGANIZATION_ID') FROM DUAL;
- --fnd_global.apps_initialize(resp_appl_id => 401, resp_id => 65780, user_id => 1013436);
- IF FND_PROFILE.VALUE_WNPS('MFG_ORGANIZATION_ID') IS NULL THEN
- fnd_profile.put('MFG_ORGANIZATION_ID', p_organization_id);
- END IF;
- c_key_flex_code := 'MTLL';
- c_appl_short_name := 'INV';
- c_structure_number := 101;
- SELECT application_id
- INTO l_application_id
- FROM fnd_application_vl a
- WHERE a.application_short_name = c_appl_short_name;
- -- Get the delimiter
- l_delim := fnd_flex_apis.get_segment_delimiter(x_application_id => l_application_id, x_id_flex_code => c_key_flex_code, x_id_flex_num => c_structure_number);
- --参数DATA_SET一定要设置,和物料的键弹性域定义的原理一样:因为INVENTORY_LOCATION_ID在数据库的基表中不是唯一的值
- --SELECT set_defining_column_name,unique_id_column_name,application_table_name FROM fnd_id_flexs WHERE id_flex_code IN ('MTLL', 'MSTK');
- l_success := fnd_flex_keyval.validate_ccid(appl_short_name => c_appl_short_name,
- key_flex_code => c_key_flex_code,
- structure_number => c_structure_number,
- data_set => to_char(p_organization_id), -- Requied
- combination_id => p_locator_id);
- dbms_output.put_line('l_success = ' || to_char(sys.diutil.bool_to_int(l_success)));
- l_error_message := fnd_flex_keyval.error_message;
- IF l_success THEN
- l_concatenated_descriptions := fnd_flex_keyval.concatenated_descriptions;
- --dbms_output.put_line('Concatenated Descriptions : ' || l_concatenated_descriptions);
- l_concatenated_segments := fnd_flex_keyval.concatenated_values;
- --dbms_output.put_line('Concatenated Segments : ' || l_concatenated_segments);
- ELSE
- l_concatenated_segments := NULL;
- l_concatenated_descriptions := NULL;
- fnd_message.set_name('FND', 'FLEX-SSV EXCEPTION');
- fnd_message.set_token('MSG', l_error_message);
- dbms_output.put_line(fnd_message.get);
- RAISE app_exceptions.application_exception;
- END IF;
- IF p_return = 'S' THEN
- RETURN(l_concatenated_segments);
- ELSIF p_return = 'D' THEN
- RETURN(l_concatenated_descriptions);
- ELSE
- RETURN(l_concatenated_segments);
- END IF;
- EXCEPTION
- WHEN OTHERS THEN
- RETURN NULL;
- app_exception.raise_exception;
- END get_mtll_flexfields;
--Get Stock Locators(MTLL) 库存货位的组合与描述 --SELECT cux_flex_pkg.get_mtll_flexfields(p_locator_id => 3950, p_organization_id => 7890, p_return => 'S') locator_name FROM dual; FUNCTION get_mtll_flexfields(p_locator_id NUMBER, p_organization_id NUMBER, p_return VARCHAR2 DEFAULT 'S') RETURN VARCHAR2 IS l_concatenated_descriptions VARCHAR2(2000); l_success BOOLEAN; l_concatenated_segments VARCHAR2(2000); c_structure_number NUMBER; c_key_flex_code VARCHAR2(20); c_appl_short_name VARCHAR2(20); l_application_id NUMBER; -- Keeps track of the current delimiter l_delim VARCHAR2(1) := ''; l_error_message VARCHAR2(1000); BEGIN -- --Bug: Value &VALUE for the flexfield segment Subinventory does not exist in the value set @VALUE_SET. --如果在健弹性域定义的值集中使用了PROFILE,需要初始化赋值之后才行,否则会出现以上错误 --SELECT FND_PROFILE.VALUE_WNPS('MFG_ORGANIZATION_ID') FROM DUAL; --fnd_global.apps_initialize(resp_appl_id => 401, resp_id => 65780, user_id => 1013436); IF FND_PROFILE.VALUE_WNPS('MFG_ORGANIZATION_ID') IS NULL THEN fnd_profile.put('MFG_ORGANIZATION_ID', p_organization_id); END IF; c_key_flex_code := 'MTLL'; c_appl_short_name := 'INV'; c_structure_number := 101; SELECT application_id INTO l_application_id FROM fnd_application_vl a WHERE a.application_short_name = c_appl_short_name; -- Get the delimiter l_delim := fnd_flex_apis.get_segment_delimiter(x_application_id => l_application_id, x_id_flex_code => c_key_flex_code, x_id_flex_num => c_structure_number); --参数DATA_SET一定要设置,和物料的键弹性域定义的原理一样:因为INVENTORY_LOCATION_ID在数据库的基表中不是唯一的值 --SELECT set_defining_column_name,unique_id_column_name,application_table_name FROM fnd_id_flexs WHERE id_flex_code IN ('MTLL', 'MSTK'); l_success := fnd_flex_keyval.validate_ccid(appl_short_name => c_appl_short_name, key_flex_code => c_key_flex_code, structure_number => c_structure_number, data_set => to_char(p_organization_id), -- Requied combination_id => p_locator_id); dbms_output.put_line('l_success = ' || to_char(sys.diutil.bool_to_int(l_success))); l_error_message := fnd_flex_keyval.error_message; IF l_success THEN l_concatenated_descriptions := fnd_flex_keyval.concatenated_descriptions; --dbms_output.put_line('Concatenated Descriptions : ' || l_concatenated_descriptions); l_concatenated_segments := fnd_flex_keyval.concatenated_values; --dbms_output.put_line('Concatenated Segments : ' || l_concatenated_segments); ELSE l_concatenated_segments := NULL; l_concatenated_descriptions := NULL; fnd_message.set_name('FND', 'FLEX-SSV EXCEPTION'); fnd_message.set_token('MSG', l_error_message); dbms_output.put_line(fnd_message.get); RAISE app_exceptions.application_exception; END IF; IF p_return = 'S' THEN RETURN(l_concatenated_segments); ELSIF p_return = 'D' THEN RETURN(l_concatenated_descriptions); ELSE RETURN(l_concatenated_segments); END IF; EXCEPTION WHEN OTHERS THEN RETURN NULL; app_exception.raise_exception; END get_mtll_flexfields;
库存物料的组合与描述库存物料的组合与描述:
- FUNCTION get_mstk_flexfields(p_item_id NUMBER,
- p_organization_id NUMBER,
- p_return VARCHAR2 DEFAULT 'S') RETURN VARCHAR2 IS
- l_concatenated_descriptions VARCHAR2(2000);
- l_success BOOLEAN;
- l_concatenated_segments VARCHAR2(2000);
- c_structure_number NUMBER;
- c_key_flex_code VARCHAR2(20);
- c_appl_short_name VARCHAR2(20);
- l_application_id NUMBER;
- -- Keeps track of the current delimiter
- l_delim VARCHAR2(1) := '';
- l_error_message VARCHAR2(1000);
- BEGIN
- --
- --如果在健弹性域定义的值集中使用了PROFILE,需要初始化赋值之后才行,否则会出现以上错误
- --SELECT FND_PROFILE.VALUE_WNPS('MFG_ORGANIZATION_ID') FROM DUAL;
- --fnd_global.apps_initialize(resp_appl_id => 401, resp_id => 65780, user_id => 1013436);
- IF FND_PROFILE.VALUE_WNPS('MFG_ORGANIZATION_ID') IS NULL THEN
- fnd_profile.put('MFG_ORGANIZATION_ID', p_organization_id);
- END IF;
- c_key_flex_code := 'MSTK';
- c_appl_short_name := 'INV';
- c_structure_number := 101;
- SELECT application_id
- INTO l_application_id
- FROM fnd_application_vl a
- WHERE a.application_short_name = c_appl_short_name;
- -- Get the delimiter
- l_delim := fnd_flex_apis.get_segment_delimiter(x_application_id => l_application_id, x_id_flex_code => c_key_flex_code, x_id_flex_num => c_structure_number);
- --参数DATA_SET一定要设置,和物料的键弹性域定义的原理一样:因为INVENTORY_LOCATION_ID在数据库的基表中不是唯一的值
- --SELECT set_defining_column_name,unique_id_column_name,application_table_name FROM fnd_id_flexs WHERE id_flex_code IN ('MTLL', 'MSTK');
- l_success := fnd_flex_keyval.validate_ccid(appl_short_name => c_appl_short_name,
- key_flex_code => c_key_flex_code,
- structure_number => c_structure_number,
- data_set => to_char(p_organization_id), -- Requied
- combination_id => p_item_id);
- dbms_output.put_line('l_success = ' || to_char(sys.diutil.bool_to_int(l_success)));
- l_error_message := fnd_flex_keyval.error_message;
- IF l_success THEN
- l_concatenated_descriptions := fnd_flex_keyval.concatenated_descriptions;
- --dbms_output.put_line('Concatenated Descriptions : ' || l_concatenated_descriptions);
- l_concatenated_segments := fnd_flex_keyval.concatenated_values;
- --dbms_output.put_line('Concatenated Segments : ' || l_concatenated_segments);
- ELSE
- l_concatenated_segments := NULL;
- l_concatenated_descriptions := NULL;
- fnd_message.set_name('FND', 'FLEX-SSV EXCEPTION');
- fnd_message.set_token('MSG', l_error_message);
- dbms_output.put_line(fnd_message.get);
- RAISE app_exceptions.application_exception;
- END IF;
- IF p_return = 'S' THEN
- RETURN(l_concatenated_segments);
- ELSIF p_return = 'D' THEN
- RETURN(l_concatenated_descriptions);
- ELSE
- RETURN(l_concatenated_segments);
- END IF;
- EXCEPTION
- WHEN OTHERS THEN
- RETURN NULL;
- app_exception.raise_exception;
- END get_mstk_flexfields;
FUNCTION get_mstk_flexfields(p_item_id NUMBER, p_organization_id NUMBER, p_return VARCHAR2 DEFAULT 'S') RETURN VARCHAR2 IS l_concatenated_descriptions VARCHAR2(2000); l_success BOOLEAN; l_concatenated_segments VARCHAR2(2000); c_structure_number NUMBER; c_key_flex_code VARCHAR2(20); c_appl_short_name VARCHAR2(20); l_application_id NUMBER; -- Keeps track of the current delimiter l_delim VARCHAR2(1) := ''; l_error_message VARCHAR2(1000); BEGIN -- --如果在健弹性域定义的值集中使用了PROFILE,需要初始化赋值之后才行,否则会出现以上错误 --SELECT FND_PROFILE.VALUE_WNPS('MFG_ORGANIZATION_ID') FROM DUAL; --fnd_global.apps_initialize(resp_appl_id => 401, resp_id => 65780, user_id => 1013436); IF FND_PROFILE.VALUE_WNPS('MFG_ORGANIZATION_ID') IS NULL THEN fnd_profile.put('MFG_ORGANIZATION_ID', p_organization_id); END IF; c_key_flex_code := 'MSTK'; c_appl_short_name := 'INV'; c_structure_number := 101; SELECT application_id INTO l_application_id FROM fnd_application_vl a WHERE a.application_short_name = c_appl_short_name; -- Get the delimiter l_delim := fnd_flex_apis.get_segment_delimiter(x_application_id => l_application_id, x_id_flex_code => c_key_flex_code, x_id_flex_num => c_structure_number); --参数DATA_SET一定要设置,和物料的键弹性域定义的原理一样:因为INVENTORY_LOCATION_ID在数据库的基表中不是唯一的值 --SELECT set_defining_column_name,unique_id_column_name,application_table_name FROM fnd_id_flexs WHERE id_flex_code IN ('MTLL', 'MSTK'); l_success := fnd_flex_keyval.validate_ccid(appl_short_name => c_appl_short_name, key_flex_code => c_key_flex_code, structure_number => c_structure_number, data_set => to_char(p_organization_id), -- Requied combination_id => p_item_id); dbms_output.put_line('l_success = ' || to_char(sys.diutil.bool_to_int(l_success))); l_error_message := fnd_flex_keyval.error_message; IF l_success THEN l_concatenated_descriptions := fnd_flex_keyval.concatenated_descriptions; --dbms_output.put_line('Concatenated Descriptions : ' || l_concatenated_descriptions); l_concatenated_segments := fnd_flex_keyval.concatenated_values; --dbms_output.put_line('Concatenated Segments : ' || l_concatenated_segments); ELSE l_concatenated_segments := NULL; l_concatenated_descriptions := NULL; fnd_message.set_name('FND', 'FLEX-SSV EXCEPTION'); fnd_message.set_token('MSG', l_error_message); dbms_output.put_line(fnd_message.get); RAISE app_exceptions.application_exception; END IF; IF p_return = 'S' THEN RETURN(l_concatenated_segments); ELSIF p_return = 'D' THEN RETURN(l_concatenated_descriptions); ELSE RETURN(l_concatenated_segments); END IF; EXCEPTION WHEN OTHERS THEN RETURN NULL; app_exception.raise_exception; END get_mstk_flexfields;