ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

%lookup

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

  • %lookup

    I have problem with %lookup. I would like to search array with my search arg. and IF not %found in array - write to array.

    When I do lookup for the first time and array is empty yet, I get decimal data error. When I write sth to array and then do lookup, it works fine.
    What could be wrong? Or is there any way to search array?

    Code:
         dINVA                           11      DIM(9999)
         d  kodkrx                       11  0   OVERLAY(INVA:1)
         d i                                 4  0                   
    
    
    
               i = 1;
               setll (3) PLLI51Al1;
               reade(n) (3) PLLI51Al1;
                dow not %eof (PLLI51AL1);
                  chain(n) KODKR PLLI51PF;
                    if %found;
    
                     if %lookup(KODKR : kodkrx) = 0;
                      kodkrx(i) = kodkr;
                      i = i+1;
                     endif;
    
                    ENDIF;
    
                reade(n) (3) PLLI51Al1;
                enddo;

  • #2
    Re: %lookup

    I don't think the program is with the %lookup. A decimal data error only occurs when the value being assigned to a numeric field is not valid (for example moving spaces to a packed field). Perhaps your file field has an invalid number? Check the value present in KODKR when doing the lookup.

    Comment


    • #3
      Re: %lookup

      I checked this -> value is number in format 00601234567.
      Error occurs when array is empty, when I write one record to array, %lookup can be done without error.
      Last edited by michal2442; March 26, 2015, 07:39 AM.

      Comment


      • #4
        Re: %lookup

        I do not see how that code even works your doing a %Lookup but both parms are arrays. That shouldn't even compile. Did you copy and past this or just retyped it? What is field KODKR, I see no D spec indicating what data type it is.
        What I think your problem is is that you have the numeric field KODKRX overlaying the character array INVA. If INVA is empty (contains all blanks) then the numeric field will also have blanks and you get data decimal errors.

        Comment


        • #5
          Re: %lookup

          The field i is specified as part of the array. It should be a standalone field - missing the 's' in the d-spec.
          Regards

          Kit
          http://www.ecofitonline.com
          DeskfIT - ChangefIT - XrefIT
          ___________________________________
          There are only 3 kinds of people -
          Those that can count and those that can't.

          Comment


          • #6
            Re: %lookup

            I added S for "i" variable, there is small problem - it didn't help.

            field KODKR is field from PF (11 0) so it isn't array. PGM has compiled correctly.


            What I think your problem is is that you have the numeric field KODKRX overlaying the character array INVA. If INVA is empty (contains all blanks) then the numeric field will also have blanks and you get data decimal errors.
            You may be right - but how can I declare array as numeric/decimal array?

            Comment


            • #7
              Re: %lookup

              Add the key word INZ to your data structure for your array. This causes the program to initialize the data structure and its sub fields with their default or Inz values when the program starts.


              Code:
              D                 DS                    Inz             
              DINVA                           11      DIM(9999)       
              D  kodkrx                       11  0   OVERLAY(INVA:1)

              Comment


              • #8
                Re: %lookup

                Add the key word INZ to your data structure for your array. This causes the program to initialize the data structure and its sub fields with their default or Inz values when the program starts.


                Code:
                D                 DS                    Inz             
                DINVA                           11      DIM(9999)       
                D  kodkrx                       11  0   OVERLAY(INVA:1)

                Comment


                • #9
                  Re: %lookup

                  Is KODKRX the only subfield of INVA? If it is and INVA is not used for anything else I would just make KODKRX the array and get rid of INVA.

                  Code:
                  D  KODKRX       S              11  0   DIM(9999)

                  Comment


                  • #10
                    Re: %lookup

                    Is KODKRX the only subfield of INVA? If it is and INVA is not used for anything else I would just make KODKRX the array and get rid of INVA.

                    Code:
                    D  KODKRX       S              11  0   DIM(9999)

                    Comment


                    • #11
                      Re: %lookup

                      You could also use the 3rd and 4th parameters of %LOOKUP to only search the elements that have data.

                      Code:
                      if %lookup(KODKR : kodkrx [COLOR="#FF0000"]: 1 : i - 1[/COLOR]) = 0;

                      Comment

                      Working...
                      X