IBM i Global

IBM i 

A space for professionals working with IBM’s integrated OS for Power systems to exchange ideas, ask questions, and share expertise on topics like RPG and COBOL development, application modernization, open source integration, system administration, and business continuity.


#Power


#IBMi
#Power
 View Only
  • 1.  Chaining a value

    Posted Fri October 06, 2023 06:12 AM

    Hi,

    I am trying to chain a value and display it as per below condition but despite the value exists in this file i get wrong result any idea why is it happening , already checked my lib. list,data using sql and through debug mode nothing worked yet.

    [code]

                // Check if it's a valid pallet (exists in FILE1)     
                                  Chain(N) (LdWhse:' ':WSCASN) FILE1;       
    CR01        //          Chain(N) (%TRIM(WSCASN)) FILE1;           
                            If  Not %Found(IDCASE10);                    
                         WsMsg = 'Pallet does not exist in FILE1';    
                                  Flg_Error = 'Y';                       
    SR01                          LeaveSr;                               
                            EndIf;                                       

    [/code]

    Note i tried both the ways like above first by this chain condition :-1)Chain(N) (LdWhse:' ':WSCASN) FILE1;

    2nd by this condition :- CR01        //          Chain(N) (%TRIM(WSCASN)) FILE1;           

    i have a field WSCASN defined in my display file let's say 'D1' where this field is defined as 20 A and same definition inside for File1 only it's name is IDCASN in this file for example when i tested this code for key value '305446C003871A'  then though this value does exist in IDCASN field of file1 and debug mode also i can see it's assigned to this WSCASN through display file screen still above  program code displays wrongly as ''Pallet does not exist in FILE1'; 

    Could someone please advise why is it happening ?

    Thanks much...



    ------------------------------
    Kevin Steve
    ------------------------------


  • 2.  RE: Chaining a value

    Posted Fri October 06, 2023 08:11 AM
    here file1 is the same idcase10.





  • 3.  RE: Chaining a value

    Posted Mon October 09, 2023 06:01 AM

    You should check %EQUAL() (Excat Match) instead of %FOUND() .

    From the IBM documentation:

    %FOUND returns '1' if the most recent relevant file operation found a record, a string operation found a
    match, or a search operation found an element. Otherwise, this function returns '0'.

    %EQUAL returns '1' if the most recent relevant operation found an exact match; otherwise, it returns '0'.



    ------------------------------
    Birgitta Hauser
    Database and Software Engineer
    Selfemployed - Modernization-Education-Consulting on IBM i
    Kaufering
    +49 170 5269964
    ------------------------------



  • 4.  RE: Chaining a value

    Posted Mon October 09, 2023 12:44 PM

    The trim is doing nothing and should be removed.

    The %Found is applied to file IDCASE10 - but you are chaining to File1

    The version of the Chain is not valid - copy/paste error? Chain(N) (LdWhse:' ':WSCASN) FILE1;  



    ------------------------------
    Jon Paris
    ------------------------------



  • 5.  RE: Chaining a value

    Posted Tue October 10, 2023 10:18 AM

    Chain(N) (LdWhse:' ':WSCASN) FILE1;       
    Chain(N) (%TRIM(WSCASN)) FILE1;           

    Looks like the file has 3 fields as key (per the 1st statement, it is searching with 3 arguments, whse, space and case)

    The second statement is searching using only one (the case)



    ------------------------------
    Carlos Romero
    ------------------------------



  • 6.  RE: Chaining a value

    Posted Tue October 10, 2023 11:00 AM
    Good point - I missed that. Looks what may be needed is SETLL rather than Chain.

    What is still unclear is whether the OP is thinking that the ‘’ will give a null key or what is intended. I’m thinking that it will result in a second key of blanks - probably not what was wanted.

    Jon P




  • 7.  RE: Chaining a value

    Posted Wed October 11, 2023 05:26 PM

    Kevin, 

      Birgitta is correct, but our code has hundreds of examples of %Found doing this same type of thing just fine.  For us, %Equal is usually used in a SETLL situation.

      You really don't give enough information to draw  exact conclusions.  So I'm going to make assumptions, and show an example I think fits your issue.

      Assuming your file IDCASE10 is keyed and there are 3 fields in the key.  Attributes and names are unknown, and the record format is also unknown.  The declare should look like this, and I'm stepping it up a bit with a key list for the chain that is a data structure modeled on the file key list.  We as a rule code the record format as the I/O for single record format files, and the file name in the "test" for success.  See what you think of this: 

           Dcl-f IDCASE10 keyed;
           Dcl-ds CseKey LikeRec(IDCASEREC: *Key) inz;
       ‚   // real record format unknown...
           Clear CseKey;

           IDWHSE = LdWhse;
           IDCASN = WACASN;
       ‚   // real key field names of record format unknown...

           Chain(n) %Kds(CseKey) IDCASEREC;
     1b    If Not %Found(IDCASE10);
                   WSMSG = 'Pallet does not exist in IDCASE10';
                   Flg_Error = 'Y';
     LV          LeaveSr;
     1e    Endif; 

      All ambiguity removed, very clean, and things line up easily.  There are other techniques you can use to tighten this up as well, we often use a data structure over the display that can move many fields into other data structures like the key data structure with the EVAL-CORR op-code, as long as names line up.



    ------------------------------
    Mike Overlander
    ------------------------------