View previous topic :: View next topic
|
Author |
Message |
kregen
New User
Joined: 16 Mar 2006 Posts: 21
|
|
|
|
Hello together,
I have the following problem.
During the processing of a file, all records older than the current date - 1 year should be omitted.
The date in the record for comparison is packed (PD) and has the following structure: 0(n)YYDDD
n = 0 = 19 century
n = 1 = 20 century
Data example
Code: |
.p.§
0907
073C
----
.r..
0930
090C
----
....
0012
160C
----
...§
0137
112C
----
.q..
0923
082C
----
...<
0004
117C
----
...%
0006
102C
...%
0236
115C
----
...*
0035
103C
----
....
0012
181C
----
....
0121
177C
----
....
0000
102C
----
.r..
0933
092C
----
...<
0124
198C
----
|
What options do I have to skip the unnecessary records.
I am very interested to see how the solution looks like.
Thanks a lot for the support.
Greetings / Regards
kregen |
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1341 Location: Bamberg, Germany
|
|
|
|
Look up the following in the manual:
you will need to adjust the length of the input field to match the format of DATE3P, then you can easily compare with what's requested.
Let's see what you have tried so far as well, please. |
|
Back to top |
|
|
kregen
New User
Joined: 16 Mar 2006 Posts: 21
|
|
|
|
HelloJerg,
if you an now tell me how i can calculate the comparative value from the input data, then the solution would be perfect.
how can i convert the input 0(n)YYDDD to YYYYDDD in DFSORT?
Code: |
in other language i use: Field + 1900000 = YYYYDDD
|
is this possible with DFSORT?
regards
kregen |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2147 Location: USA
|
|
|
|
kregen wrote: |
HelloJerg,
if you an now tell me how i can calculate the comparative value from the input data, then the solution would be perfect.
how can i convert the input 0(n)YYDDD to YYYYDDD in DFSORT?
Code: |
in other language i use: Field + 1900000 = YYYYDDD
|
is this possible with DFSORT?
regards
kregen |
How do you plan to deal with the dates of XXI century?
Please, read any SORT manual about:
- CENTWIN parameter
- date conversion parameters - Y2P, Y2T, Y2W, ... (+50 more) |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2147 Location: USA
|
|
|
|
FYI:
In SORT the arithmetics with packed decimal are performed (if the field is a correct packed decimal value of four bytes) in the following manner:
Suppose your date is stored in the field as X'00yydddC' = +yyddd
Code: |
...pos,4,PD,ADD,+1900000,LENGTH=4,... |
The result would be X'19yydddC', or X'2yyydddC'
Subtraction of one year can be done as follows:
Code: |
...pos,4,PD,SUB,+1000,LENGTH=4,... |
But you must take care of leap year's changed day numbers yourself!
Everything about arithmetic operations is described in details in any SORT manual. It would be a good idea to refer to it. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2147 Location: USA
|
|
|
|
I forgot one important parameter in both cases, to get result in packed decimal as well:
Code: |
...pos,4,PD,ADD,+1900000,TO=PD,LENGTH=4,... |
Code: |
...pos,4,PD,SUB,+1000,TO=PD,LENGTH=4,... |
|
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2147 Location: USA
|
|
|
|
kregen wrote: |
if you an now tell me how i can calculate the comparative value from the input data, then the solution would be perfect. |
A sort of a smart alec question...
Code: |
INREC OVERLAY=(81:1,4,PD,ADD,+1900000,TO=PD,LENGTH=4)
SORT FIELDS=COPY
OUTFIL OMIT=(81,4,PD,LT,&DATE3P-365),
BUILD=(1,80) |
|
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1341 Location: Bamberg, Germany
|
|
|
|
sergeyken wrote: |
Code: |
INREC OVERLAY=(81:1,4,PD,ADD,+1900000,TO=PD,LENGTH=4)
SORT FIELDS=COPY
OUTFIL OMIT=(81,4,PD,LT,&DATE3P-365),
BUILD=(1,80) |
|
Kind of this was my first attempt, however your replies made me look up the manual (again). Request can be fulfilled a bit more simple, but basically I would like to see at least one attempt to solve the issue by the TS first. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2147 Location: USA
|
|
|
|
Arithmetic conversion of the non-standard date value, and date comparison with any current-date function need to be done separately in two different statements (or IFTHEN= which is the same). This is the major limitation of SORT, other updates are less important. |
|
Back to top |
|
|
kregen
New User
Joined: 16 Mar 2006 Posts: 21
|
|
|
|
hello together,
thanks to all for the good support.
Regards
Kai |
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1341 Location: Bamberg, Germany
|
|
|
|
Please show what you have tried. I do have two more updates for this case to discuss. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2147 Location: USA
|
|
|
|
The date in the input field has proprietary format, as X'0cyydddC', not acceptable as data format by SORT utility.
Any date value calculated from the current &DATExxx in SORT has one of standard formats, such as X'yyyydddC'
Those two cannot be compared, like "oranges to apples".
Arithmetic is needed (as PD format),
either X'0cyydddC'+1900000
or X'yyyydddC'-1900000
Arithmetic operation cannot be incorporated neither into INCLUDE/OMIT condition, nor into SYMNAMES dictionary; a separate statement is needed, with extra intermediate field.
So, I did not find a more simple solution, though the order of operations can be changed. |
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1341 Location: Bamberg, Germany
|
|
|
|
sergeyken wrote: |
The date in the input field has proprietary format, as X'0cyydddC', not acceptable as data format by SORT utility. |
One of your statements made me look up the manual, and there is the following:
|
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2147 Location: USA
|
|
|
|
Joerg.Findeisen wrote: |
sergeyken wrote: |
The date in the input field has proprietary format, as X'0cyydddC', not acceptable as data format by SORT utility. |
One of your statements made me look up the manual, and there is the following:
|
It produces C'YYDDD' - cannot compare to P'0cyydddC' ... |
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1341 Location: Bamberg, Germany
|
|
|
|
sergeyken wrote: |
It produces C'YYDDD' - cannot compare to P'0cyydddC' ... |
Basically you can, look up Table 29. Permissible Comparisons for Dates in the Manual. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2147 Location: USA
|
|
|
|
Joerg.Findeisen wrote: |
sergeyken wrote: |
It produces C'YYDDD' - cannot compare to P'0cyydddC' ... |
Basically you can, look up Table 29. Permissible Comparisons for Dates in the Manual. |
Again: the date format P'cyyddd' = X'0cyydddC' is a proprietary one.
None of standard date operations, including date comparison, is applicable to this non-standard value, without its preliminary conversion. |
|
Back to top |
|
|
|