# JD Edwards C Business Function Skeleton Generator

> Source: https://netray.co/tools/jde-c-business-function-skeleton-generator
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Generate the .h and .c skeleton of a JD Edwards EnterpriseOne C business function that reads one table record by key, returns a value and sets an error correctly.

## Category

developer

## Erp

JD Edwards EnterpriseOne

## Audience

- JDE developer
- Technical consultant

## Tool

**Kind:** template

**Output:** code

**Language:** c

**Fields:**

#### Source name (upper case)

**Key:** src

**Type:** text

**Default:** B550001

#### Header file name

**Key:** hdr

**Type:** text

**Default:** b550001.h

#### Function name

**Key:** fn

**Type:** text

**Default:** GetAddressBookName

#### Data structure

**Key:** ds

**Type:** text

**Default:** D550001

#### Table

**Key:** tbl

**Type:** text

**Default:** F0101

#### Table header file

**Key:** tblh

**Type:** text

**Default:** f0101.h

#### Index ID constant

**Key:** idx

**Type:** text

**Default:** ID_F0101_ADDRESS

**Help:** From the table header file.

#### Key structure

**Key:** keyst

**Type:** text

**Default:** KEY1_F0101

#### Key column member

**Key:** keycol

**Type:** text

**Default:** aban8

#### Data structure key member

**Key:** dskey

**Type:** text

**Default:** mnAddressNumber

#### Column to return

**Key:** outcol

**Type:** text

**Default:** abalph

#### Data structure output member

**Key:** dsout

**Type:** text

**Default:** szNameAlpha

#### Error code (data dictionary)

**Key:** err

**Type:** text

**Default:** 0002

**Blocks:**

#### {{hdr}}

**Body:** #ifndef __{{src}}_H
#define __{{src}}_H

#include <jde.h>
#include <{{tblh}}>

/* Paste the typedef generated from {{ds}} (Data Structure Design, Create Type Definition). */
#ifndef DATASTRUCTURE_{{ds}}
#define DATASTRUCTURE_{{ds}}

typedef struct tagDS{{ds}}
{
  MATH_NUMERIC  {{dskey}};
  JCHAR         {{dsout}}[41];
  JCHAR         cErrorFlag;
} DS{{ds}}, *LPDS{{ds}};

#define IDERR{{dskey}}_1   1L
#define IDERR{{dsout}}_2   2L
#define IDERRcErrorFlag_3  3L

#endif

#if defined (JDEBFRTN)
   #undef JDEBFRTN
#endif

#if defined (WIN32)
   #if defined (WIN32)
      #define JDEBFRTN(r) __declspec(dllexport) r
   #else
      #define JDEBFRTN(r) __declspec(dllimport) r
   #endif
#else
   #define JDEBFRTN(r) r
#endif

JDEBFRTN (ID) JDEBFWINAPI {{fn}} (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDS{{ds}} lpDS);

#endif /* __{{src}}_H */

#### {{src}}.c

**Body:** #include <{{hdr}}>

/* {{fn}}: fetch one {{tbl}} record by key and return {{outcol}}. */
JDEBFRTN (ID) JDEBFWINAPI {{fn}} (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDS{{ds}} lpDS)
{
   ID            idReturnCode   = ER_SUCCESS;
   JDEDB_RESULT  idJDBReturn    = JDEDB_PASSED;
   HUSER         hUser          = (HUSER) NULL;
   HREQUEST      hRequest{{tbl}} = (HREQUEST) NULL;
   {{keyst}}    ds{{tbl}}Key;
   {{tbl}}         ds{{tbl}};

   /* Validate pointers */
   if ((lpBhvrCom == (LPBHVRCOM) NULL) || (lpVoid == (LPVOID) NULL) || (lpDS == (LPDS{{ds}}) NULL))
   {
      jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("4363"), (LPVOID) NULL);
      return ER_ERROR;
   }

   lpDS->cErrorFlag = _J('0');
   memset ((void *) &ds{{tbl}}Key, 0, sizeof ({{keyst}}));
   memset ((void *) &ds{{tbl}}, 0, sizeof ({{tbl}}));

   /* Get a database user handle from the calling environment */
   idJDBReturn = JDB_InitBhvr ((void *) lpBhvrCom, &hUser, (JCHAR *) NULL, JDEDB_COMMIT_AUTO);
   if (idJDBReturn != JDEDB_PASSED)
   {
      return ER_ERROR;
   }

   /* Open the table on the index we fetch by, all columns */
   idJDBReturn = JDB_OpenTable (hUser, NID_{{tbl}}, {{idx}}, (NID *) NULL, (ushort) 0,
                                (JCHAR *) NULL, &hRequest{{tbl}});
   if (idJDBReturn == JDEDB_PASSED)
   {
      MathCopy (&ds{{tbl}}Key.{{keycol}}, &lpDS->{{dskey}});

      idJDBReturn = JDB_FetchKeyed (hRequest{{tbl}}, {{idx}}, (void *) &ds{{tbl}}Key, (short) 1,
                                    (void *) &ds{{tbl}}, (int) FALSE);
      if (idJDBReturn == JDEDB_PASSED)
      {
         jdeStrncpy (lpDS->{{dsout}}, ds{{tbl}}.{{outcol}}, DIM (lpDS->{{dsout}}) - 1);
      }
      else
      {
         lpDS->cErrorFlag = _J('1');
         jdeErrorSet (lpBhvrCom, lpVoid, (ID) IDERR{{dskey}}_1, _J("{{err}}"), (LPVOID) NULL);
         idReturnCode = ER_ERROR;
      }
      JDB_CloseTable (hRequest{{tbl}});
   }
   else
   {
      idReturnCode = ER_ERROR;
   }

   JDB_FreeBhvr (hUser);
   return idReturnCode;
}

**Notes:** The typedef shown is an example: always generate the real one from your data structure in Object Management Workbench and paste it, so member names and lengths match. Take the index ID constant, the key structure and column member names from the table's generated header (for example f0101.h). Function and macro names follow the EnterpriseOne 9.2 Tools APIs; check the API reference for your Tools release if the build reports a signature mismatch.

## Content

**Intro:** This generator writes the header and source skeleton of a JD Edwards EnterpriseOne C business function (BSFN) that reads one record by key with JDB_FetchKeyed, returns a column to its data structure and raises a data dictionary error when the record is missing. It follows the 9.2 Tools API conventions for handles, Unicode strings and cleanup.

**Sections:**

#### How to create it in EnterpriseOne

**Body:** In Object Management Workbench add a data structure (D55xxxxx) with the key and output members, then a business function object (B55xxxxx) of type C, linking the function to that data structure. Use Create Type Definition on the data structure to get the typedef and paste it into the header, then replace the generated function body with this code. Build with BusBuild on the development client, test from a test application or the debugger, check in, and include the object in an update package so it reaches the enterprise server.

**Bullets:**

- Custom objects use system codes 55 to 59 so upgrades leave them alone
- The function name in OMW must match the C function name exactly
- Rebuild and redeploy the package after every change

#### What each API call does

**Body:** JDB_InitBhvr gets a user handle tied to the caller's environment and transaction, with JDEDB_COMMIT_AUTO for auto commit. JDB_OpenTable takes the user handle, the table NID, the index ID, an optional column list and count, an optional data source override and returns a request handle. JDB_FetchKeyed takes the request handle, index, key structure, the number of key fields to use, the record buffer and a lock flag. jdeErrorSet attaches a data dictionary error to a data structure member so the calling application highlights it. JDB_CloseTable and JDB_FreeBhvr release the handles on every path.

#### Worked example

**Body:** With the defaults, GetAddressBookName receives mnAddressNumber 4242, copies it into the F0101 key structure with MathCopy, fetches on index ID_F0101_ADDRESS and copies ABALPH into szNameAlpha with jdeStrncpy, bounded by the DIM of the target minus one for the terminator. If the address number does not exist it sets cErrorFlag to 1, raises error 0002 against the address number member and returns ER_ERROR, so an interactive form shows the error on the right field and a UBE can test the flag.

#### Common mistakes

**Body:** Forgetting JDB_CloseTable or JDB_FreeBhvr on an error path leaks handles and eventually hurts the call object kernel. Using strcpy or char instead of jdeStrncpy and JCHAR breaks Unicode builds. Passing the wrong number of keys to JDB_FetchKeyed silently fetches a different record on a multi-field index. Hand typing the typedef instead of generating it leads to size mismatches that crash at runtime. And for simple reads, consider whether an existing Oracle business function, a table I/O in Named Event Rules or an orchestration data request already does the job.

**Cta:** If you want developers and analysts to ask what a JD Edwards business function does, or where it is called, in plain English on your own servers, we can index your custom code for that.

**Faq:**

#### What is a business function in JDE?

**Answer:** A business function is reusable logic, written in C or in Named Event Rules, that applications, UBEs and orchestrations call through a data structure. Oracle ships thousands of them (for example the F0101 and F4211 master business functions). Custom ones are created in OMW with 55 to 59 system codes, built with BusBuild and deployed in packages.

#### When should I write a C business function instead of NER?

**Answer:** Use C when you need pointer work, caching, complex loops over many records, or APIs that Named Event Rules cannot call. Use NER for simple logic because it is easier to maintain and retrofit. Many teams default to NER and keep C for performance-sensitive or system-level code.

#### Where do I find the index ID and key structure for a table?

**Answer:** In the generated table header, for example f0101.h, which defines NID_F0101, the index ID constants (ID_F0101_ADDRESS for the primary index) and the key structures KEY1_F0101, KEY2_F0101 and so on, with lower case column members such as aban8. Open it from the include folder of your development client.

#### How do I debug a C business function?

**Answer:** Build it with debug information on the development client, attach the Visual Studio debugger to the client process that runs business functions, set a breakpoint and run the calling application. On the enterprise server, turn on jdedebug logging and read the jde and jdedebug logs for the call object kernel that ran it.

## Search terms

jde c business function, c business function in jde, business function in jde, jde business function documentation, business function jde learn, jdb_fetchkeyed example, jde bsfn template

---
Talk to an engineer: https://netray.co/contact?intent=erp_ai | Machine catalog: https://netray.co/agent/catalog.json
