Page 1 of 1

question on perform varying

PostPosted: Sat Sep 13, 2008 6:24 pm
by jollymcmuffin
given:

01 TABLE1.
     05 TABLE-1 OCCURS 4 INDEXED BY T1.
          10 SNUM     PIC X(4).
          10 SNAME   PIC X(30).
          10 GRADES OCCURS 3 INDEXED BY G1.
          10 FGD       PIC 999V99.


first question, is there something wrong with this table? can i also index the second table? :?:

can i also use the code given below, or will it cause an error or abend? :?:

MAIN-RTN
.
.
.
.
.
.
     PERFORM 100-PRINT-RTN VARYING FROM 1 BY 1
          WHEN T1 > 4
             AFTER G1 > 3
.
.
.
.
.
.
.
100-PRINT-RTN SECTION.
100-PRINT.
  MOVE SNUM(T1).
  MOVE SNAME(T1).
  MOVE GRADE(T1 G1).
  MOVE FGD(T1).
100-EXIT.
       EXIT.

Re: question on perform varying

PostPosted: Sat Sep 13, 2008 6:53 pm
by jollymcmuffin
jollymcmuffin wrote:had some errors on my first post so i'm reposting.. :oops:
given:

01 TABLE1.
     05 TABLE-1 OCCURS 4 INDEXED BY T1.
          10 SNUM     PIC X(4).
          10 SNAME   PIC X(30).
          10 GRADES OCCURS 3 INDEXED BY G1.
               15 GRD1       PIC 99V99.
               15 GRD2       PIC 99V99.
          10 FGD       PIC 999V99.


first question, is there something wrong with this table? can i also index the second table? :?:

can i also use the code given below, or will it cause an error or abend? :?:

MAIN-RTN
.
.
.
.
.
.
     PERFORM 100-PRINT-RTN VARYING FROM 1 BY 1
          WHEN T1 > 4
             AFTER G1 > 3
.
.
.
.
.
.
.
100-PRINT-RTN SECTION.
100-PRINT.
  MOVE SNUM(T1).
  MOVE SNAME(T1).
  MOVE GRD1(T1 G1).
  MOVE GRD2(T1 G1).
  MOVE FGD(T1).
100-EXIT.
       EXIT.

Re: question on perform varying

PostPosted: Sun Sep 14, 2008 9:49 pm
by dick scherrer
Hello,

What happens when you compile this?

first question, is there something wrong with this table?
The table definition looks ok unless GRADES ever becomes a reserved word. It is good practice to not use "real" words by themself (GRADES could become GRADES-1). It would also be helpful if all of the fields n the array had the same suffix (i.e. -1 or whatever).

can i also index the second table?
What you have defined is a 2-dimensional table rather than a second table. Yes, you can index the both dimensions (as you have done in the code).

I suspect the PERFROM will not successfulle compile. Look here for the rules for coding:
http://publibz.boulder.ibm.com/cgi-bin/ ... 0/6.2.27.5?
In addition to syntax rules changes, i believe you will need to re-think how to deal with the 2 dimensions and terminate each loop when there is no data at that displacement.

Once the syntax is changed, i believe there may still be problems - possibly because the array is not initialized and possibly because the code does not check to see if there is any data in the fields referenced "at that time". How does the data you want to print get into the array in the first place?

Re: question on perform varying

PostPosted: Sun Sep 14, 2008 11:12 pm
by jollymcmuffin
thanks for the reply dick.. the code i have given was just a general example code..

the table i am using is actually using an "occurs depending on...." clause that's why the table wasn't initialized..

and the perform varying statement i'm using is under a perform until clause with one of the condition terminating the program if it has reached the end of the file.

i'm sorry, i was in a hurry in writing the sample code.. here is, generally, what i'll be using..

01 GRADESFILE.
    05 SNUM     PIC X(4).
    05 SNAME   PIC X(30).
    05 GRDS OCCURS 3 INDEXED BY G1.
         10 GRD1       PIC 99V99.
         10 GRD2       PIC 99V99.
    05 FGD       PIC 999V99.

01 TABLE1.
     05 TABLE-1 OCCURS 4 INDEXED BY T1.
          10 T-SNUM     PIC X(4).
          10 T-SNAME   PIC X(30).
          10 T-GRADES OCCURS 3 INDEXED BY G1.
               15 T-GRD1       PIC 99V99.
               15 T-GRD2       PIC 99V99.
          10 T-FGD       PIC 999V99.

MAIN-RTN
.
.
.
.
.
.
     PERFORM 100-PRINT-RTN VARYING T1 FROM 1 BY 1
          UNTIL T1 > 4
             AFTER G1 FROM 1 BY 1
                UNTIL G1 > 3.
.
.
.
.
.
.
.
100-PRINT-RTN SECTION.
100-PRINT.
  INITIALIZE TABLE-1.
  MOVE SNUM TO T-SNUM(T1).
  MOVE SNAMETO T-SNAME(T1).
  MOVE GRD1 TO T-GRD1(T1 G1).
  MOVE GRD2 TO T-GRD2(T1 G1).
  MOVE FGD TO T-FGD(T1).
  WRITE GRADESFILEREC FROM DTL-LN AFTER 1.
100-EXIT.
       EXIT.


will this still yield an error?

Re: question on perform varying

PostPosted: Mon Sep 15, 2008 1:26 am
by dick scherrer
Hello,

the table i am using is actually using an "occurs depending on...." clause that's why the table wasn't initialized..
Then why is that not what you posted. . . :( There is still no depending in the code you posted. If you are going to print from the table, it had to get initialized/loaded somewhere.

i'm sorry, i was in a hurry in writing the sample code.. here is, generally, what i'll be using..
You've wasted far more time with this "scurry" than if you'd taken just a bit more time and posted properly. Do not post generally! Post what you have and what doesn't work or you don't understand. In addition to wasting time, it is rather rude to those who might be willing to help if you cannot be bothered to post your actual code/question. Keep in mind, you do not need to be in a hurry. If we could all be in the same room and talk things thru in real-time, "hurry" might not matter so much as corrections/mis-understandings could be recognized and handled "on the spot". Going thru the forum with all of us in different time zones, it makes accuracy/completeness much more important.

and the perform varying statement i'm using is under a perform until clause with one of the condition terminating the program if it has reached the end of the file.
It is good to terminate the program at end of file, but that has nothing do to with termininating the "print loop" properly.

will this still yield an error?
As coded, the print loop will probably process incorrectly.

Re: question on perform varying

PostPosted: Mon Sep 15, 2008 1:57 am
by jollymcmuffin
Do not post generally! Post what you have and what doesn't work or you don't understand.


i'm sorry.. i just thought you're not supposed to do that.. and thanks for answering my query.. :oops:

Re: question on perform varying

PostPosted: Mon Sep 15, 2008 2:20 am
by dick scherrer
Hello,

i just thought you're not supposed to do that..
How did you come to believe this?

If we (the forum) have mis-lead anyone to not post their specifics, we need to correct this.

and thanks for answering my query
You're welcome :)

When there are more questions, someone will be here.