Oracle EBS物料BOM清单维护是用户最头疼的事情,特别对一些电子产品行业的产品种类多,更新周期短和BO层级多等等特点,用户提出想在PADS软件或AD软件或PLM系统的BOM清单导出Excel,然后接接导入到Oracle EBS系统,这样可减少不了工作。也与PADS和AD开发工程师沟通了解,这二款软件支持VBA宏编程,但是暂时不考虑VBA宏编直接把数据写入Oracle EBS系统。
Excel数据导入Oracle EBS系统有二种方案:
方案1.采用Oracle Web ADI技术导入系统,也做了二三个这样的项目,并且深有体会,11i的HR 集成器设置创建一个文件档以后不能修改,比如无法添加字段。不方便后期项目扩展
方案2.使用CSV导入Oracle Form,将Excel另存为CSV文件,再使用Oracle EBS标准上传附件文件功能,把其文件上传系统中,该文件保存在Oracle EBS系统表FND_LOBS字段FILE_DATA。优点:后期项目扩展方便,缺点:若不及时删除导入的文件,则会占用表空间量用。不过缺点还是可控的,上传数据以后自动删除该记录。
一、定义BOM清单导入格式
二、Form核心代码
2.1 调用Oracle EBS标准上传文件代码
--上传文件
Function UploadFile Return Number Is
l_AccessId Number;
l_ServerUrl Varchar2(20000);
l_Url Varchar2(20000);
l_ButtonChoice Number;
l_FileId Number;
l_OracleCharset Varchar2(30);
Begin
--Get Process ID
l_AccessId := Fnd_Gfm.authorize(Null);
--Get Web Page
Fnd_Profile.Get('APPS_WEB_AGENT', l_ServerUrl);
l_Url := Rtrim(l_ServerUrl, '/') ||
'/fnd_file_upload.displayGFMform?access_id=' ||
To_Char(l_AccessId) || Chr(38) || 'l_server_url=' || l_ServerUrl;
If (l_Url Is Null) Then
Fnd_Message.Set_String('调用Url失败!');
Fnd_Message.Show;
Raise Form_Trigger_Failure;
End If;
--Open Web Page
Fnd_Utilities.Open_Url(l_Url);
Fnd_Message.Set_String('请选择在打开网页导入的文件,单击“是”按钮上传完毕! ');
l_ButtonChoice := Fnd_Message.Question(button1 => 'Yes',
button2 => null,
button3 => 'No',
default_btn => 1,
cancel_btn => 3,
icon => 'Question');
--Get File ID
l_FileId := Fnd_Gfm.Get_File_ID(l_AccessId);
--获得客户端字符集
If l_FileId Is Not Null And l_FileId <> 0 Then
Select oracle_charset
Into l_OracleCharset
From FND_LOBS
Where FILE_ID = l_FileId;
:Parameter.CLIENTCHARSET := Substr(:Parameter.CLIENTCHARSET, 1, Instr(:Parameter.CLIENTCHARSET, '.')) || l_OracleCharset;
End If;
--取消上传将要删除上传文件的记录
If(l_ButtonChoice =3)Then
Begin
Delete From FND_LOBS Where FILE_ID = l_FileId;
Exception
When No_Data_Found Then
Null;
End;
l_FileId :=0;
Forms_Ddl('commit');
End If;
Return l_FileId;
End;
2.2 自动上传数据(新增记录)代码
--导入物料清单
/*
BLOCKNAME 块名
FIELDSET 字段集如:'ASSEMBLY_NUM,ITEM_NUM,OPERATION_SEQ_NUM,COMPONENT_NUM,PRIMARY_UOM_CODE,COMPONENT_QUANTITY,'||
'EFFECTIVITY_DATE,PLANNING_FACTOR,COMPONENT_YIELD_FACTOR,ENFORCE_INT_REQUIREMENTS_DESC,INCLUDE_IN_COST_ROLLUP,'||
'SUPPLY_TYPE,SUPPLY_SUBINVENTORY,LOCATOR,COMPONENT_REMARKS,COMPONENT_REFERENCE_DESIGNATOR,REF_DESIGNATOR_COMMENT'; --字符字段集
COLUMN_SPILT 列分隔符
ROW_SPILT 行分隔符
*/
procedure ImportBom(P_BLOCKNAME Varchar2,P_FIELDSET Varchar2,P_COLUMN_SPILT Varchar2,P_ROW_SPILT Varchar2) Is
l_FileId Number; --上传文件的ID
l_FieldSet Varchar2(4000) := P_FIELDSET; --字符字段集
l_FieldCount Number; --字段个数
l_ArrayField DBMS_UTILITY.UNCL_ARRAY; --字段数组
l_ColSpilt Varchar2(1) := P_COLUMN_SPILT; --每列的分隔符是,
l_RowSpilt Varchar2(1) := P_ROW_SPILT; --每行的分隔符是Enter
l_FileLength Number; --文件长度
l_LanguageFlag Number; --语言标志
l_FilePos Number := 1; --文件起始位
l_RowPos Number := 0; --每行起始位
l_Row Number := 0; --第几行
l_ServerCharSet Varchar2(400); --服务端字符集
l_ClientCharSet Varchar2(400); ---客户端字符集
l_RowData Varchar2(32767); --每行数据
l_ColPos Number; --列位置
l_ColPosPre Number; --前一列位置
l_ColNum Number; --第几列
l_ColData Varchar2(32767); --每列数据
Begin
Go_Block(P_BLOCKNAME);
--字符串转换成数组
DBMS_UTILITY.COMMA_TO_TABLE(l_FieldSet, l_FieldCount, l_ArrayField);
--上传文件
l_FileId := GB_BOMCMPBAT.UploadFile;
:parameter.FILE_ID := l_FileId;
If(l_FileId=0)Then
Raise Form_Trigger_Failure;
End If;
--获得文件长度
Select DBMS_LOB.GETLENGTH(FILE_DATA)
Into l_FileLength
From FND_LOBS
Where FILE_ID = l_FileId;
--根据语言环境获得语言标志
Begin
Select Decode(LANGUAGE, 'US', 1, 2)
Into l_LanguageFlag
From FND_LOBS
Where FILE_ID = l_FileId;
Exception
When No_Data_Found Then
l_LanguageFlag := 2;
End;
Loop
l_Row := l_Row + 1;
Select DBMS_LOB.INSTR(FILE_DATA,UTL_RAW.CAST_TO_RAW(l_RowSpilt),l_FilePos,1)
Into l_RowPos
From FND_LOBS
Where FILE_ID = l_FileId;
--获得每行数据
If (l_RowPos > 0) Then
If (l_LanguageFlag = 1) Then
Select Rtrim(UTL_RAW.CAST_TO_VARCHAR2(UTL_RAW.CONVERT(DBMS_LOB.SUBSTR(FILE_DATA,l_RowPos -l_FilePos,l_FilePos),
l_ServerCharSet,l_ClientCharSet)))
Into l_RowData
From FND_LOBS
Where FILE_ID = l_FileId;
Else
Select Dbms_Lob.substr(FILE_DATA, l_RowPos - l_FilePos, l_FilePos)
Into l_RowData
From FND_LOBS
Where FILE_ID = l_FileId;
End If;
l_FilePos := l_RowPos + 2;
l_RowPos := l_RowPos + 2;
Else
If (l_LanguageFlag = 1) Then
Select Rtrim(UTL_RAW.CAST_TO_VARCHAR2(UTL_RAW.CONVERT(DBMS_LOB.SUBSTR(FILE_DATA,1000,l_FilePos),
l_ServerCharSet,l_ClientCharSet)))
Into l_RowData
From FND_LOBS
Where FILE_ID = l_FileId;
Else
Select Dbms_Lob.substr(FILE_DATA, 1000, l_FilePos)
Into l_RowData
From FND_LOBS
Where FILE_ID = l_FileId;
End If;
l_FilePos := 1000 + 2;
End If;
--分解每行数据的获得列数据
If (Length(Ltrim(l_RowData)) > 2 And l_Row > 1) Then
--文件标识赋值
Copy(l_FileId,P_BLOCKNAME ||'.FILE_ID');
l_ColPos := 1; --列位置
l_ColPosPre := 1; --前一列位置
l_ColNum := 1; --第几列
l_RowData := LTRIM(RTRIM(UTL_RAW.CAST_TO_VARCHAR2(l_RowData)));
If(l_Row = 4)Then
Dbms_Output.put_line('l_RowData='||l_RowData);
End If;
--获得每列数据
While(l_ColNum<= l_FieldCount And l_ColPos>0)Loop
l_ColPos := Instr(l_RowData,l_ColSpilt,l_ColPosPre);
If(l_ColPos>0)Then
l_ColData := LTRIM(RTRIM(Substr(l_RowData,l_ColPosPre,l_ColPos-l_ColPosPre)));
Else
l_ColData := LTRIM(RTRIM(Substr(l_RowData,l_ColPosPre)));
End If;
If(l_Row = 4)Then
Dbms_Output.put_line(l_ArrayField(l_ColNum)||'='||l_ColData);
End If;
--字段赋值
If(l_ArrayField(l_ColNum) = 'EFFECTIVITY_DATE')Then
If(l_ColData = '' Or l_ColData Is Null)Then
Copy(name_in('CONTROL.EFFECTIVITY_DATE'),P_BLOCKNAME||'.'||l_ArrayField(l_ColNum));
Else
--Fnd_Message.Set_String(l_ColData ||','||To_Char(To_Date(l_ColData,'YYYY-MM-DD HH24:MI:SS'),'DD-MM-YYYY HH24:MI:SS'));
--Fnd_Message.show();
Copy(To_Char(To_Date(l_ColData,'YYYY-MM-DD HH24:MI:SS'),'DD-MM-YYYY HH24:MI:SS'),P_BLOCKNAME||'.'||l_ArrayField(l_ColNum));
End If;
Else
Copy(l_ColData,P_BLOCKNAME||'.'||l_ArrayField(l_ColNum));
End If;
l_ColPosPre := l_ColPos +1;
l_ColNum := l_ColNum +1;
End Loop;
Copy(1,P_BLOCKNAME ||'.STATUS_TYPE');
Copy('输入',P_BLOCKNAME ||'.STATUS_TYPE_MIR');
Copy('输入',P_BLOCKNAME ||'.STATUS_TYPE_DSP');
End If;
Exit When l_FilePos >= l_FileLength;
--新增一行
If(l_Row > 1)Then
Next_record;
End If;
End Loop;
--删除上传的文件
If(l_FileId>0)Then
Delete From FND_LOBS Where FILE_ID = l_FileId;
Copy('0','system.message_level');
Forms_Ddl('commit');
End If;
End;
2.3 工具->上传物料清单CSV文件 代码: Form级触发器 SPECIAL7
Declare
l_FieldSet Varchar2(4000) := 'ASSEMBLY_NUM,ITEM_NUM,OPERATION_SEQ_NUM,COMPONENT_NUM,PRIMARY_UOM_CODE,COMPONENT_QUANTITY,'||
'EFFECTIVITY_DATE,PLANNING_FACTOR,COMPONENT_YIELD_FACTOR,ENFORCE_INT_REQUIREMENTS_DESC,INCLUDE_IN_COST_ROLLUP,'||
'SUPPLY_TYPE,SUPPLY_SUBINVENTORY,LOCATOR,COMPONENT_REMARKS,COMPONENT_REFERENCE_DESIGNATOR,REF_DESIGNATOR_COMMENT'; --字符字段集
Begin
--上传物料清单CSV文件
If(:SYSTEM.FORM_STATUS='CHANGED')Then
Go_Block('BBI');
Commit_Form;
Clear_Block(NO_VALIDATE); --清除数据
End If;
:CONTROL.EFFECTIVITY_DATE := Sysdate;
GB_BOMCMPBAT.ImportBom('BBI',l_FieldSet,',',Chr(13));
copy('0','system.message_level');
Forms_Ddl('commit');
End;
2.4 调用请求执行BOM清单导入API Form级触发器:SPECIAL8 代码
declare
v_ErrBuf Varchar2(1000);
v_RetCode Number;
l_Count Number := 0;
l_RequestId Number;
l_RespId Number := fnd_profile.value('RESP_ID');
l_RespApplId Number := fnd_profile.value('RESP_APPL_ID');
l_StatusType Number;
l_StatusTypeDsp Varchar2(80);
l_FileId Number;
begin
l_FileId := :BBI.FILE_ID;
--批量导入物料清单
If (:SYSTEM.FORM_STATUS = 'CHANGED') Then
Go_Block('BBI');
Commit_Form;
End If;
--获得批量导入的物料清单记录
Select Count(*)
Into l_Count
From CUX.CUX_BOM_BILLCOMPS_INTERFACE
Where FILE_ID = :BBI.FILE_ID
And STATUS_TYPE In (1,3);
l_Count := Nvl(l_Count, 0);
--更新批量导入文件标识状态
Begin
Update CUX.CUX_BOM_BILLCOMPS_INTERFACE
Set STATUS_TYPE = 2
Where FILE_ID = :BBI.FILE_ID
And STATUS_TYPE In (1,3);
copy('0', 'system.message_level');
Forms_Ddl('commit');
Go_Block('BBI');
Clear_Block(NO_VALIDATE); --清除数据
Exception
When No_Data_Found Then
Return;
When Others Then
GB_BOMCMPBAT.MsgBox('批量导入物料清单失败:' || SqlErrm);
End;
--提交请求:GB物料清单批量导入
If (l_Count > 0) Then
l_RequestId := FND_REQUEST.SUBMIT_REQUEST('CUX',
'CUX_BOMCMPBAT',
'',
'',
FALSE,
l_FileId,
:parameter.USER_ID,
l_RespId,
l_RespApplId,
chr(0),'','','','','',
'', '','','','','','','','','',
'','','','','','','','','','',
'','','','','','','','','','',
'','','','','','','','','','',
'','','','','','','','','','',
'','','','','','','','','','',
'','','','','','','','','','',
'','','','','','','','','','',
'','','','','','','','','','');
Forms_ddl('commit');
If (l_RequestId = 0) Then
GB_BOMCMPBAT.MsgBox('GB物料清单批量导入请求提交失败'||SqlErrm,'N');
Else
GB_BOMCMPBAT.MsgBox('GB物料清单批量导入请求号为: ' || l_RequestId,'N');
End If;
End If;
End;
三、BOM清单导入API
CREATE OR REPLACE Package CUX_BOMCMPBAT_PKG As
--装配件
Cursor bomCr(P_FILE_ID Number) Is
Select BBI.FILE_ID,
BBI.ASSEMBLY_ITEM_ID,
BBI.ORGANIZATION_ID,
MSI.SEGMENT1 ASSEMBLY_NUM,
MSI.DESCRIPTION ASSEMBLY_DESC,
MAX(BBI.EFFECTIVITY_DATE) EFFECTIVITY_DATE,
BBM.BILL_SEQUENCE_ID,
OOD.ORGANIZATION_CODE,
OOD.ORGANIZATION_NAME
From CUX.CUX_BOM_BILLCOMPS_INTERFACE BBI,
MTL_SYSTEM_ITEMS_B MSI,
BOM_BILL_OF_MATERIALS BBM,
ORG_ORGANIZATION_DEFINITIONS OOD
Where BBI.ASSEMBLY_ITEM_ID = MSI.INVENTORY_ITEM_ID
And BBI.ORGANIZATION_ID = MSI.ORGANIZATION_ID
And BBI.ORGANIZATION_ID = OOD.ORGANIZATION_ID
And BBI.ASSEMBLY_ITEM_ID = BBM.ASSEMBLY_ITEM_ID(+)
And BBI.ORGANIZATION_ID = BBM.ORGANIZATION_ID(+)
And BBI.FILE_ID = P_FILE_ID
And BBI.STATUS_TYPE = 2
Group By BBI.FILE_ID,
BBI.ASSEMBLY_ITEM_ID,
BBI.ORGANIZATION_ID,
MSI.SEGMENT1,
MSI.DESCRIPTION,
BBM.BILL_SEQUENCE_ID,
OOD.ORGANIZATION_CODE,
OOD.ORGANIZATION_NAME;
--组件
Cursor cmpCr(P_FILE_ID Number,P_ASSEMBLY_ITEM_ID Number) Is
Select BBI.*
From CUX_BOM_BILLCOMPS_V BBI
Where BBI.FILE_ID = P_FILE_ID
And BBI.ASSEMBLY_ITEM_ID = P_ASSEMBLY_ITEM_ID
And BBI.STATUS_TYPE = 2
Order By BBI.ITEM_NUM;
Procedure ImportBom(ERRBUF OUT VARCHAR2,
RETCODE OUT NUMBER,
P_FILE_ID Number,
P_USER_ID Number,
P_RESP_ID Number,
P_RESP_APPL_ID Number);
End CUX_BOMCMPBAT_PKG;
CREATE OR REPLACE Package Body CUX_BOMCMPBAT_PKG As
--===============================================================
-- Log
--===============================================================
Procedure Log(p_Msg In Varchar2) Is
Begin
Fnd_File.Put_Line(Fnd_File.Log, p_Msg);
End Log;
--===============================================================
-- Output
--===============================================================
Procedure Output(p_Msg In Varchar2) Is
Begin
Fnd_File.Put_Line(Fnd_File.Output, p_Msg);
End Output;
procedure ImpBomHeader(P_FILE_ID Number) Is
Begin
Output('
提交日期:'||To_Char(Sysdate,'YYYY-MM-DD HH24:MI:SS')||'
文件标识:'|| P_FILE_ID ||'
成品编码
成品描述
物料序号
工序
组件编号
组件说明
实施日期
导入结果 ');
End ImpBomHeader;
procedure ImpBomBody(P_BOM CUX_BOMCMPBAT_PKG.bomCr%RowType,
P_CMP CUX_BOMCMPBAT_PKG.cmpCr%RowType,
P_RESULT Varchar2) Is
l_Result Varchar2(720);
l_BgColor Varchar2(200);
Begin
If(P_RESULT Is Null)Then
l_Result :='导入成功';
l_BgColor :='';
Else
l_Result := P_RESULT;
l_BgColor :=' bgcolor="red" ';
End If;
Output('
'||P_BOM.Assembly_Num||'
'||P_BOM.Assembly_Desc||'
'||P_CMP.ITEM_NUM||'
'||P_CMP.Operation_Seq_Num||'
'||P_CMP.Component_Num||'
'||P_CMP.Component_Desc||'
'||To_Char(P_BOM.EFFECTIVITY_DATE,'YYYY-MM-DD HH24:MI:SS') ||'
'||l_Result||' ');
End ImpBomBody;
Procedure ImportBom(ERRBUF OUT VARCHAR2,
RETCODE OUT NUMBER,
P_FILE_ID Number,
P_USER_ID Number,
P_RESP_ID Number,
P_RESP_APPL_ID Number) Is
l_bom_header_rec bom_bo_pub.bom_head_rec_type;
l_bom_component_tbl bom_bo_pub.bom_comps_tbl_type;
l_bom_ref_designator_tbl Bom_Bo_Pub.Bom_Ref_Designator_Tbl_type;
--L_BOM_COMPONENT_REF_TBL BOM_BO_PUB.BOM_REF_DESIGNATOR_TBL_TYPE;
--L_BOM_COMPONENT_SUB_TBL BOM_BO_PUB.BOM_SUB_COMPONENT_TBL_TYPE;
x_bom_header_rec bom_bo_pub.bom_head_rec_type;
x_bom_revision_tbl bom_bo_pub.bom_revision_tbl_type;
x_bom_component_tbl bom_bo_pub.bom_comps_tbl_type;
x_bom_ref_designator_tbl bom_bo_pub.bom_ref_designator_tbl_type;
x_bom_sub_component_tbl bom_bo_pub.bom_sub_component_tbl_type;
x_bom_comp_ops_tbl bom_bo_pub.bom_comp_ops_tbl_type;
x_return_status VARCHAR2(1);
x_msg_count NUMBER;
x_message_list error_handler.error_tbl_type;
l_RefDesignatorComment Varchar2(240);
l_CmpRefDesignator Number;
--cmpIndex Number;
l_TranType Number; --0表示新增,大于0表示修改
refIndex Number;
k Number;
l_ErrorMsg Varchar2(720);
Begin
CUX_GOBAOPUBLIC_PKG.HtmlStart('GB物料清单批量导入');
ImpBomHeader(P_FILE_ID);
--Initialize?or create By will be -1
Fnd_Global.Apps_Initialize(USER_ID => P_USER_ID,
RESP_ID => P_RESP_ID,
RESP_APPL_ID => P_RESP_APPL_ID);
For bomRs In bomCr(P_FILE_ID) Loop
--Start Bomm
l_TranType := Nvl(bomRs.BILL_SEQUENCE_ID,0);
If(l_TranType =0)Then
l_bom_header_rec.transaction_type := 'CREATE';
Else
l_bom_header_rec.transaction_type := 'UPDATE';
End If;
l_bom_header_rec.organization_code := bomRs.Organization_Code;
l_bom_header_rec.assembly_item_name := bomRs.Assembly_Num;
--l_bom_header_rec.alternate_bom_code := 'SBOM';
l_bom_header_rec.bom_implementation_date := bomRs.Effectivity_Date;
--cmpIndex := 1;
For cmpRs In cmpCr(P_FILE_ID,bomRs.Assembly_Item_Id) Loop
l_bom_component_tbl.DELETE;
If(l_TranType = 0)Then
l_bom_header_rec.transaction_type := 'CREATE';
Else
l_bom_header_rec.transaction_type := 'UPDATE';
End If;
l_bom_component_tbl(1).transaction_type := 'CREATE';
--组织代码
l_bom_component_tbl(1).organization_code := l_bom_header_rec.organization_code;
--装配件
l_bom_component_tbl(1).assembly_item_name := l_bom_header_rec.assembly_item_name;
--Alternate_BOM_Code
--l_bom_component_tbl(cmpIndex).alternate_bom_code := l_bom_header_rec.alternate_bom_code;
--工序
l_bom_component_tbl(1).Operation_Sequence_Number := cmpRs.Operation_Seq_Num;
--物料序号
l_bom_component_tbl(1).item_sequence_number := cmpRs.Item_Num;
--组件
l_bom_component_tbl(1).component_item_name := cmpRs.Component_Num;
--用量
l_bom_component_tbl(1).quantity_per_assembly := cmpRs.Component_Quantity;
--有效日期
l_bom_component_tbl(1).start_effective_date := l_bom_header_rec.bom_implementation_date;
--禁用日期
--l_bom_component_tbl(cmpIndex).disable_date := line_rec.disable_date;
--New_Effectivity_Date
--New_Operation_Sequence_Number
--Planning_Percent --计划%
l_bom_component_tbl(1).Planning_Percent := cmpRs.Planning_Factor;
--Projected_Yield --出产率
l_bom_component_tbl(1).Projected_Yield := cmpRs.Component_Yield_Factor;
--dbms_output.put_line(l_item_sequence_number);
--Include_In_Cost_Rollup 包括在累计成本中
l_bom_component_tbl(1).Include_In_Cost_Rollup := cmpRs.Include_In_Cost_Rollup;
--Wip_Supply_Type --供应商类型
l_bom_component_tbl(1).Wip_Supply_Type := cmpRs.Wip_Supply_Type; --1为推式
--So_Basis 基准 订单管理
l_bom_component_tbl(1).So_Basis := 2; --2为无
--Optional --可选 订单管理
l_bom_component_tbl(1).Optional := 2;
--Mutually_Exclusive --互不相容 订单管理
l_bom_component_tbl(1).Mutually_Exclusive := 2;
--Check_Atp --ATP查检 订单管理
l_bom_component_tbl(1).Check_Atp := 2;
--Shipping_Allowed --可发运
l_bom_component_tbl(1).Shipping_Allowed := Null;
--Required_To_Ship --要求装运
l_bom_component_tbl(1).Required_To_Ship := 2;
--Required_For_Revenue --要求确认收入
l_bom_component_tbl(1).Required_For_Revenue := 2;
--Include_On_Ship_Docs 包括在装运订单中
l_bom_component_tbl(1).Include_On_Ship_Docs := 2;
--Quantity_Related
l_bom_component_tbl(1).quantity_related := 2;
--Supply_Subinventory 供应子库存
l_bom_component_tbl(1).Supply_Subinventory := cmpRs.Supply_Subinventory;
--Location_Name 供应货位
l_bom_component_tbl(1).Location_Name := cmpRs.Locator_Name;
--Minimum_Allowed_Quantity 最小数 订单管理
l_bom_component_tbl(1).Minimum_Allowed_Quantity := Null;
--Maximum_Allowed_Quantity 最大数 订单管理
l_bom_component_tbl(1).Maximum_Allowed_Quantity := Null;
--Comments 备注
l_bom_component_tbl(1).Comments := Null;
--Attribute_category
--Attribute1
--Attribute2
--Attribute3
--Attribute4
--Attribute5
--Attribute6
--Attribute7
--Attribute8
--Attribute9
--Attribute10
--Attribute11
--Attribute12
--Attribute13
--Attribute14
--Attribute15
--From_End_Item_Unit_Number
--New_From_End_Item_Unit_Number
--To_End_Item_Unit_Number
--Return_Status
--Transaction_Type
--Original_System_Reference
--Delete_Group_Name
--DG_Description
--Enforce_Int_Requirements 要求数量必须为整数
l_bom_component_tbl(1).Enforce_Int_Requirements := 0;
--Auto_Request_Material 自动请求物料
l_bom_component_tbl(1).Auto_Request_Material := 'Y';
--Row_Identifier
--Suggested_Vendor_Name
--Purchasing_Category
--Purchasing_Category_Id
--Unit_Price
--指示符
l_CmpRefDesignator := 10;
refIndex := 1;
k := 0;
l_bom_ref_designator_tbl.Delete;
While (Length(cmpRs.Ref_Designator_Comment) > 0) Loop
Log(l_bom_header_rec.assembly_item_name||','||l_bom_component_tbl(1).component_item_name ||
',' ||l_bom_component_tbl(1).Operation_Sequence_Number);
--每次取240个字符长保存指示符
l_RefDesignatorComment := Substr(cmpRs.Ref_Designator_Comment,k + 1,240);
l_bom_ref_designator_tbl(refIndex).Organization_Code := l_bom_header_rec.organization_code;
l_bom_ref_designator_tbl(refIndex).Assembly_Item_Name := l_bom_header_rec.assembly_item_name;
l_bom_ref_designator_tbl(refIndex).Start_Effective_Date := l_bom_component_tbl(1).start_effective_date;
l_bom_ref_designator_tbl(refIndex).Operation_Sequence_Number := l_bom_component_tbl(1).Operation_Sequence_Number;
l_bom_ref_designator_tbl(refIndex).Component_Item_Name := l_bom_component_tbl(1).component_item_name;
l_bom_ref_designator_tbl(refIndex).Reference_Designator_Name := l_CmpRefDesignator;
l_bom_ref_designator_tbl(refIndex).Ref_Designator_Comment := l_RefDesignatorComment;
l_bom_ref_designator_tbl(refIndex).Transaction_Type := 'CREATE';
l_CmpRefDesignator := l_CmpRefDesignator + 10;
refIndex := refIndex + 1;
k := k + 240;
Exit When(Length(cmpRs.Ref_Designator_Comment) <= k);
End Loop; --End Designator
Begin
bom_bo_pub.process_bom(p_bo_identifier => 'BOM',
p_api_version_number => 1.0,
p_init_msg_list => TRUE,
p_bom_header_rec => l_bom_header_rec,
p_bom_component_tbl => l_bom_component_tbl,
p_bom_ref_designator_tbl => l_bom_ref_designator_tbl,
x_bom_header_rec => x_bom_header_rec,
x_bom_revision_tbl => x_bom_revision_tbl,
x_bom_component_tbl => x_bom_component_tbl,
x_bom_ref_designator_tbl => x_bom_ref_designator_tbl,
x_bom_sub_component_tbl => x_bom_sub_component_tbl,
x_bom_comp_ops_tbl => x_bom_comp_ops_tbl,
x_return_status => x_return_status,
x_msg_count => x_msg_count);
--Result
Log('执行Bom:'|| bomRs.Assembly_Num || ',' || cmpRs.Component_Num);
If x_return_status <> fnd_api.g_ret_sts_success Then
Rollback;
error_handler.get_message_list(x_message_list => x_message_list);
For i In 1 .. x_message_list.COUNT Loop
l_ErrorMsg := substr(x_message_list(i).message_text, 1, 720);
Log('导入失败:'||l_ErrorMsg);
End Loop;
--状态 1为输入,2为正在导入中..,3为错误,4为完成
Update CUX.CUX_BOM_BILLCOMPS_INTERFACE
Set STATUS_TYPE = 3, ERROR_MESSAGE = l_ErrorMsg
Where FILE_ID = P_FILE_ID
And ASSEMBLY_ITEM_ID = bomRs.Assembly_Item_Id
And ITEM_NUM = cmpRs.Item_Num
And STATUS_TYPE =2;
Commit;
Else
Log('成功导入');
l_ErrorMsg := Null;
--清除接口记录
Delete From CUX.CUX_BOM_BILLCOMPS_INTERFACE
Where FILE_ID = P_FILE_ID
And ASSEMBLY_ITEM_ID = bomRs.Assembly_Item_Id
And ITEM_NUM = cmpRs.Item_Num;
Commit;
dbms_output.put_line('Row_Identifier:'||x_bom_header_rec.Row_Identifier);
l_TranType := x_bom_header_rec.Row_Identifier;
End If;
ImpBomBody(bomRs,cmpRs,l_ErrorMsg); --输出结果
Exception
When Others Then
ImpBomBody(bomRs, cmpRs,l_ErrorMsg || ', 执行BOM API错误:' || Sqlerrm); --输出结果
End;
--cmpIndex := cmpIndex + 1;
End Loop; --End Components
End Loop; --End Bom
Output('