ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

COBOL question, believe it or not!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • COBOL question, believe it or not!

    For various reasons, I find myself needing to learn some COBOL. I have a question about key fields when using the "START" statement. When I compile my program using this START:

    Code:
    START WFTINL09                                               
          KEY IS EQUAL TO SV-LDWHS, SV-LDASLE, SV-LDBAY, SV-LDLVL
       INVALID KEY SET WFTIN-END-OF-FILE TO TRUE.
    I get the following message in the compile:

    Code:
    MSGID: LNC0635  SEVERITY: 20  SEQNBR:  004601                        
    Message . . . . :   Keys specified do not match externally-described 
      keys for file 'WFTINL09'. KEY IS phrase ignored.
    Now the SV-* fields are defined with the exact same attributes as the key fields in the file (they are all 3 character). My program produces no output when START is specified like this.

    When I changed this to:

    Code:
    MOVE SV-LDWHS TO TIWHS.                          
    MOVE SV-LDASLE TO TIASLE.                        
    MOVE SV-LDBAY TO TIBAY.                          
    MOVE SV-LDLVL TO TILVL.                          
    START WFTINL09                                   
          KEY IS EQUAL TO TIWHS, TIASLE, TIBAY, TILVL
       INVALID KEY SET WFTIN-END-OF-FILE TO TRUE.
    I don't get the previously mentioned message in the compile and the program produces the output I expect. The only difference between the two is the TI* names come from WFTINL09. This tells me that you have to use the names of the key fields from the database file when using START? Being an old RPG guy, I'm used to using whatever field names I want, as long as the field matches the attributes of the file's key fields.
    Jonas Temple
    Got FROG?
    Got Tadpole? No, because it's not done yet! Stay tuned....

    01010111 01100001 01110011 01110011 01110101 01110000 00100000 01100100 01101111 01100111 00111111

  • #2
    Re: COBOL question, believe it or not!

    Cobol is based on international standards, hence the need to explicitly define the keys on a START statement Its best to initialize the key values with your data structure values (e.g. working-storage variables) and then use the following syntax:

    Code:
    start WFTINL09 key >= externally-described-key 
        invalid key
            perform Error-Processing here...
    end-start
    BTW, if your looking for equality, its best to just use a READ statement after setting up your key values. It looks like your trying to emulate SETLL, if so, then use the >= operator to position your record pointer, READ the record and then compare one or more key values to ensure you have got the right record entry. Unlike RPG, there is no READE using partial key values, you must do an IF comparison to determine if you have read the correct record.

    Terry
    Last edited by Terry Wincheste; October 15, 2007, 07:57 AM.

    Comment


    • #3
      Re: COBOL question, believe it or not!

      Originally posted by Terry Wincheste View Post
      Cobol is based on international standards, hence the need to explicitly define the keys on a START statement Its best to initialize the key values with your data structure values (e.g. working-storage variables) and then use the following syntax:

      Code:
      start WFTINL09 key >= externally-described-key 
          invalid key
              perform Error-Processing here...
      end-start
      Terry
      Well, the one thing I forgot to mention is that this is a START with a partial key. I can't use externally-described-key for that, right? Also, could you maybe provide a mock-up example of initializing key values with DS values? I'm not sure I'm following you.

      Thanks!
      Jonas Temple
      Got FROG?
      Got Tadpole? No, because it's not done yet! Stay tuned....

      01010111 01100001 01110011 01110011 01110101 01110000 00100000 01100100 01101111 01100111 00111111

      Comment


      • #4
        Re: COBOL question, believe it or not!

        I can't use externally-described-key for that, right?
        Sure you can! Assuming the WFTINL09 file is defined with the following keys:
        Code:
        	TIWHS
        	TIASLE                        
                TIBAY                          
                TILVL
        Then the following pseudo-code will position the record pointer using the START keyword with the partially filled key values, READ the record into the file record buffer and then check to ensure that we have a match of values on our partial key values. Note the >= being used for our comparison operator...

        Code:
        move SV-LDWHS   to TIWHS                          
        move SV-LDASLE  to TIASLE                        
        move spaces     to TIBAY                          
        move spaces     to TILVL                          
        start WFTINL09 key >= externally-described-key
           invalid key
        	set WFTIN-END-OF-FILE to TRUE 
        end-start
        
        read WFTINL09 next        
            at end                         
                set WFTIN-END-OF-FILE to TRUE
        end-read
        
        if  SV-LDWHS  = TIWHS                          
        and SV-LDASLE = TIASLE
            First two key values are equal!
        else
            Oops...partial key values are not equal
        end-if
        Hope this is a little clearer

        Terry

        Comment


        • #5
          Re: COBOL question, believe it or not!

          So can I also assume there is no COBOL equivalent of RPG's READE?
          Jonas Temple
          Got FROG?
          Got Tadpole? No, because it's not done yet! Stay tuned....

          01010111 01100001 01110011 01110011 01110101 01110000 00100000 01100100 01101111 01100111 00111111

          Comment


          • #6
            Re: COBOL question, believe it or not!

            Originally posted by jtemple View Post
            So can I also assume there is no COBOL equivalent of RPG's READE?
            Your assumtion is correct In effect, READE in RPG automagically checks the partial key values behind the scenes so that the programmer doesn't have to write the code

            RPG is the only language I know where file positioning (SETLL) and read statements (READx) permit partial key matching without the use of additional HLL statements.

            Terry

            Comment

            Working...
            X