Showing posts with label OM. Show all posts
Showing posts with label OM. Show all posts

Thursday, December 03, 2015

Back Order Query

SELECT *
  FROM oe_order_headers_all ooha,
       wsh_delivery_details wdd,
       oe_order_lines_all oola
 WHERE     ooha.header_id = oola.header_id
       AND ooha.header_id = wdd.source_header_id
       AND wdd.released_status = 'B'
--       AND ooha.ordered_date > SYSDATE - 1
--       AND oola.ordered_item = 'NBR'                                 -- SKU
       AND NOT EXISTS
                  (SELECT 1
                     FROM wsh_delivery_details wdd1
                    WHERE     wdd1.released_status != 'B'
                          AND wdd1.source_header_id = ooha.header_id)

Wednesday, July 08, 2015

Sales Order Shipment Status:


B: Backordered- Line failed to be allocated in Inventory
C: Shipped -Line has been shipped
D: Cancelled -Line is Cancelled
N: Not Ready for Release -Line is not ready to be released
R: Ready to Release: Line is ready to be released
S: Released to Warehouse: Line has been released to Inventory for processing
X: Not Applicable- Line is not applicable for Pick Release
Y: Staged- Line has been picked and staged by Inventory 

B : Backordered : when we try to pick release a Sales Order but On-hand is not available for the order line , in such scenarios the order line is back ordered and the released status  = 'B'

C: Shipped :Once the Order line is shipped the associated delivery details Released Status is changed to 'C' .OM interface and Inventory interface have processed and the trip is closed.

D: Cancelled : When the Order line is cancelled the released status = 'D'

N: Not Ready for Release -Line is not ready to be released . this can happen when the information is available in wsh_delivery_details but order line has not reached the Awaiting Shipping status , might be due to some workflow customization's

R: Ready to Release: The Order line has been booked and the line is ready to be pick released . Line status is Awaiting Shipping under such scenarios

S: Released to Warehouse : Depending on the Pick release process in the business it moght be that Pick release is performed with Auto Pick confirm Set to No.
In such scenarios when we do pick release the Move Order will be created
Move Order allocation is done , but since Auto Pick Confirm is set to No the Mover Order will not be transacted.
The Delivery Detail will be in state : Pick Wave

X: Not Applicable- Line is not applicable for Pick Release , for the non-shippable item lines eg : Warranty orders
Y: Staged- Line has been picked and staged by Inventory .In this Case the line has been pick released. the Move Order Creation,Allocation and transaction is completed . Goods have be transferred from the Source Sub-invenotry to Staging area of the warehouse and the line is ready to be shipped.

Saturday, December 20, 2014

Order Details Workflow

To process an Order in 11i, Order Management uses internal Workflow technology.

image

As you can see it contains a start activity and an end activity and bunch of other activities in between.
11i Order Management primarily uses two workflow processes two process a Sales Order. One for processing an header and the other one for processing lines. Depending on our requirement we will configure these workflow processes to send out an event at appropriate steps within the processing. To configure an event there is a standard activity, Event activity, which we will embed and populate it with relevant data.
Let’s look at a Header processing workflow. How do I get to it. Well in 11i most of the functionality is inside the database. Workflow technology is also implemented as a PL/SQL engine inside the database. These processes are executed at runtime by this engine. The picture that you saw above is a design time tool and can be run from your desktop. All the relevant files are stored as “wft” file extensions. As you can imagine now …these are loaded into database for execution.
So let’s pull the header workflow by connecting to the 11i database.

image

There are bunch of processes listed here. For header processing we have “R_STANDARD_HEADER”. This is what is shipped out of the box from 11i. Of course customers have the option of creating their own and customize it to their needs.
image
image

As you can see in the above workflow there is a standard “Start”, called as “Enter”, and an “End” activity. Besides this we have “Book Order, Manual” and “Close Order” activities. Let’s focus on “Book” and “Close” activity. Picture of these activities indicates that they invoke sub processes.

Booking Order Process

A Sales Order can be entered through the Sales Order form or it can be received from external systems through various order channels like web sites, EDI or  XML. When they enter the Order management system they are in a status called as “Entered”. Next step in the Order processing cycle is to book the order. Normally you enter into Order Management’s Order Form and click on the button “Book”. Above mentioned workflow get’s triggered as a result of that.

Configuring Oracle Workflow

Let’s say we want to send the Order status to external system’s when the order is Booked. So let’s see if there is any event available out of the box. To do this we can browse through 11i Event’s screen by selecting responsibility “Workflow Administrator Web Applications” and clicking on “Administrator  Workflow'” ---> “Business Events”. Give the search criterion as “oracle.apps.ont”. Here “ont” is the internal code for Order management module and “oracle.apps” is a standard used for all events shipped out of the box by 11i.

image

Alternatively you can browse the same through E-Business Suite adapter from Oracle BPEL or Oracle ESB.

image

Both of the approaches gives the same view.

Looking at the what is being shipped out its very clear that there is no event which  get’s triggered when Order is booked….OK…hum… what needs to be done in order to inform external systems, UI’s etc when Order Booking happens. Here are the steps…
  • Define a custom business event
  • Insert a new “Events” activity in the Workflow
  • Configure the activity
  • Optionally….insert another custom activity to populate additional data
Let’s go through each of the above in detail.

Define a custom Business Event

Log into Oracle apps as “sysadmin/sysadmin”. Select the responsibility “Workflow Administrator Web Applications” and clicking on “Administrator  Workflow'” ---> “Business Events”.

image

You can see “Create Event” button click on it to define the event and input the details as in the screen

image

Insert a new “Events” activity in the Workflow

In the 11i workflow builder look at the toolbar. You will notice there is an event activity. Drag and drop that in the Workflow panel


image


image

Your workflow so far looks like this

image

Configure the activity

Click on “Event Details” tab. Make sure you put the Event Name value as “oracle.apps.fnd.order_booked”. Another required value to raise the event is “Event Key”. This has to be a unique value. In our case we can map this to Order Header ID which is always unique.

image 

Optionally you can define the variables that you want to pass as a part of the event. Map these variables through the “Node Attributes” tab
In the following diagram I have defined variables (Activity Attributes) starting with name as “X”. For example in this scenario when a Order Booked event is raised we want to know following
Order Number, Customer PO Number, Organization ID and Order Header ID

image

And map these variables from the “Node Attributes” tab.

image

Well in this scenario most of the data that we want is not available as pre-defined variables….but don’t worry its quite easy to get exactly what data you want to populate. So what we will do is define additional variables for the workflow and populate them through a custom PL/SQL program and then map them through the Event we created.

Custom activity to populate additional data

Check additional data you need …is that already available in the Workflow variables. If yes… good…otherwise create the required variables. In following diagram I have created additional variables starting with name as “XX_”

image

We have defined new variables for the workflow…now let’s populate them through the custom PL/SQL activity. Go back to our wonderful 11i Workflow builder and click on Function activity….drag it and drop it on the panel…

image

Function activity will prompt for input parameters. Most important one is the name of PL/SQL program that gets called from here….In this case it’s “XX_GET_ORD_DETAILS”

image


Your workflow now looks like following

image
To summarize what we did.
Created a custom event called as “XX_ORDERED_BOOKED_EVENT”. We created some additional attributes to pass some custom data…this is optional….Created a custom PL/SQL function activity “XX_GET_ORERE_DETAILS” to populate the additional variables in the custom event.

Thursday, November 27, 2014

Permti Sales by Item ( ORDERS, RETURNS)

SELECT DISTINCT obh.attribute2 PERMIT_CLASS,
  hca.account_number,
  hca.account_name,
  msib.segment1 ITEM_CODE,
  msib.description ITEM_DESC,
  -- CDC
  xxar_extract_permit_sales_pkg.get_cdc_code(orl.inventory_item_id,orl.ship_from_org_id) CDC,
  xxar_extract_permit_sales_pkg.get_cdc_code_desc(orl.inventory_item_id,orl.ship_from_org_id) CDC_DESC,
  --RMA GROUP
  xxar_extract_permit_sales_pkg.get_rma_code(orl.inventory_item_id,orl.ship_from_org_id) RMA,
  xxar_extract_permit_sales_pkg.get_rma_code_desc(orl.inventory_item_id,orl.ship_from_org_id) RMA_DESC,
  --MILK CLASS based on RMA GROUP
  xxar_extract_permit_sales_pkg.get_milk_class(orl.inventory_item_id,orl.ship_from_org_id) MILK_CLASS,
  obh.cust_po_number PERMIT,
  rct.trx_number TRX_NUMBER,
  rctype.name TRX_TYPE,
  ooh.order_number,
  --- Actual shipment date for Order or Return as per FS for return  the shipment date will be the one in the original transaction referenced in the RMA transaction
  xxar_extract_permit_sales_pkg.get_shipment_date(DECODE(ooh.order_category_code,'ORDER',orl.line_id,'RETURN',orl.reference_line_id))SHIPMENT_DATE,
  rct.trx_date,
  --rctp.gd_gl_date gl_date,
    rctgl.gl_date gl_date,
  orl.ordered_quantity ,
  orl.unit_selling_price,
  (orl.ordered_quantity*orl.unit_selling_price) amount,
  xxar_extract_permit_sales_pkg.get_lot_details(orl.inventory_item_id,orl.ship_from_org_id) lot_number
FROM ra_customer_trx rct,
  oe_order_headers ooh,
  oe_order_lines orl,
  hz_cust_accounts hca,
  mtl_system_items_b msib,
  ra_cust_trx_types rctype,
  oe_blanket_headers obh ,
  oe_blanket_lines obl ,
  oe_transaction_types_vl ottv,
  --RA_CUSTOMER_TRX_PARTIAL_V rctp,
  ra_cust_trx_line_gl_dist rctgl,
  ra_batch_sources rbatchs--,
  --  RA_CUSTOMER_TRX_LINES_ALL rl
WHERE TO_CHAR(ooh.order_number)  = rct.ct_reference--interface_header_attribute1
AND ooh.header_id                = orl.header_id
--AND rct.interface_header_context = 'ORDER ENTRY'
  --and rl.line_type = 'LINE'
  --and rl.interface_line_context = 'ORDER ENTRY'
  --and rctgl.customer_trx_line_id=rl.customer_trx_line_id
  --and rl.interface_line_attribute6 = to_char(orl.line_id)
  --and rl.interface_line_attribute1 = to_char(ooh.order_number)
  --and rl.sales_order = ooh.order_number
AND rct.sold_to_customer_id = hca.cust_account_id
  --AND rl.inventory_item_id(+) = msib.inventory_item_id
AND msib.inventory_item_id   = orl.inventory_item_id
AND msib.organization_id     = orl.ship_from_org_id
AND rctype.cust_trx_type_id  = rct.cust_trx_type_id
AND rct.sold_to_customer_id  =obl.sold_to_org_id
AND obh.header_id            =obl.header_id
AND ottv.transaction_type_id = obh.order_type_id
  AND rctgl.customer_trx_id   =rct.customer_trx_id
--AND rctp.customer_trx_id    =rct.customer_trx_id
AND rct.batch_source_id     =rbatchs.batch_source_id
AND ottv.name               =ANY('CDC PERMIT (CCBU_CA)','PERMIS CCL (CCBU_CA)')
AND upper(rctype.name)      =ANY('INVOICE','DEBIT','CREDIT')
--AND ooh.order_category_code = ANY('ORDER','RETURN')
AND rbatchs.name            ='ORDER MANAGEMENT'
  --Parameter  selection Criteria
--  AND ooh.order_category_code = DECODE(:p_order_type,'STANDARD','ORDER','RMA','RETURN','ALL',ooh.order_category_code) --:p_order_type  for standard or RMA
  --AND TRUNC(rctgl.gl_date) BETWEEN :p_from_date AND :p_to_date
  --AND NVL(hca.account_number,-1) = NVL(:p_customer,NVL(hca.account_number,-1))
  --AND NVL(obh.attribute2,    -1) = NVL(:p_permit_class,NVL(obh.attribute2,-1))
  --AND NVL(obh.cust_po_number,-1) = NVL(:p_permit_number,NVL(obh.cust_po_number,-1))
AND obh.order_number=ooh.blanket_number
GROUP BY obh.attribute2,
  hca.account_number,
  hca.account_name,
  msib.segment1 ,
  msib.description,
  -- CDC
  xxar_extract_permit_sales_pkg.get_cdc_code(orl.inventory_item_id,orl.ship_from_org_id) ,
  xxar_extract_permit_sales_pkg.get_cdc_code_desc(orl.inventory_item_id,orl.ship_from_org_id),
  --RMA GROUP
  xxar_extract_permit_sales_pkg.get_rma_code(orl.inventory_item_id,orl.ship_from_org_id) ,
  xxar_extract_permit_sales_pkg.get_rma_code_desc(orl.inventory_item_id,orl.ship_from_org_id),
  --MILK CLASS based on RMA GROUP
  xxar_extract_permit_sales_pkg.get_milk_class(orl.inventory_item_id,orl.ship_from_org_id) ,
  obh.cust_po_number ,
  rct.trx_number ,
  rctype.name ,
  ooh.order_number,
  --- Actual shipment date for Order or Return as per FS for return  the shipment date will be the one in the original transaction referenced in the RMA transaction
  xxar_extract_permit_sales_pkg.get_shipment_date(DECODE(ooh.order_category_code,'ORDER',orl.line_id,'RETURN',orl.reference_line_id)),
  rct.trx_date,
    rctgl.gl_date,
  --rctp.gd_gl_date,
  orl.ordered_quantity ,
  orl.unit_selling_price,
  (orl.ordered_quantity*orl.unit_selling_price) ,
  xxar_extract_permit_sales_pkg.get_lot_details(orl.inventory_item_id,orl.ship_from_org_id)
UNION
 SELECT DISTINCT obh.attribute2 PERMIT_CLASS,
    hca.account_number,
    hca.account_name,
    msib.segment1 ITEM_CODE,
    msib.description ITEM_DESC,
    -- CDC
    xxar_extract_permit_sales_pkg.get_cdc_code(orl.inventory_item_id,orl.ship_from_org_id) CDC,
    xxar_extract_permit_sales_pkg.get_cdc_code_desc(orl.inventory_item_id,orl.ship_from_org_id) CDC_DESC,
    --RMA GROUP
    xxar_extract_permit_sales_pkg.get_rma_code(orl.inventory_item_id,orl.ship_from_org_id) RMA,
    xxar_extract_permit_sales_pkg.get_rma_code_desc(orl.inventory_item_id,orl.ship_from_org_id) RMA_DESC,
    --MILK CLASS based on RMA GROUP
    xxar_extract_permit_sales_pkg.get_milk_class(orl.inventory_item_id,orl.ship_from_org_id) MILK_CLASS,
    obh.cust_po_number PERMIT,
    rct.trx_number TRX_NUMBER,
    rctype.name TRX_TYPE,
    ooh.order_number,
    --- Actual shipment date for Order or Return as per FS for return  the shipment date will be the one in the original transaction referenced in the RMA transaction
    xxar_extract_permit_sales_pkg.get_shipment_date((orl.reference_line_id))SHIPMENT_DATE,
    rct.trx_date,
    --rctp.gd_gl_date gl_date,
    rctgl.gl_date gl_date,
    orl.ordered_quantity ,
    orl.unit_selling_price,
    (orl.ordered_quantity*orl.unit_selling_price) amount,
    xxar_extract_permit_sales_pkg.get_lot_details(orl.inventory_item_id,orl.ship_from_org_id) lot_number
  FROM ra_customer_trx rct,
    oe_order_headers ooh,
    oe_order_lines orl,
    hz_cust_accounts hca,
    mtl_system_items_vl msib,
    ra_cust_trx_types rctype,
    oe_blanket_headers obh ,
    oe_blanket_lines obl ,
    oe_transaction_types_vl ottv,
    ra_cust_trx_line_gl_dist rctgl,
    ra_batch_sources rbatchs
  WHERE (ooh.order_number) = (rct.ct_reference)
  AND ooh.header_id        = orl.header_id
    ---       and ooh.blanket_number(+)=obh.order_number
  AND orl.reference_header_id IS NOT NULL
  AND rct.sold_to_customer_id  = hca.cust_account_id
  AND msib.inventory_item_id   = orl.inventory_item_id
  AND msib.organization_id     = orl.ship_from_org_id
  AND rctype.cust_trx_type_id  = rct.cust_trx_type_id
  AND rct.sold_to_customer_id  =obl.sold_to_org_id
  AND obh.header_id            =obl.header_id
  AND ottv.transaction_type_id = obh.order_type_id
  AND rctgl.customer_trx_id    =rct.customer_trx_id
  AND rct.batch_source_id      =rbatchs.batch_source_id
  AND ottv.name               =ANY('CDC PERMIT (CCBU_CA)','PERMIS CCL (CCBU_CA)')
  AND upper(rctype.name)       =ANY('INVOICE','DEBIT','CREDIT')
--  AND ooh.order_category_code  = ('ORDER','RETURN')
  AND rbatchs.name             ='ORDER MANAGEMENT'
    --Parameter  selection Criteria
          -- AND ooh.order_category_code = DECODE(:p_order_type,'STANDARD','ORDER','RMA','RETURN','ALL',ooh.order_category_code) --:p_order_type  for standard or RMA
--          AND trunc(rctgl.gl_date) between     :p_from_date and :p_to_date
  --       AND nvl(hca.account_number,-1) = NVL(:p_customer,nvl(hca.account_number,-1))
    --     AND nvl(obh.attribute2,-1) = NVL(:p_permit_class,nvl(obh.attribute2,-1))
      --   AND nvl(obh.cust_po_number,-1) = NVL(:p_permit_number,nvl(obh.cust_po_number,-1))
order by  1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21/*,
  hca.account_number,
  hca.account_name,
  msib.segment1 ,
  description
 -- CDC
  xxar_extract_permit_sales_pkg.get_cdc_code(orl.inventory_item_id,orl.ship_from_org_id) ,
  xxar_extract_permit_sales_pkg.get_cdc_code_desc(orl.inventory_item_id,orl.ship_from_org_id),
  --RMA GROUP
  xxar_extract_permit_sales_pkg.get_rma_code(orl.inventory_item_id,orl.ship_from_org_id) ,
  xxar_extract_permit_sales_pkg.get_rma_code_desc(orl.inventory_item_id,orl.ship_from_org_id),
  --MILK CLASS based on RMA GROUP
  xxar_extract_permit_sales_pkg.get_milk_class(orl.inventory_item_id,orl.ship_from_org_id) ,
  obh.cust_po_number ,
  rct.trx_number ,
  rctype.name ,
  ooh.order_number,
  --- Actual shipment date for Order or Return as per FS for return  the shipment date will be the one in the original transaction referenced in the RMA transaction
--  xxar_extract_permit_sales_pkg.get_shipment_date(DECODE(ooh.order_category_code,'ORDER',orl.line_id,'RETURN',orl.reference_line_id)),
  rct.trx_date,
--    rctgl.gl_date,
  --rctp.gd_gl_date,
  orl.ordered_quantity ,
  orl.unit_selling_price,
  (orl.ordered_quantity*orl.unit_selling_price) ,
  xxar_extract_permit_sales_pkg.get_lot_details(orl.inventory_item_id,orl.ship_from_org_id)*/

Tuesday, November 25, 2014

Accounting Entries in Order to Cash Cycle

Sales order creation – No entries
    Pick release:
    Inventory Stage A/c…………………Debit
    Inventory Finished goods a/c……..Credit
    Ship confirm:
    Cogs A/c ……………………………Debit
    Inventory Organization a/c………Credit
    Receviable:
    Receviable A/c………………………Debit
    Revenue A/c………………………Credit
    Tax ………………..…………………Credit
    Freight…………..….……………….Credit
    Cash:
    Cash A/c Dr…………………………Debit
    Receivable A/c……………………….Credit

Query to display BOL, MBOL, Trip details for a Sales Order

SELECT   ooh.order_number
       , wnd.NAME delivery_name
       , wt.NAME trip_name
       , ool.line_number
       , ool.ordered_item
       , ool.flow_status_code
       , DECODE (wdd.released_status
               , 'R', 'Ready For Release'
               , 'B', 'Back Ordered'
               , 'S', 'Released To Warehouse'
               , 'D', 'Cancelled'
               , 'N', 'Not Ready For Release'
               , 'Y', 'Staged or Pick Confirmed'
               , 'C', 'Interfaced/Shipped'
               , 'I', 'Interfaced/Shipped'
               , 'O', 'Not Shipped'
                ) delivery_status
       , rct.trx_number invoice_number
       , wdd.released_status
       , ood.organization_name || ' (' || ood.organization_code || ')' ship_from_org
       , hp_carrier.party_name carrier_name
       , wdi.sequence_number bol_number
       , wds.departure_net_weight ship_weight
       , wds.actual_departure_date ship_date
       , ooh.cust_po_number
       , SUBSTR (hp.party_name, 1, 30) || ' ' || 
       SUBSTR (hl_ship.address1, 1, 36) || ' ' || 
       SUBSTR (hl_ship.address2, 1, 36) || ' ' || 
       SUBSTR (hl_ship.city, 1, 30) || ' ' || 
       SUBSTR (hl_ship.province , 1 , 2 ) || ' ' || 
       SUBSTR (hl_ship.postal_code , 1 , 8 ) ship_to_address
FROM     apps.hr_locations hl
       , org_organization_definitions ood
       , apps.oe_order_headers_all ooh
       , oe_order_lines_all ool
       , apps.hz_locations hl_ship
       , apps.hz_parties hp
       , apps.hz_party_sites hps
       , apps.hz_cust_acct_sites_all hcas
       , apps.hz_cust_site_uses_all hcsu
       , apps.hz_party_sites hps_bill
       , apps.hz_cust_acct_sites_all hcas_bill
       , apps.hz_cust_site_uses_all hcsu_bill
       , apps.wsh_delivery_details wdd
       , apps.wsh_new_deliveries wnd
       , apps.wsh_delivery_assignments wda
       , apps.wsh_trips wt
       , apps.wsh_delivery_legs wdl
       , apps.wsh_trip_stops wds
       , apps.wsh_document_instances wdi
       , apps.hz_parties hp_carrier
       , ra_customer_trx_all rct
WHERE    1 = 1
AND      ooh.header_id = ool.header_id
AND      ood.organization_id = ool.ship_from_org_id
AND      ooh.ship_from_org_id = hl.inventory_organization_id
AND      hl_ship.location_id = hps.location_id
AND      hp.party_id = hps.party_id
AND      hps.party_site_id = hcas.party_site_id
AND      hps_bill.party_site_id = hcas_bill.party_site_id
AND      hps_bill.party_id = hp.party_id
AND      hcas.cust_acct_site_id = hcsu.cust_acct_site_id
AND      hcsu.site_use_id = ooh.ship_to_org_id
AND      hcas_bill.cust_acct_site_id = hcsu_bill.cust_acct_site_id
AND      hcsu_bill.site_use_id = ooh.invoice_to_org_id
AND      ooh.header_id = wdd.source_header_id(+)
AND      wda.delivery_detail_id(+) = wdd.delivery_detail_id
AND      wda.delivery_id = wnd.delivery_id(+)
AND      ool.line_id = wdd.source_line_id
AND      wt.trip_id(+) = wds.trip_id
AND      wds.stop_id(+) = wdl.pick_up_stop_id
AND      wdl.delivery_id(+) = wnd.delivery_id
AND      hp_carrier.party_id(+) = wt.carrier_id
AND      wdi.entity_id(+) = wdl.delivery_leg_id
AND      wdi.entity_name(+) = 'WSH_DELIVERY_LEGS'
AND      TO_CHAR (ooh.order_number) = rct.ct_reference(+)
AND      TO_CHAR (ooh.order_number) = rct.interface_header_attribute1(+)
AND      interface_header_context(+) = 'ORDER ENTRY'
AND      ooh.order_number = :order_number
ORDER BY ool.flow_status_code
       , ooh.order_number
       , ool.line_number

Query to list active serial number for an item

ELECT msi.segment1 item_number
     , msn.serial_number
     , msn.current_status_name
     , msn.status_code
     , msn.current_subinventory_code
     , ml.concatenated_segments
FROM   mtl_serial_numbers_all_v msn
     , mtl_system_items_b msi
     , mtl_item_locations_kfv ml
     , mtl_parameters mp
WHERE  msi.inventory_item_id = msn.inventory_item_id
AND    mp.organization_code = msn.organization_code
AND    ml.inventory_location_id = msn.current_locator_id
AND    msn.current_status = 3
AND    mp.organization_id = msi.organization_id
AND    mp.organization_code =  :org_code
AND    msi.segment1 = :item

Relation between AR invoice and OM

Many times I have seen a question being asked in the forums about the relationship between AR Invoice and Sales Order.
There are several interface_line_attribute and interface_header_attribute columns in RA_CUSTOMER_TRX_ALL and RA_CUSTOMER_TRX_LINES_ALL table respectively which are used to map it with other modules.
The relationship is actually mapped using the descriptive flexfield.

Query for following
Application: Receivables
Title: Line Transaction Flexfield

and then in the context field is the listed different modules.

For Sales order search for Order Management or Order Entry and click on segments to see how they are mapped. Screenshots below
 


Click on the segments button to see column mappings.

 


The above method can also be used to find mapping of Receivables with other modules like Oracle Projects, Services, Contracts etc.

Wednesday, October 10, 2012

Item Attributes Loading Extract

CREATE OR REPLACE PACKAGE XXCOFI_ATTR_EXTRACT_PKG AUTHID CURRENT_USER
AS

PROCEDURE delete_tables;

PROCEDURE sku_insert (I_SKU IN VARCHAR2);

PROCEDURE attr_extract;

PROCEDURE item_attr;

PROCEDURE attr_init;

END XXCOFI_ATTR_EXTRACT_PKG;
/

CREATE OR REPLACE PACKAGE BODY XXCOFI_ATTR_EXTRACT_PKG
IS

PROCEDURE delete_tables
IS

BEGIN
DELETE FROM XXCOFI.XXCOFI_ATTR_INIT;
COMMIT;
DELETE FROM XXCOFI.XXCOFI_ATTR_ITEM;
COMMIT;
DELETE FROM XXCOFI.XXCOFI_ATTR_SKU;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
fnd_file.put_line (fnd_file.LOG, SQLERRM);
END delete_tables;

PROCEDURE sku_insert (I_SKU IN VARCHAR2)
IS
temp VARCHAR2(1);

BEGIN
    INSERT INTO XXCOFI.XXCOFI_ATTR_SKU
        (SKU)
    VALUES
        (I_SKU);
    COMMIT;
EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN
temp := temp; --continue
WHEN OTHERS THEN
fnd_file.put_line (fnd_file.LOG, SQLERRM);
END sku_insert;

PROCEDURE attr_extract
IS
-- 1 = enabled, 0 = disabled
stest NUMBER := 0;
sdev NUMBER := 0;
sconv NUMBER := 0;
sprd NUMBER := 0;
--environment variables
snum NUMBER := 4; --number of environments
scont NUMBER; --boolean trigger
sname VARCHAR2(50); --current environment name
surl VARCHAR2(100); --soap url

--INTO fields for cursor
L_SEGMENT1 XXCOFI.XXCOFI_ATTR.SEGMENT1%TYPE;
L_ITEM_CATALOG_GROUP_ID XXCOFI.XXCOFI_ATTR.ITEM_CATALOG_GROUP_ID%TYPE;
L_ELEMENT_SEQUENCE XXCOFI.XXCOFI_ATTR.ELEMENT_SEQUENCE%TYPE;
L_ELEMENT_NAME XXCOFI.XXCOFI_ATTR.ELEMENT_NAME%TYPE;
L_DESCRIPTION XXCOFI.XXCOFI_ATTR.DESCRIPTION%TYPE;
L_ELEMENT_VALUE_ENG XXCOFI.XXCOFI_ATTR.ELEMENT_VALUE_ENG%TYPE;
L_ELEMENT_VALUE_FRC XXCOFI.XXCOFI_ATTR.ELEMENT_VALUE_FRC%TYPE;

SL SYS_REFCURSOR;

soap_request CLOB;
soap_respond CLOB;
st CLOB;
l_intstatus NUMBER;
http_req sys.utl_http.req;
http_resp sys.utl_http.resp;

REC_ELE_ENG VARCHAR2(150);
REC_ELE_FRC VARCHAR2(150);

L_SEG XXCOFI.XXCOFI_ATTR.SEGMENT1%TYPE := 'x';
L_ELE_NM XXCOFI.XXCOFI_ATTR.ELEMENT_NAME%TYPE := 'x';
CE NUMBER:=1;
CV NUMBER:=1;

I NUMBER;

O_INSTANCE_NAME VARCHAR2(16);

BEGIN
SELECT INSTANCE_NAME
INTO O_INSTANCE_NAME
FROM V$INSTANCE;

IF O_INSTANCE_NAME = 'HPRD' THEN
sprd := 1;
ELSE
stest := 1;
END IF;

--DBMS_OUTPUT.ENABLE(buffer_size=>null);
attr_init;
item_attr;

FOR X IN 1..snum
LOOP

scont := 0;
sname := '';

IF X = 1 THEN
    IF stest = 1 THEN
        sname := 'TEST_ENV';
        surl := 'http://ccdev07:7080/MCFFConversionRequestServiceTEST';
        scont := 1;
    END IF;
END IF;
IF X = 2 THEN
    IF sdev = 1 THEN
        sname := 'DEV_ENV';
        surl := 'http://ccdev07:7080/MCFFConversionRequestServiceDEV';
        scont := 1;
    END IF;
END IF;
IF X = 3 THEN
    IF sconv = 1 THEN
        sname := 'CONV_ENV';
        surl := 'http://ccdev70:7080/MCFFConversionRequestServiceCONV';
        scont := 1;
    END IF;
END IF;
IF X = 4 THEN
    IF sprd = 1 THEN
        sname := 'PRD_ENV';
        surl := 'http://ccib02:7080/MCFFConversionRequestServicePRD';
        scont := 1;
    END IF;
END IF;

--DBMS_OUTPUT.put_line(sname);

IF scont = 1 THEN

OPEN SL FOR
'SELECT *
FROM
(SELECT DISTINCT A.SEGMENT1,
TO_CHAR(A.ITEM_CATALOG_GROUP_ID) ITEM_CATALOG_GROUP_ID,
4030 ELEMENT_SEQUENCE,
'||''''||'Category'||''''||' ELEMENT_NAME,
'||''''||'Category'||''''||' DESCRIPTION,
A.SEGMENT4 ELEMENT_VALUE_ENG,
A.SEGMENT4 ELEMENT_VALUE_FRC
FROM XXCOFI.XXCOFI_ATTR_ITEM A
UNION ALL
SELECT DISTINCT A.SEGMENT1,
TO_CHAR(A.ITEM_CATALOG_GROUP_ID) ITEM_CATALOG_GROUP_ID,
4020 ELEMENT_SEQUENCE,
'||''''||'Pricing Strategy'||''''||' ELEMENT_NAME,
'||''''||'Pricing Strategy'||''''||' DESCRIPTION,
A.DFFPRICINGSTRATEGY ELEMENT_VALUE_ENG,
A.DFFPRICINGSTRATEGY ELEMENT_VALUE_FRC
FROM XXCOFI.XXCOFI_ATTR_ITEM A
UNION ALL
SELECT DISTINCT A.SEGMENT1,
TO_CHAR(A.ITEM_CATALOG_GROUP_ID) ITEM_CATALOG_GROUP_ID,
4010 ELEMENT_SEQUENCE,
'||''''||'Brand'||''''||' ELEMENT_NAME,
'||''''||'Brand'||''''||' DESCRIPTION,
A.ELEMENT_VALUE ELEMENT_VALUE_ENG,
MAX(A.ELEMENT_VALUE_FRC) ELEMENT_VALUE_FRC
FROM XXCOFI.XXCOFI_ATTR_ITEM A
GROUP BY A.SEGMENT1, A.ITEM_CATALOG_GROUP_ID, A.ELEMENT_VALUE
UNION ALL
SELECT DISTINCT A.SEGMENT1,
TO_CHAR(A.ITEM_CATALOG_GROUP_ID) ITEM_CATALOG_GROUP_ID,
4000 ELEMENT_SEQUENCE,
'||''''||'Item Status'||''''||' ELEMENT_NAME,
'||''''||'Item Status'||''''||' DESCRIPTION,
A.ITEM_STATUS ELEMENT_VALUE_ENG,
A.ITEM_STATUS ELEMENT_VALUE_FRC
FROM XXCOFI.XXCOFI_ATTR_ITEM A
UNION ALL
SELECT DISTINCT '||''''||'Promotion'||''''||' SEGMENT1,
'||''''||'GENERIC_PROMO_ATTR'||''''||' ITEM_CATALOG_GROUP_ID,
1030 ELEMENT_SEQUENCE,
'||''''||'Category'||''''||' ELEMENT_NAME,
'||''''||'Category'||''''||' DESCRIPTION,
A.SEGMENT4 ELEMENT_VALUE_ENG,
A.SEGMENT4 ELEMENT_VALUE_FRC
FROM XXCOFI.XXCOFI_ATTR_ITEM A
UNION ALL
SELECT DISTINCT '||''''||'Promotion'||''''||' SEGMENT1,
'||''''||'GENERIC_PROMO_ATTR'||''''||' ITEM_CATALOG_GROUP_ID,
1020 ELEMENT_SEQUENCE,
'||''''||'Pricing Strategy'||''''||' ELEMENT_NAME,
'||''''||'Pricing Strategy'||''''||' DESCRIPTION,
A.DFFPRICINGSTRATEGY ELEMENT_VALUE_ENG,
A.DFFPRICINGSTRATEGY ELEMENT_VALUE_FRC
FROM XXCOFI.XXCOFI_ATTR_ITEM A
UNION ALL
SELECT DISTINCT '||''''||'Promotion'||''''||' SEGMENT1,
'||''''||'GENERIC_PROMO_ATTR'||''''||' ITEM_CATALOG_GROUP_ID,
1010 ELEMENT_SEQUENCE,
'||''''||'Brand'||''''||' ELEMENT_NAME,
'||''''||'Brand'||''''||' DESCRIPTION,
A.ELEMENT_VALUE ELEMENT_VALUE_ENG,
MAX(A.ELEMENT_VALUE_FRC) ELEMENT_VALUE_FRC
FROM XXCOFI.XXCOFI_ATTR_ITEM A
GROUP BY A.ELEMENT_VALUE
UNION ALL
SELECT DISTINCT '||''''||'Promotion'||''''||' SEGMENT1,
'||''''||'GENERIC_PROMO_ATTR'||''''||' ITEM_CATALOG_GROUP_ID,
1000 ELEMENT_SEQUENCE,
'||''''||'Item Status'||''''||' ELEMENT_NAME,
'||''''||'Item Status'||''''||' DESCRIPTION,
A.ITEM_STATUS ELEMENT_VALUE_ENG,
A.ITEM_STATUS ELEMENT_VALUE_FRC
FROM XXCOFI.XXCOFI_ATTR_ITEM A
UNION ALL
SELECT DISTINCT A.SEGMENT1,
TO_CHAR(A.ITEM_CATALOG_GROUP_ID) ITEM_CATALOG_GROUP_ID,
4040 ELEMENT_SEQUENCE,
'||''''||'Item Discontinue Date'||''''||' ELEMENT_NAME,
'||''''||'Item Discontinue Date'||''''||' DESCRIPTION,
A.IMPLEMENTED_DATE ELEMENT_VALUE_ENG,
A.IMPLEMENTED_DATE ELEMENT_VALUE_FRC
FROM XXCOFI.XXCOFI_ATTR_ITEM A
UNION ALL
SELECT A.SEGMENT1,
A.ITEM_CATALOG_GROUP_ID,
A.ELEMENT_SEQUENCE,
A.ELEMENT_NAME,
A.DESCRIPTION,
A.ELEMENT_VALUE_ENG,
A.ELEMENT_VALUE_FRC
FROM XXCOFI.XXCOFI_ATTR_INIT A) D
WHERE NOT EXISTS (SELECT 1
                                FROM XXCOFI.XXCOFI_ATTR C
                               WHERE C.ITEM_CATALOG_GROUP_ID = D.ITEM_CATALOG_GROUP_ID
    AND C.ELEMENT_SEQUENCE = D.ELEMENT_SEQUENCE
    AND (NVL(C.ELEMENT_VALUE_ENG,'||''''||'N/A'||''''||') = NVL(D.ELEMENT_VALUE_ENG,'||''''||'N/A'||''''||'))
    AND C.'||sname||'= 1)
ORDER BY D.SEGMENT1,
D.ELEMENT_NAME,
D.ELEMENT_VALUE_ENG';
LOOP
    FETCH SL INTO
    L_SEGMENT1,
    L_ITEM_CATALOG_GROUP_ID,
    L_ELEMENT_SEQUENCE,
    L_ELEMENT_NAME,
    L_DESCRIPTION,
    L_ELEMENT_VALUE_ENG,
    L_ELEMENT_VALUE_FRC;
    EXIT WHEN SL%NOTFOUND;
        IF NOT (L_ELEMENT_NAME = L_ELE_NM AND L_SEGMENT1 = L_SEG) THEN
            IF NOT L_SEG = 'x' THEN
soap_request := soap_request ||
'        

   
]]>
?
ItemLocalization


';

                BEGIN
                soap_respond := null;

                http_req:= utl_http.begin_request
                (surl
                ,'POST'
                , 'HTTP/1.1'
                );

                --DBMS_OUTPUT.put_line('a1');
                utl_http.set_header(http_req, 'Content-Type', 'text/xml');
                utl_http.set_header(http_req, 'Content-Length', LENGTH(soap_request));
                utl_http.set_header(http_req, 'SOAPAction', '');
                utl_http.write_text(http_req, soap_request);
                http_resp:= utl_http.get_response(http_req);
                utl_http.read_text(http_resp, soap_respond);
                utl_http.end_response(http_resp);

I := 1;
--WHILE I <= LENGTH(soap_respond) LOOP
--DBMS_OUTPUT.PUT_LINE(SUBSTR(soap_respond, I, 255));   
--I := I + 255;   
--END LOOP;   

                EXCEPTION
                WHEN OTHERS THEN
                --DBMS_OUTPUT.put_line('UTL_HTTP Calling FOR CATALOG NAMES Error Code'||' '||SQLCODE);
                --DBMS_OUTPUT.put_line('UTL_HTTP Calling FOR CATALOG NAMES Error Message'||' '||SQLERRM);
                ROLLBACK;
                END;
               
                SELECT INSTR(soap_respond,'SUCCESSFUL')
                INTO l_intstatus
                FROM dual;

                IF l_intstatus>0 THEN
                --DBMS_OUTPUT.put_line('l_intstatus: '||l_intstatus);
                COMMIT;
                ELSE
                --DBMS_OUTPUT.put_line('l_intstatusr: '||l_intstatus);
                ROLLBACK;
                END IF;
            END IF;
soap_request := '
 
 
 
<![CDATA[

        IsAllowedValueDefined="Y" IsValueMandatory="N" LongDescription="'||L_ELEMENT_NAME||'"
    Operation="Manage" OrganizationCode="BAY" SequenceNo="'||TO_CHAR(CE)||'" ShortDescription="'||L_ELEMENT_NAME||'">
       
                        Operation="Manage" ShortDescription="'||L_DESCRIPTION||'"/>
       

        '||CHR(13)||CHR(10);
           
            --DBMS_OUTPUT.PUT_LINE(L_SEGMENT1||'    '||L_ITEM_CATALOG_GROUP_ID||'    '||L_ELEMENT_SEQUENCE||'    '||L_ELEMENT_NAME||'    '||L_DESCRIPTION||'    '||CE);
            L_SEG := L_SEGMENT1;
            L_ELE_NM := L_ELEMENT_NAME;
            CE := CE + 1;
            CV := 1;
        END IF;
       
        REC_ELE_ENG := NVL(REPLACE(REPLACE(REPLACE(REPLACE(L_ELEMENT_VALUE_ENG,'&','&'||'amp;'),'"','&'||'quot;'),'<','&'||'lt;'),'>','&'||'gt;'),'N/A');
        REC_ELE_FRC := NVL(REPLACE(REPLACE(REPLACE(REPLACE(L_ELEMENT_VALUE_FRC,'&','&'||'amp;'),'"','&'||'quot;'),'<','&'||'lt;'),'>','&'||'gt;'),REC_ELE_ENG);
       
st := '                         NumericStep="" Operation="Create" SequenceNo="'||TO_CHAR(CV)||'"  ShortDescription="'||REC_ELE_ENG||'"
             Value="'||REC_ELE_ENG||'">
               
                                        Operation="" ShortDescription="'||REC_ELE_FRC||'" Variant=""/>
               

           
'||CHR(13)||CHR(10);

        IF LENGTH(soap_request) + LENGTH(st) <= 32767 - 266 THEN
soap_request := soap_request || st;
        ELSE
soap_request := soap_request ||
'        

   
]]>

?
ItemLocalization
 

 
';

                BEGIN
                soap_respond := null;

                http_req:= utl_http.begin_request
                (surl
                ,'POST'
                , 'HTTP/1.1'
                );

                --DBMS_OUTPUT.put_line('c1');
                utl_http.set_header(http_req, 'Content-Type', 'text/xml');
                utl_http.set_header(http_req, 'Content-Length', LENGTH(soap_request));
                utl_http.set_header(http_req, 'SOAPAction', '');
                utl_http.write_text(http_req, soap_request);
                http_resp:= utl_http.get_response(http_req);
                utl_http.read_text(http_resp, soap_respond);
                utl_http.end_response(http_resp);
                I := 1;
--WHILE I <= LENGTH(soap_respond) LOOP
--DBMS_OUTPUT.PUT_LINE(SUBSTR(soap_respond, I, 255));   
--I := I + 255;   
--END LOOP;   
                EXCEPTION
                WHEN OTHERS THEN
                --DBMS_OUTPUT.put_line('UTL_HTTP Calling FOR CATALOG NAMES Error Code'||' '||SQLCODE);
                --DBMS_OUTPUT.put_line('UTL_HTTP Calling FOR CATALOG NAMES Error Message'||' '||SQLERRM);
                ROLLBACK;
                END;
               
                SELECT INSTR(soap_respond,'SUCCESSFUL')
                INTO l_intstatus
                FROM dual;

                IF l_intstatus>0 THEN
                --DBMS_OUTPUT.put_line('l_intstatus: '||l_intstatus);
                COMMIT;
                ELSE
                --DBMS_OUTPUT.put_line('l_intstatusr: '||l_intstatus);
                ROLLBACK;
                END IF;
soap_request := '
 
 
 
<![CDATA[

        IsAllowedValueDefined="Y" IsValueMandatory="N" LongDescription="'||L_ELEMENT_NAME||'"
    Operation="Manage" OrganizationCode="BAY" SequenceNo="'||TO_CHAR(CE - 1)||'" ShortDescription="'||L_ELEMENT_NAME||'">
       
                        Operation="Manage" ShortDescription="'||L_DESCRIPTION||'"/>
       

        '||CHR(13)||CHR(10);

        --DBMS_OUTPUT.PUT_LINE(L_SEGMENT1||'    '||L_ITEM_CATALOG_GROUP_ID||'    '||L_ELEMENT_SEQUENCE||'    '||L_ELEMENT_NAME||'    '||L_DESCRIPTION||'    '||(CE - 1));
soap_request := soap_request || st;
        END IF;
       
        BEGIN
            EXECUTE IMMEDIATE ('DECLARE
            L_dummy  VARCHAR2(1) := NULL;
            BEGIN
                SELECT '||''''||'x'||''''||'
                INTO L_dummy
                FROM XXCOFI.XXCOFI_ATTR
                WHERE ITEM_CATALOG_GROUP_ID = '||''''||TRIM(L_ITEM_CATALOG_GROUP_ID)||''''||'
                AND ELEMENT_SEQUENCE = '||L_ELEMENT_SEQUENCE||'
                AND ELEMENT_VALUE_ENG = '||''''||REPLACE(L_ELEMENT_VALUE_ENG,'''','''||''''''''||''')||''''||';
            END;');
               
            EXECUTE IMMEDIATE('UPDATE XXCOFI.XXCOFI_ATTR
            SET '||sname||' = 1
            WHERE ITEM_CATALOG_GROUP_ID = '||''''||TRIM(L_ITEM_CATALOG_GROUP_ID)||''''||'
            AND ELEMENT_SEQUENCE = '||L_ELEMENT_SEQUENCE||'
            AND ELEMENT_VALUE_ENG = '||''''||REPLACE(L_ELEMENT_VALUE_ENG,'''','''||''''''''||''')||'''');
        EXCEPTION
        WHEN NO_DATA_FOUND THEN
            EXECUTE IMMEDIATE('INSERT INTO XXCOFI.XXCOFI_ATTR
                        (SEGMENT1, ITEM_CATALOG_GROUP_ID, ELEMENT_SEQUENCE, ELEMENT_NAME, DESCRIPTION, ELEMENT_VALUE_ENG, ELEMENT_VALUE_FRC, '||sname||')
            VALUES
                        ('||''''||L_SEGMENT1||''''||','||''''||TRIM(L_ITEM_CATALOG_GROUP_ID)||''''||','||L_ELEMENT_SEQUENCE||','||''''||REPLACE(L_ELEMENT_NAME,'''','''||''''''''||''')||''''||','||''''||REPLACE(L_DESCRIPTION,'''','''||''''''''||''')||''''||','||''''||REPLACE(L_ELEMENT_VALUE_ENG,'''','''||''''''''||''')||''''||','||''''||REPLACE(L_ELEMENT_VALUE_FRC,'''','''||''''''''||''')||''''||', 1)');
        END;

    --DBMS_OUTPUT.PUT_LINE(L_ELEMENT_VALUE_ENG||'    '||L_ELEMENT_VALUE_FRC||'    '||CV);
    CV := CV + 1;
END LOOP;

IF NOT L_SEG = 'x' THEN
    soap_request := soap_request ||
    '        

       

   
]]>

    ?
    ItemLocalization
    

    

   
';

    BEGIN
        soap_respond := null;

        http_req:= utl_http.begin_request
        (surl
        ,'POST'
        , 'HTTP/1.1'
        );

        --DBMS_OUTPUT.put_line('b1');
        utl_http.set_header(http_req, 'Content-Type', 'text/xml');
        utl_http.set_header(http_req, 'Content-Length', LENGTH(soap_request));
        utl_http.set_header(http_req, 'SOAPAction', '');
        utl_http.write_text(http_req, soap_request);
        http_resp:= utl_http.get_response(http_req);
        utl_http.read_text(http_resp, soap_respond);
        utl_http.end_response(http_resp);
       
        I := 1;
--WHILE I <= LENGTH(soap_respond) LOOP
--DBMS_OUTPUT.PUT_LINE(SUBSTR(soap_respond, I, 255));   
--I := I + 255;   
--END LOOP;   
       
    EXCEPTION
    WHEN OTHERS THEN
    --DBMS_OUTPUT.put_line('UTL_HTTP Calling FOR CATALOG NAMES Error Code'||' '||SQLCODE);
    --DBMS_OUTPUT.put_line('UTL_HTTP Calling FOR CATALOG NAMES Error Message'||' '||SQLERRM);
    ROLLBACK;
    END;

    SELECT INSTR(soap_respond,'SUCCESSFUL')
    INTO l_intstatus
    FROM dual;

    IF l_intstatus>0 THEN
    --DBMS_OUTPUT.put_line('l_intstatus: '||l_intstatus);
    COMMIT;
    ELSE
    --DBMS_OUTPUT.put_line('l_intstatusr: '||l_intstatus);
    ROLLBACK;
    END IF;
END IF;
CLOSE SL;

END IF;

END LOOP; --X LOOP

EXCEPTION
WHEN OTHERS THEN
fnd_file.put_line (fnd_file.LOG, SQLERRM);
END attr_extract;

PROCEDURE item_attr
IS

temp VARCHAR2(1);
O_IMPLEMENTED_DATE VARCHAR2(30);

CURSOR SL IS
SELECT A.*,
DECODE (A.lookup_code,'SB',B.element_value,'CON',B.element_value,'STD',B.element_value,'SPE',B.element_value,'SUITE',B.element_value,'') ELEMENT_VALUE,
DECODE (A.lookup_code,'SB',B.element_value_frc,'CON',B.element_value_frc,'STD',B.element_value_frc,'SPE',B.element_value_frc,'SUITE',B.element_value_frc,'') ELEMENT_VALUE_FRC
FROM
(SELECT msi.segment1 sku,
msi.inventory_item_id,
micg.segment1,
msi.item_catalog_group_id,
mc.segment4,
DECODE(msi.inventory_item_status_code,'COFI Activ','Active','Suppressed','Disc','EOL','Disc','Disc') item_status,
msi.attribute14 dffpricingstrategy,
flv.lookup_code
FROM mtl_system_items_b msi,
          mtl_item_categories mic,
          mtl_categories_b mc,
          mtl_category_sets_b mcs,
          mtl_category_sets_tl mcst,
          fnd_lookup_values_vl flv,
          mtl_item_catalog_groups micg
WHERE msi.organization_id = '22'
AND msi.segment1 IN (SELECT SKU FROM XXCOFI.XXCOFI_ATTR_SKU)
AND micg.item_catalog_group_id = msi.item_catalog_group_id

AND msi.inventory_item_id = mic.inventory_item_id
AND msi.organization_id = mic.organization_id
AND mic.category_id = mc.category_id

AND mic.category_set_id = mcs.category_set_id
AND mcs.category_set_id = mcst.category_set_id
AND mcst.category_set_name = 'Inventory'
AND mcst.LANGUAGE = 'US'

AND flv.lookup_code = msi.item_type

AND (flv.meaning NOT IN --Can't be included in subsequent not in section as it is different.
               ('Warranty',
                '3rd Party Installation',
                'Assemble',
                'Hook Up',
                'Installation'
                )
             AND NOT NVL(SUBSTR (msi.item_catalog_group_id, 1, 3),'xx') = 'xx'
            )
AND flv.lookup_type = 'ITEM_TYPE'
AND flv.meaning NOT IN
               ('Repair Parts Charges',
                'Repair Expense Charges',
                'Labor',
                'Expense',
                'Non-Hbc',
                'Repair Labour Charges',
                'Usage Fee',
                'Allowance',
                'Purchased item',
                'ATO item',
                'Deferred Plan Admin Fee',
                'Environmental Fee'
               )) A LEFT OUTER JOIN

(SELECT v.inventory_item_id IID,
             v.element_value  element_value,
             vt.element_value element_value_frc
 FROM mtl_descr_element_values v,
          APPS.mtl_descr_element_values_tl vt
WHERE v.inventory_item_id = vt.inventory_item_id
AND v.element_name = vt.element_name
AND vt.element_name = 'Brand/Vendor'
AND vt.LANGUAGE = 'FRC') B
ON A.inventory_item_id = B.IID;
              
BEGIN

--DBMS_OUTPUT.ENABLE(buffer_size=>null);
FOR REC IN SL LOOP
            BEGIN
                BEGIN
                SELECT MAX(IMPLEMENTED_DATE)
                INTO O_IMPLEMENTED_DATE
                FROM mtl_pending_item_status mpis
                WHERE mpis.status_code = 'Disc'
                AND mpis.organization_id = '22'
                AND mpis.inventory_item_id = REC.inventory_item_id;

                EXCEPTION
                WHEN OTHERS THEN
                O_IMPLEMENTED_DATE := NULL;
                END;

            INSERT INTO XXCOFI.XXCOFI_ATTR_ITEM
                        (SKU, INVENTORY_ITEM_ID, SEGMENT1, ITEM_CATALOG_GROUP_ID, SEGMENT4, ITEM_STATUS, DFFPRICINGSTRATEGY, LOOKUP_CODE, ELEMENT_VALUE, ELEMENT_VALUE_FRC, IMPLEMENTED_DATE)
            VALUES
                        (REC.SKU, REC.INVENTORY_ITEM_ID, REC.SEGMENT1, REC.ITEM_CATALOG_GROUP_ID, REC.SEGMENT4, REC.ITEM_STATUS, REC.LOOKUP_CODE, REC.DFFPRICINGSTRATEGY, REC.ELEMENT_VALUE, REC.ELEMENT_VALUE_FRC, O_IMPLEMENTED_DATE);
            EXCEPTION
            WHEN DUP_VAL_ON_INDEX THEN
            temp := temp; --continue
            WHEN OTHERS THEN
            fnd_file.put_line (fnd_file.LOG, SQLERRM);
            END;
            COMMIT;
END LOOP;

END item_attr;

PROCEDURE attr_init
IS

temp VARCHAR2(1);

REC_ELE_ENG VARCHAR2(150);
REC_ELE_FRC VARCHAR2(150);

CURSOR SL IS
SELECT A.SEGMENT1,
    TO_CHAR(A.ITEM_CATALOG_GROUP_ID) ITEM_CATALOG_GROUP_ID,
    A.ELEMENT_SEQUENCE,
    A.ELEMENT_NAME,
    A.DESCRIPTION,
    A.ELEMENT_VALUE_ENG,
    MAX(VT.ELEMENT_VALUE) ELEMENT_VALUE_FRC
    FROM
        (SELECT MICG.SEGMENT1,
        MSI.ITEM_CATALOG_GROUP_ID,
        V.ELEMENT_SEQUENCE,
        V.ELEMENT_NAME,
        MDET2.DESCRIPTION,
        V.ELEMENT_VALUE ELEMENT_VALUE_ENG,
        V.INVENTORY_ITEM_ID
        FROM APPS.MTL_ITEM_CATALOG_GROUPS MICG,
        APPS.MTL_SYSTEM_ITEMS_B MSI,
        APPS.MTL_DESCRIPTIVE_ELEMENTS_TL MDET2,
        APPS.MTL_DESCR_ELEMENT_VALUES V
        WHERE MICG.ITEM_CATALOG_GROUP_ID = MSI.ITEM_CATALOG_GROUP_ID
        AND MSI.ORGANIZATION_ID = 22
        AND MSI.ITEM_CATALOG_GROUP_ID = MDET2.ITEM_CATALOG_GROUP_ID
        AND MSI.INVENTORY_ITEM_ID = V.INVENTORY_ITEM_ID
        AND MDET2.LANGUAGE = 'FRC'
        AND MDET2.ELEMENT_NAME = V.ELEMENT_NAME
        AND MSI.SEGMENT1 IN (SELECT SKU FROM XXCOFI.XXCOFI_ATTR_SKU)
        GROUP BY MICG.SEGMENT1,
        MSI.ITEM_CATALOG_GROUP_ID,
        V.ELEMENT_SEQUENCE,
        V.ELEMENT_NAME,
        MDET2.DESCRIPTION,
        V.ELEMENT_VALUE,
        V.INVENTORY_ITEM_ID) A,
    APPS.MTL_DESCR_ELEMENT_VALUES_TL VT
    WHERE A.INVENTORY_ITEM_ID = VT.INVENTORY_ITEM_ID
    AND A.ELEMENT_NAME = VT.ELEMENT_NAME
    AND VT.LANGUAGE = 'FRC'
    GROUP BY A.SEGMENT1,
    A.ITEM_CATALOG_GROUP_ID,
    A.ELEMENT_SEQUENCE,
    A.ELEMENT_NAME,
    A.DESCRIPTION,
    A.ELEMENT_VALUE_ENG;
              
BEGIN


--DBMS_OUTPUT.ENABLE(buffer_size=>null);
FOR REC IN SL LOOP
            BEGIN
            REC_ELE_ENG := NVL(TRIM(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REC.ELEMENT_VALUE_ENG,CHR(133),' '),CHR(149),' '),CHR(150),' '),CHR(153),' '),CHR(191),' ')),'N/A');
            REC_ELE_FRC := NVL(TRIM(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REC.ELEMENT_VALUE_FRC,CHR(133),' '),CHR(149),' '),CHR(150),' '),CHR(153),' '),CHR(191),' ')),REC_ELE_ENG);

            INSERT INTO XXCOFI.XXCOFI_ATTR_INIT
                        (SEGMENT1, ITEM_CATALOG_GROUP_ID, ELEMENT_SEQUENCE, ELEMENT_NAME, DESCRIPTION, ELEMENT_VALUE_ENG, ELEMENT_VALUE_FRC)
            VALUES
                        (REC.SEGMENT1,TRIM(REC.ITEM_CATALOG_GROUP_ID),REC.ELEMENT_SEQUENCE,REC.ELEMENT_NAME,REC.DESCRIPTION,REC_ELE_ENG,REC_ELE_FRC);
            EXCEPTION
            WHEN DUP_VAL_ON_INDEX THEN
            temp := temp;
            WHEN OTHERS THEN
            fnd_file.put_line (fnd_file.LOG, SQLERRM);
            END;
            COMMIT;
END LOOP;

END attr_init;

END xxcofi_attr_extract_pkg;
/