FANUC codes
FANUCProgram/G-codeIntermediate10-20 minutes

126

Fanuc Alarm 126 - Invalid Function Argument

Illegal Argument

Fanuc program alarm 126: Illegal Argument. The part program contains an error or illegal condition that the Fanuc control cannot execute. Correct the program to clear this alarm.

Root Cause Summary

Fanuc Alarm 126 occurs when a custom macro program contains DO-END loop structures with loop numbers that are either mismatched, duplicated, or outside the valid range of 1 to 3. This alarm is specific to macro B programming and indicates the CNC control has detected an illegal loop identifier during program execution or verification.

Safety

  • Function failed

Causes and Fixes

  1. 1

    Enter EDIT mode and search the active program for all DO statements. Look for DO4, DO5, or higher numbered loops (e.g., DO4, END4).

  2. 2

    Verify each DO statement has a corresponding END statement with the same loop number. Valid syntax: DO1...END1, DO2...END2, DO3...END3 only.

  3. 3

    Correct any loop numbers exceeding 3 by restructuring the macro logic or consolidating nested loops to stay within the three-level limit.

  4. 4

    Reset the alarm using the RESET key and run the program in single block mode to verify proper loop structure execution.

DIY Feasiblehigh confidence

Call a technician if:

  • ·Complex nested macro logic requires restructuring
  • ·Program was working previously and alarm appeared without program changes
  • ·Multiple related alarms occur simultaneously

Prevention

  • Always use structured programming with proper indentation for DO-END loops
  • Comment complex macro logic for future troubleshooting
  • Test macro programs thoroughly in single block mode before production use
  • Maintain backup copies of working macro programs

Common Mistakes

  • Using DO0 or DO4+ thinking more loop numbers are available
  • Copying DO-END blocks without updating loop numbers
  • Using GOTO statements that skip over END statements
  • Editing programs while they're selected for execution

Related Alarms

Seeing Multiple Alarms?

Seeing another alarm with this one? Enter the code.

Get machine-aware diagnosis

AxisMD logs alarms against your actual machines, tracks patterns, and gives AI context your manual doesn't have.

Start free

Was this guide helpful?

Always verify with your machine manual or a certified technician before performing service procedures.