IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Problem with the SEARCH logic


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sandeep kumar302

New User


Joined: 14 Mar 2012
Posts: 81
Location: India

PostPosted: Tue Sep 16, 2014 3:24 pm
Reply with quote

Hi,
I am writing a cobol program:

Input: CLASS-CODE-FILE vsam file
INPUT-SELL-PRICE-FILE sequential
INPUT-AMAZON-CNTL-FILE - this is control file

output:OUTPUT-SELL-PRICE-FILE sequentil file

Purpose:
Pick class-codes from the control file and load to an array. Then read sell-price file sequentially. For every record - pick 7 digit item code and check in class-code vsam file. If class-code matches to input control card then need to write the record.

Following condition can occur:
No match in Vsam --- Drop the record.
Match in Vsam --- write the record in output. For multiple matches for same item, repeat the record in the output file. While writing the record please initialize the store-nbr field.

I have written the cobol program but the issue is that the VSAM file will be having multiple matching class codes for the same TB and Item code value but the output file is having only the 1st matching record.
Code:


*---------------------------*
 1100-READ-CONTROL-FILE.
*---------------------------*

     MOVE '1100-READ-CONTROL-FILE' TO WS-PARANAME
D    DISPLAY WS-PARANAME

     READ INPUT-AMAZON-CNTL-FILE
          NOT AT END
              MOVE I-AMZ-CLASS-CODE
                   TO WS-CNTL-CLASS-CODE(WS-CNTL-IDX)

              SET WS-CNTL-IDX UP BY 1
              ADD 1 TO WS-I-AMZ-CNTL-REC-CNT
     END-READ
     .
*--------------------------------*

In the above para, i am reading the control file and loading in the temporary array

In the below para, i am validating the class code and then further writing to the output file:
Code:

*----------------------------------*
 2100-VALIDATE-CLASS-CODE.
*----------------------------------*
     MOVE   '2100-VALIDATE-CLASS-CODE'  TO WS-PARANAME
D    DISPLAY WS-PARANAME

     MOVE ISL-PRC-ITEM-TB    TO IFCLASS-TYPE-BUS-CODE
     MOVE ISL-PRC-ITEM-CODE  TO IFCLASS-BITEM-CODE
     MOVE ZEROS              TO IFCLASS-DEAL
                                IFCLASS-PACK
                                IFCLASS-CODE
     MOVE LOW-VALUES         TO IFCLASS-COMPONENT-CODE
                                IFCLASS-LEVEL-CODE
                                IFCLASS-WHSE-CODE

     SET  NO-MATCH-FOUND TO TRUE
     START CLASS-CODE-FILE KEY GREATER THAN IFCLASS-KEY

     EVALUATE WS-ICLASSCD-FS
         WHEN '00'
              PERFORM UNTIL WS-ICLASSCD-FS > '00'

              READ CLASS-CODE-FILE NEXT
               NOT AT END
                IF ISL-PRC-ITEM-TB = IFCLASS-TYPE-BUS-CODE AND
                   ISL-PRC-ITEM-CODE = IFCLASS-BITEM-CODE
                   SET WS-CNTL-IDX TO 1
                   SEARCH WS-CONTROL-FILE-DATA
                    AT END
                    DISPLAY 'SEARCH ELEMENT NOT FOUND IN TBL:'
                       WHEN WS-CNTL-CLASS-CODE(WS-CNTL-IDX) =
                                              IFCLASS-CODE
                          SET MATCH-FOUND TO TRUE
                   END-SEARCH
                ELSE
                   SET C-ICLASSCD-NOTFND TO TRUE
                END-IF
              END-READ

              END-PERFORM
         WHEN OTHER
              CONTINUE
     END-EVALUATE

     IF  NO-MATCH-FOUND
       SET DROP-RECORD TO TRUE
     END-IF
     .


In the above para, if MATCH-FOUND is true then i am writing to output file

I guess the issue is from:
Code:

IF ISL-PRC-ITEM-TB = IFCLASS-TYPE-BUS-CODE AND
   ISL-PRC-ITEM-CODE = IFCLASS-BITEM-CODE
   SET WS-CNTL-IDX TO 1
   SEARCH WS-CONTROL-FILE-DATA
    AT END
    DISPLAY 'SEARCH ELEMENT NOT FOUND IN TBL:'
       WHEN WS-CNTL-CLASS-CODE(WS-CNTL-IDX) =
                              IFCLASS-CODE
          SET MATCH-FOUND TO TRUE
   END-SEARCH
ELSE
   SET C-ICLASSCD-NOTFND TO TRUE
END-IF


Can someone help me in rectifying this
Back to top
View user's profile Send private message
sandeep kumar302

New User


Joined: 14 Mar 2012
Posts: 81
Location: India

PostPosted: Tue Sep 16, 2014 3:38 pm
Reply with quote

The issue is that if the key(TB + Item code) from sell price file is matching with (TB+ Item code) value from VSAM file(Key is TB+ ITem code+ shc id) , then the class code will be searched in the table and if it matches, then output is written which is happening correctly.

It is also possible that for the same sell price records, there can be multiple records with same TB+ Item combination in the VSAM file and for every matching record, there should be one output record.
But, i am not getting all the records in the output file.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Wed Sep 17, 2014 3:10 am
Reply with quote

I strongly suggest you to add display's and use only few records in input file for testing purpose and then you can figure it out by yourself where is the problem very easily than just looking at the code. If you have any debugger , please make a use of that one. While you do so others here can also give you a clue of what has went wrong.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Sep 17, 2014 3:05 pm
Reply with quote

Without the data-defintions shown to us, there may well be more than one thing which needs changing.

However, one bit is easy: you don't do anything in the (PERFORM) loop to write records, so at most you'll only ever get one.
Back to top
View user's profile Send private message
sandeep kumar302

New User


Joined: 14 Mar 2012
Posts: 81
Location: India

PostPosted: Thu Sep 18, 2014 10:00 am
Reply with quote

Hi Rohit/Bill,

Thanks for your suggesions.

I did some small change the program and it worked fine. It was the issue with not setting the index properly.

If you guys want it, i can put the code here for all of us to see.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Thu Sep 18, 2014 8:16 pm
Reply with quote

Yes please <with the tags>.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Search two or more word with FILEAID Compuware & Other Tools 15
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Map Vols and Problem Dataset All Other Mainframe Topics 2
No new posts first column truncated in search result IBM Tools 13
No new posts ISRSUPC search utility - using high l... TSO/ISPF 2
Search our Forums:

Back to Top