How to prevent the printing of a report programmatically

By | July 27, 2020

In Sage X3, we may come across a situation where we need to prevent printing of a report and we can achieve this using code.

Steps to follow : 

To prevent printing of a report we need to create a specific processing script for the report and put the following code in the file.

Script Editor

The principle is that when you set GOK to 0, the report will not be printed. Of course, you have to substitute the dots after ‘If’ with the appropriate condition. For example, suppose that you print a report from the Deliveries function (GESSDH) and you want to print it only if the delivery is validated then you need to put specific conditions to prevent report printing.

This action is called just before the printing of the document by Crystal Report. Warning! This action is mandatory, if an initialization process is specified in the report dictionary. It is not called by the instruction Gosub but by the Call instruction. Two parameters are passed to it, NBPAR (number of parameters) and PARAMETRE (parameters grid).

It is used for other functionalities as well which are explained in below points:

  • As mentioned, it is used for preventing report printing when GOK variable value is set to 0.
  • To update the X3 tables (for e.g. print flags etc.)
  • construct a work table in order that the data may be more easily used by par Crystal Report.

It has also been used as an entry point. It was developed for earlier versions of X3.

Entry point IMPRIME had been created for one of the initial X3 versions. It had to be called just before selecting the printer and made it possible to inhibit the printer entry if variable GPE was different from 0.

The parameters are stored in the PARAMETRE variable with the indices 1 to NBPAR. Each value is a string in the form of “parameter=value” without any other separator.

At this level, the report parameters may be used that are stored in the PARAMETRE (1.NBPAR) grid where NBPAR is the number of parameters A parameter is expressed in this grid in the form : parameter name = parameter value.

There is also DEFIMP entry point which is used to return printer name (destination code) by entering the IMPRIMANTE variable and, if a printer’s name is mandatory.

This entry point is called at the end of the subprogram used to determine a default printer (destination code) even though a printer cannot be found after the standard setup.

This subprogram is called by the AIMDEF action and is usually called in order to initialize the printer before printing a report.

There are also other entry points which are used in the same prospect for the report printing process. (e.g. ALIMETAT) So, this entry points along with other subprogram has various uses for printing reports and other functionalities in X3 as explained in the above blog.

This blog helps to understand how we can prevent report printing pro-grammatically. Beside that it can be used for other usage which are explained in the above points.