Displaying and Formatting Data

The basic function for displaying data in a map field is called show(). To call this function you specify the map and field to display into,a pointer to the data to be displayed, the data type: for example 'C','I', or 'N', the size of the data, and flags that format the data (for example you can choose to have numbers displayed in a fixed length with leading asterisks - this might be used for printing cheques).

As it would get rather tedious to have to call this function many times in a program, you can use the show_x() functions instead. These only have three parameters - the map and field number, and a third parameter which is either a pointer to data, or sometimes a data value. These functions don't have a parameter to format the data.

However, you can set the format using the global variable show_flags for all the show_x() functions except show_d(). You use the global variable showd_flags for the format of dates that you display with show_d().

The values that these global variables may take are documented with the show_x() function. The global variables show_flags and showd_flags are initially set to DEFAULT. It is usually a good idea to set the SKIP_MISSING_FIELD flag which means that DP4 will not generate a DP4 system error if the field cannot be found in the map. This means that a field that is no longer required can be removed from a program without the need for recompilation. show_flags and showd_flags may be set to any combination of the permitted values, for example:

show_flags = LEFT_JUSTIFY + BLANK_IF_ZERO +SKIP_MISSING_FIELD;

On the whole it is best not to specify format flags in a program, It is better to specify the format flags in the map instead. If a map does specify format flags these over-ride the ones in the program. One exception is that using LEFT_JUSTIFY is probably a good idea if you want to line up a lot of output data without having to set up an explicit format for every field in a map, and there is no point lining up numbers on the (possibly implied) decimal point.There are some aspects of formatting that can only be handled in a map. For example you can associate a "unit" with numeric fields. This is most often used to display a currency symbol, but you could also use it to display abbreviations for distances or weights.

The field input functions (askf_x() and inpm_x()) do not use show_flags or showd_flags. Instead they have their own global variables, scrn_flags and scrnd_flags. These take all the same flags as show_flags and showd_flags, and they take some additional flags detailing how the program should respond to certain special keys, as it described innext.

Displaying Text

Sometimes you may want to display some text in a program that is not database data. For example you might need to display the words "Credit" or "Debit" next to a money amount. If you want your application to be able to work in any language you must avoid hard-coding such words into your program. DP4 has a function show_attach() which can be used to display text from one map into a field on another map. Another common technique for handling this situation is to take the text from small "static data" tables on the database. On the SALESORD database the REGION and PAYMENT_MEDIA tables fit into this category. A disadvantage of storing descriptive text on the database is that it will cause problems if the system is to be run in multi-lingual countries such as Belgium or Switzerland.

Displaying Composite Fields

It is quite common for a system to need fields which are stored as several fields on the database, but which should look like a single field to the user. A similar situation is where a field is stored as something like AAABBBBCCC, but should be displayed as AAA-BBBB-CCC or similar. Part numbers might be a typical example of either type of field. DP4 does not yet support such fields as well as it might, but one way to deal with them is to write your own show function that uses map_attach() to attach a small map with the several fields needed to display the composite field, then displays the fields into the attached map, and finally "glues" the attached map onto the attached field. This type of processing is also common when displaying popup windows using the pick_record() function, to be discussed later.

In 4.6xx an alternate technique is to use "embedded data" which allows you to insert data into part of a text control.