First Four records from table

hello,

i want to get only first four record from table as filter on report

i did the coding and i get the first four records , but after 4th record i want stop the looping.i use exit…but using exit i can not generate the final report.

what can do for stopping after 4th record?

You can find some useful infonrmation on this link https://dynamicsuser.net/nav/f/beginners/30058/exit-from-loop
Kind Regards,

Hello,

have a look at report 111 (Customer - Top 10 List).

This should be the condition you should use.

IF (NoOfRecordsToPrint = 0) OR (i < NoOfRecordsToPrint) THEN
i := i + 1

In your case it should be
IF (NoOfRecordsToPrint = 0) OR (i <4) THEN
i := i + 1

best regards,

i tried this but it is not work.
my code is like this

RecCount := 0;
//Firstcustomer :=’’;
//RecCount := Customer.COUNT;
IF Customer.FIND(’-’) THEN BEGIN

REPEAT
IF RecCount < 4 THEN
RecCount +=1;

IF Firstcustomer <> ‘’ THEN
Firstcustomer := Firstcustomer + ‘|’;
Firstcustomer := Firstcustomer + Customer.“No.”;
UNTIL Customer.NEXT = 0;
CLEAR(Customer);
Customer.SETFILTER(“No.”,Firstcustomer);
END;
REPORT.RUNMODAL(50050,TRUE,FALSE,Customer);

Try do to

Repeat
RecCount +=1;
IF Firstcustomer <> ‘’ THEN
Firstcustomer := Firstcustomer + ‘|’;
Firstcustomer := Firstcustomer + Customer.“No.”;
customer.next;
until(RecCount=4)

i tried but it gives first record

Hello, i think you should delete the " BEGIN "

IF Customer.FIND(’-’) THEN BEGIN

REPEAT

IF RecCount < 4 THEN

RecCount +=1;

no.it’s not like that…without begin or with begin it’s also not working

iaMendes made a correction in the code. It should work with the correction.

Sorry,But it’s not work…

I have just tried it out now and it works …
customerrec.FIND(’-’);
Repeat
RecCount +=1;
IF Firstcustomer <> ‘’ THEN
Firstcustomer := Firstcustomer + ‘|’;
Firstcustomer := Firstcustomer + customerrec.“No.”;
customerrec.next;
until(RecCount=4);
MESSAGE(Firstcustomer);

the message displays

01121212|01445544|01454545|01905893

Dis you tried writing code like this

Repeat
It will loop 4 times only.
Until Rec.Count<=4

Ok thanks @iaMendes now it is Working.

Yes it’s almost there.

RecMax := 4;
RecCount := 0;
IF Customer.FINDSET THEN
  REPEAT
    RecCount += 1;
    IF FirstCustomer <> '' THEN
      FirstCustomer := FirstCustomer + '|';
    Firstcustomer := FirstCustomer + Customer."No.";
  UNTIL (RecCount = RecMax) OR (Customer.NEXT = 0);
MESSAGE(FirstCustomer); 

Changes:

  1. Best practice for variable naming: Don’t add data type like Rec or Txt etc. to your variables.
  2. Don’t use FIND(‘-’) - use FINDSET - much more optimal performance wise for repeat loops.
  3. Check if content exists before looping.
  4. Previous code would fail if less than four records.

PS: And when you all add source code to your posts and replies, then use the Rich Text Editor (link in reply box). Here you can use the “Insert” → “Code” (NOT Tools → source code!). Then the code looks much better in the reply, and easy to copy-paste. Select format “Text” for C/AL. Nobody has volunteered to make a C/AL Syntax high-lighter yet. It’s some standard open source format, which “just” needs to be “adjusted” for C/AL. [;)]

Gem

HI Expn,

Please always remember to mark the replies that helped you to find the answer to your question and or gave the solution to your problem with “This helped me”.

This might help others who have similar need.