Esempio n. 1
0
func wrapStructure(typeDesc C.RFC_TYPE_DESC_HANDLE, container C.RFC_STRUCTURE_HANDLE, strip bool) (result map[string]interface{}, err error) {
	var errorInfo C.RFC_ERROR_INFO
	var i, fieldCount C.uint
	var fieldDesc C.RFC_FIELD_DESC

	rc := C.RfcGetFieldCount(typeDesc, &fieldCount, &errorInfo)
	if rc != C.RFC_OK {
		return result, rfcError(errorInfo, "Failed getting field count")
	}
	result = make(map[string]interface{})
	for i = 0; i < fieldCount; i++ {
		rc = C.RfcGetFieldDescByIndex(typeDesc, i, &fieldDesc, &errorInfo)
		if rc != C.RFC_OK {
			return result, rfcError(errorInfo, "Failed getting field description by index(%v)", i)
		}
		var fieldName string
		fieldName, err = wrapString((*C.SAP_UC)(&fieldDesc.name[0]), strip)
		if err != nil {
			return
		}
		result[fieldName], err = wrapVariable(fieldDesc._type, C.RFC_FUNCTION_HANDLE(container), (*C.SAP_UC)(&fieldDesc.name[0]), fieldDesc.nucLength, fieldDesc.typeDescHandle, strip)
		if err != nil {
			return
		}
	}
	return
}
Esempio n. 2
0
func fillStructureField(typeDesc C.RFC_TYPE_DESC_HANDLE, container C.RFC_STRUCTURE_HANDLE, fieldName string, fieldValue interface{}) (err error) {
	var rc C.RFC_RC
	var errorInfo C.RFC_ERROR_INFO
	var fieldDesc C.RFC_FIELD_DESC
	cName, err := fillString(fieldName)
	defer C.free(unsafe.Pointer(cName))

	rc = C.RfcGetFieldDescByName(typeDesc, cName, &fieldDesc, &errorInfo)
	if rc != C.RFC_OK {
		return rfcError(errorInfo, "Could not get field description for \"%v\"", fieldName)
	}

	return fillVariable(fieldDesc._type, C.RFC_FUNCTION_HANDLE(container), (*C.SAP_UC)(&fieldDesc.name[0]), fieldValue, fieldDesc.typeDescHandle)
}