2 Replies Latest reply on Aug 2, 2019 1:39 PM by mikrimouse

    Looping through data block items and populating other block items

    mikrimouse

      In when button pressed trigger i have loop which need to go throug data block record and populate another block items. In the first loop i count how many records are in the data block, and that is correct.

      For example.

      I got 2 count_rows and  first record in sp_iznosi data block  populates items in the second data block sp_stavke, but for second record in data block sp_iznosi it doesnt even  enter into loop.

      So how to loop through the second record in data block ? Thanks

       

       

      go_block ('sp_iznosi');      

             FIRST_RECORD;

                  count_rows := 0;

                  loop

                      IF :sp_iznosi.vp_sifra IS NOT NULL THEN

                          count_rows := count_rows+1;                   

                      END IF;           

                      if :SYSTEM.LAST_RECORD = 'TRUE' then

                          EXIT;

                      ELSE

                      NEXT_RECORD;

                      end if;                       

                  END LOOP;

       

                      check_error(count_rows) -- here i get 2 counts

              for j in 1..count_rows -1            

        

              loop

             

                  go_block ('sp_stavke');

                 

            clear_block(no_validate);

          

                  stavke_ukupno := 0;

               

                if :sp.datum_kraj < last_day(datum) then

                    broj_radnih_sati_period := obr_raz.broj_radnih_sati(datum, :sp.datum_kraj);             

                else

                     broj_radnih_sati_period := obr_raz.broj_radnih_sati(datum, last_day(datum));             

                end if;      

               

                    iznos_rate := (:sp_iznosi.iznos * broj_radnih_sati_period / broj_radnih_sati);           

                    :sp_stavke.iznos:=round(iznos_rate,2);

                    stavke_ukupno := stavke_ukupno + round(iznos_rate,2);

                    :sp_stavke.mjesec:=to_char(datum, 'yymm');

                    datum := last_day(datum) + 1;          

                    :sp_stavke.obracunato:='NE';             

                   if j <count_rows then

                        next_record;        

                   end if;

                                 

              end loop;

        • 1. Re: Looping through data block items and populating other block items
          Gary_A

          How do you know it doesn't enter the loop?

          Put some message commands in it.

          The second "loop" is not really a loop if your count_rows=2, since it will only execute once.

          • 2. Re: Looping through data block items and populating other block items
            mikrimouse

            I know beacuase of the messages ...

            This is the solution.

             

            go_block ('sp_iznosi');      

                   FIRST_RECORD;

                        count_rows := 0;

                        loop

                            IF :sp_iznosi.vp_sifra IS NOT NULL THEN

                                count_rows := count_rows+1;                   

                            END IF;           

                            if :SYSTEM.LAST_RECORD = 'TRUE' then

                                EXIT;

                            ELSE

                            NEXT_RECORD;

                            end if;                       

                        END LOOP;

                             javi_poruku('count records ' ||count_rows);

                             javi_poruku('broj mjeseci'||broj_mjeseci);

                            

                FIRST_RECORD;

               

                -----------------------

                         for j in 1..count_rows                          

                         loop        

                              go_block ('sp_stavke');                  

                              javi_poruku('broj vrste placanja '||:sp_iznosi.vp_sifra); 

                                  

                          clear_block(no_validate);

                          stavke_ukupno := 0;

                       

                     for i in 1..broj_mjeseci-1

                     loop

             

                      if :sp.datum_kraj < last_day(datum) then

                          broj_radnih_sati_period := obr_raz.broj_radnih_sati(datum, :sp.datum_kraj);             

                      else

                           broj_radnih_sati_period := obr_raz.broj_radnih_sati(datum, last_day(datum));             

                      end if;      

                     

                          iznos_rate := (:sp_iznosi.iznos * broj_radnih_sati_period / broj_radnih_sati);           

                          :sp_stavke.iznos:=round(iznos_rate,2);

                          stavke_ukupno := stavke_ukupno + round(iznos_rate,2);

                          :sp_stavke.mjesec:=to_char(datum, 'yymm');

                          datum := last_day(datum) + 1;          

                          :sp_stavke.obracunato:='NE';

                         

                     if i < count_rows * broj_mjeseci then

                          next_record;        

                     end if;

                      commit_form;

                   

                     end loop;

                    

                     go_block ('sp_iznosi');

                     

                          if j < count_rows  * broj_mjeseci -1 then

                              if :SYSTEM.LAST_RECORD = 'TRUE' then

                                            EXIT;

                                        ELSE

                                        NEXT_RECORD;

                                        end if;

                          end if;

                           commit_form;

                        end loop;