che-che4z-lsp-for-cobol icon indicating copy to clipboard operation
che-che4z-lsp-for-cobol copied to clipboard

Validation of Variables and Statements

Open jellypuno opened this issue 5 years ago • 9 comments

I have a variable that is assigned as PIC 9(02).

It would be great if the extension

  • can prevent me from moving "String data" to PIC 9 variables.
  • can warn me that my variable will be truncated because It is only defined as PIC 9(02) and I am moving a value more than 2.
  • validate missing periods in all my PERFORM inside the procedure. So far, it only validates the last PERFORM that I have.

Capture

jellypuno avatar Dec 13 '19 14:12 jellypuno

Thank you for opening this issue! We will consider that as an enhancement for our LSP.

sergiuilie avatar Dec 13 '19 14:12 sergiuilie

validate missing periods in all my PERFORM inside the procedure. So far, it only validates the last PERFORM that I have.

@jellypuno about this question, I have read on COBOL documentation that you can have a period at the end of multiple statements calls like in your example or after each one so we do not check for each individual statement if there is a bunch of them. Can you confirm that this is wrong and need to be fixed? will be helpful to have some examples from the book

sergiuilie avatar Dec 13 '19 15:12 sergiuilie

@jellypuno about this question, I have read on COBOL documentation that you can have a period at the end of multiple statements calls like in your example or after each one so we do not check for each individual statement if there is a bunch of them. Can you confirm that this is wrong and need to be fixed? will be helpful to have some examples from the book

@sergiuilie hmmm. I guess it depends on the cobol version that you have. I tested in IBM Enterprise COBOL for z/OS 4.2.0 and IBM Enterprise COBOL for z/OS 6.2.0 and I didn't experience the error. One period is enough. But I am very sure that in the previous companies that I worked for I needed period in every line. Maybe this Cobol Version can be part of the documentation?

jellypuno avatar Dec 13 '19 15:12 jellypuno

We will take a look and add this to the documentation. Thank you for looking into it 👍

sergiuilie avatar Dec 13 '19 15:12 sergiuilie

@jellypuno - COBOL has evolved and there are cases where you don't need the period at the end of every line. Our solution will support the latest level of compiler and above.

venkatzhub avatar Dec 13 '19 17:12 venkatzhub

Capture2

It would be great as well if there's an initial validation for this one. PIC X with a Value of Number

jellypuno avatar Dec 13 '19 22:12 jellypuno

@jellypuno - COBOL has evolved and there are cases where you don't need the period at the end of every line. Our solution will support the latest level of compiler and above.

@venkatzhub I do understand. If that is the decision then that is fine. I guess in my opinion, one positive thing about checking periods in every end of line is to prevent codes like this:

        WORKING-STORAGE SECTION.
        01 TEST-VAR PIC 9 VALUE 0.

000400 PROCEDURE DIVISION.                                              00040006
000600     DISPLAY "HELLO WORLD1"
           DISPLAY "HELLO WORLD2"
           DISPLAY "HELLO WORLD3", TEST-VAR
           IF TEST-VAR EQUAL 1
              DISPLAY "TEST-VAR1 HELLO WORLD4"

           MOVE 2 TO TEST-VAR
           DISPLAY "TEST-VAR NOW: ", TEST-VAR

           IF TEST-VAR EQUAL 2 
               DISPLAY "TEST-VAR2 HELLO WORLD5"
                   
000700     STOP RUN.    

If I forget my END-IF and I do not have a period after HELLO WORLD4 then everything else after that code is considered a one IF statement.

It is a bad code and maybe this is not the problem of the Cobol LSP. But it would be a great help if this can be prevented. Just my 2 cents...

jellypuno avatar Dec 13 '19 22:12 jellypuno

@jelly - The syntax check should be on the basis of what compiler would complain. What you are talking about is bad or unitended coding, which is different from syntax checking.

venkatzhub avatar Dec 15 '19 00:12 venkatzhub

Partially implemented, more semantic checks to come

temanbrcom avatar Jan 26 '21 13:01 temanbrcom