2
 IDENTIFICATION DIVISION.
 PROGRAM-ID. MP4-5.
 ENVIRONMENT DIVISION.
 DATA DIVISION.
 WORKING-STORAGE SECTION.

 01 SEAT-DESCRIPTION.
    03 FILLER PIC X(50) VALUE "01   DRIVER".
    03 FILLER PIC X(50) VALUE "02   DRIVER'S ASST".
    03 FILLER PIC X(50) VALUE "03".
    03 FILLER PIC X(50) VALUE "04".
    03 FILLER PIC X(50) VALUE "05".
    03 FILLER PIC X(50) VALUE "06".
    03 FILLER PIC X(50) VALUE "07".
    03 FILLER PIC X(50) VALUE "08".
    03 FILLER PIC X(50) VALUE "09".
    03 FILLER PIC X(50) VALUE "10".
    03 FILLER PIC X(50) VALUE "11".
    03 FILLER PIC X(50) VALUE "12".
    03 FILLER PIC X(50) VALUE "13".
    03 FILLER PIC X(50) VALUE "14".
    03 FILLER PIC X(50) VALUE "15".

 01 MAIN-MENU   PIC X.
   88 RESERVATION VALUE "R".
   88 VIEW-RESERVATION VALUE "V".
   88 CANCEL-RESERVATION VALUE "D".
   88 EXIT-PROC VALUE "E".

 01 DECISION PIC X.
   88 YES VALUE "Y".
   88 NAY VALUE "N".   

 01 SEAT-NUM PIC 9(2).

 01 CUST-NAME PIC X(18).

 01 CUST-CNTCT PIC 9(11).

 01 CHOICE PIC X.

PROCEDURE DIVISION.
MAIN-ROUTINE.

 DISPLAY "        ABC TRANSPORT COMPANY".
 DISPLAY "__________________________________________".
 DISPLAY "     [R] ADD RESERVATION/S ".
 DISPLAY "     [V] VIEW RESERVATION/S ".
 DISPLAY "     [D] CANCEL RESERVATION/S ".
 DISPLAY "     [E] EXIT".
 DISPLAY "         ENTER CHOICE: " WITH NO ADVANCING.

 ACCEPT MAIN-MENU.

 PERFORM I-CHAIN.

I-CHAIN.
 IF RESERVATION
    GO TO RESERVE-PROC
 ELSE IF VIEW-RESERVATION
    GO TO VRESERVE-PROC
 ELSE IF CANCEL-RESERVATION
    GO TO CRESERVE-PROC
 ELSE IF EXIT-PROC
    GO TO END-PGM
 ELSE
    DISPLAY "INVALID OPTION"

 GO TO MAIN-ROUTINE.


RESERVE-PROC.
 DISPLAY "RESERVE SEAT #:   "WITH NO ADVANCING.
 ACCEPT SEAT-NUM.

 IF SEAT-NUM IS NUMERIC
      IF SEAT-NUM >2 AND SEAT-NUM <16
      GO TO CONT-RES
      ELSE
             DISPLAY "INVALID OPTION"
             PERFORM RESERVE-PROC
 ELSE 
    DISPLAY "ENTER A NUMERIC VALUE"
    GO TO RESERVE-PROC.

CONT-RES.
 DISPLAY "CUSTOMER NAME :     "WITH NO ADVANCING.
 ACCEPT CUST-NAME.

 MOVE CUST-NAME TO SEAT-NUM.
 DISPLAY "CUSTOMER CONTACT #: "WITH NO ADVANCING.
 ACCEPT CUST-CNTCT.

 MOVE CUST-CNTCT TO SEAT-NUM.
 GO TO RESER-CONT.

RESER-CONT.
 DISPLAY "RESERVE MORE? [Y/N]? "WITH NO ADVANCING.
 ACCEPT DECISION.
 IF YES
     PERFORM RESERVE-PROC
 ELSE IF NAY
     PERFORM MAIN-ROUTINE
 ELSE
     DISPLAY "INVALID OPTION"
     PERFORM RESER-CONT.

VRESERVE-PROC.
 DISPLAY "        ABC TRANSPORT COMPANY".
 DISPLAY "           RESERVATION LIST".
 DISPLAY "__________________________________________".
 DISPLAY " "SEAT-DESCRIPTION.

CRESERVE-PROC.
 DISPLAY "        ABC TRANSPORT COMPANY".
 DISPLAY "         CANCEL RESERVATION".
 DISPLAY "__________________________________________".

END-PGM.
 STOP RUN.

I know the code is not complete yet but may I have some help on how to use tables because I'm having a hard time trying to display what I want to add to my variable SEAT-NUM and any tips for deleting a string 1 by 1 would be helpful

messivanio
  • 2,263
  • 18
  • 24

2 Answers2

2

To start you'd need something like

01 SEAT-DESCRIPTION-REDEF REDEFINES SEAT-DESCRIPTION.
   03 SEAT-NUMBER-DATA OCCURS 15.
      05 SEAT-NUMBER-TEXT   PIC X(02).
      05 FILLER             PIC X(04).
      05 SEAT-FILLED-BY     PIC X(44).

You can now assign a value to SEAT-FILLED-BY(SEAT-NUM) to assign a name to a seat.

It's not clear what you are doing with CUST-CNTCT but a small adjustment:

01 SEAT-DESCRIPTION-REDEF REDEFINES SEAT-DESCRIPTION.
   03 SEAT-NUMBER-DATA OCCURS 15.
      05 SEAT-NUMBER-TEXT   PIC X(02).
      05 FILLER             PIC X(04).
      05 SEAT-FILLED-BY     PIC X(32).
      05 FILLER             PIC X(01).
      05 SEAT-CONTACT       PIC X(11).

and now you can MOVE CUST-CNTCT TO SEAT-CONTACT(SEAT-NUM). which is probably close to what you want to do.

And now a little advertisement about structure.

ESCHEW GO TO.

It is NEVER necessary to use a GO TO. Always

PERFORM paragraphname [UNTIL condition].

It's not an easy discipline until you get used to it - and you'll get used to it when you have nightmares with spaghetti-code; GO TO s all over the place and PERFORM me invoking recursive code.

And if anyone ever mentions PERFORM THROUGH simply smile and nod and ignore everything they have to say. They are the epitome of evil for they are advocating layout-dependant code.

messivanio
  • 2,263
  • 18
  • 24
Magoo
  • 77,302
  • 8
  • 62
  • 84
  • @nano.galvao thanks a lot man I badly needed that now it all makes sense to that's what i'm having now as an output I keep on getting unnecessary lines thanks again – Karl laurenz Bagasan Dec 10 '13 at 22:32
  • 1
    I'll +1 back up Magoo as to the hazards of `GO TO`, but also disagree slightly. A +0.999. The sample listed here deserves the bolded ESCHEW, as it is not a practical use of jump. But, when writing state machines or single character protocol interpreters in COBOL, `GO TO DEPENDING ON` can be quite practical. When limited in scope and clean, even defensible. _Including the sub paragraph burden of a further_ `GO TO next-step-label` _required for every work segment_. So, yeah on the Never, _except maybe one Tuesday a year_, and be prepared to defend the gates from sticks, stones, and words. – Brian Tiffin Dec 11 '13 at 07:17
  • @KarllaurenzBagasan, Magoo did the work, nano.galvao only formatted it. – Bill Woodger Dec 13 '13 at 17:42
0

We use THROUGH in our shop, but for one purpose. We label each paragrah with a name and close that paragraph with that name with"-"EXIT" on the end.

Then when we call that paragraph we call it using the syntax

"PERFORM L2-SUB-PARAGRAPH THROUGH L2-SUB-PARAPGRAPH-EXIT.

That gives the code a more object oriented look and makes paragraphs more modular.

Or if want to loop through a paragraph you then can code it like this:

`PERFORM -L2-LOOPING-PARA' 
     'THROUGH L2-LOOPING-PARA-EXIT'
         'VARYING INDEX1 FROM 1 BY 1.... `
Learnin
  • 93
  • 1
  • 5
  • Think of how much easier and more object-oriented `PERFORM L2-SUB-PARAGRAPH` and `PERFORM -L2-LOOPING-PARAVARYING INDEX1 FROM 1 BY 1....` would be. No need for all those single-line paragraphs tempting the PhD student to just put in a little finalisation code. Much cleaner. It's a structure-compatibility hangover from the `PERFORM SECTION` days. Preserves verbosity and provides a security-blanket for managers rooted in the past. The only possible excuse for such a structure is `IF condition GO TO PARA-EXIT` but if you follow a Jacksonesque structure, then `IF noitidnoc PERFORM PARA-SUB` rules! – Magoo Dec 12 '13 at 23:28
  • This is a Q&A sites. `Answers` are for answers addressing the question which has been posed. I suggest you delete your `Answer` before anyone downvotes it or flags it for moderator attention. Same with your other one. If you have a comment to make on a question or an answer, then do it as a `Comment`, please. As to what you propose above, I would not encourage it, it is a *very* dated thing for COBOL. However, yes, there are always Site Standards. Does not mean it is a good thing to recommend generally. – Bill Woodger Dec 13 '13 at 16:43