The 1C programming language is a traditional greeting for beginners.

Login to the site as a student

Internal programming language 1C 8.3 for beginner programmers: installation of 1C and your first program in 1C language

If you haven't read the introduction to the lessons, please read it: .

Installation of the educational version of 1C

To learn programming we need 1C 8.3 (not lower 8.3.13.1644 ) .

If you have 1C version 8.3 installed, use it. If not, download and install the educational version, which 1C produces specifically for educational purposes.

Task No. 1: download and install the educational version of 1C 8.3.

After completing Task No. 1, the following shortcut should appear on your desktop:

Congratulations! The 1C platform is installed and very soon you will be able to write your first program.

First program

This has already become a tradition for programmers - studying new language, the first thing they write on it is a program that prints the phrase “Hello, World!” on the screen.

We will not be an exception. But, being Russian programmers, we will force the computer to display the phrase “Hello, World!” on the screen.

Task No. 2: write a program in 1C 8.3 language that, when launched, displays the phrase “Hello, World!” on the screen.

Instructions to follow:

1. Launch the "1C:Enterprise" shortcut on your desktop.

2. A list of 1C databases has opened in front of you. As you can see, it is empty. Let's create a training base in which we will program. Click " Add".

3. Select " Creating a new information base" and click the " button Further".

4. Select " Creating an infobase without configuration..." and click the " button Further".

5. Specify " Educational" and click the " button Further".

6. Specify any empty folder as the database directory (in in this case This is the "Study" folder in my documents). Click "Next".

7. Specify the authentication option " Select automatically", startup mode" Fat client". Do not specify anything as the 1C:Enterprise version, click the "Finish" button.

8. As you can see, the first database that we just created ourselves has finally appeared on the list! Let's start writing code. Click " Configurator".

9. In the window that opens, select from the menu " Configuration"->"Open configuration".

10. In the panel that opens on the left, click right click mouse on the word " Configuration" and select from the list " Open a managed application module".

11. A window with the editor has opened. You can write text here! We will work with him in the future.

12. Now, without thinking, just copy the following text into this window:

Report("Hello, World!");

13. Great! The code for our first program is ready. Let's run it. Through the menu " Debugging"->"Start debugging" (or key F5).

14. We will answer the question in the affirmative.

15. After a second or two, 1C will start and the message “Hello, World!” will appear in the window below. We got what we wanted from the computer. Congratulations on your first program!

Did something go wrong? Still have questions? Email them to me [email protected] and I will answer you today. Your teacher: Vladimir Milkin.

Teacher's message

The difficulty level of the lessons goes from bottom to top. Therefore, try to study consistently, without skipping anything or putting it off for later.

Be sure to complete all tests and homework, try to improve your results. Check reference solutions only after self-execution tasks.

Login to the site as a student

Log in as a student to access school materials

If you write in SI
Be at least thrice lame
They say about this:
"He's a cool programmer!"
(Fidosh songs - “What is Suxxx and What is Rulezzz”)

Preface

The reason for writing this article was the negative attitude of the professional community towards this platform and programmers.

As a programmer who chose 1C, I consider this opinion unfounded. The 1C platform is far from ideal, but, in my opinion, it is the best, and most importantly, a domestic product!

And even more so, it is inadequate to judge a programmer’s abilities by the language in which he writes.

In this article I will describe the advantages that I found for myself in the program. The article will turn out to be almost an advertisement, so here’s a disclaimer:

  • I have no direct relationship with the 1C company;
  • This article is not commissioned and was written solely on a voluntary basis;
  • In some cases, personal opinions are expressed, which may not coincide...;
  • The entire article, with the exception of the prologue, is the author’s, any coincidence is an accident;
  • We will talk about the 1C Enterprise 8.2 platform (currently version 8.3 is current, but I have not studied it yet - there is a lot of work on 1C 8.2). However, most of what is said applies to both the 8.3 platform and earlier versions, and some of it applies to version 7.7.
So let's get started.

What are we talking about?

Platform 1C Enterprise 8 is:
  • It works in two versions - file and server (three-link) - each has its own advantages and disadvantages;
  • An independent accounting system that is easy to install and configure;
  • A powerful ecosystem for programmers with all the necessary objects and tools;
  • Nice ergonomic interface;
  • Relatively inexpensive solution for business;
  • Franchisee network, initial training;
  • A powerful base of developments and knowledge accumulated over the years;
  • At times a problematic platform for system administrators;
  • Not the fastest execution of algorithms (although not the slowest) - this is a tribute to the information content (in case of errors, the line number and its contents are indicated);
  • There are no classes in the programming language (inheritance, encapsulation, polymorphism), no anonymous functions and other modern features. But to solve most problems, this is not necessary!
To organize accounting, one platform is not enough. The platform is a kind of “engine”, an intermediate link between the program and the database. Programs for this “engine” are called configurations. The configuration describes the structure of the database in the form of objects, procedure texts stored in separate modules (there are many modules, both each object and the system as a whole have them, and there are also common modules). The platform represents a level of abstraction at which direct access to the database is not required, and also allows you to abstract from operating system and database type.

File and server database

The platform consists of several parts and can operate in file or server version.

In the file version, the entire database is contained in one file (with the extension “1cd”) - the platform is installed on each computer and directly reads/writes to the database.

Advantages of the file option - low price and ease of deployment.

Cons - file structure "1cd" is closed, no unified system, interacting with the database. As a result, it is difficult to use when large number users (tried for 20+ users - it works). Additionally, when the database size is approximately 15 GB (or more), dynamic updates may fail. Solving such failures is a difficult task, and the utility for repairing the database does not always effectively repair, and sometimes even cripples the database.

There is a solution - this is, first of all, setting up a daily Reserve copy Database. In addition, craftsmen not only publish the 1cd file format, but also have developed utilities for working with such files and a number of methods for solving such problems.

In the server version, the platform for storing the database uses a SQL server (usually MS SQL, but starting from 8.2.14 - you can use some others, for example, Firebird PostgreSQL, IBM DB2, Oracle Database), and the platform itself uses a three-tier architecture:

Some of the code is executed on the client, some on the server. In this case, only the server interacts with the database. At the same time, starting from version 8.2, in addition to the standard operating mode, which was called the “thick client” mode, two new operating modes appeared - “thin client” and “web client”; “controlled forms” also appeared, appearance which is built in the form of an abstract tree of elements. Programming for managed forms and a three-tier architecture is more difficult, but this allows you to transfer almost the entire load to the server (that is, you can buy one powerful server and a hundred of the cheapest office computers).

Advantages of the platform: “three-link” - load distribution, openness of the database (officially 1C company declines responsibility for any data corruption if SQL database changes were made other than by means of their platform or server, but this stops few people), lack of restrictions.

Cons - price: you will have to buy client licenses separately for each client computer, separately - one license for the 1C server, separately a license for the SQL server, if you do not use the free one. Also, sometimes difficulties arise in the operation of the database. They are resolved much faster due to the availability of data and the availability of external tools for working with the database. In addition, in this case, you should make a backup of the database.

A common advantage is the versatility of the configuration code: with some exceptions, a configuration developed for a file database will work on a server database, and vice versa. An example of an exception is passing a mutable value to the server or from the server to the client (in the file version this will not cause exceptions, but in the client-server version it is prohibited).

Another plus: the platform is installed very simply, something like this: “Next-Next-Next-Ok”, not required fine tuning and installation of any components.

For the server version there are a few more settings, but everything is done in the installation dialog and does not require you to enter anything in separate files. Installing a SQL server may be somewhat difficult, because... in this case there are many more settings (and to fine-tune it requires studying additional instructions). But this does not apply to the problems of the 1C platform. Moreover, if you install, for example, a MS SQL server with all the default settings, then 1C will be able to work with it.

It's more than accounting

When it comes to the 1C platform, it is presented primarily as an accounting program. Indeed, this is the most popular area of ​​use of the 1C platform. But 1C does not live by accounting alone!
Those familiar with the platform say that it is an accounting (accounting automation) system. This is closer to the truth - there are many configurations, both from 1C and from third-party developers. Some are only indirectly related to accounting, some are not related at all.

In general, it is more correct to imagine the 1C platform as a shell for object modeling of a database, interface and programming in the 1C language. The only limitation is that for each configuration its own database is created, and only one (however, it is possible to additionally connect as part of the configuration external sources data, i.e. other bases).

Ecosystem for programmers

Let us now consider the 1C language and platform from a developer’s point of view:
Database object model. Firstly, we do not work directly with databases. It is not necessary. For our convenience, all data is presented in the form of interconnected objects (directories, documents, information registers, accumulation registers, ...), and the platform automatically “pults” this data from the database.
For example, provided that the variable “Nomenclature Element” contains a reference to the directory element “Nomenclature”, the “Nomenclature” directory has the “Main Supplier” attribute, type “Directory.Counterparties”, and the “Counterparties” directory has the “Full Name” attribute, then the code:

Nomenclature Element. Main Supplier. Full Name
... will cause the 1C platform, using internal mechanisms, to find a record in the table corresponding to the “Counterparties” directory by identifier from the “Main Supplier” field of the item item and return the values ​​of the field corresponding to the “Full Name” field in the object model of the “Counterparties” directory.

There can be many such dereferences - the system can handle it. The only caveat is that the system does not know how to optimize dereferences, so you should strive to move them outside of all kinds of loops.

In addition to objects that describe data, there are a huge number of system objects - for a variety of functions. I will highlight some of them:

Value stores
Array- an object that stores a set of data, as opposed to the classical idea of ​​arrays. This could be data various types(number, string, link, other object). It has minimal functionality and is used mainly as a temporary container for transferring values ​​between other stores.

ListValues- an object primarily for working with the user interface. In addition to data, for each element it can also contain a representation, a flag attribute and a picture (icon). It also has the “SelectElement()” and “MarkElements()” methods - when called, the user is shown an interface dialog (which is convenient - there is no need to create this dialog in the configuration).

Structure And Correspondence- storage of paired values ​​“KeyIValue”. In the structure, “Key” is a string that follows the rules for naming variables in 1C (no spaces, does not start with a number, consists only of letters, numbers and an underscore). According to - “Key” is any value. The fastest search for objects is in accordance (faster than in an array and an indexed table of values).

Table of Values- a very convenient and quite fast object for storing and processing data. Columns in the value table can be added and deleted, regardless of the number of records. In this case, the data in the rows is not lost (or only the data from the cells corresponding to the deleted columns is deleted). Also, it has the “SelectRow()” method, which calls the row selection dialog. There are indexes.

Tree of Values- an object representing hierarchical data. Contains columns; the set of columns is the same for all records at all levels. Removing/adding columns in the value tree is just as easy as in the value table. Also, it has the “SelectRow()” method.

Interface objects and objects for working with various data TextDocument, SpreadsheetDocument, Web browser, ReadFile, WriteFile, ReadZIPFile, WriteZIPFile, ReadXML, WriteXML, HTTPRequest and many more objects, and the configurator has built-in help for everything. The purpose of the listed objects is clear from their names and all this is immediately available in the platform.

Separately, it should be noted that there is a “Metadata” object - with the help of which, in a programming language, you can study the structure of the data, as well as each link or object for a directory, document, chart of accounts, etc. there is a method “Metadata()” - providing a description of this reference book/document/chart of accounts/etc. in the database (what details, tabular parts are available, length of code/number, etc.). It is often very convenient.

And we should also separately mention the objects: “Query”, “Query Constructor”, “Query Builder”, “Report Builder”, “Data Composition Schema”. This family implements a set of objects for working with the powerful 1C query language.

Query language. Queries in 1C are used only to obtain a sample of data with convenient selection, sorting, and grouping. To a first approximation, this is the “SELECT” operator from SQL translated into Russian, however, the 1C query language also has functionality that is missing in SQL, namely:

  • Working with 1C configuration objects instead of SQL tables;
  • Working with links instead of SQL identifier fields;
  • Support for dereferencing, similar to how it is done in code;
  • Selection by inclusion in a group (for directories);
  • Hierarchical totals;
  • Temporary tables and nested queries (SELECT * FROM (SELECT ...)));
  • Query builder is a convenient, object-based, automatically optimizing query text for quick reading, which can parse query text (parse query text and build an object model from it);
  • The report builder is an add-on to the query mechanism, which adds the functionality of automatic formatting of results, as well as flexible configuration of the query itself in the “Enterprise” mode (i.e. by the user). As a result, a universal report has appeared in standard 1C platforms, in which the user can configure what data and in what order he wants to see what is in the rows and what is in the columns, and the report itself generates the output table;
  • DCS (Data Composition System) is the next model that incorporates the functionality of a universal report and supplements it with some functions for processing results.

Programming language
In terms of syntax, the 1C language is similar to “Russian Pascal”, but differs from “Pascal” in less strictness and the absence of some constructions:

  • There is no need to declare variables - you can initialize them directly in the module text;
  • There is no strict typing of variables. The system has value types, but there are no strict typing rules for variables. The variable that stored the link can, after a couple of lines of code, already store a number or string;
  • You can add variables with values different types, in this case, the type of the result will be the same as the type of the first variable, for example:
    k = “25”+1; // k = “251”, not 26
  • Variables with values ​​of different types can be compared for equality or inequality (but not for more or less, this will cause an exception) - naturally, such variables are not equal;
  • There are functions and procedures, it is permissible to use recursion (with a limitation on the depth of recursion);
  • When specifying a function or procedure without parameters, it is still necessary to indicate empty parentheses at the end: like this();
  • There are modules: each directory and document has several of them, in addition, registers, reports and processing and each form have modules, and also as part of the configuration it is possible to create common modules;
  • No classes, inheritance, encapsulation, polymorphism;
  • A function cannot be passed as a reference, there are no anonymous functions;
  • There is no reverse loop (for i:=5 downto 1 do), but it is really needed when deleting records. We make do with a slightly longer entry through the “Bye” cycle.

Tools

  • The 1C platform has the ability to upload and download a configuration, compare a configuration with another configuration, and partially download changes;
  • It is possible to download module texts for batch processing and load them back into the configuration;
  • If the configuration is supported (all configurations from 1C are initially supported), then you can always perform a comparison and see what has changed third party developers or local specialists;
  • It is also possible to upload/download the entire database (along with data);
  • For collective work on one configuration, a configuration repository is used;
  • There are also a number of rules for making changes to standard configurations; there is even a document from 1C that describes methods and standards for changing standard configurations (and any others).

General impression
The 1C language combines the clarity of Pascal language texts with the frivolity of working with BASIC language variables. It lacks a number of features inherent in modern programming languages, but you can do without them. In addition, the 1C platform has a powerful garbage collector, i.e. there is no need, for example, to clear tables after use or delete them.

Interface 1C Enterprise 8.2

1C company paid special attention to the interface of its program. First of all, this is the color palette. She's gorgeous! The program windows are recognizable even from afar, and after many years of work - they do not cause hostile feelings, on the contrary - I want all programs to be just as cool.
At the same time, the style of the platform is very strict, without frills or other frills. At the same time, there is very useful features, for example, remembering the sizes of windows (the sizes are remembered only when they are changed by the user, and, at the same time, you can always reset the user settings to the default sizes and positions by pressing Alt+Shift+R).
The 8.2 Web client interface causes a number of complaints, but it seems that the 8.3 platform brings with it a new redesigned interface - “Taxi”.

Prices, supply and demand, franchising

The most “delicious” advantage of the 1C platform is its price. This is especially true now, during a crisis. After all, 1C is completely our, domestic product. And it is sold for our wooden ones. Such solutions from a foreign manufacturer will cost a lot of money. And licenses for 1C are quite reasonable.

In addition, 1C has an interesting licensing policy. The licenses and configurations themselves are purchased once. At the same time, licenses are purchased for workplace and to the server, but not to the databases, and not even to the connections, i.e. under one license, the same user can launch an unlimited number of 1C sessions, working with any number of databases. The same applies to configurations: by purchasing one license for a configuration, an organization can use it to create any number of databases; moreover, it is officially permitted to use parts of the code and objects of this configuration when developing their own configurations (in this case, their own configurations can be sold/transferred - with the stipulation that To use them you need to buy a configuration from 1C).

After this one-time purchase, you only need to subscribe to updates and pay for subscription renewal once a year, the so-called. ITS. By the way, the subscription is very inexpensive, about the same as two client licenses.

Overall, it all looks very profitable.

The second “tasty”, but with a fly in the ointment, plus, is the presence of fairly universal configurations from 1C itself and from partners.

About versatility

The concept of “versatility” was defined by one school teacher on NVP using the example of gas masks: there are universal ones that protect against many damaging factors, but the degree of protection is average or below average, and there are also specialized gas masks that protect against one impact, but with high degree protection. Until now I have not come across a more precise definition.
And the configurations from 1C are universal. In practice, there are no tasks where they could be fully used without modifications. Nevertheless, 1C managed to create a universal set of tools that covers the needs of most sectors of modern business.


The third advantage (and also with a fly in the ointment) is the network of franchisees and training centers, both for users and for novice programmers and administrators. A good idea, but very mediocre quality of its implementation. However, the prevalence and aggressive marketing is one of the reasons for the widespread popularity of 1C in our country (and this is also the reason for negativity, envy and hatred).

A spoon of tar

Having described 1C in all its colors, it would be unfair not to talk about its shortcomings, but they are there:

Unstable releases- both in the platform and in the configurations, there are a huge number of errors and glitches. And this is in official releases. Before you release official version, a “Evaluation Version” is being released. There are also Feedback to submit error descriptions so that they can be accepted for correction. However, either the trial versions are not particularly popular, or the 1C company itself does not have time to process all the letters by the release date, but it is a fact. Every time you update a platform or configuration, you can stumble upon the most unexpected “surprises”. 1C has already been repeatedly called upon to test its developments more thoroughly.

Franchisee (hereinafter referred to as franchisees). Ideally, as planned, these should have been companies with qualified specialists who knew the basic principles of operation of configurations and platforms. These same companies would have to sell the platform, configuration and support, slightly “finish” universal configurations to suit the client’s requirements (and at times adjust these requirements), trying to minimally modify the standard configuration. So as not to complicate future updates too much. But in reality the opposite is true.

When selling new licenses to a client, franchisees receive 50% of their cost (minus income tax of 13% of this 50%). At the same time, you don’t need to produce anything yourself, you just need to hand over the keys to 1C to the buyer.

When providing services, franchisees do not pay the 1C company anything (except for membership fees), but they need to pay the employee’s salary. The state also has to spend money on taxes - the Pension Fund and income tax.

It turns out that it is profitable for both 1C and franchisees to sell licenses and unprofitable for further support. At the same time, in order for a client to buy a program, it must initially be tailored to his requirements. And you have to pay for the work. And here, in order to save money, students, apprentices, non-specialists are brought in, they can be paid a little, and sometimes not paid at all, they don’t even have to be registered as staff (they will work unofficially, fortunately there is something to pay for). The result is a huge number of sales with very low quality. Improvements usually affect important mechanisms and complicate future updates. But at the sales stage, neither 1C nor the franchisee are interested in this.

I note that this is not so much the fault of the French businessmen as of the 1C company. Focusing on sales, she didn’t care about support at all (I’m not talking about schools now, but about the fact that providing support should be beneficial to both the franchisee company itself and 1C).

Technical support. In the understanding of the 1C company, technical support is the provision of access to the “update” section for the platform and configurations, as well as to information sections containing a description of some mechanisms and features of 1C operation. In addition, when you subscribe, you will receive a disc with the specified materials. There is also a forum (very meager compared to popular ones). There is also the opportunity to send email to the 1C company - but not even hoping that they will answer it (or the robot will answer “The letter has been sent to the development department.” In terms of development, Yandex.Search and the help built into the configurator provide much greater support.

Epilogue

I switched to 1C in 2008, and before that I worked in a company developing its own accounting program (Delphi 5, then Delphi 7). First, I got acquainted with the 1C Enterprise 7.7 platform and was struck by its ease of report development. At the same time, it was clear that reports were generated much longer than in similar mechanisms on Delphi, but the accountants were not particularly worried about this. Waiting a few minutes instead of a few seconds is not a problem. On the contrary, you can paint your nails there, drink tea or discuss last news without stopping from work. After all, the vast majority of accountants these days are women.
However, the 7.7 interface was very limited, and the set of objects was very poor. I was looking for alternatives. I got acquainted with the external components, but did not get to practical use of them, because... the boss decided that it was time for us to switch to 8.1 (yes, 8.2 did not exist yet), and in this platform, as a programmer, I found everything that I was missing before.
Currently, I have authority among colleagues, as well as clients who came to me from franchisees. They will probably never contact the French again.


In general, I am quite satisfied with working in the 1C Enterprise 8 platform. It is suitable for solving most accounting and database problems.

Tags: Add tags

To everyone who wants to get into programming, we want to explain some simple things that are not mentioned in all programming textbooks, but those who want to master programming in the 1C language from scratch should know about this.

1. A programming language is, first of all, a Language.

Before you start learning a language, be mentally prepared for the fact that this process is not quick. So that you can specifically imagine what learning a programming language is - it is almost the same as learning a foreign language. Everyone at school studied a foreign language and everyone understands perfectly well; to know a language it is not enough to simply learn the translation of words from a foreign language into a native language in a dictionary. For example, the phrase “I know English” can be said by a person who is able to: read text in English language, translate, compose a sentence without errors, express yourself orally. Translating foreign words without the ability to correctly compose a sentence (read the syntax of a programming language) certainly does not mean knowledge of a foreign language. Therefore, Lesson 1 - treat learning a programming language the same way you would treat learning a foreign language with the goal of completely mastering it.

2. Practice.

Surely you have heard how some people who know a foreign language well gradually forgot it without practice of using it. Having studied the basics of programming on 1C, practice daily in performing simple tasks in order not to lose the knowledge acquired earlier and gradually take on more complex tasks. Improve your skills.

Any business moves better if there is motivation.For you in the future, programming skills are a monetary reward, good job, easy social elevator, etc. It's no secret that software"1C Enterprise" is very popular in the post-Soviet space. Of the ten companies, eight use the 1C program to record their business activities. Accordingly, they need an administrator or 1C programmer who would maintain and modify the program. Naturally, such a market needs 1C specialists. Sometimes companies are ready to hire a not very highly qualified employee with programming skills for a decent salary with the condition of self-improvement. And even if you don’t want to work for a commercial company or franchise, a good qualified programmer will be able to find work on freelance exchanges or carry out custom projects. In general, a 1C programmer will not be left without work.

With an introductory part in basics of programming we're done. The rest of the material will be devoted to mastering the basics of 1C language code. Perhaps some parts will be described too briefly, but the purpose of this material is not to completely immerse the reader in the syntax of the language, but rather to initially familiarize specialists with the architecture of the 1C language in order to form a certain skeleton (base) in the user’s head on which all knowledge will be hung in the future .

». This language is an interpreted language high level. Interpretation of the text of a program module into bytecode is performed at the moment of accessing this module during operation, thus, usually only part of the text of program modules is interpreted.

The language execution environment is the 1C:Enterprise software platform. The visual development environment (“Configurator”) is an integral part of the 1C:Enterprise software package.

Language dialects for 1C platforms 7 versions (7.0, 7.5, 7.7) are compatible from the bottom up with minor exceptions. The languages ​​for the 1C:7x and 1C:8x platforms are compatible in basic operators, but differ significantly in working with application objects, as a result of which transferring code from 1C:7x to 1C:8x does not make sense.

The built-in 1C:8 language is most similar in its syntax to the Visual Basic language.

The platform provides a fixed set of base classes focused on solving typical problems in the application area:

  • Constant,
  • Directory,
  • Document,
  • Document log,
  • Transfer,
  • Report,
  • Treatment
  • Chart of accounts, etc.

Based on base classes, you can create any number of generated classes using visual configuration tools (there is no ability to define a new class programmatically). Only one explicit level of class inheritance is allowed. Typically, objects of derived classes represent records (or some sets of records) in a database. Such classes form a “Metadata Tree”. In terms of the built-in 1C programming language, such classes are called metadata objects.

The main types of metadata objects are: Directories, Documents, Reports, Processing, Plans of characteristics types, Charts of accounts, Plans of calculation types, Information registers, Accumulation registers, Calculation registers, Business processes, Tasks.

Russian and English syntax commands

Projects in the built-in 1C:Enterprise language are called configurations. Distribution (sale) and implementation of such configurations is the main commercial activity of 1C partner companies.

The working name of the language - “1Sik” (“odynesik”) - very quickly disappeared from official sources. Now, when mentioning this language in written documents, you need to write 1C Programming Language. However, this language is often called “built-in language” in the context of discussions of 1C:Enterprise.

Encyclopedic YouTube

  • 1 / 5

    There are several additional components that extend the main classes, they can be freely added and modified; they are not recommended for use by the developer. This means that 1C and its franchisees refuse any technical support configurations using such components.

    Moreover, there is a completely free 2C project that does not use any proprietary modules from 1C or other manufacturers. This is a rewritten “from scratch”, freely distributed under the GPL license, an extensible core of a 1C-like system, in which even such “built-in objects” of 1C as directories and registers are classes redefined by the application programmer.

    The 2C platform language was designed with the goal of maximum continuity with existing developments for 1C, and is an extension of the basic 1C language. By writing the appropriate base classes, the 2C language can be brought closer to both 1C 7.7 and 1C 8.0, although 2C:Platform cannot provide 100% automatic portability of configurations from one or another version of 1C:Enterprise.

    Example program

    An example of displaying a message in a special window for version 8.3:

    Procedure HelloWorld () Report ( "Hello World!"); End of Procedure

    As a rule, learning any programming language begins with an example of writing the first the simplest program(“Hello world!”). This is done in order to clearly demonstrate the work with basic syntactic structures. We will not make an exception to this generally accepted way of presenting material when exploring a new development environment, and therefore our first article should be viewed in the same light. 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 software 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 comparison, assignment, and conditional operators are there and how do you use them?
    • Boolean operations - what are they and how to work with them?
    • Why do we need loops 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 on 1C.

    Applicability

    The material is relevant for the 1C:Enterprise 8 platform, edition 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 is enough a large number of modules that are designed to handle various events.

    So, the user’s login to the system is processed in one module, and the processing of the user’s click on a certain button is processed 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 section for describing variables. Those. we can declare some variables in the module.

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

    Perem Warehouse, Division, Storekeeper Export;

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

    Behind them is a section of the main program that will be executed when this module is accessed.

    For example, in a section of the main program 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 symbol ";" (semicolon). This sign marks the end of the statement. Those. the operator can be written as follows:

    Result=100X200
    +400
    -600;

    It does not matter how many lines the statement is located 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 dozen).

    The semicolon may not be placed in the final statement of a given structure, for example, a procedure. Those. the following code will work:

    Procedure CalculateValue()

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

    End of Procedure

    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 statement will no longer be final. We will have to specifically monitor this situation.

    Variables are designed to store 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. Typing variables by values ​​in Platform 1C:Enterprise 8 is soft.

    For example, a variable can contain a value of one data type, and then 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 changes to a numeric value. Those. typing depends on the value that is assigned to a given variable.
    Variables can be described 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 for describing variables);
    • explicit description of variables (Variable Control Data;). Explicit declaration of variables is used, for example, if the subsequent passing of this variable to a function is intended.

    Variables are named using the classic identifier description. The identifier consists of letters, numbers and underscores. The 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 (like A, B, C) are bad examples. They do not reflect the essence of the variables.

    Examples of correct variable names: Counter (increasing variable for a loop), Counterparty. 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, EndLoop, etc. cannot be used in variable names. (these structures are highlighted in red in the program module).

    Reserved words are built-in language operators and there are a fairly small number 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 accept such variable names correctly.

    For writing program code case doesn't matter. For example, the word Procedure can be written with either a capital or a small letter. Moreover, large and small letters can be alternated within a word.

    This does not matter to the Platform. However, according to the rules of good manners, the beginning of a word should be written with a capital letter, and all other letters with small letters.

    Regarding the language. You can use Russian, English, or a combination of the two languages. If it is convenient for someone, you can safely use English to write program code, as well as combine Russian and English. This is not important for 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 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 follow one branch (i.e., if the value is True), if the condition is False, another branch of the algorithm will be executed.

    The conditions can be quite complex, they can be combined, and the following operators are used: AND, OR, and NOT. So, for the AND operator:

    Truth And Truth = Truth;
    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 False is obtained only when 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, you should consider priorities.

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

    For example, let’s set priorities (execution sequence) for operations in the given 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, an expanded expression is easier to read.

    Assignment operator

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

    The principle of the assignment operator is 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 look at an example:

    Variable1 = Variable2 = Variable3;

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

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

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

    Solution #1 using a temporary variable:
    TemporaryVariable = Variable1;
    Variable1 = Variable2;
    Variable2 = TemporaryVariable;

    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 OtherwiseIf(see example below). The entire construction must end with the keyword EndIf, followed by a semicolon.

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

    If the condition is true, then it will be executed Expression1, otherwise - Expression2. Example code: ExpensiveProduct = ?(Product.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 notations actually used are:

    If Variable Then
    And
    If NOT Variable Then

    Cyclic operators

    For any type of loop, an explicit indication of the end of this loop is required using keyword End of the Cycle. There are several types of cycles.

    Loop on a counter– a cycle with a fixed number of repetitions. The condition for exiting the cycle is exceeding the limit value. Example use for calculating the value of A!

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

    Loop by condition– is satisfied as long as the condition is true of this cycle. Example:

    RemainingAmount = 1000;
    Additional Product Price = 243;
    Quantity = 0;
    While Remaining Amount>0 Cycle
    Quantity = Quantity+1;
    Remaining Amount = Remaining Amount – Quantity*Price of Additional Product;
    Price of Additional Product = Price of Additional Product * 0.8;
    End of the Cycle
    Quantity = Quantity-1;

    This cycle calculates how many units of a product can be purchased 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 original price of the product is 243 rubles.

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

    Cycle through collections (another name for everyone).

    There are quite a large number of collections in the Platform (these are containers that contain elements of a certain type).

    You can iterate through the elements of a collection using a special type of loop.

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

    Amount = 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 cycle the execution of further operators of a given 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 execution even if the loop condition is true.

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

    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 it doesn’t work out, then you can take a look here.