IBM i Global

 View Only
  • 1.  SQL Fetch into *AUTO Array Does Not Go to Next Section

    Posted 3 days ago

    I finally have time to process the hand outs for the What's New and Exciting in RPG from PowerUp24. What I had hoped was the second fetch would load into the next section of the array rather than overlaying the first ten records. Instead, the fetch loads the next 20 records into slots 1-20 of the array rather than 11-30. There is some "noise" in the sample code where I am displaying stuff to the screen rather than run all of it in debug.  

    No, I do not have a use case for this yet. I am simply curious.  Like most of you, I research and work out new ideas so when the use case does present itself, I have a solution. Thanks again @Scott Clement for the session at PowerUp. 

    **FREE
    //121 Whats New and Exciting in RPG.pdf PowerUP24
    //
    ctl-opt option(*nodebugio:*srcstmt:*nounref) dftactgrp(*no) ACTGRP(*CALLER) DEBUG(*CONSTANTS);

    dcl-ds gLine qualified;
    Sales_Person varchar(15) inz;
      Sales zoned(09) inz;
    END-DS;

    dcl-ds gGrowRows likeds(gLine) dim(*AUTO:40);
    dcl-s gGrandTotal zoned(09) inz;

    //------------------------------------------------------------------

    dcl-pr RPGAUTOR extpgm;
    END-PR;

    dcl-pi RPGAUTOR ;
    END-Pi;

    exec sql declare getRows cursor for
     select Sales_Person, Sales
    From SALES;

    clear gGrowRows;
    dsply %char(%ELEM(gGrowRows));

    exec sql open GetRows;

    exec sql fetch next from getRows for 10 rows into :gGrowRows;
    dsply %char(%ELEM(gGrowRows));

    for-each gLine in gGrowRows ;
      if gLine.Sales <> *zero;
        gGrandTotal += gLine.Sales;
      endIF;
    endfor ;


    dsply %char(gGrandTotal);

    exec sql fetch next from getRows for 20 rows into :gGrowRows;
    dsply %char(%ELEM(gGrowRows));

    for-each gLine in gGrowRows ;
      if gLine.Sales <> *zero;
        gGrandTotal += gLine.Sales;
      endIF;
    endfor ;

    exec sql close GetRows;

    dsply %char(gGrandTotal);

    *INLR = *On;

    return; 



    ------------------------------
    David Taylor
    Sr Application Developer
    Range Resources
    Fort Worth
    ------------------------------


  • 2.  RE: SQL Fetch into *AUTO Array Does Not Go to Next Section

    Posted 2 days ago

    Personally this is what I would expect (least surprise).

    Usually "for x rows" idiom is intended to work in chunks, so a "window" at a time in memory.

    To append maybe you should use classic iterative processing (normal FETCH) and then moving the result in a myarray(*NEXT) if one really need the auto handling of the internal index.



    ------------------------------
    --ft
    ------------------------------



  • 3.  RE: SQL Fetch into *AUTO Array Does Not Go to Next Section

    Posted 2 days ago

    @ace ace, thanks for the input.  I suspect once I have a true use case for this, I would use the loop to store or process a chunk at a time. 



    ------------------------------
    David Taylor
    Sr Application Developer
    Range Resources
    Fort Worth
    ------------------------------