PreviousUsing Net Express Introduction to Web ApplicationsNext

Chapter 6: Maintaining and Creating Data Files

You use the Data Tools in Net Express to convert, browse, edit and create data files used by an application.


You need to have read the chapter Start Here for the Tutorials and worked through the first session, Using Net Express, before you do this session.


6.1 Overview

Using the Data Tools, you can examine data files to see how an application has updated them, or create and edit a file to provide test data for an application. Files can be in any COBOL format and you can view them at both the record and field levels. You can convert between formats and character sets.

The demo application used in this session consists of a data file and the COBOL source program that maintains it. The data file is a variable length sequential file, containing details of staff in three record types: employee, manager and executive. In this session you convert it to a variable length indexed sequential file, and then view it in various ways, formatted and unformatted, using Data File Editor.

6.2 Preparation

If you have closed Net Express, open it as before. If any project window or other windows are open, close them.

To save you creating a project, we have supplied one - click Open on the File menu, and open d:\Program Files\MERANT\Net Express\Base\Demo\Dtoldemo\dtoldemo.app. You'll see the .cbl and .dat files in the project window.

6.3 Sample Session

In this session you:

6.3.1 Converting a File

To make an indexed sequential copy of the supplied sequential file:

  1. Click Data Tools on the Tools menu, then click Convert.

  2. To supply the input file details, click on the Browse button and use the Open dialog box to select the file datavseq.dat (the dialog box should open at the right folder, d:\Program Files\MERANT\Net Express\Base\Demo\Dtoldemo).

    The details for the the input file and the output file are initialized with the information read from the file header for datavseq.dat.

  3. In the lower part of the dialog box, enter the following details for the output file (leave the remaining fields unchanged):

    Filename d:\Program Files\MERANT\Net Express\Base\Demo\Dtoldemo\staff.dat
    Format Micro Focus
    Organization Indexed Sequential

  4. Click Define Keys, then click Insert Key.

    The field to be used as the key is at the beginning of the record, and is seven bytes long.

  5. Set Key Offset to 0 and Key Length to 7, then click OK.

  6. Click Convert.

  7. Click OK on the message saying the data file conversion is complete, then click OK on the message reporting the results of the conversion.

    The Data File Convert dialog box reappears so you can convert more files.

  8. Click Cancel.

  9. Look in the project window. Net Express has added the new file staff.dat to the project automatically.

6.3.2 Viewing a Data File Unformatted

To view the file you just created:

  1. From the project window, double click on the file staff.dat.

    A message box appears, explaining that all edits to indexed and relative file types are applied immediately.

  2. To prevent this message appearing again, click in the check box to add a check mark against the prompt Do not show this message again.

  3. Click OK.

    A Data File Editor window appears displaying the contents of staff.dat, as shown in Figure 6-1.

IDE

Figure 6-1: The IDE with a Data File Editor Window

Each record is shown as one line. Because Data File Editor does not know the lengths of the fields in the record, each line is simply a continuous line of text - the records are unformatted. Non-character fields such as COMP items generally display as non-standard characters or, if they don't correspond to any printable character, as .

You can edit the file by typing over the existing data. There are many editing facilities available. For example, the Data Tools option on the Search menu offers four ways of searching a data file:

The status line at the bottom of the IDE shows various statistics, depending on the file details:

The Data File Editor window may have a right-hand pane visible, displaying "A record layout file must be loaded before using this window". We'll see in a later section what this is for.

You can see the file's properties in full:

  1. Right-click in the Data File Editor window.

  2. Click File Information on the popup menu.

    The File Information window displays information such as the file format and organization.

  3. To view more information about the file, click on the Keys and General tabs.

  4. When you have finished, click on Cancel to close the File Information window.

  5. Leave the Data File Editor window open to use later in this tutorial.

6.3.3 Creating a Record Layout File

Data File Editor can display file contents formatted, if it knows the layout of the fields. You create a record layout file from the Data Division of a COBOL program that uses the file. You must have compiled the program to create the necessary information.

Our data file staff.dat has three record types: employee, manager, and executive. You have to tell Data File Editor the layout of each type of record, and how to identify the type. You define one type to be the default. The others are called conditional.

To create a record layout file:

  1. Select the project window.

  2. Right-click dfdstaff.cbl in the left-hand pane of the project window, and click Compile on the popup menu.

  3. Right-click dfdstaff.cbl again and click Create Record Layout on the popup menu.

    A Record Layout Editor window opens. This window displays a tree view of the data division of dfdstaff.cbl.

6.3.4 Creating the Default Record Layout

To create the default record layout:

  1. Expand the FD MF-FILE entry by clicking its "+".

  2. Right-click 01 EMPLOYEE-REC, then click New Record Layout on the popup menu.

    Default Layout should be set automatically as you have not yet defined a default layout.

  3. If it is not, click Default Layout to set EMPLOYEE-REC as the default record layout.

  4. Click Next, then click Finish.

    A folder for EMPLOYEE-REC-DEFAULT appears in the right-hand pane.

6.3.5 Creating the Conditional Record Layouts

To create a conditional record layout:

  1. Right-click 01 MANAGER-REC, then click New Record Layout on the popup menu.

    Conditional Layout is set automatically as you have already defined a default layout.

  2. Click Next, then click Finish, to add MANAGER-REC as a conditional layout.

    A folder for MANAGER-REC appears in the right-hand pane.

    You now need to specify the field and condition that identify the record type.

  3. In the right-hand pane, expand the MANAGER-REC folder by clicking its "+", then expand the 01 MANAGER-REC entry by clicking its "+", then expand the 02 MN-CODE entry by clicking its "+".

  4. In the right-hand pane, right-click 03 MN-POSITION, then click Properties on the popup menu.

    The Field Properties dialog box appears.

  5. Set Condition to IS = TO, by selecting it from the pulldown list.

  6. Type M (upper case) in the left-hand Condition field.

    M indicates a Manager record type. The two characters below the dotted line are the hexadecimal equivalent, arranged vertically. They should be "4" and "D", since M in ANSI is hex 4D.

  7. Click OK.

    A small red IF appears by 03 MN-POSITION in the right-hand pane.

  8. Create a conditional record layout for the Executive record type, by repeating this section replacing MANAGER by EXECUTIVE, MN-POSITION by EX-POSITION, and M by E.

6.3.6 Saving the Record Layout File

To save the record layout file:

  1. Click Save on the File menu.

    The Save As dialog box appears. The folder defaults to d:\Program Files\MERANT\Net Express\Base\Demo\Dtoldemo.

    The filename defaults to dfdstaff.str, which is the COBOL program name with a .str extension.

    When Data File Editor loads a data file, it looks in the same folder for a record layout file with the same name as the data file but extension .str. Our data file is named staff.dat. (Remember, we used the Data File Converter to convert datavseq.dat to staff.dat.)

  2. Change the File Name field for the record layout file to staff.str. Then click Save.

  3. Close the Record Layout Editor window by clicking Close on the File menu.

6.3.7 Viewing a Data File Formatted

When you open a data file, if a record layout file with the same name (apart from the extension) is present in the folder, that record layout file is used automatically. To apply a record layout file to a data file that is already open, or whose name does not match that of the record layout file, you must load it explicitly. This is called creating an association. Once you've created an association, that record layout file will be always used for that data file even if a record layout file with a name matching the data file is also present.

To load a record layout file:

  1. Click in the Data File Editor window that you left open earlier, to bring it to the front.

  2. Click Data Tools on the File menu, then click Load Record Layouts.

  3. Select staff.str and click Open.

    A new right-hand pane appears. The left-hand pane contains the unformatted view of multiple records, one per line, that you had before.

    In the right-hand pane, Data File Editor has applied the formatting information from the record layout file. This pane shows a formatted view of a single record. The record layout name is at the top of the pane. At the top right are two navigation controls: the small up-arrow takes you to the previous record and the small down-arrow takes you to the next record.

    You can edit a record by clicking in the Value column and typing over the existing data. The editing facilities mentioned earlier for the unformatted view are available in the formatted view too.

  4. Click in the left-hand pane, and move the cursor over the records in the unformatted view

    Notice how the formatted view alters, matching the record types as you move through the file.

6.3.8 Looking Up Information about a Record Layout File

You can find out the record layout file associated with a data file and review the conditions that you set up for the different conditional layouts:

  1. Right-click in the Data File Editor window, then click File Information on the popup menu.

    The File Information window opens. Because a record layout file is now associated with the data file staff.dat, the File Information window has a new tab Record Layouts.

  2. Click the Record Layouts tab.

    This window displays information about the record layout file staff.str associated with staff.dat. The top of the window displays the name and location of the record layout file.

  3. Under Layout Name, click on MANAGER-REC.

    The Conditions box underneath shows that, for Manager records, the field MN-POSITION equals M.

  4. Under Layout Name, click on EXECUTIVE-REC.

    The Conditions box shows that, for Executive records, the field EX-POSITION equals E.

  5. Click Cancel to close the File Information window.

6.3.9 Viewing Files in Hexadecimal

You can use Data File Editor to view and edit your data in hexadecimal:

  1. Right-click in the Data File Editor window (either pane) and click Show Hex on the popup menu.

    New panes appear at the bottom of the window. The left-hand pane shows the selected record from the top left-hand pane, with the hex beneath. For elementary field items only, the right-hand pane shows the selected field from the top right-hand pane, with the hex beneath. Otherwise, the right hand pane displays a text description such as Group item.

    Each pair of hex digits is arranged vertically. For example, when you edit ANSI data, an M is shown in hex as "4" with a "D" beneath. If you can't see both lines of hex, make the window bigger by dragging its bottom edge downward.

  2. Right-click within the Data File Editor window and click Show Hex on the popup menu.

    The check mark by this menu item disappears, and the hex panes disappear.

6.3.10 Printing a Data File

You can print a data file from Data File Editor using the Print function, or use the Print Preview function to display it on screen as it would appear when printed. You can choose the formatted or unformatted view. You can choose whether to print the current record, all records or partial records.

To preview a print of the unformatted view of a data file:

  1. Click in the left-hand pane of the Data File Editor window, then click Print Setup on the File menu.

  2. Set Orientation to Landscape, then click OK.

  3. Select Print Preview on the File menu.

  4. Check the checkbox beside Header Text and specify the heading text as Print of Data File STAFF.DAT.

  5. Put check marks by:

    and select:

  6. Click Preview.

    A Preview window appears. You can use the buttons on the toolbar to zoom in and out, move around the window, and print.

  7. Click Close on the buttonbar of the Preview window.

6.3.11 Editing Multiple Data Files

As with many of the editors in Net Express, you can use Data File Editor to edit several files at once, choosing various ways to position their windows within the IDE.

To edit two data files, putting their windows one above the other:

  1. From the project window, double click on the file datavseq.dat.

    A new Data File Editor window opens for datavseq.dat. Only the unformatted pane appears, as no record layout is associated with this file.

  2. Minimize the project window by clicking its button.

  3. Click Tile Horizontally on the Window menu.

    You can now see the Data File Editor windows for both datavseq.dat and staff.dat

  4. Toggle between the windows by clicking alternatively on the tags for datavseq.dat and staff.dat near the bottom of the Net Express window.

  5. Close both Data File Editor windows. Restore the project window to its normal size (click its button).

6.3.12 Creating a New Data File

To create a fixed length sequential file:

  1. Select New on the File menu, then select Data File and click OK.

    The Create file dialog box appears.

  2. Specify d:\Program Files\MERANT\Net Express\Base\Demo\Dtoldemo\newfile.dat in the Filename field, and 20 in the Maximum Length field, accept the defaults for the other fields, and click Create.

    Since a fixed length sequential does not have a file header, Net Express prompts you to save the file header details you have just entered in a profile file. Creating a profile saves you having to enter the file header details next time you open the data file.

  3. Click Yes.

    Net Express saves the profile in a profile file in the same directory as the data file. Profile files have the same filename as the data file with a .pro extension. Therefore, the profile file for this new data file is named newfile.pro.

    A Data File Editor window appears. It displays "File Empty".

    Let's add and delete a few records.

  4. Right-click in the Data File Editor window, then click Insert Record After on the popup menu.

    The cursor is positioned at the start of the file.

  5. Type abc.

  6. Right-click in the Data File Editor window, then click Repeat Record on the popup menu.

    A copy of the above record is added to the file.

  7. Right-click in the Data File Editor window, then click Delete Record on the popup menu, and click Yes on the Delete warning message box.

    The new record is deleted from the file and the cursor is positioned on the previous record.

  8. Click Save on the File menu.

  9. Close the Data File Editor window

6.3.13 Converting a File's Character Set

To make an EBCDIC copy of the supplied sequential file:

  1. Click Data Tools on the Tools menu, then click Convert.

  2. To supply the input file details, click on the Browse button and use the Open dialog box to select the file datavseq.dat.

    The details for the the input file and the output file are initialized with the information read from the file header for datavseq.dat.

  3. Click in the Convert character set check box to put a check mark there.

    The character set for the output file, shown in the lower half of the dialog box, changes from ANSI to EBCDIC.

  4. Click in the Records contain non-text data items check box.

    The converter needs to know where the non-text data items (items such as COMP fields) are, so as not to convert them. So you need to specify a record layout file. You have already created one describing datavseq.dat.

  5. Click Select layout for conversion. Use the Browse button on the Select layout for conversion dialog box to select staff.str, and click OK.

  6. In the lower half of the dialog box, enter ebcvseq.dat as the name of the new file, then click Convert.

  7. Click OK on the message saying the conversion is complete, then click Cancel.

    The new file ebcvseq.dat has been added to the project.

6.3.14 Viewing the EBCDIC File

When Data File Editor is open, the IDE has an extra toolbar, which includes a dropdown list to switch the Data File Editor window between ANSI and EBCDIC. To display the EBCDIC file you just created:

  1. Double-click ebcvseq.dat in the project window.

    Garbage is displayed because Data File Editor is expecting ANSI.

  2. On the toolbar, use the dropdown list to change the character set from ANSI to EBCDIC.

    The file is displayed correctly.

    This field on the toolbar affects only the current display in the Data File Editor window.

    To look at the file in formatted view, you cannot use the record layout file you created earlier because the comparisons to determine record type would use ANSI. You need to change Data File Editor's default character set to EBCDIC and create a new record layout file.

  3. Click Data Tools on the Options menu, then click the General tab.

  4. Using the dropdown list, change the Character Set field to EBCDIC. Click OK.

    This makes Data File Editor read and write all files in EBCDIC. You can now if you wish create and use a new record layout file, in the same way as you did earlier in the sections Creating a Record Layout File through Viewing a Data File Formatted.

  5. When you've finished, close the Data File Editor window.

  6. Click Data Tools on the Options menu, then change the character set back to ANSI, and click OK.

    If you normally use the ANSI character set, you need to keep this option normally set to ANSI.

6.4 Before Continuing

Close the project. If you want to take a break before going on to the next session, you can close Net Express.

Return to the Tutorials Map in the chapter Start Here for the Tutorials and choose which session to go on to next, depending on your interests.


Copyright © 2000 MERANT International Limited. All rights reserved.
This document and the proprietary marks and names used herein are protected by international law.

PreviousUsing Net Express Introduction to Web ApplicationsNext