I am new to Excel VBA scripting to create sales order in SAP system via BAPI, below are the issue I am facing :
Picking Material number from the Excel cell and passing to the sales order BAPI.
Dim Material As String
Material = ActiveSheet.Range("E14")
oItemsIn.Value(1, "MATERIAL") = Material
In this case the BAPI returns this error message:
Material 2094266 does not exist in sales area
but if I pass material "000000000002094266"
then it works fine.
How I can change the format with leading zeroes in the material number after picking value from the cell?
How I can pass material config (variant config) for the line item I am passing below values?
Set CFGS_REF = oBapiCtrl.DimAs(boOrder, "CreateFromData", "OrderCfgsRef")
Set CFGS_VK = oBapiCtrl.DimAs(boOrder, "CreateFromData", "OrderCfgsInst")
Set CFGS_VALUE = oBapiCtrl.DimAs(boOrder, "CreateFromData", "OrderCfgsValue")
'OrderCfgsRefinst
CFGS_REF.Value("POSEX") = "000010"
CFGS_REF.Value("CONFIG_ID") = "000010"
CFGS_REF.Value("ROOT_ID") = "00000010"
' forOrderCfgsVk
CFGS_VK.Value("CONFIG_ID") = "000010"
CFGS_VK.Value("INST_ID") = "00000010"
CFGS_VK.Value("CLASS_TYPE") = "300"
'OrderCfgsValue
CFGS_VALUE.Value("CONFIG_ID") = "000010"
CFGS_VALUE.Value("INST_ID") = "00000010" ' Item
CFGS_VALUE.Value("CHARC") = "PRG_ORD_SOURCE"
CFGS_VALUE.Value("Value") = "Excel"
But it throws this error at the line CFGS_REF.Value("POSEX") = "000010"
:
type mismatch
To add the leading zeroes back to your material number:
oItemsIn.Value(1, "MATERIAL") = Format(Material, "000000000000000000")