2

如何对具有这种记录的 tran 文件进行排序..

AT key taname username
AP key prname prshortname
DT key taname username
CT key taname username
CP key prname prshortname
DP key prname prshortname

我需要做的是按删除、添加、更改顺序对这个 tran 文件进行排序。有什么办法吗?提前致谢..

AT = add task;
AP = add proj;
DT = delete task;
DP = delete proj;
CT = change task;
CP = change proj;
4

4 回答 4

2

您可以将文件读入表中,根据事务类型添加排序序列号。排序序列号将从表中查找。然后按排序顺序和记录中的键对表进行排序。例如,您的代码可能包括(语法并不完美,但应该为您指明正确的方向):

01  TRANSACTION-TYPES.

* 订购为删除添加更改

    05  FILLER                  PIC X(4) VALUE 'DT01'.
    05  FILLER                  PIC X(4) VALUE 'DP02'.
    05  FILLER                  PIC X(4) VALUE 'AT03'.
    05  FILLER                  PIC X(4) VALUE 'AP04'.
    05  FILLER                  PIC X(4) VALUE 'CT05'.
    05  FILLER                  PIC X(4) VALUE 'CP06'.

01  TRANS-TYPE-TABLE REDEFINES TRANSACTION-TYPES.

    05  TRANS-TYPE OCCURS 6 TIMES INDEXED BY TRANS-INDEX.
        10  TRANS-CODE          PIC XX.
        10  TRANS-SORT          PIC 99.

01  TRANSACTION-TABLE.

    05  TRANS-RECORD OCCURS 1 to 1000 TIMES DEPENDING ON TRANS-COUNT
        INDEXED BY TABLE-INDEX.
        10  TRANS-TABLE-SORT        PIC 99.
        10  TRANS-TABLE-DETAIL      PIC X(132).
...

ADD-RECORD-TO-TABLE.

    MOVE IN-RECORD TO TRANS-TABLE-DETAIL (TABLE-INDEX)
    SET TRANS-INDEX TO 1
    SEARCH TRANS-TYPE
        AT END MOVE HIGH-VALUE TO TRANS-TABLE-SORT (TABLE-INDEX)
        WHEN IN-RECORD-TRANS-CODE = TRANS-CODE (TRANS-INDEX)
            MOVE TRANS-SORT (TRANS-INDEX) TO TRANS-TABLE-SORT (TABLE-INDEX)
    .

...

SORT TRANS-RECORD

    ON ASCENDING KEY TRANS-TABLE-SORT
    ON ASCENDING KEY TRANS-TABLE-DETAIL.
于 2013-09-05T01:57:12.893 回答
1
EVALUATE TRUE
    WHEN first-char-shows-add
        MOVE outsort-adds to sort-transaction-category
    WHEN first-char-shows-change
        MOVE outsort-change to sort-transaction-category
    WHEN first-char-shows-delete
        MOVE outsort-deletes to sort-transaction-category
    WHEN OTHER
        deal with to your local standards
END-EVALUATE

WHEN 具有适当命名的 88,值 MOVEd 是带有 VALUE 语句的数据名称。说“3”“5”“7”或任何你喜欢的东西来给你下订单。

您将输入记录放入记录中以首先进行排序,然后将 outsort 字段放入,然后对记录进行排序。可以在输入/输出程序中完成。

于 2013-09-05T07:11:54.787 回答
1

您可能希望将 SORT 与 INPUT PROCEDURE 和 OUTPUT PROCEDURE 子句一起使用。

下面的示例仅用于提示,但应导致可接受的解决方案。在这些过程中,您几乎可以完全控制何时以及如何将输入记录释放到排序文件,以及如何通过输出过程管理 RETURN 记录。

为了有趣和打字,您可以将它们链接为过滤器,或者将少数类型转换为枚举并将值填充到单个 INPUT PROCEDURE IS 传递的主键中。您可以跳过 OUTPUT PROCEDURE IS 短语并混合在 GIVING 中,或者玩得很好并使用 OUTPUT PROCEDURE 将枚举转换回人类可读的标签。

OCOBOL >>SOURCE FORMAT IS FIXED
      ******************************************************************
      * Date:      02-Sep-2008
      * Purpose:   An OpenCOBOL SORT verb example
      * Tectonics: cobc -x sorting.cob
      *     ./sorting <input >output
      *   or simply 
      *     ./sorting
      *   for keyboard and screen demos 
      ******************************************************************
       identification division.
       program-id. sorting.

       environment division.
       configuration section.
      * This sets up a sort order lower then upper except for A and a
       special-names.
           alphabet mixed is " AabBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTu
      -"UvVwWxXyYzZ0123456789".

       input-output section.
       file-control.
           select sort-in
               assign keyboard
               organization is line sequential.
           select sort-out
               assign display
               organization is line sequential.
           select sort-work
               assign "sortwork".

       data division.
       file section.
       fd sort-in.
          01 in-rec        pic x(255).
       fd sort-out.
          01 out-rec       pic x(255).
       sd sort-work.
          01 work-rec      pic x(255).

       working-storage section.
       01 loop-flag        pic x value low-value.

       procedure division.
       sort sort-work
           on descending key work-rec
           collating sequence is mixed
           input procedure is sort-transform
           output procedure is output-uppercase.

       display sort-return end-display.
       goback.

      ******************************************************************
       sort-transform.
       move low-value to loop-flag
       open input sort-in
       read sort-in
           at end move high-value to loop-flag
       end-read
       perform
           until loop-flag = high-value
               move FUNCTION LOWER-CASE(in-rec) to work-rec
               release work-rec
               read sort-in
                   at end move high-value to loop-flag
               end-read
       end-perform
       close sort-in
       .

      ******************************************************************
       output-uppercase.
       move low-value to loop-flag
       open output sort-out
       return sort-work
           at end move high-value to loop-flag
       end-return
       perform
           until loop-flag = high-value
               move FUNCTION UPPER-CASE(work-rec) to out-rec
               write out-rec end-write
               return sort-work
                   at end move high-value to loop-flag
               end-return
       end-perform
       close sort-out
       .

       exit program.
       end program sorting.

有关详细信息,请参阅http://opencobol.add1tocobol.com/#sort 。

于 2013-09-05T16:22:38.107 回答
0

看起来您必须处理的排序桶的数量是一个小的固定数字(6)。您可以使用 SYNCSORT 等实用程序根据每条记录上的 DT、DP、AT、AP、CT、CP 标记值将事务文件拆分为六个子文件。接下来根据任何其他适当的标准对单个文件进行排序。接下来以所需的顺序连接六个排序的子文件。

于 2013-09-05T13:29:48.990 回答