Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cobol line number

Status
Not open for further replies.

lxslxb

Programmer
Nov 18, 2008
3
CA
We know that we can get the line number in C/C++, is there a command to retrieve the source line number in Cobol?
 
I've been working with IBM COBOL for more than 15 years now, and I've never seen it. So I think the answer must be no.
 
Thanks.

That makes the debugging very difficult. If the line number can be displayed when error happens, the error source can be quickly found.

 
For debugging, the are two possibilities:

1. If you are actually debugging, use a proper debugging tool (obviously) or, if you don't have one, add debugging code to your source (look in the manuals how to do this).
Simply adding DISPLAY statements and later removing them also works, of course.

2. If you are trying to find the cause of a problem in production, you probably will have some output which states the offset where the error occurred in the program. Using the assembler map in the compiler listing you can find on which code-line the error occurred. If Abend-Aid is installed on your system, it might give you some more info on the error.
 
I don' see the very great importance of such a function.
COBOL compiler works with statements, not lines.
When I compile the source I get a spoolfile, which is numbered by statements and if I got an error, then the listing says on which statement that was.

And if I need to debug working code, there are the possibilities as explained by wotsinaname. But how should me such a function help with the debugging?
 
Source code is not a very good source of line number for debugging purposes due to /COPY functionality which inserts different statements from different sources. The best way to debug an error if you don't have the proper tool is always your compiler listing. If you don't have a copy of the listing then just simply recompile the program with option to list.
 
IBM Mainframe COBOL provides a PLIST option. I'm not sure what it's called now, but it's a listing in assembler format of the compiled code. Each instruction has a relative address and also refers back to the source. When the program fails, the os gives the address of the failing instruction. Work backwards from there.
 
When you want to see just errors list, and without numbring the copy parts, the old 6 source line number, is very use full.
I have a program to number/renumber(reseq).

RSQ your-program or RSQ your-program.cbl or RSQ (for prompt)

In order to prevent writing non COBOL file, the program will search the string "IDENTIFICATION" in column 8, in one of source lines.

Code:
000001 IDENTIFICATION DIVISION.
000002 PROGRAM-ID. RSQ.
000003 ENVIRONMENT DIVISION.
000004 INPUT-OUTPUT SECTION.
000005 FILE-CONTROL.
000006     SELECT A ASSIGN TO DISK FILE-NAME
000007              ORGANIZATION LINE SEQUENTIAL.
000008 DATA DIVISION.
000009 FILE SECTION.
000010 FD  A RECORD IS VARYING IN SIZE FROM 0 TO 256 CHARACTERS
000011     DEPENDING ON L-REC-A.
000012 01  A-REC-21.
000013     02 A-1-6         PIC 9(6).
000014     02 A-7-7         PIC X(1).
000015     02 A-8-21        PIC X(14).
000016 01  A-REC            PIC X(256).
000017 WORKING-STORAGE SECTION.
000018 01  EOJ              PIC 9 VALUE 0.
000019 01  O-K              PIC X.
000020 01  SW-FUNCTION-X.
000021        03 SW-FUNCTION-1 PIC X.
000022        03 SW-FUNCTION-2 PIC X.
000023 01  SW-FUNCTION REDEFINES SW-FUNCTION-X PIC XX.
000024 01  SW-FUNCTION-9 REDEFINES SW-FUNCTION PIC 99.
000025 01  SW-SPACE         PIC 9 VALUE 0.
000026 01  SW-DOT           PIC 9 VALUE 0.
000027 01  L-REC-A          PIC 9999 COMP.
000028 01  I                PIC 9(2) COMP.
000029 01  J                PIC 9(2) COMP.
000030 01  H                PIC 9(2) COMP.
000031 01  K                PIC 9(2) COMP.
000032 01  L                PIC 9(2) COMP.
000033 01  M                PIC 9(2) COMP.
000034 01  N                PIC 9(2) COMP.
000035 01  X                PIC X.
000036 01  COUNTER-READ-X.
000037     02 FILLER        PIC 9(4) VALUE 0.
000038     02 COUNTER-1     PIC 99 VALUE 0.
000039 01  COUNTER-READ REDEFINES COUNTER-READ-X PIC 9(6).
000040 01  COUNTER-WRITE    PIC 9(6) VALUE 0.
000041 01  FILE-NAME        PIC X(64) VALUE SPACES.
000042 01  FILE-NAME-R REDEFINES FILE-NAME.
000043     02 VEC-FILE-NAME PIC X OCCURS 64.
000044 01  FILE-NAME1       PIC X(60) VALUE SPACES.
000045 01  FILE-NAME1-R REDEFINES FILE-NAME1.
000046     02 VEC-FILE-NAME1 PIC X OCCURS 60.
000047*********************************************************************
000048 PROCEDURE DIVISION.
000049 MAIN SECTION.
000050 1.  PERFORM PROC-BEGIN THRU EX-PROC-BEGIN.
000051     PERFORM PROC-MAIN THRU EX-PROC-MAIN UNTIL EOJ > 0.
000052     PERFORM PROC-END THRU EX-PROC-END.
000053     STOP RUN.
000054 EX-PROC-MAIN-SECTION.
000055 PROC-BEGIN.
000056     PERFORM IN-COMMAND-LINE.
000057     IF O-K = "@" MOVE 2 TO EOJ, GO TO EX-PROC-BEGIN.
000058     PERFORM IF-COBOL THRU EX-IF-COBOL.
000059     IF EOJ > 0 GO TO EX-PROC-BEGIN.
000060     MOVE 0 TO EOJ COUNTER-READ COUNTER-WRITE.
000061     OPEN I-O A.
000062     PERFORM READ-A THRU EX-READ-A.
000063 EX-PROC-BEGIN.
000064 IN-COMMAND-LINE.
000065     ACCEPT FILE-NAME1 FROM COMMAND-LINE.
000066     IF FILE-NAME1 = SPACES
000067           PERFORM IN-FILE-NAME THRU EX-IN-FILE-NAME.
000068     MOVE 0 TO SW-SPACE SW-DOT J.
000069     MOVE SPACES TO FILE-NAME.
000070     PERFORM IN-COMMAND-LINE1 THRU EX-IN-COMMAND-LINE
000071                              VARYING I FROM 1 BY 1 UNTIL I > 60.
000072     IF SW-DOT = 0
000073           STRING FILE-NAME DELIMITED BY SPACE
000074                  ".CBL"    DELIMITED BY SIZE INTO FILE-NAME.
000075    IN-COMMAND-LINE1.
000076     MOVE VEC-FILE-NAME1(I) TO X.
000077     IF X = SPACE IF SW-SPACE = 0 GO TO EX-IN-COMMAND-LINE
000078                             ELSE MOVE 88 TO I
000079                                  GO TO EX-IN-COMMAND-LINE
000080             ELSE IF X = "." MOVE 1 TO SW-DOT, END-IF
000081                  IF SW-SPACE = 0 MOVE 1 TO SW-SPACE, END-IF
000082                  ADD 1 TO J
000083                  MOVE X TO VEC-FILE-NAME(J).
000084 EX-IN-COMMAND-LINE.
000085 IN-FILE-NAME.
000086     DISPLAY   "ENTER COBOL PROGRAM:'              '  O-K:' ' (Y-Y@
000087-            "ES, N-NO, @-EXIT)             " LINE 24 ERASE.
000088     DISPLAY FILE-NAME1 LINE 24 POSITION 22 WITH SIZE 20.
000089     ACCEPT  FILE-NAME1 LINE 24 POSITION 22 WITH SIZE 20.
000090     IF FILE-NAME1 = SPACES GO TO IN-FILE-NAME.
000091   IN-FILE-NAME1.
000092     ACCEPT O-K LINE 24 POSITION 44.
000093     IF O-K = "N" GO TO IN-FILE-NAME.
000094     IF O-K = "@" MOVE FILE-NAME TO FILE-NAME1
000095                  GO TO EX-IN-FILE-NAME.
000096     IF O-K NOT = "Y" GO TO IN-FILE-NAME1.
000097     DISPLAY SPACE.
000098 EX-IN-FILE-NAME.
000099 IF-COBOL.
000100     OPEN INPUT A.
000101    IF-COBOL1.
000102     PERFORM READ-A THRU EX-READ-A.
000103     IF EOJ > 0 GO TO IF-COBOL2.
000104     IF COUNTER-READ > 50 GO TO IF-COBOL1.
000105     IF A-8-21 = "IDENTIFICATION" CLOSE A, GO TO EX-IF-COBOL.
000106     GO TO IF-COBOL1.
000107    IF-COBOL2.
000108     DISPLAY "NO COBOL PROGRAM"
000109     CLOSE A.
000110     MOVE 3 TO EOJ.
000111 EX-IF-COBOL.
000112 PROC-MAIN.
000113     PERFORM REWRITE-A THRU EX-REWRITE-A.
000114     PERFORM READ-A THRU EX-READ-A.
000115 EX-PROC-MAIN.
000116 READ-A.
000117     MOVE SPACES TO A-REC.
000118     READ A AT END MOVE 1 TO EOJ
000119                   GO TO EX-READ-A.
000120     ADD 1 TO COUNTER-READ.
000121     IF COUNTER-1 = 0 DISPLAY COUNTER-READ "/" COUNTER-WRITE.
000122 EX-READ-A.
000123 REWRITE-A.
000124     IF L-REC-A < 6 GO TO EX-REWRITE-A.
000125     MOVE COUNTER-READ TO A-1-6.
000126     REWRITE A-REC.
000127     ADD 1 TO COUNTER-WRITE.
000128 EX-REWRITE-A.
000129 PROC-END.
000130     IF EOJ > 1 GO TO EX-PROC-END.
000131     DISPLAY "READ: " COUNTER-READ.
000132     DISPLAY "WRITE:" COUNTER-WRITE.
000133     CLOSE A.
000134 EX-PROC-END.
000135*****************************************************************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top