Need help with a syntax error (COBOL) - syntax-error

I am working on my last homework assignment for COBOL this semester and I am being hit with a syntax error that is stopping my progress cold. Here is what I got:
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT USED-CAR-FILE-OUT
ASSIGN TO 'USED-CAR.RPT'
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD USED-CAR-FILE-OUT.
01 USED-CAR-RECORD-OUT PIC X(80).
WORKING-STORAGE SECTION.
01 ID-CODE PIC X(3).
01 TOTAL-CASH-PAYMENT PIC 9(5).
01 MONTHLY-PAYMENT PIC 9(4).
01 NUMBER-OF-MONTHS PIC 9(3).
01 BALANCE-TOTAL PIC S9(6)V99 VALUE ZEROS.
01 INTEREST-EARNED PIC S99V99 VALUE ZEROS.
01 COMPARE-MONTH PIC 99 VALUE ZEROS.
01 YEAR-NUMBER PIC 99 VALUE ZEROS.
01 MONTH-NUMBER PIC 99 VALUE ZEROS.
01 DETAIL-LINE.
05 ID-CODE-DL PIC X(3).
05 PIC X(3) VALUE SPACES.
05 PIC X(4) VALUE 'Yr='.
05 YEAR-NUMBER-DL PIC Z9 VALUE ZEROS.
05 PIC X(4) VALUE SPACES.
05 PIC X(4) VALUE 'Mo='.
05 MONTH-NUMBER-DL PIC Z9.
05 PIC X(4) VALUE SPACES.
05 PIC X(5) VALUE 'Pmt='.
05 PAYMENT-DL PIC $$$,$$$.
05 PIC X(4) VALUE SPACES.
05 PIC X(5) VALUE 'Int='.
05 INTEREST-EARNED-DL PIC $$$$.99.
05 PIC X(3) VALUE SPACES.
05 PIC X(5) VALUE 'Bal='.
05 BALANCE-DL PIC $$$,$$$.99.
PROCEDURE DIVISION.
100-MAIN.
OPEN OUTPUT USED-CAR-FILE-OUT
PERFORM 200-INPUT THRU 299-EXIT
CLOSE USED-CAR-FILE-OUT
STOP RUN.
200-INPUT.
DISPLAY 'Used Car Sales Report'
DISPLAY 'Enter the ID Code (or END) - maximum three char.'
ACCEPT ID-CODE
IF ID-CODE = 'END'
GO TO 299-EXIT
END-IF
DISPLAY 'Enter the Total Cash Payment - maximum five digits'
ACCEPT TOTAL-CASH-PAYMENT
DISPLAY 'Enter the Monthly Payment - maximum four digits'
ACCEPT MONTHLY-PAYMENT
DISPLAY 'Enter the Number of Months - maximum three digits'
ACCEPT NUMBER-OF-MONTHS
PERFORM 300-PROCESS.
299-EXIT.
EXIT.
300-PROCESS.
IF TOTAL-CASH-PAYMENT > 0
MOVE TOTAL-CASH-PAYMENT TO PAYMENT-DL
END-IF
IF MONTHLY-PAYMENT > 0
MOVE MONTHLY-PAYMENT TO PAYMENT-DL
END-IF
ADD PAYMENT-DL TO BALANCE-TOTAL
COMPUTE INTEREST-EARNED ROUNDED = .0175 / BALANCE-TOTAL
ADD INTEREST-EARNED TO BALANCE-TOTAL
MOVE BALANCE-TOTAL TO BALANCE-DL
ADD 1 TO COMPARE-MONTH
IF MONTH-NUMBER-DL > 13
ADD 1 TO MONTH-NUMBER
MOVE MONTH-NUMBER TO MONTH-NUMBER-DL
END-IF
IF MONTH-NUMBER-DL = 13
MOVE 1 TO MONTH-NUMBER
MOVE MONTH-NUMBER TO MONTH-NUMBER-DL
END-IF
IF MONTH-NUMBER = 1
ADD 1 TO YEAR-NUMBER
MOVE YEAR-NUMBER TO YEAR-NUMBER-DL
END-IF
MOVE DETAIL-LINE TO USED-CAR-RECORD-OUT
WRITE USED-CAR-RECORD-OUT
AFTER ADVANCING 1 LINE
IF TOTAL-CASH-PAYMENT > 0
MOVE 0 TO TOTAL-CASH-PAYMENT
MOVE 0 TO PAYMENT-DL
END-IF
IF COMPARE-MONTH > NUMBER-OF-MONTHS
PERFORM 300-PROCESS
END-IF
The problem is with PAYMENT-DL, INTEREST-EARNED-DL and BALANCE-DL. It says that an illegal character, but I know that it should work as it shows those pic clauses in my book and the teacher handed out an incomplete version of the program that I have to write. What do I have to do to get rid of those errors?

The invalid character is the "$" sign.
This should be OK, but your compiler may have been customized to use a local currency symbol as the default.
You could switch to your local currency sign (if you know it!) or change it back to "$". Changing it back to "$" depends on which compiler you are using and how the defaults are set -- you really need to read the manual for your particular compiler to find out how this is done.

Related

How to solve 'NO SPOOL' response in submitting a JCL to INTRDR from CICS?

I am practicing some CICS programming and I want to submit a job from CICS program by using spool commands. However, I get the 'NO SPOOL' return which the IBM documentation says:
80 NOSPOOL
No subsystem present.
Interface being disabled; CICS is quiescing.
Interface has been stopped.
I don't know what changes I need to make to correct this. attached below is the sample of the code I made:
IDENTIFICATION DIVISION.
PROGRAM-ID. GDGTEST
*
ENVIRONMENT DIVISION.
*
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-MSG-TEXT PIC X(56).
01 WS-MSG-LENGTH PIC S9(4) COMP VALUE 60.
01 WS-SUBMIT-MSG PIC X(56)
VALUE 'GDG BACKUP STARTED'.
01 WS-END-MSG PIC X(56)
VALUE 'BACK UP SUCCESSFULLY CREATED'.
01 WS-ERROR-MSG PIC X(56)
VALUE 'GDG BACKUP FAILED'.
01 WS-SPOOL-OPTIONS.
05 WS-TOKEN PIC X(8) VALUE LOW-VALUES.
05 WS-NODE PIC X(8) VALUE 'IBMUSER'.
05 WS-USERID PIC X(8) VALUE 'INTRDR'.
05 WS-CLASS PIC X VALUE 'A'.
05 WS-RESP PIC X(4).
05 WS-RESP2 PIC X(4).
01 WS-JCL-TXT PIC X(80).
01 WS-JOB.
05 FILLER PIC X(56) VALUE
'//GDGBCKUP JOB CLASS=A,MSGCLASS=H,MSGLEVEL=(1,1), '.
05 FILLER PIC X(56) VALUE
'// REGION=2048K,NOTIFY=&SYSUID '.
05 FILLER PIC X(56) VALUE
'//STEP1 EXEC PGM=IEBGENER '.
05 FILLER PIC X(56) VALUE
'//SYSPRINT DD SYSOUT=* '.
05 FILLER PIC X(56) VALUE
'//SYSUT1 DD DSN=IBMUSER.TEST.CASACONS.MONTHREP, '.
05 FILLER PIC X(56) VALUE
'// DISP=SHR '.
05 FILLER PIC X(56) VALUE
'//SYSUT2 DD DSN=IBMUSER.TEST.MONTHREP.BACKUP(+1), '.
05 FILLER PIC X(56) VALUE
'// DISP=(NEW,CATLG,DELETE), '.
05 FILLER PIC X(56) VALUE
'// UNIT=3390,SPACE=(TRK,4), '.
05 FILLER PIC X(56) VALUE
'// DCB=(LRECL=81,BLKSIZE=81,RECFM=FBA,DSORG=PS) '.
05 FILLER PIC X(56) VALUE
'//SYSIN DD DUMMY '.
05 FILLER PIC X(56) VALUE
'//SYSOUT DD SYSOUT=* '.
05 FILLER PIC X(56) VALUE
'//SYSUDUMP DD SYSOUT=* '.
05 FILLER PIC X(56) VALUE
'// '.
01 WX-1 PIC 9(5) VALUE 0.
*
PROCEDURE DIVISION.
0000-MAIN.
MOVE WS-SUBMIT-MSG TO WS-MSG-TEXT.
PERFORM 0200-SEND-MSG-TEXT.
IF EIBRESP NOT = DFHRESP(NORMAL)
MOVE WS-ERROR-MSG TO WS-MSG-TEXT
PERFORM 0200-SEND-MSG-TEXT
PERFORM 9999-RETURN-CICS
ELSE
PERFORM 0300-SPOOL-OPEN
ADD 1 TO ZERO GIVING WX-1
PERFORM 14 TIMES
MOVE WS-JOB(WX-1:56) TO WS-JCL-TXT
PERFORM 0400-SPOOL-WRITE
ADD 56 TO WX-1
END-PERFORM
PERFORM 0500-SPOOL-CLOSE
END-IF.
MOVE WS-END-MSG TO WS-MSG-TEXT.
PERFORM 0200-SEND-MSG-TEXT.
PERFORM 9999-RETURN-CICS.
*
0200-SEND-MSG-TEXT.
EXEC CICS SEND TEXT
FROM(WS-MSG-TEXT)
LENGTH(WS-MSG-LENGTH)
ERASE
FREEKB
END-EXEC.
*
0300-SPOOL-OPEN.
EXEC CICS SPOOLOPEN OUTPUT
TOKEN(WS-TOKEN)
USERID(WS-USERID)
NODE(WS-NODE)
CLASS(WS-CLASS)
RESP(WS-RESP)
RESP2(WS-RESP2)
END-EXEC.
*
0400-SPOOL-WRITE.
EXEC CICS SPOOLWRITE
TOKEN (WS-TOKEN)
FROM (WS-JCL-TXT)
RESP (WS-RESP)
RESP2 (WS-RESP2)
END-EXEC.
*
0500-SPOOL-CLOSE.
EXEC CICS SPOOLCLOSE
TOKEN (WS-TOKEN)
RESP (WS-RESP)
RESP2 (WS-RESP2)
END-EXEC.
*
9999-RETURN-CICS.
EXEC CICS RETURN END-EXEC.
I have a feeling the problem lies on what I specified in NODE and USER-ID options of the SPOOLOPEN OUTPUT commands. I appreciate your help. Thank you.

COBOL File I/O Formatting

As the title may indicate, I am having some difficulty getting the desired output for my COBOL program. The program takes in data from a file and outputs in a specific format, this is for a homework assignment. When i run the program it works for the name header, schoolID header, and column header. The first course works fine then the output starts to cut off by one and messes up all my other outputs.
Input File example
CMPS161 ALGORITHM DSGN/IMPLMNT I A 3.00
CMPS280 ALGORITHM DSGN/IMPLEM II B 3.00
Output file desired example
<Name>
<schoolID>
Course Title GR Earned
CMPS161 ALGORITHM DSGN/IMPLMNT I A 3.00
CMPS280 ALGORITHM DSGN/IMPLEM II B 3.00
Output actual example
<Name>
<schoolID>
Course Title GR Earned
CMPS161 ALGORITHM DSGN/IMPLMNT I A 0.00
MPS280 ALGORITHM DSGN/IMPLEM II B 0.00
COBOL Project
IDENTIFICATION DIVISION.
PROGRAM-ID. P2.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT myInFile ASSIGN TO "P2In.dat".
SELECT myOutFile ASSIGN TO "P2Out.dat".
DATA DIVISION.
FILE SECTION.
FD myInFile.
01 inRecord.
02 Course PIC X(13).
02 Title PIC X(32).
02 Grade PIC X(4).
02 Earned PIC Z9.99.
02 FILLER PIC X(3).
FD myOutFile.
01 outRecord.
02 myCourse PIC X(13).
02 myTitle PIC X(32).
02 myGrade PIC X(4).
02 myEarned PIC Z9.99.
02 FILLER PIC X(3).
WORKING-STORAGE SECTION.
01 E0F PIC X(3) VALUE "NO ".
01 NAME-HDR.
05 FILLER PIC X(10) VALUE "NAME HERE ".
01 SCHOOLID-HDR.
05 FILLER PIC X(8) VALUE "SCHOOLID"
01 COLUMN-HDR.
05 FILLER PIC X(6) VALUE "COURSE".
05 FILLER PIC X(6) VALUE SPACES.
05 FILLER PIC X(6) VALUE "TITLE".
05 FILLER PIC X(6) VALUE SPACES.
05 FILLER PIC X(6) VALUE "GR".
05 FILLER PIC X(6) VALUE SPACES.
05 FILLER PIC X(6) VALUE "EARNED".
PROCEDURE DIVISION.
MAIN-PROGRAM.
PERFORM HEADER.
PERFORM FILE-IO.
PERFORM CLOSING.
STOP RUN.
HEADER.
OPEN INPUT myInFile
OUTPUT myOutFile.
WRITE outRecord FROM NAME-HDR
AFTER ADVANCING 1 LINE.
WRITE outRecord FROM SCHOOLID-HDR
AFTER ADVANCING 1 LINE.
WRITE outRecord FROM COLUMN-HDR
AFTER ADVANCING 2 LINES.
MOVE SPACES TO outRecord.
WRITE outRecord
AFTER ADVANCING 1 LINE.
FILE-IO.
READ myInFile
AT END
MOVE "YES" TO EOF.
PERFORM PROCESS-RECORD
UNTIL EOF = "YES".
PROCESS-RECORD.
MOVE SPACES TO outRecord.
MOVE Course to myCourse.
MOVE Title to myTitle.
MOVE Grade to myGrade.
MOVE Earned to myEarned.
WRITE outRecord
AFTER ADVANCING 1 LINE.
READ myInFile
AT END
MOVE "YES" TO EOF.
CLOSING.
CLOSE myInFile
myOutFile.
My COBOL is very rusty but I don't think that 'Z' in input formats will work. Leading zero suppression is just for output formats. You may simply have to replace leading spaces with zeroes before you do anything with the data. Try something like:
INSPECT Earned REPLACING ALL SPACES BY '0'.
after the read (and change the input format to 99.99). It's a common problem but I can't remember how I used to deal with it.

How to resolve SQLCODE -805 in DB2 Express C, Windows 8.1, GnuCOBOL, OpenCOBOL IDE

I am trying to work with OpenCOBOL IDE and DB2 Express-C. A very simple program TEST0002.sqb is prep'ed and binded with DB2 creating - TEST0002.bnd and TEST0002.cbl files. Now when I execute the Program in OpenCOBOL IDE, I am getting -805. Following messages are displayed: (also attached)
F:\COBOL\bin\TEST0002.exe
CONNECT :)+000000000+1ÿ1208ÿAKADIAN
ÿSAMPLEÿQDB2/NT64ÿ2268ÿ2268ÿ0ÿ1252ÿ0ÿ
SQLCODE: -000000805
SQLCAID: SQLCA
SQLCABC: +000000136
SQLERRML: +0036
SQLERRMC: A Øõ( . CÀ[¸õ( 0X00000000604B4100
SQLERRP: SQLRA14D
SQLSTATE: 51002
SQLWARN:
Hello world: 0 -->THIS SHOULD BE 1 IF SQL WORKED :)
--- error report ---
ERROR occurred :
SQLCODE : -000000805
ERR BUFFER :
ERR BUFFER : SQL0805N Package " A Øõ( . CÀ[¸õ( 0X00000000604B4100"
was not found.
SQLSTATE=51002
Package: A Øõ( . CÀ[¸õ( 0X00000000604B4100
001SQL0805N Package " A Øõ( . CÀ[¸õ( 0X00000000604B4100" was not
found.
SQLSTATE=51002
SQLSTATE 51002: The package corresponding to an SQL statement
execution request
was not found.
--- end error report ---****
Process finished with exit code 98
TEST0002.sqb
IDENTIFICATION DIVISION.
PROGRAM-ID. TEST0002.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
*-----------------------
INPUT-OUTPUT SECTION.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
COPY 'sql.cbl'.
COPY 'sqlenv.cbl'.
EXEC SQL
BEGIN DECLARE SECTION
END-EXEC.
01 WS-SQL-FETCH pic X(01) value '0'.
EXEC SQL
END DECLARE SECTION
END-EXEC.
77 errloc pic x(80).
EXEC SQL
INCLUDE SQLCA
END-EXEC.
PROCEDURE DIVISION.
MAIN-PROCEDURE.
EXEC SQL
CONNECT TO SAMPLE
END-EXEC.
if SQLCODE not equal zero
then
display 'CONNECT failed with rc ' SQLCODE '+' SQLERRMC
else display 'CONNECT :)' SQLCODE '+' SQLERRMC
end-if.
EXEC SQL
SELECT '1'
INTO :WS-SQL-FETCH
FROM EMPLOYEE
FETCH FIRST 1 ROW ONLY
END-EXEC.
if SQLCODE not equal zero
then
DISPLAY 'SQLCODE: ' SQLCODE
DISPLAY 'SQLCAID: ' SQLCAID
DISPLAY 'SQLCABC: ' SQLCABC
DISPLAY 'SQLERRML: ' SQLERRML
DISPLAY 'SQLERRMC: ' SQLERRMC
DISPLAY 'SQLERRP: ' SQLERRP
DISPLAY 'SQLSTATE: ' SQLSTATE
DISPLAY 'SQLWARN: ' SQLWARN
DISPLAY "Hello world: " WS-SQL-FETCH
" -->THIS SHOULD BE 1 IF SQL WORKED :) "
call 'checkerr' using SQLCA, errloc
end-if.
STOP RUN.
END PROGRAM TEST0002.
PREP, BIND & PACKAGE Info:
db2 => prep F:\COBOL\sqb\TEST0002.sqb target ANSI_COBOL BINDFILE USING F:\COBOL\
bnd\TEST0002.bnd QUALIFIER AKADIAN COLLECTION AKADIAN OUTPUT F:\COBOL\cbl\TEST00
02.cbl VALIDATE BIND
LINE MESSAGES FOR TEST0002.sqb
------ --------------------------------------------------------------------
SQL0060W The "COBOL" precompiler is in progress.
SQL0091W Precompilation or binding was ended with "0"
errors and "0" warnings.
db2 => bind F:\COBOL\bnd\TEST0002.bnd OWNER AKADIAN QUALIFIER AKADIAN COLLECTION
AKADIAN EXPLAIN NO VALIDATE BIND
LINE MESSAGES FOR TEST0002.bnd
------ ---------------------------------------------- -----------------
-----
SQL0061W The binder is in progress.
SQL0091N Binding was ended with "0" errors and "0" warnings.
db2 => quit
DB20000I The QUIT command completed successfully.
C:\Windows\system32>db2bfd -b F:\COBOL\bnd\TEST0002.bnd
F:\COBOL\bnd\TEST0002.bnd: Header Contents
Header Fields:
Field Value
----- -----
releaseNum 0x800
Endian 0x4c
numHvars 1
maxSect 1
numStmt 5
optInternalCnt 5
optCount 11
Name Value
------------------ -----
Isolation Level Cursor Stability
Creator "AKADIAN "
Collection "AKADIAN "
App Name "TEST0002"
Timestamp "KAHjVNEg:2016/04/13 21:35:07:10"
Cnulreqd Yes
Sql Error No package
Qualifier "AKADIAN"
Validate Bind
Date Default/local
Time Default/local
COBOL Source after precompilation: TEST0002.cbl
IDENTIFICATION DIVISION.
PROGRAM-ID. TEST0002.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
INPUT-OUTPUT SECTION.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
01 SQLDA-ID pic 9(4) comp-5.
01 SQLDSIZE pic 9(4) comp-5.
01 SQL-STMT-ID pic 9(4) comp-5.
01 SQLVAR-INDEX pic 9(4) comp-5.
01 SQL-DATA-TYPE pic 9(4) comp-5.
01 SQL-HOST-VAR-LENGTH pic 9(9) comp-5.
01 SQL-S-HOST-VAR-LENGTH pic 9(9) comp-5.
01 SQL-S-LITERAL pic X(258).
01 SQL-LITERAL1 pic X(130).
01 SQL-LITERAL2 pic X(130).
01 SQL-LITERAL3 pic X(130).
01 SQL-LITERAL4 pic X(130).
01 SQL-LITERAL5 pic X(130).
01 SQL-LITERAL6 pic X(130).
01 SQL-LITERAL7 pic X(130).
01 SQL-LITERAL8 pic X(130).
01 SQL-LITERAL9 pic X(130).
01 SQL-LITERAL10 pic X(130).
01 SQL-IS-LITERAL pic 9(4) comp-5 value 1.
01 SQL-IS-INPUT-HVAR pic 9(4) comp-5 value 2.
01 SQL-CALL-TYPE pic 9(4) comp-5.
01 SQL-SECTIONUMBER pic 9(4) comp-5.
01 SQL-INPUT-SQLDA-ID pic 9(4) comp-5.
01 SQL-OUTPUT-SQLDA-ID pic 9(4) comp-5.
01 SQLA-PROGRAM-ID.
05 SQL-PART1 pic 9(4) COMP-5 value 172.
05 SQL-PART2 pic X(6) value "AEAQAI".
05 SQL-PART3 pic X(24) value "KAHjVNEg01111 2 ".
05 SQL-PART4 pic 9(4) COMP-5 value 8.
05 SQL-PART5 pic X(8) value "AKADIAN ".
05 SQL-PART6 pic X(120) value LOW-VALUES.
05 SQL-PART7 pic 9(4) COMP-5 value 8.
05 SQL-PART8 pic X(8) value "TEST0002".
05 SQL-PART9 pic X(120) value LOW-VALUES.
COPY 'sql.cbl'.
COPY 'sqlenv.cbl'.
01 WS-SQL-FETCH pic X(01) value '0'.
77 errloc pic x(80).
COPY 'sqlca.cbl'.
PROCEDURE DIVISION.
MAIN-PROCEDURE.
CALL "sqlgstrt" USING
BY CONTENT SQLA-PROGRAM-ID
BY VALUE 0
BY REFERENCE SQLCA
MOVE 1 TO SQL-STMT-ID
MOVE 1 TO SQLDSIZE
MOVE 2 TO SQLDA-ID
CALL "sqlgaloc" USING
BY VALUE SQLDA-ID
SQLDSIZE
SQL-STMT-ID
0
MOVE "SAMPLE"
TO SQL-LITERAL1
MOVE 6 TO SQL-HOST-VAR-LENGTH
MOVE 452 TO SQL-DATA-TYPE
MOVE 0 TO SQLVAR-INDEX
MOVE 2 TO SQLDA-ID
CALL "sqlgstlv" USING
BY VALUE SQLDA-ID
SQLVAR-INDEX
SQL-DATA-TYPE
SQL-HOST-VAR-LENGTH
BY REFERENCE SQL-LITERAL1
BY VALUE 0
0
MOVE 0 TO SQL-OUTPUT-SQLDA-ID
MOVE 2 TO SQL-INPUT-SQLDA-ID
MOVE 4 TO SQL-SECTIONUMBER
MOVE 29 TO SQL-CALL-TYPE
CALL "sqlgcall" USING
BY VALUE SQL-CALL-TYPE
SQL-SECTIONUMBER
SQL-INPUT-SQLDA-ID
SQL-OUTPUT-SQLDA-ID
0
CALL "sqlgstop" USING
BY VALUE 0
.
if SQLCODE not equal zero
then
display 'CONNECT failed with rc ' SQLCODE '+' SQLERRMC
else display 'CONNECT :)' SQLCODE '+' SQLERRMC
end-if.
CALL "sqlgstrt" USING
BY CONTENT SQLA-PROGRAM-ID
BY VALUE 0
BY REFERENCE SQLCA
MOVE 2 TO SQL-STMT-ID
MOVE 1 TO SQLDSIZE
MOVE 3 TO SQLDA-ID
CALL "sqlgaloc" USING
BY VALUE SQLDA-ID
SQLDSIZE
SQL-STMT-ID
0
MOVE 1 TO SQL-HOST-VAR-LENGTH
MOVE 452 TO SQL-DATA-TYPE
MOVE 0 TO SQLVAR-INDEX
MOVE 3 TO SQLDA-ID
CALL "sqlgstlv" USING
BY VALUE SQLDA-ID
SQLVAR-INDEX
SQL-DATA-TYPE
SQL-HOST-VAR-LENGTH
BY REFERENCE WS-SQL-FETCH
BY VALUE 0
0
MOVE 3 TO SQL-OUTPUT-SQLDA-ID
MOVE 0 TO SQL-INPUT-SQLDA-ID
MOVE 1 TO SQL-SECTIONUMBER
MOVE 24 TO SQL-CALL-TYPE
CALL "sqlgcall" USING
BY VALUE SQL-CALL-TYPE
SQL-SECTIONUMBER
SQL-INPUT-SQLDA-ID
SQL-OUTPUT-SQLDA-ID
0
CALL "sqlgstop" USING
BY VALUE 0
.
if SQLCODE not equal zero
then
DISPLAY 'SQLCODE: ' SQLCODE
DISPLAY 'SQLCAID: ' SQLCAID
DISPLAY 'SQLCABC: ' SQLCABC
DISPLAY 'SQLERRML: ' SQLERRML
DISPLAY 'SQLERRMC: ' SQLERRMC
DISPLAY 'SQLERRP: ' SQLERRP
DISPLAY 'SQLSTATE: ' SQLSTATE
DISPLAY 'SQLWARN: ' SQLWARN
DISPLAY "Hello world: " WS-SQL-FETCH
" -->THIS SHOULD BE 1 IF SQL WORKED :) "
call 'checkerr' using SQLCA, errloc
end-if.
STOP RUN.
END PROGRAM TEST0002.
Below settings did work, CobolDb2 Program with exactly same issue is
still getting -805.
In below solution - what does -"VCVARSHALL path: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" is being set up for?
There was never a release of M Vis Studio 14, it was 13 and then 15. I have installed latest M Vis Studio 17 and it's installtion does not have any file named 'vcvarsall'
Additionally, keeping -
(x) Path: C:\Program Files (x86)\OpenCobolIDE\GnuCOBOL\bin
(x)
(x)
(x)
(x)
i.e. config, copy, include & lib causes the compiler to stop working. Wihtout these even compilation can not be performed.
This issue needs to be researched again.
Following settings in OpenCOBOL IDE resolve the issue:
Go to Edit --> Preferences -->
Compiler Tab
Compiler Path: C:\Program Files (x86)\OpenCobolIDE\GnuCOBOL\bin\cobc.exe
(x) Path: C:\Program Files (x86)\OpenCobolIDE\GnuCOBOL\bin
(x)
(x)
(x)
(x)
VCVARSHALL path: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
Output directory: F:\COBOL\bin
(x) Copy runtime ddls to output directory
Associated extensions: .cob; .pco; .cbl; .lst
Standard: default
Free format: ( )
Compiler flags: ( ) -static ( ) -debug ( ) -g
( ) -ftrace ( ) -ftraceall -( ) -fdebugging-line
Copybook Paths: C:\Users\Public.ASK\Desktop\cobol_a
Library paths: C:\Program Files\IBM\SQLLIB\lib
Libraries:
Extra Compiler Flags: -ldb2api
Run Tab
COB_PRE_LOAD: db2agapi

COBOL: File status 39 error

here is my cobol code. i have the testinput.txt in my cobol folder. I compiled it and it has no errors but when i try to run it,
there's a message that says
RCL0002: File status 39 on < unopened-file >
Error detected at offset 0046 in segment 00 of program TEST
IDENTIFICATION DIVISION.
PROGRAM-ID. transactionIN.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-PC.
OBJECT-COMPUTER. IBM-PC.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INFILE ASSIGN TO 'testinput.txt'.
SELECT OUTFILE ASSIGN TO 'testoutput'.
DATA DIVISION.
FILE SECTION.
FD INFILE
LABEL RECORD IS STANDARD
DATA RECORD IS INREC.
01 INREC.
02 AC PIC X(99).
FD OUTFILE
LABEL RECORD IS OMITTED
DATA RECORD IS OUTREC.
01 OUTREC.
02 FILLER PIC X(80).
WORKING-STORAGE SECTION.
01 HEAD-1.
02 FILLER PIC X(32) VALUE SPACES.
02 FILLER PIC X(16) VALUE 'China Trust Bank'.
02 FILLER PIC X(32) VALUE SPACES.
01 HEAD-2.
02 FILLER PIC X(34) VALUE SPACES.
02 FILLER PIC X(13) VALUE 'Makati Avenue'.
02 FILLER PIC X(33) VALUE SPACES.
01 HEAD-3.
02 FILLER PIC X(35) VALUE SPACES.
02 FILLER PIC X(12) VALUE 'Makati City'.
02 FILLER PIC X(34) VALUE SPACES.
01 HEAD-4.
02 FILLER PIC X(33) VALUE SPACES.
02 FILLER PIC X(14) VALUE 'Account Report'.
02 FILLER PIC X(33) VALUE SPACES.
01 SUB-1.
02 FILLER PIC X(20) VALUE SPACES.
02 FILLER PIC X(7) VALUE 'Account'.
02 FILLER PIC X(10) VALUE SPACES.
02 FILLER PIC X(7) VALUE 'Account'.
02 FILLER PIC X(9) VALUE SPACES.
02 FILLER PIC X(7) VALUE 'Balance'.
02 FILLER PIC X(20) VALUE SPACES.
01 SUB-2.
02 FILLER PIC X(20) VALUE SPACES.
02 FILLER PIC X(6) VALUE 'Number'.
02 FILLER PIC X(12) VALUE SPACES.
02 FILLER PIC X(4) VALUE 'Name'.
02 FILLER PIC X(10) VALUE SPACES.
02 FILLER PIC X(18) VALUE SPACES.
SCREEN SECTION.
01 SCRE.
02 BLANK SCREEN.
PROCEDURE DIVISION.
MAIN-RTN.
PERFORM INIT-RTN THRU INIT-RTN-END.
PERFORM FINISH-RTN.
STOP RUN.
INIT-RTN.
OPEN INPUT INFILE, OUTPUT OUTFILE.
READ INFILE AT END PERFORM END-RTN
GO TO INIT-RTN-END.
PERFORM HEADING-RTN.
INIT-RTN-END.
END-RTN.
DISPLAY 'EMPTY FILE' LINE 3 COLUMN 20.
HEADING-RTN.
WRITE OUTREC FROM HEAD-1 AFTER PAGE.
WRITE OUTREC FROM HEAD-2 AFTER 1.
WRITE OUTREC FROM HEAD-3 AFTER 1.
WRITE OUTREC FROM HEAD-4 AFTER 3.
WRITE OUTREC FROM SUB-1 AFTER 2.
WRITE OUTREC FROM SUB-2 AFTER 1.
PROCESS-RTN.
DISPLAY SCRE.
FINISH-RTN.
CLOSE INFILE, OUTFILE.
DISPLAY 'TAPOS NA' LINE 6 COLUMN 20.
The FILE STATUS 39 means that there is a difference between what you have told COBOL about the file and what COBOL has discovered whilst attempting to OPEN it.
For the file you have defined in COBOL, the data must be exactly 99 bytes long. If you have 99 bytes per record, followed by one (or more) delimiters, then you'd need to extend the length of INREC to 100 or 101 bytes.
You may want to see if your compiler (from the error message it seems to be CA-Realia) supports LINE SEQUENTIAL files. This particular file-type understands delimited records, and the delimiters will be stripped before being presented to your program.
The simplest file-processing program in COBOL follows this outline:
OPEN files
READ input until end
process input, WRITE output
CLOSE files
That read-loop will typically be one of two forms:
PERFORM until some-flag-shows-end-of-file
READ input-file
AT END
make end-of-file-flag show "end of file"
NOT AT END
do some processing
END-READ
END-PERFORM
READ input-file ("priming read")
PERFORM until FILE STATUS field shows end-of-file
do some processing
READ input-file
END-PERFORM
The second is, to my mind, much simpler and less error-prone. It requires that the FILE STATUS is used on the SELECT for the file. This really should always be done for all files so that you can check after each IO that the IO didn't behave unexpectedly. Separate FILE STATUS field for each file.
Here's your program re-arranged. At the moment, it only reads one record (or none if end-of-file is returned immediately) but that is what you coded.
PROCEDURE DIVISION.
PERFORM INIT-RTN
PERFORM PROCESS-FILE
PERFORM END-RTN
PERFORM FINISH-RTN
STOP RUN
.
INIT-RTN.
OPEN INPUT INFILE
check file status
OPEN OUTPUT OUTFILE
check file status
PERFORM HEADING-RTN
.
PROCESS-FILE.
READ INFILE
check file status
.
END-RTN.
DISPLAY 'EMPTY FILE' LINE 3 COLUMN 20
.
HEADING-RTN.
WRITE OUTREC FROM HEAD-1 AFTER PAGE
check file status
WRITE OUTREC FROM HEAD-2 AFTER 1
check file status
WRITE OUTREC FROM HEAD-3 AFTER 1
check file status
WRITE OUTREC FROM HEAD-4 AFTER 3
check file status
WRITE OUTREC FROM SUB-1 AFTER 2
check file status
WRITE OUTREC FROM SUB-2 AFTER 1
check file status
.
PROCESS-RTN.
DISPLAY SCRE
.
FINISH-RTN.
CLOSE INFILE
check file status
CLOSE OUTFILE
check file status
DISPLAY 'TAPOS NA' LINE 6 COLUMN 20
.
So, check on FILE STATUS, LINE SEQUENTIAL, change your file (or program definition of it). Build from there.
You may think the FILE STATUS checking of the report lines will look large and ugly. You can do them like this, instead:
MOVE HEAD-1 TO OUTREC
PERFORM WRITE-OUTREC-AFTER-PAGE (other neater ways to do it later)
Where WRITE-OUTREC has the WRITE and the test of the FILE STATUS field.

COBOL data buffering without moving character by character

I am reading a variable length input file and wanting to create an output buffer (indexed table) that will not utilize a character by character move.
For example: my first input record is 79 characters, I can then move this to my group level of the table. My second input record is 101 characters -- how can I take these 101 characters and place them in my table beginning at position 80 for a length of 101 ? And the next input record beginning at position 180.....etc. We currently Perform Varying 1 by 1 but this is incredibly CPU intensive compared to a block move to a beginning address.
We do this millions of times a day and a solution would be quite useful.
Use reference modification with the length from your record. Consider:
01 Record
05 Rec-LL Pic S9(4) Binary.
05 Rec-Data Pic X(32767).
01 Tgt-Area Pic X(10000000).
01 Curr-Ptr Pic S9(8) Binary.
Once you read your record, you can move based on the length like so:
Move 1 to Curr-Ptr
Perform Get-Next-Record
Perform until no-more-data
Move Rec-Data (1:Rec-LL) to Tgt-Area (curr-ptr:rec-LL)
Compute Curr-Ptr = Curr-Ptr + Rec-LL
Perform Get-Next-Record
End-Perform
Or the old fashioned ( we are talking COBOL here so old fashioned = Jurassic) way:-
01 Record.
05 REC-LL PIC S9(4) Binary.
05 REC-DATA.
10 REC-BYTES PIC X OCCURS 32767 times depending on REC-LL.
01 TARGET-AREA.
05 TARGET-HEADER PIC X(79).
05 TARGET-REC PIC X(101) OCCURS 50 TIMES.
01 TGT-INDEX PIC S9(8) BINARY VALUE 1.
* Length calculation happens by magic!
Perform Read-Record.
move REC-DATA TO TARGET-HEADER.
perform until no-more-data
Perform Read-Record
move REC-DATA to TARGET-RED(TGT-INDEX)
add +1 to TGT-INDEX
end-perform
Or if records really vary between 1 and 101 bytes:
01 Record.
05 REC-LL PIC S9(4) Binary.
05 REC-DATA.
10 REC-BYTES PIC X OCCURS 32767 times depending on REC-LL.
01 TARGET-AREA.
05 TGT-LL PIC s9(8) BINARY.
05 TGT-REC.
10 TGX-BYTE OCCURS 3175 depending on TGT-LL.
05 TGT-EXTRA PIC X(101).
Perform Read-Record.
Move +0 to tgt-LL.
perform until no-more-data
MOVE REC-DATE to TGT-EXTRA
ADD REC-LL TO TGT-LL
Perform Read-Record
add +1 to TGT-INDEX
end-perform
Take a look at the STRING INTO verb, in particular the WITH POINTER clause. Don't forget the ON OVERFLOW imperative when stringing things together like this.
For details, grab a copy of Gary Cutler's OpenCOBOL Programmer's Guide.
http://opencobol.add1tocobol.com/OpenCOBOL%20Programmers%20Guide.pdf
This is a world class COBOL manual, and it's an open and free document (GNU FDL).