-2

I wrote program in RPG IV free-form and i met a problem. Im trying to execute sql statment with:

dcl-proc getRecord;
dcl-pi *N int(5) end-pi;
dcl-s rec int(5) inz(0);

exec sql
select max(SCORE) into :rec from SNK_HISC;

return rec;
END-PROC;   

It works only once after compilation. Maybe i should reset some indicators or sql flags? At the end of program i use:

*inlr = *on;
return;    

Where procedure is called:

   exfmt BACK;
   exfmt INFO;

   inital();


   dow run and alive;
     write MAINBOARD;
     READ(E) AKE_DSP;
     run = FKeyListener();
     alive = goForward();
   ENDDO;
   LSCORE = points;
   if points > getRecord();
     LRECORD = 'NEW RECORD!';

     exec sql
       insert into AKE_HISC( USID , SCORE) VALUES( :userID , :points);

   ENDIF;
   exfmt ENDING;


   *inlr = *on;
   return; 

And in this procedure:

dcl-proc inital;
     snake(1).x = 5;
     snake(2).x = 5;
     snake(3).x = 5;
     snake(1).y = 5;
     snake(2).y = 6;
     snake(3).y = 7;
     direction.x = 1;
     direction.y = 0;
     SCORE = points;
     RECORD = getRecord();
     genSnack();
     refresh();
   END-PROC;

I run program with this CL program:

         PGM

         MONMSG     MSGID(CPF0000 MCH0000) EXEC(GOTO CMDLBL(END))

         OVRDSPF    FILE(AKE_DSP) DEV(*REQUESTER) WAITRCD(1)

         CALL       PGM(AKE_S)

 END:    
         DLTOVR     FILE(*ALL)
         MONMSG     MSGID(CPF0000)

         ENDPGM
Charles
  • 21,637
  • 1
  • 20
  • 44
Silver
  • 3
  • 4
  • What do you mean by 'it works only once' ? Can you show your 'Ctl-Opt' statements, and your procedure call to getRecord ? Does it work again if you logout your session and login ? – Dam Aug 18 '17 at 14:41
  • Now I havent access to my ibmi till monday so now i cannot check it. But it works properly only once after compilation. Second execute of program doesent insert remaining data to rec variable. I use ctl-opt noactgrp or something like that. – Silver Aug 18 '17 at 14:53
  • what "remaining data"? – Charles Aug 18 '17 at 14:58
  • Ahhh I meant expected – Silver Aug 18 '17 at 15:22
  • Program works after logout/login – Silver Aug 21 '17 at 06:18

1 Answers1

0

Problem was not with sql query but with that where it is. I removed procedure getRecord() and make rec global variable and the sql query was placed inside the main cycle thats all.

Silver
  • 3
  • 4