× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Luis,

The "a bit faster" part is not very relevant, as it won't be noticeable
(maybe if you execute it 384.400.000 times).

The main reason - if the choice is mine - to choose the RPG implementation
instead of "default to" SQL, is that with a one-time investment you don't
have any dependency on SQL, and you can adapt the functionality of the
procedure to your own specific needs, if necessary. You're in control.

Especially if it's "simple" stuff, like replacing chars in a string, etc.

This example, calculating the weeknumber, is more tricky so i can imagine
you don't want to risk it. Also, there's not much reason to tweak or adapt
calculating weeknumbers. IMO, it makes things more simple, to not be
dependent on the SQL preprocessor and SQL runtime machinery just because
you have a couple of procedures which are a bit tricky to implement. For
me, it would be worth it. I don't dismiss SQL, of course, just use it for
what it was meant for.

It's a one time investment, and 90% of time is spent on gathering
information not actual coding, which will pay off the next x years. Once
implemented you can really forget about it. If it's implemented with
embedded SQL, and you forget about it, i think it will bite you sometimes
in the future. But maybe i'm wrong about this.

I also think that many programmers just don't want to implement it
themselves. E.g. a %replchar bif can be easily implemented with "normal"
rpg code, doesn't take days, and you can add all kinds of functionality you
think of instead of being "locked" into the functionality that's given by
the equivalent SQL bif.





On Wed, Dec 3, 2014 at 3:19 PM, Luis Rodriguez <luisro58@xxxxxxxxx> wrote:

Rob,

To add my .02 cents to what has been a very interesting thread, I remember
that many, many years ago, one of my first IBM instructors told us that, at
the very least, 70% of the time of an IT department (in those days we
called it DP) was used in maintaining (debugging, extending, adapting, etc)
existing programs.

That being the case, you have to balance the benefits of a program being a
little bit faster against the time you spend designing your own algorithm,
many times from scratch. Also, if there is any problem with the result of
the function you have, again, to check the code and wonder where it may be
wrong. As you stated, I can assume (somewhat safely) that a SQL function
will return the correct result every time.

Nevertheless, as always, every shop has different requirements and needs,
so I can easily conceive that in some cases that "little bit faster" can be
useful.

Best Regards,

Luis



Luis Rodriguez
IBM Certified Systems Expert — eServer i5 iSeries
--


On Wed, Dec 3, 2014 at 8:45 AM, <rob@xxxxxxxxx> wrote:

I don't get this implied reasoning that if I am using SQL then it must
inherently be slower. First of all, neither is doing any database I/O so
index evaluation and all that jack is out of the picture. Once the code
is compiled it can be ran on a machine that doesn't even have the SQL
option installed so it's not like it has to call a bunch of external
stuff. (Ok, maybe I'm off here. Maybe the callable stuff is installed
on
every machine with the OS. But if one can imply that imbedded sql is
inherently slower than I can imply the callable routines are not
installed.)


Rob Berendt
--
IBM Certified System Administrator - IBM i 6.1
Group Dekko
Dept 1600
Mail to: 2505 Dekko Drive
Garrett, IN 46738
Ship to: Dock 108
6928N 400E
Kendallville, IN 46755
http://www.dekko.com





From: John E <whattssonn@xxxxxxxxx>
To: Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxx>
Date: 12/03/2014 07:40 AM
Subject: Re: Get Start Date of a Week Number
Sent by: "MIDRANGE-L" <midrange-l-bounces@xxxxxxxxxxxx>



And it's probably a bit faster.

On Wed, Dec 3, 2014 at 1:29 PM, <rob@xxxxxxxxx> wrote:

And is that any easier to understand or trust than

p IsoWkdayNum b export
d IsoWkdayNum pi 10i 0
d date d const

d d s 10i 0

/free

exec sql values dayofweek_iso(date) into :d;

return d;

/end-free
p e


p IsoWeekNum b export
d IsoWeekNum pi 10i 0
d date d const

d w1 s 10i 0

/free

exec sql values week_iso(date) into :w1;

return w1;

/end-free
p e


Rob Berendt
--
IBM Certified System Administrator - IBM i 6.1
Group Dekko
Dept 1600
Mail to: 2505 Dekko Drive
Garrett, IN 46738
Ship to: Dock 108
6928N 400E
Kendallville, IN 46755
http://www.dekko.com





From: John E <whattssonn@xxxxxxxxx>
To: Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxx

Date: 12/03/2014 07:17 AM
Subject: Re: Get Start Date of a Week Number
Sent by: "MIDRANGE-L" <midrange-l-bounces@xxxxxxxxxxxx>



From http://nl.wikipedia.org/wiki/Weeknummer (which is in dutch) :

To calculate the ISO weekday (1=monday) for a given date:

p IsoWkdayNum b export
d IsoWkdayNum pi 10i 0
d date d const

d d s 10i 0

/free

d = %diff(date:d'1970-01-04':*d);

if d < -6;
return 7 - %rem(%abs(d) - 7 : 7);
elseif d < 0;
return 7 + d;
endif;

d = %rem(d : 7);

if d = 0;
return 7;
endif;

return d;

/end-free
p e


To calculate the ISO weeknumber for a given date (using the previous
IsoWkdayNum) :
The year must be from 1584 to 9998, else it returns 0.

p IsoWeekNum b export
d IsoWeekNum pi 10i 0
d date d const

d y s 10i 0
d m s 10i 0
d d s 10i 0
d w1 s 10i 0
d w2 s 10i 0
d wd1 s 10i 0
d wd2 s 10i 0
d wd3 s 10i 0
d wd4 s 10i 0
d wd5 s 10i 0
d x s 10i 0

/free

// http://nl.wikipedia.org/wiki/Weeknummer
--------------------

y = %subdt(date:*y);

if y < 1584
or y > 9998;
return 0;
endif;

m = %subdt(date:*m);
d = %subdt(date:*d);

// UK02
w1 = %div(%diff(date:%date(y*10000+104:*iso):*d):7);

// UK03
wd1 = IsoWkdayNum(date);

// UK04
wd2 = wd1 - %rem(%diff(date:%date((y-1)*10000+104:*iso):*d):7);
if wd2 < 1;
wd2 = wd2 + 7;
endif;

// UK06
w2 = %div(%diff(%date((y-1)*10000+1231:*iso)
:%date((y-1)*10000+104:*iso):*d)
:7);

// UK07
wd3 = wd1 - %rem(%diff(date:%date((y-1)*10000+1231:*iso):*d):7);
if wd3 < 1;
wd3 = wd3 + 7;
endif;

// UK08
x = %diff(date:%date(y*10000+104:*iso):*d);
if x < 0;
wd4 = wd1 - x;
if wd4 > 7;
wd4 = wd4 - 7;
endif;
else;
wd4 = wd1 - %rem(x:7);
if wd4 < 1;
wd4 = wd4 + 7;
endif;
endif;

// UK09
wd5 = wd1 + %rem(%diff(%date((y+1)*10000+104:*iso):date:*d):7);
if wd5 > 7;
wd5 = wd5 - 7;
endif;

// UK11
if m = 1
and d >= 1
and d <= 3;
if wd1 < wd4;
return 1;
else;
// UK10
if wd3 < wd4;
return 1;
elseif wd3 < wd2;
return w2 + 2;
endif;
return w2 + 1;
endif;
elseif m = 12
and d >= 29
and d <= 31
and wd1 < wd5;
return 1;
elseif wd1 < wd4;
return w1 + 2;
endif;

return w1 + 1;

/end-free
p e


The code above is tested, and is correct.


On Wed, Nov 26, 2014 at 3:52 PM, Brian <belstsrv@xxxxxxxxx> wrote:

Hello All,

I have the need to get the date of the first day of the week based on
a
week number. I've looked thorough lots of date functions and can't
seem
to
see a way to get the date of the first day of the week for a
particular
week number. Maybe I need a multi-step process, but I am just
struggling
to see it.

The date can be based off Sunday or whatever arbitrary day could be
considered as the first day of the week, if that helps.

The data is planning data so I really just need to show it as a
quantity
along with a date, but the date needs derived from a week number.

As an example, if I had week number of 1, the date might be
12/29/2014,
week 2 would give me 1/5/2015 and so on.

Can anyone provide some suggestions on a method to get to a date
based
off
the week number?

Thank you.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L)
mailing
list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.


--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.


--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.


--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.


--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.


--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.