Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2008
    Location
    India
    Posts
    40

    Unanswered: Key column getting initialized to zero after every fetch

    Hi,
    I need to fetch records from TABLE1 based on a key read from input file

    Say the input key is
    WS-KEY1 PIC 9(06) VALUE ZEROES.
    The cursor declaration is as follows

    DECLARE TABLE1_CSR CURSOR WITH HOLD FOR
    SELECT COL1,COL2
    FROM TABLE1
    WHERE COL1=:WS-CURSOR-KEY

    The dclgen declaration of col1 is
    05 COL1 pic s9(09) usage comp.

    So I am moving 6 digit input key to ws-cursor-key which is declared as below
    05 WS-CURSOR-KEY PIC S9(09) USAGE COMP.

    MOVE WS-KEY1 TO WS-CURSOR-KEY
    The fetch statement is as follows

    Fetch TABLE1_CSR
    Into : COL1, :COL1

    But the problem I am facing is that COL1 is getting initialized to 0 after fetch .
    Example if the key is 123456, it is fetching the records associated to 0 as key.
    Whatever input I am giving, the same thing is happening.

    Please help me in resolving this issue.

  2. #2
    Join Date
    Jun 2007
    Location
    germany
    Posts
    155
    you have to populate WS-CURSOR-KEY (with the value from the file)
    prior to OPEN of the cursor.

    what sqlcode do you have from the FETCH.
    Dick Brenholtz, Ami in Deutschland

  3. #3
    Join Date
    Oct 2009
    Location
    221B Baker St.
    Posts
    486
    It appears that you are not using the "input key" but rather the zero initialized working-storage field when the FETCH is issued

  4. #4
    Join Date
    Oct 2008
    Location
    India
    Posts
    40
    Thanks a lot!!!..i was moving the value after the cursor is opened.Now the values are getting fetched properly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •