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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Direct Table Lookup Part II 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Greetings once again, I have attached one of the two tables and my procedure division code,

Ultimatly, I have the branch number in the input file, and I need to use that to pull off the District-code,

If you could please help or, or direct me to a good example, I would be most greatful.

Thanks you every so kindly.

Dash


01 BRANCH-VALUES.
05 BRANCH-NUMBER.
10 PIC 999 VALUE 123.
10 PIC 999 VALUE 221.
10 PIC 999 VALUE 333.
10 PIC 999 VALUE 414.
10 PIC 999 VALUE 515.
10 PIC 999 VALUE 616.
10 PIC 999 VALUE 717.
10 PIC 999 VALUE 818.
10 PIC 999 VALUE 919.

05 DISTRICT-CODE.
10 PIC 9 VALUE 1.
10 PIC 9 VALUE 1.
10 PIC 9 VALUE 2.
10 PIC 9 VALUE 2.
10 PIC 9 VALUE 3.
10 PIC 9 VALUE 4.
10 PIC 9 VALUE 4.
10 PIC 9 VALUE 5.

01 BRANCH-TABLE REDEFINES BRANCH-VALUES.
05 ROWS OCCURS 2 TIMES.
10 COLOUMS OCCURS 9 TIMES PIC 999.

Procedure Division
MOVE COLOUMS(BRANCH-NUMBER-I) TO DISTRICT-CODE-O.


 
You created a table with 9 branches, followed by 8 district codes, at least in your example. Then you redefine it as if the branch and the district are side by side. You can not do this in the manner you attempted. Obviously it works better to have the same amount in each.

To make the redefine you need all the fields to be the same size, or you need to make a structure like

01 BRANCH-DISTRICT-VALUES.
10 PIC 999 VALUE 123.
10 PIC 9 VALUE 1.
10 PIC 999 VALUE 221.
10 PIC 9 VALUE 2.
.
.
.

01 Branch-District-table REDEFINES BRANCH-DISTRICT-VALUES.
05 Branch-Distirct occurs 9 Times indexed by BR-IDX.
10 Branch pic 999.
10 Distirct pic 9.

If you want a table with 2 occurs make all the fields the same size!!!!

TABLE-VALUES.
10 PIC 999 VALUE 123.
10 PIC 999 VALUE 1.
IF a short table wastes a little space it doesn't matter much. If it was a large table you would make 2 fields and possibly load the table from a file using varying. That way you can add and delete branches/divisions as long as the number of elements wasnt outside of the index range. The table could also be in a copybook, if it was used in different programs.



You can make one big field and one value statement.
10 table-values
pic x(36) value '12312212... ...'.
(you have to make it text to make a long string, then
they you redefine as multiple numeric fields)



Then when your input file says Branch 123 in field in-branch, you can say:

move Division (In-Branch) to District-Code-out.

But since the numbers are not in order 1,2,3 that will not work. So you have to search the table with the Branch number. When you find the branch number it is at the same occurs as the District number. By using indexed by <variable> clause, this makes the table searchable.

First you set the BR-IDX TO 1!!!
Now just search the table.
If the branch value is not found do an error routine.
(INVALID KEY)
If it is found use the BR-IDX in the subscript as
District (BR-IDX).
(NOT INVALID KEY)

Look up the verb Search for the exact Search method.

SET BR-IDX TO 1.
SEARCH BRANCH-DISTRICT (element with occurs)
AT END
PERFORM BRANCH-ERR
WHEN BRANCH-IN = BRANCH
MOVE DISTRICT (BR-IDX) TO DISTRICT-OUT
END-SEARCH



If you do not like my post feel free to point out your opinion or my errors.
 
You post was great! very informative,

my mistake in my post was that, I copied wrong, I have a table with 9 branches and 9 district codes...

but, I will use what you have shown me and try to get this silly thing working, once I see what happens, i'll reply again


thank you!
 
I'm still slightly confused...

Alright, the table redefines is right, and makes sense, thank you for that.

In the loop routine, can I now just say

if branch-number-i = branch(br-idx)
move district(br-idx) to district-code-o

???

 
Dash,

I have a feeling you are still not communicating exactly what you wish to accomplish and in what precise environment you wish to accomplish your said goal...

Your original post mentioned two 2-dimensional tables and then you take the single table example from ceh4702... and you are still slightly confused... NOT the fault of ceh4702, you just need to communicate your problem precisely...

Let me take a stab at what I think you are working on:

An input (file or data entry or whatever) gives you a value, for example the value '120'; you go to one table and look up '120' and find the corresponding value of 'Area 51'. OK now you go to the second table and look up 'Area 51' and you get the match: 'District 2'. So that in this case you are actually dealing with the two tables mentioned in your original query.

Let me know if the above characterization of your problem is right. If not, then perhaps I should shut up. If it is right, then let me know and I will try to help.

Regards.
 
I've done 2-dimensional tables fairly frequently because I am a CICS online programmer who has to sometimes display data in rows and columns on the screen.

When you are using a 2 dimensional table, you have to code the field as BRANCH (BR-IDX1, BR-IDX2). The first index (or subscript) tells you the row number you are on. The 2nd index (or subscript) tells you the column number you are on.

For instance, if you are referring to the first branch of the entire table, this would be row 1, column 1. Which would be BRANCH (1,1). Or else you set both indexes to 1.

Then when you want to go across to the next branch of the table, you keep the first index at row 1, but set the 2nd index to column 2. Which would be BRANCH (1,2) or BRANCH (BR-IDX1, BR-IDX2) with the first index set at 1 and the second index set at 2.

If you are &quot;walking through&quot; the table with a PERFORM UNTIL, then when you increment the count each time, you would code:

IF BR-IDX2 > 9
SET BR-IDX2 TO 1
SET BR-IDX1 UP BY 1 [which will get you to the 2nd row]
ELSE
SET BR-IDX2 UP BY 1 [which will move you along the same row but to the next column]
END-IF.

Your PERFORM UNTIL would end when both row and column index goes greater than 9.

2 dimensional tables can be very helpful to use, if you learn how to use them correctly.

Hope this helps, Nina Too
 
You might want to specify what your input is, how the tables are loaded or if they are hard coded and what you expect the output to be in exact terms.

You can have 2 tables and use the subscript in the first table to point to the second table. If you do not like my post feel free to point out your opinion or my errors.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top