Skip to main content

[Migrated content. Thread originally posted on 05 March 2012]

Program:

000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. TESTE1.
000030
000040 ENVIRONMENT DIVISION.
000050
000060 DATA DIVISION.
000070
000080 PROCEDURE DIVISION.
000090 PARA-1.
000100 DISPLAY "Content-Type: text/html ".
000110 DISPLAY "".
000120 DISPLAY "".
000130 DISPLAY "<html><body><h3>Teste Cobol-CGI</h3></body></html>".
000140 STOP RUN.

This program when called via CGI generates the following error:

Erro interno do Servidor!

O servidor encontrou um erro interno e não pode completar sua requisição.

Mensagem de Erro:
Premature end of script headers: TESTE1.EXE

Se você acredita ter encontrado um problema no servidor, por favor entre em contato com o webmaster.
Error 500
localhost
03/05/12 15:52:51
Apache/2.2.21 (Win32) PHP/5.3.9


As I compiled the program:



The same program compiled with openCobol does not generate the error.

Can anyone help me?

[Migrated content. Thread originally posted on 05 March 2012]

Program:

000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. TESTE1.
000030
000040 ENVIRONMENT DIVISION.
000050
000060 DATA DIVISION.
000070
000080 PROCEDURE DIVISION.
000090 PARA-1.
000100 DISPLAY "Content-Type: text/html ".
000110 DISPLAY "".
000120 DISPLAY "".
000130 DISPLAY "<html><body><h3>Teste Cobol-CGI</h3></body></html>".
000140 STOP RUN.

This program when called via CGI generates the following error:

Erro interno do Servidor!

O servidor encontrou um erro interno e não pode completar sua requisição.

Mensagem de Erro:
Premature end of script headers: TESTE1.EXE

Se você acredita ter encontrado um problema no servidor, por favor entre em contato com o webmaster.
Error 500
localhost
03/05/12 15:52:51
Apache/2.2.21 (Win32) PHP/5.3.9


As I compiled the program:



The same program compiled with openCobol does not generate the error.

Can anyone help me?

You are using an extremely old version of MF COBOL.

Later releases like the Net Express product have built-in support for creating CGI applications that include an embedded HTML preprocessor which allows you to ACCEPT/DISPLAY entire html forms from within your program.

The problem you are seeing is most likely that the DISPLAY statement is not writing to STDOUT by default.

Try changing the DISPLAY statement so that it uses the UPON CONSOLE phrase, i.e.
DISPLAY "..." UPON CONSOLE

You may also have to set the S5 run-time switch if this switch is available in your version of Object COBOL.
You can do this in your computers environment by setting the environment variable:

COBSW= S5




[Migrated content. Thread originally posted on 05 March 2012]

Program:

000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. TESTE1.
000030
000040 ENVIRONMENT DIVISION.
000050
000060 DATA DIVISION.
000070
000080 PROCEDURE DIVISION.
000090 PARA-1.
000100 DISPLAY "Content-Type: text/html ".
000110 DISPLAY "".
000120 DISPLAY "".
000130 DISPLAY "<html><body><h3>Teste Cobol-CGI</h3></body></html>".
000140 STOP RUN.

This program when called via CGI generates the following error:

Erro interno do Servidor!

O servidor encontrou um erro interno e não pode completar sua requisição.

Mensagem de Erro:
Premature end of script headers: TESTE1.EXE

Se você acredita ter encontrado um problema no servidor, por favor entre em contato com o webmaster.
Error 500
localhost
03/05/12 15:52:51
Apache/2.2.21 (Win32) PHP/5.3.9


As I compiled the program:



The same program compiled with openCobol does not generate the error.

Can anyone help me?

I found an old example on our supportline web site of how to do input and output using accept/display from a COBOL program running as CGI.

 identification division.       
 program-id. cgiraw.      
* This program will output the raw, undecoded form/url data, the      
* length of the data sent, and the method used (POST or GET).      
* Change any html form to include the following form tag      
* attributes:      
* <form action="/cgi-bin/cgiraw.exe" method=POST>.      
* You can also specify a link/url:      
* <A href="127.0.0.1/.../cgiraw.exe      
* Hello</A>      
* You can also type a URL into the address field of a web browser:      
* 127.0.0.1/.../cgiraw.exe      
*
 data division.        
 working-storage section.        
 01 access-mode        pic x comp-x value 1.       
 01 deny-mode           pic x comp-x value 3.       
 01 device                   pic x comp-x value 0.       
 01 flags                      pic x comp-x value 0.
 01  file-handle            pic x(4).       
 01  offset-0                pic x(8) comp-x value 0.
 01 input-file-name      pic x(255) value spaces.       
 01 env-value              pic x(4096).       
 01 method-type          pic x(4).       
 01 content-length       pic x(4) comp-x.       
 01 content-type          pic x(100).       
 01 sub1                      pic x(4) comp-x.       
 01 temp-01                 pic x comp-x.       
 01 temp-02                 pic x comp-x.
 01  mem-pointer          usage pointer value null.       
 01  mem-length           pic x(4) comp-5.       
 01  mem-flags             pic x(4) comp-5.
 01 alloc-mem-rtn         pic x(2) comp-5.
 01 tmp-01                    pic x(4) comp-x.        
 01 tmp-02                    pic x(4) comp-x.
 linkage section.       
 01 accept-record           pic x.
 procedure division.
        move 18 to temp-01           
        move 1 to temp-02           
        call x"A7" using temp-01 temp-02
* Use display and accept verbs to get the values of environment      
* variables set up by the web server.           
        display "CONTENT_TYPE" upon environment-name           
        accept content-type from Environment-value
        display "REQUEST_METHOD" upon environment-name           
        accept env-value from environment-value           
        if env-value = "GET"               
            move "GET" to method-type       
* If the form method=GET, we cannot use the CONTENT_LENGTH      
* environment variable to determine the size of the data, so we      
* allocate a block of memory big enough to hold the data.               
           move 4096 to content-length               
           perform alloc-accept-record               
           display "QUERY_STRING" upon environment-name               
           accept accept-record(1:4096) from environment-value               
           move 0 to sub1      
* The query string should be space-terminated, so we can determine      
* it's end and it's size.               
           inspect accept-record(1:4096) tallying sub1                       
                for characters before initial space               
           move sub1 to content-length           
        else
            move "POST" to method-type               
            display "CONTENT_LENGTH" upon environment-name               
            accept env-value from environment-value                
            move 0 to sub1               
            inspect env-value tallying sub1 for characters                                 
                 before initial space                
            move env-value (1:sub1) to content-length               
            perform alloc-accept-record
* Read data from stdin instead of query string.               
            move ":CI:" to input-file-name                
            call "CBL_OPEN_FILE"  using input-file-name                                     
                                                             access-mode                                     
                                                             deny-mode                                     
                                                             device                                     
                                                             file-handle
             call "CBL_READ_FILE" using file-handle                                    
                                                             offset-0                                    
                                                             content-length                                     
                                                             flags                                     
             accept-record               
             call "CBL_CLOSE_FILE" using file-handle           
        end-if
* Send html back to the web server/browser.           
        display "Content-type: text/html" & x"0a" & x"0a"           
        display "<html>" & x"0a"           
        display "<head><title>"           
        display "Test raw cobol cgi program"           
        display "</title></head>" & x"0a"           
        display "<body bgcolor=""#FFFFFF"">" x"0a"           
        display "Content-type:" content-type x"0a"            
        display "METHOD=" method-type           
        display "<br>"           
        display "CONTENT-LENGTH=" content-length x"0a"           
        display "<br>"           
        display "CGI-DATA=<PRE>"           
        display accept-record(1:content-length) x"0a"           
        display "</pre></body>" & x"0a"           
        display "</html>" & x"0a"
        stop run            .
 alloc-accept-record section.
* Dynamically allocate memory to hold the form/url data.           
        move 0 to mem-flags           
        move content-length to mem-length           
        call "CBL_ALLOC_MEM" using    mem-pointer                                
                                               by value mem-length                                         
                                                             mem-flags                               
                                                 returning alloc-mem-rtn
        if alloc-mem-rtn not = 0              
           display "alloc mem failed"              
           stop run           
        end-if
        set address of accept-record to mem-pointer.


 


[Migrated content. Thread originally posted on 05 March 2012]

Program:

000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. TESTE1.
000030
000040 ENVIRONMENT DIVISION.
000050
000060 DATA DIVISION.
000070
000080 PROCEDURE DIVISION.
000090 PARA-1.
000100 DISPLAY "Content-Type: text/html ".
000110 DISPLAY "".
000120 DISPLAY "".
000130 DISPLAY "<html><body><h3>Teste Cobol-CGI</h3></body></html>".
000140 STOP RUN.

This program when called via CGI generates the following error:

Erro interno do Servidor!

O servidor encontrou um erro interno e não pode completar sua requisição.

Mensagem de Erro:
Premature end of script headers: TESTE1.EXE

Se você acredita ter encontrado um problema no servidor, por favor entre em contato com o webmaster.
Error 500
localhost
03/05/12 15:52:51
Apache/2.2.21 (Win32) PHP/5.3.9


As I compiled the program:



The same program compiled with openCobol does not generate the error.

Can anyone help me?

I believe Chris has identified the problem and solution (I was going to post much the same thing, but he beat me to it). It might be useful to explain why COBSW= S5 is necessary, however.

When an HTTP server runs a CGI program, it starts the program as a child process with a number of environment variables set and with the child's standard input (stdin) and output (stdout) file descriptors set to pipes. The server owns the other end of those pipes. That lets the server write the request data to the child's stdin (for POST requests) and read the response message from the child's stdout.

Obviously, if the child process does not write anything to stdout, there won't be any data for the server to read, and the server won't be able to construct the response. That's what Apache is complaining about in your example.

Your COBOL program is not writing any data to stdout because by default DISPLAY (on Windows) does not send data to stdout. Instead it uses Windows APIs that let it write to the console window in a controlled fashion, in order to support things like color and cursor positioning.

The S5 COBOL run-time switch tells the COBOL run-time to have DISPLAY write to stdout, and ACCEPT read from stdin.

The program in Chris' second post uses the COBOL run-time library function call x"a7" to do the same thing that setting the S5 switch does.

[Migrated content. Thread originally posted on 05 March 2012]

Program:

000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. TESTE1.
000030
000040 ENVIRONMENT DIVISION.
000050
000060 DATA DIVISION.
000070
000080 PROCEDURE DIVISION.
000090 PARA-1.
000100 DISPLAY "Content-Type: text/html ".
000110 DISPLAY "".
000120 DISPLAY "".
000130 DISPLAY "<html><body><h3>Teste Cobol-CGI</h3></body></html>".
000140 STOP RUN.

This program when called via CGI generates the following error:

Erro interno do Servidor!

O servidor encontrou um erro interno e não pode completar sua requisição.

Mensagem de Erro:
Premature end of script headers: TESTE1.EXE

Se você acredita ter encontrado um problema no servidor, por favor entre em contato com o webmaster.
Error 500
localhost
03/05/12 15:52:51
Apache/2.2.21 (Win32) PHP/5.3.9


As I compiled the program:



The same program compiled with openCobol does not generate the error.

Can anyone help me?

COBSW= S5 and DISPLAY "" UPON CONSOLE not work.

cgiraw.cbl - Compiled with errors:



I changed the line 43 to: 01 accept-record pic x(4096).

and line 112 to: display accept-record x"0a"

these changes are correct?

The program worked, but exhibited dirt in the final of DISPLAY command.

Thanks.

[Migrated content. Thread originally posted on 05 March 2012]

Program:

000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. TESTE1.
000030
000040 ENVIRONMENT DIVISION.
000050
000060 DATA DIVISION.
000070
000080 PROCEDURE DIVISION.
000090 PARA-1.
000100 DISPLAY "Content-Type: text/html ".
000110 DISPLAY "".
000120 DISPLAY "".
000130 DISPLAY "<html><body><h3>Teste Cobol-CGI</h3></body></html>".
000140 STOP RUN.

This program when called via CGI generates the following error:

Erro interno do Servidor!

O servidor encontrou um erro interno e não pode completar sua requisição.

Mensagem de Erro:
Premature end of script headers: TESTE1.EXE

Se você acredita ter encontrado um problema no servidor, por favor entre em contato com o webmaster.
Error 500
localhost
03/05/12 15:52:51
Apache/2.2.21 (Win32) PHP/5.3.9


As I compiled the program:



The same program compiled with openCobol does not generate the error.

Can anyone help me?

COBSW= S5 and DISPLAY "" UPON CONSOLE not work.

cgiraw.cbl - Compiled with errors:



I changed the line 43 to: 01 accept-record pic x(4096).

and line 112 to: display accept-record x"0a"

these changes are correct?

The program worked, but exhibited dirt in the final of DISPLAY command.

Thanks.

[Migrated content. Thread originally posted on 05 March 2012]

Program:

000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. TESTE1.
000030
000040 ENVIRONMENT DIVISION.
000050
000060 DATA DIVISION.
000070
000080 PROCEDURE DIVISION.
000090 PARA-1.
000100 DISPLAY "Content-Type: text/html ".
000110 DISPLAY "".
000120 DISPLAY "".
000130 DISPLAY "<html><body><h3>Teste Cobol-CGI</h3></body></html>".
000140 STOP RUN.

This program when called via CGI generates the following error:

Erro interno do Servidor!

O servidor encontrou um erro interno e não pode completar sua requisição.

Mensagem de Erro:
Premature end of script headers: TESTE1.EXE

Se você acredita ter encontrado um problema no servidor, por favor entre em contato com o webmaster.
Error 500
localhost
03/05/12 15:52:51
Apache/2.2.21 (Win32) PHP/5.3.9


As I compiled the program:



The same program compiled with openCobol does not generate the error.

Can anyone help me?

I would expect garbage characters to be appended to ACCEPT-RECORD if you have this field statically defined as PIC X(4096) in linkage because the original program dynamically allocates the memory for this field based on the value of CONTENT-LENGTH. If CONTENT-LENGTH is

I guess I don't understand why you made these two changes to the example to begin with?

Remember the COBOL product that you are using is very old and this sample was created and runs under Net Express. Not all language features might be supported.

It seems to be complaining about the reference modification in accept-record(1:content-length) which is strange because there is another line in the program that uses this also:

move env-value (1:sub1) to content-length

do you also get an error on this line?


[Migrated content. Thread originally posted on 05 March 2012]

Program:

000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. TESTE1.
000030
000040 ENVIRONMENT DIVISION.
000050
000060 DATA DIVISION.
000070
000080 PROCEDURE DIVISION.
000090 PARA-1.
000100 DISPLAY "Content-Type: text/html ".
000110 DISPLAY "".
000120 DISPLAY "".
000130 DISPLAY "<html><body><h3>Teste Cobol-CGI</h3></body></html>".
000140 STOP RUN.

This program when called via CGI generates the following error:

Erro interno do Servidor!

O servidor encontrou um erro interno e não pode completar sua requisição.

Mensagem de Erro:
Premature end of script headers: TESTE1.EXE

Se você acredita ter encontrado um problema no servidor, por favor entre em contato com o webmaster.
Error 500
localhost
03/05/12 15:52:51
Apache/2.2.21 (Win32) PHP/5.3.9


As I compiled the program:



The same program compiled with openCobol does not generate the error.

Can anyone help me?

Edgar originally wrote:
COBSW= S5 and DISPLAY "" UPON CONSOLE not work.


They don't work in what sense? What did you do?

For COBSW= S5 to work, it has to be set in the CGI program's environment, which means it has to be set in the HTTP server process environment. On Windows, that generally means that it will have to be set in the system environment, and you'll likely have to reboot after setting it there to ensure the HTTP server gets it.

That's one reason why using library call x"a7", as in the sample program, is a better idea.

I'm not sure that the UPON CONSOLE phrase has any effect in this particular case - I believe a plain ANSI DISPLAY statement with S5 set (or, better, after calling x"a7") will write to stdout with or without UPON CONSOLE specified. But since you're using such an old COBOL product it's hard to know for sure. (I just tried it in Studio EE 6.0 SP2 WS2, and a plain DISPLAY writes to stdout even without S5 or x"a7".)

[Migrated content. Thread originally posted on 05 March 2012]

Program:

000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. TESTE1.
000030
000040 ENVIRONMENT DIVISION.
000050
000060 DATA DIVISION.
000070
000080 PROCEDURE DIVISION.
000090 PARA-1.
000100 DISPLAY "Content-Type: text/html ".
000110 DISPLAY "".
000120 DISPLAY "".
000130 DISPLAY "<html><body><h3>Teste Cobol-CGI</h3></body></html>".
000140 STOP RUN.

This program when called via CGI generates the following error:

Erro interno do Servidor!

O servidor encontrou um erro interno e não pode completar sua requisição.

Mensagem de Erro:
Premature end of script headers: TESTE1.EXE

Se você acredita ter encontrado um problema no servidor, por favor entre em contato com o webmaster.
Error 500
localhost
03/05/12 15:52:51
Apache/2.2.21 (Win32) PHP/5.3.9


As I compiled the program:



The same program compiled with openCobol does not generate the error.

Can anyone help me?

Chris I made the changes because of the error that the compiler presented. I can not explain the cause of the error, but it was only in this line.

Michael even with the environment variable "COBSW" set the program still displays the error: Premature end of script headers


[Migrated content. Thread originally posted on 05 March 2012]

Program:

000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. TESTE1.
000030
000040 ENVIRONMENT DIVISION.
000050
000060 DATA DIVISION.
000070
000080 PROCEDURE DIVISION.
000090 PARA-1.
000100 DISPLAY "Content-Type: text/html ".
000110 DISPLAY "".
000120 DISPLAY "".
000130 DISPLAY "<html><body><h3>Teste Cobol-CGI</h3></body></html>".
000140 STOP RUN.

This program when called via CGI generates the following error:

Erro interno do Servidor!

O servidor encontrou um erro interno e não pode completar sua requisição.

Mensagem de Erro:
Premature end of script headers: TESTE1.EXE

Se você acredita ter encontrado um problema no servidor, por favor entre em contato com o webmaster.
Error 500
localhost
03/05/12 15:52:51
Apache/2.2.21 (Win32) PHP/5.3.9


As I compiled the program:



The same program compiled with openCobol does not generate the error.

Can anyone help me?

Chris I made the changes because of the error that the compiler presented. I can not explain the cause of the error, but it was only in this line.

Michael even with the environment variable "COBSW" set the program still displays the error: Premature end of script headers


[Migrated content. Thread originally posted on 05 March 2012]

Program:

000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. TESTE1.
000030
000040 ENVIRONMENT DIVISION.
000050
000060 DATA DIVISION.
000070
000080 PROCEDURE DIVISION.
000090 PARA-1.
000100 DISPLAY "Content-Type: text/html ".
000110 DISPLAY "".
000120 DISPLAY "".
000130 DISPLAY "<html><body><h3>Teste Cobol-CGI</h3></body></html>".
000140 STOP RUN.

This program when called via CGI generates the following error:

Erro interno do Servidor!

O servidor encontrou um erro interno e não pode completar sua requisição.

Mensagem de Erro:
Premature end of script headers: TESTE1.EXE

Se você acredita ter encontrado um problema no servidor, por favor entre em contato com o webmaster.
Error 500
localhost
03/05/12 15:52:51
Apache/2.2.21 (Win32) PHP/5.3.9


As I compiled the program:



The same program compiled with openCobol does not generate the error.

Can anyone help me?

Chris I made the changes because of the error that the compiler presented. I can not explain the cause of the error, but it was only in this line.

Michael even with the environment variable "COBSW" set the program still displays the error: Premature end of script headers