Code

A Beginner's Guide to Value Tables in 1C

A Beginner's Guide to Value Tables in 1C / Skillbox Media

Mastering Skills: The Profession of a 1C Programmer

Learn More

In 1C:Enterprise, a value table is one of the most common objects for working with data in RAM. This tool provides convenient storage and manipulation of tabular information without the need to write data to a database.

In this article, we will consider the concept of a value table, its structure, methods of working with it, and situations in which its use is most appropriate.

Contents

  • 1C:Enterprise is a comprehensive platform for automating business processes, developed by the Russian company 1C. It covers a wide range of tasks, including financial management, inventory accounting, settlements with customers and suppliers, and personnel records. The platform allows users to adapt the software to their needs, due to which it is used in both small businesses and large corporations. 1C:Enterprise pays significant attention to ease of use, which allows users to easily master the functionality of the system. In addition, the software is regularly updated, which ensures compliance with modern business requirements and legislation.
  • Where will we conduct our training?
  • A value table is a structured set of data organized into rows and columns. It is used to present information in a readable format, allowing for easy analysis and comparison of values. Each row contains information related to a specific object or category, while the columns represent various characteristics or parameters of these objects. This approach is often used in mathematics, statistics, and other scientific fields to simplify the processing and visualization of data.
  • Creating a table of values ​​requires several steps. First, determine what data you want to include in the table. Then, choose an appropriate tool for creating it, such as a spreadsheet, word processor, or specialized program.

    Next, begin by creating column headings that will denote the different categories of information. Next, fill the table rows with the corresponding values, ensuring that the data is organized logically and clearly.

    Don't forget about formatting: clear borders between cells and a neat font will help make the table more readable. Finally, check the accuracy of the entered data and save the table in the desired format for further use.

  • Iterating over rows and columns.
  • How to calculate totals
  • To search for a row in a table of values, you can use several methods. First, you need to define the search criteria, such as specific values ​​in certain columns. Then, depending on the program or tool you are using, you can apply filtering or searching functions.

    If you are working with spreadsheets such as Excel or Google Sheets, you can use built-in functions such as VLOOKUP or FILTER. These tools allow you to find rows that meet specified criteria.

    Also, if the table is presented as a database, you can use SQL queries to extract the desired information. In this case, you will need to formulate a query specifying the necessary parameters.

    It is important to remember that the accuracy of the search depends on the correctness of the entered data and the formulation of the criteria. Therefore, careful preparation before starting your search can make the task much easier.

  • To delete one or more rows, there are several approaches, depending on the tool or environment you are using. In text editors such as Microsoft Word or Google Docs, you can select the desired rows and press Delete or Backspace. When working with spreadsheets, for example, in Excel, to delete rows, you need to select them, right-click, and select the Delete option.

    If you are using code editors such as Visual Studio Code or Sublime Text, the process is similar: select the rows and delete them using the keys on your keyboard. In programming, for example, in Python, you can delete rows from a list using the `remove()` or `del` method. It is important to remember that in most cases, deleted rows cannot be recovered unless there is an undo function, so be careful when deleting information.

  • Organizing a Data Table
  • Selecting Rows
  • There are several ways to copy a table, depending on the application you are working in.

    If you are using a text editor such as Microsoft Word, you can select the table, then right-click and select the Copy option. After that, you need to place the cursor where you want to paste the table and right-click again, selecting Paste.

    In Excel, the process is slightly different. Here, first select the desired table cells, then use the keyboard shortcut Ctrl + C to copy. To paste, use Ctrl + V in the desired location.

    If you need to copy a table from a website, select it, copy it using the keyboard shortcut Ctrl + C, and paste it into the desired document using Ctrl + V. However, keep in mind that the formatting may change depending on the program you paste into.

    Keep in mind that in some cases you may need to adjust the size or style of the table after pasting it to suit your document.

  • To collapse a table of values, there are several key steps to consider. First, it is important to determine exactly what data needs to be grouped or aggregated. This may involve selecting specific columns or rows to combine to present the information more compactly.

    Next, consider using special functions or tools available in the program you are working with, be it Excel, Google Sheets, or another spreadsheet software. These tools will allow you to perform operations such as sums, averages, maximums, and minimums, depending on the purposes of your analysis.

    Next, perform the necessary calculations and ensure that the results are presented in an easy-to-read format. It is important that the resulting table is clear and easy to read so that users can easily interpret the data.

    Finally, don't forget about the ability to visualize rolled-up data, for example through charts or graphs, which can greatly simplify the perception and analysis of information.

  • There are several ways to integrate information from one table into another. Depending on the database or tool you are using, the methods may vary.

    If you are working with SQL, you can use the INSERT INTO statement to transfer data. First, you will need to run a query that selects the required records from the source. For example:

    «`sql
    INSERT INTO target_table (column1, column2)
    SELECT column1, column2
    FROM source_table
    WHERE conditions;
    «`

    If your task is to update existing records, it is advisable to use the UPDATE statement, which allows you to modify data in the target table based on information from another. An example of such a query:

    «`sql
    UPDATE target_table
    SET column1 = source_table.column1
    FROM source_table
    WHERE target_table.id = source_table.id;
    «`

    It is also possible to use various tools, such as Microsoft Excel or Google Sheets. In them, you can copy data from one table and paste it into the desired location in another table. For a more automated approach, you can use functions such as `VLOOKUP` or `INDEX` and `MATCH` to extract data from one table and insert it into another based on certain criteria.

    In the case of working with programming, languages ​​such as Python offer libraries, for example, `pandas`, that make it easy to manipulate data. You can use methods such as merge or concat to combine tables.

    The method you choose will depend on your specific situation and data requirements.

  • Extracting rows of data into an array of structures and then returning them back requires several steps.

    First, create a structure that will represent a single data record. For example, if you are working with user data, a structure might include fields such as name, age, and address. Then, you initialize the array that will store these structures.

    When unloading rows of data, for example from a database or file, you need to iterate through each row, break it down into its constituent elements based on delimiters (such as commas or tabs), and then populate the appropriate fields in the structure. Each populated structure is added to the array.

    Once the array of structures is populated, you can use it for further processing or analysis. To load the data back, you need to iterate through the array and form rows based on the values ​​of the fields in each structure. These strings can be written to a file or to a database.

    So, the process involves creating a structure, retrieving and populating an array, and then converting it back to write the data.

  • To display a table of values ​​on a managed form, you need to complete several steps. First, make sure you have a data source that contains the required values. Then, create a new managed form or open an existing one.

    Next, add a control that will represent the table, such as a DataGrid or GridView. Configure this control so that it can display data from your source. To do this, you will need to bind the control to data using an appropriate method, such as data binding.

    After that, customize the display of columns and rows to suit your requirements. You can specify which fields from your data source should be displayed, as well as set the formatting for ease of readability.

    Remember to test the form to ensure that the data loads correctly and the table displays as you intended. If everything is done correctly, your value table will be successfully output to the managed form.

Overview of the 1C:Enterprise System

Before getting acquainted with the value table, it is worth briefly discussing the data structure in the 1C:Enterprise system.

In the 1C:Enterprise system, information is structured using metadata, which is a description of accounting objects, such as directories, documents, registers, plans, and other elements. The configuration defines the logical data model, while physical data storage is performed using relational databases such as PostgreSQL, Microsoft SQL Server, SQLite, and others.

Screenshot: "1C:Enterprise 8.3". Configurator / Skillbox Media

In the 1C system, each element, be it a "Goods" directory or a "Receipt" document, is represented as one or more tables in the database. The data in these tables is saved automatically, and the developer, as a rule, does not need direct interaction with SQL: interaction is carried out through the built-in 1C language and platform functionality.

Read also:

1C:Enterprise Programming Guide: Getting Started for Beginners

Definition and essence of a value table

A value table is a temporary construct that resides in RAM exclusively for the duration of a program's execution. It is similar to a standard two-dimensional table that stores data in the form of rows and columns.

A value table provides the ability to organize, sort, select, and explore data stored in RAM. After the work is completed, be it a module or a session, it is deleted, but its contents can be printed or saved to a persistent object, such as a directory, document, register, or external file.

As a rule, it is used in the following cases:

  • during report preparation;
  • for short-term storage of information before writing it;
  • in event management and processing;
  • for passing information between components;
  • during the preparation of data for presentation on a form.

Let's look at tables using a specific example.

A place for our practice

Let's create a new empty configuration in which we can test our code. Let's go to the GeneralCommands section and add a new command called GeneralCommand1, with the synonym Create table of values ​​- this name will be displayed in the program itself. Then you need to include this command in the Navigation Panel group. Normally, so that it is available when you start the 1C:Enterprise program.

Screenshot: "1C:Enterprise 8.3". Configurator / Skillbox Media

Let's open the command module and enter a new procedure called CommandProcessingOnServer().

Screenshot: "1C:Enterprise 8.3". Configurator / Skillbox Media

At this stage, we will integrate the code into this procedure.

Read also:

The 1C language covers such aspects as a standard system, available libraries, an integrated development environment (IDE), code aesthetics, and the authenticity of specialists in this field.

Table Formation Methods English: values

Below is the code that must be inserted into the ProcessingCommandAtServer() procedure to create a ValueTable object:

Adding columns is performed using the Columns.Add() method.

The structure of this method is as follows:

Input (, ,

, )

Where:

  • Name is the header of the column in the table and is a required element.
  • Type is the data that will be stored in this column. By default, the type is set to string.
  • Header is the name of the column that will be displayed to the user if the table is generated automatically on the form.
  • The width of a column is determined by its length, which means the number of characters it contains.

Two new text columns were introduced into our table: Model and Manufacturer. The data type in these columns remains the same — String.

Let's set the column type:

Here:

  • We create the data type for the Number column with a length of "10" and two decimal places. Thus, the values ​​in the Price column will be presented in numeric format, for example: 54,990.00.
  • We introduce new columns designated as Price and Quantity for this type.

Three new rows must be added to the table, in each of which you must specify the values ​​for all columns separated by a period. It is important to indicate the model, manufacturer, and price.

Methods for traversing rows and columns in data

Now we have the ability to display information about each smartphone. To effectively iterate through the rows of a data table, it's convenient to use the "For Each" loop operator.

Here:

  • The loop iterates through each row in the Smartphones value table.
  • At each step of the loop, the Page variable takes the value of one row from the table.
  • The Message() function is designed to display text in the 1C message area located at the bottom of the screen.

This is how it will be presented in the configurator:

Screenshot: "1C:Enterprise 8.3". Configurator / Skillbox Media

You need to update the settings, then open "1C:Enterprise" and run the command. As a result, we get:

Screenshot: "1C:Enterprise 8.3" / Skillbox Media

Similarly, we can print the names of all the columns in the table:

How to calculate the totals

Now let's include the "Amount" column and calculate the total for each smartphone.

Let's sum up the total cost of all mobile phones:

Ways to find a row in a data table

There are many ways to achieve this.

Row indices in a table are numbered from 0 to a value equal to the total number of rows minus one. To access a row, you can use its index. It is important to remember that if the requested index is outside the range of existing values, this will result in an error. Therefore, it is advisable to first ensure that the specified index is less than the total number of rows in the table, for example:

In this situation, the program will return the first row that matches the specified value:

Efficient Methods for Deleting One or More Rows

You can use the Delete (Index) method to delete rows. However, you should be careful when deleting multiple rows at once. If you run the iteration process and delete indexes at the same time, this can lead to index shifts, which will ultimately lead to the deletion of unwanted rows.

Let's consider various methods for deleting rows.

If you have the exact index value (keep in mind that you need to subtract one from the total number of rows):

At this point, we find the first row in the table that matches the given criterion, determine its index, and then delete it using the Delete() method.

In order to get rid of all rows that meet the given condition, it is optimal to start from the end of the table. This approach allows you to avoid index shifting.

This method is reliable if you need to delete several rows at once in accordance with a specified condition.

This method removes all records from the table, leaving only empty columns.

Sorting Values ​​in a Table

The 1C:Enterprise system allows you to sort a table of values ​​by one or more columns using the Sort() method. A string containing the column names and an indication of the sorting direction—ascending or descending—is passed as an argument.

First, we sort the table by the Manufacturer column in descending order, and then by the Model column in ascending order. After this, we display the obtained results on the screen.

Selection of rows

To select rows that meet the specified criteria, you need to apply a structure that specifies the column name and the required value for filtering. As a result, the program will output an array of strings:

Here:

  • At the first stage, we form a structure called SearchParameters, where we set the «Manufacturer» as the key, and assign the corresponding value to «Xiaomi».
  • The FindStrings (SearchParameters) command selects strings from the table of Smartphones values ​​and saves them in the FoundStrings array.
  • We display the values ​​of these strings on the screen using the «For Each» loop operator.

It is possible to filter data by multiple columns:

Table Duplication Methods

You can copy the entire table or select certain parts of it for copying.

At this location We create a new table that will include all the rows and columns of the original version.

Here we create a new table that includes all the columns and selected rows from the original table.

Methods for compressing a data table

To collapse a table of values ​​by specified groupings, the Collapse method is used with the GroupingColumns and SumColumns parameters.

GroupingColumns is a row containing a list of column names whose values ​​need to be used to combine the rows.

SummarizationColumns is a list of column names that will display the totals for the grouped records.

As a result of the operation, rows with identical values ​​are combined into one, and the grand totals for the collapsed rows are written to the corresponding summarization columns. Columns that were not specified in the Collapse() method are excluded from the final result.

Ways to integrate information from an alternative table

Let's create a table called tSmartphones1, which will have the same columns as in the tSmartphones table.

Let's include additional rows in it:

We need to move data from the Smartphone1 table to the Smartphone table. This can be implemented by adding new rows one by one to the Smartphone table and filling each column with values ​​taken from the corresponding columns of the Smartphone1 table.

This algorithm has a certain drawback: the column names must be explicitly specified in the code. In this regard, it is more practical to use the built-in language function FillPropertyValues().

The code has been significantly shortened and become more versatile.

The process of exporting rows to an array of structures and their subsequent import

A similar task may arise when it is necessary to transfer information from a table of values ​​located on the server to the client side. However, this cannot be done directly, since the table is available exclusively on the server. In this regard, it is necessary to transfer data from the table to an object - an array that will be available on both the server and the client side.

This problem can be solved using the function:

In order to extract information from the array and place it in the value table, there is a function:

Methods for displaying a data table on a managed form

In the configurator, it is necessary to develop a handler, after which a new attribute called tAttribute, which will be of the ValueTable type, should be added to the form. You will also need to create a corresponding form element called the RequisiteForm.

Screenshot: "1C:Enterprise 8.3". Configurator / Skillbox Media

Let's create the OutputTable command and develop the corresponding handler on both the client and server sides. After that, we will connect this command with the Display table button.

Within the DisplayTableOnServer() procedure, we will generate a table of values ​​named tSmartphones and then initiate a call to the DisplayTableOfValuesOnForm() procedure:

The process of displaying the table of values ​​on the form is carried out as follows:

Let's begin the processing process.

Screenshot: "1C:Enterprise 8.3" / Skillbox Media

As a result, the information from the value table was displayed on the form.

Results

The value table allows you to work with various types of data, including sorting and grouping, as well as displaying it on forms. This tool can be useful when creating reports, analyzing query results, and creating new records in reference books and documents.

To learn more fascinating facts about programming, join our Telegram channel! We'll be glad to see you among our subscribers!

Read also:

  • Programming in 1C:Enterprise: A Guide for Beginners

    If you want to master programming in the 1C:Enterprise system, this guide will help you take the first step. In this material, we will cover the main aspects that will help you enter the world of development on this platform.

    First, you should familiarize yourself with the system itself. 1C:Enterprise is a powerful platform for automating business processes and is typically used for accounting and managing various aspects of business. Before delving into programming, it is recommended to study the basic functions and capabilities of the system.

    The next step is to understand the 1C programming language, called 1C:Enterprise Language. It is quite simple to understand, making it accessible to novice developers. It is recommended to start by learning basic language constructs, such as variables, loops, and conditional statements.

    It is also useful to familiarize yourself with the system architecture. 1C:Enterprise has a client-server architecture, and understanding its operating principles will significantly simplify the development process. You will learn how to manage data, interact with databases, and use various modules.

    Practice is important. You can only learn to program through experience, so it is worth starting with small projects or tasks. Gradually make them more complex by adding new features and improving existing ones.

    Don't forget about the developer community. There are many forums and groups where you can ask questions, share experiences, and find like-minded people. This is an excellent opportunity for learning and knowledge sharing.

    In conclusion, programming in 1C:Enterprise is a path full of possibilities. Starting with the basics, you can develop your skills and create powerful solutions for business. Good luck on your journey into the world of 1C!

  • The 1C programming language encompasses a number of important aspects, such as type systems, libraries, integrated development environments (IDEs), code aesthetics, and developer authenticity. These elements play a key role in creating and maintaining high-quality software solutions. The 1C type system ensures strong data typing, which minimizes errors and simplifies the development process.

    Libraries enable code reuse, which significantly speeds up development and facilitates a more efficient workflow. Integrated development environments offer developers convenient tools for writing, testing, and debugging programs, thereby increasing productivity and facilitating interaction with the language.

    Furthermore, code aesthetics is becoming an important factor, as well-structured and easily readable code facilitates its maintenance and development. Finally, the "authenticity" of developers implies a deep understanding of the language and its capabilities, which in turn leads to the creation of high-quality and reliable applications.

  • Passion and aversion to 1C: who should master "our" programming language and how to take a step into the world of large IT companies.

Specifics of the work 1C Programmer

We will help you master 1C programming and get your first job in just six months.

Find out more