• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
      • Statement Format Symbols
      • Alphabetical List of Functions and Statements
      • List of Reserved Words
      • Deprecated Features
      • Declaration Statements
      • Symbol Functions
      • Item Functions
      • Array Object
      • Audio Object
      • Barcode and QR Codes
      • Case Object
      • Document Object
      • File Object
      • Freq Object
      • Geometry Object
      • HashMap Object
      • Image Object
      • List Object
      • Map Object
      • Path
      • Pff Object
      • SystemApp Object
      • ValueSet Object
      • Program Control Statements
      • Assignment Statements
      • Data Entry Statements and Functions
      • Batch Edit Statements
      • Numeric Functions
      • String Functions
      • Multiple Occurrence Functions
      • General Functions
        • Compress Function
        • Decompress Function
        • diagnostics Function
        • Encode Function
        • ErrMsg Function
        • ExecSystem Function (Desktop)
        • ExecSystem Function (Mobile)
        • ExecPFF Function
        • GetProperty Function
        • GetLabel Function
        • GetLanguage Function
        • GetSymbol Function
        • GetValueLabel Function
        • hash Function
        • htmldialog Function
        • InValueSet Function
        • Invoke Function
        • IsChecked Function
        • loadsetting Function
        • LogText Function
        • MaxValue Function
        • MinValue Function
        • paradata Function
        • PathConcat Function
        • PathName Function
        • savesetting Function
        • SetLanguage Function
        • SetProperty Function
        • SetValueSet Function
        • SetValueSets Function
        • Special Function
        • sqlquery Function
        • Stop Function
        • SysParm Function
        • tr Function
        • Trace Function
        • UUID Function
        • View Function
        • Warning Function
      • Date and Time Functions
      • External File Functions
      • Synchronization Functions
    • Templated Reporting System
    • HTML and JavaScript Integration
    • Action Invoker
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataViewer>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

ErrMsg Function

Format 1
i = errmsg(string_expʃ, argument1, ..., argument20ʅ)

         
ʃselect(caption1, fieldname1ʃ, ..., caption5, fieldname5ʅ)ʅ
         
ʃcase ‖ summaryʅ
         
ʃdenom = numeric_denomʅ;
Format 2
i = errmsg(msg_numʃ, argument1, ..., argument20ʅ)

         
ʃselect(caption1, fieldname1ʃ, ..., caption5, fieldname5ʅ)ʅ
         
ʃcase ‖ summaryʅ
         
ʃdenom = numeric_denomʅ;
Format 3
i = errmsg(string_expʃ, argument1, ..., argument20ʅ)

         
ʃselect(caption1, fieldname1ʃ, ..., caption5, fieldname5ʅ) ʃdefault(default_option)ʅ ʅ
         
ʃcase ‖ summaryʅ
         
ʃdenom = numeric_denomʅ;
Description
The errmsg function displays a message on the data entry screen (when used in a Data Entry application) or writes a message to the output listing file (when used in a Batch Edit application). If messages are defined via the message number msg_num, then those messages must be stored in a message file [.mgf]. msg_num can be a number or numeric expression.
Each argument is sequentially inserted into the error message. Arguments can be numeric or alphanumeric expressions, but the type of the argument must match the type of the receiving field in the message text. The maximum number of arguments is 20.
Some of the most common formatting options include (see Message Formatting Options for a complete list):
    %[n]d = Insert a number and display it as an integer
    %[n.d]f = Insert a number and display it as a decimal value
    %[n.d]s = Insert a text string
where "n" is the size of the field and "d" is the number of decimal places to show for a number.
Numbers are never truncated. Text strings are truncated only if ".d" is used.
If "n" is positive, the insert is right-justified in the size of the field. If "n" is negative, the insert is left-justified in the size of the field. If "n" is a positive number with a leading zero, the insert is right-justified in the size of the field and zero filled to the left.
When inserting a number, if "n" is preceded by a +, the sign of the number is always displayed.
numeric integerValue = 23456;

errmsg( "%d"       , integerValue);      //  23456
errmsg( "%-10d"    , integerValue);      //  23456
errmsg( "%10d"     , integerValue);      //       23456
errmsg( "%+10d"    , integerValue);      //      +23456
errmsg( "%+010d"   , integerValue);      //  +000023456
errmsg( "%-010d"   , integerValue);      //  0000023456
errmsg( "%f"       , integerValue);      //  23456.000000  Note the usage of %f


numeric decimalValue = 12.567;

errmsg( "%f"        , decimalValue);    //   12.567000
errmsg( "%-10.3f"   , decimalValue);    //   12.567
errmsg( "%d"        , decimalValue);    //   12           Note the usage of %d
errmsg( "%10.2f"    , decimalValue);    //        12.57
errmsg( "%10.3f"    , decimalValue);    //       12.567
errmsg( "%+10.3f"   , decimalValue);    //      +12.567
errmsg( "%+010.3f"  , decimalValue);    //   +00012.567
errmsg( "%010.3f"   , decimalValue);    //   000012.567
errmsg( "%10.5f"    , decimalValue);    //     12.56700


string stringValue = "abcdef";

errmsg( "%s"        , stringValue);     //   abcdef
errmsg( "%-10s"     , stringValue);     //   abcdef
errmsg( "%-10.3s"   , stringValue);     //   abc
errmsg( "%10s"      , stringValue);     //       abcdef
errmsg( "%10.3s"    , stringValue);     //          abc
The case and summary keywords give you some control over the output listing. By default, the output listing shows you messages case-by-case, and summarized by the number of times the message was triggered for the run (there is an optional denominator, described below). You can limit the output listing to only case-by-case reporting, or only summary reporting, by using these keywords.
The denom keyword allows you to specify a denominator, so that you can show percentages in the summary portion of the output listing. This is very useful for showing, for example, edit failure rates (and as such, this option is geared towards batch applications rather than data entry applications). In Format 1's Example 2 below, the output listing will show the number of times the head of household had more than one spouse, divided by the number of households processed during the run. Note that it is the responsibility of the application designer to write logic to put the proper values into the denominator variable.
The select keyword is used to give the option of specifying the field to go to in response to the error message. A button is placed on the error message window for each caption and fieldname pair specified as a select argument, with a maximum of 5 possible select argument pairs allowed. The caption will be displayed on the button. When a button is chosen, the system goes to the field specified by fieldname. If continue is used as the fieldname, the system proceeds to the next line of logic following the errmsg call. If a default_option is given, it will place the focus on the select option chosen when the message is presented. This is a good method to prioritize what option you want the user to make (reenter a value vs. continue for example). If a default_option is not given, no button will have the focus.
If you wish to split message text across two or more lines, refer to the Message Formatting Options page.
Return Value
The function returns the sequence number of the button pressed. When the select keyword is not used, the function will return 1, as only the "OK" button is presented to the user, corresponding to button #1 ("Cancel" is never presented, and so a code of zero is not possible).
When the select keyword is used, the function returns the sequence number of the button that was pressed, with the first button having the value 1. A maximum of 5 select argument pairs is allowed.
Format 1 Examples
Example 1
errmsg("Head of household is %d years old.", AGE);
Example 2
if count(PERSONS where RELATIONSHIP=2) > 1 then
   
errmsg("Head of HH has more than 1 spouse") denom = HH_COUNT summary;
endif;
Example 3
errmsg("Head of household is %d years old.  Age must be >= 12", AGE)
     
select("Go to RELATIONSHIP", RELATIONSHIP,"Go To AGE", AGE)
     
denom = PERSON_COUNT;
Format 2 Examples
OK = errmsg (1,"June",30,31);
where the message file contains the following entry:
1 %s has only %d days. You entered %d!
Note the errmsg call could have also been invoked as follows:
i = 1;
OK = 
errmsg (i,"June",30,31);
See also: Warning Function, Message Formatting Options, Message File (.mgf)