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

3300-LOAD-SUMMARY-TABLE. 1

Status
Not open for further replies.

suruppak

Programmer
Mar 12, 2003
17
US
3300-LOAD-SUMMARY-TABLE.


SET SUMMARY-IDX TO 1.

SEARCH TABLE-SUMMARY-INFO VARYING SUMMARY-IDX
WHEN TBL-LOCATION-CODE(SUMMARY-IDX) =
SORT-LOC
PERFORM 3400-LOAD-CAR-SUM-TABLE THRU 3400-EXIT

WHEN TBL-LOCATION-CODE(SUMMARY-IDX) =
SPACES
MOVE SORT-LOC TO
TBL-LOCATION-CODE(SUMMARY-IDX)
MOVE SORT-LOCATION-NAME TO
TBL-LOCATION-NAME(SUMMARY-IDX)
MOVE SORT-LOCATION-CITY-ST TO
TBL-LOCATION-CITY-ST(SUMMARY-IDX)
PERFORM 3400-LOAD-CAR-SUM-TABLE THRU 3400-EXIT

END-PERFORM.

3300-EXIT.
EXIT.

3400-LOAD-CAR-SUM-TABLE.

SET CAR-SUM-IDX TO 1.

SEARCH TBL-SUMMARY-INFO VARYING CAR-SUM-IDX
WHEN SUM-CARRIER(SUMMARY-IDX, CAR-SUM-IDX) =
SORT-CARRIER
ADD SORT-EDE-INCENTIVE TO
SUM-INCENTIVES(SUMMARY-IDX, CAR-SUM-IDX)

WHEN SUM-CARRIER(SUMMARY-IDX, CAR-SUM-IDX) = SPACES
MOVE SORT-CARRIER TO
SUM-CARRIER(SUMMARY-IDX, CAR-SUM-IDX)
ADD SORT-EDE-INCENTIVE TO
SUM-INCENTIVES(SUMMARY-IDX, CAR-SUM-IDX)

END-PERFORM.

3400-EXIT.
EXIT.


When it gets to the second paragraph, while searching it advanced both indexes....how do I get it to only advance the secondary index? I thought specifying only the secondary index in the VARYING clause would do it, but it didn't work.
 
please show the defintion of this table from the DATA DIVISION.

Tom Morrison
 
01 SUMMARY-TABLE.
05 TBL-SUMMARY-INFO OCCURS 20 TIMES
INDEXED BY SUMMARY-IDX.
10 TBL-LOCATION-CODE PIC X(03) VALUE SPACES.
10 TBL-LOCATION-NAME PIC X(35) VALUE SPACES.
10 TBL-LOCATION-CITY-ST PIC X(37) VALUE SPACES.
10 TBL-CARRIER-SUM OCCURS 5 TIMES
INDEXED BY CAR-SUM-IDX.
15 SUM-CARRIER PIC X(04) VALUE SPACES.
15 SUM-INCENTIVES PIC 9(05)V99 VALUE ZEROES.


and thanks for your interest in my question.
 
In the 3400- paragraph you probably meant to search on group level TBL-CARRIER-SUM not TBL-SUMMARY-INFO.

"Code what you mean,
and mean what you code!
But by all means post your code!"

Razalas
 
The compiler is doing what the COBOL standard requires it to do. Here is the explanation from one vendor's Language Reference Manual:[tt]

In Format 1 (i.e. the type of SEARCH you are using), if the VARYING index-name-1 phrase is specified, and if index-name-1 appears in the INDEXED BY phrase in the OCCURS clause referenced by identifier-1, that index-name is used for this search. If this is not the case, or if the VARYING identifier-2 phrase is specified, the first (or only) index-name given in the INDEXED BY phrase in the OCCURS clause referenced by identifier-1 is used for the search. In addition, the following operations occur:

a. If the VARYING index-name-1 phrase is used, and if index-name-1 appears in the INDEXED BY phrase in the OCCURS clause referenced by another table entry, the occurrence number represented by index-name-1 is incremented by the same amount as, and at the same time as, the occurrence number represented by the index-name associated with identifier-1 is incremented.


b. If the VARYING identifier-2 phrase is specified, and identifier-2 is an index data item, the data item referenced by identifier-2 is incremented by the same amount as, and at the same time as, the index associated with identifier-1 is incremented. If identifier-2 is not an index data item, the data item referenced by identifier-2 is incremented by the value 1 at the same time as the index referenced by the index-name associated with identifier-1 is incremented.[/tt]

(Emphasis added.)

Since you are specifying an index-name not associated with the table you are searching, both the specified index-name and the first (in this case, only) index-name associated with the table are incremented in tandem.

Pretty obscure, right? [smarty]


Tom Morrison
 
Yes I did, but I think it gave me a "SEARCH not valid in this context" error.
I will try it again.
Thanks.
 
surrupak -

Code:
3300-LOAD-SUMMARY-TABLE.
  
    SET SUMMARY-IDX TO 1.

       SEARCH TABLE-SUMMARY-INFO VARYING SUMMARY-IDX 
          WHEN TBL-LOCATION-CODE(SUMMARY-IDX) =
                                               SORT-LOC
              PERFORM 3400-LOAD-CAR-SUM-TABLE THRU 3400-EXIT
             
          WHEN TBL-LOCATION-CODE(SUMMARY-IDX) =
                                               SPACES
             MOVE SORT-LOC               TO
                      TBL-LOCATION-CODE(SUMMARY-IDX)
             MOVE SORT-LOCATION-NAME      TO
                      TBL-LOCATION-NAME(SUMMARY-IDX)
             MOVE SORT-LOCATION-CITY-ST   TO
                      TBL-LOCATION-CITY-ST(SUMMARY-IDX)
             MOVE SORT-CARRIER            TO
                      SUM-CARRIER(SUMMARY-IDX, 1)      
    END-PERFORM.

3300-EXIT.
    EXIT.
[\code]
Note the suggested change in the second WHEN to initialize SUM-CARRIER.  I assume you've properly zeroed the numeric items in the empty table before you start to load it.

I also note you have no AT END logic.  If there's any possiblity of table overflow, you should consider adding that to both SEARCHes.

Regards.

Glenn
 
surrupak,

Regarding "SEARCH not valid in this context":

The object of a SEARCH must not be subscripted. Therefore something like:
Code:
SEARCH TBL-CARRIER-SUM (SUMMARY-IDX) ...
is not permitted. I would suggest a rather simple in-line PERFORM will take care of this.

Tom Morrison
 
Thanks to everyone for all the help!!
Jeremy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top