Page 1 of 2

display not outputting correct number of characters

PostPosted: Sat Apr 06, 2013 3:54 pm
by theju112
hi im a cobol beginner trying to run this program in ideone.com online comipler...but i am not getting correct output for one display shown below..please help
program
------------------------
        IDENTIFICATION DIVISION.
        PROGRAM-ID. SAMPLE.
        ENVIRONMENT DIVISION.
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01    WS-CUSTRECORD.           
              05     WS-ACNO     PIC   9(05).
              05     WS-NAME     PIC   X(10).
              05     WS-BALANCE  PIC   9(07).
              05     WS-TYPE     PIC   X(02)   VALUE SPACES.
              05     WS-AMOUNT   PIC   9(06).
        PROCEDURE DIVISION.
        MAIN-PARA.
            DISPLAY "INSIDE MAIN PARA".
            PERFORM ACCEPT-PARA.       
            PERFORM CHECK-PARA.
            STOP RUN.
        ACCEPT-PARA.
            DISPLAY "INSIDE ACCEPT PARA".
            ACCEPT WS-ACNO.
            ACCEPT WS-NAME.
            ACCEPT WS-BALANCE.
            ACCEPT WS-AMOUNT.
            ACCEPT WS-TYPE.
           
        CHECK-PARA.
            DISPLAY "WS-TYPE=", WS-TYPE.     <------------------------------------wrong output
            DISPLAY "NAME =", WS-NAME.
            DISPLAY "DEPOSIT TRANSACTION".
            DISPLAY "BALANCE = ", WS-BALANCE.
            DISPLAY "AMOUNT = ", WS-AMOUNT.
            COMPUTE WS-BALANCE = WS-BALANCE + WS-AMOUNT.
            DISPLAY " BALANCE = ", WS-BALANCE.


input
-----------------------------------------
AC101
THEJWAL...
0900001
004002
D.


output
------------------------
INSIDE MAIN PARA
INSIDE ACCEPT PARA
WS-TYPE=D     ====================> wrong output (not printing D. printing only D)
NAME =THEJWAL...
DEPOSIT TRANSACTION
BALANCE = 0900001
AMOUNT = 004002
 BALANCE = 0904003


Code'd

Re: display not outputting correct number of characters

PostPosted: Sat Apr 06, 2013 4:47 pm
by enrico-sorichetti
the program.
EDIT       ENRICO.TEST.COB(MF001) - 01.03                  Columns 00001 00072
Command ===>                                                  Scroll ===> CSR
****** ***************************** Top of Data ******************************
000001        IDENTIFICATION DIVISION.
000002        PROGRAM-ID     MF001.
000003        AUTHOR.        <SOME AUTHOR>
000004        ENVIRONMENT    DIVISION.
000005        DATA           DIVISION.
000006        WORKING-STORAGE SECTION.
000007        01 WS-REC.
000008           05 WS-ACCT PIC 9(06).
000009           05 WS-NAME PIC X(20).
000010           05 WS-BLNC PIC 9(06).
000011           05 WS-TYPE PIC X(02).
000012           05 WS-AMNT PIC 9(06).
000013        PROCEDURE      DIVISION.
000014            DISPLAY 'MF001 - STARTED'.
000015            PERFORM ACPT-PARA.
000016            PERFORM UPDT-PARA.
000017            DISPLAY 'MF001 - ENDED  '.
000018            GOBACK.
000019        ACPT-PARA.
000020            DISPLAY 'MF001 - ACPT-PARA ENTER'.
000021            ACCEPT WS-ACCT.
000022            ACCEPT WS-NAME.
000023            ACCEPT WS-BLNC.
000024            ACCEPT WS-TYPE.
000025            ACCEPT WS-AMNT.
000026            DISPLAY 'MF001 - ACPT-PARA LEAVE'.
000027        UPDT-PARA.
000028            DISPLAY 'MF001 - UPDT-PARA ENTER'.
000029            DISPLAY 'WS-ACCT     = ' WS-ACCT.
000030            DISPLAY 'WS-NAME     = ' WS-NAME.
000031            DISPLAY 'WS-BLNC     = ' WS-BLNC.
000032            DISPLAY 'WS-TYPE     = ' WS-TYPE.
000033            DISPLAY 'WS-AMNT     = ' WS-AMNT.
000034            COMPUTE WS-BLNC = WS-BLNC + WS-AMNT.
000035            DISPLAY 'WS-BLNC NEW = ' WS-BLNC.
000036            DISPLAY 'MF001 - UPDT-PARA LEAVE'.
****** **************************** Bottom of Data ****************************

the data.
EDIT       ENRICO.TEST.COB($$RUNIT) - 01.20                Columns 00001 00072
Command ===>                                                  Scroll ===> CSR
****** ***************************** Top of Data ******************************
...... ......
000009 //SYSIN     DD *
000010 000001
000011 NAME.........
000012 000100
000013 T.
000014 000200
****** **************************** Bottom of Data ****************************

the result.
********************************* TOP OF DATA **********************************
MF001 - STARTED
MF001 - ACPT-PARA ENTER
MF001 - ACPT-PARA LEAVE
MF001 - UPDT-PARA ENTER
WS-ACCT     = 000001
WS-NAME     = NAME.........
WS-BLNC     = 000100
WS-TYPE     = T.
WS-AMNT     = 000200
WS-BLNC NEW = 000300
MF001 - UPDT-PARA LEAVE
MF001 - ENDED
******************************** BOTTOM OF DATA ********************************

not a MF ( IBM ) COBOL Problem

Re: display not outputting correct number of characters

PostPosted: Sat Apr 06, 2013 4:58 pm
by Robert Sample
Since you did you not use the Code button when posting your program and data, it is not possible to determine what happened. There could be a space before the D, for example -- as posted, spacing is not preserved so we cdannot rule that out.

What platform are you running this program on?

Re: display not outputting correct number of characters

PostPosted: Sat Apr 06, 2013 6:00 pm
by BillyBoyo
ideaone is a website with various "online" compilers and processors. The Cobol on the site is OpenCobol or TinyCobol.

I can't see anything wrong with the program, and enrico has run it.

It is either something with whichever compiler you chose to use, or with how you entered the data on the site.

You could download OpenCobol for yourself, and try it independently of the site. Depending on results, take it up with OpenCobol (at SourceForge) or ideone or with TinyCobol.

Re: display not outputting correct number of characters

PostPosted: Sat Apr 06, 2013 6:18 pm
by enrico-sorichetti
since I was curious,
my program as written does not compile on ideone.

getting
Error: syntax error, unexpected WORD, expecting '.'


I am just curious, and I do not speak COBOLESE
so my program could be just wrong in other ways ;)

Re: display not outputting correct number of characters

PostPosted: Sat Apr 06, 2013 6:56 pm
by Robert Sample
PROGRAM-ID needs a period after it before the program name. This is not an error in Enterprise COBOL, but ideaone thinks it is.

Re: display not outputting correct number of characters

PostPosted: Sat Apr 06, 2013 6:58 pm
by enrico-sorichetti
:oops:
thank You Robert

retested and it works also there.

Re: display not outputting correct number of characters

PostPosted: Sat Apr 06, 2013 7:05 pm
by c62ap90
Just for fun...
Change WS-TYPE from PIC X(02) to PIC X(03)
and see if the period gets displayed [I think it will ]

Re: display not outputting correct number of characters

PostPosted: Sat Apr 06, 2013 8:29 pm
by theju112
hi i tried changing pic x(02) to pic x(03)...then it printed D. but..thats not how it is supposed to be :) ...ill download open cobol and see..

Re: display not outputting correct number of characters

PostPosted: Sat Apr 06, 2013 9:28 pm
by Robert Sample
but..thats not how it is supposed to be
A big problem for beginning programmers is that they "know" what the results should be as opposed to what actually occurred. No matter what compiler you use, there should be a manual available for it. That manual will tell you what the results will be for any given expression in the language. You may think the result you got is not how it is supposed to be, but it is entirely likely that the results you got are what to expect from that compiler. As previously indicated, the results you got are NOT the results you would get by using the IBM Enterprise COBOL compiler on a mainframe, but there are differences between compilers. Using words like "supposed" or "should" are red flags and indicate you are projecting your desires onto the computer rather than accepting the results you got.