1c set value type

Since we work with values \u200b\u200bin the program code, we periodically need to know their type. Type 1C is always indicated in the metadata for the details - in directories, documents.

Working with 1C types is often used:

  • Conditions in the program
  • Different actions depending on the type of 1C value in the "If ... Then ..."
  • Limitations when working in the interface
  • Prohibition or permission for the user to enter values \u200b\u200bof certain types of 1C in the field on the form.
  • Determining the actual parameter of a function / procedure
  • If a function / procedure parameter can be of any 1C type, then you need to define it in order to get the value correctly.

Type 1C can be obtained:

  • Determine the type of actual value 1C
  • Object values \u200b\u200bhave properties that indicate the allowed 1C type (for example, 1C types allowed in a table column, in a field on a form, in metadata) or methods that return these 1C types
  • From the metadata - you can get the 1C type as it is indicated in the metadata in the configurator.

Types of 1C can be divided into three types:

  • Basic types 1C
  • Types of 1C databases (reference, objects)
  • Types of 1C.

Definition of 1C type and comparison of 1C types

You can find out the type of 1C value using the TypeZnch (Variable) function

To understand what type of 1C this function returned - you need to specify the Type we need ("TypeName")

For example, the definition (comparison) of the type of a 1C variable:
If TypeVal (Variable) \u003d Type ("TypeName") Then

What types should I write for TypeName?

Basic types

Basic types of 1C - number, string, date, boolean.

For instance:

Znch \u003d 12; If TypeZnch (Znch) \u003d Type ("Number" "String") Then OtherwiseIf Znch \u003d Type ("Date") Then ElseIf Znch \u003d Type ("Boolean") Then EndIf;

Database types

1C stores data in a database, but not as separate records, but as objects.

Most of the stored objects (including: directories, documents, enumerations, business processes, tasks) are available as an Object (for editing and writing) and as a Reference (for reading). See References and Objects for details.

For instance:

Znch \u003d Reference books. Organizations. EmptyRef (); If TypeZnch (Znch) \u003d Type ( "DirectoryLink.Organizations") Then Else If Znch \u003d Type ( "DirectoryObject.Organizations") Then ElseIf TypeZnch (Znch) \u003d Type ( "DocumentLink.Arrival of Goods") Then Else If Znch \u003d Type ( "DocumentObject.Goods receipt") Then EndIf;

Registers can be of various types. Register type name is compound:
RegisterTypeAccessType.RegisterName

Types of 1C registers:

  • Information
  • Accumulation
  • Accounting departments
  • Calculation.

There are several types of register access. The most commonly used:

  • Record Set
  • List
  • Sample
  • Recording
  • KeyRecords.

Example:
IfTypeZnch (Znch) \u003d Type ("InformationRegisterList.RegisterName") Then
ElseIf Znch \u003d Type ("Accumulation RegisterRecordSet.RegisterName") Then
EndIf;

Types 1C

The 1C language allows you to work with a variety of objects created dynamically in the program, for example - an array, a list of values, a table of values, a structure ...

Such types of 1C are indicated by their name (in one word, without spaces). For instance:
If TypeZnch (Znch) \u003d Type ("Array") Then
ElseIf Znch \u003d Type ("ListValues") Then
EndIf;

Determination of the value of the 1C reference type

Work with all database objects (reference books, documents ...) is done through links. For example, if we want to make a props in the document - a reference book, then its type 1C will be "ReferenceLink. ReferenceName".

For instance:

Value \u003d Directories. Organizations. EmptyRef (); If Directories. TypeAllRefs (). Contains (TypeZnch (Value)) Then // this is a reference ElseIf Documents. TypeAllRefs (). Contains (TypeZnch (Value)) Then // this is a document EndIf;

Working with 1C types in a request

In a request, the 1C type can be checked in two ways.

To check the type of a field in a 1C 8.3 request, you can use the function of the TYPE VALUE query language (<Поле>).

WHERE TYPE VALUES (Table.Sum) \u003d TYPE (NUMBER)

TYPE (<Имя типа>) gets a type by its name. Primitive type names: Number, String, Boolean, Date. Reference type names are constructed according to the following principle: Document.RealizableServiceToys or Directory.Nomenclature.

SELECT Self-supporting turnover. Subconto1, Self-supportingTurnovers. Subconto2, Self-supportingTurnovers. Subconto3, Self-supportingTurnovers. AmountTurnover, CHOICE WHEN TYPE VALUE (Self-supportingTurnover. Subconto3) \u003d TYPE (Document. Sale of goods and services) THEN "Implementation" WHEN TYPE VALUE (Self-supportingTurnover. Subconto3) \u003d Sub-TYPE (Document. Receipt. . Expense Cash Order) THEN "RKO" OTHERWISE "Another document" END AS DocumentType of Settlements FROM Accounting Register. Self-supporting. Turnovers (& BeginningPeriod, & EndPeriod, Registrar, Account \u003d & Account6201,,,,) AS Self-supporting Turnovers For reference type fields, there is another way of checking using the REFERENCE operator.

CHOICE WHEN Self-supporting Turnovers. Subconto3 LINK Document. Implementation of goods and services THEN "Implementation" WHEN Self-supportingTurnover. Subconto3 REFERENCE Document. Receipt Cash Order THEN "PKO" WHEN Self-supportingTurnover. Subconto3 LINK Document. Expense Cash Order THEN "RKO" ELSE "Another document" END

Obtaining available types of 1C

A set of objects has a property, ValueType, which contains a list of 1C types:

Fat client form field
Form Elements.FieldName.Value Type
Field on a thin client form (exception: called AvailableTypes)
Elements.Fields.AvailableTypes
Column of value table, value tree
Form props
Selection element

How to work with this list of 1C types in the field. Value Type - see "Description of Types" in the "1C Language" section.

Working with types of 1C attributes in configuration metadata

When adding and editing attributes in the configurator, the programmer indicates the type (s) of 1C attributes. In the program code in the 1C language, you can get (find out) the type (s) of 1C props.

Basic methods:

Call the Metadata () method for the 1C object, which returns the metadata of a specific object and then work with the list of attributes (and attributes of the tabular section)

Use the global variable "Metadata", which returns all configuration metadata, and then go to the details of a specific object

Metadata.Documents.Incoming Goods.Attributes

The attribute has a property, Type, which contains the list of 1C types set in the configurator for this attribute.

How to work with this list of 1C types - see "Description of Types" in the "1C Language" section.

Specify filter of types 1C

For many objects, it is possible to specify a filter of 1C value types that can be used, for example:

List of Values \u200b\u200b(.Available Values)
Managed Client Form Field (.AvailableTypes)
Where the filter is not available for modification, it is possible to specify the filter in the object method. For example, a column of a table (tree) of values \u200b\u200bhas a Value Type and we cannot change it, but when adding a column using the Add () method, you can specify a list of available 1C types as the second parameter.

To specify a list of 1C types for a filter - a list of 1C types is used, how to work with it - see "Description of types" in the "1C Language" section.

Attention! This is an introductory version of the lesson, the materials of which may be incomplete.

Log in as a student

Log in as a student to access school materials

1C 8.3 query language for beginner programmers: functions and operators for working with types (TYPE VALUE, TYPE, REFERENCE, IS NULL, EXPRESS)

Let's remember that each attribute (property, field) of a dictionary, document or any other applied object has its own type. And we can see this type in the configurator:

In the query language, there is a whole class of functions and operators for working with attribute types. Let's take a look at them.

TYPE VALUE function

This function takes one parameter (value) and returns its type. For the props described in the picture (above) Tastehandbook Food will return the following:

Now let's look at the props Distinctive feature at the directory Cities:

You can see that this props can be of one of several types: Line, Directory.Tastes, Reference.Colors... This type of requisites is called COMPOSITE.

If we try to fill in the value of such a variable in 1C: Enterprise mode, the system will ask us what type of value the input will be:

And only after our selection will it allow us to enter the value of the selected type.

Thus, the elements of the directory of the same type ( Directory.Cities) can be stored in the same props ( Distinctive feature) values \u200b\u200bof different types (String, Colors or Tastes).

You can see for yourself by clicking on the elements of the directory Cities in 1C: Enterprise mode. You are reading an introductory version of the lesson, full lessons are found.

Here the value of the distinguishing feature is a directory entry Flavors:

Here with the line:

And here, in general, an element of the directory Colors:

This is what the composite data type offers us!

I wonder how the function will behave TYPE OF VALUE on the props Distinctive Elementwith a composite data type:

This is already very interesting. Let's deal with each line separately.

The distinctive attribute value type for the Russia element is NULL... This is the first time we come across this type. Values \u200b\u200bof this type are used solely to identify a missing value when working with a database.

This is so, because the element Russia is a group, and not an ordinary element of the directory Citiesso it has no field Distinctive feature... And the type of the missing value, as we read above, is always NULL.

The distinctive attribute value type for Perm is Flavors... Indeed, the value of the distinctive feature hammered in the database for the city of Perm is a link to an element of the directory Flavors.

For Krasnoyarsk, the feature type is Colors, because the value selected in the base is a link to a catalog item Colors.

For Voronezh, the feature type is Line, because the value entered in the database is a regular string.

India is a group again, so there is no meaning. And the type of the missing value, as we remember, is NULL.

Here's the thing. If you go to the element of the directory Cities with the name Sao Paulo, you will see that the field Distinctive feature not filled at all. It's empty. AND all empty fields of a composite type have a special meaningUNDEFINED .

FROM UNDEFINED we also encounter for the first time. Value UNDEFINED it is used when it is necessary to use an empty value that does not belong to any other type. This is exactly our situation. And the value type UNDEFINED, as you probably already guessed is NULL.

TYPE function

It takes only one parameter - the name of the primitive type ( LINE, NUMBER, DATE, BULEVO), or the name of the table whose link type you want to get.

The result of this construction will be a value of type Type for the specified type.

Sounds hazy, doesn't it?

Let's look at the application of this design and everything will immediately fall into place.

Suppose we need to select all directory entries Citieswith composite props Distinctive feature has a value of type LINE:

Now let's select all records that have props values Distinctive feature are links to directory items Colors (table Reference.Colors):

Retreat

As you remember, some of the elements of the directory Citiesdo not have props Distinctive feature... Function TYPE OF VALUE for such elements produces NULL.

How can you select such elements in a query? For this, a special logical operator is provided IS NULL (not to be confused with the function IS NULLwhich we'll look at below). You are reading an introductory version of the lesson, full lessons are found.

Here's an example of using it:

Excellent. But you noticed there is no Sao Paulo element here, props value type Distinctive feature which also issued NULL... Why did it happen?

And the thing is that the situation is for groups (Russia, India, Brazil), for which filling in the props Distinctive feature impossible in principle, since they do not have it at all, it differs from the situation for the Sao Paulo element, for which filling in the props is possible, but it is simply not filled in and is equal, as we remember, to a special value UNDEFINED.

To select all records that have the requisite Distinctive feature present, but not filled in, another construction should be used:

But comparison with UNDEFINED to define empty (unfilled) props will only work for composite types.

By the way, the logical operator IS NULL, the negation form looks like this:

Logical operator REFERENCE

For example, let's select from the directory Citiesonly those records that have a compound variable value Distinctive feature are a link to a directory item Flavors:

As you remember, we could solve the same problem using TYPE OF VALUE and A TYPE:

ISNULL function

The function is intended to replace the value NULL to another value.

We remember that the meaning NULL is returned if the requested attribute (field, property) does not exist.

Like props Distinctive feature for directory groups Cities:

Function IS NULL will help us display a different value in the event that this value is equal NULL... You are reading an introductory version of the lesson, full lessons are found. Let in this case it be the line "There is no such attribute!":

It turns out that if the first parameter of the function IS NULL not equal NULL, then it returns. If it is NULL, then the second parameter is returned.

EXPRESS function

This function is only intended for fields of a composite type. An excellent example of such a field is the property Distinctive feature the elements of the directory Cities.

As we remember, composite fields can be one of several types specified in the configurator.

For the field Distinctive feature such valid types are LINE, Reference.Colors and Directory.Tastes.

Sometimes it becomes necessary to cast the values \u200b\u200bof a composite field to a certain type.

Let's give all the field values Distinctive feature to type Reference.Colors:

As a result, all values \u200b\u200bof elements that were of type Reference.Colors,remained filled and were cast to the specified type. All values \u200b\u200bof other types ( LINE, Directory.Tastes) are now equal NULL... This is the peculiarity of type casting using the function To express.

You can cast a type either to a primitive type ( BULEVO, NUMBER, LINE, DATE) or to a reference type. You are reading an introductory version of the lesson, full lessons are found. But the type to which the cast is made must be included in the list of types for this composite field, otherwise the system will generate an error.

Take the test

Start test

1. Choose the most correct statement

2. Attributes that can take values \u200b\u200bof one of several types are called

3. To determine the type of the attribute value, the function

4. Unfilled complex type details are important

- classification of values \u200b\u200b(that is, data) by their type - strings, numbers, dates, etc. A value type is one of the basic concepts in any programming language.

Type conversion is the conversion of a value (data) from one type to another, for example from a string to a number or vice versa. A narrower concept of formatting a value is a conversion from any type to a string with conversion to a form that will be convenient for the user to read, including localization.

There are strongly typed languages. This means that when creating (defining) a variable, the programmer rigidly specifies what type of data it can store. The same with functions, procedure parameters, etc. In 1C metadata, the type of the details is strictly indicated (although there is a composite type - allowing you to specify several options). But in the program code in the 1C language there is no rigid typing, which means that you can create a numeric variable, then equate it to a string. The function can, depending on the parameters and conditions, return a number, or a boolean, or a string.

How to work with data types in the 1C language and how to convert 1C types?

1C value Undefined

Undefined is a 1C value, which means there is no value. Using this 1C value, you can "zero" variables, including for an implicit call of a destructor, for example, COM objects.
Variable1 \u003d New COMObject ("Excel.Application");
Variable1 \u003d Undefined;

A similar value 1C NULL, which a request can return when trying to get data from the database, if it was not possible to get such data (more precisely, the value in the NULL field means that the field in the database is "not filled").
Selection \u003d Query.Run (). Select ();
While Sampling.Next () Loop
If Sample.Field1 \u003d NULL Then
Proceed;
EndIf;
End of Cycle;

Types of 1C values

It is possible to use as "variables":

  • Variables created in the program text (by the methods described above)
  • Details of the metadata object or form (created in the configurator, indicating the exact type of 1C).

The props can have a composite type 1C, that is, several possible ones. In this case, the assignment of 1C value by the user can be two-stage:

  • Selecting the 1C value type from the available
  • Selection of 1C value.

By default, this variable has the value 1C Undefined. When the 1C type is selected, but the 1C value has not yet been selected, the empty value of this 1C type (0 for a number, an empty reference for 1C reference types, see below). And finally, then - the 1C value. From the program, the value is assigned directly, without an intermediate choice of the 1C type.

It is possible to determine the type of 1C value in several ways:
// method 1 - comparison with known types of 1C
Variable1 \u003d 12;
If TypeVal (Variable1) \u003d Type ("Number") Then
//…
ElseIfTypeVal (Variable1) \u003d Type ("ReferenceRef.Refname") Then
//…
EndIf;

Type conversion 1C

The 1C value of simple 1C types can be converted using the operator - 1C type names:
// in number
ZnNumber \u003d Number ("22"); // if it is impossible to convert 1C types, an error will be raised, therefore it is better to use an error handler (see below)

// to string
ZnchString \u003d String (22);
ZnchString \u003d SocrLP (22);
ZnchString \u003d Format (22, "ChG \u003d 0");

// on date
ZnchDate \u003d Date ("20120101120000"); //01.01.2012 12:00:00
ZnchDate \u003d Date (2012, 01, 01, 12, 0, 0);
ZnchDate \u003d Date (2012, 01, 01);

Conversion of 1C types - values \u200b\u200bof complex 1C types

Formatting 1C values

To specify the exact format, use the Format () function, with which it is possible to specify the required representation.
NumberString \u003d Format (2400, "Settings")

As the line "Settings" you need to specify the required 1C format. Such settings are indicated in a special encoded form. Let's take a look at the most commonly used settings:

1C date and number format according to the rules of different countries
If you need to display a date or number and do not want to bother with knowing how they should be presented according to the rules of the required country, there is a simple setting that will allow you to do this:
L \u003d Short Name of Desired Country

An example of a date display according to the rules of some countries:
Format (CurrentDate (), "L \u003d ru")
> 28.03.2012 14:21:32
Format (CurrentDate (), "L \u003d en")
\u003e 3/28/2012 2:21:24 PM
Format (CurrentDate (), "L \u003d fr")
> 28/03/2012 14:22:08

Date format in 1C language
If the default setting is not enough for you and you would like to specify the order of the date parts and the symbols for separating them yourself, you must use the setting:
DF \u003d "dmg chms"

Accordingly, "dmg" is the day, month and year, and "chms" are hours, minutes and seconds. You can skip any of these parts. The order is any. Characters specified between parts will be used as separation characters.

Date part symbol m b. is specified several times in a row, the type of this part of the date depends on it, for example "d" or "dd" or "dddd".

Decoding parts of the date:

  • d - day
    o small "d"
    o 1 to 4 times
  • M - month
    o big "M"
    o 1 to 4 times
  • y - year
    o small "g"
    o 1 or 2 or 4 times
  • h - hours
    o small "h" - 12 hour format
    o large "H" - 24 hour format
    o 1 or 2 times
  • m - minutes
    o small "m"
    o 1 or 2 times
  • s - seconds
    o small "c"
    o 1 or 2 times
  • cc - display AM / PM for 12 hour format
  • k - quarter.

An example of a date display indicating the rules:

Number format in 1C language
Unlike date formatting, which is simple enough, there are many options for number formatting. Here are the ones that are more commonly used.

The first "problem" is related to the default grouping of digits in numbers by 3 and separating the groups with a space, for example:
StringNumber \u003d String (22300500)
> 22 300 500

This is inconvenient when the number is converted to a string not for a nice and understandable display to the user, but for service needs. This can be influenced by the "CH" parameter, for example:

The parameter that allows you to round the number when displayed to the required number of digits after the decimal point "CDC":
Format (3.535353, "ЧДЦ \u003d" "2" "")
> 3,54

The parameter that allows you to specify the integer and fractional separator character "RHD":
Format (3.535353, "RRD \u003d" "." "")
> 3.535353

For some cases it is useful to be able to display something else instead of the number "0": an empty string or "not filled". This allows you to do the "CHN" parameter:
Format (0, "CHN \u003d" "" "")