The following UCS COBOL sample code shows the use of APIs in OS 2200. For OS 2200, the header files are not required. To build UCS COBOL, build script must include HTTP Client Library. Building and linking of the library for UCS COBOL application varies depending on the OS 2200 machine.
* * This is User Program for calling the HTTP Client Library. * This is calling GETATMS Rest API from * Ebanksamplewebservice Web Service * IDENTIFICATION DIVISION. PROGRAM-ID. USERPROGRAMBANK1. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. UNIVAC-2200. OBJECT-COMPUTER. UNIVAC-2200. SPECIAL-NAMES. PRINTER IS PTR. DATA DIVISION. WORKING-STORAGE SECTION. 01 VERSION PIC X(11). 01 SESSIONS PIC S9(10) usage binary value 0. 01 TIME-OUT PIC S9(10) usage binary value 0. 01 LOG-LEVEL PIC S9(10) usage binary value 0. 01 LOG-FILE PIC X(255). 01 SYNC-MODE PIC S9(10) usage binary value 0. 01 COMAPIMODE PIC X(1). 01 HANDLE PIC S9(18) usage binary value 0. 01 SERVER PIC X(125). 01 PORT-NUM PIC S9(10) usage binary value 0. 01 URL PIC X(255). 01 KEEP-ALIVE PIC S9(10) usage binary value 0. 01 AUTH-TYPE PIC S9(10) usage binary value 0. 01 CREDENTIALS PIC X(255). 01 CALL-ID PIC X(255). 01 SOL-SSL PIC S9(10) usage binary value 0. 01 OPTION PIC S9(10) usage binary value 0. 01 OPTION-VALUE PIC X(30). 01 OPTION-LEN PIC S9(10) usage binary value 0. 01 OPTION-RESULT PIC S9(10) usage binary value 0. 01 REQ-CONTENT PIC X(24250). 01 REQ-CONTENT-LEN PIC S9(10) usage binary value 0. 01 STATUS-CODE PIC S9(10) usage binary value 0. 01 RES-CONTENT PIC X(20000). 01 RES-CONTENT-LEN PIC S9(10) usage binary value 0. 01 REASON PIC X(255). 01 METHOD PIC X(10) VALUE "POST". 01 RESULT PIC S9(10) usage binary value 0. 77 TEMP-INDEX PIC S9(5) BINARY VALUE 0. 77 INDEX1 PIC S9(5) BINARY VALUE 1. 77 RESPONSE-CODE PIC X(15). ********************REQ-EBANKSAMPLEWEBSERVICE******************** 01 REQ-EBANKSAMPLEWEBSERVICE. 03 OPERATIONID PIC X(22). * GetATMS 88 GETATMS VALUE "GETATMS ". 03 REQ-BUFFER PIC X(2403). *****************************GETATMS***************************** * Summary:Get all ATMs * GetATMS 03 GETATMS REDEFINES REQ-BUFFER. 05 FILLER PIC X(2403). ********************RSP-EBANKSAMPLEWEBSERVICE******************** 01 RSP-EBANKSAMPLEWEBSERVICE. 03 RSP-CODE PIC X(30). * GetATMS 88 GET-400-GETATMS VALUE "GET-400-GETATMS ". * GetATMS 88 GET-401-GETATMS VALUE "GET-401-GETATMS ". * GetATMS 88 GET-200-GETATMS VALUE "GET-200-GETATMS ". 03 RSP-BUFFER PIC X(2508). *****************************GETATMS***************************** * Get-400-GetATMS * Description: Bad Request 03 GET-400-GETATMS REDEFINES RSP-BUFFER. 05 LEN-DESCRIPTION PIC 9(5). 05 DESCRIPTION PIC X(100). 05 FILLER PIC X(2403). * Get-401-GetATMS * Description: Unauthorized 03 GET-401-GETATMS REDEFINES RSP-BUFFER. 05 LEN-DESCRIPTION PIC 9(5). 05 DESCRIPTION PIC X(100). 05 FILLER PIC X(2403). * Get-200-GetATMS * Description: Success 03 GET-200-GETATMS REDEFINES RSP-BUFFER. 05 LEN-DESCRIPTION PIC 9(5). 05 DESCRIPTION PIC X(100). * Schema Name: Unisys.eBankSampleWebService.ATM * Description: Unisys-eBankSampleWebServi, Actual elements count * in the array. 05 CNT-UNISYS-EBANKSAMPLEWEBSERVI PIC S9(3). 05 UNISYS-EBANKSAMPLEWEBSERVI OCCURS 10 TIMES. * Description: id, ATM ID 06 ID PIC S9(9). * Description: name, Name 06 LEN-NAME PIC S9(3). 06 NAME PIC X(30). * Description: street, Street 06 LEN-STREET PIC S9(3). 06 STREET PIC X(100). * Description: state, State 06 LEN-STATE PIC S9(3). 06 STATE PIC X(30). * Description: country, Country 06 LEN-COUNTRY PIC S9(3). 06 COUNTRY PIC X(30) VALUE "UNITED STATES". * Schema Name: current * Description: X-current, Time stamp - COBOL keyword 06 X-CURRENT. 08 YEAR PIC 9(4). 08 MONTH PIC 9(2). 08 X-DAY PIC 9(2). 08 X-TIME. 10 HOUR PIC 9(2). 10 MIN PIC 9(2). 10 SEC PIC 9(2). 10 MS PIC 9(2). * Description: zipCode, Zip Code * Pattern: ^\d{5}(-\d{4})?$ 06 LEN-ZIPCODE PIC S9(3). 06 ZIPCODE PIC X(10). ******************EBANKSAMPLEWEBSERVICE-DEFAULT****************** 01 EBANKSAMPLEWEBSERVICE-DEFAULT. 03 RSP-CODE PIC X(30). * HTTP Status Message 03 X-MESSAGE-LEN PIC 9(3). 03 X-MESSAGE PIC X(256). * HTTP Response Code 03 X-CODE PIC 9(3). * Local Response Subcode (Unisys-specific response subcodes) 03 SUBCODE PIC 9(3). * HTTP Response Message 03 RESPONSE-LEN PIC 9(3). 03 RESPONSE PIC X(2560). *****************************MAIN-PROCEDURE***************************** PROCEDURE DIVISION. MAIN-PROCEDURE. GO TO INIT-PROCEDURE. * INIT-PROCEDURE. MOVE 4 TO LOG-LEVEL. MOVE "VERSION 1.0" TO VERSION. MOVE 0 TO SYNC-MODE. MOVE 5000 TO TIME-OUT. MOVE "A" TO COMAPIMODE. MOVE 1 TO SESSIONS. CALL "INITHTTPLIBRARY" USING VERSION SESSIONS TIME-OUT LOG-LEVEL LOG-FILE SYNC-MODE COMAPIMODE RESULT. IF RESULT = 1 GO TO CREATE-PROCEDURE. IF RESULT = 0 THEN DISPLAY "CALL HTTP INITIALIZATION FAILED. ERROR : " RESULT GO TO CLOSELIB-PROCEDURE END-IF. * CREATE-PROCEDURE. MOVE "/api/Ebankrestwebservice/GETATMS" TO URL. MOVE "10.62.156.227" TO SERVER. MOVE 5000 TO PORT-NUM. MOVE 0 TO HANDLE. MOVE "USER:PASS" TO CREDENTIALS. CALL "CREATEHTTPSESSION" USING HANDLE SERVER PORT-NUM URL KEEP-ALIVE AUTH-TYPE CREDENTIALS RESULT. IF RESULT = 1 GO TO SEND-PROCEDURE. IF RESULT = 0 THEN DISPLAY "CALL HTTP SESSION CREATION FAILED. ERROR=" RESULT GO TO CLOSELIB-PROCEDURE END-IF. * SEND-PROCEDURE. MOVE SPACES TO REQ-BUFFER. MOVE "GETATMS " TO OPERATIONID. MOVE 2425 TO REQ-CONTENT-LEN. MOVE REQ-EBANKSAMPLEWEBSERVICE TO REQ-CONTENT. CALL "SENDHTTPREQUEST" USING HANDLE OPERATIONID REQ-CONTENT REQ-CONTENT-LEN STATUS-CODE RESULT. IF RESULT = 1 GO TO RECEIVE-PROCEDURE. IF RESULT = 0 THEN DISPLAY "CALL HTTP SEND REQUEST FAILED. ERROR : " RESULT GO TO CLOSE-PROCEDURE END-IF. * RECEIVE-PROCEDURE. CALL "RECEIVEHTTPRESPONSE" USING HANDLE RES-CONTENT RES-CONTENT-LEN STATUS-CODE REASON RESULT. IF RESULT = 1 GO TO READ-PROCEDURE. IF RESULT = 0 THEN DISPLAY "CALL HTTP RECEIVE REQUEST FAILED. ERROR : " RESULT DISPLAY "REASON : " REASON GO TO CLOSE-PROCEDURE END-IF. * READ-PROCEDURE. MOVE RES-CONTENT TO RSP-EBANKSAMPLEWEBSERVICE. MOVE RSP-CODE OF RSP-EBANKSAMPLEWEBSERVICE TO RESPONSE-CODE. DISPLAY "RESPONSE-CODE = " RESPONSE-CODE. IF RESPONSE-CODE = "GET-400-GETATMS" THEN DISPLAY "DESCRIPTION = " DESCRIPTION OF GET-400-GETATMS OF RSP-EBANKSAMPLEWEBSERVICE END-IF. IF RESPONSE-CODE = "GET-401-GETATMS" THEN DISPLAY "DESCRIPTION = " DESCRIPTION OF GET-401-GETATMS OF RSP-EBANKSAMPLEWEBSERVICE END-IF. IF RESPONSE-CODE = "GET-200-GETATMS" THEN GO TO DISPLAY-PROCEDURE END-IF. GO TO CLOSE-PROCEDURE. * DEFAULT-ERROR-DISPLAY. MOVE RES-CONTENT TO EBANKSAMPLEWEBSERVICE-DEFAULT. DISPLAY "------------ERROR MESSAGE-----------". DISPLAY " ". DISPLAY "RSP-CODE = " RSP-CODE OF EBANKSAMPLEWEBSERVICE-DEFAULT. DISPLAY "X-MESSAGE = " X-MESSAGE OF EBANKSAMPLEWEBSERVICE-DEFAULT. DISPLAY "X-CODE = " X-CODE OF EBANKSAMPLEWEBSERVICE-DEFAULT. DISPLAY "SUBCODE = " SUBCODE OF EBANKSAMPLEWEBSERVICE-DEFAULT. DISPLAY "RESPONSE = " RESPONSE OF EBANKSAMPLEWEBSERVICE-DEFAULT. DISPLAY " ". DISPLAY "----------------DONE----------------". GO TO CLOSE-PROCEDURE. * DISPLAY-PROCEDURE. DISPLAY "------------RESULT------------------". DISPLAY " ". DISPLAY "DESCRIPTION = " DESCRIPTION OF GET-200-GETATMS OF RSP-EBANKSAMPLEWEBSERVICE. DISPLAY "Total Count = " CNT-UNISYS-EBANKSAMPLEWEBSERVI OF GET-200-GETATMS OF RSP-EBANKSAMPLEWEBSERVICE. DISPLAY " ". PERFORM WITH TEST AFTER UNTIL INDEX1 = CNT-UNISYS-EBANKSAMPLEWEBSERVI OF GET-200-GETATMS DISPLAY "ID = " ID OF UNISYS-EBANKSAMPLEWEBSERVI(INDEX1) DISPLAY "NAME = " NAME OF UNISYS-EBANKSAMPLEWEBSERVI(INDEX1) DISPLAY "CITY = " STREET OF UNISYS-EBANKSAMPLEWEBSERVI(INDEX1) DISPLAY "STATE = " STATE OF UNISYS-EBANKSAMPLEWEBSERVI(INDEX1) DISPLAY "COUNTRY = " COUNTRY OF UNISYS-EBANKSAMPLEWEBSERVI(INDEX1) DISPLAY "ZIPCODE = " ZIPCODE OF UNISYS-EBANKSAMPLEWEBSERVI(INDEX1) DISPLAY "YEAR = " YEAR OF X-CURRENT OF UNISYS-EBANKSAMPLEWEBSERVI(INDEX1) DISPLAY "MONTH = " MONTH OF X-CURRENT OF UNISYS-EBANKSAMPLEWEBSERVI(INDEX1) DISPLAY "X-DAY = " X-DAY OF X-CURRENT OF UNISYS-EBANKSAMPLEWEBSERVI(INDEX1) DISPLAY "HOUR = " HOUR OF X-TIME OF X-CURRENT OF UNISYS-EBANKSAMPLEWEBSERVI(INDEX1) DISPLAY "MIN = " MIN OF X-TIME OF X-CURRENT OF UNISYS-EBANKSAMPLEWEBSERVI(INDEX1) DISPLAY "SEC = " SEC OF X-TIME OF X-CURRENT OF UNISYS-EBANKSAMPLEWEBSERVI(INDEX1) DISPLAY "MS = " MS OF X-TIME OF X-CURRENT OF UNISYS-EBANKSAMPLEWEBSERVI(INDEX1) ADD 1 TO INDEX1 DISPLAY " " END-PERFORM. DISPLAY "------------RESULT DONE-------------". GO TO CLOSE-PROCEDURE. * CLOSE-PROCEDURE. CALL "DESTROYHTTPSESSION" USING HANDLE RESULT. IF RESULT = 0 DISPLAY "CALL HTTP SESSION DESTROY FAILED. ERROR : " RESULT. GO TO CLOSELIB-PROCEDURE. * CLOSELIB-PROCEDURE. CALL "CLOSEHTTPLIBRARY" USING RESULT. IF RESULT = 0 DISPLAY "CALL HTTP CLOSE LIBRARY FAILED. ERROR : " RESULT. STOP RUN.