Monday, 13 July 2015

API To Create Instance manually in Install Base

We can create instance manually using API CSI_ITEM_INSTANCE_PUB.CREATE_ITEM_INSTANCE.

Application of API:-

DECLARE
l_instance_rec            csi_datastructures_pub.instance_rec;
l_ext_attrib_values_tbl   csi_datastructures_pub.extend_attrib_values_tbl;
l_party_tbl               csi_datastructures_pub.party_tbl;
l_party_account_tbl       csi_datastructures_pub.party_account_tbl;
l_pricing_attribs_tbl     csi_datastructures_pub.pricing_attribs_tbl;
l_org_assignments_tbl     csi_datastructures_pub.organization_units_tbl;
l_asset_assignment_tbl    csi_datastructures_pub.instance_asset_tbl;
l_txn_rec                 csi_datastructures_pub.transaction_rec;
x_instance_id_lst         csi_datastructures_pub.id_tbl;

lr_party_rec              csi_datastructures_pub.party_rec;
lr_party_account_rec      csi_datastructures_pub.party_account_rec;
lr_ext_attrib_value_rec   csi_datastructures_pub.extend_attrib_values_rec;

l_return_status           VARCHAR2 (1);
l_msg_count               NUMBER;
l_msg_data                VARCHAR2 (2000);
l_msg_index_out           VARCHAR2 (100);
l_api_version    CONSTANT NUMBER := 1.0;

l_error_stage             VARCHAR2 (240);
l_start_date              DATE;
l_start_time              DATE;
l_location_id  hz_locations.location_id%TYPE;
l_party_id  hz_parties.party_id%TYPE;
l_cust_account_id  hz_cust_accounts.cust_account_id%TYPE;
BEGIN
BEGIN
SELECT internal_party_id
INTO l_internal_party_id
FROM csi_install_parameters;
EXCEPTION
WHEN OTHERS THEN
l_internal_party_id := NULL;
END;

BEGIN
SELECT hps.location_id
INTO l_location_id
FROM oe_order_lines_all oola,
HZ_CUST_SITE_USES_ALL hcsua,
hz_cust_acct_sites_all hcasa,
hz_party_sites hps
WHERE     oola.ship_to_org_id = hcsua.site_use_id
AND hcsua.cust_acct_site_id = hcasa.cust_acct_site_id
AND hcasa.party_site_id = hps.party_site_id
AND oola.line_id = <LINE_ID>;
EXCEPTION
WHEN OTHERS THEN
l_location_id := NULL;
END;

BEGIN
SELECT party_id, cust_account_id
INTO l_party_id, l_cust_account_id
FROM hz_cust_accounts hca, oe_order_lines_all oola
WHERE hca.cust_account_id = oola.sold_to_org_id
AND oola.line_id = <LINE_ID>;
EXCEPTION
WHEN OTHERS THEN
l_party_id := NULL;
END;

l_instance_rec.serial_number := '';
l_instance_rec.instance_id := NULL;
l_instance_rec.instance_number := NULL;
l_instance_rec.external_reference := '';

l_instance_rec.inventory_item_id :=
<INVENTORY_ITEM_ID>;
l_instance_rec.inv_master_organization_id := <MASTER_ORGANIZATION_ID>;
l_instance_rec.vld_organization_id :=
<SHIP_FROM_ORG_ID of LINE>;
l_instance_rec.LAST_OE_ORDER_LINE_ID :=
<LINE_ID FROM OE_ORDER_LINES_ALL>;
--l_instance_rec.instance_status_id         := 1011;
l_instance_rec.object_version_number := 1.0;
-- l_instance_rec.location_type_code := 'HZ_PARTY_SITES';
l_instance_rec.quantity := <SHIPPED_QUANTITY of LINE_ID>;
l_instance_rec.unit_of_measure :=
<UOM of ORDERED_ITEM LINE_ID>;
l_instance_rec.mfg_serial_number_flag := 'N';
l_instance_rec.version_label := 'AS_CREATED';
-- l_instance_rec.location_id := l_location_id;
l_instance_rec.active_start_date := SYSDATE;
l_instance_rec.install_date := SYSDATE;
l_instance_rec.location_id := l_location_id;
l_instance_rec.owner_party_id := l_party_id;
--l_instance_rec.ACCOUNTING_CLASS_CODE := l_accounting_class_code;--'CUST_PROD';
--l_instance_rec.rec.active_end_date := l_hdr_rec.ib_end_date;

lr_party_rec.party_source_table := 'HZ_PARTIES';
lr_party_rec.instance_id := NULL;
lr_party_rec.relationship_type_code := 'OWNER';
lr_party_rec.party_id := l_party_id;
lr_party_rec.contact_flag := 'N';
l_party_tbl (1) := lr_party_rec;

lr_party_account_rec.relationship_type_code := 'OWNER';
lr_party_account_rec.parent_tbl_index := 1;
lr_party_account_rec.party_account_id := l_cust_account_id;
lr_party_account_rec.instance_party_id := l_party_id;
--lr_party_account_rec.bill_to_address := '';
--lr_party_account_rec.ship_to_address := '';
l_party_account_tbl (1) := lr_party_account_rec;

lr_ext_attrib_value_rec.attribute_value_id := NULL;

l_txn_rec.transaction_date := SYSDATE;
l_txn_rec.source_transaction_date := SYSDATE;
l_txn_rec.transaction_type_id := 1;

l_error_stage :=
'Call API CSI_ITEM_INSTANCE_PUB.CREATE_ITEM_INSTANCE';

l_msg_data := NULL;
l_msg_index_out := NULL;
l_msg_count := NULL;

CSI_ITEM_INSTANCE_PUB.CREATE_ITEM_INSTANCE (
p_api_version             => l_api_version,
p_commit                  => FND_API.G_FALSE,
p_init_msg_list           => FND_API.G_FALSE,
p_validation_level        => FND_API.G_VALID_LEVEL_FULL,
p_instance_rec            => l_instance_rec,
p_ext_attrib_values_tbl   => l_ext_attrib_values_tbl,
p_party_tbl               => l_party_tbl,
p_account_tbl             => l_party_account_tbl,
p_pricing_attrib_tbl      => l_pricing_attribs_tbl,
p_org_assignments_tbl     => l_org_assignments_tbl,
p_asset_assignment_tbl    => l_asset_assignment_tbl,
p_txn_rec                 => l_txn_rec,
x_return_status           => l_return_status,
x_msg_count               => l_msg_count,
x_msg_data                => l_msg_data);

IF (l_return_status IN ('E', 'U'))
THEN
--l_error_code := 'E';
ROLLBACK;
FOR i IN 1 .. fnd_msg_pub.count_msg
LOOP
fnd_msg_pub.get (p_msg_index       => i,
p_encoded         => 'F',
p_data            => l_msg_data,
p_msg_index_out   => l_msg_index_out);
dbms_output.put_line (

'l_return_status: ' || l_return_status);
dbms_output.put_line (
 
  'l_msg_data: ' || SUBSTR (l_msg_data, 1, 250));
END LOOP;
dbms_output.put_line( 'Instance creation failed for order# ' || order_rec.order_number || ' Serial Number :- ' || l_serial_number);
ELSE
dbms_output.put_line ('------------------------------------------');
dbms_output.put_line ('l_return_status: ' || l_return_status);
dbms_output.put_line('The instance ID: '
|| TO_CHAR (l_instance_rec.INSTANCE_ID)
|| ' Created For Order# :- ' || order_rec.order_number
|| ' and Serial number :- ' || l_serial_number);
dbms_output.put_line ('------------------------------------------');
COMMIT;
END IF;
END;

No comments:

Post a Comment

Lookup For Hold Release Reasons In Order Management

 Oracle has provided an OE lookup "RELEASE_REASON" where it stores all the hold release reason codes.  You can enter your release ...