ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

indicators and file

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

  • indicators and file

    Hi,

    When trying to read a file with setting indicator on 'LO' position then trying to see it's impact it seems it makes no impact whether the file have records or not in it but same seem to show impact when it is placed at 'EQ' position.

    why is it so?


    Thanks..

  • #2

    Comment


    • #3
      thanks I went through this link on page no. 835 it states regarding READ opcode but could not find answer specific to my query here with respect to setting the position on 'LO' and 'HI' places for READ operation on a keyed file.
      it says "You can specify an indicator in positions 75-76 to signal whether an end of file occurred on the READ operation. The indicator is either set on (an EOF condition) or off every time the READ operation is performed. This information can also be obtained from the %EOF built-in function, which returns '1' if an EOF condition occurs and '0' otherwise. The file must be repositioned after an EOF condition, in order to process any further successful sequential operations (for example, READ or READP) to the file."

      but

      Code:
      1 fp7 if e k disk
      2 c 101 setll p7
      3 c if *in20 = *on
      4 c 'hi' dsply
      5 c else
      6 c 'bye' dsply
      7 c endif
      8 c seton
      
      
      
      
      
      
      
      
      Debug . . .
      
      F3=End program F6=Add/Clear breakpoint F10=Step F11=Dis
      F12=Resume F17=Watch variable F18=Work with watch F
      *IN20 = '0'
      so how can i know where is this position 75-76 in debug mode and in this above example program irrespective of whether my file p7 have records or not in it indicator 20 always show value to '0' in debug mode why is it so?


      Thanks ...

      Comment


      • John192
        John192 commented
        Editing a comment
        below is the program in which i am testing this indicator 20.

        Code:
         SEU==>                                                                                              
         FMT FX FFilename++IPEASF.....L.....A.Device+.Keywords+++++++++++++++++++++++++++++Comments++++++++++
                *************** Beginning of data ***********************************************************
        0001.00 fp7        if   e           k disk                                                           
        0002.00 c     101           setll     p7                                   20                        
        0003.00 c                   if        *in20 = *on                                                    
        0004.00 c     'hi'          dsply                                                                    
        0005.00 c                   else                                                                     
        0006.00 c     'bye'         dsply                                                                    
        0007.00 c                   endif                                                                    
        0008.00 c                   seton                                            lr


        Thanks...

    • #4
      First - why on why are you trying to learn to code a version of RPG that has been (at best) obsolete for over 20 years? You are also mixing styles i.e. fixed column indicators <shudder> and slightly more modern IF constructs. In other words trying to learn to code RPG in this "style" is a really bad idea and if you ever showed it to me as a student or as an example off your skills during a hiring interview I would show you the door.

      Please - if you want to learn the language find a good source to learn from - whatever you're using that leads you to believe that this type of code is a good idea was a bad choice. Tell us a little about your background and we can introduce you to sources that will help rather than hinder your progress.

      OK. Sermon over.

      Your first problem is that you are not reading the file. SETLL is a positioning operation that sets a cursor for a subsequent read operation.

      A SETLL can set three conditions. %Found (the inverse of column 71's NR indicator) - this will be set on if a record that matches or is higher than the requested key is found. %Error on a SETLL(E) ( equivalent to column 73's ER) and finally %Equal (column 75's EQ).

      Say there are keys 1, 5 and 7 in the file. SETLL with a key of 5 would result in both %Found and %Equal being set. Using a key of 6 would result in %Found but NOT %Equal. Normally only %Found is used.

      Typical usage is:
      Code:
      SETLL  myKey  myFile;
      If %Found;
        ReadE  myFile;  // Normally this is a Read loop until %EOF is reached
      Else; 
        Dsply 'No matching key found';
      EndIf;

      Comment


      • #5
        What is your background? Are you totally new to the environment?

        Why are you writing in an outdated language? You should be doing ALL your RPG logic in **FREE ( we do need a new name).

        If you do not know SQL, learn it. Throw out your Chains and Reads and Setll's.



        You mention in your problem that you Read the table.

        You don't. You are doing nothing but setting limits to your P7 table.

        If indicator 20 is in 75-76 and you return zero, there is no match on your SETLL.

        Comment


        • #6
          Thanks, but I tested it with read opcode indicator 20 which is set on 'Lo' indicator position which always shows value( *in20 value in debug mode) as '0' in debug mode irrespective of p8 file have records in it or not.

          below is the program to test it.

          Code:
          FMT FX FFilename++IPEASF.....L.....A.Device+.Keywords++++ +++++++++++++++++++++++++Comments++++
          *************** Beginning of data ************************************************** ***
          0001.00 fp8 if e k disk
          0002.00 c read p8 20
          0003.00 c if *in20 = '0'
          0004.00 c 'hi' dsply
          0005.00 c else
          0006.00 c 'bye' dsply
          0007.00 c endif
          0008.00 c seton lr

          p8 physical file DDS:-

          Code:
          FMT PF .....A..........T.Name++++++RLen++TDpB......Functi ons+++++++++++++++++++++++
          *************** Beginning of data ******************************************
          001.00 R REC
          002.00 ID 3P 0
          003.00 NAME 20A
          004.00 K ID

          Thanks..

          Comment


          • #7
            Originally posted by corvair61 View Post
            What is your background? Are you totally new to the environment?

            Why are you writing in an outdated language? You should be doing ALL your RPG logic in **FREE ( we do need a new name).

            If you do not know SQL, learn it. Throw out your Chains and Reads and Setll's.



            You mention in your problem that you Read the table.

            You don't. You are doing nothing but setting limits to your P7 table.

            If indicator 20 is in 75-76 and you return zero, there is no match on your SETLL.
            records does exist in file p7 for '101' value still that indicator always shows '0' why so? is it because i have kept it at incorrect position (out of these 3 options HI,,LO and EQ) ?


            Thanks..

            Comment


            • #8
              READ only sets the error indicator if there is an error. There isn't. It can also set the EOF indicator but if there are records in the file that will not be set by a single read. SO from your code indicator 20 being off is correct.

              If the file is keyed you should be using CHAIN to read a specific record by key. Alternatively if the full key is not known, or there are multiple records with the same key, you can use SETLL followed by a READE loop. That will continue until EOF is set once all records with a matching key have been read.

              If you want to learn RPG I am more than happy to help - as will many others here. But PLEASE learn the current version of RPG - not the outdated (by 20+ years) columnar version. Once you understand the language then it is quite easy to understand the old columnar stuff - but start in the right place. Particularly since most RPG IV teaching materials will rightly ignore all the outdated stuff.

              If however you continue to insist on learning these antiquated fixed form indicator based techniques then sorry but I have better things to do with my time.

              Comment


              • #9
                Originally posted by JonBoy View Post
                If however you continue to insist on learning these antiquated fixed form indicator based techniques then sorry but I have better things to do with my time.
                LOL, can't agree more. I've never really learnt the old indicator stuff enough to know what each position means, so every time I see RPG code using indicators, I have to go to the manual/help and try and work out what those silly things refer to. It's a pain in the backside and is very time consuming. The columnar code is also a lot less readable (worse if there's a factor 1, 2 and result as it normally means a visit to the manual again to work out how those go together)...

                John192, I don't know why you're learning this ancient form but I'd suggest taking the advice and changing to free form. If you're modifying old code, you should use free-form specs in the new bits you write, you can mix them in the same source. There are also tools that will convert them for you if you want to convert it before making changes.

                Comment

                Working...
                X