Print multiple fields in a single line 6 times



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Print multiple fields in a single line 6 times

Postby Priqroe » Mon Mar 12, 2012 1:01 am

Hello I need help with my code. Basically i'd like to print a line with 3 fields 3 times on a line and then print the line 6 times with each line displaying different variables. Im using Net Express 5.1

Example:
DISC-NAME TOTALS
xxx xxxxxxxx 9999 xxx xxxxxxxx 9999 xxx xxxxxxxx 9999
xxx xxxxxxxx 9999 xxx xxxxxxxx 9999 xxx xxxxxxxx 9999

I want to print this fields 18 times in total on 6 lines because I have 18 different variables. I made a table for the DISC-NAME TOTALS and also for the printline. THis is my code.

01 WORKNG-AREA.
05 TABLE-SUB PIC 99 VALUE ZEROES.


01 DISC-TABLE-AREA.
05 FILLER PIC X(27) VALUE "01STAR VULCAN 1350".
05 FILLER PIC X(27) VALUE "02DX WEDGE 0899".
05 FILLER PIC X(27) VALUE "03NUKE ELITE-X 0899".
05 FILLER PIC X(27) VALUE "04P1 MANIAC P-LINE 0999".
05 FILLER PIC X(27) VALUE "05KATANA 0999".
05 FILLER PIC X(27) VALUE "06R-PRO WAHOO 1350".
05 FILLER PIC X(27) VALUE "07AVIAR YETI PRO 0899".
05 FILLER PIC X(27) VALUE "08ARCH ANGEL DX 1350".
05 FILLER PIC X(27) VALUE "09ASSASSIN EVOLUTION 0999".
05 FILLER PIC X(27) VALUE "10AVENGER PRO-D 1350".
05 FILLER PIC X(27) VALUE "11BANSHEE DX 0999".
05 FILLER PIC X(27) VALUE "12BOSS PRO 0899".
05 FILLER PIC X(27) VALUE "13BANGER GT PRO-D 1350".
05 FILLER PIC X(27) VALUE "14CROSSHAIR BASELINE 0999".
05 FILLER PIC X(27) VALUE "15DART DX 0899".
05 FILLER PIC X(27) VALUE "16FOCUS PRO-D 1350".
05 FILLER PIC X(27) VALUE "17JUJU SUPREME 0899".
05 FILLER PIC X(27) VALUE "18MAGIC (SOFT) S-SERIES1099".

01 DISC-TABLE REDEFINES DISC-TABLE-AREA.
05 DISC-DATA OCCURS 18 TIMES.
10 DISC-CODE PIC 99.
10 DISCNAME PIC X(21).
10 DISCPRICE PIC 99V99.


=====PRINTLINE
01 O-SALES-DETAILS.
05 SALES-DETAIL OCCURS 4 TIMES.
10 FILLER PIC XX VALUE SPACES.
10 O-GTDISCCODE1 PIC 99.
10 FILLER PIC XX VALUE SPACES.
10 O-GTDISCNAME1 PIC X(21).
10 FILLER PIC XX VALUE SPACES.
10 O-GTDISCSALES1 PIC $$,$$$.99.
10 FILLER PIC X(10) VALUE SPACES.

3000-TOTAL.
PERFORM 3100-GRANDTOTALS.
PERFORM 3200-DISCTOTALS

WRITE PRTLINE
FROM O-SALES-DETAILS
AFTER ADVANCING 4 LINE.
ADD 1 TO TABLE-SUB.

3200-DISCTOTALS.
MOVE 1 TO TABLE-SUB.
PERFORM 3210-CLR-DISCTOTAL

VARYING SUB FROM 1 BY 1
UNTIL SUB > 4.



3210-CLR-DISCTOTAL.

MOVE DISC-CODE(TABLE-SUB) TO O-GTDISCCODE1(SUB).
MOVE DISCNAME(TABLE-SUB) TO O-GTDISCNAME1(SUB).
MOVE C-DISCTOTSALES(TABLE-SUB) TO O-GTDISCSALES1(SUB).

ADD 1 TO TABLE-SUB.

This is how I want it to look like:

XX DISCNAME01 9999 XX DISCNAME02 9999 XX DISCNAME03 9999
XX DISCNAME04 9999 XX DISCNAME05 9999 XX DICSNAME06 9999
XX DISCNAME07 9999 XX DISCNAME08 9999 XX DISCNAME09 9999
XX DISCNAME10 9999 XX DISCNAME11 9999 XX DISCNAME12 9999
XX DISCNAME13 9999 XX DISCNAME14 9999 XX DISCNAME15 9999
XX DISCNAME16 9999 XX DISCNAME17 9999 XX DISCNAME18 9999

PLEASE HELP ME!
Priqroe
 
Posts: 3
Joined: Sat Mar 10, 2012 10:44 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Print multiple fields in a single line 6 times

Postby Robert Sample » Mon Mar 12, 2012 1:57 am

How come you have OCCURS 4 in your print line if you only want 3 occurrences? And why use SUB > 4 in your PERFORM if you only want 3 occurrences in your print line?

Furthermore, you did NOT post where you're having problems -- this is not a forum to write code for you, it is a forum to help you fix code problems you have. Since you did not post what your code is currently doing, just what you want it to look like, there's not much help we can give you -- especially since you posted that you want one thing (3 occurrences on a line) while your code is doing something totally different (4 occurrences on a line).
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Print multiple fields in a single line 6 times

Postby Priqroe » Mon Mar 12, 2012 2:12 am

Oops, sorry, this was the old code that i was working on so i forgot to change the occurrence to only 3. That should only 3 and not 4. And btw the problem is when I print this code, I will have the same variables for each line.

xx DISCNAME1 9999 XX DISCNAME2 9999 XX DISCNAME3 9999
xx DISCNAME1 9999 XX DISCNAME2 9999 XX DISCNAME3 9999
xx DISCNAME1 9999 XX DISCNAME2 9999 XX DISCNAME3 9999
xx DISCNAME1 9999 XX DISCNAME2 9999 XX DISCNAME3 9999
xx DISCNAME1 9999 XX DISCNAME2 9999 XX DISCNAME3 9999

So I dont really know how to print all 18 variables and their totals.
Priqroe
 
Posts: 3
Joined: Sat Mar 10, 2012 10:44 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Print multiple fields in a single line 6 times

Postby Priqroe » Mon Mar 12, 2012 2:19 am

I tried to print the 3200-disctotal module six times using the code below, since that's what ive been told to do and the result I got is the one I posted above ^.

This is my current write code:
PERFORM 3200-DISCTOTALS.
WRITE PRTLINE
FROM O-SALES-DETAILS
AFTER ADVANCING 4 LINE.


PERFORM 3200-DISCTOTALS.
WRITE PRTLINE
FROM O-SALES-DETAILS
AFTER ADVANCING 1 LINE.


PERFORM 3200-DISCTOTALS.
WRITE PRTLINE
FROM O-SALES-DETAILS
AFTER ADVANCING 1 LINE.

PERFORM 3200-DISCTOTALS.
WRITE PRTLINE
FROM O-SALES-DETAILS
AFTER ADVANCING 1 LINE.

PERFORM 3200-DISCTOTALS.
WRITE PRTLINE
FROM O-SALES-DETAILS
AFTER ADVANCING 1 LINE.



PERFORM 3200-DISCTOTALS.
WRITE PRTLINE
FROM O-SALES-DETAILS
AFTER ADVANCING 1 LINE.
Priqroe
 
Posts: 3
Joined: Sat Mar 10, 2012 10:44 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Print multiple fields in a single line 6 times

Postby Robert Sample » Mon Mar 12, 2012 4:33 am

You set TABLE-SUB to 1 in 3200-DISCTOTALS. Hence you're never going to see anything but the first three items of your table in the output line. You need to initialize TABLE-SUB before you do the first PERFORM 3200-DISCTOTALS for your first print line, not as part of 3200-DISCTOTALS.

Further, your supposed output does not match the table elements -- I don't see a DISCNAME1 (much less -2 or -3) anywhere in your table. If you're going to post something that you tell us is the output, then don't try to edit it -- since you're more likely to mess it up and confuse the issue than provide additional information. When we tell you we want to see output, we want to see what the compiled program is providing as output, not your interpretation of that output. Sometimes subtle things, like a single byte in a 132-byte line, can indicate where the problem is; if you're removed that byte as part of your editing then your problem can't get solved, can it?

And learn to use the Code tag to post code and computer output -- once you hit the Code button and paste something, the spacing is preserved (which can be important).
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Print multiple fields in a single line 6 times

Postby BillyBoyo » Mon Mar 12, 2012 4:39 am

What is Net Express 5.1? How does this relate to a Mainframe, and a Mainframe forum?

You are getting the same details each time because you are starting the subscript off from one each time you do the six performs. If you give the subscript a value of one before doing the performs, and then just leave it increasing, you will see different data.

In your table, your data does not match your definitions. Prices should all be in a fixed position.

If you are using a Mainframe somewhere along the way, please use the Code tags for any further posting. Goes like this:

MOVE +1                                                          TO W-DISC-TABLE-SUB


If you click on QUOTE, you'll see how it is done. Preserves the spacing. Format using the Preview button. When happy, submit. It helps everyone.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Print multiple fields in a single line 6 times

Postby BillyBoyo » Mon Mar 12, 2012 5:21 am

You also don't need six seperate performs like that. Just one, and do it six times.

You don't have any code for testing if the page is full, to do the headings.

You don't have any code for either a partial table or a partial line. Even if not in the exercise, it is good practice, because in real life tables and things are often not completely full.

To find your problem next time, get a listing of the program, a pencil, and work through the code for any loops/tables writing down the values of any subscripts/indexes as they change. You'll find it easy to spot where you went wrong. Keep doing it that way, until you can do it "in your head", which means you find that when you are writing the code, you think about those things without thinking.

Can be good to start with pseudo-code, before writing a line of your program. Work through the pseudo-code with a pencil in the same way. You'll save yourself a lot of time, and even more when you get to do it "in your head".

With the pseudo-code approach, you have logic which "works" before writing a line of code. A tendency for new starters is, having written the code, to patch-up bad stuff rather than deleting it an starting again. Makes your code more difficult to understand. On a Mainframe, you'll be working in a team. Once you've implemented your code you may never see it again, Or not for months. Make it easy on others, and yourself, by making the code as clear as possible, not a patched-up mess (which can be fine for college-work, where someone just wants the result, but doesn't cut it in this business).
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post