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 onsize1000000

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

 

  selectnvl(rtrim(ltrim(upper('&Application_user_name'))),'SYSADMIN')

  into:v_username

  from dual;

 

  selectsubstr(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.');

  endif;

 

  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)>0loop

    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);

  endloop;

 

  DBMS_OUTPUT.PUT_LINE(' ');

 

  if l_counter =0then

    raiseno_data_found;

  endif;

  dbms_sql.close_cursor(l_cursor);

 

exception

  whenno_data_foundthen

    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));

  whenothersthen

    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 numberPROMPT  '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

      1into:s_item_org_count

    FROM

    mtl_system_items_b

    WHERE

        organization_id =:s_orgid and

    inventory_item_id =:s_itemid;

 

    exception

  whenno_data_foundthen

    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

selecttranslate('&partnum',

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

                  'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') OPARTNUM from dual;

clear breaks

set termout on

 

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

Defineu='_'

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

--@CoreApiHtml.sql

@@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 inVARCHAR2)is

    l_proc VARCHAR2(40):='SecionPrintBig';

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

 

begin

 

    run_sql(p_title,l_sql,'N');

    exceptionwhenothersthen DisplayError('SectionPrintBig',null);

 

end SectionPrintBig;

 

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

-- function GetOrgID

--      return organization_id

--      of a given organization short name

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

function GetOrgID( p_orgcode varchar2)

    returnnumberis

 

    v_orgid numberdefault-1;

 

begin

    SELECT

      organization_id  into v_orgid

    FROM

    mtl_parameters

    WHERE

    organization_code = p_orgcode;

 

    return v_orgid;

 

    exceptionwhenno_data_foundthen

        return-99;

 

end GetOrgID;

 

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

-- function GetItemID

--      return inventory_item_id

--      of a given item name/part number

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

function GetItemID( p_partnum varchar2)

    returnnumberis

 

    v_itemid numberdefault-1;

 

begin

    SELECT

      distinct(inventory_item_id)into v_itemid

    FROM

    mtl_item_flexfields

    WHERE

    item_number = p_partnum;

 

    return v_itemid;

 

    exceptionwhenno_data_foundthen

        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)

    returnbooleanis

 

    v_count numberdefault-1;

 

begin

    selectcount(*)into v_count

  from mtl_system_items_b

    where organization_id = p_orgid

    and inventory_item_id = p_itemID;

 

    if v_count <>1then

        returnfalse;

    else

        returntrue;

    endif;

end CheckItemOrg;

 

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

-- function IsSerialControlled

--      return true if the item is serial controlled

--      return false otherwise

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

function IsSerialControlled(

    p_orgid number,

    p_itemid number)

    returnbooleanis

 

    v_ctrl_code numberdefault1;

 

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 <>1then

        returntrue;

    else

        returnfalse;

    endif;

   

end IsSerialControlled;

 

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

-- function HasMOQDTable

--      return true if the table mtl_onhand_quantities_detail exists

--      return false otherwise

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

function HasMOQDTable returnbooleanis

 

    hold_count numberdefault0;

 

begin

    SELECT

  count(*)into hold_count

    FROM

  all_tables

    WHERE

  table_name ='MTL_ONHAND_QUANTITIES_DETAIL'  and

  owner ='INV';

 

    if hold_count >0then

        returntrue;

    else

        returnfalse;

    endif;

end HasMOQDTable;

 

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

-- procedure DisplayItemCtrlInfo

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

--      + revision

--          + lot

--          + locator

--          + serial

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

procedure DisplayItemCtrlInfo (p_orgid innumber, p_itemid innumber)is

 

    v_sqltext_num number;

    sqltext varchar2(32767);

    v_LotCtrlCode numberdefault1;

    v_LocCtrlCode numberdefault1;

 

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 =1then

    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",';

    endif;

 

    -- =======

    -- 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"';

    endif;

   

    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

        WHENOTHERSTHEN

            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 innumber)is

        sql_text         varchar2(32767);

        l_hold_num      number;

begin

 

      select1into 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 =1then

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

      endif;

 

      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

        WHENOTHERSTHEN

            DisplayError('DisplayOrganizationInfo',null);

 

end DisplayOrganizationInfo;

 

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

-- procedure DisplayItemInfo

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

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

procedure DisplayItemInfo (p_orgid innumber, p_itemid innumber)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

        WHENOTHERSTHEN

            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 innumber, p_itemid innumber)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,  '

||'                 1, ''Approved'', '

||'                 2, ''Unapproved'', '

||'                 ''Other('' || MSI.REQUISITION_APPROVAL_TYPE || '')'') "Requisition Approval Type",'

||'        gcc1.concatenated_segments "Material Account",'

||'        gcc2.concatenated_segments "Material Overhead Account",'

||'        gcc3.concatenated_segments "Resource Account",'

||'        gcc4.concatenated_segments "Overhead Account",'

||'        gcc5.concatenated_segments "Outside Processing Account",'

||'        gcc6.concatenated_segments "Expense Account",'

||'        gcc7.concatenated_segments "Encumbrance Account",'

||'        msi.material_overhead_account,'

||'        msi.resource_account,'

||'        msi.overhead_account,'

||'        msi.outside_processing_account,'

||'        msi.expense_account,'

||'        msi.encumbrance_account,'

||'        sublist."Has Onhand Qty?"'

||' from mtl_secondary_inventories msi, '

||'      gl_code_combinations_kfv gcc1,'

||'      gl_code_combinations_kfv gcc2,'

||'      gl_code_combinations_kfv gcc3,'

||'      gl_code_combinations_kfv gcc4,'

||'      gl_code_combinations_kfv gcc5,'

||'      gl_code_combinations_kfv gcc6,'

||'      gl_code_combinations_kfv gcc7,'

||' ('

||' select msi_only.*,''No'' "Has Onhand Qty?" from'

||'        ('

||'        select distinct msi.secondary_inventory_name'

||'        from MTL_SECONDARY_INVENTORIES MSI,MTL_ITEM_SUB_INVENTORIES MISI'

||'        where MSI.ORGANIZATION_ID = MISI.ORGANIZATION_ID and'

||'        MSI.SECONDARY_INVENTORY_NAME = MISI.SECONDARY_INVENTORY and'

||'        MSI.ORGANIZATION_ID = '|| p_orgid ||' and '

||'        MISI.INVENTORY_ITEM_ID = '|| p_itemid

||'        minus'

||'        select distinct secondary_inventory_name '

||'        from mtl_secondary_inventories msi, '

||'             MTL_ONHAND_QUANTITIES MOQ '

||'        where moq.organization_id = '|| p_orgid ||' and '

||'              moq.inventory_item_id = '|| p_itemid

||'        and msi.secondary_inventory_name = moq.SUBINVENTORY_CODE'

||'        ) msi_only'

||' union '

||' select moq.*,''Yes'' "Has Onhand Qty?" from'

||'        (      '

||'        select distinct secondary_inventory_name '

||'        from mtl_secondary_inventories msi, '

||'             MTL_ONHAND_QUANTITIES MOQ '

||'        where moq.organization_id = '|| p_orgid

||'        and moq.inventory_item_id = '|| p_itemid

||'        and msi.secondary_inventory_name = moq.SUBINVENTORY_CODE'

||'        ) moq'

||' ) sublist'

||' where msi.secondary_inventory_name = sublist.secondary_inventory_name'

||'   and msi.organization_id = '|| p_orgid

||'   and msi.material_account = gcc1.CODE_COMBINATION_ID(+)'

||'   and msi.material_overhead_account = gcc2.CODE_COMBINATION_ID(+)'

||'   and msi.resource_account = gcc3.CODE_COMBINATION_ID(+)'

||'   and msi.overhead_account = gcc4.CODE_COMBINATION_ID(+)'

||'   and msi.outside_processing_account = gcc5.CODE_COMBINATION_ID(+)'

||'   and msi.expense_account = gcc6.CODE_COMBINATION_ID(+)'

||'   and msi.encumbrance_account = gcc7.CODE_COMBINATION_ID(+)'

||' order by msi.secondary_inventory_name ';

 

                v_sqltext_num := Display_SQL(sql_text,'Subinventory Assignments','Y');

 

    EXCEPTION

        WHENOTHERSTHEN

            DisplayError('DisplaySubinvInfo',null);

 

end DisplaySubinvInfo;

 

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

-- procedure DisplayCategoryInfo

--      display all categories that the item belongs

--    together with structure and category set names

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

procedure DisplayCategoryInfo( p_orgid innumber, p_itemid innumber)is

    sql_text    varchar2(32767);

    v_sqltext_num   number;

   

begin

 

    sql_text :=

' SELECT'

||'  micv.CATEGORY_SET_NAME "Category Set",'

||'  micv.CATEGORY_SET_ID "Category Set ID",'

||'  decode( micv.CONTROL_LEVEL,'

||'                   1, ''Master'','

||'                 2, ''Org'','

||'                 ''Other'') "Control Level",'

||'  micv.CATEGORY_ID "Category ID",'

||'  micv.CATEGORY_CONCAT_SEGS "Category"'

||' FROM '

||'  MTL_ITEM_CATEGORIES_V micv'

||' WHERE '

||'  micv.organization_id = '|| p_orgid ||' and '

||'  micv.inventory_item_id = '||p_itemid ;

 

        v_sqltext_num := Display_SQL(sql_text,'Category Assignments','Y');

 

    EXCEPTION

        WHENOTHERSTHEN

            DisplayError('DisplayCategoryInfo',null);

 

end DisplayCategoryInfo;

 

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

-- procedure DisplayCatalogInfo

--      display any catalog group information and

--    display any descriptive element information

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

procedure DisplayCatalogInfo( p_orgid innumber, p_itemid innumber)is

    sql_text    varchar2(32767);

    v_sqltext_num   number;

 

begin

 

    sql_text :=

' SELECT '

||'  msi.ITEM_CATALOG_GROUP_ID "Group id",'

||'  micgv.CONCATENATED_SEGMENTS "Group Name"'

||' FROM '

||'  mtl_system_items_b msi,'

||'  mtl_item_catalog_groups_kfv micgv'

||' WHERE '

||'  msi.organization_id = '|| p_orgid ||' and'

||'  inventory_item_id = '|| p_itemid ||'  and'

||'  msi.ITEM_CATALOG_GROUP_ID = micgv.ITEM_CATALOG_GROUP_ID';

 

    v_sqltext_num := Display_SQL(sql_text,'Catalog Group Assignments','Y');

 

    sql_text :=

  ' select '

||' mdv.ELEMENT_SEQUENCE "Element Sequence",'

||' mdv.ELEMENT_NAME "Element Name", '

||' mde.DESCRIPTION "Description", '

||' mdv.ELEMENT_VALUE "Element Value",'

||' decode( mde.REQUIRED_ELEMENT_FLAG ,'

||'         ''N'', ''No'','

||'                 ''Y'', ''Yes'','

||'                 ''Other'') "Required",'

||' decode( mde.DEFAULT_ELEMENT_FLAG,'

||'                 ''N'', ''No'','

||'                 ''Y'', ''Yes'','

||'                 ''Other'') "Defaulted"'

||' from mtl_descriptive_elements mde,'

||' mtl_descr_element_values mdv,'

||' mtl_system_items_b msi'

||' where '

||' msi.organization_id = '|| p_orgid ||' and'

||' msi.inventory_item_id = '|| p_itemid ||' and'

||' msi.inventory_item_id = mdv.inventory_item_id and'

||' mde.ITEM_CATALOG_GROUP_ID = msi.ITEM_CATALOG_GROUP_ID and'

||' mdv.element_value is not null';

 

    v_sqltext_num := Display_SQL(sql_text,'Catalog Descriptive Elements','Y');

 

    EXCEPTION

        WHENOTHERSTHEN

            DisplayError('DisplayCatalogInfo',null);

 

end DisplayCatalogInfo;

 

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

-- procedure DisplaySerialNumberInfo

--      display any serial number information for the item

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

procedure DisplaySerialNumberInfo( p_orgid innumber, p_itemid innumber)is

    sql_text    varchar2(32767);

    v_sqltext_num   number;

    l_cnt number;

    l_title varchar2(4000);

 

begin

 

    sql_text :='select count(*) from dual';

    sql_text :=

  '   SELECT'

||'       s.SERIAL_NUMBER, '

||'       s.CURRENT_STATUS || '' '' || LU.MEANING "Current status", '

||'       s.CURRENT_SUBINVENTORY_CODE "Current subinv", '

||'       s.CURRENT_LOCATOR_ID "Current locator ID", '

||'       s.COST_GROUP_ID "Cost Group ID", '

||'       s.LPN_ID "LPN ID", '

||'       s.GROUP_MARK_ID "Group mark",'

||'       s.LINE_MARK_ID "Line mark" ,'

||'       s.LOT_LINE_MARK_ID "Lot line mark"'

||'     FROM '

||'       mtl_serial_numbers s, mfg_lookups lu'

||'     WHERE '

||'       s.CURRENT_ORGANIZATION_ID = '|| p_orgid ||' and'

||'       s.INVENTORY_ITEM_ID = '|| p_itemid

||'       and ''SERIAL_NUM_STATUS'' = lu.lookup_type(+) and s.current_status = lu.lookup_code(+) '

||'     ORDER BY s.last_update_date desc ';

 

    selectcount(*)into l_cnt from mtl_serial_numbers

    WHERE CURRENT_ORGANIZATION_ID = p_orgid and INVENTORY_ITEM_ID = p_itemid;

 

    l_title :='Serial Number Assignments';

    if l_cnt >100then

        l_title := l_title ||' (first 100 most recently updated rows out of '|| l_cnt ||')';

    endif;

 

    v_sqltext_num := Run_SQL(l_title, sql_text,'Y',100);

 

    sql_text :=

' SELECT'

||'   mut.SERIAL_NUMBER "Serial Number",'

||'   mut.transaction_date "Transaction Date",'

||'   mut.transaction_id "Transaction ID",'

||'   mttv.TRANSACTION_TYPE_NAME "Transaction Type",'

||'   mut.transaction_source_id "Source ID",'

||'   mut.subinventory_code "Subinventory",'

||'   mut.locator_id "Locator Id"'

||' FROM '

||'   mtl_unit_transactions mut,'

||'   mtl_material_transactions mmt,'

||'   MTL_TRX_TYPES_VIEW mttv'

||' WHERE '

||'   mut.organization_id = '|| p_orgid ||' and'

||'   mut.inventory_item_id = '|| p_itemid ||' and'

||'   mut.organization_id = mmt.organization_id and'

||'   mut.inventory_item_id = mmt.inventory_item_id and'

||'   mut.transaction_id = mmt.transaction_id and'

||'   mut.serial_number in ('

||'     SELECT '

||'       SERIAL_NUMBER'

||'     FROM '

||'       mtl_serial_numbers'

||'     WHERE '

||'       CURRENT_ORGANIZATION_ID = '|| p_orgid ||' and'

||'       INVENTORY_ITEM_ID = '|| p_itemid ||' ) '

||' order by mut.transaction_date desc, mut.serial_number';

 

   

    -- Commented Output (Not currently implemented)

    -- v_sqltext_num := Run_SQL('Serial Number Transaction Information, 100 most current', sql_text, 'Y', 100);

 

    EXCEPTION

        WHENOTHERSTHEN

            DisplayError('DisplaySerialNumberInfo',null);

 

end DisplaySerialNumberInfo;

 

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

-- procedure DisplayRevisionInfo

--      display any Revision information for the item

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

procedure DisplayRevisionInfo( p_orgid innumber, p_itemid innumber)is

    sql_text    varchar2(32767);

    v_sqltext_num   number;

 

begin

 

    sql_text :=

' SELECT'

||'   REVISION "Revision",'

||'   CREATION_DATE "Creation Date",'

||'   CHANGE_NOTICE "ECO Name",'

||'   IMPLEMENTATION_DATE "Implementation Date",'

||'   EFFECTIVITY_DATE "Effectivity Date"'

||' FROM '

||'   MTL_ITEM_REVISIONS'

||' WHERE '

||'   ORGANIZATION_ID = '|| p_orgid ||' and'

||'   INVENTORY_ITEM_ID = '|| p_itemid;

 

    v_sqltext_num := Display_SQL(sql_text,'Revision Assignments','Y');

 

    EXCEPTION

        WHENOTHERSTHEN

            DisplayError('DisplayRevisionInfo',null);

 

end DisplayRevisionInfo;

 

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

-- procedure DisplayLotInfo

--      display any Lot Number information for the item

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

procedure DisplayLotInfo( p_orgid innumber, p_itemid innumber)is

    sql_text    varchar2(32767);

    v_sqltext_num   number;

    l_cnt number;

    l_title varchar2(4000);

 

begin

 

    sql_text :=

' SELECT '

||'   LOT_NUMBER "Lot Number",'

||'   DESCRIPTION "Description",'

||'   EXPIRATION_DATE "Expiration Date",'

||'   decode( DISABLE_FLAG,'

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

||'           ''No'' ) "Disabled"'

||' FROM '

||'   MTL_LOT_NUMBERS '

||' WHERE '

||'   ORGANIZATION_ID = '|| p_orgid ||' and'

||'   INVENTORY_ITEM_ID = '|| p_itemid

||'   order by last_update_date desc ';

 

    selectcount(*)into l_cnt

        FROM MTL_LOT_NUMBERS WHERE ORGANIZATION_ID = p_orgid and INVENTORY_ITEM_ID = p_itemid;

 

    l_title :='Lot Assignments';

    if l_cnt >100then

        l_title := l_title ||' (first 100 most recently updated rows out '|| l_cnt ||')';

    endif;

 

    v_sqltext_num := Run_SQL(l_title, sql_text,'Y',100);

 

    EXCEPTION

        WHENOTHERSTHEN

            DisplayError('DisplayLotInfo',null);

 

end DisplayLotInfo;

 

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

-- procedure DisplayLocatorInfo

--      display any Locator information for the item

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

procedure DisplayLocatorInfo( p_orgid innumber, p_itemid innumber)is

    sql_text    varchar2(32767);

    v_sqltext_num   number;

    v_itemloc_count numberdefault0;

 

begin

    SELECT

      count(*)into v_itemloc_count

    FROM

      mtl_secondary_locators

    WHERE

      organization_id = p_orgid  and

      inventory_item_id = p_itemid;

 

    if v_itemloc_count >0then

        sql_text :=

    'SELECT'

||'   msl.SUBINVENTORY_CODE "Subinventory",'

||'   milv.CONCATENATED_SEGMENTS "Restrict Locator",'

||'   msl.SECONDARY_LOCATOR "Locator ID",'

||'   sum(moq.transaction_quantity) "Onhand"'

||' FROM '

||'   mtl_item_locations_kfv milv,'

||'   mtl_secondary_locators msl'

||' WHERE '

||'   msl.organization_ID = '|| p_orgid ||'  and'

||'   msl.inventory_item_ID = '|| p_itemid ||' and'

||'   milv.ORGANIZATION_ID (+) = moq.ORGANIZATION_ID and'

||'   msl.SECONDARY_LOCATOR = milv.INVENTORY_LOCATION_ID (+)'

||' group by msl.SUBINVENTORY_CODE, msl.secondary_locator, milv.CONCATENATED_SEGMENTS';

 

        v_sqltext_num := Display_SQL(sql_text,'Locators within Subinventories setup for the Item specifically','Y');

    endif;

 

    sql_text :=

'SELECT'

||'  moq.SUBINVENTORY_CODE "Subinventory",'

||'  milv.CONCATENATED_SEGMENTS "Locator",'

||'  moq.locator_id "Locator ID",  '

||'  moq.revision "Revision",'

||'  moq.lot_number "Lot",'

||'  moq.cost_group_id "Cost Group ID",'

||'  sum(moq.transaction_quantity) "Onhand"'

||' FROM ';

   

    if HasMOQDTable then

        sql_text := sql_text

||'  MTL_ONHAND_QUANTITIES_DETAIL MOQ,  ';

    else

        sql_text := sql_text

||'  MTL_ONHAND_QUANTITIES MOQ, ';

    endif;

 

        sql_text := sql_text

||'  mtl_item_locations_kfv milv'

||' WHERE '

||'  moq.organization_id = '|| p_orgid ||' and'

||'  moq.inventory_item_id = '|| p_itemid ||' and'

||'  milv.ORGANIZATION_ID (+) = moq.ORGANIZATION_ID and'

||'  moq.locator_id = milv.INVENTORY_LOCATION_ID (+)'

||' group by moq.SUBINVENTORY_CODE, milv.CONCATENATED_SEGMENTS, moq.locator_id, '

||'       moq.revision, moq.lot_number, moq.cost_group_id';

 

    v_sqltext_num := Display_SQL(sql_text,'Locators within Subinventories the Item has Current Onhand Quantity','Y');

 

    EXCEPTION

        WHENOTHERSTHEN

            DisplayError('DisplayLocatorInfo',null);

 

end DisplayLocatorInfo;

 

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

-- procedure DisplayOnhandInfo

--      display any Onhand information for the item

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

procedure DisplayOnhandInfo( p_orgid innumber, p_itemid innumber)is

    sql_text    varchar2(32767);

    v_sqltext_num   number;

 

begin

 

    sql_text :=

' SELECT '

||'  nvl(o.subinventory_code,  ''~'') "Subinventory",'

||'  nvl(l.CONCATENATED_SEGMENTS ,  ''~'') "Locator",'

||'  nvl(o.revision,  ''~'') "Revision",'

||'  nvl(o.lot_number,  ''~'') "Lot",'

||'  nvl(o.cost_group_id,  -999) "Cost Group ID",'

||'  sum(o.transaction_quantity) "Current Onhand"'

||' FROM '

||'  MTL_ONHAND_QUANTITIES o, '

||'  mtl_item_locations_kfv l'

||' WHERE '

||'  o.organization_id = '|| p_orgid ||'  and'

||'  o.inventory_item_id = '|| p_itemid  ||'  and'

||'  o.organization_id = l.ORGANIZATION_ID (+)      and'

||'  o.LOCATOR_ID  = l.INVENTORY_LOCATION_ID (+)'

||' group by    '

||'  o.subinventory_code,   '

||'  l.CONCATENATED_SEGMENTS ,      '

||'  o.revision,    '

||'  o.lot_number,  '  

||'  o.cost_group_id ';

 

    v_sqltext_num := Display_SQL(sql_text,'Onhand Quantity Information','Y');

 

    EXCEPTION

        WHENOTHERSTHEN

            DisplayError('DisplayOnhandInfo',null);

 

end DisplayOnhandInfo;

 

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

-- procedure DisplayUnprocessedMtlInfo

--      display any unprocessed transaction information for the item

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

procedure DisplayUnprocessedMtlInfo( p_orgid innumber, p_itemid innumber)is

    sql_text    varchar2(32767);

    v_sqltext_num   number;

 

begin

 

    sql_text :=

' SELECT'

||'   mti.TRANSACTION_INTERFACE_ID "Transaction Interface ID",'

||'   mti.TRANSACTION_TYPE_ID "Transaction Type ID",'

||'   mttv.TRANSACTION_TYPE_NAME "Transaction Type Name",'

||'   mti.TRANSACTION_QUANTITY "Transaction Quantity",'

||'   mti.ERROR_CODE "Error Code",'

||'   mti.ERROR_EXPLANATION "Error Explanation",'

||'   mti.PROCESS_FLAG "Process Flag",'

||'   mti.LOCK_FLAG "Lock Flag",'

||'   mti.TRANSACTION_MODE "Transaction Mode"'

||' FROM '

||'   MTL_TRANSACTIONS_INTERFACE mti,'

||'   MTL_TRX_TYPES_VIEW mttv '

||' WHERE '

||'   mti.ORGANIZATION_ID  = '|| p_orgid ||' and'

||'   mti.INVENTORY_ITEM_ID = '|| p_itemid ||' and'

||'   mti.TRANSACTION_TYPE_ID = mttv.TRANSACTION_TYPE_ID';

 

    v_sqltext_num := Display_SQL(sql_text,'Unprocessed Material','Y');

 

    EXCEPTION

        WHENOTHERSTHEN

            DisplayError('DisplayUnprocessedInfo',null);

 

end DisplayUnprocessedMtlInfo;

 

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

-- procedure DisplayPendingMtlInfo

--      display any pending transaction information for the item

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

procedure DisplayPendingMtlInfo( p_orgid innumber, p_itemid innumber)is

    sql_text    varchar2(32767);

    v_sqltext_num   number;

 

begin

 

    sql_text :=

' SELECT'

||'   mmtt.TRANSACTION_TEMP_ID "Transaction Temp ID",'

||'   mmtt.TRANSACTION_TYPE_ID "Transaction Type ID",'

||'   mttv.TRANSACTION_TYPE_NAME "Transaction Type Name",'

||'   mmtt.TRANSACTION_QUANTITY "Transaction Quantity",'

||'   mmtt.ERROR_CODE "Error Code",'

||'   mmtt.ERROR_EXPLANATION "Error Explanation",'

||'   mmtt.PROCESS_FLAG "Process Flag",'

||'   mmtt.LOCK_FLAG "Lock Flag",'

||'   mmtt.TRANSACTION_MODE "Transaction Mode"'

||' FROM '

||'   MTL_MATERIAL_TRANSACTIONS_TEMP mmtt,'

||'   MTL_TRX_TYPES_VIEW mttv '

||' WHERE '

||'   mmtt.ORGANIZATION_ID  = '|| p_orgid ||' and'

||'   mmtt.INVENTORY_ITEM_ID = '|| p_itemid ||' and'

||'   mmtt.TRANSACTION_TYPE_ID = mttv.TRANSACTION_TYPE_ID';

 

    v_sqltext_num := Display_SQL(sql_text,'Pending Material','Y');

 

    EXCEPTION

        WHENOTHERSTHEN

            DisplayError('DisplayPendingMtlInfo',null);

 

end DisplayPendingMtlInfo;

 

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

-- procedure DisplayUncostedMtlInfo

--      display any uncosted transaction information for the item

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

procedure DisplayUncostedMtlInfo( p_orgid innumber, p_itemid innumber)is

    sql_text    varchar2(32767);

    v_sqltext_num   number;

 

begin

 

    sql_text :=

' SELECT'

||'       mmt.TRANSACTION_ID "Transaction Id",'

||'       mmt.TRANSACTION_TYPE_ID "Transaction Type Id",'

||'       mmt.TRANSACTION_GROUP_ID "Transaction Group Id",'

||'       mttv.TRANSACTION_TYPE_NAME "Transaction Type Name",'

||'       mmt.TRANSACTION_DATE "Transaction Date",'

||'       mmt.ACCT_PERIOD_ID "Acct Period Id",'

||'       mmt.TRANSACTION_QUANTITY "Transaction Quantity",'

||'       mmt.COSTED_FLAG "Costed Flag",'

||'       mmt.ERROR_CODE "Error Code",'

||'       mmt.ERROR_EXPLANATION "Error Explanation"'

||'     FROM '

||'       MTL_MATERIAL_TRANSACTIONS mmt,  '

||'       MTL_TRX_TYPES_VIEW mttv '

||'     WHERE '

||'       mmt.ORGANIZATION_ID  = '|| p_orgid ||' and'

||'       mmt.INVENTORY_ITEM_ID = '|| p_itemid ||' and'

||'       mmt.TRANSACTION_TYPE_ID = mttv.TRANSACTION_TYPE_ID and'

||'   mmt.COSTED_FLAG in (''N'', ''E'')';

 

    v_sqltext_num := Display_SQL(sql_text,'Uncosted Material','Y');

 

    EXCEPTION

        WHENOTHERSTHEN

            DisplayError('DisplayUncostedMtlInfo',null);

 

end DisplayUncostedMtlInfo;

 

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

-- procedure DisplayPhysicalInvInfo

--      display any physical inventory information for the item

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

procedure DisplayPhysicalInvInfo( p_orgid innumber, p_itemid innumber)is

    sql_text    varchar2(32767);

    v_sqltext_num   number;

 

begin

 

    sql_text :=

'       SELECT'

||'       distinct(mpa.physical_inventory_id) "Physical Inventory ID",'

||'       mpi.physical_inventory_name "Physical Inventory Name",'

||'         mpa.APPROVAL_STATUS "Status",'

||'       count(*) "Total Number of Posted Trxn"'

||'     FROM '

||'       mtl_physical_adjustments mpa,'

||'       mtl_physical_inventories mpi'

||'     WHERE '

||'       mpi.organization_id = mpa.organization_id  and'

||'       mpi.physical_inventory_id = mpa.physical_inventory_id and'

||'       mpi.organization_id = '|| p_orgid ||' and'

||'       mpa.inventory_item_id = '|| p_itemid ||' and'

||'          mpa.APPROVAL_STATUS = 3 '

||'     group by mpa.physical_inventory_id,mpi.physical_inventory_name,mpa.APPROVAL_STATUS';

 

    v_sqltext_num := Display_SQL(sql_text,'Physical Inventory Information','Y');

 

    EXCEPTION

        WHENOTHERSTHEN

            DisplayError('DisplayPhysicalInvInfo',null);

 

end DisplayPhysicalInvInfo;

 

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

-- procedure DisplayCycleCountInfo

--      display any cycle count information for the item

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

procedure DisplayCycleCountInfo( p_orgid innumber, p_itemid innumber)is

    sql_text    varchar2(32767);

    v_sqltext_num   number;

 

begin

 

    sql_text :=

' SELECT '

||'   mcch.CYCLE_COUNT_HEADER_NAME "Cycle Count Name",'

||'   mcce.CYCLE_COUNT_HEADER_ID "CC ID",'

||'   mac.ABC_CLASS_NAME "ABC Class Name",'

||'   mcci.ABC_CLASS_ID "ABC Class ID",'

||'   mcci.ITEM_LAST_SCHEDULE_DATE "Last Scheduled Count Date",'

||'   count(*) "Total Complete CC Entries"'

||' FROM '

||'   MTL_CYCLE_COUNT_ITEMS mcci,'

||'   MTL_CYCLE_COUNT_HEADERS mcch,'

||'   MTL_ABC_CLASSES mac,'

||'   MTL_CYCLE_COUNT_ENTRIES mcce'

||' WHERE '

||'   mcce.CYCLE_COUNT_HEADER_ID = mcch.CYCLE_COUNT_HEADER_ID and'

||'   mcce.INVENTORY_ITEM_ID = mcci.INVENTORY_ITEM_ID and'

||'   mcce.CYCLE_COUNT_HEADER_ID = mcci.CYCLE_COUNT_HEADER_ID and'

||'   mcci.ABC_CLASS_ID = mac.ABC_CLASS_ID and'

||'   mac.ORGANIZATION_ID = mcce.ORGANIZATION_ID and'

||'   mcce.ORGANIZATION_ID = '|| p_orgid ||' and'

||'   mcce.INVENTORY_ITEM_ID = '|| p_itemid ||' and'

||'   mcce.ENTRY_STATUS_CODE = 5 '

||' group by   mcch.CYCLE_COUNT_HEADER_NAME, mcce.CYCLE_COUNT_HEADER_ID, '

||'   mac.ABC_CLASS_NAME, mcci.ABC_CLASS_ID, mcci.ITEM_LAST_SCHEDULE_DATE'

||' order by mcch.CYCLE_COUNT_HEADER_NAME';

 

    v_sqltext_num := Display_SQL(sql_text,'Cycle Count Information','Y');

 

    EXCEPTION

        WHENOTHERSTHEN

            DisplayError('DisplayCycleCountInfo',null);

 

end DisplayCycleCountInfo;

 

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

-- procedure DisplayTxnDefaultInfo

--      display any Item Transaction Default information for the item

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

procedure DisplayTxnDefaultInfo( p_orgid innumber, p_itemid innumber)is

    sql_text    varchar2(32767);

    v_sqltext_num   number;

 

begin

 

    sql_text :=

' select * from ('

||'   SELECT '

||'    SUBINVENTORY_CODE "Subinventory",'

||'    '''' "Locator",'

||'    0 "Locator ID",'

||'    decode( DEFAULT_TYPE,  '

||'            1,  ''Shipping'', '

||'            2,  ''Receiving'',  '

||'            ''Other'') "Default Type",'

||'    ''Subinventory'' "Setup Type"'

||'   FROM '

||'    MTL_ITEM_SUB_DEFAULTS'

||'   WHERE '

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

||'    inventory_item_id = '|| p_itemid

||'   union '

||'   SELECT '

||'    mild.SUBINVENTORY_CODE "Subinventory",'

||'    milv.CONCATENATED_SEGMENTS "Locator",'

||'    milv.INVENTORY_LOCATION_ID "Locator ID",'

||'    decode( DEFAULT_TYPE,  '

||'            1,  ''Shipping'', '

||'            2,  ''Receiving'',  '

||'            ''Other'') "Default Type",'

||'    ''Subinventory/Locator'' "Setup Type"'

||'   FROM '

||'    MTL_ITEM_LOC_DEFAULTS mild,'

||'    mtl_item_locations_kfv milv'

||'   WHERE '

||'    mild.ORGANIZATION_ID = milv.ORGANIZATION_ID and'

||'    mild.LOCATOR_ID = milv.INVENTORY_LOCATION_ID and'

||'    mild.organization_id = '|| p_orgid ||' and'

||'    mild.inventory_item_id = '|| p_itemid ||' )'

||' order by "Subinventory", nvl("Locator",'' ''), "Default Type"';

 

    v_sqltext_num := Display_SQL(sql_text,'Transaction Defaults','Y');

 

    EXCEPTION

        WHENOTHERSTHEN

            DisplayError('DisplayOrganizationInfo',null);

 

end DisplayTxnDefaultInfo;

 

 

 

 

-- --------------------- Main starts here -------------------------------------

 

begin  -- begin (block 1)

 

  declare-- declare (block 2)

    p_username varchar2(100);

    p_respid number;

 

        -- ------------------------ Script Declare Section ----------------------

       

        p_orgcode varchar2(3);

        p_partnum varchar2(40);

        p_orgid number;

        p_itemid number;

        p_serial_num varchar2(30);

   

       

  begin  -- begin (block 2)

    p_username :=:v_username;

   

    IF &v_respid ISNULLTHEN

      p_respid :=-10;

    ELSE

      p_respid := &v_respid;

    ENDIF;

       

    Set_Client(p_username,p_respid);

    Show_Header('&v_hostnote','&v_scriptlongname');

 

   

    -- -------------------- Script Execution Section -----------------------

   

        p_orgcode :=:v_orgcode;

        p_partnum :=:v_partnum;

 

        p_orgid   := getOrgID( p_orgcode );

        p_itemid  := getItemID( p_partnum );

 

        line_out('<br><span class="BigPrint">'||'Input Parameters'||'</span>');

 

        if p_orgid <0then

            Tab1Print('Organization Code = '|| p_orgcode ||' (Organization_id   = '|| p_orgid ||')');

        else

            Tab1Print('Organization Code = '|| p_orgcode ||' (Organization_id   = '|| p_orgid ||')');

        endif;

           

        if p_itemid <0then

            Tab1Print('Part Number       = '|| p_partnum ||' (Inventory_item_id = '|| p_itemid ||')');

        else

            Tab1Print('Part Number       = '|| p_partnum ||' (Inventory_item_id = '|| p_itemid ||')');

        endif;  

 

        if CheckItemOrg(p_itemid, p_orgid)then

            Tab1Print('Item '|| p_partnum ||' exists in Organization '|| p_orgcode);

        else

            dbms_output.put_line('Item '||:v_partnum ||' does not exist in Organization '||:v_orgcode );

            dbms_output.put_line('Press CTRL-C to exit script and check the item/organization!');

   

            ErrorPrint('Item '|| p_partnum ||' does not exist in Organization '|| p_orgcode );

            ActionErrorPrint('Enter valid item/organization!');

        endif;

 

        --if HasMOQDTable then

        --  Tab1Print( 'Table mtl_onhand_quantities_detail does exist');

        --else

        --  Tab1Print( 'Table mtl_onhand_quantities_detail does NOT exist');

        --end if;

 

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

        -- Output starts here

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

        BRPrint();

        NoticePrint('The output displayed in this report is only data that is associated with values entered for the "Organization" and "Item" input parameters');

        DisplayItemCtrlInfo( p_orgid, p_itemid );

        DisplayOrganizationInfo ( p_itemid );

        DisplayItemInfo( p_orgid, p_itemid );

        DisplaySubinvInfo( p_orgid, p_itemid );

        DisplayCategoryInfo( p_orgid, p_itemid );

        DisplayCatalogInfo( p_orgid, p_itemid );

        DisplaySerialNumberInfo( p_orgid, p_itemid );

        DisplayRevisionInfo( p_orgid, p_itemid );

        DisplayLotInfo( p_orgid, p_itemid );

        DisplayOnhandInfo( p_orgid, p_itemid );

        DisplayUnprocessedMtlInfo( p_orgid, p_itemid );

        DisplayPendingMtlInfo( p_orgid, p_itemid );

        DisplayUncostedMtlInfo( p_orgid, p_itemid );

        DisplayPhysicalInvInfo( p_orgid, p_itemid );

        DisplayCycleCountInfo( p_orgid, p_itemid );

        DisplayTxnDefaultInfo( p_orgid, p_itemid );

 

 

    --  -------------------- Feedback ----------------------------

    BRPrint;

    Show_Footer('&v_scriptlongname','&v_headerinfo');

   

  -- -------------------- Script Exception Section -------------------------

  exceptionwhenothersthen-- exception section (block 2) for script code

    BRPrint;

    ErrorPrint(sqlerrm||' occurred in Script');

    ActionErrorPrint('Please report the above error to Oracle Support Services.');

    BRPrint;

    Show_Footer('&v_scriptlongname','&v_headerinfo');

    BRPrint;

  end;  -- end (block 2), script code

   

exceptionwhenothersthen   -- exceptions (block 1) for API and template code

  BRPrint;

  ErrorPrint(sqlerrm||' occurred in script');

  ActionErrorPrint('Please report the above error to Oracle Support Services.');

  BRPrint;

  Show_Footer('&v_scriptlongname','&v_headerinfo');

  BRPrint;

end;  -- end (block 1), API and template code

/

 

 

/*<TOAD_FILE_CHUNK>*/

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

Spooloff

 

set termout on

 

promptComplete.....

PROMPT

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

PROMPT  Please review the output file:  &v_spoolfilename

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

undefine v_exit

accept v_exit PROMPT  'Press <Enter> to exit...'

PROMPT

exit;

 

原文地址:https://www.cnblogs.com/quanweiru/p/3119264.html