1c request condition for an empty line. Where do they come from

What is meant by a line in 1c

Strings in 1C, how to distinguish a string from other types because in the module all the characters are text, and therefore a string. Each continuous set of characters surrounded by double quotes (“”) is considered a string; by default in the configurator it is black.

Report("Hello, world!");

You should also remember that some methods, both system and self-written, can return a string value.

To find out whether the value we are interested in is a string, we can compare its type with the type " Line":

If TypeValue("Some text") = Type("String") Then Report("Value type - String"); endIf;

There are several special functions for working with a string that convert other types to a string and vice versa. Here are some examples:

String to Number

Number("123.45");

Number("123.45");

If the parameter contains invalid characters, such as letters, this will cause an error.

String to Date

Date("20101220235959");

It is not necessary to indicate the time (last 6 characters).

Checking for empty string

EmptyString() – this function checks whether the string passed as a parameter contains significant characters (insignificant characters are mostly invisible on the screen: space, line break, etc.)

Empty line(" ");
EmptyString(" a ");

Number to String

Row(123.45); Format(1253.25);

To compare strings you can simply use the equal sign

If "Thursday" = "Thursday" Then
endIf;

The plus sign (+) is used to connect strings. Connecting strings in programming is called concatenation.

Cunning! If several different types of variables are added, the program will take the type of the first variable as a basis. Therefore, to accurately get a value of a string type, you can use the following notation:

SomeString = ""+Day of the Year(CurrentDate()) +Day of the Week(CurrentDate());

If you get the result from the previous listing, it will look something like this:

As you can see, there is not enough space separating the day of the year and the day of the week; to do this, you can add a space (“ ”) as follows:

SomeString = ""+Day of the Year(CurrentDate()) + " " +Day of the Week(CurrentDate());

Line break

To break a line, you can use either a newline character:

SomeString = ""+Day of the Year(CurrentDate()) + Symbols.PS +Day of the Week(CurrentDate());

or a straight line

SomeString = ""+Day of the Year(CurrentDate()) + " |"+Day of the Week(CurrentDate());

A string is one of the primitive data types in 1C:Enterprise 8 systems. Variables with the type line contain text.

Type variable values line are enclosed in double quotes. Multiple Variables of this type can be folded.

Per1 = "Word 1" ;
Per2 = "Word 2" ;
Per3 = Per1 + " " + Per2;

Eventually Per3 will mean " Word 1 Word 2″.

In addition, 1C:Enterprise 8 systems provide functions for working with strings. Let's look at the main ones:

EnterString(<Строка>, <Подсказка>, <Длина>, <Многострочность>) — the function is designed to display a dialog box in which the user can specify a value variable type Line. Parameter <Строка> is required and contains the name of the variable into which the entered string will be written. Parameter <Подсказка> optional - this is the title of the dialog box. Parameter <Длина> optional, shows the maximum length of the input string. Defaults to zero, which means unlimited length. Parameter <Многострочность> optional. Defines the multiline text input mode: True—multiline text input with line separators; False - enter a simple string.

You can enter a string if you know the character code in Unicode:

Symbol(<КодСимвола>) — the code is entered as a number.

Letter= Symbol(1103) ;

// I

There is also an inverse function that allows you to find out the code of a symbol.<Строка>, <НомерСимвола>) — SymbolCode(

returns the Unicode number of the specified character as a number.

Text case conversion functions:<Строка>) VReg( - converts all characters in a string to.

uppercase<Строка>) NReg(

— Converts all characters in a string to lowercase.<Строка>) TReg(

— converts all characters in the string to title case. That is, the first letters in all words are converted to upper case, and the remaining letters are converted to lower case.

Functions for searching and replacing characters in a string:<Строка>, <ПодстрокаПоиска>) Find(

— finds the character number of the occurrence of the search substring. For example:

Find ("String" , "oka" ) ;<Строка>, <ПодстрокаПоиска>, <НаправлениеПоиска>, <НачальнаяПозиция>, <НомерВхождения>) // 4 StrFind(— finds the character number of the occurrence of the search substring, the occurrence number is indicated in the corresponding parameter. In this case, the search begins with the character whose number is specified in the parameter

InitialPosition. Searching is possible from the beginning or the end of the string. For example: Number4 Occurrences = Str Find (

"Defensiveness"<Строка>, <ПодстрокаПоиска>, <ПодстрокаЗамены>) , "about" ,Search Direction. From Start, 1, 4);

// 7

StrReplace(<Строка>) – finds all occurrences of the search substring in the source string and replaces it with the replacement substring. StrReplace ("String" , "oka" , "" ) ;// Page Empty line(.

StrNumberOccurrences(<Строка>, <ПодстрокаПоиска>) – Calculates the number of occurrences of the search substring in the source string.

StrNumberOccurrences ( "Study, study and study again", "study" , "" ) ; // 3

StrTemplate(<Строка>, <ЗначениеПодстановки1>…<ЗначениеПодстановкиN> — substitutes parameters into a string by number. The line must contain substitution markers of the form: “%1..%N”. Marker numbering starts from 1. If the parameter value Undefined, an empty string is substituted.

StrTemplate ( "Parameter 1 = %1, Parameter 2 = %2", "1" , "2" ) ; // Parameter 1= 1, Parameter 2 = 2

String conversion functions:

A lion(<Строка>, <ЧислоСимволов>) – returns the first characters of a string.

Right(<Строка>, <ЧислоСимволов>) – returns the last characters of a string.

Wednesday(<Строка>, <НачальныйНомер>, <ЧислоСимволов>) – returns a string of length<ЧислоСимволов>, starting from symbol<НачальныйНомер>.

AbbrL(<Строка>) trims non-significant characters to the left of the first significant character in the string.

Abbr(<Строка>) — cuts off insignificant characters to the right of the last significant character in the line.

AbbrLP(<Строка>) – cuts off insignificant characters to the left of the first significant character in the line and to the right of the last significant character in the line.

StrGetString(<Строка>, <НомерСтроки>) – Gets a multiline string by number.

Other features:

StrLength(<Строка>) – returns the number of characters in the string.

StrNumberRow(<Строка>) – returns the number of lines in a multiline string. A line is considered new if it is separated from the previous one by a newline character.

StrCompare(<Строка1>, <Строка2> ) – compares two strings in a case-insensitive manner. A function works like an object Comparison of Values. Returns:

  • 1 - if the first line is greater than the second
  • -1 - if the second line is greater than the first
  • 0 - if the strings are equal

StrCompare("First line" , "Second line" ) ;

// 1 In 1C, checking for an empty value is carried out by a special function. To check whether your attribute or variable is filled in, you should use a function from the global context<Значение>) .

ValueFilled( In 1C 8, a value is considered filled (not empty) if it differs from the default value for a given type. For example, for a reference type the default value is Empty link (this reference book, document, etc.). Variables and details containing values ​​are also empty. Null Undefined.

And

1c check for empty value. Examples

Variable = Directories.Nomenclature.EmptyLink(); Check = ValueFilled(Variable); In this case the variable Empty line( Examination In 1C, checking for an empty value is carried out by a special function. To check whether your attribute or variable is filled in, you should use a function from the global context<Значение>) will contain the value

. Also function

. can be used directly in conditions.

Variable = Documents.AdvanceReport.FindByNumber("000000001"); Check = ValueFilled(Variable);

IN in this example, if the document Advance report with number 000000001 exists, then in the variable Check = ValueFilled(Variable); will contain the value StrReplace ("String" , "oka" , "" ) ;, otherwise Empty line(.

Use function ValueFilled not possible for variables of mutable types, such as Table of values, Tree of values and so on. The function works for all configurations.

How can you check that the table of values ​​in 1C is empty? For this purpose the method is used Quantity(), you can use it to check how many rows are contained in the table of values.

Example 3. Let MyTable— table of values ​​defined above in the code.

If MyTable.Quantity() = 0 Then Return; endIf;

The same method can be used to determine the fullness of the value tree and query result selection.

Example 4. Let MyTree— tree of values ​​defined above in the code.

If MyTree.Rows.Quantity() = 0 Then Return; endIf;

As you can see, in the value tree we check for the presence of first-level rows; if they are not there, then the tree is empty.

Example 5. Let Request— query to the 1C 8 database defined above.

When working with queries, any programmer has to interact with empty values ​​in one way or another. What do we mean by empty value?

A null value is either no value or the default value for the data type. With primitive types, everything is quite simple: the default value is some initial value that serves as a starting point.

Types of Null Values

Let's look at the types of empty values ​​that may be encountered or required in a query.

  • For the Number type, the empty value is zero – 0.
  • For the String type – an empty string – “”.
  • For the Date type – January 1st of the first year – 01/01/0001 00:00:00. It is from this date that time is counted in 1C.*
  • For the Boolean type, the default value is technically False, but logically both values ​​of the type are padded. Therefore, deciding whether an empty value is False or not is based on the logic of a specific algorithm.

*Be careful, there are outside 1C various systems calculating dates with different reference points.

The missing value fully corresponds only to the type Null. This type contains only one value, which indicates no value.

Similar type Undefined also contains only one value, but Undefined does not mean the absence of data, but only the impossibility of determining the default value for the type. Undefined is the default value for composite types, including those not explicitly defined. For example, a value in a new row of a value table in a column for which the type is not explicitly defined.

Co reference types there is much less uncertainty. All reference types provide a null value. An empty value is the same reference indicating the data type, but without a unique identifier for the specific value. Thanks to this, we can treat an empty link as if it were a regular one and apply all the methods provided by the platform to it, working with it as if it were a full-fledged value.

Working with Null Values ​​in a Query

Whether you need to explicitly enter a null value into a query result or compare existing values ​​to a null value, you need to know how to describe null values ​​in your query.

Types Number, String, Boolean are described in the request as in the built-in language:

SELECT 0 AS ExampleTypeNumber, "Hello world" AS ExampleTypeString, True AS ExampleTypeBoolean

Undefined, being essentially a primitive type, is described similarly:

Select Batch.Period From Accumulation Register.Batch As Batch Where Remains.DocumentBatch = Undefined

Empty reference values ​​are a little more difficult to define. All reference objects have a predefined service value of EmptyReference. Thanks to this, it is possible to select an empty link in a single way - through the Value function:

Select Value(Directory.Nomenclature.EmptyLink) How to Empty Nomenclature

The possibilities for working with Null values ​​are somewhat richer. Like other primitive types, Null is described in the same way as in the built-in language. In addition, there is a special operator Is Null and a function IsNull.

  • The Is Null operator allows you to create logical expression comparing the selected value with the Null value.
  • The IsNull function returns the first argument if it is not Null, and the second argument otherwise.

Expressions that define empty values ​​can be used in any query sections that support expressions. For example, you can add an empty link to the Select section or a Null check to the Condition.

Practical examples

Using the Value function

Select Products.Link As Nomenclature, Products.Link = Value(Directory.Nomenclature.EmptyLink) Like ThisLinkEmpty From TueProducts As TueProducts

Using the Is Null operator

Select Products.Link As Nomenclature, Products.Link Is Null Like This LinkEmpty From TueProducts As TueProducts

Null on left or full join

Checking for Null

The example demonstrates a common practical situation when, with a left join, there is no match for the first table in the second. In this case, all fields of the second table will be Null.

Select TueProducts.Link As Nomenclature, Remains.QuantityRemaining As Quantity, Remains.QuantityRemaining Is Null As NoRemaining From TueProducts as TueProducts Left Connection RegisterAccumulations.ProductsInWarehouses.Remains As Remains By TueProducts.Link = Remains.Nomenclature

Handling Null Values

Modification of the previous query to demonstrate a common technique for obtaining some default values ​​to replace missing ones. In this example, using the IsNull function, the missing remainder value is replaced with a logically correct 0.

Select TueProducts.Link As Nomenclature, IsNull (Remaining.QuantityRemaining, 0) As Quantity From TueProducts as TueProducts Left Connection RegisterAccumulations.ProductsInWarehouses.Remains As Remains By TueProducts.Link = Remains.Nomenclature

In this article, we looked at various types of empty values ​​and their properties, and studied ways to determine various types empty values ​​in queries, and in the practical part we were convinced of the ease of application of the material considered.



2024 wisemotors.ru. How it works. Iron. Mining. Cryptocurrency.