2024 Mar 04 2:40 PM - edited 2024 Mar 04 2:41 PM
Hi guys,
I would like to read out the activation data of an assest from transaction AS02 in Powershell, but unfortunately the scripts tells me that the asset does not exist, but when I use it in SAP GUI I find the asset.
[Reflection.Assembly]::LoadFile("C:\Windows\Microsoft.NET\assembly\GAC_64\sapnco\v4.0_3.1.0.42__50436dca5c7f7d23\sapnco.dll") > $Null
[Reflection.Assembly]::LoadFile("C:\Windows\Microsoft.NET\assembly\GAC_64\sapnco_utils\v4.0_3.1.0.42__50436dca5c7f7d23\sapnco_utils.dll") > $Null
Function Get-Destination {
#-Connect paramters-----------------------------------------------
$cfgParams = New-Object SAP.Middleware.Connector.RfcConfigParameters
#---TEST---
$cfgParams.Add("NAME", "SAP")
$cfgParams.Add("ASHOST", "xx.xx.xxx.xx")
$cfgParams.Add("SYSNR", "00")
$cfgParams.Add("CLIENT", "100")
$cfgParams.Add("USER", "user")
$cfgParams.Add("PASSWD", "password")
Return [SAP.Middleware.Connector.RfcDestinationManager]::GetDestination($cfgParams)
}
#-Sub Invoke-SAPFunctionModule----------------------------------------
$destination = Get-Destination
[SAP.Middleware.Connector.IRfcFunction]$bapiChangeAsset = $destination.Repository.CreateFunction("BAPI_FIXEDASSET_GETDETAIL")
$bapiChangeAsset.SetValue("COMPANYCODE", "0001")
$bapiChangeAsset.SetValue("ASSET", "31745")
$bapiChangeAsset.Invoke($destination)
[SAP.Middleware.Connector.IRfcStructure]$return = $bapiChangeAsset.GetStructure("RETURN")
Write-Host $return.GetValue("MESSAGE")
2024 Mar 04 3:43 PM - edited 2024 Mar 04 5:49 PM
You pass the asset in an external format. During SAP GUI session, it is implicitly converted to internal format, but not during background processing (without GUI)
2024 Mar 05 9:42 AM - edited 2024 Mar 05 9:43 AM
Hey thanks for your help but online I can't find much about BAPI_CONVERSION_EXT2INT1 and on the support page also finds what helps me so I tried to delete the whole thing like this
$ItemAnlage = 31745
$ItemAnlage = "0000000" + $ItemAnlage
$destination = Get-Destination
[SAP.Middleware.Connector.IRfcFunction]$bapiChangeAsset = $destination.Repository.CreateFunction("BAPI_FIXEDASSET_GETDETAIL")
$bapiChangeAsset.SetValue("COMPANYCODE", "0001")
$bapiChangeAsset.SetValue("ASSET", $ItemAnlage)
$bapiChangeAsset.SetValue("SUBNUMBER", "0")
$bapiChangeAsset.Invoke($destination)
Unfortunately this did not work and now it tells me that the attachment 000000031745 does not exist
2024 Mar 05 10:12 AM
Subnumber is a character field of length 4, try to replace "0" with "0000".
2024 Mar 05 10:33 AM
2024 Mar 05 10:37 AM - edited 2024 Mar 05 11:56 AM
Small sample in Abap for conversion BAPI external format to internal format
MOVE 'BUS1022' TO CONVERSION_LS-OBJTYPE.
MOVE 'GETDETAIL' TO CONVERSION_LS-METHOD.
MOVE 'ASSET' TO CONVERSION_LS-PARAMETER.
MOVE '1234' TO CONVERSION_LS-EXT_FORMAT.
APPEND CONVERSION_LS TO CONVERSION_LT.
MOVE 'SUBNUMBER' TO CONVERSION_LS-PARAMETER.
MOVE '0' TO CONVERSION_LS-EXT_FORMAT.
APPEND CONVERSION_LS TO CONVERSION_LT.
CALL FUNCTION 'BAPI_CONVERSION_EXT2INT1'
DESTINATION LV_BACKEND
TABLES
DATA = CONVERSION_LT
RETURN = RETURN.
LOOP AT CONVERSION_LT INTO CONVERSION_LS.
MOVE CONVERSION_LS-INT_FORMAT TO <INTVALUE>. " 000000001234 and 0000
MOVE CONVERSION_LS-CONV_LEN TO <LENGTH>. " 012 et 004
ENDLOOP.
You can find the requesed values in transaction BAPI
|
|