Sql server 将COBOL数据转换为SQL Server
我们从COBOL接收到如下数据,并将其转换为SQL Server。我遵循了这一点Sql server 将COBOL数据转换为SQL Server,sql-server,vb.net,cobol,Sql Server,Vb.net,Cobol,我们从COBOL接收到如下数据,并将其转换为SQL Server。我遵循了这一点 <item display-length="122" level="01" name="Location-Record" position="1" storage-length="122"> <item display-length="2" level="03" name="Record-Type" picture="xx" position="1" storage-length="2"/
<item display-length="122" level="01" name="Location-Record" position="1" storage-length="122">
<item display-length="2" level="03" name="Record-Type" picture="xx" position="1" storage-length="2"/>
<item display-length="12" level="03" name="location" occurs="10" position="3" storage-length="12">
<item display-length="4" level="05" name="DC-Number" numeric="true" picture="9(4)" position="3" storage-length="4"/>
<item display-length="8" level="05" name="Pack-Quantity" numeric="true" picture="9(8)" position="7" storage-length="8"/>
</item>
</item>
并创建了SSIS包。然而,在将一些数据从COBOL转换为SQL时,我面临一个问题
<item display-length="122" level="01" name="Location-Record" position="1" storage-length="122">
<item display-length="2" level="03" name="Record-Type" picture="xx" position="1" storage-length="2"/>
<item display-length="12" level="03" name="location" occurs="10" position="3" storage-length="12">
<item display-length="4" level="05" name="DC-Number" numeric="true" picture="9(4)" position="3" storage-length="4"/>
<item display-length="8" level="05" name="Pack-Quantity" numeric="true" picture="9(8)" position="7" storage-length="8"/>
</item>
</item>
我将输入列标记为字节,将数字数据输出为10和精度2
<item display-length="122" level="01" name="Location-Record" position="1" storage-length="122">
<item display-length="2" level="03" name="Record-Type" picture="xx" position="1" storage-length="2"/>
<item display-length="12" level="03" name="location" occurs="10" position="3" storage-length="12">
<item display-length="4" level="05" name="DC-Number" numeric="true" picture="9(4)" position="3" storage-length="4"/>
<item display-length="8" level="05" name="Pack-Quantity" numeric="true" picture="9(8)" position="7" storage-length="8"/>
</item>
</item>
1.尝试在SQL中将列创建为十进制(10,2)2.尝试使用COBOL date的SQL date数据类型
<item display-length="122" level="01" name="Location-Record" position="1" storage-length="122">
<item display-length="2" level="03" name="Record-Type" picture="xx" position="1" storage-length="2"/>
<item display-length="12" level="03" name="location" occurs="10" position="3" storage-length="12">
<item display-length="4" level="05" name="DC-Number" numeric="true" picture="9(4)" position="3" storage-length="4"/>
<item display-length="8" level="05" name="Pack-Quantity" numeric="true" picture="9(8)" position="7" storage-length="8"/>
</item>
</item>
包成功运行,但未填充数据。
<item display-length="122" level="01" name="Location-Record" position="1" storage-length="122">
<item display-length="2" level="03" name="Record-Type" picture="xx" position="1" storage-length="2"/>
<item display-length="12" level="03" name="location" occurs="10" position="3" storage-length="12">
<item display-length="4" level="05" name="DC-Number" numeric="true" picture="9(4)" position="3" storage-length="4"/>
<item display-length="8" level="05" name="Pack-Quantity" numeric="true" picture="9(8)" position="7" storage-length="8"/>
</item>
</item>
尝试了下面的函数来解包、翻译、拼图
<item display-length="122" level="01" name="Location-Record" position="1" storage-length="122">
<item display-length="2" level="03" name="Record-Type" picture="xx" position="1" storage-length="2"/>
<item display-length="12" level="03" name="location" occurs="10" position="3" storage-length="12">
<item display-length="4" level="05" name="DC-Number" numeric="true" picture="9(4)" position="3" storage-length="4"/>
<item display-length="8" level="05" name="Pack-Quantity" numeric="true" picture="9(8)" position="7" storage-length="8"/>
</item>
</item>
Public函数将(ByVal str作为字符串,scoversiontable作为字符串)转换为字符串
Dim Temp作为字符串,I作为Int32
温度=空间(长(短))
对于I=1到Len(str)
Mid(临时,I,1)=Mid(可转换,Asc(Mid(str,I,1))+1,1)
下一个
翻译=温度
端函数
私有函数解包(ByVal bPacked为Byte(),ByVal iDecimalPlaces为Integer)为十进制
作为整数的Dim i
Dim HINIBLE作为字节
作为字节的字节
Dim dResult作为十进制=0
对于i=0到b打包。长度-2
解包字节数(bPacked(i)、lonible、HiNibble)
dResult=Convert.ToDecimal(dResult*10^2I+hinible*10+lonible)
下一个
解包字节数(bPacked(bPacked.Length-1)、lonible、HiNibble)
dResult=dResult*10+HINIBLE
如果LoNibble=&HD&那么
dResult=-dResult
如果结束
解包=转换为特定值(dResult*10^(-iDecimalPlaces))
端函数
私有子解包字节(ByVal InputNibbles作为字节,ByRef Lonible作为字节,ByRef HiNibble作为字节)
LoNibble=(Me.F和InputNibbles)
HiNibble=((Me.F0和InputNibbles)>>4)
端接头
作为字符串的公共函数DecimalToCOBOLZonedPic(ByVal dNumber为十进制,ByVal iPadLength为整数,ByVal iDecimalPlaces为整数,ByVal BmodifiedZonedPIC为布尔值)
Dim为负值,布尔值=False
作为字符串的Dim strNumber
Dim sPositive As String=“{ABCDEFGHI”
Dim sNegativeMod As String=“}JKLMNOPQR”
尺寸sNegativeStrict为String=“pqrstuvwxy”
“确定标志
如果dNumber<0,则
isNegative=True
dNumber=-dNumber
如果结束
dNumber=将.ToDecimal(dNumber*(10^iDecimalPlaces))
strNumber=dNumber.ToString
如果strNumber.IndexOf(“.”)大于-1,则
'截断剩余的小数位
strNumber=strNumber.Substring(0,strNumber.IndexOf(“.”)
如果结束
'用前导零填充
如果strNumber.Length-1
strNumber=strNumber.Substring(0,strNumber.Length-1)和spospositive.IndexOf(sZoneChar)
convertedNumber=Convert.ToDecimal(strNumber)
案例sNegativeMod.IndexOf(sZoneChar)>-1
strNumber=strNumber.Substring(0,strNumber.Length-1)和sNegativeMod.IndexOf(sZoneChar)
convertedNumber=-Convert.ToDecimal(strNumber)
案例sNegativeStrict.IndexOf(sZoneChar)>-1
strNumber=strNumber.Substring(0,strNumber.Length-1)和sNegativeStrict.IndexOf(sZoneChar)
convertedNumber=-Convert.ToDecimal(strNumber)
其他情况
convertedNumber=Convert.ToDecimal(strNumber)
结束选择
返回Convert.ToDecimal(convertedNumber/(10^decimalPlaces))
端函数
当前文件
转换为EBCDIC的0x0200EAA4为x0200529F,这是一个有效的comp-3值(2020-5-29)
<item display-length="122" level="01" name="Location-Record" position="1" storage-length="122">
<item display-length="2" level="03" name="Record-Type" picture="xx" position="1" storage-length="2"/>
<item display-length="12" level="03" name="location" occurs="10" position="3" storage-length="12">
<item display-length="4" level="05" name="DC-Number" numeric="true" picture="9(4)" position="3" storage-length="4"/>
<item display-length="8" level="05" name="Pack-Quantity" numeric="true" picture="9(8)" position="7" storage-length="8"/>
</item>
</item>
在二进制EBCDIC文件(如此文件)上运行ascii转换将损坏该文件
不要尝试处理当前文件
<item display-length="122" level="01" name="Location-Record" position="1" storage-length="122">
<item display-length="2" level="03" name="Record-Type" picture="xx" position="1" storage-length="2"/>
<item display-length="12" level="03" name="location" occurs="10" position="3" storage-length="12">
<item display-length="4" level="05" name="DC-Number" numeric="true" picture="9(4)" position="3" storage-length="4"/>
<item display-length="8" level="05" name="Pack-Quantity" numeric="true" picture="9(8)" position="7" storage-length="8"/>
</item>
</item>
解决
- 在源计算机(大型机???)上将文件转换为文本,并传输/翻译文件
<item display-length="122" level="01" name="Location-Record" position="1" storage-length="122">
<item display-length="2" level="03" name="Record-Type" picture="xx" position="1" storage-length="2"/>
<item display-length="12" level="03" name="location" occurs="10" position="3" storage-length="12">
<item display-length="4" level="05" name="DC-Number" numeric="true" picture="9(4)" position="3" storage-length="4"/>
<item display-length="8" level="05" name="Pack-Quantity" numeric="true" picture="9(8)" position="7" storage-length="8"/>
</item>
</item>
<item display-length="122" level="01" name="Location-Record" position="1" storage-length="122">
<item display-length="2" level="03" name="Record-Type" picture="xx" position="1" storage-length="2"/>
<item display-length="12" level="03" name="location" occurs="10" position="3" storage-length="12">
<item display-length="4" level="05" name="DC-Number" numeric="true" picture="9(4)" position="3" storage-length="4"/>
<item display-length="8" level="05" name="Pack-Quantity" numeric="true" picture="9(8)" position="7" storage-length="8"/>
</item>
</item>
<item display-length="122" level="01" name="Location-Record" position="1" storage-length="122">
<item display-length="2" level="03" name="Record-Type" picture="xx" position="1" storage-length="2"/>
<item display-length="12" level="03" name="location" occurs="10" position="3" storage-length="12">
<item display-length="4" level="05" name="DC-Number" numeric="true" picture="9(4)" position="3" storage-length="4"/>
<item display-length="8" level="05" name="Pack-Quantity" numeric="true" picture="9(8)" position="7" storage-length="8"/>
</item>
</item>
如果可以的话
<item display-length="122" level="01" name="Location-Record" position="1" storage-length="122">
<item display-length="2" level="03" name="Record-Type" picture="xx" position="1" storage-length="2"/>
<item display-length="12" level="03" name="location" occurs="10" position="3" storage-length="12">
<item display-length="4" level="05" name="DC-Number" numeric="true" picture="9(4)" position="3" storage-length="4"/>
<item display-length="8" level="05" name="Pack-Quantity" numeric="true" picture="9(8)" position="7" storage-length="8"/>
</item>
</item>
- 运行java
- 拿到Cobol文案
- Cobol手册中没有重新定义
<item display-length="122" level="01" name="Location-Record" position="1" storage-length="122">
<item display-length="2" level="03" name="Record-Type" picture="xx" position="1" storage-length="2"/>
<item display-length="12" level="03" name="location" occurs="10" position="3" storage-length="12">
<item display-length="4" level="05" name="DC-Number" numeric="true" picture="9(4)" position="3" storage-length="4"/>
<item display-length="8" level="05" name="Pack-Quantity" numeric="true" picture="9(8)" position="7" storage-length="8"/>
</item>
</item>
EBCDIC 存在多个EBCDIC字符集Cp037/IBM037为US EBCDIC;CP273/IBM273是德语EBCDIC,您需要了解使用的是哪种EBCDIC方言
<item display-length="122" level="01" name="Location-Record" position="1" storage-length="122">
<item display-length="2" level="03" name="Record-Type" picture="xx" position="1" storage-length="2"/>
<item display-length="12" level="03" name="location" occurs="10" position="3" storage-length="12">
<item display-length="4" level="05" name="DC-Number" numeric="true" picture="9(4)" position="3" storage-length="4"/>
<item display-length="8" level="05" name="Pack-Quantity" numeric="true" picture="9(8)" position="7" storage-length="8"/>
</item>
</item>
注意:CP037代表编码页037
<item display-length="122" level="01" name="Location-Record" position="1" storage-length="122">
<item display-length="2" level="03" name="Record-Type" picture="xx" position="1" storage-length="2"/>
<item display-length="12" level="03" name="location" occurs="10" position="3" storage-length="12">
<item display-length="4" level="05" name="DC-Number" numeric="true" picture="9(4)" position="3" storage-length="4"/>
<item display-length="8" level="05" name="Pack-Quantity" numeric="true" picture="9(8)" position="7" storage-length="8"/>
</item>
</item>
主机固定宽度
在主机固定宽度的情况下,所有记录的长度都是相同的
你不是Ca吗