INVItemCt115h.sql <-- (INVItemCt115h.sql ) Note: 223702.1

INVItemCt115h.sql

/*<TOAD_FILE_CHUNK>*/

undefine v_headerinfo

Define   v_headerinfo     = '$Header: INVItemCt115h.sql 115.3  18-FEB-2005 support $'

undefine v_scriptlongname

Define   v_scriptlongname = 'Inventory Item Setup Data Collection Tool'

undefine v_hostnote

Define   v_hostnote       = '223702.1'

 

 

REM   =========================================================================

REM   Copyright ?2002 Oracle Corporation Redwood Shores, California, USA

REM   Oracle Support Services.  All rights reserved.

REM   =========================================================================

REM   PURPOSE:           Provide setup and usage information of

REM                      an inventory item

REM   PRODUCT:           Oracle Inventory (INV)

REM                           

REM   PRODUCT VERSIONS:  11.5

REM   PLATFORM:          Generic

REM   PARAMETERS:       

REM              Appliation User Name

REM              Reponsibility Id

REM              Organization Short Name

REM              Part Number

REM   =========================================================================

 

 

REM   =========================================================================

REM   USAGE:             sqlplus apps/apps INVItemCt115h.sql

REM   EXAMPLE:

REM   OUTPUT:            HTML file

REM   =========================================================================

 

 

REM   =========================================================================

REM   CHANGE HISTORY:

REM     12-AUG-2002     vntran    Created

REM     18-FEB-2005     rcoleman  o Convert special chars in item names for

REM                                 use in spool output filename

REM                               o Fix decode of SERIAL_NUMBER_CONTROL_CODE

REM                               o Change DisplaySerialNumberInfo

REM                                 to join with MFG_LOOKUPS like

REM                                 MTL_SERIAL_NUMBERS_ALL_V

REM     

REM   =========================================================================

 

 

 

REM  ================SQL PLUS Environment setup================================

set serveroutput on size 1000000

set verify off

set feedback off

 

 

REM ============== Define SQL Variables for input parameters ==================

VARIABLE    v_username VARCHAR2(100);

 

VARIABLE    v_orgcode       VARCHAR2(3);

VARIABLE    v_partnum       VARCHAR2(40);

VARIABLE    s_orgid             number;

VARIABLE        s_itemid            number;

VARIABLE        s_item_org_count    number;

 

 

REM ================Show responsibilities assigned to given user===============

DECLARE

  l_applversion  fnd_product_groups.release_name%type;

  l_counter      integer;

  l_cursor       integer;

  sqltxt         varchar2(3000);

  l_resp_id      integer;

  l_resp_name    varchar2(300);

 

BEGIN

 

  select nvl(rtrim(ltrim(upper('&Application_user_name'))), 'SYSADMIN')

  into :v_username

  from dual;

 

  select substr(release_name,1,4)  into l_applversion from fnd_product_groups;

 

  if l_applversion = '11.5' then

    sqltxt := 'select to_char(a.responsibility_id) id, '||

              '       b.responsibility_name name '||

              'from   fnd_user_resp_groups a, '||

              '       fnd_responsibility_vl b, '||

              '       fnd_user u '||

              'where  a.user_id = u.user_id '||

              'and    a.responsibility_id = b.responsibility_id '||

              'and    a.responsibility_application_id = b.application_id '||

              'and    sysdate between '||

              '          a.start_date and nvl(a.end_date,sysdate+1) '||

              'and    upper(u.user_name) = '''|| :v_username ||''''||

              'order  by b.responsibility_name';

  elsif l_applversion = '11.0' or l_applversion = '10.7' then

    sqltxt := 'select to_char(a.responsibility_id) id, '||

              '       b.responsibility_name name '||

              'from   fnd_user_responsibility a, '||

              '       fnd_responsibility_vl b, '||

              '       fnd_user u '||

              'where  a.user_id = u.user_id '||

              'and    a.responsibility_id = b.responsibility_id '||

              'and    a.application_id = b.application_id '||

              'and    sysdate between '||

              '          a.start_date and nvl(a.end_date,sysdate+1) '||

              'and    upper(u.user_name) = '''|| :v_username ||''''||

              'order  by b.responsibility_name';

  else

    DBMS_OUTPUT.PUT_LINE('ERROR  - Invalid Application Version  '|| l_applversion);

    DBMS_OUTPUT.PUT_LINE('ACTION - This Script is not intended for this Application version.'  || chr(10) ||

                         '         Type Ctrl-C <Enter> to exit the script.');

  end if;

 

  DBMS_OUTPUT.PUT_LINE(chr(10) || 'Responsibilities assigned to User:  '|| :v_username);

  DBMS_OUTPUT.PUT_LINE('=================================================================' || chr(10) );

 

  l_cursor := dbms_sql.open_cursor;

  dbms_sql.parse(l_cursor, sqltxt, dbms_sql.native);

  dbms_sql.define_column(l_cursor, 1, l_resp_id);

  dbms_sql.define_column(l_cursor, 2, l_resp_name,100);

  l_counter := dbms_sql.execute(l_cursor);

  l_counter := 0;

  while dbms_sql.fetch_rows(l_cursor) > 0 loop

    l_counter := l_counter + 1;

    dbms_sql.column_value(l_cursor, 1, l_resp_id);

    dbms_sql.column_value(l_cursor, 2, l_resp_name);

    DBMS_OUTPUT.PUT_LINE(to_char(l_resp_id)||' ... '||l_resp_name);

  end loop;

 

  DBMS_OUTPUT.PUT_LINE(' ');

 

  if l_counter = 0 then

    raise no_data_found;

  end if;

  dbms_sql.close_cursor(l_cursor);

 

exception

  when no_data_found then

    DBMS_OUTPUT.PUT_LINE('ERROR  - Could not retrieve any responsibilities for this User');

    DBMS_OUTPUT.PUT_LINE('ACTION - Ensure User is valid and has at least one responsibility assigned.' || chr(10) ||

                         '         Type Ctrl-C <Enter> to exit the script.  Rerun the script with a valid user name.' || chr(10));

  when others then

    DBMS_OUTPUT.PUT_LINE('ERROR  - Responsibility error: '|| sqlerrm);

    DBMS_OUTPUT.PUT_LINE('ACTION - Please report the above error to Oracle Support Services.'  || chr(10) ||

                         '         Type Ctrl-C <Enter> to exit the script.'  || chr(10) );

 

END;

/

 

/*<TOAD_FILE_CHUNK>*/

PROMPT

undefine v_respid

accept v_respid number PROMPT  'Please choose a Responsibility ID from the list : '

PROMPT

 

 

REM ============= Accept other Input Parameters ===============================

 

prompt

accept partnum prompt 'Enter Part Number/Item Name   : '

accept orgcode prompt 'Enter Organization Short Name : '

prompt

 

 

 

begin

 

    :v_partnum := '&partnum';

    :v_orgcode := '&orgcode';

 

    -- dbms_output.put_line( 'Part Number entered       = '|| :v_partnum );

    -- dbms_output.put_line( 'Organization Code entered = '|| :v_orgcode );

 

    SELECT

      organization_id  into :s_orgid

    FROM

    mtl_parameters

    WHERE

    organization_code = :v_orgcode;

 

    SELECT

      distinct(inventory_item_id) into :s_itemid

    FROM

    mtl_item_flexfields

    WHERE

    item_number = :v_partnum;

 

    SELECT

      1 into :s_item_org_count

    FROM

    mtl_system_items_b

    WHERE

        organization_id = :s_orgid and

    inventory_item_id = :s_itemid;

 

    exception

  when no_data_found then

    DBMS_OUTPUT.PUT_LINE('ERROR  - Part Number or Organization short name, ');

        DBMS_OUTPUT.PUT_LINE('ERROR  - or combination of both does not exist');

        dbms_output.put( chr(10) );

    DBMS_OUTPUT.PUT_LINE('ACTION - Ensure Partnumber and Organization short name are valid and');

        DBMS_OUTPUT.PUT_LINE('ACTION - the item/org combination exist.');

        DBMS_OUTPUT.PUT_LINE('ACTION - Type Ctrl-C <Enter> to exit the script.  ');

        DBMS_OUTPUT.PUT_LINE('ACTION - Rerun the script with valid values.');

        dbms_output.put( chr(10) );

 

end;

/

 

/*<TOAD_FILE_CHUNK>*/

REM Remove special characters from the item name that may cause

REM a problem when used as the output spool name

COLUMN OPARTNUM   NEW_VALUE TPARTNUM

 

set termout off

select translate( '&partnum',

                  ' !@#$%^&*()''+~`"|{}[];?/<>\' || chr(9),

                  'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') OPARTNUM from dual;

clear breaks

set termout on

 

REM ============ Spooling the output file======================================

Define u = '_'

Define suffix = 'diag.html'

Define v_spoolfilename  = 'INVItemCt115h_&TPARTNUM&u&orgcode&u&suffix'

 

PROMPT  =======================================================================

PROMPT  Output will be spooled to &v_spoolfilename

PROMPT  =======================================================================

PROMPT

PROMPT Running.....

PROMPT

--mdofify by ru 2013/06/05

--spool  &v_spoolfilename

spool  D:\itemcoll\&v_spoolfilename

 

REM =================Run the Pl/SQL api file ==================================

--mdofify by ru 2013/06/05

[email protected]

@@CoreApiHtml.sql

 

 

 

-- **************************************************

-- Display an error message, taken from suppINVCt.sql

-- **************************************************

PROCEDURE DisplayError(p_proc VARCHAR2, p_data VARCHAR2) IS

    l_proc VARCHAR2(35) := 'DisplayError';

    l_stmt NUMBER := 10;

BEGIN

    ErrorPrint(SQLCODE || ' - ' || sqlerrm || ' occurred in ' || p_proc);

    ActionErrorPrint('Please report this error to Oracle Support using the feedback instructions noted at the end of this script.');

END DisplayError;

 

-- ****************************

-- Display large section header

-- ****************************

procedure SectionPrintBig (p_title in VARCHAR2) is

    l_proc VARCHAR2(40) := 'SecionPrintBig';

    l_sql VARCHAR2(100) := 'select * from dual where 1=0';

 

begin

 

    run_sql(p_title,l_sql,'N');

    exception when others then DisplayError('SectionPrintBig',null);

 

end SectionPrintBig;

 

-- =====================================

-- function GetOrgID

--      return organization_id

--      of a given organization short name

-- =====================================

function GetOrgID( p_orgcode varchar2 )

    return number is

 

    v_orgid number default -1;

 

begin

    SELECT

      organization_id  into v_orgid

    FROM

    mtl_parameters

    WHERE

    organization_code = p_orgcode;

 

    return v_orgid;

 

    exception when no_data_found then

        return -99;

 

end GetOrgID;

 

-- ===================================

-- function GetItemID

--      return inventory_item_id

--      of a given item name/part number

-- ===================================

function GetItemID( p_partnum varchar2 )

    return number is

 

    v_itemid number default -1;

 

begin

    SELECT

      distinct(inventory_item_id) into v_itemid

    FROM

    mtl_item_flexfields

    WHERE

    item_number = p_partnum;

 

    return v_itemid;

 

    exception when no_data_found then

        return -99;

 

end GetItemID;

 

-- ================================================

-- function CheckItemOrg

--      return true if item exist in the organization

--      return false otherwise

-- ================================================

function CheckItemOrg(

    p_itemID number,

    p_orgID number )

    return boolean is

 

    v_count number default -1;

 

begin

    select count(*) into v_count

  from mtl_system_items_b

    where organization_id = p_orgid

    and inventory_item_id = p_itemID;

 

    if v_count <> 1 then

        return false;

    else

        return true;

    end if;

end CheckItemOrg;

 

-- ===============================================

-- function IsSerialControlled

--      return true if the item is serial controlled

--      return false otherwise

-- ===============================================

function IsSerialControlled(

    p_orgid number,

    p_itemid number )

    return boolean is

 

    v_ctrl_code number default 1;

 

begin

    select serial_number_control_code

    into v_ctrl_code

    from mtl_system_items_b

    where organization_id = p_orgID

    and inventory_item_id = p_itemID;

 

    if v_ctrl_code <> 1 then

        return true;

    else

        return false;

    end if;

   

end IsSerialControlled;

 

-- ===============================================================

-- function HasMOQDTable

--      return true if the table mtl_onhand_quantities_detail exists

--      return false otherwise

-- ===============================================================

function HasMOQDTable return boolean is

 

    hold_count number default 0;

 

begin

    SELECT

  count(*) into hold_count

    FROM

  all_tables

    WHERE

  table_name = 'MTL_ONHAND_QUANTITIES_DETAIL'  and

  owner = 'INV';

 

    if hold_count > 0 then

        return true;

    else

        return false;

    end if;

end HasMOQDTable;

 

-- =====================================================

-- procedure DisplayItemCtrlInfo

--      display main control setup for the item in the org

--      + revision

--          + lot

--          + locator

--          + serial

-- =====================================================

procedure DisplayItemCtrlInfo (p_orgid in number, p_itemid in number) is

 

    v_sqltext_num number;

    sqltext varchar2(32767);

    v_LotCtrlCode number default 1;

    v_LocCtrlCode number default 1;

 

begin

    select lot_control_code into v_LotCtrlCode

    from mtl_system_items_b

    where organization_id = p_orgid

    and inventory_item_id = p_itemid;

 

    -- ========

    -- Revision

    -- ========

    sqltext :=

         'SELECT'

  || '      ( select decode( nvl(mia.CONTROL_LEVEL,-1),'

    || '                    ''1'',''Item/Master'','

    || '                    ''2'',''Item/Organization'','

    || '                    ''3'',''Viewable'','

    || '                    ''-1'',''null'','

    || '                    mia.CONTROL_LEVEL)'                    

  || '      from mtl_item_attributes mia'

  || '      where mia.ATTRIBUTE_NAME ='

  || '                    ''MTL_SYSTEM_ITEMS.REVISION_QTY_CONTROL_CODE'')'

  || '                                                                                  "Revision Attr Ctrl Level",'

  || '      decode( nvl(msi.REVISION_QTY_CONTROL_CODE, -1),'

  || '                  ''1'', ''No'','

    || '                    ''2'', ''Yes'','

    || '                    ''-1'', ''null'','

    || '                    msi.REVISION_QTY_CONTROL_CODE)      "Revision Control",'

  || '      mp.STARTING_REVISION                                        "Starting Revision",';

   

    -- ===

    -- Lot

    -- ===

    if v_LotCtrlCode = 1 then

    sqltext := sqltext

    || '    ( select decode( nvl(mia.CONTROL_LEVEL,-1 ),'

        || '                    ''1'',''Item/Master'','

        || '                    ''2'',''Item/Organization'','

        || '                    ''3'',''Viewable'','

        || '                    ''-1'',''null'','

        || '                    mia.CONTROL_LEVEL )'                       

    || '        from mtl_item_attributes mia'

    || '      where mia.ATTRIBUTE_NAME ='

    || '                    ''MTL_SYSTEM_ITEMS.LOT_CONTROL_CODE'')'

    || '                                                                                    "Lot Attr Ctrl Level",'

        || '        decode( nvl(msi.LOT_CONTROL_CODE, -1),'

    || '                    ''1'', ''No lot control'','

        || '                    ''2'', ''Full lot control'','

        || '                    ''-1'', ''null'','

        || '                    msi.LOT_CONTROL_CODE)                           "Item Lot Control",';

    else

        sqltext := sqltext

    || '    ( select decode( nvl(mia.CONTROL_LEVEL,-1),'

        || '                    ''1'',''Item/Master'','

        || '                    ''2'',''Item/Organization'','

        || '                    ''3'',''Viewable'','

        || '                    ''-1'',''null'','

        || '                    mia.CONTROL_LEVEL)'                    

    || '        from mtl_item_attributes mia'

    || '      where mia.ATTRIBUTE_NAME ='

    || '                    ''MTL_SYSTEM_ITEMS.LOT_CONTROL_CODE'')'

    || '                                                                                    "Lot Attr Ctrl Level",'

        || '        decode( nvl(msi.LOT_CONTROL_CODE, -1),'

    || '                    ''1'', ''No lot control'','

        || '                    ''2'', ''Full lot control'','

        || '                    ''-1'', ''null'',' 

        || '                    msi.LOT_CONTROL_CODE)                           "Item Lot Control",'

        || '        msi.AUTO_LOT_ALPHA_PREFIX                           "Item Start Lot Prefix",'

        || '        msi.START_AUTO_LOT_NUMBER                               "Item Start Lot Number",'

        || '        decode( nvl(mp.LOT_NUMBER_UNIQUENESS, -1), '

        || '                    ''1'', ''Unique for item'','

        || '                    ''2'', ''No uniqueness control'','

        || '                    ''-1'', ''Null'','

        || '                    mp.LOT_NUMBER_UNIQUENESS )              "Org Lot Ctrl Unique",'

        || '        decode( nvl(mp.LOT_NUMBER_GENERATION, -1),'

        || '                    ''1'', ''At organization level'','

        || '                    ''2'', ''At item level'','

        || '                    ''-1'', ''null'','

        || '                    mp.LOT_NUMBER_GENERATION )              "Org Lot Generation",'

        || '        decode( nvl(mp.LOT_NUMBER_ZERO_PADDING, -1),'

        || '                    ''1'', ''Yes'','

        || '                    ''2'', ''No'','

        || '                    ''-1'', ''Null'','

        || '                    mp.LOT_NUMBER_ZERO_PADDING )            "Org Lot ZeroPadSuf Flag",'

        || '        mp.AUTO_LOT_ALPHA_PREFIX                            "Org Start Lot Prefix",'

        || '        mp.LOT_NUMBER_LENGTH                                        "Org Lot Total Length",';

    end if;

 

    -- =======

    -- Locator

    -- =======

    sqltext := sqltext

    || '    ( select decode( nvl(mia.CONTROL_LEVEL,-1),'

    || '                    ''1'',''Item/Master'','

    || '                    ''2'',''Item/Organization'','

    || '                    ''3'',''Viewable'','

    || '                    ''-1'',''null'','

    || '                    mia.CONTROL_LEVEL)'                    

    || '        from mtl_item_attributes mia'

    || '      where mia.ATTRIBUTE_NAME ='

    || '                    ''MTL_SYSTEM_ITEMS.LOCATION_CONTROL_CODE'')'

    || '                                                                                        "Locator Attr Ctrl Level",'

    || '        decode( nvl(msi.LOCATION_CONTROL_CODE, -1),'

    || '                    ''1'', ''No locator control'','

    || '                    ''2'', ''Prespecified locator control'','

    || '                    ''3'', ''Dynamic entry locator control'','

    || '                    ''4'', ''Locator control determined at subinventory level'','

    || '                    ''5'', ''Locator control determined at item level'','

    || '                    ''-1'', ''null'','

    || '                    msi.LOCATION_CONTROL_CODE)                  "Item Locator Control",'

    || '        decode( nvl(msi.RESTRICT_SUBINVENTORIES_CODE,-1),'

    || '                    ''1'', ''Yes'','

    || '                    ''2'', ''No'','

    || '                    ''-1'', ''null'','

    || '                    msi.RESTRICT_SUBINVENTORIES_CODE )  "Restrict Subinventories",'

    || '        decode( nvl(msi.RESTRICT_LOCATORS_CODE, -1),'

    || '                    ''1'', ''Yes'','

    || '                    ''2'', ''No'','

    || '                    ''-1'', ''Null'','

    || '                    msi.RESTRICT_LOCATORS_CODE )                "Restrict Locators",'

    || '        decode( nvl(mp.STOCK_LOCATOR_CONTROL_CODE, -1),'

    || '                    ''1'', ''No locator control'','

    || '                    ''2'', ''Prespecified locator control'','

    || '                    ''3'', ''Dynamic entry locator control'','

    || '                    ''4'', ''Locator control determined at subinventory level'','

    || '                    ''5'', ''Locator control determined at item level'','

    || '                    ''-1'', ''null'','

    || '                    mp.STOCK_LOCATOR_CONTROL_CODE)          "Org Locator Control",';

 

    -- ======

    -- Serial

    -- ======

    if  not IsSerialControlled( p_orgid, p_itemid ) then

    sqltext := sqltext

    || '    ( select decode( nvl(mia.CONTROL_LEVEL,-1),'

        || '                    ''1'',''Item/Master'','

        || '                    ''2'',''Item/Organization'','

        || '                    ''3'',''Viewable'','

        || '                    ''-1'',''null'','

        || '                    mia.CONTROL_LEVEL)'                    

    || '        from mtl_item_attributes mia'

    || '      where mia.ATTRIBUTE_NAME ='

    || '                    ''MTL_SYSTEM_ITEMS.SERIAL_NUMBER_CONTROL_CODE'')'

    || '                                                                                        "Serial Attr Ctrl Level",'

        || '        decode( nvl(msi.SERIAL_NUMBER_CONTROL_CODE, -1),'

    || '                    ''1'', ''No control'','

        || '                    ''2'', ''Predefined serial numbers'','

        || '                    ''5'', ''Dynamic entry at inventory receipt'','

        || '                    ''6'', ''Dynamic entry at sales order issue'','

        || '                    ''-1'', ''null'','

        || '                    msi.SERIAL_NUMBER_CONTROL_CODE )        "Item Serial Control"';

    else

        sqltext := sqltext

    || '    ( select decode( nvl(mia.CONTROL_LEVEL,-1),'

        || '                    ''1'',''Item/Master'','

        || '                    ''2'',''Item/Organization'','

        || '                    ''3'',''Viewable'','

        || '                    ''-1'',''null'','

        || '                    mia.CONTROL_LEVEL)'                    

    || '        from mtl_item_attributes mia'

    || '      where mia.ATTRIBUTE_NAME ='

    || '                    ''MTL_SYSTEM_ITEMS.SERIAL_NUMBER_CONTROL_CODE'')'

    || '                                                                                        "Serial Attr Ctrl Level",'

        || '        decode( nvl(msi.SERIAL_NUMBER_CONTROL_CODE, -1),'

    || '                    ''1'', ''No control'','

        || '                    ''2'', ''Predefined serial numbers'','

        || '                    ''5'', ''Dynamic entry at inventory receipt'','

        || '                    ''6'', ''Dynamic entry at sales order issue'','

        || '                    ''-1'', ''null'','

        || '                    msi.SERIAL_NUMBER_CONTROL_CODE )        "Item Serial Control",'

    || '        msi.AUTO_SERIAL_ALPHA_PREFIX                            "Item Start Serial Prefix",'

    || '        msi.START_AUTO_SERIAL_NUMBER                            "Item Start Serial Number",'

    || '        decode( nvl(mp.SERIAL_NUMBER_TYPE, -1),'

    || '                    ''1'', ''Unique within inventory items'','

        || '                    ''2'', ''Unique within organization'','

        || '                    ''3'', ''Unique across organization'','

        || '                    ''-1'', ''Null'','

        || '                    mp.SERIAL_NUMBER_TYPE )                     "Org Serial Uniqueness",'

    || '        decode( nvl(mp.SERIAL_NUMBER_GENERATION, -1),'

    || '                    ''1'', ''At organization level'','

        || '                    ''2'', ''At item level'','

        || '                    ''-1'', ''Null'','

        || '                    mp.SERIAL_NUMBER_GENERATION )       "Org Serial Generation",'

    || '        mp.AUTO_SERIAL_ALPHA_PREFIX                             "Org Start Serial Prefix",'

    || '        mp.START_AUTO_SERIAL_NUMBER                             "Org Start Serial Number",'

    || '        mp.ALLOCATE_SERIAL_FLAG                                     "Org Allocate SN Flag"';

    end if;

   

    sqltext := sqltext

    || ' FROM'

  || '  mtl_system_items_b msi,'

  || '  mtl_parameters mp'

    || ' WHERE '

  || '  msi.ORGANIZATION_ID = mp.ORGANIZATION_ID and'

  || '  msi.ORGANIZATION_ID = ' || p_orgid || ' and'

  || '  msi.INVENTORY_ITEM_ID = ' || p_itemid ;

 

    v_sqltext_num := Display_SQL(sqltext, 'Item Controls', 'Y');

 

    EXCEPTION

        WHEN OTHERS THEN

            DisplayError('DisplayItemCtrlInfo',null);

 

end DisplayItemCtrlInfo;

 

-- =====================================================================

-- Procedure DisplayOrgSetupInfo

--      This procedure is almost same as suppINVCt.DisplayOrganizationInfo

--      I have taken most information from that procedure

--      and display it the same order INV parameters form shows

-- =====================================================================

procedure DisplayOrganizationInfo(p_itemid in number) is

        sql_text         varchar2(32767);

        l_hold_num      number;

begin

 

      select 1 into l_hold_num from all_tab_columns where table_name = 'MTL_PARAMETERS' and column_name = 'WMS_ENABLED_FLAG';

      sql_text :=

      ' select ' ||

      ' mp.organization_code "Org", ' ||

      ' mpm.organization_code "Master Org", ' ||

      ' mpc.organization_code "Cost Org", ' ||

      ' mp.organization_id "Org_ID", ' ||

      ' mp.master_organization_id "Master Org Id", ' ||

      ' mp.cost_organization_id "Cost Org Id", ' ||

      ' nvl(sob.short_name,''null'') "Set Of Books Name", ' ||

      ' nvl(ood.set_of_books_id,0) "Set Of Books Id", ' ||

      ' ou.name "Operating Unit Name", ' ||

      ' ood.operating_unit "Operating Unit", ' ||

      ' mp.calendar_code "Calendar Code", ' ||

      ' decode(nvl(mp.primary_cost_method,-1),' ||

      '          ''1'',''Standard'',' ||

      '          ''2'', ''Average'', ' ||

      '          ''3'', ''Periodic Average'', ' ||

      '          ''4'', ''Periodic Incremental LIFO'', ' ||

      '          ''5'', ''LIFO'', ' ||

      '          ''6'', ''FIFO'', ' ||

      '          ''-1'',''null'',' ||

      '          ''Other''' ||

      '        ) || ''('' || nvl(mp.primary_cost_method,-1) || '')'' "Primary Cost Method",' ||

      ' decode(mp.negative_inv_receipt_code,1,''Yes'',''No'') "Negative Balances Allowed", ' ||

      ' mp.default_cost_group_id "Default Cost Group Id", ' ||

      ' decode(nvl(mp.serial_number_generation,-1), ' ||

      '          ''1'',''Org Level'',' ||

      '          ''2'',''Item Level'', ' ||

      '          ''-1'',''null'',' ||

      '          ''Other''' ||

      '       ) || ''('' || nvl(mp.serial_number_generation,-1) || '')'' "Serial Number Generation",' ||

      ' decode(nvl(mp.lot_number_uniqueness,-1),' ||

      '          ''1'',''Unique for Item'',' ||

      '          ''2'',''None'', ' ||

      '          ''-1'',''null'',' ||

      '          ''Other''' ||

      '       ) || ''(''|| nvl(mp.lot_number_uniqueness,-1) || '')'' "Lot Number Uniqueness",' ||

      ' decode(nvl(mp.lot_number_generation,-1),' ||

      '          ''1'',''Org Level'',' ||

      '          ''2'',''Item Level'',' ||

      '          ''3'',''User Defined'', ' ||

      '          ''-1'',''null'',' ||

      '          ''Other''' ||

      '       ) || ''('' || nvl(mp.lot_number_generation,-1) || '')'' "Lot Number Generation", ' ||

      ' decode(nvl(mp.serial_number_type,-1),' ||

      '          ''1'',''Unique within Inventory Items'',' ||

      '          ''2'',''Unique within Org'',' ||

      '          ''3'',''Unique across Orgs'', ' ||

      '          ''-1'',''null'',' ||

      '          ''Other''' ||

      '       ) || ''('' || nvl(mp.serial_number_type,-1) || '')'' "Serial Number Type",' ||

      ' decode(nvl(mp.stock_locator_control_code,-1),' ||

      '          ''1'',''None'',' ||

      '          ''2'',''Prespecified'',' ||

      '          ''3'',''Dynamic'',' ||

      '          ''4'',''Determined at Subinventory Level'',' ||

      '          ''5'',''Determined at Item Level'',' ||

      '          ''-1'',''null'',' ||

      '          ''Other''' ||

      '       ) || ''('' || nvl(mp.stock_locator_control_code,-1) || '')'' "Stock Locator Control Code",' ||

      ' nvl(ct.cost_type,''null'') "Avg Rates Cost Type", ' ||

      ' mp.avg_rates_cost_type_id "Avg Rates Cost Type Id"';

 

      if l_hold_num = 1 then

          sql_text := sql_text || ', mp.WMS_ENABLED_FLAG "WMS Enabled"';

      end if;

 

      sql_text := sql_text ||

        ' FROM ' ||

        '   mtl_parameters mp,' ||

        '   mtl_parameters mpc,' ||

        '   mtl_parameters mpm,' ||

        '   cst_cost_types ct,' ||

        '   org_organization_definitions ood,' ||

        '   gl_sets_of_books sob,' ||

        '   hr_operating_units ou' ||

        ' WHERE ' ||

                '   mp.organization_id in (select organization_id from mtl_system_items_b where inventory_item_id = ' || p_itemid || ') and' ||

        '   mp.cost_organization_id = mpc.organization_id  and' ||

        '   mp.master_organization_id = mpm.organization_id  and' ||

        '   ( mp.organization_id = ct.organization_id(+) and mp.avg_rates_cost_type_id = ct.cost_type_id(+) ) and' ||

        '     mp.organization_id = ood.organization_id  and' ||

        '      ood.set_of_books_id = sob.set_of_books_id(+)  and' ||

        '     ood.operating_unit = ou.organization_id(+)' ||

        ' ORDER BY mp.organization_code';

 

    l_hold_num := Display_SQL(sql_text, 'Organization Assignments', 'Y');

   

    EXCEPTION

        WHEN OTHERS THEN

            DisplayError('DisplayOrganizationInfo',null);

 

end DisplayOrganizationInfo;

 

-- ======================================================

-- procedure DisplayItemInfo

--      display all attribute setup for the item in the org

-- ======================================================

procedure DisplayItemInfo (p_orgid in number, p_itemid in number) is

    sql_text         varchar2(32767);

    v_sqltext_num number;

 

begin

    sql_text :=

        'SELECT'

    || '    user_group_name "Group", '

        || '    user_attribute_name "Attribute Name", '

    || '    nvl(user_attribute_value,  ''~'') "Attribute Value", '

    || '    control_level_dsp "Controlled at" '

        || 'FROM '

    || '    MTL_ITEM_ATTRIBUTE_VALUES_V '

        || 'WHERE '

    || '    organization_id = ' || p_orgid || ' and '

    || '    inventory_item_id = ' || p_itemid  

        || '    order by "Group" ';

 

    v_sqltext_num := Display_SQL(sql_text, 'Item Attribute Values', 'Y');

 

    EXCEPTION

        WHEN OTHERS THEN

            DisplayError('DisplayItemInfo',null);

 

end DisplayItemInfo;

 

-- ===============================================

-- procedure DisplaySubinvInfo

--      display all subinventories setup that either

--     - Item/org is restrictted to or

--     - Item/org has onhand quantity

-- ===============================================

procedure DisplaySubinvInfo( p_orgid in number, p_itemid in number ) is

    sql_text    varchar2(32767);

    v_sqltext_num   number;

   

begin

    sql_text :=

' select '

||'          msi.secondary_inventory_name, '

||'        MSI.SECONDARY_INVENTORY_NAME "Subinventory", '

||'        MSI.DESCRIPTION "Description", '

||'        MSI.DISABLE_DATE "Disable Date",' 

||'        msi.PICKING_ORDER "Picking Order",'

||'        decode(MSI.ASSET_INVENTORY, '

||'                 1, ''Asset'', '

||'                 2, ''Expense'','

||'                 ''Other ('' || MSI.ASSET_INVENTORY || '')'' ) "Asset or Expense",   '

||'        decode(MSI.INVENTORY_ATP_CODE, '

||'                 1, ''Yes'', '

||'                 2, ''No'', '

||'                 ''Other('' || INVENTORY_ATP_CODE || '')'') "Include in ATP calculation",'

||'        decode(MSI.AVAILABILITY_TYPE, '

||'                 1, ''Yes'', '

||'                 2, ''No'', '

||'                 ''Other ('' || MSI.AVAILABILITY_TYPE || '')'') "Nettable",      '

||'        decode(MSI.RESERVABLE_TYPE,        '

||'                 1, ''Yes'', '

||'                 2, ''No'', '

||'                 ''Other ('' || MSI.RESERVABLE_TYPE || '')'') "Reservable", '

||'        decode(MSI.LOCATOR_TYPE, '

||'                 1, ''No'', '

||'                 2, ''Prespecified'', '

||'                 3, ''Dynamic Entry'', '

||'                 4, ''Determined at Subinv level'', '

||'                 5, ''Determined at Item level'', '

||'                 ''Other ('' || MSI.LOCATOR_TYPE || '')'') "Locator Control", '

||'        decode(MSI.QUANTITY_TRACKED,  '

||'                 1, ''Yes'', '

||'                 2, ''No'', '

||'                 ''Other ('' || MSI.QUANTITY_TRACKED || '')'') "Quantity Tracked", '

||'        decode(MSI.SOURCE_TYPE,  '

||'                 1, ''Inventory'', '

||'                 2, ''Vendor'', '

||'                 ''Other ('' || MSI.SOURCE_TYPE || '')'') "Source Type", '

||'        decode(MSI.REQUISITION_APPROVAL_TYPE,  '

你可能感兴趣的:(Note)