Program language 1s. Language element description format

💖 Like it? Share the link with your friends

The built-in programming language for 1C:Enterprise programs is a programming language used in the 1C:Enterprise family of accounting automation software. This language belongs to the class of precompiled domain-specific languages. high level. Its execution environment is the 1C:Enterprise platform (including 1C:Accounting). Its visual development environment is called "Configurator" and is part of the 1C:Enterprise package.

The language supports command syntax in Russian and English language. Built-in language dialects for versions 1C:7.0, 1C:7.5 and 1C:7.7 are backward compatible with minor exceptions. Dialects for 1C:7x are compatible with 1C:8x in terms of basic operators, but they differ significantly in working with application objects, as a result of which it makes little sense to transfer code from the 1C:7x platform to the 1C:8x platform.

In its syntax, the 1C: 8 programming language is similar to the Visual Basic language. The platform provides a fixed set of main classes that are designed to solve typical problems in their application area. Some base classes:

  • Document,
  • Document journal,
  • Constant,
  • Treatment,
  • Report,
  • enumeration,
  • chart of accounts,
  • Handbook, etc.

From these base classes, you can create any number of derived classes using visual configuration tools. Moreover, there is no way to programmatically define a new class. Only an explicit step in class inheritance is allowed. Objects of derived classes are typically records in a database or collections of records. In terms of the 1C language, they are called metadata objects and form the so-called "Metadata Tree".

The types of these metadata objects are Business processes, Documents, Tasks, Processing, Reports, Plans of types of calculation and characteristics, Charts of accounts, Registers of accumulation, calculation and information, Directories. Projects written in 1C:Enterprise are called configurations. Sale, implementation and maintenance of 1C and its configurations is the main commercial activity of 1C partner firms.

There are also additional components that extend the main classes, allowing them to be freely created and modified. However, these components are not recommended by the developer for use. In practice, their use entails the rejection technical support by 1C and its partners.

So, for example, the 1C++ component extends the language by means of a full-fledged OOP. Its use expands the possibilities for configuring 1C. It is a free product distributed under the GNU GPL.

There is also a free 2C project that does not use proprietary modules from 1C or other software vendors. This is what is called "from scratch" an extensible core of a system similar to 1C, which is freely distributed under the GNU GPL license. "Built-in objects" 1C, such as registers and directories, are classes in it that are redefined by the application programmer.

Initially, the 1C language had the working name "1Sik", which was pronounced as "onesik". However, it quickly fell out of use in official sources. When this built-in language is mentioned in documents, it is now customary to call it "1C Programming Language". On this moment it does not have its own name, convenient for oral pronunciation. In the context of the discussion of the 1C:Enterprise package, it is often referred to simply as the "built-in language".

I would like to conclude the review with an example program that displays the traditional greeting for beginners learning a programming language:

Show("Hello World!");

This code will work in 1C:Enterprise version 7.7.

21.12.2010

Previous publications:

Even if you have previously studied other programming languages, for example, C ++, PHP, Java, it is worth remembering that 1C, although in many ways similar, still has many fundamental differences.

The most important thing in 1C is that you do not need to invent your own types of objects. All of them are already in the configuration.

Install the 1C technology platform on your computer and open a new or existing database in the configurator. For starters, you can absolutely use it for learning programming.

In the left part of the window, you will see a tree of configuration objects. These include documents, directories, registers, business processes, and more.

The data is also stored in the DBMS, but the developer usually does not work with it directly. With the help of the technological platform, the programmer already refers to the objects of the configuration or the infobase.

In 1C, as in many other programming languages, queries are very often used. similar to T-SQL. Requests can be written in both English and Russian, in other words, like the rest of the code.

Everything seems to be simple, but knowledge of a programming language is often not enough to work "in the field". The fact is that in most organizations using 1C, standard configurations are installed, and you need to know them.

In terms of work for 1C programmers, there are two main branches: a franchisee or work "for yourself" and work as a full-time programmer in the IT department of an organization. This choice depends on your preferences.

When working in a franchisee, freelancing or running your own business, payment will be piecework. There can be a lot of work and you need to give all your best. There is no cap on wages, and you can earn an impressive amount of money.

If you decide to freelance or open your own business, you will not need to “share” your earnings with anyone (except for the state and the freelance platform, of course). But in this case, it will be necessary to look for clients on your own.

If you still decide to get a job in an organization as a full-time programmer, then you will not depend much on the amount of work performed. In this case, there is some stability, but the salary bar is limited.

Of course, these two ways can be combined, working as a full-time programmer during the day and freelancing in the evenings.

What is good about 1C programmers is that you may not have a technical education (for example, you are an economist, accountant, etc.). To confirm your knowledge in front of clients or an employer, you can provide your 1C certificates.

There are various types of certificates, both by platform (for programmers) and by standard solutions. You can get them at 1C by passing an exam in the form of a test or a practical task.

Books on 1C

It is best to study 1C from books published by 1C. So to speak, from the source. Some of them come with standard configurations. You can also buy individual books.

The book "1C: Programming for Beginners" is intended for people who are far from programming, but who want to learn how to create their own solutions in 1C 8.3 from scratch.

"Hello, 1C" shows the simplest, basic possibilities for developing application solutions in the 1C:Enterprise 8 system.

The 101 Tips describe various ways solving the same problems.

The 1C Enterprise 8.3 Developer's Practical Guide is a very detailed guide that describes development techniques with simple and understandable examples. This book is one of the best for learning 1C programming.

This tutorial describes the query language from scratch for those who are not even familiar with SQL.

As a rule, the study of any programming language begins with an example of writing the first the simplest program(“Hello world!”). This is done in order to visually show the work with basic syntactic constructions. We will not make an exception to this common way of presenting material when learning a new development environment, and therefore our first article should be considered in the same vein. In it, we will analyze in detail the answers to the following questions regarding programming on the 1C:Enterprise 8 platform:

  • Where and with what help to write program code in the built-in 1C language?
  • What are program modules, what are the rules for working with them?
  • What is a variable, how to work with it, how and where to declare it?
  • What are the comparison, assignment, and conditional operators and how do you use them?
  • Boolean operations - what are they and how to work with them?
  • Why loops are needed and how to use them?

The article will be useful to all those who are not yet familiar with development on the 1C:Enterprise 8 platform, but want to learn how to program in 1C.

Applicability

The material is relevant for the platform "1C:Enterprise 8" editions 8.2. and 8.3.

Variables and Operators

In this article, we begin to study the built-in language 1C:Enterprise 8. The executable code is contained in program modules.

There are a fairly large number of modules that are designed to handle various events.

So, the user login is processed in one module, and the processing of the user clicking on a certain button is handled in a completely different one.

Thus, each module describes the behavior of the configuration at a certain point. The module contains, first of all, a variable declaration section. Those. we can declare some variables in a module.

In the future, they can be used in the procedures and functions of this module. If a variable is defined with the Export keyword, then it will be available outside of this module. Variable declaration line example:

Rem Warehouse, Division, Storekeeper Export;

After the declaration of variables, there is a section of procedures and functions.

Behind them is the section of the main program, which will be executed at the time of accessing this module.

For example, in the main program section, you can initialize variables, i.e. give them some initial values:

State=1;
NewExpression=2;
result=3;

A module can be thought of as a combination of different operators that perform different actions we need.

The operator separator is the character ";" (semicolon). This sign is a sign of the end of the operator. Those. operator can be written like this:

Result=100X200
+400
-600;

It doesn't matter how many lines the statement is on.

Of course, it is often more convenient and clearer to place the operator on one line, but sometimes the operators are quite long (the number of lines can reasonably reach several tens).

A semicolon can be omitted in the final statement of a given construction, for example, a procedure. Those. the following code will work:

Procedure CalculateValue()

InitialValue = 100;
IntermediateValue = InitialValue / 5;
FinalValue = InitialValue+IntermediateValue

EndProcedure

However, it is better to use a semicolon in the final statement. It is possible that over time the construction will be continued, and the final operator will no longer be final. We will have to specifically monitor this situation.

Variables are designed to hold some value of any data type. They are used for intermediate storage of information for processing.

In almost any software module that performs some action, there are various variables. Variable typing by values ​​in Platform 1C:Enterprise 8 is soft.

For example, a variable can contain a value of one data type, and a few lines later, another type:

Created = false;
Created = true;
Created =100;

In the first two statements, the value of the variables is boolean, and in the third it is changed to a numeric value. Those. typing depends on the value that is assigned to this variable.
Variables can be declared in two ways:

  • implicit method (the mention on the left side of the assignment operator describes this variable, there is no preliminary description of the variable with the word Variable, i.e. there is no special section of the declaration of variables);
  • explicit declaration of variables (Variable ControlData;). An explicit declaration of variables is used, for example, if the subsequent transfer of this variable to a function is expected.

For the names of variables, the classic description of the identifier is used. The identifier consists of letters, numbers, and underscores. An identifier must begin with either a letter or an underscore.

In this case, the name of the variable should reflect the meaning of this variable. Single-letter variable names (such as A, B, C) are bad examples. They do not reflect the essence of the variables.

Examples of correct variable names: Counter (incrementing variable for the loop), Contractor. If the variable name contains several words, then each new word, for clarity, should begin with a capital letter.

Reserved words, such as Procedure, Function, Loop, EndCycle, etc., cannot be used in variable names. (these constructs are highlighted in red in the program module).

Reserved words are built-in language operators and there are quite a few of them. All of them are presented in Syntax Assistant.

It should be noted that data types are not reserved words (for example, Array, Boolean, True, False). The system will perceive such variable names correctly.

For writing program code, case does not matter. For example, the word Procedure can be written with both capital and small letters. Moreover, uppercase and lowercase letters can be interleaved within a word.

It doesn't matter to the Platform. However, according to the rules of good manners, the beginning of a word must be written with a capital letter, all other letters in small letters.

About the language. You can use both Russian and English, and a combination of two languages. If it is convenient for someone, you can safely use English to write program code, as well as combine Russian and English. It doesn't matter to the platform.

Many names in English are quite difficult to remember. When using a combination of two languages, the readability of the program code deteriorates.

Boolean operations

Comparison operators very often use Boolean logic that returns True or False.

For example, in a conditional operator, you can compare: If Event = Sale Then the algorithm will go along one branch (ie, if the value is True), according to the False condition, another branch of the algorithm is executed.

Conditions can be quite complex, they can be combined, using the following operators: AND, OR, and NOT. So, for the AND operator:

Truth AND Truth = True;
True AND False = False;
False AND True = False;
False AND False = False.

For the OR operator, it is enough that one of the operands is equal to True, then the value of the combination will be True. The value is False only if both operands are False.

The NOT operator simply inverts the current value (False to True, True to False).

Using a combination of these operators, you can build quite complex conditions. When composing complex conditional statements, take precedence into account.

The NOT operator has the highest precedence, followed by the AND operator, followed by the OR operator. Anything enclosed in parentheses has the highest precedence and is executed first.

For example, let's prioritize (execution sequence) for the operations in the above expression:

NOT(Condition1 OR Condition2) AND Condition3 OR Condition4
1.Result1 = (Condition1 OR Condition2);
2. Result2 = NOT Result1;
3. Result3 = Result2 AND Condition1;
4. Result = Result3 OR Condition4;

There is a conversion rule:

NOT (Condition1 OR Condition2) = NOT Condition1 AND NOT Condition2.

However, one should not always strive to simplify the expression, since often, logically, the expanded expression is easier to read.

assignment operator

The assignment operator should not be confused with equality, even though they have the same spelling.

The principle of the assignment operator is such that the left value (the variable on the left side) is assigned the value that is to the right of the equal sign. Let's take an example:

Variable1 = Variable2 = Variable3;

Variable1 is assigned the value of equality from Boolean logic, i.e. True if Variable2 = Variable3, or False otherwise.

When testing for the position of a novice programmer, the task is often used: to swap the values ​​of two variables in places.

This problem is solved using the assignment operator and has two solutions.

Solution #1 using temporary variable:
TempVar = Variable1;
Variable1 = Variable2;
Variable2 = TempVariable;

Solution #2:
Variable1 = Variable1 + Variable2;
Variable2 = Variable1 – Variable2;
Variable1 = Variable1 – Variable2;

Conditional operator

There is such an operator If, after which it is necessary to describe some condition (the condition itself can be quite large). The condition is followed by the word Then and the statements to be executed.

This may be followed by the keyword Else and a series of other statements. If there are several different conditions, you can use a series of keywords ElseIf(see example below). The whole structure must be completed with the keyword EndIf followed by a semicolon.

In addition to the simple and multiple conditions, there is an abbreviated form of the conditional operator: ?(Condition, Expression1, Expression2);

If the condition is true, then the Expression1, otherwise - Expression2. Code example: ExpensiveItem = ?(Item.Price>100000, True, False);

In practice, instead of comparison records with the value True (Lie) type:

If Variable = True Then
and
If Variable = False Then

the equivalent notation is actually used:

If Variable Then
and
If NOT Variable Then

Cyclic Operators

For any kind of cycle, an explicit indication of the end of this cycle is required using keyword EndCycle. There are several types of cycles.

Cycle by counter- a cycle with a fixed number of repetitions. The condition for exiting the loop is that the limit value has been exceeded. An example of using to calculate the value of A!

A = 5;
Factorial = 1;
For Counter = 1 By A Loop
Factorial = Factorial * Counter;
EndCycle;

Loop by condition– is executed while the condition of this cycle is true. Example:

RemainderSum = 1000;
Additional Item Price = 243;
Quantity = 0;
While RemainingAmount>0 Cycle
Quantity = Quantity+1;
Remaining Amount = Remaining Amount - Quantity * Price of Additional Goods;
ExtraItem Price = ExtraItem Price * 0.8;
EndCycle
Quantity = Quantity-1;

This loop calculates how many units of a product can be bought for a given amount (1000 rubles) if, after purchasing each unit of a product, its previous price is multiplied by a factor of 0.8. The initial price of the goods is 243 rubles.

An example of a mistake when using this type of loop by beginners is an eternal loop, when the loop condition is initially true, but within the loop itself it does not change in any way.

Loop through collections (another name is For each).

The Platform has a fairly large number of collections (these are containers that contain elements of a certain type).

You can iterate over the elements of a collection using a special kind of loop.

For example, there is an array of numbers, you need to calculate the sum of all elements of the array:

Sum = 0;
For Each Element From Array Loop
Sum=Sum+Item;
EndCycle;

There are special operators for loops: Continue and abort.

If, at some point in the loop, the execution of further statements of this loop becomes meaningless, then the operator is used to return to the beginning of the loop and organize its next loop. Continue.

Operator abort allows the loop to end even if the loop condition is true.

This concludes our first acquaintance with the development in the internal language of 1C.

What about Hello World? We haven't written it yet, have we? Yes, but nothing prevents you from doing it yourself, because. knowledge is already enough. Well, if that doesn't work, you can look here.

1. What is the language 1c.
2. Methods, variables, other language constructs.

What is language 1c.

Any programming language is designed to tell the program to perform the actions we need. Writing code is like writing instructions, in which we tell you what to do and in what order. All executable configuration code can only be in modules, consider the main 4 types:

1. application module

2. common modules

3. object module

4. form module.

AT different types code modules are executed at different stages of program execution. In the application module, the code can be executed when the program is started or closed, in common modules when called from other modules, in the object module - during actions on the object (creation, modification, deletion), in the form module - during actions on the form. What can be used when writing code:
Variables, objects and their details, methods created by us (1C programmers) and system methods (embedded in the platform), as well as built-in language constructs.

Methods, variables, language constructs

Variables used to store data during a user session. A variable is a word that begins with a letter (Russian or English) or with an underscore "_" and consists of letters, numbers and underscores.
For example :

  • This is a variable
  • _This is a variable
  • _This1_Variable

The fact that letters can be Russian and English can play a cruel joke when using similar letters from different languages.

The case of letters in the code is not taken into account, i.e. variables "Variable1" and "VARIABLE1" when executing the code for the program are the same. It is desirable that the names of the variables are meaningful. This improves the readability of the code.

Objects and props are read and modified while working on the data.
An object is a set of data grouped according to a certain attribute. Typically, objects in information base it is a reflection of documents, lists of data, enumerations of the material world. Object attributes, in fact, store data.

For example: Object "Commodity receipt No. 00018 dated 01/01/2005".
We can distinguish this sales receipt from other sales receipts by the details it contains. This is the "Number" attribute with the value "00018" ( string type ) and the attribute "Date" ( date type ) with the value "01/01/2005". The only thing that we could determine by the object, without knowing the values ​​of its details, was its type "Commodity receipt".
Methods are small and usually complete instructions.

For example, the system method "CurrentDate ()" From the name it is clear that it will return the current date of the computer. Or let's say you can create a method " StringContainsDigit(CheckedString)" which will return the answer True or Lie, here we pass parameters in brackets i.e. data operating on which the method should do some action. Both considered methods are functions; there are also methods-procedures in the language. There is only one difference between them. A function must return a value.

Other language constructs (operators, collections of values, etc.) are words reserved by the 1c system that help to manipulate data.

For example :

For each CollectionItemFromCollectionName Loop EndLoop;

The example shows the construction of iterating over the elements of a collection. This construction is called cycle . Most object types, as well as their props, are collections, which can be iterated over in the above way and accessing an element of the collection by specifying its index (CollectionName [ 0] ). All collections start with an element whose index is 0.

tell friends