Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
krunalbafna
Warnings : 1

Active User

Joined: 18 Jan 2010
Posts: 143
Location: Pune

 Posted: Thu Jun 03, 2010 9:01 am    Post subject: ASCII comparision. Following are my two variable: XXA-CDE PIC X(04). CCC-DDD PIC X(04). i m using follwing comparsion: IF( XXA-CDE (1:1) < CCC-DDD (1:1) ) STATEMENTS.......... END-IF for value: XXA-CDE = 5AXY CCC-DDD = ABAB My above condition should be true and it should execute statements but the control is going in the else part. For initial value of XXXA-CDE the control flow is proper. May you suggest where i have commited a mistake causing the above error.

dick scherrer

Site Director

Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

Posted: Thu Jun 03, 2010 9:12 am    Post subject:

Hello,

 Quote: My above condition should be true
Not on the mainframe. . . If you ran this same cobol code on UNIX or Windows, the compare would be as you want but not on the mainframe. When comparing values for > or <, the collating sequence of the system is used.

In hex the 5 is an x'F5' while the A is an x'C1" - which is lower than the x'F5'.

 Quote: May you suggest where i have commited a mistake causing the above error.
Your only mistake is the expectation that 5 will be less than A.
krunalbafna
Warnings : 1

Active User

Joined: 18 Jan 2010
Posts: 143
Location: Pune

 Posted: Thu Jun 03, 2010 9:24 am    Post subject: Hi Dick, From ascii value table The hex value of '5' is 35 The hex value of 'A' is 41 while doing above comparision value of 5 should be less than A. If cobol is not taking ascii values for comparision may you please suggest how comparision is done in cobol. If so value of '5' is greater than 'A' how should i proceed to avoid termination of code when others codes are present in file.
dick scherrer

Site Director

Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

 Posted: Thu Jun 03, 2010 9:37 am    Post subject: Hello, I don't know of a way to have part of your code use the ebcdic collating sequence and part use ascii. . . Suggest you consider doing everything in ebcdic on the mainframe. It will be a nightmare if the system tries to store data both ways, have logic that works both ways, etc.
krunalbafna
Warnings : 1

Active User

Joined: 18 Jan 2010
Posts: 143
Location: Pune

 Posted: Thu Jun 03, 2010 9:53 am    Post subject: Hi Dick, May you help how should be check in which comparision is done in mainframe. If it is in EBCDIC format how should be proceed with above comparision to go with proper flow.
enrico-sorichetti

Senior Member

Joined: 14 Mar 2007
Posts: 10478
Location: italy

 Posted: Thu Jun 03, 2010 12:29 pm    Post subject: Reply to: ASCII comparision. a byte is a byte ... there is not a thing such an ascii byte and an ebcdic byte ascii and ebcdic are conventions used when exchanging data between different but as a general point in the IBM world there are COLLATING SEQUENCE which means order something according to a sequence different from the one expressed by the byte numerical value the only way to compare according to a different COLLATING SEQUENCE is to use translate tables and compare the translated values strings seen as EBCDIC str1 "12345678" ==> x'f1f2f3f4f5f6f7f8f9' str2 "abcdefghi" ==> x'c1c2c3c4c5c6c7cc8c9' str1 > str2 strings seen as ASCII str1 "12345678" ==> x'313233343536373839' str2 "abcdefghi" ==> x'414243444546474849' str1 < str2 but the programming language will never be aware OF the external meanig of the bytes if You use two temporary variables and do an ispect replacing You can compare according to two different COLLATING SEQUENCES the wisest approach would be to review the application specifications in order to make it compliant with different CODE PAGES and COLLATING SEQUENCES and provide proper standards and NOT have each program/programmer use it' s own approach
Robert Sample

Global Moderator

Joined: 06 Jun 2008
Posts: 8339
Location: Dubuque, Iowa, USA

Posted: Thu Jun 03, 2010 4:33 pm    Post subject:

There is a link to manuals at the top of the page. You need to click on it, find the COBOL Language Reference and Programming Guide manuals and read them extensively. If you are new to mainframes, you definitely need to be aware that mainframes use EBCDIC, not ASCII. Files are created in EBCDIC, FTP text transfers result in EBCDIC files, and programming languages use EBCDIC. Attempting to change this will cause you a great deal of problems and grief along the way -- you are much, much better off learning to deal with EBCDIC.

That said, if you do manage to find and read the COBOL manuals, you can find this in the Language Reference manual:
 Quote: APPENDIX1.6.1.1 OBJECT-COMPUTER and SPECIAL-NAMES paragraphs When at least one file in the program is an ASCII-encoded file, the alphabet-name clause of the SPECIAL-NAMES paragraph must be specified; the alphabet-name must be associated with STANDARD-1 or STANDARD-2 (for ASCII or ISCII collating sequence or CODE SET, respectively). When alphanumeric comparisons within the object program are to use the ASCII collating sequence, the PROGRAM COLLATING SEQUENCE clause of the OBJECT-COMPUTER paragraph must be specified; the alphabet-name used must also be specified as an alphabet-name in the SPECIAL-NAMES paragraph, and associated with STANDARD-1. For example: Object-computer. IBM-system Program collating sequence is ASCII-sequence. Special-names. Alphabet ASCII-sequence is standard-1. When both clauses are specified, the ASCII collating sequence is used in this program to determine the truth value of the following alphanumeric comparisons: * Those explicitly specified in relation conditions * Those explicitly specified in condition-name conditions * Any alphanumeric sort or merge keys (unless the COLLATING SEQUENCE phrase is specified in the MERGE or SORT statement). When the PROGRAM COLLATING SEQUENCE clause is omitted, the EBCDIC collating sequence is used for such comparisons. The PROGRAM COLLATING SEQUENCE clause, in conjunction with the alphabet-name clause, can be used to specify EBCDIC alphanumeric comparisons for an ASCII-encoded tape file or ASCII alphanumeric comparisons for an EBCDIC-encoded tape file. The literal option of the alphabet-name clause can be used to process internal data in a collating sequence other than NATIVE or STANDARD-1.
I would not recommend following these suggestions unless you are a very experienced COBOL programmer but IBM does provide the possibility.
dick scherrer

Site Director

Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

Posted: Thu Jun 03, 2010 8:36 pm    Post subject:

Hello,

 Quote: If it is in EBCDIC format how should be proceed with above comparision to go with proper flow.
As i mentioned earlier - i believe you need to change your expectation. . .

Just accept that A-Z is less than 0-9.

All i can do is repeat that if you persist it is most likely that the result will be a nightmare. Keep in mind that anything done with a utility (sort, file-aid, etc) may not do what you want (worse case is that it will run, but produce incorrect results - an abend would be better, but might not happen). Tools like Easytrieve would be problematic as well.
Phrzby Phil

Active Member

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

 Posted: Thu Jun 03, 2010 10:37 pm    Post subject: If you really need to keep the mainframe order = the order on an ASCII system, then you could have a 2nd, ASCII, copy of each field you order on (created by SAS, e.g., which has EBCDIC and ASCII format codes), and then sort on the ASCII version of each field.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Can EDCICONV convert EBCDIC to ASCII... natt.sut IBM Tools 3 Fri Nov 17, 2017 8:46 pm Comparision with current time arunsoods DFSORT/ICETOOL 5 Thu Nov 09, 2017 10:37 am EBCDIC to ASCII conversion using OCOPY mistah kurtz All Other Mainframe Topics 5 Tue Sep 06, 2016 2:26 pm How to display data in separate lines... salilnigam1970 DFSORT/ICETOOL 2 Tue Jan 26, 2016 9:49 pm How to display data in separate lines... salilnigam1970 JCL & VSAM 6 Tue Jan 26, 2016 5:30 pm

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us