Discrete ManufacturingFree referencePDF, Excel, Word exportMachining

Fanuc Macro B System Variables Reference

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.

Download:
VariableAreaMeaningAccessExample
#0
Null
Always empty, cannot be written
Read only
IF [#1 EQ #0] GOTO10
#1 to #33
Local
Local variables used inside a macro call or main program
Read/write
#1=5.0
#100 to #199
Common
Common variables, cleared on power off on most controls
Read/write
#100=#100+1
#500 to #999
Common (retained)
Persistent common variables kept after power off
Read/write
#500=12.5
#3000
Alarm
Raises a macro alarm, number plus message text
Write
#3000=1 (TOOL MISSING)
#3001
Timer
Millisecond timer that runs while power is on
Read/write
#101=#3001
#3002
Timer
Timer in hours that runs while the cycle start lamp is on
Read/write
#102=#3002
#3003
Control
Single block suppression and cycle start wait
Read/write
#3003=1
#3004
Control
Feed hold, feed override and exact stop control
Read/write
#3004=7
#3006
Message
Stops the program and displays a message to the operator
Write
#3006=1 (CHECK CLAMP)
#3011
Clock
Current date as YYYYMMDD
Read only
#103=#3011
#3012
Clock
Current time as HHMMSS
Read only
#104=#3012
#3901
Parts
Number of parts required
Read/write
#3901=100
#3902
Parts
Number of parts machined
Read/write
#3902=#3902+1
#4001 to #4022
Modal
Modal G code groups from the previous block
Read only
IF [#4003 EQ 90] GOTO20
#5001 to #5003
Position
End point of previous block, X Y Z in the workpiece system
Read only
#105=#5001
#5021 to #5023
Position
Current position in the machine coordinate system, X Y Z
Read only
#106=#5023
#5041 to #5043
Position
Current position in the workpiece coordinate system, X Y Z
Read only
#107=#5041
#5201 to #5203
Work offset
External workpiece offset X Y Z
Read/write
#5201=0
#5221 to #5223
Work offset
G54 work offset X Y Z
Read/write
#5221=-350.0
#5241 to #5243
Work offset
G55 work offset X Y Z
Read/write
#5241=-120.5
#5261 to #5263
Work offset
G56 work offset X Y Z
Read/write
#5263=-410.0
#5281 to #5283
Work offset
G57 work offset X Y Z
Read/write
#5281=0
#5301 to #5303
Work offset
G58 work offset X Y Z
Read/write
#5301=0
#5321 to #5323
Work offset
G59 work offset X Y Z
Read/write
#5321=0

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.

Make CNC programs searchable

Optional: a short discussion on linking NC programs and macros to parts, routings and revisions in your ERP.

Optional. The tool and every export work without this. No spam.

How to use the table

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

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

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.

  • 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

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.

Frequently Asked Questions

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

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?

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?

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?

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.

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.