ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Perform varying // for - array in cobol

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Perform varying // for - array in cobol

    Hi guys,
    I have a question if you could me help with these:
    I want to implement in cobol a repetitive structure like these:
    for i = 1 to n
    execute different instructions
    end-for
    -----
    I make something like these:
    01 n pic 9(2) value 1.
    01 ws-x.
    05 ws-a pic x(500) occurs 1000 times.
    indexed by n.
    ---
    perform varying i from 1 by 1 until i > n
    //different instructions
    end-perform
    ..
    but I have some errors for n when I compile, I get LNC1463 " 'N' is not unique in this context"
    How I can resolve these? please help me with some info regarding for in cobol and how I can arrive to the end in perform varying structure, I'm newbie in cobol :P, thanks in advance.

  • #2
    Re: Perform varying // for - array in cobol

    Don't define N at the 01 level. The system defines it automatically.

    Comment


    • #3
      Re: Perform varying // for - array in cobol

      The COBOL manual describes the INDEXED BY clause with this: "These index-names are not data-names, and are not identified elsewhere in the COBOL program...". When you code an INDEXED BY clause, the clause defines the index variable as a special data type. You can't define a variable with the same name in the same scope.

      That's about all there is to it.
      Tom

      There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

      Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

      Comment

      Working...
      X