K
kfp
Unregistered / Unconfirmed
GUEST, unregistred user!
delphi7 取SAP中文地址数据,数据自动被截断,困惑两天了还没找到解决方案,用JAVA开发程序取数据就没有问题,难道是Delphi 变体变量(variant)存在的问题?请各位大虾指教,源代码如下,红色的那一行为被截断的变量值!谢谢了===================================================library PCZMIB07;{ Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. }uses SysUtils, System, Classes, SAPLogonCtrl_TLB, SAPFunctionsOCX_TLB, SAPBAPIControlLib_TLB, StdCtrls, forms, DBGrids, DB, ADODB, inifiles, ComObj;var Connection,Table,Table2,Table3,Table4,Funct : variant; r,iCount,iCount2,iCount3,iCount4: integer; saplogin: TSAPLogoncontrol; fun: TSAPFunctions; adoqTemp: TADOQuery; ADOConnection1: TADOConnection; ins1,ins2,ins3,ins4,sSQL,sSQL2,sSQL3,sSQL4,ATable,ATable2,ATable3,ATable4 : string; h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13,h14,h15 : string; h16,h17,h18,h19,h20,h21,h22,h23,h24,h25,h26,h27,h28,h29,h30: string; s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12 : string; bill:Boolean;function PCDZMIB07(order,tablename,user,password,DBname,IPaddress: string): Boolean;begin bill:= false; //创建数据库连接 ADOConnection1 := TADOConnection.Create(nil); adoqTemp := TADOQuery.Create(nil); ADOConnection1.Connected:= false; ADOConnection1.ConnectionString:= ' Provider=SQLOLEDB.1; Network Library=dbmssocn; '+ ' Password='+password+';Persist Security Info=True;User ID='+user+'; '+ ' Initial Catalog='+DBname+';Data Source='+IPaddress+'; ' + ' Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096; ' + ' Workstation ID='+IPaddress+';Use Encryption for Data=False; ' + ' Tag with column collation when possible=False '; ADOConnection1.LoginPrompt:= false; ADOConnection1.Connected:= true; adoqTemp.Connection:=ADOConnection1; //表头 ATable := '##PCDZMIB07Bill' + tablename; sSQL := 'if exists(select * from tempdb..sysobjects where '+ 'substring(name,1,len('''+ATable+'''))='''+ATable+''' '+ 'and type = ''U'') drop table ' + ATable; adoqTemp.Close; adoqTemp.SQL.Clear; adoqTemp.SQL.Add(sSQL); adoqTemp.ExecSQL; sSQL := 'create Table '+ATable+'(ITF_ConsignmentBillNo varchar(20),ITF_CredenceTime varchar(20),ITF_MatureTime varchar(20),'+ 'ITF_OrderFormTime varchar(20),ITF_ConsignmentTime varchar(20),ITF_PlanReachDate varchar(20),ITF_Country varchar(20),'+ 'ITF_FilialeCode varchar(20),ITF_FilialeName varchar(100),ITF_Street1 varchar(100),ITF_Street2 varchar(100),' + 'ITF_LinkMan varchar(20),ITF_Tel varchar(20),ITF_Extension varchar(20),ITF_TrafficModeCode varchar(20),'+ 'ITF_TrafficModeDesc varchar(100),ITF_ArriveHarbor varchar(100),ITF_CarryHarbor varchar(100),ITF_TradeMode varchar(100),'+ 'ITF_TradeAddr varchar(100),ITF_Text varchar(600),ITF_MatureNo varchar(10),ITF_PayCode varchar(4),'+ 'ITF_PayTextEN varchar(60),ITF_TrafficModeDescEN varchar(100),ITF_PayText varchar(60),ITF_TradeAddrEN varchar(100),'+ 'ITF_CarryHarborDesc varchar(100),ITF_MatureNo2 varchar(500),ITF_TradeMode2 varchar(300)) '; adoqTemp.Close; adoqTemp.SQL.Clear; adoqTemp.SQL.Add(sSQL); adoqTemp.ExecSQL; //发货单明细 ATable2 := '##PCDZMIB07Billlist' + tablename; sSQL2 := 'if exists(select * from tempdb..sysobjects where '+ 'substring(name,1,len('''+ATable2+'''))='''+ATable2+''' '+ 'and type = ''U'') drop table ' + ATable2; adoqTemp.Close; adoqTemp.SQL.Clear; adoqTemp.SQL.Add(sSQL2); adoqTemp.ExecSQL; sSQL2 := 'create Table '+ATable2+'(ITF_ConsignmentBillNo varchar(20),ITF_ConsignmentItemID varchar(10),ITF_WorkBillNo varchar(10),'+ 'ITF_WorkBillItem varchar(20),ITF_ProduceFlag varchar(4),ITF_MaterielCode varchar(18),'+ 'ITF_MaterielDesc varchar(100),ITF_MaterielNum varchar(20),ITF_EntryName varchar(200),'+ 'ITF_IdentifyCode varchar(60),ITF_EngineModel varchar(60),ITF_MaterielEngDesc varchar(200)) '; adoqTemp.Close; adoqTemp.SQL.Clear; adoqTemp.SQL.Add(sSQL2); adoqTemp.ExecSQL; //合作伙伴 ATable3 := '##PCDZMIB07BillPartner' + tablename; sSQL3 := 'if exists(select * from tempdb..sysobjects where '+ 'substring(name,1,len('''+ATable3+'''))='''+ATable3+''' '+ 'and type = ''U'') drop table ' + ATable3; adoqTemp.Close; adoqTemp.SQL.Clear; adoqTemp.SQL.Add(sSQL3); adoqTemp.ExecSQL; sSQL3 := 'create Table '+ATable3+'(ITF_ConsignmentBillNo varchar(20),ITF_FellowType varchar(10),ITF_Fellow varchar(10),'+ 'ITF_Client1 varchar(100),ITF_Client2 varchar(100),ITF_Street1 varchar(100),'+ 'ITF_Street2 varchar(100),ITF_Linkman varchar(70),ITF_Tel varchar(40),'+ 'ITF_Extension varchar(20),ITF_Fax varchar(30),ITF_Street3 varchar(100)) '; adoqTemp.Close; adoqTemp.SQL.Clear; adoqTemp.SQL.Add(sSQL3); adoqTemp.ExecSQL; { //发货单英文特性 ATable4 := '##PCDZMIB07BillEn' + tablename; sSQL4 := 'if exists(select * from tempdb..sysobjects where '+ 'substring(name,1,len('''+ATable4+'''))='''+ATable4+''' '+ 'and type = ''U'') drop table ' + ATable4; adoqTemp.Close; adoqTemp.SQL.Clear; adoqTemp.SQL.Add(sSQL4); adoqTemp.ExecSQL; sSQL4 := 'create Table '+ATable4+'(ITF_Consignment varchar(10),ITF_ConsignmentObj varchar(6),ITF_ConsignmentTxt varchar(60)) '; adoqTemp.Close; adoqTemp.SQL.Clear; adoqTemp.SQL.Add(sSQL4); adoqTemp.ExecSQL; } //SAP连接 saplogin := TSAPLogoncontrol.Create(nil); fun:= TSAPFunctions.Create(nil); Connection := saplogin.NewConnection; Connection.User := ''; Connection.System := ''; Connection.Client := ''; //Connection.ApplicationServer := ''; Connection.ApplicationServer := ''; Connection.SystemNumber := '01'; Connection.Password := '' Connection.Language := '' ; Connection.CodePage := ''; saplogin.Enabled := false; if Connection.LogOn(0,true) = false then begin //Application.MessageBox('连接不上SAP,请检查参数是否设置正确!','提示',MB_OK); fun.autologon := false; fun.free; saplogin.free; exit; end; fun.Connection := connection; Funct := fun.add('ZMIB07'); //函数名称 Funct.exports('I_VBELN').value := '00'+ trim(order); if not Funct.call then begin end else begin Table := Funct.tables.item('T_LIKP'); //发货单表头 Table2 := Funct.tables.item('T_LIPS'); //发货单明细 Table3 := Funct.tables.item('T_VBPK'); //合作伙伴 // Table4 := Funct.tables.item('T_ATWTB'); //英文特性 iCount := Table.rowcount; iCount2 := Table2.rowcount; iCount3 := Table3.rowcount; //iCount4 := Table4.rowcount; //发货单表头 for r := 1 to iCount do begin h1 := Table.value(r,'VBELN'); h2 := Table.value(r,'BLDAT'); h3 := Table.value(r,'GUEEN'); h4 := Table.value(r,'AUDAT'); h5 := Table.value(r,'WADAT_IST'); h6 := Table.value(r,'LFDAT'); h7 := Table.value(r,'VKBUR'); h8 := Table.value(r,'ZVKBUR'); h9 := Table.value(r,'BEZEI'); // h10 := Table.value(r,'STRAS'); h10 := stringreplace(Table.value(r,'STRAS'),'''','''''',[rfReplaceAll]); //h11 := Table.value(r,'STR_SUPPL1'); h11 := stringreplace(Table.value(r,'STR_SUPPL1'),'''','''''',[rfReplaceAll]); h12 := Table.value(r,'NAMELX'); h13 := Table.value(r,'TEL_NUMBER'); h14 := ''; h15 := Table.value(r,'VSART'); h16 := Table.value(r,'VBEZEI'); h17 := Table.value(r,'BOLNR'); h18 := Table.value(r,'ROUTE'); h19 := Table.value(r,'INCO1'); //h20 := Table.value(r,'INCO2'); h20 := stringreplace(Table.value(r,'INCO2'),'''','''''',[rfReplaceAll]); //h21 := Table.value(r,'ZS02'); h21 := stringreplace(Table.value(r,'ZS02'),'''','''''',[rfReplaceAll]); while Pos('"', h21) > 0 do begin h21 := StringReplace(h21, '"', '“', []); end; h22 := Table.value(r,'VBLNBG'); h23 := Table.value(r,'ZTERM'); h24 := Table.value(r,'VTEXT'); h25 := Table.value(r,'EBEZEI'); h26 := Table.value(r,'HTVEXT'); //h27 := Table.value(r,'EINCO2'); h27 := stringreplace(Table.value(r,'EINCO2'),'''','''''',[rfReplaceAll]); h28 := Table.value(r,'RBEZEI'); h29 := Table.value(r,'VBELN_VF'); h30 := Table.value(r,'ZINCO1'); ins1:= 'INSERT INTO '+ATable+'(ITF_ConsignmentBillNo,ITF_CredenceTime,ITF_MatureTime,ITF_OrderFormTime,ITF_ConsignmentTime' + ',ITF_PlanReachDate,ITF_Country,ITF_FilialeCode,ITF_FilialeName,ITF_Street1,ITF_Street2,ITF_LinkMan,ITF_Tel,ITF_Extension,' + 'ITF_TrafficModeCode,ITF_TrafficModeDesc,ITF_ArriveHarbor,ITF_CarryHarbor,ITF_TradeMode,ITF_TradeAddr,ITF_Text,ITF_MatureNo,' + 'ITF_PayCode,ITF_PayTextEN,ITF_TrafficModeDescEN,ITF_PayText,ITF_TradeAddrEN,ITF_CarryHarborDesc,ITF_MatureNo2,ITF_TradeMode2)' + ' VALUES ('''+h1+''','''+h2+''','''+h3+''','''+h4+''','''+h5+''','''+h6+''','''+h7+''','+ ' '''+h8+''','''+h9+''' ,'''+h10+''','''+h11+''','''+h12+''','''+h13+''','''+h14+''','''+h15+''','+ ' '''+h16+''','''+h17+''' ,'''+h18+''','''+h19+''','''+h20+''','''+h21+''','''+h22+''','''+h23+''','+ ' '''+h24+''','''+h25+''','''+h26+''','''+h27+''','''+h28+''','''+h29+''','''+h30+''') '; adoqTemp.Close; adoqTemp.SQL.Clear; adoqTemp.SQL.Add(ins1); adoqTemp.ExecSQL; end; //发货单明细表 for r := 1 to iCount2 do begin s1 := Table2.value(r,'VBELN'); s2 := Table2.value(r,'POSNR'); s3 := Table2.value(r,'VGBEL'); s4 := Table2.value(r,'VGPOS'); s5 := Table2.value(r,'SOBKZ'); s6 := Table2.value(r,'MATNR'); //s7 := Table2.value(r,'ARKTX'); s7 :=stringreplace(Table2.value(r,'ARKTX'),'''','''''',[rfReplaceAll]); s8 := Table2.value(r,'LFIMG'); s9 := Table2.value(r,'DESHG'); s10 := Table2.value(r,'TZ06'); s11 := Table2.value(r,'ZMODEL'); //s12 := Table2.value(r,'EMAKTX'); s12 := stringreplace(Table2.value(r,'EMAKTX'),'''','''''',[rfReplaceAll]); while Pos('"', s7) > 0 do begin s7 := StringReplace(s7, '"', '“', []); end; while Pos('"', s12) > 0 do begin s12 := StringReplace(s12, '"', '“', []); end; ins2 := 'INSERT INTO '+ATable2+'(ITF_ConsignmentBillNo,ITF_ConsignmentItemID,ITF_WorkBillNo,ITF_WorkBillItem,' + ' ITF_ProduceFlag,ITF_MaterielCode,ITF_MaterielDesc,ITF_MaterielNum,ITF_EntryName,ITF_IdentifyCode,ITF_EngineModel,' + ' ITF_MaterielEngDesc)' + ' VALUES ('''+s1+''','''+s2+''','''+s3+''','''+s4+''','''+s5+''','''+s6+''','''+s7+''','+ ' '''+s8+''','''+s9+''','''+s10+''','''+s11+''','''+s12+''' ) '; adoqTemp.Close; adoqTemp.SQL.Clear; adoqTemp.SQL.Add(ins2); adoqTemp.ExecSQL; end; //发货单合作伙伴 for r := 1 to iCount3 do begin s1 := Table3.value(r,'VBELN'); s2 := Table3.value(r,'PARVW'); s3 := Table3.value(r,'KUNNR'); //s4 := Table3.value(r,'NAME1');// stringreplace(ComBoUser.Text,'''','''''',[rfReplaceAll]) s4 := stringreplace(Table3.value(r,'NAME1'),'''','''''',[rfReplaceAll]); //s5 := Table3.value(r,'NAME2'); s5 := stringreplace(Table3.value(r,'NAME2'),'''','''''',[rfReplaceAll]);[red] s6 := Table3.value(r,'STRAS');//此处为从SAP中取出的地址数据,数据为中文,只要取出的数据的字符串长度超过30则被自动截断[/red] s7 := stringreplace(Table3.value(r,'STR_SUPPL1'),'''','''''',[rfReplaceAll]); //s8 := Table3.value(r,'NAMELX'); s8 := stringreplace(Table3.value(r,'NAMELX'),'''','''''',[rfReplaceAll]); s9 := Table3.value(r,'TEL_NUMBER'); s10 := Table3.value(r,'TEL_EXTENS'); s11 := Table3.value(r,'FAX_NUMBER'); //s12 := Table3.value(r,'STR_SUPPL2'); s12 := stringreplace(Table3.value(r,'STR_SUPPL2'),'''','''''',[rfReplaceAll]); ins3 := 'INSERT INTO '+ATable3+'(ITF_ConsignmentBillNo,ITF_FellowType,ITF_Fellow,ITF_Client1,ITF_Client2,' + 'ITF_Street1,ITF_Street2,ITF_Linkman,ITF_Tel,ITF_Extension,ITF_Fax,ITF_Street3)' + ' VALUES ('''+s1+''','''+s2+''','''+s3+''','''+s4+''','''+s5+''','''+s6+''','''+s7+''','+ ' '''+s8+''','''+s9+''','''+s10+''','''+s11+''','''+s12+''' ) '; adoqTemp.Close; adoqTemp.SQL.Clear; adoqTemp.SQL.Add(ins3); adoqTemp.ExecSQL; end; { //发货单英文特性 for r := 1 to iCount4 do begin h1 := Table4.value(r,'VBELN'); h2 := Table4.value(r,'POSNR'); h3 := Table4.value(r,'ATWTB'); ins4:= 'INSERT INTO '+ATable4+'(ITF_Consignment,ITF_ConsignmentObj,ITF_ConsignmentTxt)' + ' VALUES ('''+h1+''','''+h2+''','''+h3+''') '; adoqTemp.Close; adoqTemp.SQL.Clear; adoqTemp.SQL.Add(ins4); adoqTemp.ExecSQL; end; } fun.autologon := false; fun.free; saplogin.free; exit; bill := true; result := bill; end;end;exportsPCDZMIB07 index 14;{$R *.res}beginend.