* http://www.cobug.com/cobug/forums/cobolLang/130.shtml
*I am tasked with sorting an input file via an account
* number. This account number is not numeric, it is
* alpha numeric. It contains numbers only but can also
* have letters (in most cases). When I sort by acct
* nbr, the sort is incorrect because acct nbrs that
* are greater than others are not in the correct
* places. Is there a way for me to sort correctly
* by just the numbers in the account number while
* ignoring the letters?
* The acct nbr can show up like the following
* examples:
* 123456ABC
* 456789
* 123ABC
* 12345678ABC
* 1234
* Thanks
* Ru1
* 4/09/2008 08:46:43
* RE: COBOL sort by
*Message:
* If the account number is an alpha field, you can
* check for numberics fir
SD SortFile.
01 Sort-record.
05 sr-account-nbr-key pic 9(12).
05 sr-account-nbr-x pic x(12).
fd acct-file.
01 acct-rec.
05 in-acct pic x(12).
05 in-acct-x redefines in-acct.
10 in-acct-entry pic x(01) occurs 12.
working-storage.
05 sub Pic 9(02).
05 ws-account-nbr Pic x(12).
05 ws-account-nbr-n redefines ws-account-nbr
pic 9(12).
05 ws-account-nbr-t redefines ws-account-nbr.
03 ws-acct-entry pic x(01) occurs 12.
05 ws-ctr pic 9(01) value zeros.
Procedure Division.
read record.
move in-acct to ws-account-nbr.
if in-account-nbr numeric
move ws-account-nbr-n to sr-account-nbr-key
else
perform 0000-handle-alpha.
0000-handle-alpha.
move spaces to ws-account-nbr.
perform 0000-build-sort-key
varying sub from 1 by 1
until sub > 12
or in-acct-entry(sub) numeric.
move ws-account-nbr-n to sr-account-nbr-key.
0000-build-sort-key.
move in-acct-entry(sub) to ws-acct-entry(sub).
¤ Dauer der Verarbeitung: 0.20 Sekunden
(vorverarbeitet)
¤
|
Haftungshinweis
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.
|