Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Problem with the SEARCH logic

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
sandeep kumar302

New User


Joined: 14 Mar 2012
Posts: 69
Location: India

PostPosted: Tue Sep 16, 2014 3:24 pm    Post subject: Problem with the SEARCH logic
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: 69
Location: India

PostPosted: Tue Sep 16, 2014 3:38 pm    Post subject:
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

Senior Member


Joined: 21 Sep 2010
Posts: 1609
Location: NY,USA

PostPosted: Wed Sep 17, 2014 3:10 am    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Wed Sep 17, 2014 3:05 pm    Post subject: Reply to: Problem with the SEARCH logic
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: 69
Location: India

PostPosted: Thu Sep 18, 2014 10:00 am    Post subject:
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

Senior Member


Joined: 21 Sep 2010
Posts: 1609
Location: NY,USA

PostPosted: Thu Sep 18, 2014 8:16 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Problem in writing Output file vickey_dw COBOL Programming 5 Mon Nov 14, 2016 11:14 pm
No new posts Problem in Running Query via JCL vickey_dw DB2 3 Tue Oct 18, 2016 11:11 pm
No new posts DB2 Streaming Batch Processing Problem Manshadi DB2 4 Sat Sep 24, 2016 12:14 pm
No new posts Wildcard logic in COBOL dudenithy COBOL Programming 13 Thu Sep 01, 2016 7:36 pm
No new posts Problem with GETMAIN command amitc23 CICS 6 Thu Sep 01, 2016 1:01 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us