首页 > 代码库 > PLSQL_R12 MOAC多组织的四个应用(案例)

PLSQL_R12 MOAC多组织的四个应用(案例)

2014-05-31 BaoXinjian In Capgemini

一、摘要

R12 Form 或者其他二次开发时,很多情况下会涉及R12 MOAC多组织开发,以下介绍了4个常见的应用,还请学友继续补充

1. 开发时打开Form自动弹出组织选择实现方式(增加Choose ORG功能)

2. 开发时打开Form中有组织LOV选择实现方式

3. R12多组织的技术实现方式-VPD技术

4. VPD技术详解,数据库安全策略 

 

二、案例

案例1、开发时打开Form自动弹出组织选择实现方式(增加Choose ORG功能)

    (1). 新增4个Paramters: Chart_Of_Account_Id, Org_Name, Org_Code, Org_id四个参数;

    (2). 在Form Level中Pre-Form中新增fnd_org.choose_org;

    (3). 在Form Level中When-New-Form-Instance中新增app_window.set_title(‘bxj_windows‘, :parameter.org_code);

 

案例2、开发时打开Form中有组织LOV选择实现方式

    (1). Pre-Form触发器初始化MOAC配置环境

        MO_GLOBAL.init(‘ONT’);

        IF l_default_org_id IS NOT NULL THEN — default org id not null
             MO_GLOBAL.SET_POLICY_CONTEXT(‘S’,l_default_org_id);
         ELSE
             MO_GLOBAL.SET_POLICY_CONTEXT(‘M’,null);
         END IF;

    (2). When-Create-Record触发器中复制OU默认值

        在此触发器中将默认的OU ID和OU Name拷贝给Form界面上对应的自动,实现创建记录的时候默认带出默认OU信息。
        copy(name_in(‘global.mo_default_org_id’),’’);
        copy(name_in(‘global.mo_default_ou_name’),’’);

    (3). 创建OU的LOV

        Form界面上的OU 名称字段创建一个LOV,LOV对应记录组的SQL语句如下:
            SELECT hr.organization_id organization_id, hr.NAME organization_name
               FROM hr_operating_units hr
             WHERE mo_global.check_access(hr.organization_id) = ‘Y’
          ORDER BY organization_name

 

案例3、R12多组织的技术实现方式-VPD技术

    (1). 三个Profile<MO: Security Profile、MO: Default Operating Unit、MO: Operating Unit>

    (2). ap_invoices 定义在ap_invoices_all基础之上

        a. 对于VPD<ap_invoices>表,简单的查询一般是不返回记录的,如果想查到记录,需要设置一下上下文先

        b. 普通查询VPD表

            select * from ap_invoices; -->No Output

        c. Single OU Mode

            BEGIN  execute mo_global.set_policy_context(‘S‘,204);

            --204为ORG_ID,S表示Single Org ContextEND;select * from PO_HEADERS;--会输出OU:204下边的所有PO

            --Multiple OU Mode(simulate login to a specific responsibility)

           Call fnd_global.apps_initialize(userid,resp_id,resp_appl_id);

        d. call MO_GLOBAL.INIT(p_appl_short_name);This will read the MO profile option values for your responsibility/user,

            and will initialize the Multi Org Access.

        e.select * from po_headers; -->Output
     (3). MO_GLOBAL.ORG_SECURITY的作用实际上就是根据你关于MOAC Profiles的设置,然后转换为相应Where条件(组织过滤),再进行查询

            

 

案例4、 VPD技术详解,数据库安全策略 

(1). 创建Table Or View的数据<bxj_invoices_policy_v>

    CREATE OR REPLACE VIEW apps.bxj_invoices_policy_v AS

        SELECT a.invoice_id,

                       b.vendor_name,

                       c.vendor_site_code,

                       a.invoice_num,

                       a.invoice_amount,

                       a.invoice_currency_code

            FROM ap_invoices_all a, ap_suppliers b, ap_supplier_sites_all c

          WHERE a.vendor_id = b.vendor_id AND a.vendor_site_id = c.vendor_site_id

               AND ROWNUM< = 10

(2). 创建Policy Function

    CREATE OR REPLACE FUNCTION bxj_fun_invoices_policy (s_schema IN VARCHAR2,

                                                                                                    s_object IN VARCHAR2)

        RETURN VARCHAR2

    AS

    BEGIN

        RETURN ‘invoice_currency_code = ‘ || ‘‘‘EUR‘‘‘;

    END;

(3). 注册VPD Policy

    BEGIN

        DBMS_RLS.add_policy (object_schema => ‘APPS‘,

                                                object_name => ‘BXJ_INVOICES_POLICY_V‘,

                                                policy_name => ‘POLICY_LIMITED_QUERY_INVOICES‘,

                                                function_schema => ‘APPS‘,

                                                policy_function => ‘BXJ_FUN_INVOICES_POLICY‘);

    END;

(4). 比较注册Policy前后,View的输出结果,由10条变为了7条,直接过滤了USD的记录

    a. 注册前

         

    a. 注册后