Hi, I was wondering in visual cobol the files I read and write to are they in Access and Excel format?  Do I use SQL to access  these files and how to I tell the program where to look for the file.  The last part I can probablt figure out when I get the software.

  • Verified Answer

    If you mean the files you define in your COBOL program using file-control entries, etc, then no, they aren't in an Access or Excel format. Access and Excel are Microsoft applications and they use multiple file formats, none of which are suitable for COBOL indexed files. (At least that's true of the Excel file formats. I'm not sure what Access uses, but given its reputation, I'd be leery of it.)

    If you need to write a COBOL program that can use Access and Excel files, you should probably use COM objects provided by Microsoft for that purpose. There are alternatives (MS Office APIs, CSV files with Excel), but they're more complicated.

    Regarding your second question, no, you don't use SQL for file access. Embedded SQL is only used for operations against DBMSes. For file operations, COBOL provides various statements (OPEN, READ, etc), and MF COBOL also supplies library routines (CBL_OPEN_FILE, etc) for low-level file access. Or you can call OS or third-party APIs, directly or through interfaces like COM.

    There's a chapter on file handling in the product documentation:

  • Here is some extra information for you

    When you first start out, select New Project

    In the New Project window, on the left side, under COBOL, select NATIVE

    In the centre area of the window, select Console Application

    In the lower part of the window, type in a Name: (it is defaulted to ConsoleApplication1)

    The Solution Name field attracts the same name as you type

    Set the Location field - e.g. C:\Users\jeswoope\Documents\ProjectX\

    In the Solution field select Create new solution

    Now you will have a project to work with

    Then a Program1.cbl sample/skeleton program will appear and the Solution Explorer window on the right side

    What you can do here is to go to the actual project folder on your machine and put another program in there - it doesn't matter what it is for the time being

    Call it ABC123.cbl - use the .cbl extension (note: it will attract the .txt file icon under Windows Explorer but when you use Properties you will see it's a .cbl file)

    And, when doing this step, use the left side of the Windows Explorer window which will expand the project without trying to start it

    Dbl-click ProjectX and another ProjectX appears as subordinate to it

    Dbl-click that subordinate one and you will see the Program1.cbl file (notice the icon is as for a .txt file), a Projectx COBOL Project file and a ProjectX.dep file

    Copy your ABC123.cbl into there - it can be anything because you will replace the contents in the next few steps

    Now go back to MF VC and the Solution Explorer window on the right side (if the Solution Explorer window is not there you can select VIEW from the second top line on your screen and select Solution Explorer from there)

    Expand ProjectX so you see Properties and Program1.cbl

    Right click the ProjectX line then select Add then select Existing Item

    A little directory of your project will pop up on the left side of your screen

    You can see ABC123.cbl there - select it and click Add

    ABC123.cbl is now part of ProjectX and an Output window pops up to give you some status info - read it and then close it

    Back in the Solution Explorer window on the right side right-click Program1.cbl then select Exclude from Project

    Program1.cbl is no longer part of ProjectX but it's code is still in the ProjectX folder on your machine and you can keep it or delete it - whatever you want to do

    Assuming ABC123.cbl is a valid COBOL program you can now compile it

    Right-click ABC123.cbl and select Compile

    An Output window pops up - read the info in that window to get an idea of what it did, then close it

    Thus far, you have a project called ProjectX with program ABC123.cbl in it that has been compiled and at this point we assume it compiled clean

    Now you must Build the project

    Select BUILD on the second top line on your screen

    9 options appear

    For now, just concentrate on options 4, 5 & 6

    Select the 4th option - Build ProjectX

    Another Output window pops up - read it then close it

    From here you will probably just use Rebuild ProjectX and occasionally use Clean ProjectX

    At this point you will need to do the COBOL programming part

    Using the inbuilt (automatic) editor, modify your COBOL code so it does what you want

    Then select Rebuild ProjectX from the BUILD menu and keep doing that until you are happy with it

    To establish a stock standard flat file in your program, use this:








                  ACCESS IS SEQUENTIAL.

          DATA DIVISION.

          FILE SECTION.


          01  ABC123-DISPLAY-MESSAGES-RECORD      PIC  X(100).

    Note that all records in this file will be variable length, as in RECORDING MODE V on a mainframe, even though you pad out the record with spaces.

    Then you can use this:



    There is also OPEN INPUT just like a DSORG=PS flat file on a mainframe and then you can use this:

              READ <filename>

                AT END

                  PERFORM ... THRU ...    {or}

                  COMPUTE ...             {or}

                  MOVE, SET, ADD, etc

                  GO TO <filename>-END.

    There is also this:


    As for the overall programming, you will find this product extremely capable and very pleasurable to use

    You do not need to worry about EXTENTs or file allocations (the mainframe DD statement) as this is all done automagically for you, probably by Windows

    Now, to run program ABC123 go back to the Solution Explorer window on the right side of the 'Development Environment' area

    Select Rebuild ProjectX and if no errors you are ready to run it

    Note that Build ProjectX for the first time and then Rebuild, Rebuild, Rebuild, etcetera

    Even if you add another program into ProjectX you can just use Rebuild

    Next to BUILD on the second top line there is DEBUG - select it

    Options 2 and 3 are Start Debugging and Start Without Debugging

    It's up to you here but if you Start Debugging then you will need to familiarise with Stop Debugging and it's pre-requisites

    First, select the 3rd option Start Without Debugging

    Your ProjectX will run

    When a project runs it starts with the first program in the list and from there it's at your discretion of the ordering of all the other programs in the project, by way of your use of the CALL statement

    This works really well

    Put a DISPLAY 'PROGRAM ABC123 ENDED OK' line in there and you will see the window pop up

    The sample Program1.cbl has GOBACK

    I use EXIT PROGRAM. instead because you can run one of the programs stand alone or as part of a stream and EXIT PROGRAM works in both cases

    If you have coded your program to include something like this

               MOVE 'Hello World from ProjectX' TO ABC123-DISPLAY-MESSAGES-RECORD.


    you will then be able to look into "C:\SAMPLE\ABC123.DISPLAY.MESSAGES.TXT" and see what's in there

    There is a lot of information I have not included in here but this will get you going

    I must admit to taking several months of false starts to get MF VC working for me because of a lack of 'Simple Steps Documentation' to guide the user through the first steps

    Finally, one of the people on the Forum who supplies lots of advice pointed me along and I was able to get traction and get going

    The MOVE statement can be used like an IBM Assembler MVC or MVI statement

    For example, MOVE FIELDA (004:008) TO FIELDB (020:008).

    Depending on how you think and work, and on your programming background, you can use this version of MF VC in different ways, to suit your own style

    It's a really good product so take the time to get started and then pick up speed later on

    What I have put here is a very basic MF COBOL project and there are other more exotic ways of doing all this

    Storage SORTs

    As far as I know, the IBM mainframe COBOL cannot sort an array but MF VC can

    Use this:

                 01  WS-ABC123-MESSAGES-ARRAY-AREA.

                     03  WS-ABC123-MESSAGES-ARRAY      OCCURS 100.  

                         05  WS-ABC123-MESSAGES-KEY    PIC  X(050).


                     MOVE <data> TO WS-ABC123-MESSAGES-ARRAY (<subscript>)

                     SORT WS-ABC123-MESSAGES-ARRAY

                       ON ASCENDING

                       KEY WS-ABC123-MESSAGES-KEY.

    Write from SPACES

    Instead of moving spaces to the output record and then writing it, you can do this:


    That will write a blank line to your output file in one coded line

    This is a sample program I set up:


          PROGRAM-ID.    ABC123.








                  ACCESS IS SEQUENTIAL.

          DATA DIVISION.

          FILE SECTION.


          01  ABC123-DISPLAY-MESSAGES-RECORD      PIC  X(100).





            FROM 'Hello World from ProjectX'.



              EXIT PROGRAM.