Page 1 of 1

Formatting Values

PostPosted: Thu Jun 25, 2009 11:56 pm
by hakghen
Hello fellow friends, I'd like to know if you can help me format my values from a sample cobol program.

This is the source code:

       ID DIVISION.                           
       PROGRAM-ID.  PROGZ002                 
      *                                       
      *PROGRAMA - CALCULAR A MEDIA DE 4 NOTAS
      *                                       
       DATA DIVISION.                         
       WORKING-STORAGE SECTION.               
      *                                       
       01 N1    PIC 99V99 VALUE 0.           
       01 N2    PIC 99V99 VALUE 0.           
       01 N3    PIC 99V99 VALUE 0.           
       01 N4    PIC 99V99 VALUE 0.           
       77 MEDIA PIC 99V99 VALUE 0.           
      *                                       
       PROCEDURE DIVISION.                   
           ACCEPT N1 FROM SYSIN.             
           ACCEPT N2 FROM SYSIN.             
           ACCEPT N3 FROM SYSIN.             
           ACCEPT N4 FROM SYSIN.             
           ACCEPT N4 FROM SYSIN.                               
           COMPUTE MEDIA = (N1 + N2 + N3 + N4) / 4.           
           DISPLAY '* PROGRAMA PARA CALCULAR MEDIA DE 4 NOTAS'.
           DISPLAY '*'.                                       
           DISPLAY '* NOTA 1: ' N1.                           
           DISPLAY '* NOTA 2: ' N2.                           
           DISPLAY '* NOTA 3: ' N3.                           
           DISPLAY '* NOTA 4: ' N4.                           
           DISPLAY '*'.                                       
           DISPLAY '* MEDIA => ' MEDIA.                       
           STOP RUN.                                           


And I'm using this JCL to execute it:

//GPAL03EX JOB MSGLEVEL=1,CLASS=C,MSGCLASS=X,NOTIFY=GPAL03,TIME=(,20)
//*                                                                                                                               
//     EXEC PGM=PROGZ002                                             
//STEPLIB DD DSN=GP.GERAL.LOADLIB,DISP=SHR                           
//SYSOUT  DD SYSOUT=*                                               
//SYSIN   DD *                                                       
100                                                                 
050                                                                 
080                                                                 
070                                                                 
/*                                                                   


And this is my output in SDSF spool(The SYSOUT):

********************************* TOP OF DATA **********************************
* PROGRAMA PARA CALCULAR MEDIA DE 4 NOTAS                                       
*                                                                               
* NOTA 1: 100                                                                   
* NOTA 2: 050                                                                   
* NOTA 3: 080                                                                   
* NOTA 4: 070                                                                   
*                                                                               
* MEDIA => 0750                                                                 
******************************** BOTTOM OF DATA ********************************


Question is: I would like to format the N1, N2, N3, N4 and MEDIA values to show, not as 100, 050, 080, 070 and 0750, but as this:

N1: 10,0
N2: 5,0
N3: 8,0
N4: 7,0
and
MEDIA: 7,5

So, any help? Thanks in advance!

Re: Formatting Values

PostPosted: Fri Jun 26, 2009 3:02 am
by dick scherrer
Hello,

You need to move the Nn values to an edited field to reformat them.

If a decimal point will do (instead of the comma), you could use:
01 E1    PIC Z9.99.

MOVE N1 TO E1.
DISPLAY '* NOTA 1: ' E1.


Domething you want to download (or at least bookmark) is the COBOL Language Reference manual:
http://publibz.boulder.ibm.com/cgi-bin/ ... 0/CONTENTS?

Re: Formatting Values

PostPosted: Fri Jun 26, 2009 3:13 am
by hakghen
Oh Thanks dick! I'll take a look when I arrive home... But I think it will solve everything :P

Re: Formatting Values

PostPosted: Fri Jun 26, 2009 3:33 am
by dick scherrer
You're welcome - if there are questions, let us know :)

d

Re: Formatting Values

PostPosted: Fri Jun 26, 2009 6:03 pm
by hakghen
Hello again, just to post the formatted code. I think I'll try, later, using the parameter DECIMAL POINT IS COMMA under the special-names to use the comma as a decimal point (as the Brazillian standards). If it works I'll post here too, if anybody is interested.

So, here it is:

Source-Code.:
        ID DIVISION.                         
        PROGRAM-ID.  PROGZ002                 
       *                                     
       *PROGRAMA - CALCULAR A MEDIA DE 4 NOTAS
       *                                     
        DATA DIVISION.                       
        WORKING-STORAGE SECTION.             
       *                                     
        01 N1    PIC 99V99 VALUE ZERO.       
        01 N2    PIC 99V99 VALUE ZERO.       
        01 N3    PIC 99V99 VALUE ZERO.       
        01 N4    PIC 99V99 VALUE ZERO.       
        01 MEDIA PIC Z9.99.                   
        01 E1    PIC Z9.99.                   
        01 E2    PIC Z9.99.                   
        01 E3    PIC Z9.99.                   
        01 E4    PIC Z9.99.                   
       *                                                       
        PROCEDURE DIVISION.                                     
            ACCEPT N1 FROM SYSIN.                               
            ACCEPT N2 FROM SYSIN.                               
            ACCEPT N3 FROM SYSIN.                               
            ACCEPT N4 FROM SYSIN.                               
            COMPUTE MEDIA = (N1 + N2 + N3 + N4) / 4.           
            DISPLAY '* PROGRAMA PARA CALCULAR MEDIA DE 4 NOTAS'.
            DISPLAY '*'.                                       
            MOVE N1 TO E1.                                     
            DISPLAY '* NOTA 1: ' E1.                           
            MOVE N2 TO E2.                                     
            DISPLAY '* NOTA 2: ' E2.                           
            MOVE N3 TO E3.                                     
            DISPLAY '* NOTA 3: ' E3.                           
            MOVE N4 TO E4.                                     
            DISPLAY '* NOTA 4: ' E4.                           
            DISPLAY '*'.                                       
            DISPLAY '* MEDIA => ' MEDIA.                       
            STOP RUN.                                           


Output.:
********************************* TOP OF DATA **********************************
* PROGRAMA PARA CALCULAR MEDIA DE 4 NOTAS                                       
*                                                                               
* NOTA 1: 10.00                                                                 
* NOTA 2:  5.00                                                                 
* NOTA 3:  8.00                                                                 
* NOTA 4:  7.00                                                                 
*                                                                               
* MEDIA =>  7.50                                                               
******************************** BOTTOM OF DATA ********************************


Thanks once again! ;)

Re: Formatting Values

PostPosted: Sat Jun 27, 2009 1:44 am
by dick scherrer
You're welcome :)

Yes, the special-names entry should do what you want. And, sure post the code :)

d

Re: Formatting Values

PostPosted: Sat Jun 27, 2009 9:40 am
by hakghen
Here it is, using special names!

Source Code:
            ID DIVISION.                         
            PROGRAM-ID.  PROGZ002                 
           *
            ENVIRONMENT DIVISION.     
            CONFIGURATION SECTION.     
           *                           
            SPECIAL-NAMES.             
                   DECIMAL-POINT IS COMMA.       
           *                         
           *PROGRAMA - CALCULAR A MEDIA DE 4 NOTAS
           *                                     
            DATA DIVISION.                       
            WORKING-STORAGE SECTION.             
           *                                     
            01 N1    PIC 99V99 VALUE ZERO.       
            01 N2    PIC 99V99 VALUE ZERO.       
            01 N3    PIC 99V99 VALUE ZERO.       
            01 N4    PIC 99V99 VALUE ZERO.       
            01 MEDIA PIC Z9,99.                   
            01 E1    PIC Z9,99.                   
            01 E2    PIC Z9,99.                   
            01 E3    PIC Z9,99.                   
            01 E4    PIC Z9,99.                   
           *                                                       
            PROCEDURE DIVISION.                                     
                ACCEPT N1 FROM SYSIN.                               
                ACCEPT N2 FROM SYSIN.                               
                ACCEPT N3 FROM SYSIN.                               
                ACCEPT N4 FROM SYSIN.                               
                COMPUTE MEDIA = (N1 + N2 + N3 + N4) / 4.           
                DISPLAY '* PROGRAMA PARA CALCULAR MEDIA DE 4 NOTAS'.
                DISPLAY '*'.                                       
                MOVE N1 TO E1.                                     
                DISPLAY '* NOTA 1: ' E1.                           
                MOVE N2 TO E2.                                     
                DISPLAY '* NOTA 2: ' E2.                           
                MOVE N3 TO E3.                                     
                DISPLAY '* NOTA 3: ' E3.                           
                MOVE N4 TO E4.                                     
                DISPLAY '* NOTA 4: ' E4.                           
                DISPLAY '*'.                                       
                DISPLAY '* MEDIA => ' MEDIA.                       
                STOP RUN.                                           


Output:
    ********************************* TOP OF DATA **********************************
    * PROGRAMA PARA CALCULAR MEDIA DE 4 NOTAS                                       
    *                                                                               
    * NOTA 1: 10,00                                                                 
    * NOTA 2:  5,00                                                                 
    * NOTA 3:  8,00                                                                 
    * NOTA 4:  7,00                                                                 
    *                                                                               
    * MEDIA =>  7,50                                                               
    ******************************** BOTTOM OF DATA ********************************

Re: Formatting Values

PostPosted: Sat Jun 27, 2009 10:56 pm
by dick scherrer
Thanks for the update :)

d