【问题标题】:Trouble using Intrinsic function in COBOL在 COBOL 中使用内部函数时遇到问题
【发布时间】:2013-02-06 07:47:09
【问题描述】:

我是 COBOL 编程的新手,我在一些可能应该是微不足道的事情上遇到困难。我想找到用户输入的最小值和最大值。当用户点击 0 时,应显示最大值、最小值和平均值。平均值很简单,但最小值和最大值让我想知道。如果这是 JAVA 或其他语言,我会做一些比较 MAX INT 值的场景。不幸的是 COBOL 中的 High-Value 和 Low-Value 不是整数值????所以我决定把用户的条目放在一个表中,然后使用内部函数来做我需要的事情。但是,一旦我尝试这样计算:

 compute Min-Result = Function Min (Num-Field(ALL))

我收到一条错误消息,提示“语法错误,全部意外。”在这一点上,我完全不知道该怎么做以及为什么会出现此错误。我正在使用 OpenCOBOL 1.1 Mingw。这是我的完整代码。任何帮助将不胜感激。什么都可以。我还确保没有超过 72 行。

     identification division.
       program-id.  lab1a.
      * no envionrment division since there are no files needed, etc.
       data division.
       working-storage section.

      * declaring proper variables to store integer values
       01  Max-Result        PIC S9(5).
       01  Min-Result        PIC S9(5).
       01  Count-Val         PIC 9  Value 0.
       01  Running-Tot       PIC S9(10)v99.
       01  First-Zero        PIC 9  Value 1.
       01  Final-Format-Avg       PIC ZZZZZ9.9999.
       01  Avg-Ent              PIC S9(5)v9999.
       01  Calc-Table.
            03  Table-Record  Occurs 1 to 500 times
                              depending on Entered-Num.
                05  Num-Field    PIC S9(5).
       01  Entered-Num       PIC S9(5).

       procedure division.
       000-Main.



           perform with test after until Entered-Num = 0
              display "Enter a 4-digit number (0 to stop): "
                 with no advancing
              accept Entered-Num

              add 1 to Count-Val
              add Entered-Num to Running-Tot

              display Running-Tot
              display Count-Val
              move Entered-Num to Num-Field(Count-Val)



      * this way every time the user enters a non zero number it will be re-assigned
      * to the variable Ending-Num. If they enter zero the if condition is skipped, the
      * loop condition is tested at the top and is ended.


           end-perform.
           subtract 1 from Count-Val
           display Count-Val
           display " "  
           display " "    
      *WATCH FOR TRUNCATION ERROR.....
           Divide Running-Tot By Count-Val Giving Avg-Ent
           move Avg-Ent to Final-Format-Avg

      *******WHY DOES THIS NOT WORK???????*********************** 
           compute Min-Result = Function Min (Num-Field(ALL))
           compute Max-Result = Function Max (Num-Field(ALL))


           if First-Zero = 0
           display "The first number you entered was zero. 
 &                  Next time enter a different one."
           else                
           display "The lowest value entered: " Min-Result             
           display "The highest value entered: " Max-Result
           display "The average value entered: " 
                    Final-Format-Avg
           end-if

           stop run.

【问题讨论】:

    标签: arrays cobol min


    【解决方案1】:

    OpenCOBOL 内部函数目前不支持 ALL,这是一个在书上实现的特性。

    【讨论】:

    • 再次感谢您。我对此一无所知。因为我看到了多个使用 ALL 的教程,所以我只是认为它会默认工作。无论哪种方式,很高兴知道它目前没有。
    【解决方案2】:

    您将“Entered-Num”作为您的 Occurs取决于字段。 Entered-Num 在您使用该功能时为零。应该是 Count-Val。

    这不是问题,但你问了。

    查看 2009 OpenCobol Programmer's Guid,我找不到支持 ALL 的确认信息。

    保持“最低值”和“最高值”并根据需要与输入的数字进行比较/替换会更简单/更快。

    【讨论】:

    • 我想我通常把事情复杂化了。我想我会尝试用等比较值来做到这一点。
    猜你喜欢
    • 1970-01-01
    • 2020-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多