How to write User Defined Script to calculate Discount?

I need to let the system to calculate a discount based on Sales Order Header - 4. Totals -Order Total.

The formula will be 5% * Order Total. I need to create a UDF, UDF_DISCOUNT,  under Sales Order Header - 4. Totals Tab to show this amount.

I don't know where I can find the "Order Total" field in system tables and how to write a UDS to achieve it.

Sage ERP 100 / MAS 200 4.5

Here is the script I wrote but it doesn't work:

UDF_PREPAY_DISCOUNT=0
AMT=0

retVal = oBusObj.GetValue("NonTaxableAmt",AMT)

retVal = oBusObj.SetValue("UDF_PREPAY_DISCOUNT",AMT*0.05)

Anyone can help?

Thanks,

Luke