Editing Source Files

This topic describes the editing features for the various file types (COBOL, JCL, IMS, BMS, and Data Files).
Important: We recommend that you create backup copies of all files before you start editing them.

Editing COBOL Files

You are going to explore some of the COBOL editing features using the ZBNKPRT1.cbl program which produces a report from a sequential data file.

  1. In the Application Explorer view, double-click ZBNKPRT1.cbl in the Sources/cbl folder of the project.

    This opens the file in the COBOL editor in Eclipse.

Copybooks
  1. Scroll down the file until you see some COPY statements.
  2. Press F4 to open the file in COBOL Copy View, which shows the code of the copybooks expanded in the source file.

    The COBOL Copy View is read-only and you cannot edit the code in it. The screen background changes from white to pale yellow.

  3. Press Ctrl+F4 to close the COBOL Copy View.
  4. To edit a copybook, position the cursor on the COPY statement and press F3 (Go To Definition).

    This opens the copybook file in a new tab in the editor.

Copybook Dependencies
By expanding a source file node in the Application Explorer view, you can see a list of all copybooks referenced in the source code, and nested within them any other copybooks referenced by those copybooks. Double-click a copybook to open it in the editor.

Use the Copybook Dependency view to show where in the source file's structure the COPY statements appear, and which copybooks they reference. If the Copybook Dependency view is not displayed in the Team Developer perspective, to open this view click Window > Show View > Other > Micro Focus > Copybook Dependency.

Click a copybook reference in the Copybook Dependency view to locate the associated COPY statement at the appropriate line in the source code.

Unused data
Notice that some data items in the Data Division are crossed out. This is because they are not referenced in the Procedure Division.
Program outline
  1. Right-click anywhere in the COBOL editor and select Quick Outline.

    This opens a pop-up with the outline of the program similar to what the Outline view shows.

  2. Press Ctrl+O in the pop-up to see a more detailed outline similar to the Program Outline view.
  3. Double-click an item in the outline to see how the cursor positions itself on the line of code that this outline item refers to.
  4. Click on the permanent Outline view.

  5. Expand and collapse various lines in the Outline view.
  6. Double-click items in the Outline view to see how the cursor positions itself on the respective line of code that each one of these outline items refers to and highlights the referenced item in the editor window.
  7. Click the (Sort) in the Outline view to toggle between a physical or alphabetical sequence.
Hyperlinks
  1. In the editor, scroll down the file to a line in the Procedure Division.
  2. Press and hold Ctrl and move your mouse around the code.

    This turns the data items and the paragraph names you hover over into hyperlinks.

  3. Click one of the hyperlinks to position the cursor on the definition of the respective data item or paragraph.
Viewing data definitions
  1. Hover over a data item in the Procedure Division to see information about the data item and how many times it is used in the program.
  2. Clicking a data item or paragraph name highlights all their occurrences in the code.
Breadcrumbs
The (Toggle Context Breadcrumbs icon) in the toolbar lets you see another view of the program showing the copybooks.
  1. Click the icon to enable breadcrumbs.

    This opens a new toolbar in the editor with the name of your COBOL program.

  2. Click the arrow to the right of the program name to see a list of copybooks the program uses.
  3. Click one of these copybooks to load it in a new tab in the editor.
Marking text and block mode
You can either use the mouse to mark a block of text or click (Toggle Block Selection Mode) and select square blocks of text. When a selection is made, you can cut or copy it.
Rename
You can use rename refactoring to rename all occurrences of a variable:
  1. Scroll down to line 022000 in the file.
  2. Double-click WS-EXEC-PARM-LL to select it and click Refactor > Rename.

    A pop-up is displayed prompting you to enter a new name for the variable.

  3. Click the down arrow to show the context menu and click Open Rename Dialog.
  4. Specify WS-EXEC-PARM as a New name in the dialog box and click Preview.

    This opens the Rename COBOL Element dialog box that enables you to preview and approve

  5. Click Cancel as you are not going to apply these changes for this demo.

You can change your Eclipse preferences and rename without the Rename COBOL Element dialog box. To do this, go to Window > Preferences > Micro Focus > COBOL > Editor and uncheck Rename in editor without dialog.

Smart editing
Next, we are going to look at smart editing with background COBOL parsing. First you'll check the IDE preferences for suggestions that Content Assist offers you in the editor:
  1. Click Window > Preferences > Micro Focus > COBOL > Editor > Content Assist.
  2. Check Enable auto activation then click Apply and Close.
  3. Scroll down to line 025000 in the code and start typing the following, starting in area A of the code, one character at a time:
    MOVE W TO

    Notice how the words you type change in the editor. Once a word is recognized as a reserved word or a data item, its color changes. If a line of code contains invalid COBOL syntax, a red cross appears to the left of the line and the word is underlined with a wavy red line.

    Also, Content Assist automatically displays a pop-up with suggested keywords and names of data items appears as you type.

  4. Change the line to:
    MOVE 34 TO WS-

    If the IDE preferences for auto-activation of Content Assist have not been changed, Content Assist opens a list of potential data names that start with WS- to choose from. If Content Assist does not display a list, to open it manually click Ctrl+Space.

  5. Finally, if you have changed this COBOL program, copy the backup version back in again.
Renumbering the COBOL sources
You can use the commands Renumber and Unnumber to insert and remove line numbers from your code. Your sources include some comments beyond column 73, so you need to configure the line numbering in order to ensure you only apply changes to the COBOL sequence area:
  1. Click Window > Preferences > Micro Focus > COBOL > Editor > Line Numbering.
  2. Ensure that only the COBOL (left-hand margin) option is enabled.
  3. Click Apply and Close.

You can now remove the line numbers from your code:

  1. Right-click the ZBNKPRT1.cbl file in the editor, and click Source > Unnumber. Alternatively, click Unnumber icon in the Eclipse toolbar.
  2. Click Yes to confirm.

    This removed the line numbers from the COBOL sequence area.

To reinsert the line numbers in your code:

  1. Right-click the ZBNKPRT1.cbl file in the editor, and click Source > Renumber. Alternatively, click Renumber icon in the Eclipse toolbar.
  2. Click Yes to confirm.

    This reinserts the line numbers from the COBOL sequence area.

To insert line numbers beyond the end of area B:

  1. In the IDE preferences for line numbering, check Standard (right-hand margin).
  2. Click Apply and Close.
  3. Right-click the ZBNKPRT1.cbl file in the editor, and click Source > Renumber.
  4. Click Yes to confirm.

    You should now see line numbers running down both sides of the source code:

    COBOL line numbering
  5. Click Edit > Undo Typing as necessary to revert your changes to the file.

JCL and IMS editing

  1. Double-click the JCL file in the Bankdemo project to open it in the associated editor.

    The editor supports background parsing, syntax checking, content assist and an outline view like the COBOL Editor does.

    Note: You can open and edit DBD, PSB, and MFS files in the same way. The editors open these files in text view and offer a basic level of colorization for items such as reserved words and comments.

BMS editing

There are two ways to edit BMS files. The first one is to use the basic BMS text editor available in the IDE. The other is to use a WYSIWYG version, the Micro Focus BMS Painter, which is available as a separate utility installed with this product.

To open the BMS file in the IDE text view:

  1. In the Application Explorer view, right-click MBANK10.bms in the bms folder and click Open With > BMS Text Editor.

Although you can use this basic text editor to make small changes, it is quite difficult to edit BMS files in text view.

A much more suitable and less error-prone way to edit BMS files is to use the BMS Painter.

  1. Close the BMS text editor.
  2. In the Application Explorer view, right-click MBANK10.bms in the bms folder and click Open With > BMS Paint.

    This starts the external Micro Focus BMS Painter.

    BMS painter window

  3. In BMS Painter, you can click fields and move them by dragging.

    For example, double-click the data field immediately following the text “User Id” and move it to a different position on the map.

  4. To add a field, click in the desired place in the window and start typing.
  5. To change a field's properties, right-click it and select Properties.
  6. To change the properties of the map or mapset, right-click the item and select Properties.

    For example, do this for the MBANK10 mapset and the BANK10A map.

  7. Click File > Exit to close the utility and do not save the file.

Editing data files

You can edit data files using one of two available Micro Focus data editors - the Classic Data File Tools which was available with Net Express and a newer one, called Data File Tools.

  1. In the Application Explorer view, right-click the .dat file and click Open With > Classic Data File Tools.

    Close the utility now as we are going to use the new one for this demonstration.

To use the new editor:

  1. In the Application Explorer view, right-click the .dat file and click Open With > Data File Tools.

    This starts the Data File Editor and loads the .dat file in the Open Data File dialog box.

  2. Click Open Exclusive to load the file.
  3. Data File Editor loads the data file and shows two views:
    • The left-hand pane shows the raw form of the file. Because many of the field are COMP-3 fields, the data in these fields is presented in an ASCII view.
    • The right-hand pane shows the record layout for the file in its detailed field view and the COMP-3 fields are shown in a much better, editable form.

  4. Change the value of BAC-REC-BALANCE from 91.14 to 132.76 as follows:
    1. Click the line for BAC-REC-BALANCE in the right pane and then click , Edit Record.

      This highlights the record.

    2. Double-click in the Value field for BAC-REC-BALANCE.
    3. Type 132.76 then click , Save Record.
    4. Confirm you want to save the changes to this record.
    5. Using the same method, restore the previous value of BAC-REC-BALANCE.
  5. Close the Data File Tools utility.