Friday, May 24, 2019

Inventory Queries

Inventory Queries

Organization Details

SELECT a.organization_id,  a.organization_code,  a.organization_name,
  y.LOCATION_CODE ORG_LOCATION_CODE,  a.USER_DEFINITION_ENABLE_DATE ORG_ENABLE_DATE,
  a.DISABLE_DATE ORG_DISABLE_DATE,  y.ADDRESS_LINE_1
  ||' '  ||y.TOWN_OR_CITY   ||' '  ||y.COUNTRY
  ||' '  || y.POSTAL_CODE "Org Location Address",
  a.operating_unit,  b.name OU,   a.set_of_books_id,
  d.name LEDGER,  a.legal_entity,   c.name LE_NAME
FROM apps. ORG_ORGANIZATION_DEFINITIONS a,
  apps. HR_OPERATING_UNITS b,
  apps. xle_entity_profiles c,
  apps. gl_ledgers d,
  apps.HR_ORGANIZATION_UNITS_V y
WHERE a.operating_unit=b.organization_id
AND c.legal_entity_id =a.legal_entity
AND d.ledger_id       =a.set_of_books_id
AND a.organization_id = y.organization_id
AND (a.DISABLE_DATE  IS NULL OR DISABLE_DATE       >SYSdate)
and a.organization_code='&Org';


Organization MTL parameter Details

select
ood.organization_code ORG_CODE,
a.master_organization_id MASTER_ORG_ID,
o1.organization_code MASTER_ORG_CD,
o1.organization_name MASTER_ORG_NM,
a.cost_organization_id COST_ORG_ID,
o2.organization_code COST_ORG_CD,
o2.organization_name COST_ORG_NM,
a.source_organization_id SOURCE_ORG_ID,
o3.organization_code SOURCE_ORG_CD,
o3.organization_name SOURCE_ORG_NM,
mfg1.meaning PRIMARY_COST_METHOD,
mfg2.meaning NEGATIVE_BALANCE,
a.QA_SKIPPING_INSP_FLAG QA_Skipping_Inspection_Control,
a.WMS_ENABLED_FLAG,
mfg11.meaning GL_UPDATE_CODE,
a.calendar_code CALENDAR_CODE,
a.default_demand_class DEFAULT_DEMAND_CLASS,
mfg12.meaning ENCUMBRANCE_REVERSAL_FLAG,
mfg3.meaning LOCATOR_CONTROL,
mfg4.meaning INTERORG_TRANSFER_CODE,
DECODE(a.maintain_fifo_qty_stack_type, NULL,'',mfg6.meaning)
MAINTAIN_FIFO_COST,
mfg7.meaning SERIAL_NUMBER_TYPE,
mfg8.meaning LOT_NUMBER_UNIQUENESS,
mfg9.meaning LOT_NUMBER_GENERATION,
DECODE(a.LOT_NUMBER_ZERO_PADDING, NULL, '' ,
mfg10.meaning)
LOT_NUMBER_ZERO_PADDING,
b.rule_name ATP_RULE_NAME,
c.picking_rule_name PICKING_RULE_NAME,
a.default_locator_order_value,
a.default_subinv_order_value,
a.interorg_trnsfr_charge_percent intorg_charge_percent,
a.auto_serial_alpha_prefix,
a.start_auto_serial_number,
a.auto_lot_alpha_prefix,
a.lot_number_length,
mfg13.meaning SERIAL_GENERATION,
mfg14.meaning SOURCE_TYPE,
a.source_subinventory SOURCE_SUBINV
from
mtl_parameters a,
mtl_atp_rules b,
mtl_picking_rules c,
org_organization_definitions ood,
org_organization_definitions o1,
org_organization_definitions o2,
org_organization_definitions o3,
mfg_lookups mfg1,
mfg_lookups mfg2,
mfg_lookups mfg3,
mfg_lookups mfg4,
mfg_lookups mfg6,
mfg_lookups mfg7,
mfg_lookups mfg8,
mfg_lookups mfg9,
mfg_lookups mfg10,
mfg_lookups mfg11,
mfg_lookups mfg12,
mfg_lookups mfg13,
mfg_lookups mfg14
where a.organization_id = &organization_id
and a.master_organization_id = o1.organization_id (+)
and a.cost_organization_id = o2.organization_id (+)
and a.source_organization_id = o3.organization_id (+)
and a.organization_id = ood.organization_id (+)
and a.default_atp_rule_id = b.rule_id(+)
and a.default_picking_rule_id = c.picking_rule_id(+)
and mfg1.lookup_type (+) = 'MTL_PRIMARY_COST'
and a.primary_cost_method = mfg1.lookup_code(+)
and mfg2.lookup_type (+) = 'SYS_YES_NO'
and a.negative_inv_receipt_code = mfg2.lookup_code(+)
and mfg3.lookup_type (+) = 'MTL_LOCATION_CONTROL'
and a.stock_locator_control_code = mfg3.lookup_code(+)
and mfg4.lookup_type (+) = 'MTL_INTER_INV_TRANSFER'
and a.matl_interorg_transfer_code = mfg4.lookup_code(+)
and mfg6.lookup_type (+) = 'SYS_YES_NO'
and a.maintain_fifo_qty_stack_type = mfg6.lookup_code(+)
and mfg7.lookup_type (+) = 'MTL_SERIAL_NUMBER_TYPE'
and a.serial_number_type = mfg7.lookup_code(+)
and mfg8.lookup_type (+) = 'MTL_LOT_UNIQUENESS'
and a.lot_number_uniqueness = mfg8.lookup_code(+)
and mfg9.lookup_type (+) = 'MTL_LOT_GENERATION'
and a.lot_number_generation = mfg9.lookup_code(+)
and mfg10.lookup_type (+) = 'SYS_YES_NO'
and a.lot_number_zero_padding = mfg10.lookup_code(+)
and mfg11.lookup_type (+) = 'SYS_YES_NO'
and a.general_ledger_update_code = mfg11.lookup_code(+)
and mfg12.lookup_type (+) = 'SYS_YES_NO'
and a.encumbrance_reversal_flag = mfg12.lookup_code(+)
and mfg13.lookup_type (+) = 'MTL_SERIAL_GENERATION'
and a.serial_number_generation = mfg13.lookup_code(+)
and mfg14.lookup_type (+) = 'MTL_SOURCE_TYPES'
and a.source_type = mfg14.lookup_code (+);




Subinventory and Locator

SELECT p.organization_code ,
  s.secondary_inventory_name ,s.DESCRIPTION,s.DISABLE_DATE,s.STATUS_CODE SUBINV_STATUS,
  l.segment1
  ||'.'
  ||l.segment2
  ||'.'
  ||l.segment3 locator_name, l.description location ,l.START_DATE_ACTIVE LOC_START_DATE, l.END_DATE_ACTIVE LOC_END_DATE,
  DECODE (s.locator_type,1,'Not locator controlled','Locator controlled') locator_controlled
FROM apps.MTL_ITEM_LOCATIONS l ,
  apps.MTL_SECONDARY_INVENTORIES_FK_V s ,
  apps.MTL_PARAMETERS P
WHERE S.Organization_Id        = P.Organization_Id
AND S.Organization_id          = L.organization_id (   +)
AND S.Secondary_Inventory_Name = L.Subinventory_Code ( +)
AND p.organization_code='&ORG_CODE';

Inter-Organization Transfer



Difference between Inter-Org Transfer and IR-ISO


Additionally we can use Inter Org transfer for OSP Subassembly Item whereas IR-ISO cannot be used for OSP Subassembly Item



What is  Inter-Org Transfer

Transferring the material from Source Org to Receiving Org within same Operating Unit.

Inter-Organization transfers can be performed as either direct or intransit shipments.

Direct inter-organization transfers:
Inventory is moved directly from a shipping organization to the destination organization. Receipt is not required to be made as the transfer is direct to inventory. Therefore no ASN.

Intransit inventory:
When two org at having some distance and transportation is involved then usually we go for this as Intransit times comes in picture and to track the material we use this. Usually done when transfer time is significant. Delivery location isn't specified during transfer transaction, You only need to enter subinventory you are shipping from, a shipment number, the freight information and inter-organization transfer charge. Then you need to perform Receipt from the Receiving forms.


Setups Required for Inter-Org Transfer

1. Shipping Network

Shipping Network between source org and destination org should be defined. Please make sure that Internal Order Required should be unchecked.

All accounts which you set here gets involved during this transaction.

2. Item Setup
Inventory Item with Active status.


Inter-Org Transfer Transaction

Navigation: Inventory > Transactions > Inter-organization Transfer > Select Source/Shipping Org




Accounting in Inter-Org Transfer


From org -              Inter-org receivables debited
                                                                                   Inv valuation is 
credited


To Org -                  Inv valuation debited
                                                                                    Inter-org payables credited

Purchase Price Variance Account also gets hit if source Org and Destination Org having different Item Cost.

Thursday, May 23, 2019

List of Setups needs to perform for Implementing Oracle Apps

List of Setups needs to perform for Implementing Oracle Apps Ebiz Application

Below list will help you to identify which all setups needs to perform for Implementing Oracle Apps Application

ElementsSub-elementsSetup Type
Language Patches Optional
ResponsibilitiesResponsibility ListStructural Setup
ResponsibilitiesCustom Form Attached in the ResponsbilityTransactional Setup
ResponsibilitiesRequest GroupsTransactional Setup
ResponsibilitiesCustom Request attached to the List of ResponsibilitiesTransactional Setup
ResponsibilitiesType Of ResponsibilitiesStructural Setup
ResponsibilitiesDiff of responsibilities in Source and destination instancesOptional
Modules Installed Optional
Organization StructureOrganization, Operating Unit, Legal Entity DetailsStructural Setup
Organization StructureOrganization MTL Parameter DetailsStructural Setup
Organization StructureSubinventory and Locator DetailsStructural Setup
Org AccessOrg Access data and its comparisionStructural Setup
InventoryInventory OrganizationStructural Setup
InventoryInventory ParametersStructural Setup
InventorySubinventoriesStructural Setup
InventoryStock LocatorsStructural Setup
InventoryItem StatusesTransactional Setup
InventoryABC CodesTransactional Setup
InventoryABC CompilesTransactional Setup
InventoryABC Assignment GroupsTransactional Setup
InventoryAccount AliasesTransactional Setup
InventoryDefault SubinventoriesTransactional Setup
InventoryDefault LocatorsTransactional Setup
PO SetupsFinancials OptionsStructural Setup
PO SetupsPurchasing OptionsStructural Setup
PO SetupsReceiving OptionsTransactional Setup
PO SetupsDocument TypesTransactional Setup
PO SetupsPosition Hierarchies for Document approvalTransactional Setup
PO SetupsApproval GroupsTransactional Setup
PO SetupsApproval AssignmentsTransactional Setup
PO SetupsPurchasing and GL PeriodsStructural Setup
OM SetupsSystem ParametersStructural Setup
OM SetupsTransaction TypesTransactional Setup
OM SetupsOrder HoldsTransactional Setup
OM SetupsDefaulting RulesTransactional Setup
OM SetupsProcessing ConstraintsTransactional Setup
OM SetupsValidation TemplatesTransactional Setup
OM SetupsCredit CheckTransactional Setup
OM SetupsDocument SequencingTransactional Setup
Oracle ShippingPick Slip Grouping RulesTransactional Setup
Oracle ShippingPick Release RulesTransactional Setup
Oracle ShippingPick Release Sequence RuleTransactional Setup
Oracle ShippingDocument SetsTransactional Setup
Oracle ShippingCalender AssignmentTransactional Setup
Oracle ShippingFreight CarriersTransactional Setup
EDI setupsTrading PartnersTransactional Setup
EDI setupsCode Conversion ValuesTransactional Setup
EDI setupsProcessing RulesTransactional Setup
EDI setupsCustomer CUM quantityTransactional Setup
EDI setupsSupplier CUM quantityTransactional Setup
Bill of MaterialBOM ParametersStructural Setup
Bill of MaterialDepartmentsTransactional Setup
Bill of MaterialResourcesTransactional Setup
MRPMRP ParametersStructural Setup
MRPMPS NamesTransactional Setup
MRPMPS OptionTransactional Setup
MRPMRP OptionsStructural Setup
MRPForecast SetsTransactional Setup
Work in ProcessWIP Account ClassesTransactional Setup
Work in ProcessWIP ParametersTransactional Setup
QualityUser GroupsTransactional Setup
QualityGrant PrivilegesTransactional Setup
QualitySkip Lot ProcessTransactional Setup
QualityCollection PlanTransactional Setup
QualitySkip Lot CriteriaTransactional Setup
QualityCollection ElementsTransactional Setup
Accounts ReceivablesSystem optionsStructural Setup
Accounts ReceivablesRemit-To AddressesTransactional Setup
Accounts ReceivablesTransaction SourceTransactional Setup
Accounts ReceivablesTransaction TypeTransactional Setup
Accounts ReceivablesAuto AccountigTransactional Setup
Accounts ReceivablesAutoInvoice Line Ordering RulesTransactional Setup
Accounts ReceivablesGrouping ruleTransactional Setup
Accounts ReceivablesAcccounting rulesTransactional Setup
Accounts PayablePayables System SetupStructural Setup
Accounts PayablePayable optionsStructural Setup
Accounts PayablePayment MethodsTransactional Setup
EB TaxGeographiesTransactional Setup
EB TaxTax ZonesTransactional Setup
EB TaxLegal Entity Tax ProfileTransactional Setup
EB TaxTax RegimesTransactional Setup
EB TaxTax JurisdictionsTransactional Setup
EB TaxApplication Tax OptionsTransactional Setup
EB TaxTax Condition SetsTransactional Setup
EB TaxTaxesTransactional Setup
EB TaxTax RulesTransactional Setup
Descriptive FlexFieldsFlexfield SegmentsTransactional Setup
Descriptive FlexFieldsValue SetsTransactional Setup
Descriptive FlexFieldsValue Set ValuesTransactional Setup
FOLDERS Transactional Setup
Profiles for each moduleINV ProfilesStructural Setup
Profiles for each moduleOM profilesStructural Setup
Profiles for each moduleMRP profilesStructural Setup
Profiles for each modulePO ProfilesStructural Setup
Profiles for each moduleEDI ProfilesStructural Setup
Profiles for each moduleWIP ProfilesStructural Setup
Profiles for each moduleOther Imp ProfilesStructural Setup
Critical ScenariosBusiness Sceanrios, Critical Reports/CNI/Forms 
R12 Form Design Changes Optional
User and User Responsibility Assignment Optional

SysAdmin Queries

-- ----------------------------------------------------------------------------------------
--  Query To get All Notifications Sent By A Particular Workflow
-- ----------------------------------------------------------------------------------------
select  wn.notification_id nid,
        wn.context,
        wn.group_id,
        wn.status,
        wn.mail_status,
        wn.message_type,
        wn.message_name,
        wn.access_key,
        wn.priority,
        wn.begin_date,
        wn.end_date,
        wn.due_date,
        wn.callback,
        wn.recipient_role,
        wn.responder,
        wn.original_recipient,
        wn.from_user,
        wn.to_user,
        wn.subject
from    wf_notifications wn, wf_item_activity_statuses wias
where  wn.group_id = wias.notification_id
and  wias.item_type =  '&item_type'
and  wias.item_key =  '&item_key';


-- -----------------------------------------------------------------------------------------------------------------------------
-- To Check Workflow Mailer Up or down
-- -----------------------------------------------------------------------------------------------------------------------------

SELECT component_name as Component, component_status as Status FROM fnd_svc_components WHERE component_type = 'WF_MAILER'

-- --------------------------------------------------------------------------------------------------------------
--  Query To get the Activity Statuses For All Workflow Activities For A Particular Item Type and Item key
-- --------------------------------------------------------------------------------------------------------------
SELECT execution_time,
       to_char(ias.begin_date,
               'DD-MON-RR HH24:MI:SS') begin_date,
       ap.display_name || '/' || ac.display_name activity,
       ias.activity_status status,
       ias.activity_result_code RESULT,
       ias.assigned_user ass_user
  FROM wf_item_activity_statuses ias,
       wf_process_activities     pa,
       wf_activities_vl          ac,
       wf_activities_vl          ap,
       wf_items                  i
 WHERE ias.item_type = '&item_type'
   AND ias.item_key = '&item_key'
   AND ias.process_activity = pa.instance_id
   AND pa.activity_name = ac.name
   AND pa.activity_item_type = ac.item_type
   AND pa.process_name = ap.name
   AND pa.process_item_type = ap.item_type
   AND pa.process_version = ap.version
   AND i.item_type = '&item_type'
   AND i.item_key = ias.item_key
   AND i.begin_date >= ac.begin_date
   AND i.begin_date < nvl(ac.end_date,
                          i.begin_date + 1)
UNION ALL
SELECT execution_time,
       to_char(ias.begin_date,
               'DD-MON-RR HH24:MI:SS') begin_date,
       ap.display_name || '/' || ac.display_name activity,
       ias.activity_status status,
       ias.activity_result_code RESULT,
       ias.assigned_user ass_user
  FROM wf_item_activity_statuses_h ias,
       wf_process_activities       pa,
       wf_activities_vl            ac,
       wf_activities_vl            ap,
       wf_items                    i
 WHERE ias.item_type = '&item_type'
   AND ias.item_key = '&item_key'
   AND ias.process_activity = pa.instance_id
   AND pa.activity_name = ac.name
   AND pa.activity_item_type = ac.item_type
   AND pa.process_name = ap.name
   AND pa.process_item_type = ap.item_type
   AND pa.process_version = ap.version
   AND i.item_type = '&item_type'
   AND i.item_key = ias.item_key
   AND i.begin_date >= ac.begin_date
   AND i.begin_date < nvl(ac.end_date,
                          i.begin_date + 1)
 ORDER BY 2,
          1
/
-- -------------------------------------------------------------------------------------------
-- Query To get Errored Workflow Activities For A Particular Item Type/ Item Key
-- -------------------------------------------------------------------------------------------

SELECT ac.display_name          activity,
       ias.activity_result_code RESULT,
       ias.error_name           error_name,
       ias.error_message        error_message,
       ias.error_stack          error_stack
  FROM wf_item_activity_statuses ias,
       wf_process_activities     pa,
       wf_activities_vl          ac,
       wf_activities_vl          ap,
       wf_items                  i
 WHERE ias.item_type = '&item_type'
   AND ias.item_key = '&item_key'
   AND ias.activity_status = 'ERROR'
   AND ias.process_activity = pa.instance_id
   AND pa.activity_name = ac.name
   AND pa.activity_item_type = ac.item_type
   AND pa.process_name = ap.name
   AND pa.process_item_type = ap.item_type
   AND pa.process_version = ap.version
   AND i.item_type = '&item_type'
   AND i.item_key = ias.item_key
   AND i.begin_date >= ac.begin_date
   AND i.begin_date < nvl(ac.end_date,
                          i.begin_date + 1)
 ORDER BY ias.execution_time

-- ---------------------------------------------------------------------------------------------------
-- Query To get Errored Process Activity Statuses For A Particular Item Type/Item Key
-- ----------------------------------------------------------------------------------------------------

SELECT execution_time,
       to_char(ias.begin_date,
               'DD-MON-RR HH24:MI:SS') begin_date,
       ap.display_name || '/' || ac.display_name activity,
       ias.activity_status status,
       ias.activity_result_code RESULT,
       ias.assigned_user ass_user
  FROM wf_item_activity_statuses ias,
       wf_process_activities     pa,
       wf_activities_vl          ac,
       wf_activities_vl          ap,
       wf_items                  i
 WHERE ias.item_type = i.item_type
   AND ias.item_key = i.item_key
   AND ias.process_activity = pa.instance_id
   AND pa.activity_name = ac.name
   AND pa.activity_item_type = ac.item_type
   AND pa.process_name = ap.name
   AND pa.process_item_type = ap.item_type
   AND pa.process_version = ap.version
   AND i.parent_item_type = '&item_type'
   AND i.parent_item_key = '&item_key'
   AND i.begin_date >= ac.begin_date
   AND i.begin_date < nvl(ac.end_date,
                          i.begin_date + 1)
UNION ALL
SELECT execution_time,
       to_char(ias.begin_date,
               'DD-MON-RR HH24:MI:SS') begin_date,
       ap.display_name || '/' || ac.display_name activity,
       ias.activity_status status,
       ias.activity_result_code RESULT,
       ias.assigned_user ass_user
  FROM wf_item_activity_statuses_h ias,
       wf_process_activities       pa,
       wf_activities_vl            ac,
       wf_activities_vl            ap,
       wf_items                    i
 WHERE ias.item_type = i.item_type
   AND ias.item_key = i.item_key
   AND ias.process_activity = pa.instance_id
   AND pa.activity_name = ac.name
   AND pa.activity_item_type = ac.item_type
   AND pa.process_name = ap.name
   AND pa.process_item_type = ap.item_type
   AND pa.process_version = ap.version
   AND i.parent_item_type = '&item_type'
   AND i.parent_item_key = '&item_key'
   AND i.begin_date >= ac.begin_date
   AND i.begin_date < nvl(ac.end_date,
                          i.begin_date + 1)
 ORDER BY 2,
          1

-- ---------------------------------------------------------------------------------------------
--  Query To get The Errored Activities For A Particular Item Type/Item Key
-- ---------------------------------------------------------------------------------------------
SELECT ac.display_name          activity,
       ias.activity_result_code RESULT,
       ias.error_name           error_name,
       ias.error_message        error_message,
       ias.error_stack          error_stack
  FROM wf_item_activity_statuses ias,
       wf_process_activities     pa,
       wf_activities_vl          ac,
       wf_activities_vl          ap,
       wf_items                  i
 WHERE ias.item_type = i.item_type
   AND ias.item_key = i.item_key
   AND ias.activity_status = 'ERROR'
   AND ias.process_activity = pa.instance_id
   AND pa.activity_name = ac.name
   AND pa.activity_item_type = ac.item_type
   AND pa.process_name = ap.name
   AND pa.process_item_type = ap.item_type
   AND pa.process_version = ap.version
   AND i.parent_item_type = '&item_type'
   AND i.parent_item_key = '&item_key'
   AND i.begin_date >= ac.begin_date
   AND i.begin_date < nvl(ac.end_date,
                          i.begin_date + 1)
 ORDER BY ias.execution_time
/

 Query To get Out Attribute Values Of A Workflow:
SELECT NAME attr_name,
       nvl(text_value,
           nvl(to_char(number_value),
               to_char(date_value))) VALUE
  FROM wf_item_attribute_values
 WHERE item_type = upper('&item_type')
   AND item_key = nvl('&item_key',
                      item_key)
/
-- -----------------------------------------------------------------------------------------------
--  Query To get Out Number Of Deferred Workflow Activities
-- -----------------------------------------------------------------------------------------------

SELECT COUNT(1),
       was.item_type
  FROM apps.wf_items                  wi,
       apps.wf_item_activity_statuses was,
       apps.wf_process_activities     pra
 WHERE wi.item_type = was.item_type
   AND wi.item_key = was.item_key
   AND wi.end_date IS NULL
   AND was.end_date IS NULL
   AND was.activity_status = 'DEFERRED'
      --AND was.item_type = 'REQAPPRV'
   AND was.item_type = wi.item_type
   AND pra.instance_id(+) = was.process_activity
 GROUP BY was.item_type;

 -- ------------------------------------------------------------------------------------------------
 --  Query To Get The Details Of Various Workflow Agent Listeners And Their Statuses
 -- ------------------------------------------------------------------------------------------------

SELECT t.component_name,
       p.owner,
       p.queue_table,
       t.correlation_id
  FROM applsys.fnd_svc_components t,
       applsys.wf_agents          o,
       dba_queues                 p
 WHERE t.inbound_agent_name || t.outbound_agent_name = o.name
   AND p.owner || '.' || p.name = o.queue_name
   AND t.component_type LIKE 'WF_%AGENT%';                         

-- --------------------------------------------------------------------------------------------------
--  Query To get Records That Are Pending In Each Of The Workflow Agent Listener Queues
-- --------------------------------------------------------------------------------------------------

SELECT 'select ''' || t.component_name || ' (queue_table: ' || p.queue_table ||
       ')''||'' Count: ''||count(*) c from ' || p.owner || '.' || p.queue_table ||
       ' where deq_time is null and nvl(delay,enq_time)<sysdate-1/24 ' ||
       nvl2(t.correlation_id,
            'and corrid like ''' || t.correlation_id || ''' ',
            NULL) || 'having count(*)>0;'
  FROM applsys.fnd_svc_components t,
       applsys.wf_agents          o,
       dba_queues                 p
 WHERE t.inbound_agent_name || t.outbound_agent_name = o.name
   AND p.owner || '.' || p.name = o.queue_name
   AND t.component_type LIKE 'WF_%AGENT%';



-- -----------------------------------------------------------------------------------
-- For finding COncurrent program attached to responsibility
-- -----------------------------------------------------------------------------------

SELECT                                                   
         DISTINCT fcpt.user_concurrent_program_name, frt.responsibility_name
    --   frg.request_group_name,
    --   frgu.request_unit_type,
    -- frgu.request_unit_id,
    --,decode(instance,'CFGAPPRD','FAP1C','N')
    FROM apps.fnd_Responsibility fr,                 
         apps.fnd_responsibility_tl frt,
         apps.fnd_request_groups frg,
         apps.fnd_request_group_units frgu,
         apps.fnd_concurrent_programs_tl fcpt
   WHERE     frt.responsibility_id = fr.responsibility_id
         AND frg.request_group_id = fr.request_group_id
         AND frgu.request_group_id = frg.request_group_id
         AND fcpt.concurrent_program_id = frgu.request_unit_id
         AND frt.language = USERENV ('LANG')
         AND fcpt.language = USERENV ('LANG')
         AND fcpt.user_concurrent_program_name LIKE
                '%%'
                ORDER BY 2;
-- -----------------------------------------------------------------------------------
-- Query to get Menus & Functions attached to Responsibility.
-- -----------------------------------------------------------------------------------

  SELECT LEVEL,
                  LPAD (' ', (LEVEL-1)*3)||prompt,
                  Description
    FROM  fnd_menu_entries_vl fme
 WHERE  prompt IS NOT NULL
       AND grant_flag='Y'
      AND NOT EXISTS (SELECT 1
                     FROM fnd_resp_functions frf,
                          fnd_responsibility_vl frv
                    WHERE frv.responsibility_id = frf.responsibility_id
                      AND frf.application_id = frv.application_id
                      AND frf.rule_type='M'
                      AND frf.action_id = NVL(fme.sub_menu_id,-1)
                      AND frv.responsibility_name=:RESP_NAME)
   AND NOT EXISTS (SELECT 1
                     FROM fnd_resp_functions frf,
                          fnd_responsibility_vl frv
                    WHERE frv.responsibility_id = frf.responsibility_id
                      AND frf.application_id = frv.application_id
                      AND frf.rule_type='F'
                      AND frf.action_id = NVL(fme.function_id,-1)
                      AND frv.responsibility_name=:RESP_NAME)                   
 CONNECT BY PRIOR sub_menu_id = menu_id
   AND prompt IS NOT NULL
   AND NOT EXISTS (SELECT 1
                     FROM fnd_resp_functions frf,
                          fnd_responsibility_vl frv
                    WHERE frv.responsibility_id = frf.responsibility_id
                      AND frf.application_id = frv.application_id
                      AND frf.rule_type='M'
                      AND frf.action_id = NVL(fme.menu_id,-1)
                      AND frv.responsibility_name=:RESP_NAME)
 START WITH menu_id = (SELECT menu_id
                         FROM fnd_responsibility_vl
                        WHERE responsibility_name=:RESP_NAME)
ORDER SIBLINGS BY entry_sequence

-- -----------------------------------------------------------------------------------
-- Find all menus to which function is attached
-- -----------------------------------------------------------------------------------

select fme.menu_id
,FM.MENU_NAME
,fme.entry_sequence
,fff.function_name
from fnd_menu_entries_vl fme
,fnd_menus_vl fm
,fnd_form_functions_vl fff
where fme.menu_id=fm.menu_id
and fme.function_id=fff.function_id
and function_name LIKE 'XX%';

-- -----------------------------------------------------------------------------------
-- Query for finding menu exclusion for a responsibility
-- -----------------------------------------------------------------------------------

select res.responsibility_name
     , app.application_name
     , res.responsibility_key
     , res.description
     , res.start_date
     , res.end_date
     , dat.data_group_name
     , apd.application_name
     , mnu.menu_name
     , req.request_group_name
     , apr.application_name
     , decode(exc.rule_type,'F','Function','M', 'Menu', rule_type) Exclusion_Type
     , decode(exc.rule_type,'F',(select function_name || ',' || description
                                   from fnd_form_functions_vl fnc
                                  where fnc.function_id = exc.action_id
                                )
                           ,'M',(select menu_name || ',' || description
                                   from fnd_menus_vl imn
                                   where imn.menu_id = exc.action_id
                                )
                           , to_char(exc.action_id)
             ) Excluded_Menu_Or_func
  from apps.fnd_responsibility_vl res
     , apps.fnd_application_vl    app
     , apps.fnd_data_groups       dat
     , apps.fnd_menus_vl          mnu
     , apps.fnd_request_groups    req
     , apps.fnd_application_vl    apd
     , apps.fnd_application_vl    apr
     , apps.fnd_resp_functions    exc
 where res.application_id            = app.application_id
   and res.data_group_id             = dat.data_group_id
   and res.data_group_application_id = apd.application_id
   and res.menu_id                   = mnu.menu_id
   and req.request_group_id          = res.request_group_id
   and req.application_id            = res.group_application_id
   and apr.application_id            = req.application_id
   and exc.application_id            = res.application_id
   and exc.responsibility_id         = res.responsibility_id
   and responsibility_name ='APAC IT Support';
 
 -- -----------------------------------------------------------------------------------
 -- To find responsibilities assigned to particular user
 -- -----------------------------------------------------------------------------------

 SELECT resp_type 
       ,user_id 
       ,user_name 
       ,responsibility_id 
       ,responsibility_name 
       ,start_date 
       ,end_date 
       ,application_short_name 
       ,application_name 
 FROM  (SELECT 'DIRECT' resp_type 
              ,fu.user_id 
              ,fu.user_name 
              ,resp.responsibility_id 
              ,resp.responsibility_name 
              ,frd.start_date 
              ,frd.end_date 
              ,app.application_short_name 
              ,app.application_name 
        FROM  fnd_user                    fu 
             ,fnd_user_resp_groups_direct frd 
             ,fnd_responsibility_vl       resp 
             ,fnd_application_vl          app 
        WHERE fu.user_id            = frd.user_id 
        AND   frd.responsibility_id = resp.responsibility_id 
        AND   resp.application_id   = app.application_id 
        UNION ALL 
        SELECT 'INDIRECT' resp_type 
              ,fu.user_id 
              ,fu.user_name 
              ,resp.responsibility_id 
              ,resp.responsibility_name 
              ,fri.start_date 
              ,fri.end_date 
              ,app.application_short_name 
              ,app.application_name 
        FROM  fnd_user                      fu 
             ,fnd_user_resp_groups_indirect fri 
             ,fnd_responsibility_vl         resp 
             ,fnd_application_vl            app 
        WHERE fu.user_id           = fri.user_id 
        AND  fri.responsibility_id = resp.responsibility_id 
        AND  resp.application_id   = app.application_id) 
 WHERE 1=1 
 AND   user_name           = 'AJTEST'                -- Comment this if you need all user of a responsibility 
 AND   responsibility_name = 'System Administrator'; -- Comment this if you need all responsibilities of a user 

 -- --------------------------------------------------------------------------------------
 -- Profile Option
 -- --------------------------------------------------------------------------------------

select user_profile_option_name ,sum(level_value)
from fnd_profile_option_values fp
    ,fnd_profile_options_vl fpv
where fp.profile_option_id=fpv.profile_option_id
and level_id =10004
group by fpv.user_profile_option_name
having sum(level_value)>2;

 -- -----------------------------------------------------------------------------------
 -- Query to get the profile option values
 -- -----------------------------------------------------------------------------------

 SELECT b.user_profile_option_name "Long Name" ,
  a.profile_option_name "Short Name" ,
  NVL(g.responsibility_name,c.level_value)  "Level Value" ,
  c.PROFILE_OPTION_VALUE "Profile Value",
  b.sql_validation
FROM apps.fnd_profile_options a ,
  apps.FND_PROFILE_OPTIONS_VL b ,
  apps.FND_PROFILE_OPTION_VALUES c ,
  apps.FND_USER d ,
  apps.FND_USER e ,
  apps.FND_RESPONSIBILITY_VL g ,
  apps.FND_APPLICATION h
WHERE 1                   =1
AND a.profile_option_name = b.profile_option_name
AND a.profile_option_id   = c.profile_option_id
AND a.application_id      = c.application_id
AND c.last_updated_by     = d.user_id (+)
AND c.level_value         = e.user_id (+)
AND c.level_value         = g.responsibility_id (+)
AND c.level_value         = h.application_id (+)
  --
AND c.level_id            = 10003
AND g.responsibility_name = 'APAC IT Support'
ORDER BY b.user_profile_option_name,  c.level_id
;

-- -----------------------------------------------------------------------------------
-- Query for form function details
-- -----------------------------------------------------------------------------------

SELECT DISTINCT u.user_name, rtl.responsibility_name, ff.function_name, ffl.user_function_name
           FROM fnd_compiled_menu_functions cmf,
                fnd_form_functions ff,
                fnd_form_functions_tl ffl,
                fnd_responsibility r,
                fnd_responsibility_tl rtl,
                fnd_user_resp_groups urg,
                fnd_user u
          WHERE cmf.function_id = ff.function_id
            AND r.menu_id = cmf.menu_id
            AND urg.responsibility_id = r.responsibility_id
            AND rtl.responsibility_id = r.responsibility_id
            AND cmf.grant_flag = 'Y'
            AND r.application_id = urg.responsibility_application_id
            AND u.user_id = urg.user_id
            AND UPPER (ffl.user_function_name) = UPPER ('Returns')   --CES DEU1 Purchasing Plant Super User
            AND FF.FUNCTION_ID = FFL.FUNCTION_ID
       ORDER BY u.user_name;

 
-- -----------------------------------------------------------------------------------
-- Query to get all fuctions attached to responsibilities
-- -----------------------------------------------------------------------------------


SELECT DISTINCT faa.application_name application, rtl.responsibility_name,
ffl.user_function_name, ff.function_name, ffl.description,
ff.TYPE
FROM fnd_compiled_menu_functions cmf,
fnd_form_functions ff,
fnd_form_functions_tl ffl,
fnd_responsibility r,
fnd_responsibility_vl rtl,
apps.fnd_application_all_view faa
WHERE cmf.function_id = ff.function_id
AND r.menu_id = cmf.menu_id
AND rtl.responsibility_id = r.responsibility_id
AND cmf.grant_flag = 'Y'
AND ff.function_id = ffl.function_id
AND faa.application_id(+) = r.application_id
AND r.end_date IS NULL
AND rtl.end_date IS NULL
ORDER BY rtl.responsibility_name;

-- -----------------------------------------------------------------------------------
-- Following are the FND_PROFILE values that can be used in the PL/SQL code:
-- -----------------------------------------------------------------------------------

   fnd_profile.value('PROFILEOPTION');
   fnd_profile.value('MFG_ORGANIZATION_ID');
   fnd_profile.value('ORG_ID');
   fnd_profile.value('LOGIN_ID');
   fnd_profile.value('USER_ID');
   fnd_profile.value('USERNAME');
   fnd_profile.value('CONCURRENT_REQUEST_ID');
   fnd_profile.value('GL_SET_OF_BKS_ID');
   fnd_profile.value('SO_ORGANIZATION_ID');
   fnd_profile.value('APPL_SHRT_NAME');
   fnd_profile.value('RESP_NAME');
   fnd_profile.value('RESP_ID');

Following are the FND_GLOBAL values that can be used in the PL/SQL code:

   FND_GLOBAL.USER_ID;
   FND_GLOBAL.APPS_INTIALIZE;
   FND_GLOBAL.LOGIN_ID;
   FND_GLOBAL.CONC_LOGIN_ID;
   FND_GLOBAL.PROG_APPL_ID;
   FND_GLOBAL.CONC_PROGRAM_ID;
   FND_GLOBAL.CONC_REQUEST_ID;
 
 -- -----------------------------------------------------------------------------------
 -- AOL Defeinitions
 -- -----------------------------------------------------------------------------------

--CONCURRENT_PROGRAM_NAME
SELECT USER_CONCURRENT_PROGRAM_NAME
FROM FND_CONCURRENT_PROGRAMS_TL
WHERE LANGUAGE = 'US'
AND APPLICATION_ID = 50001
ORDER BY USER_CONCURRENT_PROGRAM_NAME;

--FORM
SELECT USER_FORM_NAME , FORM_NAME
FROM FND_FORM_VL
WHERE APPLICATION_ID = 50001
ORDER BY 1,2;

--FORM FUNCTIONS
SELECT USER_FUNCTION_NAME
FROM FND_FORM_FUNCTIONS_VL
WHERE FORM_ID IN (SELECT FORM_ID
                  FROM FND_FORM_VL
                  WHERE APPLICATION_ID = 50001)
ORDER BY 1;

--LOOKUP
SELECT DISTINCT LOOKUP_TYPE
FROM FND_LOOKUP_VALUES_VL
WHERE LOOKUP_TYPE LIKE 'XX%'
ORDER BY LOOKUP_TYPE;

SELECT LOOKUP_TYPE,LOOKUP_CODE
FROM FND_LOOKUP_VALUES_VL
WHERE LOOKUP_TYPE LIKE 'XX%'
AND ENABLED_FLAG = 'Y'
ORDER BY LOOKUP_TYPE,LOOKUP_CODE;

--REQUEST GROUPS
SELECT fr.REQUEST_GROUP_NAME,fp.USER_CONCURRENT_PROGRAM_NAME
FROM FND_REQUEST_GROUPS fr
    , FND_REQUEST_GROUP_UNITS fru
    , FND_CONCURRENT_PROGRAMS_TL fp
WHERE fr.REQUEST_GROUP_ID  = fru.REQUEST_GROUP_ID
AND fru.REQUEST_UNIT_ID = fp.CONCURRENT_PROGRAM_ID
AND fp.LANGUAGE = 'US'
AND fru.REQUEST_UNIT_TYPE = 'P'
AND  fr.APPLICATION_ID = 50001
UNION
SELECT fr.REQUEST_GROUP_NAME,frs.USER_REQUEST_SET_NAME
FROM FND_REQUEST_GROUPS fr
    , FND_REQUEST_GROUP_UNITS fru
    , FND_REQUEST_SETS_TL frs
WHERE fr.REQUEST_GROUP_ID  = fru.REQUEST_GROUP_ID
AND fru.REQUEST_UNIT_ID = frs.REQUEST_SET_ID
AND frs.LANGUAGE = 'US'
AND fru.REQUEST_UNIT_TYPE = 'S'
AND  fr.APPLICATION_ID = 50001
ORDER BY 1,2;

--MENUS--
SELECT fm.MENU_NAME , PROMPT
     , (CASE WHEN SUB_MENU_ID IS NOT NULL THEN (SELECT MENU_NAME
                                                FROM FND_MENUS
                                                WHERE MENU_ID = fmv.SUB_MENU_ID )
             WHEN fmv.FUNCTION_ID IS NOT NULL THEN (SELECT USER_FUNCTION_NAME
                                                 FROM FND_FORM_FUNCTIONS_TL f
                                                 WHERE f.FUNCTION_ID = fmv.FUNCTION_ID
                                                 AND f.LANGUAGE = 'US')
             END) MENU_FUNCTION
FROM FND_MENU_ENTRIES_VL fmv
  , FND_MENUS fm
WHERE fm.MENU_ID = fmv.MENU_ID
AND fm.MENU_NAME LIKE 'XX%'


-- --------------------------------------------------------------------------------------------
-- Form Personalization query
-- --------------------------------------------------------------------------------------------

Select Distinct
    A.Id,
    A.Form_Name ,
    A.Enabled,
    C.User_Form_Name,
    D.Application_Name ,
    A.Description,
    Ca.Action_Type,
    Ca.Enabled,
    Ca.Object_Type,
    ca.message_type,
    ca.message_text
from
    FND_FORM_CUSTOM_RULES a,
    FND_FORM b,
    FND_FORM_TL c,
    Fnd_Application_Tl D,
    Fnd_Form_Custom_Actions ca
where a.form_name = b.form_name
    And B.Form_Id = C.Form_Id
    And B.Application_Id = D.Application_Id
    --And D.Application_Id = 230 --For Order Management
    And C.User_Form_Name Like 'Inventory%'  --All the Forms that Start with Sales
    And A.Enabled ='Y'
    and a.id = ca.rule_id
--------------------------------------------------------------------------------------------
select ffv.form_id , ffv.form_name, ffv.user_form_name, ffv.description, ffcr.description, ffcr.sequence
from fnd_form_vl ffv,fnd_form_custom_rules ffcr
where ffv.form_name = ffcr.form_name
and ffcr.description like '%7663%';

-- -----------------------------------------------------------------------------------------
-- Template and its bursting path
-- -----------------------------------------------------------------------------------------
select
lt.application_short_name || '.' || lt.template_code || '.' || lt.default_language || '.' || lt.default_territory as burst_template_xdo_location
from
apps.xdo_templates_b lt
where lt.template_code ='XXAR0387'

-- -------------------------------------------------------------------------------------------
-- Query to Find Only Required fields in a particular DFF
-- -------------------------------------------------------------------------------------------

-- Query to Find All the fields in a particular DFF:-

SELECT ffv.descriptive_flexfield_name DFFName,
                 ffv.application_table_name TableName,
                 ffv.title Title,
                 ap.application_name Application,
                 att.column_seq_num SegmentNumber,
                 att.form_left_prompt SegmentName,
                 att.application_column_name,
                 fvs.flex_value_set_name ValueSet,
                 att.required_flag
            FROM apps.fnd_descriptive_flexs_vl ffv,
                 apps.fnd_descr_flex_contexts_vl ffc,
                 apps.fnd_descr_flex_col_usage_vl att,
                 apps.fnd_flex_value_sets fvs,
                 apps.fnd_application_vl ap
           WHERE     ffv.descriptive_flexfield_name =
                        att.descriptive_flexfield_name
                 AND ap.application_id = ffv.application_id
                 AND ffv.descriptive_flexfield_name =
                        ffc.descriptive_flexfield_name
                 AND ffv.application_id = ffc.application_id
                 AND ffc.descriptive_flex_context_code =
                        att.descriptive_flex_context_code
                 AND fvs.flex_value_set_id = att.flex_value_set_id
                 AND ffv.title IN ('Invoice Line Information')
        ORDER BY ffv.title;

-- Query to Find Only Required fields in a particular DFF

SELECT *
  FROM (  SELECT ffv.descriptive_flexfield_name DFFName,
                 ffv.application_table_name TableName,
                 ffv.title Title,
                 ap.application_name Application,
                 att.column_seq_num SegmentNumber,
                 att.form_left_prompt SegmentName,
                 att.application_column_name,
                 fvs.flex_value_set_name ValueSet,
                 att.required_flag
            FROM apps.fnd_descriptive_flexs_vl ffv,
                 apps.fnd_descr_flex_contexts_vl ffc,
                 apps.fnd_descr_flex_col_usage_vl att,
                 apps.fnd_flex_value_sets fvs,
                 apps.fnd_application_vl ap
           WHERE     ffv.descriptive_flexfield_name =
                        att.descriptive_flexfield_name
                 AND ap.application_id = ffv.application_id
                 AND ffv.descriptive_flexfield_name =
                        ffc.descriptive_flexfield_name
                 AND ffv.application_id = ffc.application_id
                 AND ffc.descriptive_flex_context_code =
                        att.descriptive_flex_context_code
                 AND fvs.flex_value_set_id = att.flex_value_set_id
                 AND ffv.title IN ('Invoice Line Information')
        ORDER BY ffv.title)
 WHERE required_flag = 'Y';

-- --------------------------------------------------------------------------------------
-- Request id and its resp
-- --------------------------------------------------------------------------------------
select c.request_id, r.responsibility_name
from fnd_responsibility_vl r, fnd_concurrent_requests c
where c.request_id = 97131851
and c.responsibility_application_id = r.application_id
and c.responsibility_id = r.responsibility_id

OM Queries


-- ----------------------------------------------------------------------------------
-- Query to get Customer Related information for a Sales Order
-------------------------------------------------------------------------------------

SELECT ooh.order_number
     , hp_bill.party_name
     , hl_ship.address1 ||Decode(hl_ship.address2,NULL,'',chr(10))
      ||hl_ship.address2||Decode(hl_ship.address3,NULL,'',chr(10))
      ||hl_ship.address3||Decode(hl_ship.address4,NULL,'',chr(10))
      ||hl_ship.address4||Decode(hl_ship.city,NULL,'',chr(10))
      ||hl_ship.city    ||Decode(hl_ship.state,NULL,'',',')
      ||hl_ship.state   ||Decode(hl_ship.postal_code,'',',')
      ||hl_ship.postal_code ship_to_address
     , hl_bill.address1 ||Decode(hl_bill.address2,NULL,'',chr(10))
      ||hl_bill.address2||Decode(hl_bill.address3,NULL,'',chr(10))
      ||hl_bill.address3||Decode(hl_bill.address4,NULL,'',chr(10))
      ||hl_bill.address4||Decode(hl_bill.city,NULL,'',chr(10))
      ||hl_bill.city    ||Decode(hl_bill.state,NULL,'',',')
      ||hl_bill.state   ||Decode(hl_bill.postal_code,'',',')
      ||hl_bill.postal_code bill_to_address
     , ooh.transactional_curr_code currency_code
     , mp.organization_code
     , ooh.fob_point_code
     , ooh.freight_terms_code
     , ooh.cust_po_number
,hcs_ship.site_use_id ship_to_location
, hcs_bill.site_use_id bill_to_location
FROM   oe_order_headers_all ooh
     , hz_cust_site_uses_all hcs_ship
     , hz_cust_acct_sites_all hca_ship
     , hz_party_sites hps_ship
     , hz_parties hp_ship
     , hz_locations hl_ship
     , hz_cust_site_uses_all hcs_bill
     , hz_cust_acct_sites_all hca_bill
     , hz_party_sites hps_bill
     , hz_parties hp_bill
     , hz_locations hl_bill
     , mtl_parameters mp
WHERE  1 = 1
AND    header_id =p_header_id
AND    ooh.ship_to_org_id = hcs_ship.site_use_id
AND    hcs_ship.cust_acct_site_id = hca_ship.cust_acct_site_id
AND    hca_ship.party_site_id = hps_ship.party_site_id
AND    hps_ship.party_id = hp_ship.party_id
AND    hps_ship.location_id = hl_ship.location_id
AND    ooh.invoice_to_org_id = hcs_bill.site_use_id
AND    hcs_bill.cust_acct_site_id = hca_bill.cust_acct_site_id
AND    hca_bill.party_site_id = hps_bill.party_site_id
AND    hps_bill.party_id = hp_bill.party_id
AND    hps_bill.location_id = hl_bill.location_id
AND    mp.organization_id(+) = ooh.ship_from_org_id;

-- ----------------------------------------------------------------------------------
-- Query for get RMA order details
-------------------------------------------------------------------------------------

SELECT ooha.ORDER_NUMBER "SALES ORDER"
              ,ooha.ORDER_CATEGORY_CODE
              ,oola.ORDERED_ITEM
              ,oola.SUBINVENTORY
              ,rsh.SHIPMENT_NUM
              ,rsh.RECEIPT_NUM
              ,rsh.CUSTOMER_ID
              ,rsl.UNIT_OF_MEASURE
              ,rsl.ITEM_DESCRIPTION
              ,rsl.SHIPMENT_LINE_STATUS_CODE
              ,rsl.SOURCE_DOCUMENT_CODE
FROM OE_ORDER_HEADERS_ALL ooha
           ,OE_ORDER_LINES_ALL oola
           ,RCV_SHIPMENT_HEADERS rsh
           ,RCV_SHIPMENT_LINES rsl
WHERE  1=1
AND ooha.header_id                                = oola.header_id
AND ooha.header_id                                = rsl.OE_ORDER_HEADER_ID
AND rsh.shipment_header_id                  = rsl.shipment_header_id
AND rsl.OE_ORDER_LINE_ID                = oola.line_id
--AND ooha.ORDER_NUMBER                 = '56'
AND rsl.SOURCE_DOCUMENT_CODE = 'RMA'

-- -------------------------------------------------------------------------------------
-- Query to get open sales order details
-- -------------------------------------------------------------------------------------

select
LEGACY_SO_NUM,
CUSTOMER_NAME,
 CUSTOMER_NO,
 BILL_TO_LOCATION,
 SHIP_TO_LOCATION,
 ORDER_TYPE,
 CUST_PO_NUMBER,
 ORDERED_DATE,
PRICE_LIST,
PAYMENT_TERMS,
ORGANIZATION_NAME,
VERIFY_FLAG,
PRICING_DATE        ,
REQUEST_DATE           ,
flow_status_code ,
ORDER_CATEGORY           ,
RETURN_REASON_CODE      ,
SALESREP               ,
PACKING_INSTRUCTIONS   ,
DROP_SHIP_FLAG        ,
ORDER_DATE_TYPE_CODE   ,
ORG_ID,
SHIPPING_METHOD_CODE,
SHIPPING_INSTRUCTIONS,
FREIGHT_CARRIER_CODE
from (
SELECT distinct null  RECORD_ID,
 h.order_number legacy_so_num ,
        (select party_name from hz_parties
        where party_id = (select party_id from hz_cust_accounts where account_number =  cust_acct.account_number) )customer_name ,
        cust_acct.account_number customer_no,
        bill_su.location BILL_TO_LOCATION,
  ship_su.location SHIP_TO_LOCATION,
ot.name ORDER_TYPE ,
cust_po_number  ,
ordered_date  ,
(select name from qp_list_headers_v where list_header_id = h.PRICE_LIST_ID) price_list ,
(select NAME
from ra_terms_tl where LANGUAGE = 'US' and TERM_ID = h.payment_term_id)payment_terms ,
nvl ((select organization_name 
from org_organization_definitions  where ORGANIZATION_ID =  h.ship_from_org_id ),
(select o.organization_name 
from org_organization_definitionso , oe_order_lines_alll
  where o.ORGANIZATION_ID =  l.ship_from_org_id
  and  l.header_id = h.header_id
  and rownum < 2)
) ORGANIZATION_NAME ,
null verify_flag,
h.PRICING_DATE        ,
h.REQUEST_DATE           ,
h.flow_status_code ,
h.ORDER_CATEGORY_CODE ORDER_CATEGORY           ,
h.RETURN_REASON_CODE      ,
--(select distinct name from ra_salesreps_all where SALESREP_ID = h.SALESREP_ID )  SALESREP ,
(select b.RESOURCE_NAME from ra_salesreps_all  a ,
JTF_RS_DEFRESOURCES_V b
where a.RESOURCE_ID = b.RESOURCE_ID
and a.salesrep_id = h.SALESREP_ID
and rownum < 2) SALESREP,
PACKING_INSTRUCTIONS   ,
DROP_SHIP_FLAG        ,
ORDER_DATE_TYPE_CODE   ,
h.org_id,
h.SHIPPING_METHOD_CODE,
h.SHIPPING_INSTRUCTIONS,
h.FREIGHT_CARRIER_CODE       
          FROM hz_cust_site_uses_all ship_su,
               hz_cust_site_uses_all bill_su,
               hz_cust_acct_sites_all  hcasa,
               hz_cust_accounts cust_acct,
               hz_party_sites  hps,
               hz_locations  hl,
               oe_order_headers_all h,
               oe_transaction_types_tl ot
         WHERE     h.order_type_id = ot.transaction_type_id
               AND ot.language = USERENV ('LANG')
                and hcasa.party_site_id = hps.party_site_id
                and hcasa.cust_acct_site_id = bill_su.cust_acct_site_id
                AND hl.location_id = hps.location_id
               AND h.sold_to_org_id = cust_acct.cust_account_id(+)
               AND h.ship_to_org_id = ship_su.site_use_id(+)
               AND h.invoice_to_org_id = bill_su.site_use_id(+)
                and upper (ot.name) not like '%INTERNAL%'
                and ot.language  ='US'
                          --  and h.org_id in ()
         --  and h.order_number  in( '11699')
            AND  h.FLOW_STATUS_CODE NOT IN ('CLOSED', 'CANCELLED' ) 
   )
 
 
 -- -----------------------------------------------------------------------------------------------------
 --  find delivery leg AND pick up STOP info
 -- -----------------------------------------------------------------------------------------------------

 SELECT wt.trip_id, wt.NAME, wt.status_code, wt.vehicle_item_id,
wt.vehicle_number, wt.carrier_id, wt.ship_method_code, wts.stop_id,
wts.stop_location_id, wts.status_code, wts.stop_sequence_number,
wts.planned_arrival_date, wts.planned_departure_date,
wts.actual_arrival_date, wts.actual_departure_date,
wts.departure_net_weight, wts.weight_uom_code, wdl.delivery_leg_id,
wdl.delivery_id, wdl.pick_up_stop_id, wdl.drop_off_stop_id,
wdl.sequence_number, wdl.loading_order_flag, wdl.shipper_title,
wdl.shipper_phone
FROM wsh_trips wt, wsh_trip_stops wts, wsh_delivery_legs wdl
WHERE wdl.delivery_id = '189560'
AND
 wts.stop_id = wdl.pick_up_stop_id
AND wts.trip_id = wt.trip_id;

-- ---------------------------------------------------------------------------------------------------------
-- Query to get current onhand quantity of inventory Items.
-- ---------------------------------------------------------------------------------------------------------

SELECT ALL mtl.organization_id, orgs.NAME organization_name,
           mtl.inventory_item_id, mtl.segment1 item_number,
           mtl.description item_description, mtl.item_type,
           mtl.inventory_item_status_code, mtl.primary_uom_code,
           mtl.secondary_uom_code,
-- get current onhand
                      (  TO_NUMBER ((SELECT SUM (NVL (motv.on_hand, 0))
                            FROM apps.mtl_onhand_total_v motv
                           WHERE mtl.inventory_item_id =
                                                        motv.inventory_item_id
                             AND mtl.organization_id = motv.organization_id)
                        )
            + NVL ((SELECT -1 * SUM (NVL (primary_quantity, 0))
                                 FROM   mtl_material_transactions mmt
                     WHERE mmt.inventory_item_id = mtl.inventory_item_id
                       AND mmt.organization_id = mtl.organization_id
                       AND mmt.costed_flag IN ('N', 'E')
                       AND mmt.transaction_action_id NOT IN
                                                     (24, 40, 41, 50, 51, 52)
                       AND NVL (mmt.owning_tp_type, 2) = 2
                       AND mmt.organization_id =
                              NVL (mmt.owning_organization_id,
                                   mmt.organization_id
                                  )
                       AND NVL (mmt.logical_transaction, -1) <> 1),
                   0
                  )
           ) current_onhand  ,
           TO_NUMBER (NVL ((SELECT SUM (cict.item_cost)
                              FROM apps.cst_item_cost_type_v cict
                             WHERE mtl.inventory_item_id = cict.inventory_item_id(+)
                               AND mtl.organization_id = cict.organization_id(+)
                               AND cict.cost_type = 'Frozen'),
                           0
                          )
                     ) current_cost,
           DECODE (mtl.planning_make_buy_code,
                   2, 'Buy',
                   1, 'Make',
                   'Other'
                  ) make_buy_code,
           (SELECT organization_code
              FROM org_organization_definitions ood
             WHERE orgs.organization_id =
                                        ood.organization_id)
                                                            organization_code
      FROM apps.mtl_system_items_b mtl,
           apps.hr_all_organization_units orgs,
           apps.mtl_item_categories_v cat
     WHERE orgs.organization_id = mtl.organization_id
       AND (    mtl.inventory_item_id = cat.inventory_item_id(+)
            AND mtl.organization_id = cat.organization_id(+)
            AND cat.category_set_id = 1
           )
       AND (SELECT SUM (motv.on_hand)
              FROM apps.mtl_onhand_total_v motv
             WHERE mtl.inventory_item_id = motv.inventory_item_id
               AND mtl.organization_id = motv.organization_id) > 0;