Open topic with navigation
PL1 include files (a.k.a. PL1 copybooks) can be converted into COBOL copybooks in a DMExpress job. The COBOL copybook can subsequently be used as metadata in a DMExpress task to interpret and transform corresponding data sources created by a PL1 program.
A copybook is a file on disk containing a fragment of a COBOL program. The fragment is included in the COBOL source code at compile time by means of the COPY statement. A common example of a copybook is the description of a record layout which is used in multiple locations in the program in order to reduce coding and avoid inconsistencies. Many other languages, like PL1, have a similar feature and often use the keyword "include" instead of “copybook”.
DMExpress supports external metadata in a COBOL copybook, allowing you to link to or import record layouts directly from the copybook. Copybooks and include files used by other programming languages, such as PL1, Natural (a 4th generation language from Software AG), and Assembler, are not natively supported in DMExpress. However, when the structure of the unsupported include file is sufficiently similar to that of a COBOL copybook, and the data types can be mapped one-to-one in a reasonable way, it is possible to convert the include file into a COBOL copybook:
Attached to this article is a set of examples containing two DMExpress jobs and associated files. The first example, CONVERT_PL1_TO_COBOL.dxj, converts a PL1 include file to a COBOL copybook, and the second example, PROCESS_FILES.dxj, uses the copybook generated from the first job to process PL1 files.
The conversion solution in DMExpress consists of one job, CONVERT_PL1_TO_COBOL.dxj, with three tasks. The tasks run in sequence and are connected via a direct data flow, though you can switch to intermediate files to inspect the data transferred between tasks and debug the job in case of problems.
The task T01_GET_TOKENS.dxt identifies the syntax elements in a PL1 include file.
The input to the task is a PL1 include file, specified via the environment variable PL1_COPYBOOK. Each line in the file is scanned for PL1 syntax elements, and identified keywords are written to a target file called TOKENS.txt.
The following is assumed for this task to work properly:
The task uses a series of functions and a regular expression to accomplish the following steps:
In the last step, the pattern below is used 4 times to extract the different elements by position number:
([^ ]+) +([^ .]+)[ .]([^(]*)([^.]*)
where the elements are matched as follows:
The results from these steps are written to TOKENS.txt as follows:
The task T02_TRANSLATE.dxt converts the PL1 include syntax into the corresponding COBOL copybook syntax.
The output of the first task is translated from PL1 syntax into COBOL copybook syntax by using a lookup table, MAP_TYPE_PL1_COBOL.txt, for data type (shown below), and another lookup table, MAP_DETAIL_PL1_COBOL.txt, for details. These lookup tables can be expanded or modified as required. Transformation rules are used to re-calculate precision and scale for numerical data types, and additional ones may be required if you modify the lookup table.
The results of the translation are written to TOKENS_TRANSLATED.txt as follows:
The task T03_CONSTRUCT_COPYBOOK.dxt assembles the COBOL copybook using the translated syntax elements.
The translated elements are finally put together in a COBOL Copybook by using a reformat and conditions to determine the correct content for each field.
This copybook can be referenced or imported in a DMExpress task, as shown with expanded level 01 ITEM and ORDERS below:
The PL1 data processing solution in DMExpress consists of one sub-job to perform the PL1 to COBOL conversion described above, and one task for each PL1 source file to be processed. In this example, there are two PL1 source files, so there are two tasks, and the copybook contains two level 01 layouts, one for each source file. The tasks to process DEMO_ORDERS.dat and DEMO_ITEMS.dat run in parallel.
The details of the CONVERT_PL1_TO_COBOL.dxj sub-job are described above.
Note that the conversion job could be run as a separate job scheduled to run before the data processing job rather than as a subjob.
The task READ_ORDERS.dxt reads the PL1 file DEMO_ORDERS.dat using the previously created copybook with level 01 name ORDERS. The task converts EBCDIC encoding to ASCII, removes all trailing 0x00 (padding) characters from the text fields, converts fields to numerical format, and finally sorts the records on CUSTOMER_ID.
The task READ_ITEMS.dxt reads the PL1 file DEMO_ITEMS.dat using the previously created copybook with level 01 name ITEM. In this case, no NULL character cleansing is done and binary numbers (COMP) are converted into edited numerical format.
415_PL1_to_COBOL.zip, compatible with DMExpress version 9.0.2 or higher. Included is a script for running the sample jobs.
The indentation of the levels usually seen in COBOL copybooks is simplified in the attached example job to reduce the complexity; only the indentation levels required for correct interpretation of copybooks by DMExpress are included.
COBOL layouts have levels indicated by 2-digit numbers ranging from 01 to 49 and “special” levels 66 and 88. The convention is to increment copybook levels by a number greater than 1, but the levels are incremented by 1 in the attached example job for simplicity. The job can be modified to increment by a different factor.
Copyright © 2016 Syncsort All rights reserved.