sponsored links



No announcement yet.

Debug - EVAL ambiguous fields?

  • Filter
  • Time
  • Show
Clear All
new posts

  • Debug - EVAL ambiguous fields?

    Say I have 2 logicals with no prefix(); in debug how can I view the value in field1 for each file? i've tried qualifying with the filename, record format or using "OF" but it doesn't work and Google isn't helping.

    Also; how does the program know? If I say field1 = value does it just set the field of the last file read with that fieldname?

  • #2
    You have encountered one of the fundamental rules of RPG. One field name = one memory location.

    Suppose files 1 and 2 both have a fieldA. Read file 1 and the value of fieldA will be the one from that file. Now read file 2 and the value will change to the one from file 2. Thus it has ever been!

    If you want to know what the values from the different files are then you need to have the debugger break before each I/O on the relevant files - and note the content of the field before and after the operation.

    Alternatively use DS I/O - in which case each file will have its own copy of the field, or rename/prefix the field in one or both of the files.


    • #3
      Ahhh, ok that makes sense - thanks JonBoy.

      So I guess in this scenario (say they are keyed differently so it's a different record in each logical);
      Read LOGICAL1
      Read LOGICAL2
      update LOGICAL1R

      This would set the logical1 record to = the logical 2 record?


      • #4
        If all the fields match then yes.


        • #5
          Just be aware that the key fields of locical1 is not changed by reading logical2 ( unless you really want this to happen ).
          Otherwise you will experience to "live in interesting times".


          • #6
            To expand on what Peder said, if you update a key field and the new key has a greater value than the old key, you will read the record again.

            For example, LOGICAL1 is defined in RPG as keyed, and key field FLD1 in LOGICAL1 has the value 'DDDD', and FLD1 has the value 'EEEE' in LOGICAL2, then FLD1 will have the value 'EEEE' in your RPG program after you read LOGICAL2. When you update LOGICAL1R, the key in LOGICAL1 will get updated to 'EEEE'. A later READ of LOGICAL1 would get the same record again, since key 'EEEE' is greater than key 'DDDD'.

            This could even result in an infinite loop if causes the key for the record is continually updated to a higher value. As Peder said, "interesting times".