Having some issues using a charachter data type (EV01) in C BSFN

serenity_now

Active Member
Hi All,

I will be the first to admit I would never usually touch C Business Functions. However, I have to follow some guides / do some digging and create one that consumes an external web service by calling an Internal BSSV. This is working good, however, one of the return fields in my data structure is a character field, EV01. I can't seem to find any examples using a field like this, I have found math numeric, jdedate, strings but not these. I was hoping someone could help me out.

Here is the portion of code that that gets the EV01 value from the data structure of the BSFN. This takes the value and from what I understand from reading other examples it takes the character and sets it to a JCHAR variable szRecordWritten1or2[2] variable. This part works and if something is passed in I can access the value in my BSSV:

Code:
	/* Get the Record Written value element and set its value to passed in Record Written parameter */
	XRCSStatus = XRCS_getElementsByTagName(hRootElm, _J("CRecordWritten1or0"), &hElm,&nElmCount);
	if(XRCSStatus != XRCS_SUCCESS)
	{
		jdeVWriteLogEntry(_J("N5555"), __FILE__, __LINE__, 0, _J("XRCS_getElementsByTagName failed"));
		XRCS_freeParser(hParser);
		XRCS_freeDocument(hDoc);
		XRCS_freeElement(hRootElm);
		XRCS_terminateEngine();
		return ER_ERROR;
	}
	szRecordWritten1or0[0] = lpDS->cRecordWritten1or0;
	szRecordWritten1or0[1] = _J('\0');

	XRCSStatus = XRCS_setElementText(hElm[0],szRecordWritten1or0);
	if(XRCSStatus != XRCS_SUCCESS)
	{
		jdeVWriteLogEntry(_J("N5555"), __FILE__, __LINE__, 0, _J("XRCS_setElementText failed"));
		XRCS_freeParser(hParser);
		XRCS_freeDocument(hDoc);
		XRCS_freeElement(hRootElm);
		XRCS_freeElementArray(hElm,nElmCount);
		XRCS_terminateEngine();
		return ER_ERROR;
	}

This part is meant to return the value back to the DSTR, I can't get this to work.
Code:
if (jdeStricmp(elmName,_J("CRecordWritten1or0"))==0) {
					jdeStrncpyTerminate((JCHAR *)lpDS->cRecordWritten1or0, elmValue, lpDS->cRecordWritten1or0);
				}

For comparison sake, here is one that does work:
Code:
if (jdeStricmp(elmName,_J("sz-name-surname"))==0) {
					jdeStrncpyTerminate((JCHAR *)lpDS->szNameSurname, elmValue, DIM(lpDS->szNameSurname));
				}

Apologies if this is something I should know, but my exposure to C code is minimal and I am just using for the purpose of calling this web service. The error I get on compiling is
C:\E910\DV910\source\N5555.c(821) : warning C4047: 'function' : 'JCHAR *' differs in levels of indirection from 'JCHAR'
C:\E910\DV910\source\N5555.c(821) : warning C4024: 'jdeStrcpyFillAndTerminate' : different types for formal and actual
 
Last edited:
Assign a JCHAR variable: cVariable = _J('x');
Compare a JCHAR: if( cVariable == _J('x') || cVariable == cVariable2 )


The assumption in your code about szRecordWritten0or1 is that it is defined as a string (array of JCHAR).
There is no special function for string-to-JCHAR assigning/comparing. You have to understand that the code is trying to put a single character into the szRecordWritten0or1 string.

So they explicitly assign the first array element of the string ([0]) = lpDS->cRecordWritten;
Then they terminate the string by assigning the 2nd character (2nd array element [1]) of the string to null (_J('\0')). All strings need to be null terminated.

JCHAR strings are defined as JCHAR arrays (szTemp[21] is a 20-character string with an extra element for the null terminating character)

A JCHAR variable is kind of like a 1 character string array.

When you access a specific element in a string (szTemp[4], for instance, you are referring to one specific JCHAR element and that notation allows for JCHAR operations to be performed)
 
Last edited:
Thanks, I think I have gotten my head around this now! Was able to get things working once I understood some of these basics.
 
Back
Top