With the CREXPORT tool, it is possible to create batch print or multiple files export from a report in one step. CREXPORT can also be used for starting an export/print based on a parameter.
The following prerequisites should be met:
-
.NET Framework 4
-
SAP Crystal Reports runtime engine for .Net Framework 4. Make sure that the installed bit-version corresponds to the bit-version of your operating system otherwise it will not work.
Download CREXPORT
Download CREXPORT here: http://www.rainforestnet.com/crystal-reports-exporter/download.html
For more information about the program see: http://www.rainforestnet.com/crystal-reports-exporter/how-to-use.html
Test if CREXPORT working correctly with the standard script and a report without parameters.
For more information about the program see: http://www.rainforestnet.com/crystal-reports-exporter/how-to-use.html
Test if CREXPORT working correctly with the standard script and a report without parameters.
General Process
Once CREXPORT is installed, create a batch file with your command.
IMPORTANT: .bat file + CREXPORT.EXE + Crystal Reports must all be in the same folder!List of arguments that can be used in CREXPORT:
IMPORTANT: .bat file + CREXPORT.EXE + Crystal Reports must all be in the same folder!List of arguments that can be used in CREXPORT:
-
-U: Data source/ server login username
-
-P: Data source/ server login password
-
-S: Server Name
-
-D: Database Name
-
-F: Crystal Reports filename (i.e. “C:\Report Source\Report1.rpt”)
-
-O: Crystal Reports Output filename (i.e. “C:\Reports Output\Report1.pdf” )
-
-E: Specifies the intended export file format. (i.e. pdf, doc, xls .. and etc). To print directly, add: -E print instead of specifying the file format.
-
-N: Specifies the printer name. To add a network printer, use: -N \ \computer01\printer1. If printer name is not specified, the default printer will be used.
-
-a: Pass Crystal Reports file parameter set on run time
EXAMPLE 01: Export multiple invoices to pdf files
Create BAT file:
For creating multiple .pdf files add the input parameters through an additional .txt file. Please note: Input parameters are case sensitive.To print multiple invoices, we will use these parameters for Crystal Reports:
First create the .txt file. Run a query which lists the docentries of the invoices. Save the list in a txt file. E.g.: ‘Invoice.txt’.
-
DocKey@
-
ObjectID@ (13 invoice)
First create the .txt file. Run a query which lists the docentries of the invoices. Save the list in a txt file. E.g.: ‘Invoice.txt’.
Then create the batch file. E.g.: ‘PrintInvoice.bat’. Add the following command:
The parameter -a “ObjectID@:13 is hardcoded. It refers to sales invoices (OINV table). The next parameter -a “DocKey@:% %a” will get the DocEntry from the .txt file.Setup the database connection with the –U, -P, -S, -D arguments and define the path to the report after he –F argument.
for /f %%a in (Invoice.txt) do ( crexport.exe -U USERNAME -P PASSWORD -S "SERVER" -D "DATABASE" -F "C:\COMPANY\PDF\Report.rpt" -O "C:\COMPANY\PDF\OUTPUT\INVOICE\Output.pdf" -E pdf -a "ObjectID@:13" -a "DocKey@:%%a" run "C:\COMPANY\PDF\OUTPUT\INVOICE\Output.pdf" "%%a.pdf")This creates a loop that will run through the Invoice.txt file and will pick up every new DocEntry.The first line for /f % %a in (Invoice.txt) do will call the txt file.
The parameter -a “ObjectID@:13 is hardcoded. It refers to sales invoices (OINV table). The next parameter -a “DocKey@:% %a” will get the DocEntry from the .txt file.Setup the database connection with the –U, -P, -S, -D arguments and define the path to the report after he –F argument.
Output files
When creating output files instead of direct prints, define the output folder and file name after the –O argument and add the file format after the –E argument. It is not possible to add a variable file name. To avoid the constant overwriting of the file, add the following code which renames the output file to the DocEntry:
run "C:\COMPANY\PDF\OUTPUT\INVOICE\Output.pdf" "%%a.pdf")It is also possible to change the file name to another parameter by calling an additional batch file. For example, run the query
SELECT CAST("DocEntry" AS nvarchar) + '.pdf ' + CAST("DocNum" AS nvarchar) + '.pdf' FROM OINVwhere the DocEntry is the input parameter (original file name) and the DocNum is the new file name. Copy it and save as a text file, e.g.: RenameFiles.txt.Create the batch file for renaming with the command below. E.g.: Rename.bat.
for /f "usebackq tokens=1,*" %%a in ("C:\COMPANY\PDF\OUTPUT\INVOICE\RenameFiles.txt") run "%%a" "%%b"
Place the code below under the previous code in the first batch file (‘PrintInvoice.bat’).
cd C:\ COMPANY\PDF\OUTPUT\INVOICE call C:\ COMPANY\PDF\OUTPUT\INVOICE\Rename.bat
E.g. 51492.pdf will be renamed to 14102015.pdf.
Print directly
To print directly, add the word “print” after the -E argument and define the printer with the –N argument. To print with a network printer, use: -N \ \computer01\printer1.
EXAMPLE 02: Print item label after entering the Item Code and Serial Number
It is also possible to add extra parameters to the label with CREXPORT. In our example the Item Code and the Serial Number will be the extra parameters that have to be entered.
First create a report containing the Item Code/ Serial Number and the barcodes and import it to SAP. (In the example: Report.rpt= report, @itemcode= parameter for the Item Code on the report @serialnumber= parameter for the Serial Number on the report)
Then create the batch file with the following script:
First create a report containing the Item Code/ Serial Number and the barcodes and import it to SAP. (In the example: Report.rpt= report, @itemcode= parameter for the Item Code on the report @serialnumber= parameter for the Serial Number on the report)
Then create the batch file with the following script:
@ECHO OFF :start ECHO GET ITEM CODES AND SERIAL NUMBERS ECHO ------------------------------------- SET /p ItemCode=Item Code: SET /p SerialNumber= Serial Number: crexport.exe -U USERNAME -P PASSWORD -S "SERVER" -D "DATABASE" -F "C:\LABELS\Report.rpt" -E print -N "\\computer01\printer1" -a "@itemcode:%ItemCode%" -a "@serialnumber:%SerialNumber%" ECHO. ECHO.After launching the batch file, enter the Item Code and Serial Number on the command window. The label will only printed if the combination of the item code and serial numbers exists in the system.
Comments
0 comments
Please sign in to leave a comment.