Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MS Cobol 5.0 and CGI

22 views
Skip to first unread message

Salvatore De Salve

unread,
Feb 12, 2002, 3:10:32 AM2/12/02
to
Hi,

I need to write a cgi in MS Cobol 5.0, then I write this source:

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.
AUTHOR. Cobra.
SPECIAL-NAMES.
DECIMAL-POINT IS COMMA.

DATA DIVISION.

PROCEDURE DIVISION.
****************************************
Main-Line.
DISPLAY "<HTML>".
DISPLAY " <HEAD>".
DISPLAY " <meta name='Author' content='Cobra82'>".
DISPLAY " </HEAD>".
DISPLAY " <BODY>".
DISPLAY " Hi from Cobra®".
DISPLAY " </BODY>".
DISPLAY "</HTML>".

End-Main-Line.
Ex-Main-Line.
STOP RUN.
****************************************

this program run in a dos shell but if call it from an html page it
does'nt run!!!

There is someone that can help me???

Hi from Cobra®


--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG

Richard Plinston

unread,
Feb 13, 2002, 2:09:20 AM2/13/02
to
Salvatore De Salve wrote:

> I need to write a cgi in MS Cobol 5.0, then I write this source:

It can work, but to get displays to go to 'stdout' you will need to have
an environment variable COBSW=S5



> IDENTIFICATION DIVISION.
> PROGRAM-ID. HELLO.
> AUTHOR. Cobra.
> SPECIAL-NAMES.
> DECIMAL-POINT IS COMMA.
>
> DATA DIVISION.
>
> PROCEDURE DIVISION.
> ****************************************
> Main-Line.
> DISPLAY "<HTML>".
> DISPLAY " <HEAD>".
> DISPLAY " <meta name='Author' content='Cobra82'>".
> DISPLAY " </HEAD>".
> DISPLAY " <BODY>".
> DISPLAY " Hi from Cobra ".
> DISPLAY " </BODY>".
> DISPLAY "</HTML>".
>
> End-Main-Line.
> Ex-Main-Line.
> STOP RUN.
> ****************************************
>
> this program run in a dos shell but if call it from an html page it
> does'nt run!!!

You are not putting out a content header which is a requirement.

DISPLAY "Content-Type: text/html"
DISPLAY " "

Whether this will work may depend on the web server you use. Some will
not run DOS programs, some will uses files to interface (WIN-CGI). MS
Cobol 5 will allow you to compile 16bit Windows and these will work with
Xitami server (www.xitami.com) on Windows. To make it work as a Windows
program it does need some Windows API bits.

You can also use CobolScript (www.deskware.com) but this is not quite
the same as Cobol and won't, for example, read MS ISAM files.

I have quite large Cobol CGI programs using an equivalent to MS Cobol
4.5 and they run on Windows/Xitami, OS/2/Xitami, DOS/Windows3.1/(forget
the web server name) and recompile for Linux/Apache.

Peter E. C. Dashwood

unread,
Feb 12, 2002, 8:38:53 AM2/12/02
to
The STOP RUN will prevent the Server writing the necessary header to the
Client.

Replace it with an EXIT PROGRAM.

You will also need an HTTP Header with "content type: mime/text".

Finally, are you actually running it in a CGI Environment? Like, you have a
Server or Server Simulator available?

Pete.

Salvatore De Salve <cob...@libero.it> wrote in message
news:3feca20dab38a09665a...@mygate.mailgate.org...

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

ronald leenheer

unread,
Feb 12, 2002, 7:33:31 PM2/12/02
to
Hi,
When you're looking for a great cgi/rpc product take a look at this site:
http://showcase.netins.net/web/etsinc/index.html

I'm using that products on RMcobol for a online ordering system and its easy
to work with.
With the RPC option you'll one machine running as dataserver wher the whole
compagny is working on and another machine as webserver.

Ronald Leenheer

"Salvatore De Salve" <cob...@libero.it> schreef in bericht
news:3feca20dab38a09665a...@mygate.mailgate.org...

Richard Plinston

unread,
Feb 13, 2002, 10:35:01 AM2/13/02
to
Peter E. C. Dashwood wrote:
>
> The STOP RUN will prevent the Server writing the necessary header to the
> Client.
>
> Replace it with an EXIT PROGRAM.

Nonsense. My CGI programs do a STOP RUN and work fine. In fact the
EXIT PROGRAM would act as a no-op and the program would drop-thru to the
end of the source file and terminate as if a STOP RUN had been found
after the source-code.

You are obviously thinking of two other people.

Salvatore De Salve

unread,
Feb 13, 2002, 9:57:53 AM2/13/02
to
I use PWS for WINDOWS 98 SE....

Salvatore De Salve

unread,
Feb 13, 2002, 9:59:26 AM2/13/02
to
Thank's I try as soon as possible....
Hi From Cobra®
:-)

Salvatore De Salve

unread,
Feb 13, 2002, 3:11:08 PM2/13/02
to
Hi
OKKKKKKKKKK!!!!!!!!!!

It's working fine!!! I've installed the xitami WEB server.
The final's source code is:

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.
AUTHOR. Cobra.
SPECIAL-NAMES.
DECIMAL-POINT IS COMMA.

DATA DIVISION.

PROCEDURE DIVISION.
*****************************************************
Main-Line.
DISPLAY "Content-type: text/html".
DISPLAY " ".


DISPLAY "<HTML>".
DISPLAY " <HEAD>".

DISPLAY " <TITLE>Prova CGI Cobol</TITLE>".


DISPLAY " </HEAD>".
DISPLAY " <BODY>".

DISPLAY " Ciao da Cobra©".


DISPLAY " </BODY>".
DISPLAY "</HTML>".

STOP RUN.
*****************************************************

and I've compiled the program with:
cobol hello,,,,

and I've linked the objec's file:
link hello+adis+adisinit+adiskey,,,lcobol+cobapi/nod;

I haven't add the "SET" variable "COBSW=S5" because it preventing the
program run.

Thank's very much and excume for my english!!! ;-)

Salvatore De Salve

unread,
Feb 13, 2002, 5:24:08 PM2/13/02
to
Ok, and now how I can get:
- the request query string?
- the post data sent from a FORM?

Thank's so much.

by Cobra®

Peter E. C. Dashwood

unread,
Feb 13, 2002, 6:09:22 PM2/13/02
to
Richard,

While I have the utmost respect for your knowledge in this area, I can
assure you that with PWS under Win 98, using Fujitsu CGI, the STOP RUN will
behave exactly as described.

(Salvatore has already indicated that he is using PWS under Win 98, as am
I...)

I know this from bitter experience.

You should know from experience that I don't post nonsense.

This post is based on first hand experience. If your experience is
different, then I can only say that the environment must be different.

I had exactly this problem with some CGI code the other day. As soon as the
STOP RUN was changed it then ran properly to conclusion.

Pete.


Richard Plinston <rip...@Azonic.co.nz> wrote in message
news:3C6A87A5...@Azonic.co.nz...

Posted Via Usenet.com Premium Usenet Newsgroup Services

Richard Plinston

unread,
Feb 14, 2002, 1:08:39 PM2/14/02
to
Salvatore De Salve wrote:
>
> Ok, and now how I can get:
> - the request query string?
> - the post data sent from a FORM?
>
> Thank's so much.

Yes, I thought that may be next on the list.

You need to get the environment variables that the Web Server sets:

01 CGI-Environment-Names.
03 N-Query-String PIC X(20) VALUE "QUERY_STRING".
03 N-Auth-Type PIC X(20) VALUE "AUTH_TYPE".
03 N-Content-Encoding PIC X(20) VALUE "CONTENT_ENCODING".
03 N-Content-Length PIC X(20) VALUE "CONTENT_LENGTH".
03 N-Content-Type PIC X(20) VALUE "CONTENT_TYPE".
03 N-GateWay-Interface PIC X(20) VALUE "GATEWAY_INTERFACE".
03 N-HTTP-Accept PIC X(20) VALUE "HTTP_ACCEPT".
03 N-HTTP-Cookie PIC X(20) VALUE "HTTP_COOKIE".
03 N-HTTP-User-Agent PIC X(20) VALUE "HTTP_USER_AGENT".
03 N-Path-Info PIC X(20) VALUE "PATH_INFO".
03 N-Path-Translated PIC X(20) VALUE "PATH_TRANSLATED".
03 N-Referer-URL PIC X(20) VALUE "REFERER_URL".
03 N-Remote-Addr PIC X(20) VALUE "REMOTE_ADDR".
03 N-Remote-Host PIC X(20) VALUE "REMOTE_HOST".
03 N-Remote-User PIC X(20) VALUE "REMOTE_USER".
03 N-Request-Method PIC X(20) VALUE "REQUEST_METHOD".
03 N-Server-Name PIC X(20) VALUE "SERVER_NAME".
03 N-Server-Port PIC X(20) VALUE "SERVER_PORT".
03 N-Server-Protocol PIC X(20) VALUE "SERVER_PROTOCOL".
03 N-Server-Software PIC X(20) VALUE "SERVER_SOFTWARE".
03 N-End PIC X(20) VALUE SPACES.

01 CGI-N-RDF REDEFINES CGI-Environment-Names.
03 N-Environment-Name PIC X(20) OCCURS 21.

01 CGI-Windows-Names.
03 W-Query-String PIC X(20) VALUE "Query String".
03 W-Auth-Type PIC X(20) VALUE "AUTH_TYPE".
03 W-Content-Encoding PIC X(20) VALUE "Content File".
03 W-Content-Length PIC X(20) VALUE "Content Length".
03 W-Content-Type PIC X(20) VALUE "Content Type".
03 W-GateWay-Interface PIC X(20) VALUE "GATEWAY_INTERFACE".
03 W-HTTP-Accept PIC X(20) VALUE "Accept".
03 W-HTTP-Cookie PIC X(20) VALUE "HTTP_COOKIE".
03 W-HTTP-User-Agent PIC X(20) VALUE "HTTP_USER_AGENT".
03 W-Path-Info PIC X(20) VALUE "PATH_INFO".
03 W-Path-Translated PIC X(20) VALUE "PATH_TRANSLATED".
03 W-Referer-URL PIC X(20) VALUE "REFERER_URL".
03 W-Remote-Addr PIC X(20) VALUE "Remote Address".
03 W-Remote-Host PIC X(20) VALUE "Remote Host".
03 W-Remote-User PIC X(20) VALUE "Remote User".
03 W-Request-Method PIC X(20) VALUE "Request Method".
03 W-Server-Name PIC X(20) VALUE "Server Name".
03 W-Server-Port PIC X(20) VALUE "Server Port".
03 W-Server-Protocol PIC X(20) VALUE "SERVER_PROTOCOL".
03 W-Server-Software PIC X(20) VALUE "Server Software".
03 W-End PIC X(20) VALUE SPACES.

01 CGI-W-RDF REDEFINES CGI-Windows-Names.
03 W-Environment-Name PIC X(20) OCCURS 21.

These can be accessed using DISPLAY name UPON ENVIRONMENT-NAME, ACCEPT
value FROM ENVIRONMENT-VALUE, or by using CALL "_EXTNAME" in MS/MF
Cobol.

CGIINPUT.CBL program (old version) attached will help (if attachment
works). Processing the URL query string requires converting '+' to
space, '%nn' to character x"nn" and breaking up the string on &s.

CGIINPUT.CBL

Richard Plinston

unread,
Feb 14, 2002, 1:33:06 PM2/14/02
to
Peter E. C. Dashwood wrote:
>
> While I have the utmost respect for your knowledge in this area, I can
> assure you that with PWS under Win 98, using Fujitsu CGI, the STOP RUN will
> behave exactly as described.

Except, of course, he had indicated he was using a completely different
Cobol (MicroSoft Cobol 5.0) and was not using any form of CGI library,
just attempting to use stdin and stdout.

> I had exactly this problem with some CGI code the other day. As soon as the
> STOP RUN was changed it then ran properly to conclusion.

And, given the program as written, replacing the STOP RUN with an EXIT
PROGRAM will result in _exactly_ what I described, the program dropping
thru all following code until it fell off the end of the source code.

Now I suspect that PWS won't execute a DOS program, and it may use
Win-CGI, which is a file interface, rather than httpd style
stdin/stdout, but given what he is attempting a STOP RUN is appropriate.

If he had been using Fujitsu and its CGI library then you would have
been correct.

Peter E. C. Dashwood

unread,
Feb 14, 2002, 5:57:02 AM2/14/02
to

Richard Plinston <rip...@Azonic.co.nz> wrote in message
news:3C6C02E2...@Azonic.co.nz...

> Peter E. C. Dashwood wrote:
> >
> > While I have the utmost respect for your knowledge in this area, I can
> > assure you that with PWS under Win 98, using Fujitsu CGI, the STOP RUN
will
> > behave exactly as described.
>
> Except, of course, he had indicated he was using a completely different
> Cobol (MicroSoft Cobol 5.0) and was not using any form of CGI library,
> just attempting to use stdin and stdout.
>

Yes, he did and I temporarily missed it...sorry. I was trying to help but I
should've been more careful.

> > I had exactly this problem with some CGI code the other day. As soon as
the
> > STOP RUN was changed it then ran properly to conclusion.
>

I went back and checked this again after seeing the post in this thread. In
the interests of accuracy (and despite my red face...<G>) I have to report
that the STOP RUN I replaced was in a CGI SUBPROGRAM called by CGI code...

I therefore have no reason to believe (now) that a standalone program,
written using Fujitsu V6 CGI code, will behave in any way differently from
what you described, Richard.

> And, given the program as written, replacing the STOP RUN with an EXIT
> PROGRAM will result in _exactly_ what I described, the program dropping
> thru all following code until it fell off the end of the source code.
>

I'm sure you're right, and I can only apologise for getting it wrong. It was
based on my own experience, but that was flawed in this instance.

> Now I suspect that PWS won't execute a DOS program, and it may use
> Win-CGI, which is a file interface, rather than httpd style
> stdin/stdout, but given what he is attempting a STOP RUN is appropriate.
>

Yes, it would seem so.

Pete.

Peter E. C. Dashwood

unread,
Feb 14, 2002, 6:01:08 AM2/14/02
to
Thanks for posting this, Richard.

I have filed it for future reference and found it very interesting as
another aspect of CGI programming.

Pete.

Richard Plinston <rip...@Azonic.co.nz> wrote in message

news:3C6BFD27...@Azonic.co.nz...


----------------------------------------------------------------------------
----


>
> $ SET DE-EDIT"1" BOUND
> IDENTIFICATION DIVISION.
> PROGRAM-ID. CGIInput.
>
> ENVIRONMENT DIVISION.
> DATA DIVISION.
> WORKING-STORAGE SECTION.
> 01 File-Status PIC XX.
> 01 EOF-Flag PIC X.
> 88 EOF VALUE "E".
> 88 NOT-EOF VALUE SPACE.
> 01 EOLN-Flag PIC X.
> 88 EOLN VALUE "E".
> 88 NOT-EOLN VALUE SPACE.
>
> 78 Buffer-Len VALUE 78.
>
> 01 Line-Buffer.
> 03 LB-Char PIC X
> OCCURS Buffer-Len
> INDEXED BY LB.
>
> 01 Env-Name PIC X(50).
> 01 Env-Value PIC X(2000).
>
> 01 ws-pc-area.
> 05 WS-PC-NUM PIC 9(8).
> 05 WS-PC-DATE REDEFINES WS-PC-NUM.
> 10 WS-PC-CC PIC 99.
> 10 WS-PC-YY PIC 99.
> 10 WS-PC-MM PIC 99.
> 10 WS-PC-DD PIC 99.
> 01 WS-PC-BIN PIC S9(9) COMP SYNC.
>
> 01 Clear-To PIC X VALUE SPACE.
> 01 Attribute PIC 99 COMP VALUE 7.
>
> *01 Request-Method PIC X(10).
> 01 Content-Length PIC X(6).
> 01 Content-LengthZ REDEFINES Content-Length
> PIC Z(5)9.
> 01 Content-Size PIC 9(6).
>
> 01 Command-Line-Buffer PIC X(256).
> 01 Request-Buffer PIC X(2000).
>
> 01 Work-Field PIC X(100).
>
> 01 InChar PIC S9(4) COMP.
> 01 OutChar PIC S9(4) COMP.
> 01 C PIC X.
>
> 01 Hex-Value PIC 9(4) COMP.
> 01 Hex-RDF REDEFINES Hex-Value.
> 03 FILLER PIC X.
> 03 Hex-Char PIC X.
> 01 Char-Value PIC 9(4) COMP.
> 01 Char-RDF REDEFINES Char-Value.
> 03 FILLER PIC X.
> 03 Char-Char PIC X.
>
> COPY "CGINames.WS".
>
> LINKAGE SECTION.
>
> COPY "CGIData.WS".
>
> PROCEDURE DIVISION USING CGI-Data.
> Main SECTION.
> Read-CGI-Data-Functions.
>
> MOVE "CGIForm" TO Next-Program
>
> MOVE SPACES TO CGI-Environment-Values
> PERFORM Get-Environ
> VARYING InChar FROM 2 BY 1
> UNTIL N-Environment-Name(InChar) = SPACES
>
> EVALUATE V-Request-Method
> WHEN "GET"
> PERFORM Process-Get
> WHEN "POST"
> PERFORM Process-Post
> WHEN OTHER
> PERFORM CGI-Request-Error
> END-EVALUATE
>
> EXIT PROGRAM
> .
>
> Get-Environ.
>
> MOVE N-Environment-Name(InChar) TO Env-Name
> MOVE SPACES TO Env-Value
> CALL "_EXTNAME"
> USING Env-Name Env-Value
> MOVE Env-Value TO Environment-Value(InChar)
>
> * DISPLAY Env-Name Env-Value
> .
>
> Process-Get.
>
> MOVE "QUERY_STRING" TO Env-Name
> MOVE SPACES TO Request-Buffer
> CALL "_EXTNAME"
> USING Env-Name Request-Buffer
>
> PERFORM Process-Request
> .
>
> Process-Post.
>
> MOVE SPACES TO Request-Buffer
> ACCEPT Request-Buffer FROM CONSOLE
> PERFORM Process-Request
> .
>
> Process-Request.
>
> MOVE V-Content-Length TO Content-Length
> MOVE Content-LengthZ TO Content-Size
>
> MOVE SPACES TO CGI-Table
> MOVE SPACES TO Work-Field
> MOVE 1 TO CGI-Index
> MOVE 1 TO InChar
> MOVE 1 TO OutChar
>
> MOVE "X" TO C
> PERFORM Extract-Data
> * UNTIL InChar > Content-Size
> UNTIL C NOT > SPACE
>
> MOVE CGI-Index TO CGI-Limit
> .
>
> Extract-Data.
>
> MOVE Request-Buffer(InChar:1) TO C
> EVALUATE C
> WHEN "="
> MOVE Work-Field TO CGI-Name(CGI-Index)
> MOVE OutChar TO CGI-NSize(CGI-Index)
> MOVE SPACES TO Work-Field
> MOVE 1 TO OutChar
>
> WHEN "&"
> WHEN SPACE
> MOVE Work-Field TO CGI-Value(CGI-Index)
> MOVE OutChar TO CGI-VSize(CGI-Index)
> MOVE SPACES TO Work-Field
> MOVE 1 TO OutChar
> ADD 1 TO CGI-Index
>
> WHEN "%"
> MOVE ZERO TO Char-Value
>
> MOVE ZERO TO Hex-Value
> ADD 1 TO InChar
> MOVE Request-Buffer(InChar:1) TO Hex-Char
> PERFORM DeHex
> MULTIPLY Hex-Value BY 16
> GIVING Char-Value
>
> MOVE ZERO TO Hex-Value
> ADD 1 TO InChar
> MOVE Request-Buffer(InChar:1) TO Hex-Char
> PERFORM DeHex
> ADD Hex-Value TO Char-Value
>
> IF Char-Value = x"0D"
> MOVE Work-Field TO CGI-Value(CGI-Index)
> MOVE OutChar TO CGI-VSize(CGI-Index)
> MOVE SPACES TO Work-Field
> MOVE 1 TO OutChar
> ADD 1 TO CGI-Index
>
> MOVE "+" TO CGI-Name(CGI-Index)
> MOVE 1 TO CGI-NSize(CGI-Index)
>
> ELSE
> MOVE Char-Char TO Work-Field(OutChar:1)
> ADD 1 TO OutChar
> END-IF
> WHEN "+"
> MOVE SPACE TO Work-Field(OutChar:1)
> ADD 1 TO OutChar
>
> WHEN OTHER
> MOVE C TO Work-Field(OutChar:1)
> ADD 1 TO OutChar
>
> END-EVALUATE
>
> ADD 1 TO InChar
> .
>
> DeHex.
>
> IF Hex-Char NOT < "a"
> SUBTRACT 87 FROM Hex-Value
> ELSE
> IF Hex-Char NOT < "A"
> SUBTRACT 55 FROM Hex-Value
> ELSE
> SUBTRACT 48 FROM Hex-Value
> END-IF
> END-IF
> .
>
> CGI-Request-Error.
>
> MOVE "CGIError" TO Next-Program
> .
>
> * ================================================================
> * (c) Copyright C.scott Services and Azonic Associates 1997
> * End of source program
> * ================================================================

Salvatore De Salve

unread,
Feb 14, 2002, 8:20:59 AM2/14/02
to
Thank's very much.

By Cobra®

0 new messages