Verizon Service Corp.

12470 Telecom Drive, DC R2A Temple Terrace, Florida 33637 Phone: 813-978-5250 Intranet: http://tels.verizon.com

Published by...

COBOL for the Web
"Copyright © 2003 by Verizon Service Corp. All Rights Reserved." June 2003 This documentation contains material that is the proprietary property of and confidential to Verizon Service Corp. Disclosure outside Verizon is prohibited except by license agreement or other confidentiality agreement.

COBOL for the Web • Page 1.1

Document Conventions
CHARACTERIST MEANING/EXAMPLE: IC:
Bold type • New terminology used the first time. • Words/lines of code or instructor notes within code examples. • Characters or commands that the student types. • Navigation buttons, menus, textboxes, etc., that appear on screen. • Shortcut text for menu navigation:

Insert  Picture  From File  type file name

Italics type

• Placeholder for variable information and names. • Acronyms or uppercase-sensitive code. • Example programs, program fragments and names of userdefined functions.

• Book titles.

UPPERCASE

Mono-space (Letter Gothic font)

• File and folder names. • Screen text.

COBOL for the Web • Page 1.2

<Enter>, <F6>, <Ctrl+D>

• Indicates the key(s) to press: Key1 + Key2 …means press Key1 and Key2 simultaneously Key1, Key2 …means press Key1, then Key2

COBOL for the Web • Page 1.3

.............................2 COBINPG................................................................................0 COMPILE CONSIDERATIONS................................................. 35 4.. 40 4..................................................0 CALLING REXX...........59 5.........................................................................16 3......................................................5 Dynamic File Allocation Using an Environment Variable.........5........................................................................................29 3.............Data Calling COBOL Example.................................................................................0 OVERVIEW...............62 5...................4 Processing Line Sequential (HFS) Files in COBOL.............................................1 DISPLAY...............................38 4........................................................................................................3 UNIX/POSIX Functions.............13 3.........................2 Line-sequential (HFS) File Allocation.............5 2.............................................................................................................................24 3.........................................................3 Program COBWEB: COBOL as CGI Example.....4...........................................................4................................................................. 8 3...........8 3.....................................................45 5............1 Dataset Allocation...........................................................................................................................0 NET...............................................................................................................................DATA COBOL FUNCTION BLOCK...............................1 Getting the Address.......................................................................................................2 Allocating Line Sequential Files in JCL..........................................................................COBOL FOR THE WEB TABLE OF CONTENTS 1.......................................... 9 3....................................................0 I/O............................7 3........1 The Function Block and Passing Parameters.2 Net.........................................1 Control Characters ......................................2 ACCEPT........................................4..............................................................................................................................5..................................................................58 COBOL for the Web • Page 1.......................4 ................................. 42 4.............10 3.................................14 3............... 31 3..................3 COBOL Source for Processing HFS Files...............................................................................

. meaning that a Net. ASSIGN. permitting dynamic file allocation by means of an environment variable named in SELECT .Data has been updated to allow the coding of a COBOL function block. Net.0 Overview ♦ Beginning with COBOL for OS/390. ACCEPT can read from stdin and DISPLAY can write to stdout. including passing data back and forth. and spawn(). linking.5 .Data macro can invoke a COBOL executable directly. ♦ Beginning with DB2 UDB for OS/390 v. • Toleration of fork(). IBM has made several enhancements to COBOL to make it useful as a web (CGI) language: • Support for compiling. COBOL for the Web • Page 1. and the ability to call UNIX/POSIX functions. When running under USS. 7. with COBOL files able to reside in the HFS (hierarchical file system). exec().1. with records delimited by the new-line character. • Enhanced input-output function. . • Support for line-sequential file organization for accessing HFS files that contain text data. and executing in the OS/390 UNIX System Services environment.

6 .♦ This paper explains the basics of using COBOL as a web CGI program and the use of a COBOL function block in a Net.Data macro. COBOL for the Web • Page 1.

If the name of the function being called is longer than eight characters and/or in mixed or lower case. getenv()). • Concatenate loadlib to web server’s STEPLIB DD.0 Compile Considerations ♦ Compiling for invocation via Net. ♦ In both cases: • Use the RENT compile option. • If you are calling UNIX/POSIX functions (e. COBOL for the Web • Page 1.Data COBOL function block: • Compile normally into a loadlib. ♦ Compiling for direct invocation by web server as a CGI: • Compile into HFS cgi-bin directory (or directory where executables are stored).g. compile with the NODYNAM and NOCMPR2 compiler options. use the PGMNAME(LONGMIXED) compiler option (not valid when compiling into a PDS).2.7 .

e. ♦ This does NOT work for COBOL executables being run via Net. ♦ This is the default setting for DISPLAY under USS. the browser) using the DISPLAY command. DISPLAY 'HTTP/1.0 200 OK '. the OUTDD() compile option is not needed to direct output to stdout.3. DISPLAY '<H1 ALIGN=CENTER>Hello World</H1>' COBOL for the Web • Page 1. *The X’15’ is the newline character.0 I/O 3.1 DISPLAY ♦ COBOL executed under USS (which includes as a CGI invoked by a web server) can write directly to stdout (i. (See section 5 for more information on running COBOL via Net. which signifies to *the browser the end of the header and start of the data.Data.8 . *The next three lines write the HTTP response header and *a line of HTML code out to the browser. DISPLAY 'Content-Type: text/html' X'15'.Data.) 002400 002410 002415 002420 002430 002500 002600 002700 PROCEDURE DIVISION.

9 . 003700 ACCEPT WS-DATA-STRING-D COBOL for the Web • Page 1.Data. the browser) using the ACCEPT command. the data from 003610 *the form is available from stdin. ♦ This is the default setting for ACCEPT under USS. The next line retrieves 003620 *that data into WS-DATA-STRING-D.e.2 ACCEPT ♦ COBOL executed under USS (which includes as a CGI invoked by a web server) can read directly from stdin (i.3.Data. ♦ This does NOT work for COBOL executables being run via Net. (See section 5 for more information on running COBOL via Net.) 003600 *If this program was invoked with METHOD=POST.

3. COBOL for the Web • Page 1. ♦ Compiler option NODYNAM must be used when compiling COBOL that calls UNIX/POSIX functions. ♦ Traditional MVS load modules can also call UNIX/POSIX functions – they're part of the Language Environment. ♦ Character strings must be passed as BY VALUE pointers to strings. arguments must be passed BY VALUE. ♦ Because these are C functions.3 UNIX/POSIX Functions ♦ COBOL executed under USS (which includes as a CGI invoked by a web server) can call standard UNIX/POSIX functions.10 . ♦ Compiler option PGMNAME(LONGMIXED) must be used if function name is longer than eight characters and/or in mixed or lower case.

3 UNIX/POSIX Functions (continued) 001000 77 WS-PTR POINTER. 002800 SET WS-PTR TO ADDRESS OF REQUEST-METHOD. 003000 SET ADDRESS OF METHOD-STRING TO WS-ENV-PTR.3. 002300 01 DATA-STRING PIC X(5000). 001100 77 WS-ENV-PTR POINTER. 001300 77 QUERY-STRING PIC X(12) VALUE 'QUERY_STRING'. 001900 05 WS-DATA-STRING-L PIC S9(4) COMP. 001200 77 REQUEST-METHOD PIC X(14) VALUE 'REQUEST_METHOD'. 003100 IF METHOD-STRING(1:3) = 'GET' THEN 003200 SET WS-PTR TO ADDRESS OF QUERY-STRING 003210 *GET DATA FROM ENVIRONMENTAL VARIABLE QUERY_STRING. 002200 77 METHOD-STRING PIC X(4). 001800 01 WS-DATA-STRING. 002100 LINKAGE SECTION. 002910 *OBJECT OF SET MUST BE LINKAGE VARIABLE IF NOT A POINTER. 002000 05 WS-DATA-STRING-D PIC X(5000). 002810 *DETERMINE IF PROGRAM CALLED WITH REQUEST METHOD GET OR POST. 002900 CALL 'GETENV' USING BY VALUE WS-PTR RETURNING WS-ENVPTR. 002400 PROCEDURE DIVISION. 003300 CALL 'GETENV' USING BY VALUE WS-PTR RETURNING WS-ENV-PTR 003400 SET ADDRESS OF DATA-STRING TO WS-ENV-PTR COBOL for the Web • Page 1.11 .

COBOL for the Web • Page 1.003500 003600 003700 003800 MOVE DATA-STRING TO WS-DATA-STRING-D ELSE ACCEPT WS-DATA-STRING-D END-IF.12 .

13 . records are placed one after another according to entry order. ♦ Because these are sequential files. ♦ Each record ends with an EBCDIC new-line character (X’15’) or return carriage (X’0D’).4 Processing Line Sequential (HFS) Files in COBOL ♦ Files maintained in the hierarchical file system (HFS).3. ♦ Contain only printable characters and certain control characters as data. which is not included in the length of the record. COBOL for the Web • Page 1.

3.1 Control Characters The control characters shown below are the only characters other than printable characters that line-sequential files can contain.14 . HEX VALUE X’05’ X’0B’ X’0C’ X’0D’ X’0E’ X’0F’ X’15’ X’16’ X’2F’ CONTROL CHARACTER Horizontal Tab Vertical Tab Form Feed Carriage Return DBCS Shift-out DBCS shift-in New-line Backspace Alarm COBOL for the Web • Page 1.4.

COBOL for the Web • Page 1.15 .

and PATHDISP. COBOL for the Web • Page 1. //MASTERFL DD PATH='/VZ/ttgttrg.OCREAT).3.KEEP). a JES statement is needed to ensure that the job runs on the correct machine.2 Allocating Line Sequential Files in JCL ♦ The DD statement specifies PATH=’absolute-path-name’ with optional parameters of PATHOPTS. // PATHOPTS=(ORDONLY.trgfweb1. /*JOBPARM SYSAFF=(system name) such as C7 or TS73.SIXOTH) Note: Because an HFS is specific to the machine on which it exists (not shared DASD). // PATHMODE=(SIRWXU.SIROTH.16 .4.r00v00l0/docs/class/data'.SIXGRP.SIRGRP. PATHMODE. // PATHDISP=(KEEP.

• Job step ends normally (first positional parameter). • Do not code on the following DD statements: o o o o JOBCAT and JOBLIB STEPCAT and STEPLIB SYSABEND SYSMDUMP or SYSUDUMP ♦ PATHDISP specifies the disposition of an HFS file. • Job step ends abnormally (second positional parameter).2 Allocating Line Sequential Files in JCL (continued) ♦ PATH identifies a file in an HFS: • Can contain symbolic parameters. • Is case sensitive.17 .4.3. • Values are: o KEEP o DELETE COBOL for the Web • Page 1.

• KEEP is the default for first positin. Second position defaults to value of first position.

COBOL for the Web • Page 1.18

3.4.2 Allocating Line Sequential Files in JCL (continued) ♦ PATHOPTS specifies the access and status for the HFS file. • You can specify up to 7 options in any order separated by commas, but code only one access option. • Access options: ORDON Opens the file for reading LY OWRON Opens the file for writing LY ORDWR Opens the file for reading and writing ♦ Status options: OAPPEN Appends data to the end of the file D OCREAT If the file does not exist, creates it (directories will NOT be created); if the file exists, uses it (if OEXCL is not also specified) OEXCL If the file does not exist, creates it; if the file already exists,
COBOL for the Web • Page 1.19

abends; OEXCL is ignored if OCREAT is not also specified OTRUN C Specifies that the system is to truncate the file length to zero if the file exists, the file is a regular file, and the file successfully opened with ORDWR or OWRONLY

♦ There are other values that are beyond the scope of this discussion.

COBOL for the Web • Page 1.20

• Values: COBOL for the Web • Page 1.21 .2 Allocating Line Sequential Files in JCL (continued) ♦ PATHMODE specifies the file access attributes (permissions) when creating a new file.3.4.

4. COBOL for the Web • Page 1. • If PATHMODE is omitted when creating a file.22 . permissions are set to 000.SIRUSR SIWUSR SIXUSR SIRWXU SIRGRP SIWGRP SIXGRP SIRWXG SIROTH SIWOTH SIXOTH SIRWXO Owner level read Owner level write Owner level search a directory or execute a file Owner level read/write/search a directory or read/write/execute a file Group level read Group level write Group level search a directory or execute a file Group level read/write/search a directory or read/write/execute a file Other level read Other level write Other level search a directory or execute a file Other level read/write/search a directory or read/write/execute a file 3.2 Allocating Line Sequential Files in JCL (continued) • 14 options in any order separated by commas can be specified.

• PATHMODE is ignored if the file already exists. COBOL for the Web • Page 1.23 .

♦ There are no changes to the corresponding FD statements. SELECT REPORT-FILE ASSIGN REPORTFL ORGANIZATION IS LINE SEQUENTIAL ACCESS MODE IS SEQUENTIAL FILE STATUS IS M-STATUS. ♦ The ASSIGN assignment-name clause must not include an organization field (S.24 .4. ♦ The ACCESS phrase and the FILE STATUS phrase are optional.3.3 COBOL Source for Processing HFS Files ♦ To define a line-sequential file in a COBOL program.or AS-) before the external name. use the FILECONTROL in the ENVIRONMENT DIVISION as follows: FILE-CONTROL. SELECT MASTER-FILE ASSIGN MASTERFL ORGANIZATION IS LINE SEQUENTIAL ACCESS MODE IS SEQUENTIAL FILE STATUS IS M-STATUS. COBOL for the Web • Page 1.

3.25 . • A line-sequential file cannot be opened as I-O. OUTPUT.3 COBOL Source for Processing HFS Files (continued) ♦ OPEN statement: • A line-sequential file can be opened as INPUT. or EXTEND. • EXTEND permits opening the file for output operations. OPEN INPUT MASTER-FILE OUTPUT REPORT-FILE1 EXTEND REPORT-FILE2 COBOL for the Web • Page 1.4. The EXTEND is allowed for sequential file access only if the new data is written in ascending sequence.

COBOL for the Web • Page 1. o The record area is filled.4.3.3 COBOL Source for Processing HFS Files (continued) ♦ READ statement: • Characters in the file record are read one at a time into the record area until one of the following occurs: o A record delimiter (EBCDIC new-line character) is encountered. The delimiter is discarded. The next READ statement reads from the first character of the next record.26 . Any remaining spaces in the record area are padded with blanks.

if signed. • The new-line character is added to end of each output record after removing any trailing blanks.3 COBOL Source for Processing HFS Files (continued) ♦ WRITE statement: • To add records to a line-sequential file. CLOSE MASTER-FILE REPORT-FILE WITH LOCK.3.27 . code CLOSE WITH LOCK clause. open the file as EXTEND. Records will be added immediately after the last record in the file. COBOL for the Web • Page 1. ♦ CLOSE statement: • Disconnects your program from a line-sequential file. • Records written to line-sequential files must contain only USAGE DISPLAY and DISPLAY-1 items. To ensure that the file cannot be opened again while the program is running.4. External decimal data items must be unsigned or declared with the SEPARATE CHARACTER phrase.

4.3 COBOL Source for Processing HFS Files (continued) ♦ Coding Not Supported for Line Sequential Files APPLY WRITE ONLY clause CODE-SET clause DATA RECORDS clause LABEL RECORDS clause LINAGE clause OPEN I-O option PADDING CHARACTER clause RECORD CONTAINS 0 clause RECORD CONTAINS X TO Y CHARACTERS clause RECORD DELIMITER clause RECORDING MODE clause RERUN clause RESERVE clause REVERSED phrase of OPEN statement REWRITE statement VALUE OF clause of file description entry WRITE…AFTER ADVANCING WRITE…AT END-OF-PAGE WRITE…BEFORE ADVANCING COBOL for the Web • Page 1.3.28 .

COBOL for the Web • Page 1. • Dynamic allocation fails. • Environment variable name is the DD name used in the SELECT… ASSIGN TO statement. • Open.29 . read or write. ♦ The COBOL run time de-allocates all dynamic allocations at run unit termination. ♦ File Status 35 results from: • System cannot find the environment variable. ♦ File Status 98 results from: • Not a valid PATH or DSN option. and close just like a dataset or file allocated in JCL.5 Dynamic File Allocation Using an Environment Variable ♦ Sequential datasets and line-sequential (HFS) files can be dynamically allocated in COBOL source code by using the putenv() function to establish an environment variable that identifies a physical dataset or file. • DD statement in execution JCL is not needed.3.

♦ If there is both a JCL DD allocation and a dynamic allocation for the same DD name. the JCL allocation will take precedence.30 . COBOL for the Web • Page 1.

♦ Cannot use a temporary dataset starting with &&.1 Dataset Allocation ♦ For a sequential dataset. the environment variable must contain: • Dataset name fully qualified. • Options following DSN – any order and separated by a comma or by one or more blanks.3.31 .5. COBOL for the Web • Page 1. ♦ Coded in WORKING STORAGE.

mmm) VOL(volumn-serial) UNIT(type) TRACKS CYL KEEP DATACLAS(data-class) DELETE CATALOG UNCATALOG STORCLASS(storage-class) MGMTCLAS(management-class) COBOL for the Web • Page 1.1 Dataset Allocation (continued) ♦ Syntax for dataset allocation parameters: DSN (data set name) (member-name) NEW OLD SHR MOD SPACE(nnn.5.3.32 .

WEBS390. COBOL for the Web • Page 1. 002100 CALL 'PUTENV' USING BY VALUE WS-PTR. 002200 OPEN INPUT FILE-IN. 000300 ENVIRONMENT DIVISION.1 Dataset Allocation (continued) 000100 IDENTIFICATION DIVISION. IBM-370.TRGF0000. 000700 INPUT-OUTPUT SECTION. 001500 WORKING-STORAGE SECTION. 001200 FD FILE-IN 001300 RECORD CONTAINS 80 CHARACTERS.MESSAGE) SHR'. 'DYNAMALL'.5. 001400 01 RECORD-IN PIC X(80). 002000 SET WS-PTR TO ADDRESS OF INPUT-FILE.33 . 001600 77 WS-PTR POINTER. 000500 SOURCE-COMPUTER. 002300 READ FILE-IN. 001000 DATA DIVISION. 001700 77 INPUT-FILE PIC X(48) VALUE 001800 'INFILE=DSN(TTGTTRG. IBM-370.3. 000900 SELECT FILE-IN ASSIGN TO INFILE. 000400 CONFIGURATION SECTION. 000800 FILE-CONTROL. 000200 PROGRAM-ID. 001100 FILE SECTION. 001900 PROCEDURE DIVISION. 000600 OBJECT-COMPUTER.

002400 002500 002600 DISPLAY RECORD-IN. COBOL for the Web • Page 1. GOBACK.34 . CLOSE FILE-IN.

35 .2 Line-sequential (HFS) File Allocation ♦ For a line-sequential file. ♦ Coded in WORKING STORAGE. COBOL for the Web • Page 1.3. the environment variable must contain: • File name fully qualified.5. • No other options.

002600 CLOSE FILE-IN. 'DYNAMALH'. 002100 SET WS-PTR TO ADDRESS OF INPUT-FILE.r00v00l0/text/cgimsg. 001600 WORKING-STORAGE SECTION.3. 000600 OBJECT-COMPUTER. COBOL for the Web • Page 1. IBM-370. 001100 DATA DIVISION. 001800 77 INPUT-FILE PIC X(58) VALUE 001900 'INFILE=PATH(/VZ/ttgttrg. 001700 77 WS-PTR POINTER. 001300 FD FILE-IN 001400 RECORD CONTAINS 80 CHARACTERS. 002200 CALL 'PUTENV' USING BY VALUE WS-PTR. 000500 SOURCE-COMPUTER. 002000 PROCEDURE DIVISION. 002500 DISPLAY RECORD-IN.5. 000900 SELECT FILE-IN ASSIGN TO INFILE 001000 ORGANIZATION IS LINE SEQUENTIAL. 000700 INPUT-OUTPUT SECTION.2 Line-sequential (HFS) File Allocation (continued) 000100 IDENTIFICATION DIVISION.trgfweb1.txt)'. 001200 FILE SECTION. 000300 ENVIRONMENT DIVISION. 000400 CONFIGURATION SECTION. 002400 READ FILE-IN. 000200 PROGRAM-ID. 002300 OPEN INPUT FILE-IN.36 . IBM-370. 001500 01 RECORD-IN PIC X(80). 000800 FILE-CONTROL.

COBOL for the Web • Page 1.37 .002700 GOBACK.

The COBOL could UNSTRING the data returned by the REXX into working storage variables fairly easily.0 Calling REXX ♦ COBOL isn't the greatest when it comes to string manipulation. especially when it comes to REXX passing information back to the calling COBOL program.4. • Drawback for web work.38 .birthdate="01/30/1962" ♦ It would be useful for a COBOL program to be able to call the REXX and pass the URL-encoded string. since data from the browser is URL-encoded name=Bill+Smith&birthdate=01%2f30%2f1962 and must be de-encoded to name=Bill Smith birthdate=01/30/1962 ♦ The TeLS training department has a REXX that does the de-encoding and returns a string name="Bill Smith". ♦ Unfortunately. and receive the de-encoded string back. the ways COBOL and REXX pass data are somewhat different. COBOL for the Web • Page 1.

• That address has to be given to REXX in numeric form (cannot just pass a pointer). meaning it has to know the address in memory of the working storage variable.• Basically. COBOL for the Web • Page 1. it has to put the data directly into the working storage location.39 . the REXX can't just hand something back.

40 .SORCELIB. 77 ITEM USAGE POINTER. SET PTR TO ITEM.1 Getting the Address ♦ In COBOL you can create a pointer variable and set it to the address of a variable in working storage. • But passing a pointer to a REXX won't work. GOBACK. ♦ To get around this. • A pointer cannot be moved into a PIC 9 field. PROCEDURE DIVISION USING BY VALUE ITEM BY REFERENCE PTR. call program ADDROF • Can be found in TTGTTRG. COBOL for the Web • Page 1. 77 PTR USAGE POINTER. and a variable into which it will put that address.4. • ADDROF: LINKAGE SECTION.COBWEB on the C7 machine in Tampa. • Pass it the name of the field in working storage for which you need the address.

COBOL for the Web • Page 1.41 .♦ While you cannot set a pointer to the address of a variable and then move that pointer to a PIC 9 field all in the same COBOL program. you CAN accomplish the same thing by calling ADDROF and let the LE handle the conversion between pointer and PIC 9.

COBWEB.2 COBINPG ♦ COBINPG is a stripped down version of the CGIINPG REXX that you may have learned about in the class S/390 Web Hosting I.REXX on the C7 machine in Tampa.4.42 . ♦ When passing COBOL variables to a REXX. the COBOL variables must have a length component and a data component or the REXX will not read them correctly. • It receives a URL-encoded string and returns a de-encoded version of the data.EXEC. COBOL for the Web • Page 1. • Get a copy from TTGTTRG.

and populates a variable called parmsData with the data in a var1="value1". The first parameter must be in readable hex. /* storage is an external subroutine that will go to the address in the first parameter and bring back the amount of data specified in the second parameter. @p1 = @p1 + 0 /* by adding zero. hence the d2x function. it will put the data in the third parameter in the address of the first parameter.4. convert it from decimal to character.var2="value2". */ call storage d2x(@p1).2). making all of the appropriate substitutions. REXX recognizes @p1 as numeric */ /* Initialize sets up the ASCII-code-to-EBCDIC-character conversion table */ call Initialize /* ProcessParms parses through query_string.2 COBINPG (continued) ♦ COBINPG main procedure: /* receive decimal address into variable @p1 */ @p1 = arg(1).43 . and force a size of two positions (with a leading 0 if needed) – this will populate the length component of the working storage variable */ parmsLength = d2c(length(parmsData). If a third parameter is specified. format */ call ProcessParms /* get the length of parmsData.parmsLength||parmsData. COBOL for the Web • Page 1.. /* receive URL-encoded string into variable query_string */ query_string = arg(2).

return COBOL for the Web • Page 1.44 .

COBOL for the Web • Page 1.4. 01 DATA-STRING PIC X(5000). 05 WS-ADDRESS-D PIC 9(09). 77 QUERY-STRING PIC X(12) VALUE 'QUERY_STRING'. 01 WS-DATA-STRING.45 . DISPLAY 'Content-Type: text/html' X'15'. 77 METHOD-STRING PIC X(4). 05 WS-ADDRESS-L PIC S9(4) COMP VALUE 9. PROCEDURE DIVISION. * write out HTTP response header info DISPLAY 'HTTP/1. 05 WS-DATA-STRING-L PIC S9(4) COMP. LINKAGE SECTION. 01 VAR-LEN PIC 9(4) BINARY.3 Program COBWEB: COBOL as CGI Example WORKING-STORAGE SECTION. 05 WS-DATA-STRING-D PIC X(5000).0 200 OK '. 77 REQUEST-METHOD PIC X(14) VALUE 'REQUEST_METHOD'. 77 WS-ENV-PTR POINTER. 77 WS-BIN-PTR PIC S9(9) BINARY. * write out web page title DISPLAY '<H1 ALIGN=CENTER>Hello World</H1>' * determine the value of the environment variable request_method. 77 WS-PTR POINTER. 01 WS-ADDRESS.

46 . COBOL for the Web • Page 1.* this is needed so that you know whether to get URL-encoded info * from stdin or query_string environment variable. CALL 'GETENV' USING BY VALUE WS-PTR RETURNING WS-ENV-PTR. SET WS-PTR TO ADDRESS OF REQUEST-METHOD.

WS-DATA-STRING. put ws-data-string's address in the data component of ws-address. IF METHOD-STRING(1:3) = 'GET' THEN SET WS-PTR TO ADDRESS OF QUERY-STRING CALL 'GETENV' USING BY VALUE WS-PTR RETURNING WS-ENV-PTR SET ADDRESS OF DATA-STRING TO WS-ENV-PTR MOVE DATA-STRING TO WS-DATA-STRING-D ELSE ACCEPT WS-DATA-STRING-D END-IF. this bit of code calculates its length and populates the length component of of ws-data-string so that it can be passed to the COBINPG REXX. CALL 'COBINPG' USING WS-ADDRESS. WS-BIN-PTR. MOVE WS-BIN-PTR TO WS-ADDRESS-D. COBOL for the Web • Page 1. do the appropriate substituting. CALL 'ADDROF' USING WS-DATA-STRING.47 * * * * * * * * . call COBINPG to read the URL-encoded string from ws-data-string. URL-encoded data is now in ws-data-string-d.3 Program COBWEB: COBOL as CGI Example (continued) SET ADDRESS OF METHOD-STRING TO WS-ENV-PTR.4. MOVE 0 TO WS-DATA-STRING-L INSPECT WS-DATA-STRING-D TALLYING WS-DATA-STRING-L FOR CHARACTERS BEFORE INITIAL X'00' use ADDROF to get the address of ws-data-string. and then return its output right back into ws-data-string.

48 . COBOL for the Web • Page 1. GOBACK.DISPLAY 'WS-DATA-STRING-D: ' WS-DATA-STRING-D(1:WS-DATA-STRING-L).

• The following screen prints show that COBWEB can handle being called with either method. you can use UNSTRING to pull it apart and populate appropriate variables in working storage.3 Program COBWEB: COBOL as CGI Example (continued) ♦ COBWEB was compiled directly into the cgi-bin directory. ♦ Alternatively. • The first form calls COBWEB with METHOD=GET.4. ♦ Once the data has been returned by COBINPG. ♦ A web page was created with two forms on it. • The second form calls COBWEB with METHOD=POST. the REXX can populate each address as it parses the URLencoded string and does its conversions.49 . you could change your copy of COBINPG to return individual values directly into individual working storage variables – pass it the URL-encoded string and as many addresses as there are variables in the string. COBOL for the Web • Page 1.

50 .3 Program COBWEB: COBOL as CGI Example (continued) COBOL for the Web • Page 1.4.

51 .COBOL for the Web • Page 1.

52 .3 Program COBWEB: COBOL as CGI Example (continued) COBOL for the Web • Page 1.4.

COBOL for the Web • Page 1.53 .

3 Program COBWEB: COBOL as CGI Example (continued) COBOL for the Web • Page 1.4.54 .

55 .COBOL for the Web • Page 1.

3 Program COBWEB: COBOL as CGI Example (continued) COBOL for the Web • Page 1.4.56 .

57 .COBOL for the Web • Page 1.

ini file. • To change the default size in the db2www.Data COBOL Function Block ♦ Include the following in your db2www.ini file: ENVIRONMENT (DTW_COBOL) coboldll ( ) ♦ Net.5. add: DTW_COBOL_PARAMETER_BUFFER_SIZE number_of_bytes ♦ The loadlib containing your COBOL executables must be concatenated to the STEPLIB DD of your web server started task.58 .0 Net. COBOL for the Web • Page 1. • The default size of that parameter is 512 bytes.Data strings together all arguments being passed to the COBOL program (separated by HEX low values) into a single parameter.

which is then copied into the corresponding parameter in the function call statement. The value will be passed to the COBOL program.59 . nor does it pass data to the COBOL program. • out – the parameter does not receive a value from the calling statement. The value will be passed to the COBOL program. • inout – the parameter receives a value from the corresponding parameter in the function call statement. It receives a COBOL for the Web • Page 1. but the parameter will NOT receive a value back from the COBOL program.5.1 The Function Block and Passing Parameters ♦ Example: %function (DTW_COBOL) callCOBOL (in fname. inout lname. The parameter will also receive a value back from the COBOL program. out message) returns(newmsg) { %EXEC {COBND %} %} ♦ Be sure to specify a status for the parameters: • in – the parameter receives a value from the corresponding parameter in the function call statement.

which is then copied into the corresponding parameter in the function call statement.value from the COBOL program. COBOL for the Web • Page 1. ♦ The returns parameter receives a value from the COBOL program and returns it as the value of the function.60 .

COBOL for the Web • Page 1. ACCEPT and DISPLAY will not receive or display data from stdin or stdout when the program is called from a Net. ♦ Keep in mind that Net. ♦ Net.Data macro. delimited by HEX low-values) into the inout.5.1 The Function Block and Passing Parameters ♦ The %EXEC command inside the COBOL function block is where you specify the name of the COBOL load module.Data macro and the COBOL program is the only way for the COBOL program to communicate with the Net.Data will take all values being passed to the COBOL program and string them together (separated by a HEX lowvalue) into one parameter. and returns (if present) parameters coded on the function statement.Data then receives a single parameter back from the COBOL program and parses out the included values (again. out. ♦ The single parameter passed between the Net.Data macro.61 . and pass that one parameter to the COBOL program.

Data macro: %define message = "COBOL not yet called.2 Net. inout lname. out message) returns(newmsg) { %EXEC {COBND %} %} %html (start) { <h1> <form method="post" action="report"> First name: <input type=text name=fname maxlength=24><br> Last name: <input type=text name=lname maxlength=24><br> <input type=submit value="Run that COBOL!"></form> </h1> %} %html (report) { <h3>Values prior to call:<br> fname: $(fname)<br> COBOL for the Web • Page 1." %function (DTW_COBOL) callCOBOL (in fname.Data Calling COBOL Example ♦ Net.62 .5.

63 .lname: $(lname)<br> message: $(message)<p> Federal law mandates that all introductory-level training must COBOL for the Web • Page 1.

lname.64 .5.message) <p>Values after the call:<br> fname: $(fname)<br> lname: $(lname)<br> message: $(message)<p> %} COBOL for the Web • Page 1.Data Calling COBOL Example (continued) include the following: @callCOBOL(fname.2 Net.

77 WS-LNAME PIC X(25). IBM-370. UNSTRING LS-ALL-VALUES DELIMITED BY X'00' INTO WS-FNAME WS-LNAME. COBND. OBJECT-COMPUTER. 77 WS-DELIM PIC X(01) VALUE X'00'. MOVE Z'The COBOL load module has executed!' TO WS-MESSAGE. 77 WS-FNAME PIC X(25). MOVE Z'Smith' TO WS-LNAME. IBM-370. SOURCE-COMPUTER. PROGRAM-ID. 77 WS-MESSAGE PIC X(100). INITIALIZE LS-ALL-VALUES.5. PROCEDURE DIVISION USING LS-ALL-VALUES. WORKING-STORAGE SECTION. LINKAGE SECTION.65 . 77 WS-NEWMSG PIC X(100).2 Net. ENVIRONMENT DIVISION. COBOL for the Web • Page 1.Data Calling COBOL Example (continued) ♦ COBOL source code: 000100 000200 000300 000400 000500 000600 000700 000800 000900 001000 001100 001200 001300 001400 001500 001600 001700 001800 001900 002000 002100 IDENTIFICATION DIVISION. CONFIGURATION SECTION. 77 LS-ALL-VALUES PIC X(512). DATA DIVISION.

002200 002300 002400 STRING WS-LNAME DELIMITED BY X'00' WS-DELIM DELIMITED BY SIZE WS-MESSAGE DELIMITED BY X'00' COBOL for the Web • Page 1.66 .

GOBACK.Data Calling COBOL Example (continued) 002500 002600 002700 002800 002900 003000 003100 WS-DELIM DELIMITED BY SIZE 'Hello World (Especially for ' DELIMITED BY SIZE WS-FNAME DELIMITED BY ' ' '!)' DELIMITED BY SIZE WS-DELIM DELIMITED BY SIZE INTO LS-ALL-VALUES.67 .5.2 Net. COBOL for the Web • Page 1.

5.Data Calling COBOL Example (continued) COBOL for the Web • Page 1.68 .2 Net.

69 .Data Calling COBOL Example (continued) COBOL for the Web • Page 1.5.2 Net.

COBOL for the Web • Page 1.70 .

Sign up to vote on this title
UsefulNot useful