0

I would like to know how to use a COPY statement. I am on Linux and I use GnuCOBOL with Visual Studio.

I have already tried several things but nothing works...

Here is my code:

   identification division.
   environment division.
   data division.
       working-storage section.
       copy laCopy.

   procedure division.

       accept w-user-entry.
       display w-user-entry.
       stop run.

and my copy :

   identification division.
  *environment division.
  *data division.
       working-storage section.
       01 variable.
          05 w-entreeUser PIC X(100).
       
   procedure division.
       stop run
  * GOBACK
       .

Each time I get the following error message:

laCopy:1: Error: Invalid indicator '' at column 7

Rick Smith
  • 3,962
  • 6
  • 13
  • 24
  • What byte is at position 7 in laCopy? Are there tabs before? [can you post the first bytes as hex (there's the ms hexeditor extension that will allow you to easily have a look in vscode]. – Simon Sobisch Jul 24 '22 at 13:46
  • This copy is no copy, but a program with missing division. Commonly you define (only) variables in copybooks or (only) procedures, then use the `COPY` statement to get it included (similar to C's `#include'). To use multiple programs compile both separate then use `the CALL` statement in the first program to call the second. As it is missing: Which GnuCOBOL version do you use [start the terminal, then `cobc --version` to get that info]? – Simon Sobisch Jul 27 '22 at 12:27

2 Answers2

2

Cobol comes from the age of punch cards. The first seven columns in a line are reserved. I forgot what the first six are, but the 7th is used for (among other things), comments: If there is a * in that column, the line is commented out. Your code does not use exactly seven spaces at the beginning of the line.

This compiles for me:

       identification division.
       program-id. hello.

      *environment division.

       data division.
       working-storage section.
       01 variable.
          05 w-entreeUser PIC X(100).

       procedure division.
       display 'test'.
       stop run.
      *GOBACK
Robert
  • 7,394
  • 40
  • 45
  • 64
  • 2
    The indicator area (column 7 in fixed-format COBOL) can be '*' (a comment), '/' (comment line with page ejection), or '-' (line continuation). This last is "an obsolete feature and is to be removed from the next edition of standard COBOL" according to section 6.2.1 of the [latest draft standard](https://isotc.iso.org/livelink/livelink?func=ll&objId=19468956). – cschneid Jul 23 '22 at 20:45
  • I expressed myself badly, in fact I manage to compile my copy, but when I try to compile my program which calls my copy I have the error: laCopy:1: Error: Invalid indicator '' at column 7 – Nolween_deadra Jul 27 '22 at 12:05
  • The copybook cannot be "called", it can only be "included" with the `COPY` statement. If it would be included correctly then you should not get this strange message - but directly afterwards a parser error - see comment on the question. – Simon Sobisch Jul 27 '22 at 12:24
  • I use the COPY statement to use my copy, but I always get the error.. – Nolween_deadra Jul 28 '22 at 14:55
0

I think the problem is that you have cobol code in your copybook.

Your copybook should have only variable definitions and should be like this:

        01 variable.
          05 w-entreeUser PIC X(100).

As @Robert stated above in cobol you can use the 8th column onwards.