0

I have some error in this program. When I compile, the Code show error like this

prak.cob: In paragraph 'isi-data-tabel':

prak.cob:34: Error: syntax error, unexpected '('

Please check code below, this is error in line 34:

 isi-data-tabel. 
       DISPLAY ( , ) 'cabang ', subscript-cabang, bulan ', subscript-bulan, ' : '.   
       ACCEPT ( , ) jumlah-unit-terjual (subscript-cabang, subscript-bulan).
       DISPLAY SPACE.

this full code


  IDENTIFICATION DIVISION.
   PROGRAM-ID. tabel2.
   ENVIRONMENT DIVISION.
   DATA DIVISION.
   WORKING-STORAGE SECTION.
   01  ws-subscript.
       02  subscript-cabang  PIC 9.
       02  subscript-bulan  PIC 9.
   01  tabel-penjualan-mobil.
       02  cabang  OCCURS 4 TIMES.
       03  bulan   OCCURS 3 TIMES.
           04 jumlah-unit-terjual PIC 99.
   77 total-penjualan-cabang PIC 99 VALUE 0. 
   SCREEN SECTION. 
   01 hapus-layar.
       02  BLANK SCREEN.
   PROCEDURE DIVISION.

  program-utama. 
       PERFORM entry-tabel. 
       PERFORM tampilkan-tabel. 
       STOP RUN.

  entry-tabel. 
       DISPLAY ' Pemasukan data ke dalam tabel dimensi dua: '. 
       PERFORM isi-data-tabel
       VARYING subscript-cabang FROM 1 BY 1 
       UNTIL subscript-cabang > 4
       AFTER subscript-bulan FROM 1 BY 1 
       UNTIL subscript-bulan > 3.

   isi-data-tabel. 
       DISPLAY ( , ) 'cabang ', subscript-cabang, bulan ', subscript-bulan, ' : '.   
       ACCEPT ( , ) jumlah-unit-terjual (subscript-cabang, subscript-bulan).
       DISPLAY SPACE.

   tampilkan-tabel. 
       DISPLAY hapus-layar. 
       DISPLAY ' Menampilkan isi tabel berdimensi dua : '.

       PERFORM display-data-tabel 
         VARYING subscript-cabang FROM 1 BY 1 
         UNTIL subscript-cabang > 4 
         AFTER subscript-bulan FROM 1 BY 1 
         UNTIL subscript-bulan > 3.

   display-data-tabel. 
         DISPLAY ( , ) 'cabang ', subscript-cabang,
              'bulan ', subscript-bulan, ' : ',
               jumlah-unit-terjual (subscript-cabang, subscript-bulan). 
         DISPLAY SPACE.
         ADD jumlah-unit-terjual (subscript-cabang, subscript-bulan) 
               TO total-penjualan-cabang.
         IF (subscript-bulan = 3) 
               DISPLAY '*** Total penjualan per cabang = ', total-penjualan-cabang.

         MOVE 0 TO total-penjualan-cabang.

I use OpenCOBOL 1.1.0 in Mac Environment as compiler.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • What version of cobol are you using ???, ( , ) does not look like standard cobol – Bruce Martin Oct 30 '13 at 22:03
  • OpenCOBOL 1.1.0 for Mac. I also, I don't know why "( , )" must pointed on code, this program given to us (students) from my college teacher. I try to search "( , )" function in DISPLAY and ACCEPT, but still i don't get any reference. have idea to fix that? or I must re-write the code... – agnanzakariya Oct 31 '13 at 04:46
  • There won't be more information on ( , ) for DISPLAY or ACCEPT, as that is not valid COBOL syntax. *Was this a fill in the blank piece of homework perhaps?* I'd drop the `DISPLAY hapus-layar` line as that will initialize extended display, which you don't want in this example. Add a missing quote for this code, `subscript-cabang, bulan '` and compile `cobc -x -free`. You'll be good to go. `*** Total penjualan per cabang = 67` was the last line output from a sample run. We run a Help Getting Started forum at http://sourceforge.net/p/open-cobol/discussion – Brian Tiffin Nov 01 '13 at 03:47

1 Answers1

2

I don't know what you think they would do, or if perhaps your particular COBOL supports something similar, but I've never come accross the "( , )" in DISPLAY or ACCEPT.

If you remove those, that particular type of error will be fixed.

You should update your question to include compiler name or vendor, and a Tag if available for that.

You also have a problem in display-data-tabel. You are adding to a total, but after testing if you want to display it, you are unconditionally setting it to zero. The MOVE 0 should be conditional, within the IF. Probably.

You'll get a much nicer program if you use scope-delmiters, like END-IF instead of periods/full-stops.

In response to your further information, you do have another problem in the DISPLAY:

DISPLAY ( , ) 'cabang ', subscript-cabang, bulan ', subscript-bulan, ' : '.

If you count the quote marks (') you'll find five. They should always be even. It looks like you want this:

DISPLAY 'cabang ', subscript-cabang, ' bulan ', subscript-bulan, ' : '.

or even this:

DISPLAY 'cabang ', subscript-cabang, ' bulan ', subscript-bulan, ' : '

or even this:

DISPLAY 'cabang ' subscript-cabang ' bulan ' subscript-bulan ' : '

All of that punctuation is optional. Means you don't need it. Means if you put it in, more to get wrong, more to look at, more to wonder about. It doesn't do any harm, but look how much "cleaner" the last is.

Even further, this is how I do it:

DISPLAY 
      'cabang' 
      '>' 
      subscript-cabang 
      '<' 
      'bulan' 
      '>' 
      subscript-bulan 
      '<' 

When I want to DISPLAY, I just paste any old DISPLAY statement and change the literals and data-names, and extend the number if necessary. The point of the ">" and "<" is to show exactly which bytes are part of the data (so you can pick trailing spaces, for instance). Save me a lot of time over the years.

Bill Woodger
  • 12,968
  • 4
  • 38
  • 47