# JD Edwards User Defined Codes Table SQL (F0004, F0005)

> Source: https://netray.co/tools/jde-f0005-udc-lookup-sql-generator
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Generate SQL that lists JD Edwards UDC types and values, decodes a code in a business table with the correct trim on DRKY, and reads alternate language descriptions.

## Category

developer

## Erp

JD Edwards EnterpriseOne

## Audience

- JDE developer
- Report writer
- CNC administrator

## Tool

**Kind:** template

**Output:** code

**Language:** sql

**Fields:**

#### Control tables schema

**Key:** ctl

**Type:** text

**Default:** CRPCTL

**Help:** UDCs live in the control tables data source (for example PRODCTL, CRPCTL, TESTCTL).

#### Business data schema

**Key:** dta

**Type:** text

**Default:** CRPDTA

#### Product code (DRSY)

**Key:** sy

**Type:** text

**Default:** 00

#### UDC type (DRRT)

**Key:** rt

**Type:** text

**Default:** DT

**Help:** 00/DT is document type.

#### Language preference code

**Key:** lang

**Type:** text

**Default:** F

**Help:** From UDC 01/LP.

**Blocks:**

#### 1. UDC types for a product code (F0004)

**Body:** SELECT t.DTSY  AS product_code,
       t.DTRT  AS udc_type,
       t.DTDL01 AS description,
       t.DTCDL AS code_length,
       t.DTCNUM AS numeric_flag,
       t.DTLN2 AS two_line_flag
FROM   {{ctl}}.F0004 t
WHERE  t.DTSY = '{{sy}}'
ORDER  BY t.DTRT;

#### 2. Values of one UDC (F0005)

**Body:** SELECT u.DRSY,
       u.DRRT,
       LTRIM(RTRIM(u.DRKY)) AS code,
       u.DRDL01 AS description_1,
       u.DRDL02 AS description_2,
       u.DRSPHD AS special_handling,
       u.DRHRDC AS hard_coded
FROM   {{ctl}}.F0005 u
WHERE  u.DRSY = '{{sy}}'
  AND  u.DRRT = '{{rt}}'
ORDER  BY LTRIM(RTRIM(u.DRKY));

#### 3. Decode a code in a business table (F0101 search type, UDC 01/ST)

**Body:** -- DRKY is CHAR(10) and short codes are stored right-justified with leading blanks,
-- while business columns such as ABAT1 are left-justified. Trim both sides.
SELECT a.ABAN8,
       a.ABALPH,
       a.ABAT1,
       u.DRDL01 AS search_type_description
FROM   {{dta}}.F0101 a
LEFT JOIN {{ctl}}.F0005 u
       ON u.DRSY = '01'
      AND u.DRRT = 'ST'
      AND LTRIM(RTRIM(u.DRKY)) = LTRIM(RTRIM(a.ABAT1))
ORDER  BY a.ABAN8;

#### 4. Translated description with fallback (F0005D)

**Body:** SELECT LTRIM(RTRIM(u.DRKY)) AS code,
       COALESCE(d.DRDL01, u.DRDL01) AS description
FROM   {{ctl}}.F0005 u
LEFT JOIN {{ctl}}.F0005D d
       ON d.DRSY = u.DRSY
      AND d.DRRT = u.DRRT
      AND d.DRKY = u.DRKY
      AND d.DRLNGP = '{{lang}}'
WHERE  u.DRSY = '{{sy}}'
  AND  u.DRRT = '{{rt}}'
ORDER  BY LTRIM(RTRIM(u.DRKY));

**Notes:** Works on Oracle and SQL Server (LTRIM/RTRIM and COALESCE exist on both). On IBM i use your library names in place of the schemas. Check the control tables data source name for your path code in OCM before running. Wrapping DRKY in TRIM stops index use; for large decode reports, materialise the trimmed UDC list first.

## Content

**Intro:** This generator writes four SQL queries against the JD Edwards EnterpriseOne user defined code tables: F0004 for UDC types, F0005 for values, a decode join from a business table, and F0005D for alternate language descriptions. It handles the right-justified DRKY key that breaks most first attempts.

**Sections:**

#### Where UDCs live in EnterpriseOne

**Body:** User defined codes are maintained in P0004A (Work With User Defined Codes) and stored in the control tables data source, not with business data. On a typical install that means schemas such as PRODCTL, CRPCTL and TESTCTL, one per path code, while F0101 or F4211 sit in PRODDTA or CRPDTA. F0004 holds one row per UDC type (product code DTSY plus type DTRT) with its code length DTCDL. F0005 holds the values: DRSY, DRRT, the code DRKY, descriptions DRDL01 and DRDL02, special handling DRSPHD and the hard-coded flag DRHRDC. F0005D holds translated descriptions keyed by language DRLNGP.

#### How to use it

**Body:** Set the control schema for the environment you are reporting on, the business data schema, and the product code and type you want (for example 00/DT for document types, 01/ST for address book search types). Query 1 lists every type under a product code with its length, useful when you are hunting for the right UDC. Query 2 lists values. Query 3 is the pattern for any decode join; replace F0101 and ABAT1 with your table and column and the 01/ST literals with that column's UDC. Query 4 returns the translated description when one exists and falls back to the base text.

**Bullets:**

- Find a column's UDC in the data dictionary (P92001), on the item's edit rule
- Hard-coded UDCs (DRHRDC = Y) are used by program logic; do not change their values
- Special handling codes drive logic in many programs, so report them too

#### The DRKY trap

**Body:** DRKY is a 10 character field. When a UDC's code length is shorter than 10, JD Edwards stores the value right-justified, so a document type OP sits in DRKY as eight blanks followed by OP. The same value in a business column such as F4211 SDDCTO is left-justified. A join of DRKY = SDDCTO returns nothing, which is why the generated SQL trims both sides. The cost is that the database cannot use the F0005 index on DRKY, which is fine for UDCs of a few hundred rows but worth a materialised lookup in a heavy report.

#### Common mistakes

**Body:** Querying the business data schema for F0005 often works by accident on a demo database and then fails in production where control tables are separate, so always point at the control tables data source. Second, people forget that each path code can have its own control tables, so a UDC added in CRP may not exist in production yet. Third, product codes are stored as four characters; comparing to the two character literal works on Oracle and SQL Server because trailing blanks are ignored in CHAR comparisons, but keep that in mind on other engines.

**Cta:** If you want people to ask JD Edwards questions in plain English and get answers with UDC codes already decoded, on your own servers, we can set that up.

**Faq:**

#### Which table holds JD Edwards user defined codes?

**Answer:** F0005 holds the UDC values and F0004 holds the UDC type definitions. Alternate language descriptions are in F0005D and alternate type descriptions in F0004D. All of them sit in the control tables data source for the path code, not in the business data schema.

#### Why does my join to F0005 return no rows?

**Answer:** Almost always because DRKY is stored right-justified with leading blanks for codes shorter than ten characters, while the business column is left-justified. Trim both sides of the comparison, as the generated query does, and make sure you query the control tables schema rather than the business data schema.

#### How do I see user defined codes in JDE 9.2 without SQL?

**Answer:** Use P0004A, Work With User Defined Codes, entering the product code and UDC type. From there you can also see the type definition, including code length and whether the code is numeric. Changing a UDC there writes to F0005 in the control tables data source for your environment.

#### What does the hard-coded flag DRHRDC mean?

**Answer:** When DRHRDC is Y, programs depend on the code values, so they must not be changed or deleted. You can usually change the description, but adding or removing values in a hard-coded UDC can break processing. Treat hard-coded UDCs as read-only configuration owned by Oracle's application logic.

## Search terms

jde user defined codes table, jd edwards udc table, jde 9.2 user defined codes, jd edwards reference table, jde f0005 table, jde f0004 table, jde drky join

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