Ejemplo n.º 1
0
func wrapResult(funcDesc C.RFC_FUNCTION_DESC_HANDLE, container C.RFC_FUNCTION_HANDLE, filterParameterDirection C.RFC_DIRECTION, strip bool) (result map[string]interface{}, err error) {
	var errorInfo C.RFC_ERROR_INFO
	var i, paramCount C.uint
	var paramDesc C.RFC_PARAMETER_DESC

	rc := C.RfcGetParameterCount(funcDesc, &paramCount, &errorInfo)
	if rc != C.RFC_OK {
		return result, rfcError(errorInfo, "Failed getting parameter count")
	}

	result = make(map[string]interface{})
	for i = 0; i < paramCount; i++ {
		rc = C.RfcGetParameterDescByIndex(funcDesc, i, &paramDesc, &errorInfo)
		if rc != C.RFC_OK {
			return result, rfcError(errorInfo, "Failed getting parameter decription by index(%v)", i)
		}
		if paramDesc.direction != filterParameterDirection {
			var fieldName string
			fieldName, err = wrapString((*C.SAP_UC)(&paramDesc.name[0]), strip)
			if err != nil {
				return
			}
			result[fieldName], err = wrapVariable(paramDesc._type, container, (*C.SAP_UC)(&paramDesc.name[0]), paramDesc.nucLength, paramDesc.typeDescHandle, strip)
			if err != nil {
				return
			}
		}
	}

	return
}
Ejemplo n.º 2
0
func wrapFunctionDescription(funcDesc C.RFC_FUNCTION_DESC_HANDLE) (goFuncDesc FunctionDescription, err error) {
	var rc C.RFC_RC
	var errorInfo C.RFC_ERROR_INFO
	var funcName C.RFC_ABAP_NAME
	var i, paramCount C.uint
	var paramDesc C.RFC_PARAMETER_DESC

	rc = C.RfcGetFunctionName(funcDesc, &funcName[0], &errorInfo)
	if rc != C.RFC_OK {
		return goFuncDesc, rfcError(errorInfo, "Failed getting function name")
	}

	goFuncName, err := wrapString((*C.SAP_UC)(&funcName[0]), false)
	if err != nil {
		return
	}
	goFuncDesc = FunctionDescription{Name: goFuncName}

	rc = C.RfcGetParameterCount(funcDesc, &paramCount, &errorInfo)
	if rc != C.RFC_OK {
		return goFuncDesc, rfcError(errorInfo, "Failed getting function(%v) parameter count", goFuncName)
	}

	for i = 0; i < paramCount; i++ {
		rc = C.RfcGetParameterDescByIndex(funcDesc, i, &paramDesc, &errorInfo)
		if rc != C.RFC_OK {
			return goFuncDesc, rfcError(errorInfo, "Failed getting function(%v) parameter description by index(%v)", goFuncName, i)
		}

		optional := true
		if paramDesc.optional == 0 {
			optional = false
		}

		var paramName string
		var paramType string
		var paramDir string
		var paramDefaultVal string
		var paramText string
		paramName, err = wrapString((*C.SAP_UC)(&paramDesc.name[0]), false)
		paramType, err = wrapString((*C.SAP_UC)(C.RfcGetTypeAsString(paramDesc._type)), false)
		paramDir, err = wrapString((*C.SAP_UC)(C.RfcGetDirectionAsString(paramDesc.direction)), false)
		paramDefaultVal, err = wrapString((*C.SAP_UC)(&paramDesc.defaultValue[0]), false)
		paramText, err = wrapString((*C.SAP_UC)(&paramDesc.parameterText[0]), false)
		if err != nil {
			return
		}

		goParamDesc := ParameterDescription{
			Name:          paramName,
			ParameterType: paramType,
			Direction:     paramDir,
			NucLength:     uint(paramDesc.nucLength),
			UcLength:      uint(paramDesc.ucLength),
			Decimals:      uint(paramDesc.decimals),
			DefaultValue:  paramDefaultVal,
			ParameterText: paramText,
			Optional:      optional,
		}

		if paramDesc.typeDescHandle != nil {
			goParamDesc.TypeDesc, err = wrapTypeDescription(paramDesc.typeDescHandle)
			if err != nil {
				return
			}
		}

		goFuncDesc.Parameters = append(goFuncDesc.Parameters, goParamDesc)
	}

	return
}