ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

AS400 Array and DS

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

  • AS400 Array and DS


    Hi ,
    Can anyone help me on this one. Please send the code for this.
    In this Table I need to read all record and should store ITEM_ID, ITEM_DESC, ITEM_PRICE in One Array.( I tried by Array and DS but i am not sure whether am I right)
    And need to Display ITEM_PRICE that is greater than 2000 and ITEM_DESC of those.
    By Using both Chain and SeTLL they need program. I am not sure with chain and SetLL we can do., But They said need to do

    ITEM00PF - Physical File
    ITEM_ID ITEM_DESC ITEM_PRICE
    S0001 SHIRT 1,000
    J0001 JEANS 2,500
    TS001 TSHIRT 1,500
    P0001 PANT 1,700
    TR001 TROUSER 2,200

  • #2
    This sounds a lot like a homework assignment and we're not here for that.

    I will give you a hint at a DS that would work.

    Code:
    Dcl-ds itemArray Dim(*Auto: 9999);
       ITEM_ID;
       ITEM_DESC;
       ITEM_PRICE;
    End-ds;

    Now if you want to use something like that and then show us your code if you run into trouble we'll be glad to help.

    Unless the table is indexed on ITEM_PRICE I see no use for SETLL - so perhaps a requirement is missing from your description?
    Last edited by JonBoy; August 3, 2021, 01:53 PM.

    Comment


    • #3
      Hi,
      I am unable to retrieve the values from the Array,,,i have loaded values in array,...But Unable to retrieve it,,,
      Can Anyone help me on this..

      FITEM00PF IF E K DISK
      *
      DAry_Dtl S DIM(9999)LIKE(DS01_ItemDtl)
      DI S 2S 0
      *
      DDS01_ItemDtl DS
      DD1_ItemId LIKE(ITEM_ID)
      DD1_ItemDesc LIKE(ITEM_DESC)
      DD1_ItemPrice 6S 0
      *
      C *loval SetLL ITEM00R1
      C Read ITEM00R1
      C Eval I = 1
      C Dow Not %Eof(ITEM00PF)
      C Eval D1_ItemId = ITEM_ID
      C Eval D1_ItemDesc = ITEM_DESC
      C Eval D1_ItemPrice = ITEM_PRICE
      C Eval Ary_Dtl(I) = DS01_ItemDtl
      C Read ITEM00PF
      C Add 1 I
      C Enddo
      *
      C Eval I = 1
      C Dow Ary_Dtl(I) <> *Blanks
      C Eval D1_ItemId = ITEM_ID
      C Eval D1_ItemDesc = ITEM_DESC
      C Eval D1_ItemPrice = ITEM_PRICE
      C If D1_ItemPrice > 2000 -------------------- While Debug ,Here I am Facing Issue
      C D1_ItemPrice Dsply
      C D1_ItemDesc Dsply
      C EndIf
      C Add 1 I
      C Enddo
      *
      C Eval *Inlr = '1'

      Comment


      • #4
        The actual cause of your error is that you are testing the wrong field. You are testing the value in the DS that you used to build the array element - not the value that you stored in the array - so you'll always see the last value loaded.

        Best fix is not to do it the way you have. There is no need to build data in the DS01_ItemDtl DS and then copy it to the array. Just load the array elements directly.

        Here's a version in free-form (sorry - I refuse to code RPG in fixed form - it was deprecated 15+ years ago.) I leave it up to you to convert it to fixed form if feel you have to.

        Code:
        Dcl-DS ItemDtl Dim(9999) qualified;  <A>
           ItemId LIKE(ITEM_ID);
           ItemDesc LIKE(ITEM_DESC);
           ItemPrice Zoned(6);
        End-Ds;
        
        Dow Not %Eof(ITEM00PF) ;    
           ItemDtl(I).ItemId = ITEM_ID;   <B>
           ItemDtl(I).ItemDesc = ITEM_DESC;
        ...
        
        For X = 1 to I; // Use loaded number to control loop  <C>
           If ItemDtl(X).ItemPrice > 2000;   <D>
        Notes:
        <A> Items defined directly in array DS.
        <B> Data from record loaded directly into appropriate array element
        <C> Don't rely on an element being blank for loop termination - what if the (say) second entry of 50 was actually blank? You have a count (I) of the number loaded, use it to control the loop. FOR (in my opinion) is a better choice when the number of entries is known and X will be incremented automagically.
        <D> Test directly against the current item price.

        Comment

        Working...
        X