CREATE OR REPLACE PACKAGE A07_REPLENISHMENT_INT AUTHID CURRENT_USER AS
/******************************************************************************
   NAME:       A07_REPLENISH_INTERFACE
   PURPOSE:    Item Replenishment Interface.

   PARAMETERS:
   INPUT:
   OUTPUT:
   RETURNED VALUE:
   CALLED BY:
   CALLS:
   EXAMPLE USE:     NUMBER := A07_REPLENISH_INTERFACE.MyFuncName(Number);
                    A07_REPLENISH_INTERFACE.MyProcName(Number, Varchar2);
   ASSUMPTIONS:+
   LIMITATIONS:
   ALGORITHM:
   NOTES:
******************************************************************************/
— All the Global Variables to be used in this package
      g_create_dt       date   := sysdate;
      g_create_by       number := 10005218;
      g_update_dt       date   := sysdate;
      g_update_by       number := 10005218;
      v_sqlcode         number;
      v_sqlerrm         varchar2(255);
— All Global Variables specific to the package
— All the Functions used in this package
   Function CHK_ORG_EXISTS (org_id mtl_parameters.organization_id%type) return boolean;
   Function CHK_ITEM_EXISTS (item_id mtl_system_items_b.inventory_item_id%type,
                                     v_org_id mtl_system_items_b.organization_id%type) return boolean;
   Function CHK_ITEM_SUBINV (v_item_id number, v_subinv varchar2, v_org_id number) return boolean;
   Function GET_ITEM_PLAN (v_org_id number, v_item_id number, v_subinv varchar2) return number;
   Function GET_ITEM_UOM (v_org_id number, v_item_id number) return varchar2;
— All the Procedures used in this package
   Procedure Validate_Organization;
   Procedure Validate_Item;
   Procedure Validate_Item_SubInv;
   Procedure Validate_Plan_Method;
   Procedure Validate_Uom;
   Procedure Validate ;
   Procedure Populate_Interface;
   Procedure Run (errcode out number, errbuf out varchar2);
END A07_REPLENISHMENT_INT;
/
CREATE OR REPLACE PACKAGE BODY A07_REPLENISHMENT_INT AS
Function CHK_ORG_EXISTS (org_id mtl_parameters.organization_id%type) return boolean
Is
   cnt number;
Begin
      Select count(*) into cnt
      From hr_all_organization_units
      where organization_id = org_id;
      if cnt <> 0
      then
         return true;
      Else
         return false;
      End if;
End;
Function CHK_ITEM_EXISTS (item_id mtl_system_items_b.inventory_item_id%type,
                                     v_org_id mtl_system_items_b.organization_id%type) return boolean
Is
    cnt     number;
Begin
      Select count(*) into cnt
      From mtl_system_items_b
      Where inventory_item_id = item_id
      And   organization_id = v_org_id;
      if cnt <> 0
      then
         return true;
      else
         return false;
      end if;
End;
Function CHK_ITEM_SUBINV (v_item_id number, v_subinv varchar2, v_org_id number) return boolean
Is
      cnt number;
Begin
      Select count(*) into cnt
      From mtl_item_sub_inventories
      Where inventory_item_id = v_item_id
      and  secondary_inventory = v_subinv
      and organization_id = v_org_id;
      if cnt <> 0
      then
         return true;
      else
         return false;
      end if;
End;
Function GET_ITEM_PLAN (v_org_id number, v_item_id number, v_subinv varchar2) return number
Is
      ipm number;
Begin
      Select inventory_planning_code into ipm
      From mtl_item_sub_inventories
      Where inventory_item_id = v_item_id
      And   organization_id = v_org_id
      And   secondary_inventory = v_subinv;
      Return ipm;
Exception
      When NO_DATA_FOUND then
             return 2;
      When OTHERS then
             return 1;
End;
Function GET_ITEM_UOM (v_org_id number, v_item_id number) return varchar2
is
      uom varchar2(3);
Begin
      Select primary_uom_code into uom
      From mtl_system_items_b
      Where organization_id = v_org_id
      And inventory_item_id = v_item_id;
      Return uom;
Exception
      When NO_DATA_FOUND then
             return NULL;
      When OTHERS then
             return NULL;
End;
Procedure Validate_Organization
As
      Cursor c_org is Select distinct organization_id from A07_replenish_interface;
      v_org  c_org%rowtype;
Begin
      Open c_org;
      Loop
             Fetch c_org into v_org;
             Exit when c_org%NOTFOUND;
             Begin
                  If chk_org_exists(v_org.organization_id)
                  then
                     null;
                  Else
                     Update A07_replenish_interface
                     Set error_flag = 1,
                          error_description = ‘Organization does not exist’
                     Where organization_id = v_org.organization_id;
                End If;
             Exception
                        When OTHERS then
                               v_sqlcode := sqlcode;
                               v_sqlerrm := sqlerrm;
                               Rollback;
                               update A07_replenish_interface
                               Set error_flag = v_sqlcode,
                                     error_description = v_sqlerrm
                               where organization_id = v_org.organization_id;
             End;
      End Loop;
      Close c_org;
      Commit;
      fnd_file.put_line(FND_FILE.OUTPUT,‘Validate Organization completed successfully’);
Exception
      When OTHERS then
             v_sqlcode := sqlcode;
             v_sqlerrm := sqlerrm;
             Rollback;
             fnd_file.put_line(FND_FILE.LOG,‘In the process : Validate Organization’);
             fnd_file.put_line(FND_FILE.LOG,‘Error Code is ‘ || v_sqlcode);
             fnd_file.put_line(FND_FILE.LOG,‘Error Mesg is ‘ || v_sqlerrm);
End Validate_Organization;
Procedure Validate_Item
As
      Cursor c_item is Select inventory_item_id, organization_id from A07_replenish_interface
                               Where error_flag is null;
      v_item c_item%rowtype;
Begin
    Open c_item;
      Loop
             Fetch c_item into v_item;
             Exit when c_item%NOTFOUND;
             Begin
                  If chk_item_exists(v_item.inventory_item_id, v_item.organization_id)
                then
                     null;
                  else
                     Update A07_replenish_interface
                     Set error_flag = 2,
                           error_description = ‘Item does not exist’
                     Where organization_id = v_item.organization_id
                     And   inventory_item_id = v_item.inventory_item_id;
                  End If;
             Exception
                        When OTHERS then
                               v_sqlcode := sqlcode;
                               v_sqlerrm := sqlerrm;
                               Rollback;
                               update A07_replenish_interface
                               Set error_flag = v_sqlcode,
                                     error_description = v_sqlerrm
                               Where organization_id = v_item.organization_id
                               And   inventory_item_id = v_item.inventory_item_id;
             End;
      End Loop;
      Close c_item;
      Commit;
      fnd_file.put_line(FND_FILE.OUTPUT,‘Validate Item completed successfully’);
Exception
      When OTHERS then
             v_sqlcode := sqlcode;
             v_sqlerrm := sqlerrm;
             Rollback;
             fnd_file.put_line(FND_FILE.LOG,‘In the process : Validate Item’);
             fnd_file.put_line(FND_FILE.LOG,‘Error Code is ‘ || v_sqlcode);
             fnd_file.put_line(FND_FILE.LOG,‘Error Mesg is ‘ || v_sqlerrm);
End Validate_Item;
Procedure Validate_Item_SubInv
As
      Cursor c_item is Select inventory_item_id, subinventory_code,organization_id
                               from A07_replenish_interface
                               Where error_flag is null;
      v_item c_item%rowtype;
Begin
    Open c_item;
      Loop
             Fetch c_item into v_item;
             Exit when c_item%NOTFOUND;
             Begin
                  If chk_item_subinv(v_item.inventory_item_id,v_item.subinventory_code,v_item.organization_id)
                then
                     null;
                  else
                     Update A07_replenish_interface
                     Set error_flag = 2,
                           error_description = ‘Item does not exist in suninventory’
                     Where organization_id = v_item.organization_id
                     And   inventory_item_id = v_item.inventory_item_id
                     And   subinventory_code = v_item.subinventory_code;
                  End If;
             Exception
                        When OTHERS then
                               v_sqlcode := sqlcode;
                               v_sqlerrm := sqlerrm;
                               Rollback;
                               update A07_replenish_interface
                               Set error_flag = v_sqlcode,
                                     error_description = v_sqlerrm
                               Where organization_id = v_item.organization_id
                               And   inventory_item_id = v_item.inventory_item_id
                             And   subinventory_code = v_item.subinventory_code;
             End;
      End Loop;
      Close c_item;
      Commit;
      fnd_file.put_line(FND_FILE.OUTPUT,‘Validate Item completed successfully’);
Exception
      When OTHERS then
             v_sqlcode := sqlcode;
             v_sqlerrm := sqlerrm;
             Rollback;
             fnd_file.put_line(FND_FILE.LOG,‘In the process : Validate Item’);
             fnd_file.put_line(FND_FILE.LOG,‘Error Code is ‘ || v_sqlcode);
             fnd_file.put_line(FND_FILE.LOG,‘Error Mesg is ‘ || v_sqlerrm);
End Validate_Item_SubInv;
Procedure Validate_Plan_Method
As
      Cursor c_plan is Select organization_id, inventory_item_id, subinventory_code, count_method
                               from A07_replenish_interface
                               Where error_flag is null;
      v_plan c_plan%rowtype;
      ipm number;
Begin
      Open c_plan;
      Loop
             Fetch c_plan into v_plan;
             Exit when c_plan%NOTFOUND;
             ipm := get_item_plan(v_plan.organization_id, v_plan.inventory_item_id,v_plan.subinventory_code);
             Begin
                  If ipm = 1
                then
                        if v_plan.count_method != 2
                        then
                          Update A07_replenish_interface
                          Set error_flag = 3,
                                error_description = ‘Planning method and Counting Method mismatch’
                          Where organization_id = v_plan.organization_id
                          And   inventory_item_id = v_plan.inventory_item_id
                          and  subinventory_code = v_plan.subinventory_code;
                        end if;
                  Elsif ipm = 2 then
                        if v_plan.count_method != 3
                        then
                          Update A07_replenish_interface
                          Set error_flag = 3,
                                error_description = ‘Planning method and Counting Method mismatch’
                          Where organization_id = v_plan.organization_id
                          And   inventory_item_id = v_plan.inventory_item_id
                          and  subinventory_code = v_plan.subinventory_code;
                        end if;
                  Elsif ipm = 6 then
                        if v_plan.count_method != 1
                        then
                          Update A07_replenish_interface
                          Set error_flag = 3,
                                error_description = ‘Planning method and Counting Method mismatch’
                          Where organization_id = v_plan.organization_id
                          And   inventory_item_id = v_plan.inventory_item_id
                          and  subinventory_code = v_plan.subinventory_code;
                        end if;
                  Else
                          null;
                  End If;
             Exception
                        When OTHERS then
                               v_sqlcode := sqlcode;
                               v_sqlerrm := sqlerrm;
                               Rollback;
                               update A07_replenish_interface
                               Set error_flag = v_sqlcode,
                                     error_description = v_sqlerrm
                               Where organization_id = v_plan.organization_id
                             And   inventory_item_id = v_plan.inventory_item_id
                             And   subinventory_code = v_plan.subinventory_code;
             End;
      End Loop;
      Close c_plan;
      Commit;
      fnd_file.put_line(FND_FILE.OUTPUT,‘Validate Plan Method completed successfully’);
Exception
      When OTHERS then
             v_sqlcode := sqlcode;
             v_sqlerrm := sqlerrm;
             Rollback;
             fnd_file.put_line(FND_FILE.LOG,‘In the process : Validate Plan Method’);
             fnd_file.put_line(FND_FILE.LOG,‘Error Code is ‘ || v_sqlcode);
             fnd_file.put_line(FND_FILE.LOG,‘Error Mesg is ‘ || v_sqlerrm);
End Validate_Plan_Method;
Procedure Validate_UOM
As
      Cursor c_uom is Select distinct inventory_item_id, organization_id
                               from A07_replenish_interface
                               Where error_flag is null;
      v_plan  c_uom%rowtype;
      uom varchar2(3);
Begin
      Open c_uom;
      Loop
             Fetch c_uom into v_plan;
             Exit when c_uom%NOTFOUND;
             uom := get_item_uom(v_plan.organization_id, v_plan.inventory_item_id);
             Begin
                  If uom is NULL
                then
                          Update A07_replenish_interface
                          Set error_flag = 4,
                                error_description = ‘UOM not found’
                          Where organization_id = v_plan.organization_id
                          And   inventory_item_id = v_plan.inventory_item_id;
                  Else
                          Update A07_replenish_interface
                          Set    UOM_CODE = uom
                          Where organization_id = v_plan.organization_id
                          And   inventory_item_id = v_plan.inventory_item_id;
                  End If;
             Exception
                        When OTHERS then
                               v_sqlcode := sqlcode;
                               v_sqlerrm := sqlerrm;
                               Rollback;
                               update A07_replenish_interface
                               Set error_flag = v_sqlcode,
                                     error_description = v_sqlerrm
                               Where organization_id = v_plan.organization_id
                             And   inventory_item_id = v_plan.inventory_item_id;
             End;
      End Loop;
      Close c_uom;
      Commit;
      fnd_file.put_line(FND_FILE.OUTPUT,‘Validate Plan Method completed successfully’);
Exception
      When OTHERS then
             v_sqlcode := sqlcode;
             v_sqlerrm := sqlerrm;
             Rollback;
             fnd_file.put_line(FND_FILE.LOG,‘In the process : Validate Plan Method’);
             fnd_file.put_line(FND_FILE.LOG,‘Error Code is ‘ || v_sqlcode);
             fnd_file.put_line(FND_FILE.LOG,‘Error Mesg is ‘ || v_sqlerrm);
End Validate_UOM;
Procedure Validate
As
Begin
   Update A07_replenish_interface
   Set error_flag = NULL, error_description = NULL;
— Update the organization_ids to the respective organization
   Validate_organization;
— Check if the items exist for the given organization in MTL_SYSTEM_ITEMS_B
   Validate_item;
— Check if the organization costing method and the item costing method are same.
   Validate_Plan_Method;
— Check if the item is existing in the subinventory
   Validate_Item_SubInv;
— To Check if the item cost already exists in the CST_ITEM_COSTS
   Validate_UOM;
   Update A07_replenish_interface
   Set error_flag = 0, error_description = ‘Clean Data’
   Where error_flag is null;
   Commit;
   fnd_file.put_line(FND_FILE.OUTPUT,‘Validate Interface completed successfully’);
Exception
      When OTHERS then
             v_sqlcode := sqlcode;
             v_sqlerrm := sqlerrm;
             Rollback;
             fnd_file.put_line(FND_FILE.LOG,‘In the process : Validate Interface’);
             fnd_file.put_line(FND_FILE.LOG,‘Error Code is ‘ || v_sqlcode);
             fnd_file.put_line(FND_FILE.LOG,‘Error Mesg is ‘ || v_sqlerrm);
End Validate;
Procedure Populate_Interface
As
    CURSOR C1 IS    SELECT * FROM A07_REPLENISH_INTERFACE;
      Cursor c_hdr is Select distinct organization_id, subinventory_code, count_date
                              from A07_replenish_interface
                              where error_flag = 0;
      Cursor c_lines (org_id in number,subinv_code in varchar2) is
                           Select inventory_item_id, organization_id
                           from A07_replenish_interface
                              where error_flag = 0;
      h_id           number;
      l_id           number;
      h_name               varchar2(15);
    V_HDR          C_HDR%ROWTYPE;
Begin
      Open c_hdr;
      Loop <<OUTER>>
             Fetch c_hdr into v_hdr;
             Exit when c_hdr%NOTFOUND;
             Select mtl_replenish_headers_s.nextval into h_id from dual;
             h_name     := ‘SRT’ || h_id ;
    END LOOP;  
        
     
       FOR REC IN C1
             LOOP
             Insert into mtl_replenish_headers_int
             ( REPLENISHMENT_HEADER_ID,REPLENISHMENT_COUNT_NAME,COUNT_DATE, LAST_UPDATE_DATE,CREATION_DATE,
             CREATED_BY ,LAST_UPDATED_BY,ORGANIZATION_ID,SUBINVENTORY_CODE, PROCESS_STATUS,PROCESS_MODE  )
             Values
             (REC.REPLENISHMENT_HEADER_ID,REC.REPLENISHMENT_COUNT_NAME,REC.COUNT_DATE,REC.LAST_UPDATE_DATE,REC.CREATION_DATE,
             REC.CREATED_BY,REC.LAST_UPDATED_BY,REC.ORGANIZATION_ID,REC.SUBINVENTORY_CODE,REC.PROCESS_STATUS,REC.PROCESS_MODE);
             END LOOP;
END;
END A07_REPLENISHMENT_INT;
Oracle WorkFlow Interview Questions ?

1. How to find the latest version of a current workflow process, and how to revert to the old version of workflow

2. Name five very important base tables of oracle workflow and their significance.

3. Name five oracle workflow apis and their significance and use

4. How would you clear stuck or deferred workflows and what is meant by a deferred workflow

5. What is the difference between workflow wait activity and block activity, what is the api which is used in this regard to put a wait and to put a block.

6. How would you continue the workflow which is in wait and which is in block mode, name the api which is responsible for that

7. What is access level in oracle workflow and how it is significant.

8. Apart from loading the workflow from workflow builder is there any other method of loading the workflow from database to local machine.

9. How many types of attributes are present in workflow and what is a document type attribute

10. How would you force a user to not re-assign the workflow to other user.

What is Flexfield?
A flexfield is a field made up of segments. A flex field is a flexible data field that your organization can customize to your business needs without programming. Oracle Applications uses two types of flexfields, key flexfields and descriptive flexfields.
What is a Set of Books (SOB)?
Set of Books is a financial entity that shares a common Chart of Accounts, Functional Currency and Accounting Calendar (3Cs).
What is Segment?
A segment is a single sub–field within a flexfield. You define the appearance and meaning of individual segments when customizing a flexfield. A segment is represented in your database as a single table column.
What is a Value Set?
The flexfield validates each segment against a set of valid values that are usually predefined are called Value Sets.
What is Cross Validation?
A cross-validation rule defines whether a value of a particular segment can be combined with specific values of other segments
What are the different types of tables in Oracle 11i Apps?
B – The Main base tables
_ALL – Contains multi-org data
_V – View created on base table
_TL – Table that supports multi language
_VL – View created on multi language tables
_F – Data tracking tables. Used in HRMS
_S – Sequence related table
_DFV / _KFV – The DFF/KFF table created on the base table
What is the difference between Request Group and Request Set?
A request group is a collection of reports or concurrent programs.  A System Administrator defines report groups in order to control user access to reports and concurrent programs.  Only a System Administrator can create a request group.
Request sets define run and print options, and possibly, parameter values, for a collection of reports or concurrent program. End users and System Administrators can define request sets. A System Administrator has request set privileges beyond those of an end user. 
What are different types of validations of Value Sets?
None (not validated at all)
Independent
Dependent
Table
Special (advanced)
Pair (advanced)
Can you change the validation type of the existing Value set?
No.
What are the validation types supported by Accounting Flexfield?
Dependent, Independent, Table

What is the difference between Discrete Manufacturing and Process Manufacturing?
Discrete manufacturing is a manufacturing process where distinct products are built or manufactured in discrete batches on manufacturing floor. The resulting product is what you can count. It uses Bills of Materials (BOMs) and assembles along a routing.
Eg: Computer Manufacturing, Machinery Manufacturing, Automobiles, etc
Process manufacturing is a manufacturing process in which the end product manufactured are undifferentiated. It uses formulations or recipes and blends in a batch.
Eg: Pharmaceutical, Food and beverages, Refineries, etc
What are Shared Entities in Oracle 11i Apps?
Shared entities enable one-time definition of object and are accessed by several products/Modules.
Few shared entities and the owned applications are
Set of Books – General Ledger
Items – Inventory
Unit of Measure – Inventory
Suppliers – Purchasing
Customers – Receivables
Locations – Human Resource
Employee – Human Resource
Organization – Human Resource
How data are secured (partitioned) in Oracle 11i Applications?
General Ledger and Fixed Assets – Set of Books
Human Resource – Business Group
Order Management, Accounts Receivables, Accounts Payables, Purchasing, Cash Management, Projects, Service, Sales Compensation, Sales and Marketing – Operating Unit
Inventory, Manufacturing – Inventory Unit
There are 34 KFF’s available in Oracle 11i. They are as follows
S.No.
Flex Field
Owning Application
Maximum Segments
1
AHL Operation
Advanced Service Online
15
2
AHL Route
Advanced Service Online
15
3
Asset Key Flexfield
Assets
10
4
Category Flexfield
Assets
7
5
Location Flexfield
Assets
7
6
Group Asset
CRL Financials Assets
7
7
Super Group
CRL Financials Assets
7
8
Management Flexfield
Financials Intelligence
9
Accounting Flexfield
General Ledger
30
10
Reporting Attributes: Accounting
General Ledger
11
CAGR Flexfield
Human Resources
20
12
Competence Flexfield
Human Resources
30
13
Grade Flexfield
Human Resources
30
14
Item Contexts Key Flex
Human Resources
30
15
Job Flexfield
Human Resources
30
16
Personal Analysis Flexfield
Human Resources
30
17
Position Flexfield
Human Resources
30
18
Soft Coded Key Flexfield
Human Resources
30
19
Account Aliases
Inventory
20
20
Item Catalogs
Inventory
20
21
Item Categories
Inventory
20
22
ORACLE_SERVICE_ITEM_FLEXFIELD
Inventory
20
23
Sales Orders
Inventory
20
24
Stock Locators
Inventory
20
25
System Items
Inventory
20
26
Bank Details Key Flexfield
Payroll
30
27
Cost Allocation Flexfield
Payroll
30
28
People Group Flexfield
Payroll
30
29
PSB Position Flexfield
Public Sector Budgeting
30
30
ARTA-Receipt Prof Ident
Receivables
15
31
Sales Tax Location Flexfield
Receivables
10
32
Territory Flexfield
Receivables
20
33
Oracle Service Item Flexfield
Service
20
34
Training Resources
Training Administration
20
Lets take a case Food industry:

FG Foods Ltd. sell variety of Chicken which can have different weight. The superior quality of a chicken weighs to 4 Pound (on an average) but the deviation can be ±10%. This chicken is purchased on number basis and later it is sold on Number (Each) basis as well as on weight (Pound-Lbs) basis. So here Chicken is getting transacted based on two UOM and FG Foods want to track Qty on both UoM basis.
To satisfy this requirement we need to define an item which can be tracked on two UoM, define converser rate between these UoMs.

Item Definition:
UoM Conversion:
Also define Inter-class conversion that too item specific.
1 Unit = 4 Pound

Transactions:
Lets look at the transaction below, 100 Lbs comes to 25 chickens (as per tolerance), but if it goes beyond the tolerance then Oracle will not accept it.


In this case, based on tolerance defined it will accept values for secondary UoM ±2.5 (10% of 25).
So in below transactions one line is on –ve tolerance and other is on +ve tolerance.

On-hand and Availability:

Miscellaneous Issue:
Lets try doing issue transaction based on only Secondary UoM (Each). Oracle will automatically calculate quantity in other UoM based on the conversion rate.


On-hand Qty:
In above transaction, even though we did not give value in Lbs, Oracle deducted one chicken and 4 Pounds (refer the conversion).
51-1   = 50 Each
200-4 = 196 Lbs


Price List View:
Oracle accepts different price values for different UoM as shown below, and you can sell the product on any UoM.


Sales Order Lines 68097 :
Lets sell this product based on different UoM..
Oracle will pull the price based on UoM you mentioned on the Order line, also it asks to feed the secondary qty as well. But remember the final transaction will happen based on UoM added on Order line and then other qty will be calculated.


Now Process the Order: Book > Pick Release > Pick Confirm > Ship Confirm.

Observe the above shipping transactions,
Line 1.1: even though its showing Secondary Req Qty as 12 actual Secondary Shipped Qty is 11.5 (as per the conversion), as 46Lbs of chicken comes to 11.5 (46/4)
Line 1.2: Here we did not give qty in Lbs, so oracle calculated it based on conversion and populated.
At the end of this transaction the final On-Hand shall as below:
50 – (11.5+12) =  26.5
196 – (46+48)  = 102