# Fanuc Macro B System Variables Reference

> Source: https://netray.co/tools/fanuc-macro-b-system-variables-reference
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

A lookup table of widely used Fanuc Custom Macro B variable numbers for offsets, positions, timers and alarms.

## Category

manufacturing

## Industry

Machining

## Audience

- CNC programmer
- Machinist
- Manufacturing engineer

## Tool

**Kind:** worksheet

**Mode:** reference

**Columns:**

#### Variable

**Key:** variable

**Type:** text

#### Area

**Key:** area

**Type:** text

#### Meaning

**Key:** meaning

**Type:** text

#### Access

**Key:** access

**Type:** text

#### Example

**Key:** example

**Type:** text

**Rows:**

**Variable:** #0

**Area:** Null

**Meaning:** Always empty, cannot be written

**Access:** Read only

**Example:** IF [#1 EQ #0] GOTO10

**Variable:** #1 to #33

**Area:** Local

**Meaning:** Local variables used inside a macro call or main program

**Access:** Read/write

**Example:** #1=5.0

**Variable:** #100 to #199

**Area:** Common

**Meaning:** Common variables, cleared on power off on most controls

**Access:** Read/write

**Example:** #100=#100+1

**Variable:** #500 to #999

**Area:** Common (retained)

**Meaning:** Persistent common variables kept after power off

**Access:** Read/write

**Example:** #500=12.5

**Variable:** #3000

**Area:** Alarm

**Meaning:** Raises a macro alarm, number plus message text

**Access:** Write

**Example:** #3000=1 (TOOL MISSING)

**Variable:** #3001

**Area:** Timer

**Meaning:** Millisecond timer that runs while power is on

**Access:** Read/write

**Example:** #101=#3001

**Variable:** #3002

**Area:** Timer

**Meaning:** Timer in hours that runs while the cycle start lamp is on

**Access:** Read/write

**Example:** #102=#3002

**Variable:** #3003

**Area:** Control

**Meaning:** Single block suppression and cycle start wait

**Access:** Read/write

**Example:** #3003=1

**Variable:** #3004

**Area:** Control

**Meaning:** Feed hold, feed override and exact stop control

**Access:** Read/write

**Example:** #3004=7

**Variable:** #3006

**Area:** Message

**Meaning:** Stops the program and displays a message to the operator

**Access:** Write

**Example:** #3006=1 (CHECK CLAMP)

**Variable:** #3011

**Area:** Clock

**Meaning:** Current date as YYYYMMDD

**Access:** Read only

**Example:** #103=#3011

**Variable:** #3012

**Area:** Clock

**Meaning:** Current time as HHMMSS

**Access:** Read only

**Example:** #104=#3012

**Variable:** #3901

**Area:** Parts

**Meaning:** Number of parts required

**Access:** Read/write

**Example:** #3901=100

**Variable:** #3902

**Area:** Parts

**Meaning:** Number of parts machined

**Access:** Read/write

**Example:** #3902=#3902+1

**Variable:** #4001 to #4022

**Area:** Modal

**Meaning:** Modal G code groups from the previous block

**Access:** Read only

**Example:** IF [#4003 EQ 90] GOTO20

**Variable:** #5001 to #5003

**Area:** Position

**Meaning:** End point of previous block, X Y Z in the workpiece system

**Access:** Read only

**Example:** #105=#5001

**Variable:** #5021 to #5023

**Area:** Position

**Meaning:** Current position in the machine coordinate system, X Y Z

**Access:** Read only

**Example:** #106=#5023

**Variable:** #5041 to #5043

**Area:** Position

**Meaning:** Current position in the workpiece coordinate system, X Y Z

**Access:** Read only

**Example:** #107=#5041

**Variable:** #5201 to #5203

**Area:** Work offset

**Meaning:** External workpiece offset X Y Z

**Access:** Read/write

**Example:** #5201=0

**Variable:** #5221 to #5223

**Area:** Work offset

**Meaning:** G54 work offset X Y Z

**Access:** Read/write

**Example:** #5221=-350.0

**Variable:** #5241 to #5243

**Area:** Work offset

**Meaning:** G55 work offset X Y Z

**Access:** Read/write

**Example:** #5241=-120.5

**Variable:** #5261 to #5263

**Area:** Work offset

**Meaning:** G56 work offset X Y Z

**Access:** Read/write

**Example:** #5263=-410.0

**Variable:** #5281 to #5283

**Area:** Work offset

**Meaning:** G57 work offset X Y Z

**Access:** Read/write

**Example:** #5281=0

**Variable:** #5301 to #5303

**Area:** Work offset

**Meaning:** G58 work offset X Y Z

**Access:** Read/write

**Example:** #5301=0

**Variable:** #5321 to #5323

**Area:** Work offset

**Meaning:** G59 work offset X Y Z

**Access:** Read/write

**Example:** #5321=0

**Notes:** Variable ranges, options and write access vary by control model (0i, 30i, 31i and others) and by machine tool builder parameters. Tool offset variables use different numbers depending on the memory type, so check the macro section of your control's programming manual before relying on any value.

## Content

**Intro:** Custom Macro B turns a Fanuc program into a small programming language with variables, loops and probing logic. The hard part is remembering which variable number reads what. This lookup lists the commonly used system variables for offsets, position, timers, alarms and counters.

**Sections:**

#### How to use the table

**Body:** Search for a variable number or a keyword such as G54, timer or alarm. The access column tells you whether a macro can write the value or only read it. Examples are written in the standard macro syntax where square brackets enclose expressions. Export the list to keep with your macro library.

#### Local, common and persistent variables

**Body:** Local variables #1 to #33 exist only inside the current macro level, and argument letters in a G65 call map onto them. Common variables #100 to #199 are shared across programs and cleared on power off on most controls, while #500 to #999 survive power cycles and are the safe place for counters and calibration values.

#### Reading and writing work offsets

**Body:** Work offsets are readable and writable through the #5221 series, with each additional work coordinate system 20 higher: G54 at 5221, G55 at 5241, and so on. This is how probing macros update G54 after finding a part edge. Always write offsets in the correct units and confirm that the offset write option is enabled.

**Bullets:**

- G54 starts at #5221, G55 at #5241
- The X, Y, Z axes are consecutive numbers
- Writing offsets needs the correct control option and parameters
- Test in single block with the machine locked first

#### Common mistakes

**Body:** Programmers often write to a variable that is read only, store a counter in a common variable that clears at power off, or assume a variable number from one control exists on another. Another frequent problem is forgetting that #3006 stops the program for operator action, so it should not be used for routine logging.

**Cta:** If your CNC programs and macro libraries are stored in file shares, we can show how they could be made searchable and linked to part and routing records.

**Faq:**

#### What is the difference between #100 and #500 variables?

**Answer:** Both are common variables shared between programs. On most Fanuc controls the #100 to #199 range is cleared when power is turned off, while #500 to #999 is retained. Use the retained range for counters and stored measurements.

#### How do I stop a program with a message?

**Answer:** Set variable #3006 to a number and put the message in parentheses, for example #3006=1 (CHECK PART CLAMPED). The control stops and shows the message to the operator. Use #3000 instead to raise a full macro alarm.

#### Which variable holds the G54 X offset?

**Answer:** G54 X is in #5221, Y in #5222 and Z in #5223. G55 starts at #5241, G56 at #5261, G57 at #5281, G58 at #5301 and G59 at #5321. External offsets begin at #5201.

#### Do Haas and Okuma use the same variables?

**Answer:** Haas macros are similar in style, but system variable numbers and options differ, and Okuma uses its own user task language. Treat this table as Fanuc specific and check the manual for other controls.

## Search terms

fanuc macro variables list, fanuc macro b system variables, fanuc 5221 work offset variable, fanuc #3006 message, fanuc common variables 100 199, fanuc persistent variables 500, custom macro b reference, fanuc macro variable table

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