Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Alphanumeric comparison with another alphanumeric

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
amdparsn

New User


Joined: 09 Feb 2009
Posts: 8
Location: Chennai

PostPosted: Fri Oct 15, 2010 3:15 pm    Post subject: Alphanumeric comparison with another alphanumeric
Reply with quote

Whether alphanumeric field can be compared with a another alphanumeric field?

Example:

EX-DATE(alphanumeric) > EX-DATE1(alphanumeric)
Back to top
View user's profile Send private message

Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Fri Oct 15, 2010 4:07 pm    Post subject: Reply to: Alphanumeric comparison
Reply with quote

In your example, we're assuming both fields are the same length and this length is greater than one?

If true, then you can only easily compare both fields for EQUAL or NOT EQUAL.

If the length is one, then you can also compare for LESS THAN or GREATER THAN.

If the length is greater than one, then you would have to compare each byte of each field, one-on-one/left-to-right, if you were attempting a LESS THAN or GREATER THAN condition or try a more "creative" approach (yours to decide), if the fields lengths were different.

You need to put your EBCDIC hat on, because (for example) NUMERIC values 0-9 are greater than CAPITAL letters A-Z, whereas, in ASCII, it's just the opposite.

Your field-names indicate that these could be date-values, perhaps of the same format, such as "CCYYMMDD"?

If they only contain NUMERIC values and they're the same length and same format, then a LESS THAN or GREATER THAN comparison could be used as well.

Things to ponder.... icon_wink.gif

Bill
Back to top
View user's profile Send private message
amdparsn

New User


Joined: 09 Feb 2009
Posts: 8
Location: Chennai

PostPosted: Fri Oct 15, 2010 5:20 pm    Post subject: Hiii Bill
Reply with quote

Well Yess they are date fields with this format DD/MM/CCYY. can i move this alphanumeric field to a group like this below

01 A.
05 B PIC 9(02).
05 FILLER PIC X(01)
05 C PIC 9(02).
05 FILLER PIC X(01).
05 D PIC 9(04).
01 E pic 9(08).

MOVE EX-DATE TO A.???????

After this move,

MOVE B TO E(1:2)
MOVE C TO E(3:2)
MOVE D TO E(5:8)

WHETHER THIS WILL WORK????
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Oct 15, 2010 5:45 pm    Post subject:
Reply with quote

yes, it would seem logical to move a DD/MM/CCYY fomated date field
to a CCYYMMDD formated field,
if one expected a rational outcome.

your question is not predicated on alphanumeric comparing
but assuming that somehow the cobol compiler will re-arrange your date field.
Sorry, cobol does not do that.

whether it be alphanumeric or numeric compare,
you have to organize your field structure in a way to reflect logical order.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Fri Oct 15, 2010 5:48 pm    Post subject:
Reply with quote

You really, really, really need to spend some time in the COBOL Language Reference and Programming Guide manuals -- you can find them by clicking the manuals link at the top of this page.

COBOL always allows you to move an alphanumeric variable to a group (which is also alphanumeric). Reference modification can be used on USAGE DISPLAY variables without any issues, as well. So semantically, the answer to your question is yes you can do it.

However, the code you posted has three syntax errors -- you need a period after the first filler in A, reference modification references need spaces in them, and E is not 13 characters long so moving 8 bytes starting in position 5 will generate a compile error. So the code you posted will not compile from a syntax standpoint, even though it could work if you fixed the syntax errors.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Fri Oct 15, 2010 5:57 pm    Post subject: Reply to: Alphanumeric comparison
Reply with quote

Actually -

Code:

MOVE D TO E(5:8)

Specifies an incorrect length, which Robert has noted.

Either replace 8 with 4 or change the MOVE to -

Code:

MOVE D TO E(5:)

And the compiler will automatically calculate the length for you.

But, you need to devote more time reading the manuals and familiarizing yourself with the language.

Bill
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Oct 15, 2010 6:13 pm    Post subject:
Reply with quote

i just spent a few moments looking,
and no computer language (that I know of)
will allow you to compare two fields
built on the dd/mm/ccyy format
and provide proper results,
without the aid of functions to re-arrange the order.
Back to top
View user's profile Send private message
Phrzby Phil

Active Member


Joined: 31 Oct 2006
Posts: 961
Location: Richmond, Virginia

PostPosted: Fri Oct 15, 2010 6:25 pm    Post subject:
Reply with quote

SAS has informats (i.e., input formats) for various date formats, including ddmmyy10.:

Test:

Code:

data;
input @1  d1 ddmmyy10.
      @12 d2 ddmmyy10.
      ;

format d1 d2 date9.;   /* print as date rather than internal value */

put d1= d2= ;          /* print dates */

if d1 < d2
   then put 'd1 less than d2';
   else put 'd1 not less than d2';

/* inline data */
datalines;
20/01/2010 21/01/2009
;

run;


Results:

Code:

d1=20JAN2010 d2=21JAN2009
d1 not less than d2
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Oct 15, 2010 7:22 pm    Post subject:
Reply with quote

Quote:
SAS has informats (i.e., input formats) for various date formats, including ddmmyy10


which are internal functions to manipulate the data during comparison.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Fri Oct 15, 2010 8:11 pm    Post subject:
Reply with quote

Actually, if you use informat DDMMYY10. then SAS converts the date into the number of days since January 1, 1960 and the comparison is just two numeric values being compared to each other. SAS does all the hard work in the informat conversion during the input processing.
Back to top
View user's profile Send private message
santohsks1987
Warnings : 1

New User


Joined: 29 Dec 2010
Posts: 31
Location: Mumbai

PostPosted: Thu May 26, 2011 7:45 pm    Post subject:
Reply with quote

Hi all,

I have 2 dates in the same format yyyymmdd.

can i compare them using the greater than or less than operator as this does not have any symbols inbetween them?

i.e., ws-date1 < ws-date2
Back to top
View user's profile Send private message
Phrzby Phil

Active Member


Joined: 31 Oct 2006
Posts: 961
Location: Richmond, Virginia

PostPosted: Thu May 26, 2011 7:49 pm    Post subject:
Reply with quote

1. And you tried this, right, or do we do your (very simple) work for you? If you cannot test this, how can you test more complicated processes?

2. Also, while you're at it, try with separators (e.g., / or -). Did that work, too? Why would you think that would affect a character comparison when the separators would be in the same positions?
Back to top
View user's profile Send private message
gylbharat

Active Member


Joined: 31 Jul 2009
Posts: 565
Location: Bangalore

PostPosted: Fri May 27, 2011 3:38 pm    Post subject:
Reply with quote

santohsks1987 wrote:
Hi all,

I have 2 dates in the same format yyyymmdd.

can i compare them using the greater than or less than operator as this does not have any symbols inbetween them?

i.e., ws-date1 < ws-date2


Yes, if both are valid dates and both the dates are in same format then they can be compared using greater than or less than operators
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Fri May 27, 2011 4:41 pm    Post subject:
Reply with quote

No requirement for the dates to be "valid".

Obviously, the the test to make any sense in the specific context, it would be good to have actual dates in them. As Phil has said, seperators, of any time or size, do not matter as long as they are in the same position in both fields.

But, many-a-time, I have move HIGH-VALUES to such a date field when doing file comparisons. This is by no means a "valid" date, but it is a logical and normal way to do things when there is no more input for one or other of the files.

As far as the "validity" of the date data is concerned, I guess the TS already covered that in his description.
Back to top
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Fri May 27, 2011 7:33 pm    Post subject:
Reply with quote

gylbharat wrote:
Yes, if both are valid dates and both the dates are in same format then they can be compared using greater than or less than operators


A true, but VERY misleading statement.

While two "valid" dates in the "same format" CAN be compared using greater than or less than operators, the results of such a comparison will not be VALID unless the dates are in a format that is in, or encodes a date that is in century,year,month,day order (note: this includes both display formats (e.g. YYYY/MM/DD), and internal formats derived from same (e.g. COBOL's INTEGER-OF-DATE function). Consider the following comparisons that would give invalid results, even though the dates and date formats are "valid" and in the "same format":

dates in the format month,day,year (with or without the century)(U.S. format),
e.g. comparing 05/27/2011 to 06/27/2010

dates in the format day,month,year (with or without the century) (non-U.S. format),
e.g. comparing 27/05/2011 to 23/06/2011

dates in the format month-name, day, year,
e.g. comparing May 27, 2011 to Aug 15, 2011

dates in the format day, month-name, year,
e.g. comparing 27 May, 2011 to 28 Apr, 2011

dates in the format year,day,month (without the century)
e.g. comparing 11/27/05 to 11/28/03

dates in the format year,month,day (without the century),
e.g. comparing 11/05/27 to 99/05/27
note: the format YYMMDD CAN be valid if the comparison is being done in COBOL and the dates are defined as windowed (DATE-FORMAT YYXXXX)

dates in the julian format YYDDD,
e.g. comparing 11143 to 99143
note: the format YYMMDD CAN be valid if the comparison is being done in COBOL and the dates are defined as windowed (DATE-FORMAT YYXXXX)
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. How to move a long alphanumeric data ... lind sh COBOL Programming 8 Mon Dec 05, 2016 7:51 pm
No new posts CICS NEW SIT PARAMETERS CICS BEHAVIOR... Kyle Carroll CICS 0 Fri Nov 04, 2016 11:55 pm
This topic is locked: you cannot edit posts or make replies. Alphanumeric to Numeric move on UNIX mistah kurtz COBOL Programming 16 Wed Jul 27, 2016 8:47 pm
No new posts alphanumeric sequence generation sivaprasad.gadhi COBOL Programming 6 Wed Mar 30, 2016 3:03 am
No new posts alphanumeric sequence generation sivaprasad.gadhi DFSORT/ICETOOL 8 Mon Mar 21, 2016 1:09 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us