View previous topic :: View next topic
|
Author |
Message |
mitha
New User
Joined: 01 Dec 2021 Posts: 19 Location: India
|
|
|
|
Hi All,
I need a clarification for the condition used in my program.
Below is the condition I gave in my program. If the TRC-TRAILER-DATE is less when compared to TRP means ,it should abend. But in my case , it is running opposite.
Code: |
IF TRC-TRAILER-DATE < TRP-TRAILER-DATE
DISPLAY ' CURRENT TRAILER DATE : '
TRC-TRAILER-DATE
DISPLAY ' PREVIOUS TRAILER DATE : '
TRP-TRAILER-DATE
MOVE 3180 TO ABEND-CODE
PERFORM 9100-ABEND-PROGRAM THRU 9109-EXIT
END-IF
|
Code: |
CURRENT TRAILER DATE : 01/01/2022
PREVIOUS TRAILER DATE : 12/31/2021
**************************************************
CURR TRAILER DT < PRIOR TRAILER DT
|
Here Current trailer date is greater than previous trailer but it is abending. Kindly anyone advice me on this. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2141 Location: USA
|
|
|
|
It looks like your fields named "...-DATE" are actually defined as character strings: PIC X(10). For some reason your prefer to hide this information from the forum?...
If so, you get what is expected from character strings comparison. In order to compare as dates, the fields must be defined accordingly. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
|
|
Remove slashes and reformat to use pic 9(8) to compare as numerics. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10888 Location: italy
|
|
|
|
unfortunately since it looks like the format is MM/DD/YYYY
getting rid of the slashes will not help
the date must be converted to YYYY/MM/DD with or without the slashes |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
|
|
That’s right .. YYYYMMDD |
|
Back to top |
|
|
mitha
New User
Joined: 01 Dec 2021 Posts: 19 Location: India
|
|
|
|
How to convert? I tried some methods but it is not working correctly. Can anyone share your code snippet |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
The code is not particularly difficult:
Code: |
05 MDY-DATE.
10 MDY-MM PIC X(02).
10 PIC X(01).
10 MDY-DD PIC X(02).
10 PIC X(01).
10 MDY-YY PIC X(04).
05 YMD-DATE.
10 YMD-YY PIC X(04).
10 YMD-MM PIC X(02).
10 YMD-DD PIC X(02).
MOVE MDY-MM TO YMD-MM.
MOVE MDY-DD TO YMD-DD.
MOVE MDY-YY TO YMD-YY. |
This removes the slashes from the MDY date. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2141 Location: USA
|
|
|
|
mitha wrote: |
How to convert? I tried some methods but it is not working correctly. Can anyone share your code snippet |
What are "some methods you have tried"?
This forum is supposed to point to any wrong usage of mainframe tools and features, but not to present a ready-to-use solution from scratch. |
|
Back to top |
|
|
mitha
New User
Joined: 01 Dec 2021 Posts: 19 Location: India
|
|
|
|
Code: |
77 MMDDYY-TRC-DATE PIC X(10).
77 YYMMDD-TRC-DATE PIC X(8).
77 MMDDYY-TRP-DATE PIC X(10).
77 YYMMDD-TRP-DATE PIC X(8).
UNSTRING TRC-TRAILER-DATE
DELIMITED BY '/'
INTO MMDDYY-TRC-DATE
END-UNSTRING
MOVE MMDDYY-TRC-DATE(1:2) TO YYMMDD-TRC-DATE(5:2)
MOVE MMDDYY-TRC-DATE(3:2) TO YYMMDD-TRC-DATE(7:2)
MOVE MMDDYY-TRC-DATE(5:4) TO YYMMDD-TRC-DATE(1:4)
DISPLAY 'CURRENT TRC DATE : ' YYMMDD-TRC-DATE
UNSTRING TRP-TRAILER-DATE
DELIMITED BY '/'
INTO MMDDYY-TRP-DATE
END-UNSTRING
MOVE MMDDYY-TRP-DATE(1:2) TO YYMMDD-TRP-DATE(5:2)
MOVE MMDDYY-TRP-DATE(3:2) TO YYMMDD-TRP-DATE(7:2)
MOVE MMDDYY-TRP-DATE(5:4) TO YYMMDD-TRP-DATE(1:4)
DISPLAY 'CURRENT TRP DATE : ' YYMMDD-TRP-DATE
IF YYMMDD-TRC-DATE < YYMMDD-TRP-DATE
DISPLAY ' CURRENT TRAILER DATE : '
TRC-TRAILER-DATE
DISPLAY ' PREVIOUS TRAILER DATE : '
TRP-TRAILER-DATE
MOVE 3180 TO ABEND-CODE
PERFORM 9100-ABEND-PROGRAM THRU 9109-EXIT
END-IF
|
|
|
Back to top |
|
|
mitha
New User
Joined: 01 Dec 2021 Posts: 19 Location: India
|
|
|
|
I tried the above method but still it is abending. Can anyone share how to make this condition work properly.
TRC-TRAILER-DATE => 01/01/2022
TRP-TRAILER-DATE => 12/31/2021 |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2141 Location: USA
|
|
|
|
mitha wrote: |
Code: |
77 MMDDYY-TRC-DATE PIC X(10).
77 YYMMDD-TRC-DATE PIC X(8).
77 MMDDYY-TRP-DATE PIC X(10).
77 YYMMDD-TRP-DATE PIC X(8).
UNSTRING TRC-TRAILER-DATE
DELIMITED BY '/'
INTO MMDDYY-TRC-DATE
END-UNSTRING
MOVE MMDDYY-TRC-DATE(1:2) TO YYMMDD-TRC-DATE(5:2)
MOVE MMDDYY-TRC-DATE(3:2) TO YYMMDD-TRC-DATE(7:2)
MOVE MMDDYY-TRC-DATE(5:4) TO YYMMDD-TRC-DATE(1:4)
DISPLAY 'CURRENT TRC DATE : ' YYMMDD-TRC-DATE
UNSTRING TRP-TRAILER-DATE
DELIMITED BY '/'
INTO MMDDYY-TRP-DATE
END-UNSTRING
MOVE MMDDYY-TRP-DATE(1:2) TO YYMMDD-TRP-DATE(5:2)
MOVE MMDDYY-TRP-DATE(3:2) TO YYMMDD-TRP-DATE(7:2)
MOVE MMDDYY-TRP-DATE(5:4) TO YYMMDD-TRP-DATE(1:4)
DISPLAY 'CURRENT TRP DATE : ' YYMMDD-TRP-DATE
IF YYMMDD-TRC-DATE < YYMMDD-TRP-DATE
DISPLAY ' CURRENT TRAILER DATE : '
TRC-TRAILER-DATE
DISPLAY ' PREVIOUS TRAILER DATE : '
TRP-TRAILER-DATE
MOVE 3180 TO ABEND-CODE
PERFORM 9100-ABEND-PROGRAM THRU 9109-EXIT
END-IF
|
|
What did you see after the first two DISPLAY statements?
What did you see after the second pair of DISPLAY? (If any) |
|
Back to top |
|
|
mitha
New User
Joined: 01 Dec 2021 Posts: 19 Location: India
|
|
|
|
Only the if condition display is showing in sysout .Other two display , not showing in sysout |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2141 Location: USA
|
|
|
|
mitha wrote: |
Only the if condition display is showing in sysout .Other two display , not showing in sysout |
This cannot happen. How the IF condition can be showing, at all???
Find out what is wrong with the first two DISPLAY?
Do you have any compilation warnings, or errors?
Do you have any run-time warnings or errors?
Are you sure you are running the same code produced after compilation of the example you demonstrate?
Add more DISPLAY statements to trace your execution, the simplest ones, like:
Code: |
DISPLAY "Entry point passed." |
|
|
Back to top |
|
|
mitha
New User
Joined: 01 Dec 2021 Posts: 19 Location: India
|
|
|
|
No compilation error. Working correctly .Ok Will try to find out what the reason. Can you please say me whether this logic is correct or not. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2141 Location: USA
|
|
|
|
mitha wrote: |
No compilation error. Working correctly .Ok Will try to find out what the reason. Can you please say me whether this logic is correct or not. |
The logic itself (with one IF only) is correct.
The used data formats are incorrect, or data conversion is wrong.
Trace everything up to more details if needed.
This is the standard way of debugging any code! |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
|
|
Why do you need all that UNSTRING ? Just use a raw date (field with slashes value) and do as exactly suggested by Robert or at the least simply do reference modification to get into YYYYMMDD format before doing any compare.
Moved to beginners section of the forum |
|
Back to top |
|
|
|