将显示结果存储在PIC X(n)中

时间:2019-01-31 16:54:03

标签: cobol netcobol

picture子句定义DISPLAY命令将输出到控制台的格式。 有没有办法将格式化的字符串“输出”到变量?类似于以下内容,但可行。以下是数字的任意示例,通过图片进行转换,然后以货币格式存储在字符串中。

IDENTIFICATION DIVISION. 
 PROGRAM-ID.    Demo1234. 
 ENVIRONMENT DIVISION. 
 DATA DIVISION. 
 WORKING-STORAGE SECTION.
 01  Price           Pic     $$$,$$9.99.
 01  Formated-Output Pic     X(10).

 PROCEDURE DIVISION. 

     Move 10.50 to Price.
     Display Price Upon Formated-Output.
     *> Formated-Output would now contain "$10.50    "
     GOBACK.

1 个答案:

答案 0 :(得分:6)

将此行添加到WORKING-STORAGE

   01  Start-pos       Pic     9(4)    Binary.

Display Price语句替换为

       Move 1 to Start-pos
       Inspect Price tallying
           Start-pos for leading spaces
       Move Price (Start-pos:) to Formated-Output

结果"$10.50"后跟4个空格位于Formated-Output中。