# Infor LN DAL Script Template Generator

> Source: https://netray.co/tools/infor-ln-dal-script-template-generator
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Generate a Data Access Layer (DAL) script skeleton for an LN table with object hooks, a field check hook, a mandatory hook and error message handling.

## Category

developer

## Erp

Infor LN

## Audience

- LN developer
- Technical consultant
- Integration developer

## Tool

**Kind:** template

**Output:** code

**Language:** text

**Fields:**

#### Table code

**Key:** table

**Type:** text

**Default:** tdsls400

**Help:** Logical table code, e.g. tdsls400 (sales orders).

#### Package VRC

**Key:** vrc

**Type:** text

**Default:** B61C a7 cus1

#### Purpose

**Key:** purpose

**Type:** text

**Default:** Block saving a sales order without a sold-to business partner

#### String field to check

**Key:** field1

**Type:** text

**Default:** ofbp

**Help:** A string field of the table, e.g. ofbp (sold-to business partner).

#### Field to make mandatory

**Key:** field2

**Type:** text

**Default:** odat

#### Error message code

**Key:** msg_code

**Type:** text

**Default:** tdslsc0001

**Help:** A message code you created in your own VRC.

#### Author

**Key:** author

**Type:** text

**Default:** AJ

**Blocks:**

#### Header, include and declaration

**Body:** |******************************************************************************
|* DAL script for table {{table}}
|* VRC     : {{vrc}}
|* Purpose : {{purpose}}
|* Author  : {{author}}
|******************************************************************************
#include <bic_dal>

table	t{{table}}

#### Object hook: before.save.object

**Body:** function extern long before.save.object(long mode)
{
	| runs for every insert and update, from UI, AFS, BOD or import
	if mode = DAL_NEW then
		| checks only for a new record
	endif

	if isspace({{table}}.{{field1}}) then
		dal.set.error.message("{{msg_code}}")
		return(DALHOOKERROR)
	endif

	return(0)
}

#### Object hook: after.save.object

**Body:** function extern long after.save.object(long mode)
{
	| follow-up actions after the record is written, e.g. update a related table
	| do not commit here: the caller owns the transaction
	return(0)
}

#### Property hooks

**Body:** function extern long {{table}}.{{field1}}.check(long mode)
{
	| field-level validation, runs when {{field1}} is set
	if isspace({{table}}.{{field1}}) then
		dal.set.error.message("{{msg_code}}")
		return(DALHOOKERROR)
	endif
	return(0)
}

function extern boolean {{table}}.{{field2}}.is.mandatory()
{
	return(true)
}

**Notes:** Before shipping, open the standard DAL of a comparable table in Program Scripts / Libraries (ttadv2530m000) and the Data Access Layer chapter of the Infor ES Programmer's Guide for your Tools version, and confirm the hook signatures, the DAL_NEW constant, DALHOOKERROR and dal.set.error.message exactly as your version defines them. The string check uses isspace, so field1 must be a string field. Compile as script type DAL in your customer VRC and test both through the session and through an integration path (AFS or BOD).

## Content

**Intro:** This generator writes a DAL script skeleton for an Infor LN 10.x table: object hooks before.save.object and after.save.object, a property check hook, an is.mandatory hook and error handling through a message code. It is the place for rules that must hold however the record is written, which a UI script cannot guarantee.

**Sections:**

#### How to use it

**Body:** Enter the logical table code, your customer VRC, the string field you want to validate, a field to make mandatory and the message code you created for the error. Copy the blocks into a new script of type DAL for that table in Program Scripts / Libraries (ttadv2530m000), keep only the hooks you need and compile. The before.save.object hook shows the pattern every DAL check follows: test the condition, set an error message, return DALHOOKERROR; return 0 when the record is fine. The mode argument tells you whether the record is new or changed, so you can run some checks only on insert.

#### Where DAL logic runs

**Body:** LN introduced DAL 1 scripts in Baan 5.0 to keep integrity rules with the table instead of in each session. Object hooks replace the main.table.io sections of older program scripts. Because the DAL sits under every entry path, the same check fires for a user in the session, an AFS program, an inbound BOD through the LN business adapter and an exchange import. That is the reason to put data rules here rather than in a 4GL UI script, which only protects one screen.

**Bullets:**

- Object hooks: logic for the whole record on save or delete
- Property hooks: logic tied to one field, such as check and is.mandatory
- Script type in ttadv2530m000: DAL

#### Worked example

**Body:** With the defaults, the script refuses to save a sales order header in tdsls400 when the sold-to business partner (ofbp) is empty and marks the order date (odat) as mandatory. A user in the sales order session sees your message; an inbound Process.SalesOrder BOD gets the same message back in its acknowledgement; an AFS program receives it in its error string. When importing through the DAL, LN logs hook errors, but if a hook sets several messages only the first is logged, so make that first message specific.

#### Gotchas

**Body:** Never commit or abort a transaction inside a hook: the DAL runs inside the caller's transaction and a commit there corrupts the caller's unit of work. Keep hooks fast, because they run for every row of a mass update. Avoid user interaction in a DAL; there is no form when a BOD or import calls it. Test with both the UI and an integration path, since a rule that depends on session variables behaves differently without a session. Put customer DAL changes in your own VRC, document them, and diff them against the standard script before every upgrade.

**Cta:** If you want an assistant that reads and documents your existing DAL customizations on-prem before an upgrade, we can set that up on your own servers.

**Faq:**

#### What is a DAL in Infor LN?

**Answer:** The Data Access Layer is a script attached to a table that holds its integrity logic. It runs whenever the table is written through LN, regardless of whether the call comes from a session, AFS, a BOD or an import, which makes it the right place for rules that must always hold.

#### How do I return an error from a DAL hook?

**Answer:** Set a message with dal.set.error.message using a message code from your VRC, then return DALHOOKERROR from the hook. Return 0 when the check passes. Confirm the exact names in the Programmer's Guide for your Tools version, and use message codes rather than hard-coded text so the message can be translated.

#### Where is the Infor LN development guide for DAL?

**Answer:** The Data Access Layer chapter of the Infor ES Programmer's Guide covers hooks and functions in detail; Infor references it as a Support Portal knowledge base document. The LN online help also has DAL 1 and DAL 2 overview pages. LN Studio and the Tools sessions are where you edit and compile the script.

#### DAL script or 4GL UI script: which one?

**Answer:** Use the DAL for data rules that must hold on every entry path. Use the UI script for screen behaviour such as defaults, enabling fields and user prompts. Logic only in the UI script is skipped by BODs and imports, so integrations will create records your UI would have rejected.

## Search terms

infor ln dal, infor ln dal script, baan dal before.save.object, infor ln data access layer, dal.set.error.message, infor ln development guide, infor ln studio download

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