How to Write a C Business Function to Return a Special Character
Purpose of Document
To manipulate string or text values you need to make use of special characters available, which can be accomplished only by C programming. This document is a simple example of how a C business function can be written to return a special character.
NOTE: The following example is provided as is, Oracle does not provide warranty and is not responsible for any issues with using this example. This information is provided as an example only.
User must be proficient in C++ programming in order to use the information in this document.
In C library, the standard "string" library contains many useful functions to manipulate strings (referenced by K & R C Programming Language). Some of the most useful functions are:
char *strcpy(s,ct) -> copy ct into s, including ``\0''; return s
char *strncpy(s,ct,n) -> copy ncharcater of ct into s, return s
char *strncat(s,ct) -> concatenate ct to end of s; return s
char *strncat(s,ct,n) -> concatenate n character of ct to end of s, terminate with ``\0''; return s
int strcmp(cs,ct) -> compare cs and ct; return 0 if cs=ct, <0 if cs0 if cs>ct
char *strchr(cs,c) -> return pointer to first occurrence of c in cs or NULL if not encountered
size_t strlen(cs) -> return length of cs
(s and t are char*, cs and ct are const char*, c is an char converted to type int, and n is an int.)
Refer to the attachment "Unicode Cookbook Documentation.doc" from <Document 626598.1> - E1: BSFN: Unicode and C Business Functions to get a list of JDE APIs which makes use of the standard "string" library functions.
This document mainly cover concatenation as below:
Function
Standard Library
Used for
JCHAR *jdeStrcat(JCHAR *d, const JCHAR *s)
Strcat
Concatenate one Unicode string with another
JCHAR *jdeStrncat(JCHAR *d, const JCHAR *s, int n)
Strncat
Concatenate one Unicode string with another, stopping after n characters (Note, this is characters not bytes).
C representation of special characters,
Five white space characters:
Space (' ' )
Horizontal tab ('\t')
Form feed ('\f')
Vertical tab ('\v')
New-line character ('\n')
And control characters:
New-line character (represented by '\n' in the source file),
Alert (bell) tone ('\a' )
Backspace ('\b' )
Carriage return ('\r' )
Null character ('\0' )
NOTE:
The null character is a byte or wide character with all bits set to 0. It is used to mark the end of a character string. In C, a string is treated as a Character Array so to indicate end of character array is important.
The new-line character splits the source character stream into separate lines for greater legibility and for proper operation of the pre-processor.
In C, a single quotation(' ') is the instruction for a character and double quotation (" ") is the instruction for a string
To implement this, 1. Create a data structure with a data dictionary item with data type character (e.g., EV01)
2. Create a C function (this is an important step because currently system function concat() only accepts string argument. For example, f(s) concat ("string", "string") so if we assign parameter '\r' for example the output will be 'string\r'. That is, '\r' is recognized as "\r".)
switch(lpDS->cReturnType) { case _J('1'): lpDS->cCharacter = _J('\t'); /* Horizontal tab */ break; case _J('2'): lpDS->cCharacter = _J('\f'); /* form feed */ break; case _J('3'): lpDS->cCharacter = _J('\v'); /* Vertical tab */ break; case _J('4'): lpDS->cCharacter = _J('\n'); /* New-Line Character */ break; case _J('5'): lpDS->cCharacter = _J('\a'); /* Alert Tone */ break; case _J('6'): lpDS->cCharacter = _J('\b'); /* Backspace */ break; case _J('7'): lpDS->cCharacter = _J('\r'); /* Carriage Return */ break; case _J('8'): lpDS->cCharacter = _J('\0'); /* NULL Character */ break; }
3. Compile it 4. If needed call it from Report Design Aid (RDA), Form Design Aid (FDA) or Named Event Rule (NER)
NOTE:
Do not misuse special character or use it only when your concern is how to display text or string
To convert character to string make use of existing standard business function B9800460 - ConvertCharacterToString (Convert Character to String)
Oracle is not responsible for any problems caused by custom code.
Oracle Global Support does not support creation of or troubleshooting of custom code.