Hi I am total beginner in cobol and need help in compiling this sendmail program.
I need to send a mail to SMTP domain using COBOL program on OpenVMS.
Can you please help me to fix this compilation error?
COBOl Program
identification division.
program-id. sendmail.
data division.
working-storage section.
01 stat pic s9(9) comp.
01 context pic 9(9) comp value 0.
01 null-item.
03 filler pic 9(4) comp value 0.
03 filler pic 9(4) comp value 0.
03 filler pic 9(9) comp value 0.
03 filler pic 9(9) comp value 0.
01 dummy-len pic 9(9) comp.
01 subject pic x(12) value 'test subject'.
01 subject-item.
03 subject-len pic 9(4) comp value 12.
03 filler pic 9(4) comp value external mail$_send_subject.
03 subject-addr pointer value reference subject.
03 filler pointer value reference dummy-len.
03 filler pic 9(9) comp value 0.
01 first_addressee pic x(64) value 'hein'.
01 second_addressee pic x(64) value 'heinvandenheuvel#xxx.yyy'.
01 addr-item.
03 addr-user-len pic 9(4) comp value 64.
03 filler pic 9(4) comp value external mail$_send_username.
03 addr-user-addr pointer value reference first_addressee.
03 filler pointer value reference dummy-len.
03 filler pic 9(9) comp value 0.
01 line1 pic x(6) value 'line 1'.
01 line2 pic x(6) value 'line 2'.
01 body-item.
03 body-file-len pic 9(4) comp value 6.
03 filler pic 9(4) comp value external mail$_send_record.
03 body-file-addr pointer value reference line1.
03 filler pointer value reference dummy-len.
03 filler pic 9(9) comp value 0.
procedure division.
main.
initialize context
call 'mail$send_begin' using context, null-item, null-item giving stat
if stat is failure
call 'lib$signal' using by value stat
else
call 'mail$send_add_attribute' using context, subject-item, null-item
giving stat
if stat is failure
call 'lib$signal' using by value stat
else
call 'mail$send_add_address' using context, addr-item, null-item
giving stat
if stat is failure
call 'lib$signal' using by value stat
end-if
set addr-user-addr to reference of second_addressee
call 'mail$send_add_address' using
context, addr-item, null-item
giving stat
if stat is failure
call 'lib$signal' using by value stat
else
call 'mail$send_add_bodypart' using
context, body-item, null-item
giving stat
if stat is failure
call 'lib$signal' using by value stat
else
set body-file-addr to reference of line2
call 'mail$send_add_bodypart' using
context, body-item, null-item
giving stat
if stat is failure
call 'lib$signal' using by value stat
else
call 'mail$send_message' using
context, null-item, null-item
giving stat
if stat is failure
call 'lib$signal' using by value stat
end-if
end-if
end-if
end-if
end-if
if stat is failure
call 'mail$send_abort' using context, null-item, null-item
giving stat
if stat is failure
call 'lib$signal' using by value stat
end-if
else
call 'mail$send_end' using context, null-item, null-item
giving stat
if stat is failure
call 'lib$signal' using by value stat
end-if
end-if
exit program.
Error during compilation
I%ILINK-W-NUDFSYMS, 3 undefined symbols:
%ILINK-I-UDFSYM, MAIL$_SEND_RECORD
%ILINK-I-UDFSYM, MAIL$_SEND_SUBJECT
%ILINK-I-UDFSYM, MAIL$_SEND_USERNAME
%ILINK-W-USEUNDEF, undefined symbol MAIL$_SEND_SUBJECT referenced
section: $LOCAL$
offset: %X000000000000003A
module: SENDMAIL
file: $DISK54:[DEVL.OHN.UH15]TENDMAIL.OBJ;3
%ILINK-W-USEUNDEF, undefined symbol MAIL$_SEND_USERNAME referenced
section: $LOCAL$
offset: %X00000000000000CA
module: SENDMAIL
file: $DISK54:[DEVL.OHN.UH15]TENDMAIL.OBJ;3
%ILINK-W-USEUNDEF, undefined symbol MAIL$_SEND_RECORD referenced
section: $LOCAL$
offset: %X00000000000000EA
module: SENDMAIL
file: $DISK54:[DEVL.OHN.UH15]TENDMAIL.OBJ;3
%ILINK-W-USEUNDEF, undefined symbol MAIL$_SEND_SUBJECT referenced
section: $LOCAL$
offset: %X0000000000000258
module: SENDMAIL
file: $DISK54:[DEVL.OHN.UH15]TENDMAIL.OBJ;3
%ILINK-W-USEUNDEF, undefined symbol MAIL$_SEND_USERNAME referenced
section: $LOCAL$
offset: %X0000000000000330
module: SENDMAIL
file: $DISK54:[DEVL.OHN.UH15]TENDMAIL.OBJ;3
%ILINK-W-USEUNDEF, undefined symbol MAIL$_SEND_RECORD referenced
section: $LOCAL$
offset: %X00000000000003D8
module: SENDMAIL
file: $DISK54:[DEVL.OHN.UH15]TENDMAIL.OBJ;3
$ set noverify
The Cobol program above requests the value for (mail) symbols to be provided externally by the linker.
You'd have to provide it the MAIL$ symbols for example by creating a helper module MAILDEF
For example:
$ cre maildef.mar
.TITLE MAILDEF
$MAILDEF GLOBAL
$MAILMSGDEF GLOBAL
.END
Exit
$ macr maildef
$ cob mail
$ link mail,maildef
Good luck,
Hein
Related
I'm trying to create a COBOL program using OpenCobol that has an external module when it does a calculation and then brings the result back into the main program using CALL. But everytime I try to run the program it says it can't find the module. I have already changed my module to Program Type "Module" from executable and I have added the module path as a Library path but nothing is working so far
Here is my main program code:
PROGRAM-ID. Project2 AS "Project2".
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
*****The student input file
SELECT STUDENT-FILE-IN
ASSIGN TO "C:\STUFILE.TXT"
ORGANIZATION IS LINE SEQUENTIAL.
*****The program input file
SELECT PROGRAM-FILE-IN
ASSIGN TO "C:\PROGRAM.TXT"
ORGANIZATION IS LINE SEQUENTIAL.
*****The student report output file
SELECT STUDENT-REPORT-FILE-OUT
ASSIGN TO "C:\REPORT.TXT"
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
*Student input file
FD STUDENT-FILE-IN.
01 STUDENT-RECORD.
05 STUDENT-NUMBER PIC 9(6).
05 TUITION-OWED-IN PIC 9(4)V99.
05 STUDENT-NAME-IN PIC X(40).
05 PROGRAM-OF-STUDY PIC X(5).
05 COURSE-CODE-1 PIC X(7).
05 COURSE-AVERAGE-1 PIC 9(3).
05 COURSE-CODE-2 PIC X(7).
05 COURSE-AVERAGE-2 PIC 9(3).
05 COURSE-CODE-3 PIC X(7).
05 COURSE-AVERAGE-3 PIC 9(3).
05 COURSE-CODE-4 PIC X(7).
05 COURSE-AVERAGE-4 PIC 9(3).
05 COURSE-CODE-5 PIC X(7).
05 COURSE-AVERAGE-5 PIC 9(3).
*Program input file
FD PROGRAM-FILE-IN.
01 PROGRAM-RECORD-IN.
05 PROGRAM-CODE-IN PIC X(5).
05 PROGRAM-NAME-IN PIC X(20).
*Student report output file
FD STUDENT-REPORT-FILE-OUT.
01 STUDENT-REPORT-RECORD-OUT PIC x(90).
WORKING-STORAGE SECTION.
*Table to hold program records
01 PROGRAM-RECORD.
05 PROGRAM-TABLE.
10 PROGRAM-CODE PIC X(5) OCCURS 20 TIMES.
10 PROGRAM-NAME PIC X(20) OCCURS 20 TIMES.
*The student report record
01 STUDENT-REPORT-RECORD.
05 STUDENT-NAME PIC X(40).
05 FILLER PIC X(2) VALUE SPACES.
05 PROGRAM-NAME-OUT PIC X(20).
05 FILLER PIC X(4) VALUE SPACES.
05 TUITION-OWED PIC Z,ZZ9.99.
*A line to make the output look good
01 HEADER-LINE.
05 FILLER PIC X(90) VALUE ALL "-".
*The column header
01 COLUMN-HEADER.
05 NAME-COLUMN PIC X(42) VALUE "NAME".
05 AVG-COLUMN PIC X(7) VALUE "AVE".
05 PROG-COLUMN PIC X(24) VALUE "PROGRAM NAME".
05 OWED-COLUMN PIC X(12) VALUE "TUITION OWED".
01 CONTROL-FIELDS.
05 STUFILE-EOF-FLAG PIC A(3).
05 PROG-EOF-FLAG PIC A(3).
05 PROG-SUB PIC 9(2).
05 FOUND-PROG-FLAG PIC A(3).
01 COUNTERS.
05 STUDENT-RECORDS-READ-CTR PIC 9(3).
05 STUDENT-REPORTS-WRITTEN-CTR PIC 9(3).
01 WW-SEND-AREA.
05 STUDENT-AVERAGE PIC 9(3).
01 WW-SUB-PROG PIC X(75)
VALUE 'C:\Users\google\Program3Call'.
PROCEDURE DIVISION.
PERFORM 200-INITIALIZATION-RTN.
*Read and process all student records
PERFORM 200-PROCESS-STUDENT-RECORD-RTN
UNTIL STUFILE-EOF-FLAG = "YES".
PERFORM 200-FINISH-RTN.
STOP RUN.
200-INITIALIZATION-RTN.
PERFORM 300-OPEN-FILES-RTN.
*****Load all program records into the table
PERFORM 300-LOAD-PROGRAM-TABLE-RTN
VARYING PROG-SUB FROM 1 BY 1
UNTIL PROG-SUB > 20 OR PROG-EOF-FLAG = "YES".
PERFORM 300-INITIALIZE-REPORT-FILE-RTN.
PERFORM 300-INITIALIZE-COUNTERS-RTN.
200-PROCESS-STUDENT-RECORD-RTN.
PERFORM 300-READ-STUDENT-RECORD-RTN.
IF STUFILE-EOF-FLAG NOT EQUALS "YES"
*********Get the program name
PERFORM 300-GET-PROGRAM-NAME-RTN
VARYING PROG-SUB FROM 1 BY 1 UNTIL
FOUND-PROG-FLAG = "YES" OR PROG-SUB > 20
PERFORM 300-GET-STUDENT-AVERAGE
PERFORM 300-PRINT-STUDENT-REPORT-RTN
END-IF.
200-FINISH-RTN.
PERFORM 300-PRINT-COUNTERS-RTN.
PERFORM 300-CLOSE-FILES-RTN.
300-OPEN-FILES-RTN.
OPEN INPUT STUDENT-FILE-IN.
OPEN INPUT PROGRAM-FILE-IN.
OPEN OUTPUT STUDENT-REPORT-FILE-OUT.
300-LOAD-PROGRAM-TABLE-RTN.
READ PROGRAM-FILE-IN
AT END MOVE "YES" TO PROG-EOF-FLAG
NOT AT END MOVE PROGRAM-CODE-IN TO PROGRAM-CODE (PROG-SUB)
MOVE PROGRAM-NAME-IN TO PROGRAM-NAME (PROG-SUB).
300-INITIALIZE-REPORT-FILE-RTN.
MOVE COLUMN-HEADER TO STUDENT-REPORT-RECORD-OUT.
WRITE STUDENT-REPORT-RECORD-OUT.
MOVE HEADER-LINE TO STUDENT-REPORT-RECORD-OUT.
WRITE STUDENT-REPORT-RECORD-OUT.
300-INITIALIZE-COUNTERS-RTN.
MOVE 0 TO STUDENT-RECORDS-READ-CTR.
MOVE 0 TO STUDENT-REPORTS-WRITTEN-CTR.
300-READ-STUDENT-RECORD-RTN.
READ STUDENT-FILE-IN
AT END MOVE "YES" TO STUFILE-EOF-FLAG
NOT AT END ADD 1 TO STUDENT-RECORDS-READ-CTR.
300-GET-PROGRAM-NAME-RTN.
IF PROGRAM-CODE (PROG-SUB) = PROGRAM-OF-STUDY
MOVE PROGRAM-NAME (PROG-SUB) TO PROGRAM-NAME-OUT
MOVE "YES" TO FOUND-PROG-FLAG
END-IF.
300-GET-STUDENT-AVERAGE.
CALL WW-SUB-PROG USING WW-SEND-AREA.
300-PRINT-STUDENT-REPORT-RTN.
MOVE "NO" TO FOUND-PROG-FLAG.
MOVE STUDENT-NAME-IN TO STUDENT-NAME.
MOVE TUITION-OWED-IN TO TUITION-OWED.
MOVE STUDENT-REPORT-RECORD TO STUDENT-REPORT-RECORD-OUT.
WRITE STUDENT-REPORT-RECORD-OUT.
ADD 1 TO STUDENT-REPORTS-WRITTEN-CTR.
300-PRINT-COUNTERS-RTN.
DISPLAY "Student records read: ", STUDENT-RECORDS-READ-CTR.
DISPLAY "Student reports written: ",
STUDENT-REPORTS-WRITTEN-CTR.
300-CLOSE-FILES-RTN.
CLOSE STUDENT-FILE-IN, PROGRAM-FILE-IN
STUDENT-REPORT-FILE-OUT.
END PROGRAM Project2.
Here is my Call Program:
******************************************************************
* Author: Desiree Hanuman
* Date: August 14th 2021
* Purpose:Call Section code for project 3
* Tectonics: cobc
******************************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID. Program3Call.
DATA DIVISION.
LINKAGE SECTION.
01 LS-STUDENT-AVERAGE-AREA.
05 COURSE-AVERAGE-1 PIC 9(3).
05 COURSE-AVERAGE-2 PIC 9(3).
05 COURSE-AVERAGE-3 PIC 9(3).
05 COURSE-AVERAGE-4 PIC 9(3).
05 COURSE-AVERAGE-5 PIC 9(3).
05 STUDENT-AVERAGE PIC 9(3).
PROCEDURE DIVISION.
MAIN-PROCEDURE.
100-STUDENT-AVERAGE.
PERFORM 300-CALCULATE-AVERAGE-RTN.
300-CALCULATE-AVERAGE-RTN.
COMPUTE STUDENT-AVERAGE ROUNDED = (COURSE-AVERAGE-1 +
COURSE-AVERAGE-2 + COURSE-AVERAGE-3 + COURSE-AVERAGE-4 +
COURSE-AVERAGE-5) / 5.
GOBACK.
The normal way to CALL in most COBOL implementations is to just specify the module name - without a path or extension.
Then you either do "static linking" (as in Scott's answer below for OpenCOBOL/GnuCOBOL just specify all sources on the command line and use either -x [fat executable] or -b [fat module, then callable for example with cobcrun], commonly with -static); or do "dynamic linking" (separate compilation of all modules) and specify the module path in a configuration file or by environment variable. For OpenCOBOL/GnuCOBOL this is COB_LIBRARY_PATH.
I am not a user of OpenCobol, but, according to their manual in section 7, there are many ways to accomplish what you want.
But the simplest would be to statically compile and link the main and sub programs in one command line:
cobc -x Project2.cbl Program3Call.cbl
This example work´s for me.
Please keep in mind that the name of the dll file routine module must be same as the routine name.
It is not necessary reconfigure OpenCobol path library.
I use OpenCobol 4.7.6.
The Code:
Main program (file build "MAINPROG.exe")
IDENTIFICATION DIVISION.
PROGRAM-ID. "MAINPROG".
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 X PIC X(1).
01 INPUTS.
05 PRM-LENGTH PIC S9(4) COMP.
05 INPUT1 PIC 9(2).
05 INPUT2 PIC 9(2).
PROCEDURE DIVISION.
MAIN-PARA.
MOVE 12 TO INPUT1.
MOVE 13 TO INPUT2.
CALL 'MFPROG1' USING PRM-LENGTH, INPUT1, INPUT2.
ACCEPT X.
STOP RUN.
END PROGRAM "MAINPROG".
Rutine program (file build module "MFPROG1.dll")
IDENTIFICATION DIVISION.
PROGRAM-ID. "MFPROG1".
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 OUTPUT-DATA PIC 9(4).
LINKAGE SECTION.
01 PARM-BUFFER.
05 PARM-LENGTH PIC S9(4) COMP.
05 PARM-INPUT1 PIC 9(2).
05 PARM-INPUT2 PIC 9(2).
PROCEDURE DIVISION USING PARM-BUFFER.
MAIN-PARA.
COMPUTE OUTPUT-DATA = PARM-INPUT1 + PARM-INPUT2.
DISPLAY 'PARM-INPUT1: ' PARM-INPUT1.
DISPLAY 'PARM-INPUT2: ' PARM-INPUT2.
DISPLAY 'SUM VALUE : ' OUTPUT-DATA.
GOBACK.
END PROGRAM "MFPROG1".
I have a very simple COBOL code here that has a given input data and output data. The problem is that, it shows an error on line 60 which is the MOVE STUD-AGE TO AGE-OUT. and everytime I run OpenCOBOLIDE, I always get and error which is:
libcob: test.cob: 60: 'STUD-AGE' not numeric: ' '
WARNING - Implicit CLOSE of STUDENT-OUT ('C:\STUD-OUT.DAT')
WARNING - Implicit CLOSE of STUDENT-IN ('C:\STUD-IN.DAT')
And I don't know exactly what's wrong with it. Here is supposedly the input file I created:
----5---10---15---20---25---30---35---40--
00-123345 ALISON MARTIN WOLF 1912056
00-789012 KEN DENNIOS ROME 1914156
00-345678 JACK ADRIAN TOCKSIN 1622234
00-901234 EJHAYZ ALONEY 2045645
00-567890 CHARLES JOHN GUINNIVER 1813243
00-123457 JEAN MICHAEL YARTER 2034253
Here's the code to it:
IDENTIFICATION DIVISION.
PROGRAM-ID. SAMPLE.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT STUDENT-IN ASSIGN TO "C:\STUD-IN.DAT".
SELECT STUDENT-OUT ASSIGN TO "C:\STUD-OUT.DAT".
DATA DIVISION.
FILE SECTION.
FD STUDENT-IN.
01 STUD-REC.
02 STUD-NO PIC X(10).
02 STUD-NAME PIC X(25).
02 STUD-AGE PIC 99.
02 STUD-ALLOWANCE PIC 999V99.
FD STUDENT-OUT.
01 PRINT-REC PIC X(80).
WORKING-STORAGE SECTION.
01 HDG-1.
02 FILLER PIC X(20) VALUE SPACES.
02 FILLER PIC X(22) VALUE "WILLOW PARK UNIVERSITY".
02 FILLER PIC X(14) VALUE " OF MADAGASCAR".
01 HDG-2.
02 FILLER PIC X(9) VALUE SPACES.
02 FILLER PIC X(14) VALUE "STUDENT NUMBER".
02 FILLER PIC X(8) VALUE SPACES.
02 FILLER PIC X(12) VALUE "STUDENT NAME".
02 FILLER PIC X(15) VALUE SPACES.
02 FILLER PIC X(3) VALUE "AGE".
02 FILLER PIC X(8) VALUE SPACES.
02 FILLER PIC X(9) VALUE "ALLOWANCE".
01 PRINT-LINE.
02 FILLER PIC X(9) VALUE SPACES.
02 SNO-OUT PIC X(10).
02 FILLER PIC X(12) VALUE SPACES.
02 SNAME-OUT PIC X(25).
02 FILLER PIC X(2) VALUE SPACE.
02 AGE-OUT PIC Z9.
02 FILLER PIC X(9) VALUE SPACES.
02 ALL-OUT PIC ZZZ.99.
01 E-O-F PIC XXX VALUE "NO".
PROCEDURE DIVISION.
OPEN INPUT STUDENT-IN
OUTPUT STUDENT-OUT.
WRITE PRINT-REC FROM HDG-1 BEFORE 1 LINE.
WRITE PRINT-REC FROM HDG-2 AFTER 2 LINES.
MOVE SPACES TO PRINT-REC.
WRITE PRINT-REC AFTER 1 LINE.
PERFORM READ-RTN UNTIL E-O-F = "YES".
PERFORM CLOSE-RTN.
READ-RTN.
READ STUDENT-IN AT END MOVE "YES" TO E-O-F.
MOVE STUD-NO TO SNO-OUT.
MOVE STUD-NAME TO SNAME-OUT.
MOVE STUD-AGE TO AGE-OUT.
MOVE STUD-ALLOWANCE TO ALL-OUT.
WRITE PRINT-REC FROM PRINT-LINE AFTER 1 LINE.
CLOSE-RTN.
CLOSE STUDENT-IN, STUDENT-OUT.
STOP RUN.
What I want to achieve is just to output the file correctly but the error only inputs the HDG-1 and then the rest blank.
To answer your question: COBOL accept numeric data however you define it.
So for "text data" (as long as it isn't UTF-16 or another multibyte encoded file) PIC 99 (which says "two digits in the default USAGE DISPLAY - so one byte per digit) is perfectly fine.
As with every other language: "never trust input data" is something I can recommend. For example: someone could run this program with a file that was saved with an UTF-8 encoded character in the name and then it "looks" right but the code has an unexpected shift in its data. For COBOL things like FUNCTION TEST-NUMVAL(inp) [ignores spaces and allows decimal-point] or IS NUMERIC (strict class test) can be useful.
Using data-check you could for example also skip empty lines or leading/trailing extra data (temporary rulers, headline, summary, ...).
For the actual problem:
It looks like you feed the program with a "common" text file, but you actually did not specify this so your COBOL implementation uses the default SEQUENTIAL. Because of the missing check of the input data you did not spot this directly.
To align expectations and code:
SELECT STUDENT-IN ASSIGN TO "C:\STUD-IN.DAT"
ORGANIZATION IS LINE SEQUENTIAL.
SELECT STUDENT-OUT ASSIGN TO "C:\STUD-OUT.DAT"
ORGANIZATION IS LINE SEQUENTIAL.
Installed GnuCOBOL version 3.0-rc1.0 to try out the recent Report Writer additions.
Attempting to compile the first listing [with the PIC X(52) being a fix by me to the too-small PIC X(51) in the book] in Chapter 18 of Beginning COBOL for Programmers by Michael Coughlan throws the errors:
Listing18-1.cbl:99: error: syntax error, unexpected IS, expecting LEADING or TRAILING
Listing18-1.cbl:99: error: PROCEDURE DIVISION header missing
Listing18-1.cbl:99: error: syntax error, unexpected .
Listing18-1.cbl:100: error: unknown statement '03'
Listing18-1.cbl:101: error: unknown statement '03'
Listing18-1.cbl:102: error: unknown statement '03'
Listing18-1.cbl:104: error: unknown statement '02'
Listing18-1.cbl:105: error: unknown statement '03'
Listing18-1.cbl:106: error: unknown statement '03'
Listing18-1.cbl:107: error: unknown statement '03'
Listing18-1.cbl:109: error: unknown statement '01'
Listing18-1.cbl:110: error: unknown statement '02'
Listing18-1.cbl:111: error: unknown statement '03'
Listing18-1.cbl:112: error: unknown statement '03'
Listing18-1.cbl:113: error: unknown statement '03'
Listing18-1.cbl:115: error: unknown statement '01'
Listing18-1.cbl:117: error: unknown statement '02'
Listing18-1.cbl:118: error: unknown statement '03'
Listing18-1.cbl:119: error: unknown statement '03'
Listing18-1.cbl:120: error: unknown statement '03'
Listing18-1.cbl:121: error: unknown statement '03'
Listing18-1.cbl:123: error: unknown statement '01'
Listing18-1.cbl:124: error: unknown statement '02'
Listing18-1.cbl:125: error: unknown statement '03'
Listing18-1.cbl:127: error: unknown statement '01'
Listing18-1.cbl:128: error: unknown statement '02'
Listing18-1.cbl:129: error: unknown statement '03'
Listing18-1.cbl:130: error: unknown statement '03'
Listing18-1.cbl:131: error: unknown statement '03'
Listing18-1.cbl:133: error: syntax error, unexpected PROCEDURE
Listing18-1.cbl: in paragraph 'PrintSalaryReport':
Listing18-1.cbl:153: error: 'DetailLine' is not defined
I think the first error reported may be the real problem, with the others being a knock-on effect.
Here is the complete program listing:
IDENTIFICATION DIVISION.
PROGRAM-ID. Listing18-1.
AUTHOR. Michael Coughlan.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT SalesFile ASSIGN TO "Listing18-1-Sales.DAT"
ORGANIZATION IS LINE SEQUENTIAL.
SELECT PrintFile ASSIGN TO "Listing18-1.Rpt".
DATA DIVISION.
FILE SECTION.
FD SalesFile.
01 SalesRecord.
88 EndOfFile VALUE HIGH-VALUES.
02 StateNum PIC 99.
02 SalesAgentNum PIC 999.
02 ValueOfSale PIC 9(5)V99.
FD PrintFile
REPORT IS SolaceSalesReport.
WORKING-STORAGE SECTION.
01 StateNameTable.
02 StateNameValues.
03 FILLER PIC X(14) VALUE "Alabama".
03 FILLER PIC X(14) VALUE "Alaska".
03 FILLER PIC X(14) VALUE "Arizona".
03 FILLER PIC X(14) VALUE "Arkansas".
03 FILLER PIC X(14) VALUE "California".
03 FILLER PIC X(14) VALUE "Colorado".
03 FILLER PIC X(14) VALUE "Connecticut".
03 FILLER PIC X(14) VALUE "Delaware".
03 FILLER PIC X(14) VALUE "Florida".
03 FILLER PIC X(14) VALUE "Georgia".
03 FILLER PIC X(14) VALUE "Hawaii".
03 FILLER PIC X(14) VALUE "Idaho".
03 FILLER PIC X(14) VALUE "Illinois".
03 FILLER PIC X(14) VALUE "Indiana".
03 FILLER PIC X(14) VALUE "Iowa".
03 FILLER PIC X(14) VALUE "Kansas".
03 FILLER PIC X(14) VALUE "Kentucky".
03 FILLER PIC X(14) VALUE "Louisiana".
03 FILLER PIC X(14) VALUE "Maine".
03 FILLER PIC X(14) VALUE "Maryland".
03 FILLER PIC X(14) VALUE "Massachusetts".
03 FILLER PIC X(14) VALUE "Michigan".
03 FILLER PIC X(14) VALUE "Minnesota".
03 FILLER PIC X(14) VALUE "Mississippi".
03 FILLER PIC X(14) VALUE "Missouri".
03 FILLER PIC X(14) VALUE "Montana".
03 FILLER PIC X(14) VALUE "Nebraska".
03 FILLER PIC X(14) VALUE "Nevada".
03 FILLER PIC X(14) VALUE "New Hampshire".
03 FILLER PIC X(14) VALUE "New Jersey".
03 FILLER PIC X(14) VALUE "New Mexico".
03 FILLER PIC X(14) VALUE "New York".
03 FILLER PIC X(14) VALUE "North Carolina".
03 FILLER PIC X(14) VALUE "North Dakota".
03 FILLER PIC X(14) VALUE "Ohio".
03 FILLER PIC X(14) VALUE "Oklahoma".
03 FILLER PIC X(14) VALUE "Oregon".
03 FILLER PIC X(14) VALUE "Pennsylvania".
03 FILLER PIC X(14) VALUE "Rhode Island".
03 FILLER PIC X(14) VALUE "South Carolina".
03 FILLER PIC X(14) VALUE "South Dakota".
03 FILLER PIC X(14) VALUE "Tennessee".
03 FILLER PIC X(14) VALUE "Texas".
03 FILLER PIC X(14) VALUE "Utah".
03 FILLER PIC X(14) VALUE "Vermont".
03 FILLER PIC X(14) VALUE "Virginia".
03 FILLER PIC X(14) VALUE "Washington".
03 FILLER PIC X(14) VALUE "West Virginia".
03 FILLER PIC X(14) VALUE "Wisconsin".
03 FILLER PIC X(14) VALUE "Wyoming".
02 FILLER REDEFINES StateNameValues.
03 State OCCURS 50 TIMES.
04 StateName PIC X(14).
REPORT SECTION.
RD SolaceSalesReport
CONTROLS ARE StateNum
SalesAgentNum
PAGE LIMIT IS 54
FIRST DETAIL 3
LAST DETAIL 46
FOOTING 48.
01 TYPE IS REPORT HEADING NEXT GROUP PLUS 1.
02 LINE 1.
03 COLUMN 20 PIC X(32) VALUE "Solace Solar Solutions".
02 LINE 2.
03 COLUMN 6 PIC X(52) VALUE "Sales Agent - Sales and Salary Report Monthly Report".
01 TYPE IS PAGE HEADING.
02 LINE IS PLUS 1.
03 COLUMN 2 PIC X(5) VALUE "State".
03 COLUMN 16 PIC X(5) VALUE "Agent".
03 COLUMN 32 PIC X(8) VALUE "Value".
02 LINE IS PLUS 1.
03 COLUMN 2 PIC X(4) VALUE "Name".
03 COLUMN 16 PIC X(6) VALUE "Number".
03 COLUMN 31 PIC X(8) VALUE "Of Sales".
01 DetailLine TYPE IS DETAIL.
02 LINE IS PLUS 1.
03 COLUMN 1 PIC X(14) SOURCE StateName(StateNum).
03 COLUMN 17 PIC ZZ9 SOURCE SalesAgentNum.
03 COLUMN 30 PIC $$$,$$$.99 SOURCE ValueOfSale.
01 SalesAgentGrp
TYPE IS CONTROL FOOTING SalesAgentNum NEXT GROUP PLUS 2.
02 LINE IS PLUS 1.
03 COLUMN 15 PIC X(21) VALUE "Sales for sales agent".
03 COLUMN 37 PIC ZZ9 SOURCE SalesAgentNum.
03 COLUMN 43 PIC X VALUE "=".
03 TotalAgentSales COLUMN 45 PIC $$$$$,$$$.99 SUM ValueOfSale.
01 StateGrp TYPE IS CONTROL FOOTING StateNum NEXT GROUP PLUS 2.
02 LINE IS PLUS 1.
03 COLUMN 1 PIC X(58) VALUE ALL "-".
01 TYPE IS PAGE FOOTING.
02 LINE IS 49.
03 COLUMN 1 PIC X(29) VALUE "Programmer - Michael Coughlan".
03 COLUMN 55 PIC X(6) VALUE "Page :".
03 COLUMN 62 PIC ZZ9 SOURCE PAGE-COUNTER.
PROCEDURE DIVISION.
Begin.
OPEN INPUT SalesFile
OPEN OUTPUT PrintFile
READ SalesFile
AT END SET EndOfFile TO TRUE
END-READ
INITIATE SolaceSalesReport
PERFORM PrintSalaryReport UNTIL EndOfFile
TERMINATE SolaceSalesReport
CLOSE SalesFile, PrintFile
STOP RUN.
PrintSalaryReport.
GENERATE DetailLine
READ SalesFile
AT END SET EndOfFile TO TRUE
END-READ.
I get the same problem on 3 different machines: a 64-bit desktop running Mint Cinnamon, a 64-bit laptop running Ubuntu, and an old 32-bit Netbook running Lubuntu.
I think the first error reported may be the real problem, with the others being a knock-on effect.
Yes, that's exactly the case.
GnuCOBOL 3.0-rc-1 does not support LINE IS PLUS - either adjust to LINE PLUS or update to a 3.1 version available as release.
To query the current version of GnuCOBOL use cobc --version (or the short cobc -V <-upper case).
I'm trying to create a report for a given input file where I am supposed to ill examine each record to determine if it fails to meet certain criteria. The issue that I am facing now is that the cob file wont compile eventhough it doesn't explicitly show any errors when compiling it on the command window and the executable doesn't get created. I was wondering if any of you could help me figure out where the error lies in my code.
Identification Division.
Program-ID. lab5.
Environment Division.
Input-Output Section.
File-Control.
Select PayrollFile
Assign to "lab5-in.dat"
Organization is Line Sequential.
Select OutputReport
Assign to "lab5-out.dat"
Organization is Line Sequential.
Data Division.
File Section.
FD PayrollFile.
01 Input-Rec.
05 Rec-RegionNum Pic X(2).
05 Rec-RegionName Pic X(15).
05 Rec-DeptNum Pic X(5).
05 Rec-DeptName Pic X(30).
05 Rec-EmployeeNum Pic X(5).
05 Rec-LastName Pic X(20).
05 Rec-FirstName Pic X(15).
05 Rec-Gender Pic X.
05 Rec-Address Pic X(20).
05 Rec-CityState Pic X(20).
05 Rec-Title Pic X(20).
05 Rec-DOB Pic 9(8).
05 Rec-DOH.
10 RecDOH-YYYY Pic 9(4).
10 RecDOH-MM Pic 9(2).
10 RecDOH-DD Pic 9(2).
05 Rec-Marital Pic X.
05 Rec-Deps Pic 99.
05 Rec-SD Pic X(3).
05 Rec-Ins Pic X(3).
05 Rec-401k Pic V999.
05 Rec-PayCode Pic X.
05 Rec-Pay Pic 9(7)V9(2).
05 Rec-HrsPerWeek Pic 9(2)V9(2).
05 Rec-CommissionRate Pic V999.
05 Rec-ActualSales Pic 9(7)V9(2).
FD OutputReport.
01 Output-Rec Pic X(210).
Working-Storage Section.
01 WS-EmployeeNum Pic X(5).
01 WS-DeptName Pic X(30).
01 WS-Gender Pic X.
88 ValidGender Values "M" "m" "F" "f".
01 WS-Marital Pic X.
88 ValidMarital Values "D" "d" "M" "m" "P" "p" "S" "s" "W"
"w".
01 WS-PayCode Pic X.
88 ValidPayCode Values "C" "c" "H" "h" "S" "s".
01 WS-HrsPerWeek Pic S9(2)V9(2).
01 WS-Pay Pic S9(7)V9(2).
01 WS-DOH.
10 DOH-YYYY Pic 9(4).
10 DOH-MM Pic 9(2).
10 DOH-DD Pic 9(2).
01 WS-SD Pic X(3).
01 WS-Date.
05 WS-YYYY Pic 9(4).
05 WS-MM Pic 9(2).
05 WS-DD Pic 9(2).
01 EndOfFileIndicator Pic X.
88 EOF Value "Y" When Set To False is "N".
01 Total-Line.
05 Pic X(25) Value "Total errors: ".
05 TL-TotalE Pic ZZ9.
01 TotalRE-Line.
05 Pic X(50) Value "Total record with errors: ".
05 TL-TotalRE Pic ZZ9.
01 TotError Pic 9(3).
01 TotRecordError Pic 9(3).
01 CurrentRec Pic X(208).
01 Blank-Line Pic X Value Spaces.
01 Report-Fields.
05 PageNumber Pic 99 Value 0.
05 LinesPerPage Pic 99 Value 35.
05 LineNumber Pic 99 Value 99.
Procedure Division.
000-MAIN.
Perform 100-initialize
Perform until EOF
Read PayrollFile
At End
Set EOF to True
not at end
perform 300-process
End-read
End-perform
Perform 900-finalize
Close PayrollFile OutputReport
Stop Run.
100-initialize.
Perform 110-open-files
Move Zero to TotError
Move Zero to TotRecordError.
110-open-files.
Open Input PayrollFile
Open Output OutputReport.
300-Process.
Move Input-Rec to CurrentRec
Move Rec-EmployeeNum to WS-EmployeeNum
Move Rec-DeptName to WS-DeptName
Move Rec-Gender to WS-Gender
Move Rec-Marital to WS-Marital
Move Rec-PayCode to WS-PayCode
Move Rec-HrsPerWeek to WS-HrsPerWeek
Move Rec-Pay to WS-Pay
Move Rec-DOH to WS-DOH
Perform 400-check.
400-check.
If WS-EmployeeNum is Not Numeric
Add 1 to TotError TotRecordError
End-If
If WS-DeptName Is Not Alphabetic
Add 1 to TotError TotRecordError
End-If
If Not ValidGender
Add 1 to TotError TotRecordError
End-If
If Not ValidMarital
Add 1 to TotError TotRecordError
End-If
If Not ValidPayCode
Add 1 to TotError TotRecordError
End-If
If WS-HrsPerWeek Is Negative And >= 60
Add 2 to TotError
Add 1 to TotRecordError
End-If
If WS-HrsPerWeek Is Negative Or >=60
Add 1 to TotError TotRecordError
End-If
If WS-Pay Is Not Numeric and Is Negative
Add 2 to TotError
Add 1 to TotRecordError
End-If
If WS-Pay Is Negative Or Not Numeric
Add 1 to TotError TotRecordError
End-If
If Function Test-Date-YYYYMMDD(WS-DOH) Is Not Zero Or WS-DOH Is Not Numeric
Add 1 to TotError TotRecordError
End-If.
900-finalize.
perform 950-print-grand-total.
950-print-grand-total.
Write Output-Rec from Blank-Line
After advancing 1 line
Move TotError to TL-TotalE
Write Output-Rec from Total-Line
after advancing 1 line
Move TotRecordError to TL-TotalRE
Write Output-Rec from TotalRE-Line
after advancing 1 line.
As you've used the GnuCOBOL tag I've just used a simple compile.
Result:
main.cobc: in paragraph '400-check':
main.cobc: 139: error: invalid expression
main.cobc: 143: error: invalid expression
main.cobc: 146: error: invalid expression
main.cobc: 150: error: invalid expression
main.cobc: 153: error: FUNCTION 'TEST-DATE-YYYYMMDD' has invalid parameter
main.cobc: 153: error: invalid expression
main.cobc: 153: error: invalid expression
The invalid expression part is "is negative" (additional line 139 doesn't make sense "Negative And >= 60" as this would never be true; line 146 is even more weird: "Is Not Numeric and Is Negative").
The issue that I am facing now is that the cob file wont compile eventhough it doesn't explicitly show any errors when compiling it
I guess the messages from the compilers are redirected somewhere.
How I can read a .dat file with struct like that: ( A = ALPHANUMERIC && N = NUMERIC )
0AAAAAAAANNNN (233 BLANK SPACES ) 999999 ( SEQUENTIAL NUMBER ONE BY ONE )
1NNNNNNNNNNNNAAAAAAAAAAAAAAAAAAA (194 BLANK SPACES) 999999 (SEQUENTIAL NUMBER ONE BY ONE)
2AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA (194 BLANK SPACES) 999999 (SEQUENTIAL NUMBER ONE BY ONE)
1NNNNNNNNNNNNAAAAAAAAAAAAAAAAAAA (194 BLANK SPACES) 999999 (SEQUENTIAL NUMBER ONE BY ONE)
2AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA (194 BLANK SPACES) 999999 (SEQUENTIAL NUMBER ONE BY ONE)
1NNNNNNNNNNNNAAAAAAAAAAAAAAAAAAA (194 BLANK SPACES) 999999 (SEQUENTIAL NUMBER ONE BY ONE)
2AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA (194 BLANK SPACES) 999999 (SEQUENTIAL NUMBER ONE BY ONE)
1NNNNNNNNNNNNAAAAAAAAAAAAAAAAAAA (194 BLANK SPACES) 999999 (SEQUENTIAL NUMBER ONE BY ONE)
2AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA (194 BLANK SPACES) 999999 (SEQUENTIAL NUMBER ONE BY ONE)
9 (245 BLANK SPACES) 999999 (SEQUENTIAL NUMBER ONE BY ONE)
So, I know, how I can make a program to read this in C/C++ or in C#, but, I try to make in Cobol, just for study....
But, I don't know what the command I need to use to open the file with this style ( I just know the:
ORGANIZATION IS LINE SEQUENTIAL.
I think, exist a another command to open with custon instructions... i don't know...
So, btw, how I can open the file and read the informations ??
( i just need to read the line 1 on time, and, I need to read the line 2 and 3 always paried ... 4 and 5 && 6 and 7 && 8 and 9 ... )
and, I whant to show that information with DISPLAY ( just for study )
Thanks :)
Something like this below your FD:
01 INPUT-RECORD.
05 IR-RECORD-TYPE PIC X.
88 INPUT-RECORD-IS-HEADER VALUE '0'.
88 INPUT-RECORD-IS-DATA1 VALUE '1'.
88 INPUT-RECORD-IS-DATA2 VALUE '2'.
88 INPUT-RECORD-IS-TRAILER VALUE '9'.
05 FILLER PIC X(whatever).
You may need a "trailing" byte for a record-delimiter, I don't know, and you'll have to sort out the lengths, as they seem to vary.
These in Working-Storage:
01 INPUT-RECORD-HEADER.
05 IRH-RECORD-TYPE PIC X.
05 IRH-ITEM1 PIC X(8).
05 IRH-ITEM2 PIC 9(4).
05 FILLER PIC X(233).
05 IRH-SEQUENCE PIC X(6)
01 INPUT-RECORD-DATA1.
05 IRD1-RECORD-TYPE PIC X.
05 IRD1-ITEM1 PIC 9(14).
05 IRD1-ITEM1 PIC X(19).
05 FILLER PIC X(194).
05 IRD1-SEQUENCE PIC X(6)
01 INPUT-RECORD-DATA2.
05 IRD2-RECORD-TYPE PIC X.
05 IRD2-ITEM1 PIC X(33).
05 FILLER PIC X(194).
05 IRD2-SEQUENCE PIC X(6)
01 INPUT-RECORD-TRAILER.
05 IRT-RECORD-TYPE PIC X.
05 FILLER PIC X(245).
05 IRT-SEQUENCE PIC X(6).
You have to read each record, one at a time. Identify it. Put it in the correct W-S definition. When you read a "2" you can process the "1" you have stored along with the "2".
My datanames aren't very good, as I don't know what your data is. Also I have not "formatted" the definitions, which will make them more readable when you do it.
For OpenCOBOL, here is a sample standard in/standard out filter program:
>>SOURCE FORMAT IS FIXED
*> ***************************************************************
*><* ===========
*><* filter
*><* ===========
*><* :Author: Brian Tiffin
*><* :Date: 20090207
*><* :Purpose: Standard IO filters
*><* :Tectonics: cobc -x filter.cob
*> ***************************************************************
identification division.
program-id. filter.
environment division.
configuration section.
input-output section.
file-control.
select standard-input assign to keyboard.
select standard-output assign to display.
data division.
file section.
fd standard-input.
01 stdin-record pic x(32768).
fd standard-output.
01 stdout-record pic x(32768).
working-storage section.
01 file-status pic x value space.
88 end-of-file value high-value
when set to false is low-value.
*> ***************************************************************
procedure division.
main section.
00-main.
perform 01-open
perform 01-read
perform
until end-of-file
perform 01-transform
perform 01-write
perform 01-read
end-perform
.
00-leave.
perform 01-close
.
goback.
*> end main
support section.
01-open.
open input standard-input
open output standard-output
.
01-read.
read standard-input
at end set end-of-file to true
end-read
.
*> All changes here
01-transform.
move stdin-record to stdout-record
.
*>
01-write.
write stdout-record end-write
.
01-close.
close standard-input
close standard-output
.
end program filter.
*><*
*><* Last Update: dd-Mmm-yyyy
and here is a demonstration of using LINAGE that just happens to read in a text file.
*****************************************************************
* Example of LINAGE File Descriptor
* Author: Brian Tiffin
* Date: 10-July-2008
* Tectonics: $ cocb -x linage-demo.cob
* $ ./linage-demo <filename ["linage-demo.cob"]>
* $ cat -n mini-report
*****************************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID. linage-demo.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
select optional data-file assign to file-name
organization is line sequential
file status is data-file-status.
select mini-report assign to "mini-report".
DATA DIVISION.
FILE SECTION.
FD data-file.
01 data-record.
88 endofdata value high-values.
02 data-line pic x(80).
FD mini-report
linage is 16 lines
with footing at 15
lines at top 2
lines at bottom 2.
01 report-line pic x(80).
WORKING-STORAGE SECTION.
01 command-arguments pic x(1024).
01 file-name pic x(160).
01 data-file-status pic 99.
01 lc pic 99.
01 report-line-blank.
02 filler pic x(18) value all "*".
02 filler pic x(05) value spaces.
02 filler pic x(34)
VALUE "THIS PAGE INTENTIONALLY LEFT BLANK".
02 filler pic x(05) value spaces.
02 filler pic x(18) value all "*".
01 report-line-data.
02 body-tag pic 9(6).
02 line-3 pic x(74).
01 report-line-header.
02 filler pic x(6) VALUE "PAGE: ".
02 page-no pic 9999.
02 filler pic x(24).
02 filler pic x(5) VALUE " LC: ".
02 header-tag pic 9(6).
02 filler pic x(23).
02 filler pic x(6) VALUE "DATE: ".
02 page-date pic x(6).
01 page-count pic 9999.
PROCEDURE DIVISION.
accept command-arguments from command-line end-accept.
string
command-arguments delimited by space
into file-name
end-string.
if file-name equal spaces
move "linage-demo.cob" to file-name
end-if.
open input data-file.
read data-file
at end
display
"File: " function trim(file-name) " open error"
end-display
go to early-exit
end-read.
open output mini-report.
write report-line
from report-line-blank
end-write.
move 1 to page-count.
accept page-date from date end-accept.
move page-count to page-no.
write report-line
from report-line-header
after advancing page
end-write.
perform readwrite-loop until endofdata.
display
"Normal termination, file name: "
function trim(file-name)
" ending status: "
data-file-status
end-display.
close mini-report.
* Goto considered harmful? Bah! :)
early-exit.
close data-file.
exit program.
stop run.
****************************************************************
readwrite-loop.
move data-record to report-line-data
move linage-counter to body-tag
write report-line from report-line-data
end-of-page
add 1 to page-count end-add
move page-count to page-no
move linage-counter to header-tag
write report-line from report-line-header
after advancing page
end-write
end-write
read data-file
at end set endofdata to true
end-read
.
*****************************************************************
* Commentary
* LINAGE is set at a 20 line logical page
* 16 body lines
* 2 top lines
* A footer line at 15 (inside the body count)
* 2 bottom lines
* Build with:
* $ cobc -x -Wall -Wtruncate linage-demo.cob
* Evaluate with:
* $ ./linage-demo
* This will read in linage-demo.cob and produce mini-report
* $ cat -n mini-report
*****************************************************************
END PROGRAM linage-demo.
With those samples, along with Gilbert's answer, you should have enough to tackle your problem, with the caveat that these examples are shy on proper error handling, so be careful is this is homework or a paid assignment. For an example of standard input/output or by filename depending on command line arguments (or lack thereof), see the ocdoc.cob program in the OpenCOBOL FAQ.
Offtopic: Output of an ocdoc pass over ocdoc.cob itself can be seen at http://opencobol.add1tocobol.com/ocdoc.html (Why mention it? The COBOL lexicon highlighter for Pygments has just been accepted into main. Any Pygments pulled after version 1.6 will allow for COBOL (context free) lexical highlighting.)
You write an ordinary Cobol program that reads a file.
The first byte (character) of the record is either 0, 1, 2, or 9.
Define a Working-Storage area (01 level) for each of the 4 record types. Then, after you read the record, you move it from the input area to the appropriate Working-Storage area for the record.
Then you process the record how you wish from one of the 4 Working-Storage areas.