Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Am I Correct here

Status
Not open for further replies.

scurf

Programmer
Feb 5, 2002
19
0
0
GB
Hi, Garry Back again, please have a look at the coding below and see if my list of errors are correct......

WORKING STORAGE SECTION
01 W-TABLE PIC 9(4).
03 W-TABLE-ITEM OCCURS 100.
01 W-INDEX PIC 999.

PROCEDURE DIVISION.
PERFORM VARYING W-INDEX FROM 1 BY 1
UNTIL BAD-CODE OR W-INDEX > 100
IF IN-CODE = W-TABLE (W-INDEX) THEN
MOVE 'T' TO OUT-TYPE
DISPLAY W-INDEX (3)
DISPLAY W-TABLE-ITEM (200)
END-IF
END-PERFORM.

OPEN OUTPUT TEMP-FILE
SORT TEMP-FILE ON KEY T-VALUE
USING IN-FILE GIVING SORTED-FILE
MERGE TEMP-FILE ON KEY T-VALUE USING F-1 F-2.
CALL PROGRAM-2 USING W-TABLE W-INDEX
IF ERROR-1 OR ERROR-2 = "Y" THEN
PERFORM PRINT-ROUTINE
MOVE ALL ZERO TO W-INDEX


The errors I have spotted are as follows:-

1. Line 2 W-TABLE must not have a picture value as it refers to the whole table.

2 Line 3 I think a picture declaration should follow W-TABLE-ITEM otherwise the elements would have no fixed size.

3. Line 4 I am not sure if W-INDEX is defined properly, should it be a level 1 item??

4. Line 8 If W-INDEX is a subscript then can it be used as other than a subscript.

5. Line 12. Cannot display W-TABLE-ITEM (200) as it would be out of range...


Apparantly there are ten errors but I can only pick out the above......
 
Here is an obvious one. Unless there is some sort of COBOL which I've never heard of.

The coding:

IF IN-CODE = W-TABLE (W-INDEX) THEN
MOVE 'T' TO OUT-TYPE
DISPLAY W-INDEX (3)
DISPLAY W-TABLE-ITEM (200)
END-IF

The first line has a glaring error. I know that back in my younger days, if I were to code it like this, my compiler would go bonkers.

Do you see it?

Nina Too
 
Usually if you are going to index a table you use the:
"INDEXED BY"
clause.
A Table is usually indexed if you want to search the table for a match. The index is used to search the table by varying or BY "SET UP BY 1", or using the search verb.
In your coding you have an item level 01. It will not repeat if that is what you want. It is not wrong to have a separate index but it makes for inefficient coding and is a pain.

Example:

01 W-TABLE.
05 W-TABLE-ITEM OCCURS 100 TIMES INDEXED BY W-INDEX
PIC 9(04).

The first thing is what does IN-CODE and BAD-CODE mean?
Are they defined conditions?
If not, then they have no meaning.
It looks like IN-CODE is some input and BAD-CODE seems to be some sort of hold field for error processing.

In your table you say TABLE ITEM OCCURS 100 TIMES, but there is not picture clause. What is occuring 100 times?

If you search using varying, when is there a match?
Either the table item must equal something else or you are wasting your time.

If you want to use the index and you already have a number then you just use that number with subscripting.
MOVE W-TABEL-ITEM (NUMBER) TO NEW-FIELD.

You can not display W-INDEX (3) because W-INDEX does not have an occurs! W-INDEX is the index!!!

You can display W-TABLE-ITEM (3) OR W-TABLE-ITEM (W-INDEX).
(if you set (W-INDEX) to a number in the range.)

TABLE-ITEM (200) is out of sub-script range.

You can say
IF IN-CODE = W-TABLE-ITEM (W-INDEX)
DO SOMETHING.
But if the number in IN-CODE is less than 1 or more than 100 your program will probably abort due to a sub script being out of range. Have to test it first or use the SEARCH VERB.

Refer to my table discription.

PERFORM SEARCH-TABLE-1.
.
.
.

SEARCH-TABLE-1.
SET W-INDEX TO 1.
SEARCH W-TABLE-ITEM
AT END MOVE IN-CODE TO BAD-CODE
WHEN IN-CODE = W-TABLE-ITEM
Imperitive Statement.(PERFORM OR DO SOMETHING)
END-SEARCH

(END-SEARCH is an IBM extension, not in the standard.)

This works if you say indexed by w-index for your
w-table-item! If you say occurs 100 times, the compiler knows what the limit is already. The table index must be set to 1 every time.







If you do not like my post feel free to point out your opinion or my errors.
 
Hi Nina,

How did I miss that one? X-)

Regards, Jack.
 
Thanks to all of you, you are very helpful, I shall spend some time with your advice tonight and have another look at the coding...

Once again....Thanks...

Garry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top