---
title: "外部程序调用BAPI应注意输入参数的位数..."
author: "csstome"
date: "2007-12-26T10:33:00Z"
tags: []
slug: "bapi"
draft: false
lastmod: "2007-12-26T10:33:00Z"
id: 1032491
url: "https://csstome.iteye.com/blog/1032491"
---

今天上午 在.net 中创建 Bapi\_Customer\_Getdetail2 再读取sap 的customer的相关信息，测试不成功，Customer 10030 在SAP SE37 中没问题，但在.net 的web page 测试页却拿不到数据，原因是在调用BAPI 的过程中能输入的参数有严格的位数限制， 在SAP 的表 KNA1 中 KUNNR， Customer 的位数是10 位，所在就要写采用在前面补0 的功能，

.net 的class 中创建如下function 将参数进行格式化:

Private Function FormatStringZW(ByVal p\_str As String, ByVal p\_len As Integer) As String  
Dim len As Integer  
len = p\_str.Length  
FormatStringZW = p\_str  
While len &lt; p\_len  
FormatStringZW = "0" + FormatStringZW  
len = len + 1  
End While  
End Function

再次测试通过！