Hi guys,
Do any of you know how to loop through fields in a table, the example being: Day 1, Day 2, Day 3,…,Day 31 in Nav 2009 R2? I have code:
If “Day 1” Then
…
If “Day 2” Then
…
And so on
Hi guys,
Do any of you know how to loop through fields in a table, the example being: Day 1, Day 2, Day 3,…,Day 31 in Nav 2009 R2? I have code:
If “Day 1” Then
…
If “Day 2” Then
…
And so on
Hi'
This code will loop through all records and you can put your test statement inside it.
Is this what you are looking for?
IF SomeRec.FIND('-') THEN
REPEAT
IF SomeRec.Field = "Day 1" THEN
BEGIN
(put code here)
END;
UNTIL SomeRec.NEXT = 0;
Not really what I am looking for. Maybe I was not clear. The code you supplied requires me to write manually the same thing for all 31 days and this is exactly the thing I want to avoid. I am looking for an equivalent of a FOR loop (Day[i]), which ,of course does not work in navision.
You can look at Date table…
What do you mean by that? What will I see there?
I havent tested this, but it’s something along these lines… It loops through all records 32 times though…
While i < 32 DO
BEGIN
IF SomeRec.FIND(’-’) THEN
REPEAT
IF SomeRec.Field = 'Day ’ + FORMAT(i) THEN
BEGIN
(put code here)
END;
UNTIL SomeRec.NEXT = 0;
END;
If you need the current number of days within a month you could use
NoOfDaysInMonth := DATE2DMY(CALCDATE(‘CM’,DMY2DATE(01,MonthNumber,YearNumber)),1);
And replace 32 with that!
I will test this tomorrow and let you know if it works and I will post here the solution. Thanks for the guidance.
Hi Georgi,
Are you saying that you have a table with fields named “Day 1”, “Day 2” … “Day 31”, and you’re interested in inspecting the values of these fields without having to refer to them explicitly in code? If that’s the case, take a look at the documentation for data types RecRef and FieldRef.