Oracle Apps tables ending with _ALL holds transaction data for multiple org ( Operating Units).

In 11i we had views on these tables. It requires setting context in order to fetch data from these views. This  is for security concerns as these objects holds transaction details.

The SQL command to set the ORG_ID prior to running a script is:

SQL> EXECUTE DBMS_APPLICATION_INFO.SET_CLIENT_INFO(&ORG_ID);

Enter the org_id when prompted.

If using Toad:

BEGIN
     FND_CLIENT_INFO.SET_ORG_CONTEXT (&ORG_ID);
END;   

In R12 oracle uses VPD (Virtual Private Database) to secure these transactional data .This is one of major difference in application architecture between 11i and R12.

In order to retrieve data from transactional objects, set policy context first ( as below ) –

BEGIN
     MO_GLOBAL.SET_POLICY_CONTEXT(‘MODE’ CHAR(1),ORG_ID NUMBER);
END;

    MODE – This is  either “S” – For Single Operating Unit OR “M” – For Multiple Operating Unit

    Org_ID – Operating unit (Value from column ORG_ID in all transactional objects)
                         This is mandatory for “S” mode.
Example :-

BEGIN
    MO_GLOBAL.SET_POLICY_CONTEXT(‘S’, 123);
END;

This article presents a mixed bag of Oracle functionality relating to the identification of host names and IP addresses for Oracle clients and servers.

UTL_INADDR
SYS_CONTEXT
V$INSTANCE
V$SESSION

    UTL_INADDR

    The UTL_INADDR provide a means of retrieving host names and IP addresses of remote hosts from PL/SQL.
    The GET_HOST_ADDRESS function returns the IP address of the specified host name.
    SQL> SELECT UTL_INADDR.get_host_address('TEST') FROM dual;

    UTL_INADDR.GET_HOST_ADDRESS('TEST')
    --------------------------------------------------------------------------------
    192.167.1.56

    SQL>

     The IP address of the database server is returned if the specified host name is NULL or is omitted.

    SQL> SELECT UTL_INADDR.get_host_address from dual;

    GET_HOST_ADDRESS
    --------------------------------------------------------------------------------
    192.161.1.55

    SYS_CONTEXT

    The SYS_CONTEXT function is able to return the following host and IP address information for the current session:
    • TERMINAL – An operating system identifier for the current session. This is often the client machine name.
    • HOST – The host name of the client machine.
    • IP_ADDRESS – The IP address of the client machine.
    • SERVER_HOST – The host name of the server running the database instance.
    SQL> SELECT SYS_CONTEXT('USERENV','TERMINAL') FROM dual;

    SYS_CONTEXT('USERENV','TERMINAL')
    --------------------------------------------------------------------
    TEST10

    SQL> SELECT SYS_CONTEXT('USERENV','IP_ADDRESS') FROM dual;

    SYS_CONTEXT('USERENV','IP_ADDRESS')
    --------------------------------------------------------------------
    192.167.1.55

    SQL> SELECT SYS_CONTEXT('USERENV','SERVER_HOST') FROM dual;

    SYS_CONTEXT('USERENV','SERVER_HOST')
    --------------------------------------------------------------------
    Z4210gr11

    V$INSTANCE

    The HOST_NAME column of the V$INSTANCE view contains the host name of the server running the instance.
    SQL> SELECT host_name FROM v$instance;

    HOST_NAME
    ------------------------------------------------
    Z4210gR11

    V$SESSION

    The V$SESSION view contains the following host information for all database sessions:

    TERMINAL – The operating system terminal name for the client. This is often set to the client machine name.

    MACHINE – The operating system name for the client machine. This may include the domain name if present.

    The following examples show the typical output for each column.

    SQL> SELECT terminal, machine FROM v$session WHERE username = 'OEAG';

    TERMINAL MACHINE
    ------------------------------ ----------------------------------------------------
    TEST10 ORACLE-BASETEST10

    In R12, We Can’t just directly get the Code Combination ( i.e Accounting Flex Field) Description from a single table. But Oracle has provided a package, which will help to get the description easily.

    Script:
    SELECT GCC.CODE_COMBINATION_ID,
           GCC.SEGMENT1,
           GCC.SEGMENT2,
           GCC.SEGMENT3,
           GCC.SEGMENT4,
           GCC.SEGMENT5,
           GCC.SEGMENT6,
           GCC.SEGMENT7,
           GCC.SEGMENT8,
           SUBSTR (
              APPS.GL_FLEXFIELDS_PKG.GET_DESCRIPTION_SQL (
                 GCC.CHART_OF_ACCOUNTS_ID,
                 1,
                 GCC.SEGMENT1),
              1,
              40)
              SEGMENT1_DESC,
           SUBSTR (
              APPS.GL_FLEXFIELDS_PKG.GET_DESCRIPTION_SQL (
                 GCC.CHART_OF_ACCOUNTS_ID,
                 2,
                 GCC.SEGMENT2),
              1,
              40)
              SEGMENT2_DESC,
           DECODE (
              GCC.SEGMENT3,
              NULL, ”,
              SUBSTR (
                 APPS.GL_FLEXFIELDS_PKG.GET_DESCRIPTION_SQL (
                    GCC.CHART_OF_ACCOUNTS_ID,
                    3,
                    GCC.SEGMENT3),
                 1,
                 40))
              SEGMENT3_DESC,
           DECODE (
              GCC.SEGMENT4,
              NULL, ”,
              SUBSTR (
                 APPS.GL_FLEXFIELDS_PKG.GET_DESCRIPTION_SQL (
                    GCC.CHART_OF_ACCOUNTS_ID,
                    4,
                    GCC.SEGMENT4),
                 1,
                 40))
              SEGMENT4_DESC,
           DECODE (
              GCC.SEGMENT5,
              NULL, ”,
              SUBSTR (
                 APPS.GL_FLEXFIELDS_PKG.GET_DESCRIPTION_SQL (
                    GCC.CHART_OF_ACCOUNTS_ID,
                    5,
                    GCC.SEGMENT5),
                 1,
                 40))
              SEGMENT5_DESC,
           DECODE (
              GCC.SEGMENT6,
              NULL, ”,
              SUBSTR (
                 APPS.GL_FLEXFIELDS_PKG.GET_DESCRIPTION_SQL (
                    GCC.CHART_OF_ACCOUNTS_ID,
                    6,
                    GCC.SEGMENT6),
                 1,
                 40))
              SEGMENT6_DESC,
           DECODE (
              GCC.SEGMENT7,
              NULL, ”,
              SUBSTR (
                 APPS.GL_FLEXFIELDS_PKG.GET_DESCRIPTION_SQL (
                    GCC.CHART_OF_ACCOUNTS_ID,
                    7,
                    GCC.SEGMENT7),
                 1,
                 40))
              SEGMENT7_DESC,
           DECODE (
              GCC.SEGMENT9,
              NULL, ”,
              SUBSTR (
                 APPS.GL_FLEXFIELDS_PKG.GET_DESCRIPTION_SQL (
                    GCC.CHART_OF_ACCOUNTS_ID,
                    8,
                    GCC.SEGMENT8),
                 1,
                 40))
              SEGMENT8_DESC,
           GCC.CHART_OF_ACCOUNTS_ID CHART_OF_ACCOUNTS_ID,
           GCC.ACCOUNT_TYPE
      FROM GL_CODE_COMBINATIONS GCC
      WHERE CODE_COMIBINATION_ID = :P_ID

    Where: P_ID, you can pass Code Combination Id to get description for particular Accounting Combination.

    –Information can be retrieved from the table:
    XLE_LE_OU_LEDGER_V

    –Query for Ledger, Operating Unit, Legal Entity, balancing segment:
    select HRL.COUNTRY,
      HROUTL_BG.name BG,
      HROUTL_BG.ORGANIZATION_ID,
      LEP.LEGAL_ENTITY_ID,
      LEP.name LEGAL_ENTITY,
      HROUTL_OU.name OU_NAME,
      HROUTL_OU.ORGANIZATION_ID ORG_ID,
      HRL.LOCATION_ID,
      HRL.LOCATION_CODE,
      GLEV.FLEX_SEGMENT_VALUE
    from XLE_ENTITY_PROFILES LEP,
      XLE_REGISTRATIONS REG,
      HR_LOCATIONS_ALL HRL,
      HZ_PARTIES HZP,
      FND_TERRITORIES_VL TER,
      HR_OPERATING_UNITS HRO,
      HR_ALL_ORGANIZATION_UNITS_TL HROUTL_BG,
      HR_ALL_ORGANIZATION_UNITS_TL HROUTL_OU,
      HR_ORGANIZATION_UNITS GLOPERATINGUNITSEO,
      GL_LEGAL_ENTITIES_BSVS GLEV
    where LEP.TRANSACTING_ENTITY_FLAG      = ‘Y’
    and LEP.PARTY_ID                       = HZP.PARTY_ID
    and LEP.LEGAL_ENTITY_ID                = REG.SOURCE_ID
    and REG.SOURCE_TABLE                   = ‘XLE_ENTITY_PROFILES’
    and HRL.LOCATION_ID                    = REG.LOCATION_ID
    and REG.IDENTIFYING_FLAG               = ‘Y’
    and TER.TERRITORY_CODE                 = HRL.COUNTRY
    and LEP.LEGAL_ENTITY_ID                = HRO.DEFAULT_LEGAL_CONTEXT_ID
    and GLOPERATINGUNITSEO.ORGANIZATION_ID = HRO.ORGANIZATION_ID
    and HROUTL_BG.ORGANIZATION_ID          = HRO.BUSINESS_GROUP_ID
    and HROUTL_OU.ORGANIZATION_ID          = HRO.ORGANIZATION_ID
    and GLEV.LEGAL_ENTITY_ID               = LEP.LEGAL_ENTITY_ID;

    There are few APIs in INV_ITEM_CATEGORY_PUB package related to item category. This article will follow a category flexfield structure. Please refer the below post for more detail.
    1. INV_ITEM_CATEGORY_PUB.Create_Category:
    DECLARE
    l_category_rec    INV_ITEM_CATEGORY_PUB.CATEGORY_REC_TYPE;
    l_return_status   VARCHAR2(80);
    l_error_code      NUMBER;
    l_msg_count       NUMBER;
    l_msg_data        VARCHAR2(80);
    l_out_category_id NUMBER;
    BEGIN
      l_category_rec.segment1 := 'RED';
    
      SELECT f.ID_FLEX_NUM
        INTO l_category_rec.structure_id
        FROM FND_ID_FLEX_STRUCTURES f
       WHERE f.ID_FLEX_STRUCTURE_CODE = 'INV_COLORS';
    
      l_category_rec.description := 'Red';
    
      INV_ITEM_CATEGORY_PUB.Create_Category
              (
              p_api_version   => 1.0,
              p_init_msg_list => FND_API.G_FALSE,
              p_commit        => FND_API.G_TRUE,
              x_return_status => l_return_status,
              x_errorcode     => l_error_code,
              x_msg_count     => l_msg_count,
              x_msg_data      => l_msg_data,
              p_category_rec  => l_category_rec,
              x_category_id   => l_out_category_id
              );
      IF l_return_status = fnd_api.g_ret_sts_success THEN
        COMMIT;
        DBMS_OUTPUT.put_line ('Creation of Item Category is Successful : '||l_out_category_id);
      ELSE
        DBMS_OUTPUT.put_line ('Creation of Item Category Failed with the error :'||l_error_code);
        ROLLBACK;
      END IF;
    END ;
    
    
    2. INV_ITEM_CATEGORY_PUB. Delete_Category:
    
    
    DECLARE
    l_return_status VARCHAR2(80);
    l_error_code    NUMBER;
    l_msg_count     NUMBER;
    l_msg_data      VARCHAR2(80);
    l_category_id   NUMBER;
    BEGIN
      SELECT mcb.CATEGORY_ID
        INTO l_category_id
        FROM mtl_categories_b mcb
       WHERE mcb.SEGMENT1='RED'
         AND mcb.STRUCTURE_ID =
            (SELECT mcs_b.STRUCTURE_ID
               FROM mtl_category_sets_b mcs_b
              WHERE mcs_b.CATEGORY_SET_ID =
                   (SELECT mcs_tl.CATEGORY_SET_ID
                      FROM mtl_category_sets_tl mcs_tl
                     WHERE CATEGORY_SET_NAME ='INV_COLORS_SET'
                     )
            );
    
        INV_ITEM_CATEGORY_PUB.Delete_Category
              (
              p_api_version     => 1.0,
              p_init_msg_list   => FND_API.G_FALSE,
              p_commit          => FND_API.G_TRUE,
              x_return_status   => l_return_status,
              x_errorcode       => l_error_code,
              x_msg_count       => l_msg_count,
              x_msg_data        => l_msg_data,
              p_category_id     => l_category_id);
    
      IF l_return_status = fnd_api.g_ret_sts_success THEN
        COMMIT;
        DBMS_OUTPUT.put_line ('Deletion of Item Category is Successful : '||l_category_id);
      ELSE
        DBMS_OUTPUT.put_line ('Deletion of Item Category Failed with the error :'||l_error_code);
        ROLLBACK;
      END IF;
    END ;
    
    
    3. INV_ITEM_CATEGORY_PUB.Update_Category_Description
    Updates the category description.
    DECLARE
             l_return_status VARCHAR2(80);
             l_error_code    NUMBER;
             l_msg_count     NUMBER;
             l_msg_data      VARCHAR2(80);
             l_category_id   NUMBER;
             l_description   VARCHAR2(80);
    BEGIN
          select mcb.CATEGORY_ID into l_category_id
            from mtl_categories_b mcb
           where mcb.SEGMENT1='BLACK'
             and mcb.STRUCTURE_ID = (select mcs_b.STRUCTURE_ID
                 from mtl_category_sets_b mcs_b
                 where mcs_b.CATEGORY_SET_ID = (select mcs_tl.CATEGORY_SET_ID
                     from mtl_category_sets_tl mcs_tl
                     where CATEGORY_SET_NAME ='INV_COLORS_SET'));
    
          l_description := 'new black color';
    
         INV_ITEM_CATEGORY_PUB.Update_Category_Description (
           p_api_version     => 1.0,
           p_init_msg_list   => FND_API.G_FALSE,
           p_commit          => FND_API.G_TRUE,
           x_return_status   => l_return_status,
           x_errorcode       => l_error_code,
           x_msg_count       => l_msg_count,
           x_msg_data        => l_msg_data,
           p_category_id     => l_category_id,
           p_description     => l_description);
    
      IF l_return_status = fnd_api.g_ret_sts_success THEN
        COMMIT;
        DBMS_OUTPUT.put_line ('Update of Item Category Description is Successful : '||l_category_id);
      ELSE
        DBMS_OUTPUT.put_line ('Update of Item Category Description Failed with the error :'||l_error_code);
        ROLLBACK;
      END IF;
    END ;
    
    
    Use following API for assigning a category to a category set. A category will be available in the list of valid categoies for a category set only if it is assigned to the category set. This is a required step if for categories enforce list is checked on.
    
    
    4. INV_ITEM_CATEGORY_PUB.Create_Valid_Category
    
    
    Create a record in mtl_category_set_valid_cats.
    
    
    DECLARE
            l_return_status   VARCHAR2(80);
            l_error_code      NUMBER;
            l_msg_count       NUMBER;
            l_msg_data        VARCHAR2(80);
            l_category_set_id NUMBER;
            l_category_id     NUMBER;
    BEGIN
           select mcs_tl.CATEGORY_SET_ID into l_category_set_id
             from mtl_category_sets_tl mcs_tl
            where mcs_tl.CATEGORY_SET_NAME ='INV_COLORS_SET';
    
           select mcb.CATEGORY_ID into l_category_id
             from mtl_categories_b mcb
            where mcb.SEGMENT1='RED'
              and mcb.STRUCTURE_ID = (select mcs_b.STRUCTURE_ID
                  from mtl_category_sets_b mcs_b
                  where mcs_b.CATEGORY_SET_ID = (select mcs_tl.CATEGORY_SET_ID
                        from mtl_category_sets_tl mcs_tl
                        where CATEGORY_SET_NAME ='INV_COLORS_SET'));
    
           INV_ITEM_CATEGORY_PUB.Create_Valid_Category (
                 p_api_version        => 1.0,
                 p_init_msg_list      => FND_API.G_FALSE,
                 p_commit             => FND_API.G_TRUE,
                 x_return_status      => l_return_status,
                 x_errorcode          => l_error_code,
                 x_msg_count          => l_msg_count,
                 x_msg_data           => l_msg_data,
                 p_category_set_id    => l_category_set_id,
                 p_category_id        => l_category_id,
                 p_parent_category_id => NULL );
    
      IF l_return_status = fnd_api.g_ret_sts_success THEN
        COMMIT;
        DBMS_OUTPUT.put_line ('Create Valid Category is Successful : '||l_category_id);
      ELSE
        DBMS_OUTPUT.put_line ('Create Valid Category Failed with the error :'||l_error_code);
        ROLLBACK;
      END IF;
    END ;
    
    
    5. INV_ITEM_CATEGORY_PUB.Delete_Valid_Category
    
    
    Delete the record from mtl_category_set_valid_cats.
    
    
    DECLARE
               l_return_status    VARCHAR2(80);
               l_error_code       NUMBER;
               l_msg_count        NUMBER;
               l_msg_data         VARCHAR2(80);
               l_category_set_id  NUMBER;
               l_category_id      NUMBER;
    BEGIN
             select mcs_tl.CATEGORY_SET_ID into l_category_set_id
               from mtl_category_sets_tl mcs_tl
              where mcs_tl.CATEGORY_SET_NAME ='INV_COLORS_SET';
    
             select mcb.CATEGORY_ID into l_category_id
               from mtl_categories_b mcb
              where mcb.SEGMENT1='RED'
                and mcb.STRUCTURE_ID = (select mcs_b.STRUCTURE_ID
                    from mtl_category_sets_b mcs_b
                    where mcs_b.CATEGORY_SET_ID = (select mcs_tl.CATEGORY_SET_ID
                      from mtl_category_sets_tl mcs_tl
                      where CATEGORY_SET_NAME ='INV_COLORS_SET'));
    
          INV_ITEM_CATEGORY_PUB.Delete_Valid_Category (
                p_api_version      => 1.0,
                p_init_msg_list    => FND_API.G_FALSE,
                p_commit           => FND_API.G_TRUE,
                x_return_status    => l_return_status,
                x_errorcode        => l_error_code,
                x_msg_count        => l_msg_count,
                x_msg_data         => l_msg_data,
                p_category_set_id  => l_category_set_id,
                p_category_id      => l_category_id);
    
      IF l_return_status = fnd_api.g_ret_sts_success THEN
        COMMIT;
        DBMS_OUTPUT.put_line ('Delete Valid Category is Successful : '||l_category_id);
      ELSE
        DBMS_OUTPUT.put_line ('Delete Valid Category Failed with the error :'||l_error_code);
        ROLLBACK;
      END IF;
    END ;