📜 ⬆️ ⬇️

Reporting in 1C: Data Composition System (ACS), idea and architecture

One of the most important areas of business software is reporting. How easy it is to adjust an existing report to a changing business needs (and legislation) or make a new one may depend (and not in a figurative sense!) The fate of the business, whether it is a report for the tax inspectorate or a chart of the demand for goods from the season and other factors . A powerful and flexible reporting system that allows you to easily extract the necessary data from the system, present it in an easy-to-understand form, allowing the end user to reconfigure the standard report to see the data in a new light - this is the ideal every business system should strive for.

In the 1C: Enterprise platform, a mechanism called Data Composition System (abbreviated to ACS) is responsible for generating reports. In this article we will try to give a brief description of the idea and architecture of the SKD mechanism and its capabilities.

image

ACS is a mechanism based on a declarative report description. SKD is designed to build reports and to display information that has a complex structure. By the way, in addition to developing reports, the ACS mechanism is also used in 1C: Enterprise in a dynamic list , a means of displaying list information with rich functionality (showing flat and hierarchical lists, conditional design of lines, grouping, etc.).
')

A bit of history


In the very first version of the 1C: Enterprise 8 platform, version 8.0, the reports were made as follows:

  1. One or several queries were written in the 1 query language (SQL-like language, more about it below).
  2. A code was written that transferred the results of executed queries to a tabular document or to a chart. The code could also do work that could not be done in the request — for example, calculated values ​​using the built-in 1C language.

The approach is straightforward, but not the most convenient - at least visual settings, everything has to be programmed by "hand-to-hand". At that time, one of the trump cards of the completely new platform “1C: Enterprise 8” is the minimization of the amount of code that you need to write manually in an application solution, in particular, due to visual design. It would be logical to go the same way in the reporting engine. This was done by developing a new mechanism - the Data Composition System.

One of the ideas that formed the basis of the SKD was the flexibility and customizability of reports, which was available both to the developer and to the end user. Ideally, I would like to give the end user access to the same set of tools for report design as the developer. It would be logical to make a single set of tools available to all. Well, since the tools require the participation of the end user, it means that you need to use programming in them to the minimum (the best thing is to eliminate it completely), and to use the visual settings to the maximum.

Formulation of the problem


The task for the development team was to create a reporting system based not on an algorithmic (ie, through writing code), but on a declarative approach to creating reports. And we believe that the problem was successfully solved. In our experience, about 80% of the required reporting can be implemented using ACS without a single line of code (except for writing formulas for calculated fields), mostly through visual settings.
The development of the first version of SKD took about 5 man-years.

Two languages


Two languages ​​are involved in creating reports. One is the query language used to fetch the data. The second, a data composition expression language, is intended to record expressions used in various parts of the system, for example, in data composition settings, to describe expressions of user fields.

Query language


The query language is based on SQL and is easily mastered by those who know SQL. Request example:
image

It is easy to see analogs of sections standard for SQL query - SELECT, FROM, GROUP BY, ORDER BY.

At the same time, the query language contains a significant number of extensions aimed at reflecting the specifics of financial and economic tasks and at maximally reducing efforts to develop application solutions:


The request mechanism automatically modifies the request taking into account the roles to which the user belongs, on whose behalf the request is executed (that is, the user will see only the data that he has the right to see) and the functional options (that is, according to the functionality).

There are also special query language extensions for ACS. The extension is carried out using special syntactic instructions, enclosed in braces and placed directly in the query text. Using extensions, the developer determines which operations the end user will be able to perform by customizing the report.

For example:


An example of using extensions:
image

Data Layout Expression Language


The data composition expression language is designed to record expressions used, in particular, to describe custom field expressions. ACS allows you to define custom fields in the report using either your own expressions or a set of options with the conditions of their choice (similar to CASE in SQL). Custom fields are analogous to calculated fields. They can be set both in the configurator and in the “1C: Enterprise” mode, but in the expressions of custom fields the functions of common modules cannot be used. Therefore, user fields are intended for the user rather than the developer.

Example:
image

The process of creating a report on ACS


When creating a report, we need to create a layout that determines how the data will be displayed in the report. You can create a layout based on the data composition schema. The data composition scheme describes the essence of the data that is provided to the report (where to get the data from and how its composition can be managed). The data composition scheme is a base from which various reports can be generated. The data composition scheme may contain:



image

For example, you can add a query to the data composition scheme as a data set, and call the query designer, which allows you to graphically create a query of arbitrary complexity:

image

The result of the launch of the query designer will be the query text (in the query language “1C: Enterprise”). This text can be manually corrected if necessary:

image

There can be several data sets in the data composition scheme, data sets can be arbitrarily linked in the layout, calculated fields can be added, report parameters are set, etc. It is worth mentioning an interesting feature of the query mechanism in 1C: Enterprise. Queries are ultimately translated into a SQL dialect specific to the DBMS, with which the application works directly. We generally try to use the capabilities of the database servers to the maximum (we are limited by the fact that we use only those capabilities that are simultaneously in all supported by the 1C: Enterprise platform DBMS - MS SQL, Oracle, IBM DB2, PostgreSQL). Thus, at the query level in the calculated fields, we can use only those functions that are translated to SQL.

But at the level of the data composition scheme, we can already add custom fields and use functions in them in the built-in 1C development language (including those written by us), which greatly expands the capabilities of the reports. Technically, it looks like this - everything that can be translated into SQL is translated into SQL, the query is executed at the DBMS level, the query results are placed in the memory of the 1C application server and the ACS calculates the values ​​of the calculated fields for each record, whose formulas are written in 1C.

image
Add custom fields

An arbitrary number of tables and charts can be added to the report:

image
Report Designer

image
Runtime Report

With the help of ACS, the user can add complex selections to the report (which will be added to the request in the right places), conditional design (allowing different formatting - with font, color, etc. - displayed fields depending on their values) and much more .

Briefly describe the process of building and generating a report as follows:



image
The process of forming the report mechanism SKD

We try to minimize the amount of data reports transmitted from the server to the client application. When displaying data in a tabular document when opening a tabular document, we send only those lines from the server that the user sees at the beginning of the document. As the user moves along the lines of the document to the client, the missing data is downloaded from the server.

Custom settings


All SKD tools are available to both the developer and the end user. But practice has shown that the end user is often intimidated by the abundance of capabilities of the tool. Moreover, in most cases all the power of settings to the end user is not needed - it is enough for him to have quick access to setting up one or two report parameters (for example, period and counterparty). Starting from a certain version of the platform, the report developer has the opportunity to note which report settings are available to the user. This is done using the checkbox "Include in user settings." Also, the report settings now have a “Display Mode” flag, which accepts one of three values:



image
Setting display mode at design time

image
Display settings in the mode "Quick Access" at run time (under the button "Generate")

Development plans


One of the priorities in the development of ACS for us is to simplify user settings. Our experience shows that for some end users, working with user preferences is still a serious work. We take this into account and work in this direction. Accordingly, it will also be easier for developers to work with ACS, since we, as before, want to provide a single report customization toolkit for both the developer and the end user.

Source: https://habr.com/ru/post/336258/


All Articles