Page 1 of 3

Problem with WRITE AFTER ADVANCING

PostPosted: Wed Jun 22, 2011 12:28 pm
by ang
Hi all,

I try to write a report as shown below. However the program seems ignored the AFTER ADVANCING clause when I used it with WRITE statement. The space lines that I desired are not appeared in the report. However, when I used BEFORE instead of AFTER, the spacing is there but appear in whole report where after each print statement, there will be a line spacing regardless of the number of line I inserted in the statement. Any idea? Thanks.

Report format:
--- SPACE ---
-- --SPACE-- --HEADER-1-- --SPACE--- --
--- SPACE ---
-----------------SPACE---------------HEADER-2-----------------SPACE-------------

CODE:
WRITE report-1 FROM header-1
AFTER ADVANCING 1 LINE.
WRITE report-1 FROM header-2
AFTER ADVANCING 1 LINE.

Re: Problem with WRITE AFTER ADVANCING

PostPosted: Wed Jun 22, 2011 12:40 pm
by enrico-sorichetti
review Your understanding of printer control chars ...
the first position of the output buffer contains the control char
and the most common are ...
" " <== blank single space
"0" <== double space
"-" <=== triple space

the <thing> will appear with the proper spacing when printed
but when browsed under SDSF or if routed to a dataset You will see only THREE records

Re: Problem with WRITE AFTER ADVANCING

PostPosted: Wed Jun 22, 2011 12:55 pm
by ang
Thanks for your reply enrico. I do check with the solution in IBM website and followed the instruction but no luck. Well under DATA DIVISION, my report is defined as below. Any problem with that?

FD
REPORT-FILE
BLOCK CONTAINS 0 RECORD
LABEL RECORDS ARE STANDARD
RECORD CONTAINS 133 CHARACTER.

01 REPORT-REC.
03 PRT-CTR PIC X.
03 PRT-LINE PIC X(132).

WORKING-STORAGE SECTION.
01 HEADER-1.
03 FILLER PIC X.
03 FILLER PIC X(20) VALUE SPACES.
03 FILLER PIC X(05) VALUE 'HELLO'.
03 FILLER PIC X(117) VALUE SPACES.

Re: Problem with WRITE AFTER ADVANCING

PostPosted: Wed Jun 22, 2011 1:06 pm
by ang
BTW, why when I use BEFORE there will be line spacing even though it applies to whole report instead of only one print statement but not AFTER? I am wondering the problem is due to the declaration in JCL?

Thanks.

Re: Problem with WRITE AFTER ADVANCING

PostPosted: Wed Jun 22, 2011 1:22 pm
by BillyBoyo
Well, we can't tell about the JCL if we can't see it.

Re: Problem with WRITE AFTER ADVANCING

PostPosted: Wed Jun 22, 2011 9:05 pm
by Ed Goodman
For the file declaration you showed us, the JCL will need to be RECFM=FBA,LRECL=134. That is assuming you have the "ADV" compiler option selected. Check the top of the listing to see if it says "ADV" or "NOADV". With "ADV", the compiler adds one character at the beginning of every line if you use "after advancing" ANYWHERE in the program for that file. Even if you just use it once, like in the header routines.

Also, "after advancing 1 line" really means "go to the next line." It doesn't mean "skip an extra line before printing this."

I've never used "BEFORE" advancing, so I can't help you there. The manual says the only difference is that it does the x number of lines on top of the output instead of under it. So what you're reporting here does not sound like it should be happening. If you brought that problem to my desk, I'd double check to make SURE that the only difference between the two programs was the before/after. I'd recompile it both ways to make SURE the compiler options were the same. I'd print both of the reports out to make SURE the difference is really what you think it is. But that's all just healthy skepticism.

Re: Problem with WRITE AFTER ADVANCING

PostPosted: Wed Jun 22, 2011 9:15 pm
by enrico-sorichetti
But that's all just healthy skepticism.


Naahh... around here is just healthy self defense :D

Re: Problem with WRITE AFTER ADVANCING

PostPosted: Thu Jun 23, 2011 12:34 am
by Ed Goodman
no no no... I just know I've found myself in the trap of being CERTAIN something is wrong until someone else comes along and finds the real problem. It really is a trap that's easy to fall into.

Actually, the more advanced the person asking me is, the MORE likely it is that it's something simple they assumed. People who aren't sure will start from scratch, people who ARE sure will grab something they know is right without verifying it first.

In this case, I would suspect that the compiles are different somehow, or that the before/after change is more than that, or that the format of the report is being assumed (without actually printing it). Anything the person is CERTAIN of has to be checked.

My favorite was when a person that I KNOW is good came to me and said that "DFSORT has the wrong record count." We looked at the file and sure enough, the output of that job step had a different record count than the file actually contained. it turned out another job had updated that file with DISP=MOD after the sort step.

Re: Problem with WRITE AFTER ADVANCING

PostPosted: Thu Jun 23, 2011 5:48 am
by BillyBoyo
Welcome Ed. Nice to see some more experience here.

01 REPORT-REC.
03 PRT-CTR PIC X.
03 PRT-LINE PIC X(132).


I think here the TS has actually allowed for the print control character (PRT-CTR). Assumption would be they're using NOADV. So lrecl would be 133.

I can't understand what he is saying about the spacing, why he thinks BEFORE and AFTER would get substantially different results. Let's see if he's back tommorow.

Re: Problem with WRITE AFTER ADVANCING

PostPosted: Thu Jun 23, 2011 7:14 am
by ang
Hi all,

Thanks for the replies. Sorry if i caused you guys confuse as I only touched COBOL about 2 weeks.

Well in JCL, NOADV option is selected and RECFM=FB, so the record length should be 133, right? Actually, my program is very simple, get data from an input file then print result on output file. The task I am trying to do is, I want to print a Heading at the first line of the report, then the second line will be blanked, and the third line print another Heading.

So I coded as below:
WRITE report FROM heading-1.
WRITE report FROM heading-2
AFTER ADVANCING 1 LINE.

However, the report showed that the second line is not blank but continue print the second Heading even when I change the number of line to 2. Then, I change the code again to:
WRITE report FROM heading-1
BEFORE ADVANCING 1 LINE.
WRITE report FROM heading-2.

This time there is a blank line between Heading-1 and Heading-2 (first and third line), but there is a blank line between third and fifth line...which every even number line is a blank line. Then this problem really confusing me. I read the books, surf the net but seems no one faced the same problem as me and I thought the difference between BEFORE and AFTER just print the statement then space a blank line or space a blank line before print statement, isn't it?

Thanks.