The following COBOL sample code shows the use of APIs in MCP.
The COBOL85 (SYMBOL/EPORTAL/OUTBOUND/INCLUDE) include file is provided and the file must be included in the COBOL file. Building and linking of the library for COBOL application vary depending on the MCP machine.
* * This is User Program for calling the WEBAPPSUPPORT Library. * IDENTIFICATION DIVISION. PROGRAM-ID. USERPROGRAM. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 77 LOG-LEVEL PIC 9(11) BINARY. 77 SYNC-MODE PIC S9(11) BINARY VALUE IS 0. 01 REQ-CONTENT PIC X(10000). 77 REQ-CONTENT-LEN PIC 9(11) BINARY. 77 PORT-NUM PIC 9(11) BINARY. 01 SERVER PIC X(50). 01 BASE-PATH PIC X(255). 01 OPERATION-ID PIC X(255). 01 RES-CONTENT PIC X(100000). 77 RES-CONTENT-LEN PIC 9(11) BINARY. 77 STATUS-CODE PIC 9(11) BINARY. 77 AUTH-TYPE PIC 9(11) BINARY VALUE IS 0. 01 CREDENTIALS PIC X(255). 77 SOL-SSL PIC 9(11) BINARY. 77 OPTION PIC 9(11) BINARY. 77 OPTION-VALUE PIC X(30). 77 OPTION-LEN PIC 9(11) BINARY. 77 OPTION-RESULT PIC S9(11) BINARY. 77 VERSION PIC S9(11) BINARY VALUE 4. 77 MAX-SESSIONS PIC S9(11) BINARY VALUE 2. 01 REASON PIC X(255). 77 RESULT PIC S9(11) BINARY. 77 CLIENT-HANDLE PIC 9(11) BINARY. 77 HOST-HANDLE PIC 9(11) BINARY. 77 SOCKET-HANDLE-1 PIC 9(11) BINARY. 77 REQUEST-HANDLE-1 PIC 9(11) BINARY. 77 SOCKET-HANDLE-2 PIC 9(11) BINARY. 77 REQUEST-HANDLE-2 PIC 9(11) BINARY. 77 TIME-OUT PIC 9(11) BINARY VALUE 15. 01 KEEP-ALIVE PIC X(10) VALUE "Keep-Alive". 01 LOG-FILE PIC X(255). * Sample PayLOAD * OutBound Service Base Path: /api/AirportsAPIV2/ * Example: * Path: /api/AirportsAPIV2/{OPERATIONID} ************************REQ-AIRPORTSAPIV2*********************** * * 01 REQ-AIRPORTSAPIV2. 03 OPERATIONID PIC X(26). 88 X-58D8BCB7A9E6240E200CFF25 VALUE "X-58D8BCB7A9E6240E200CFF25". 03 REQ-BUFFER PIC X(412). ********************X-58D8BCB7A9E6240E200CFF25****************** * ** * Summary: Airport by id. * X-58d8bcb7a9e6240e200cff25 * Description: Retrieve airport by id. 03 X-58D8BCB7A9E6240E200CFF25 REDEFINES REQ-BUFFER. * Description: id, Airport code (3-character IATA code). * The parameter ID is required 05 LEN-ID PIC S9(3). 05 ID PIC X(100). 05 FILLER PIC X(309). ************************RSP-AIRPORTSAPIV2*********************** * * 01 RSP-AIRPORTSAPIV2. 03 RSP-CODE PIC X(30). * 58d8bcb7a9e6240e200cff25 88 GET-200-58D8BCB7A9E6240E20-1 VALUE "GET-200-58D8BCB7A9E6240E20-1 ". * 58d8bcb7a9e6240e200cff25 88 GET-400-58D8BCB7A9E6240E20-1 VALUE "GET-400-58D8BCB7A9E6240E20-1 ". * 58d8bcb7a9e6240e200cff25 88 GET-500-58D8BCB7A9E6240E20-1 VALUE "GET-500-58D8BCB7A9E6240E20-1 ". 03 RSP-BUFFER PIC X(99708). ********************X-58D8BCB7A9E6240E200CFF25****************** * ** * Get-200-58d8bcb7a9e6240e20-1 * Description: OK 03 GET-200-58D8BCB7A9E6240E20-1 REDEFINES RSP-BUFFER. 05 LEN-DESCRIPTION PIC 9(5). 05 DESCRIPTION PIC X(100). * Description: city, City where the airport is located. 05 LEN-CITY PIC S9(3). 05 CITY PIC X(100). 05 COUNTRY. * Schema Name: code 07 LEN-X-CODE PIC S9(3). 07 X-CODE PIC X(100). 07 LEN-NAME PIC S9(3). 07 NAME PIC X(100). 05 GEOCOORDINATES. 07 LATITUDE PIC S9(18)V9(5). 07 LONGITUDE PIC S9(18)V9(5). * Description: id, Unique identifier. 05 LEN-ID PIC S9(3). 05 ID PIC X(100). 05 INBOUNDROUTES. 07 LEN-HREF PIC S9(3). 07 HREF PIC X(100). * Schema Name: name * Description: name-1, Name of the airport. 05 LEN-NAME-1 PIC S9(3). 05 NAME-1 PIC X(100). 05 OUTBOUNDROUTES. * Schema Name: href 07 LEN-HREF-1 PIC S9(3). 07 HREF-1 PIC X(100). 05 FILLER PIC X(98836). * Get-400-58d8bcb7a9e6240e20-1 * Description: BadRequest 03 GET-400-58D8BCB7A9E6240E20-1 REDEFINES RSP-BUFFER. 05 LEN-DESCRIPTION PIC 9(5). 05 DESCRIPTION PIC X(100). * Description: errorMessages, Actual elements count in the * array. 05 CNT-ERRORMESSAGES PIC S9(3). 05 ERRORMESSAGES OCCURS 10 TIMES. 06 ERRORMESSAGES PIC X(100). 06 LEN-ERRORMESSAGES PIC S9(3). 05 FILLER PIC X(98570). * Get-500-58d8bcb7a9e6240e20-1 * Description: InternalServerError 03 GET-500-58D8BCB7A9E6240E20-1 REDEFINES RSP-BUFFER. 05 LEN-DESCRIPTION PIC 9(5). 05 DESCRIPTION PIC X(100). 05 LEN-ERRORMESSAGE PIC S9(3). 05 ERRORMESSAGE PIC X(100). 05 LEN-REFERENCEID PIC S9(3). 05 REFERENCEID PIC X(100). 05 FILLER PIC X(99397). ********************AIRPORTSAPIV2-DEFAULT-RSP******************* * * 01 AIRPORTSAPIV2-DEFAULT-RSP. 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). * auto-generated Cobol Payload Ends * * * Assing the Values * LOCAL-STORAGE SECTION. COPY INCLUDE OF OUTBOUND OF EPORTAL OF SYMBOL ON DISK. PROCEDURE DIVISION. MAIN-PROCEDURE. * * Assing the Values for making outboud call * MOVE 1 TO LOG-LEVEL. MOVE 1 TO SYNC-MODE. MOVE 5000 TO PORT-NUM. MOVE "172.22.7.208" TO SERVER. MOVE "/Api/AirportsAPIV2/" TO BASE-PATH. MOVE "X_58D8BCB7A9E6240E200CFF25" TO OPERATION-ID. * * Call the library procedure passing the identifying string * CALL INITHTTPLIBRARY USING VERSION, TIME-OUT, LOG-LEVEL, LOG-FILE, SYNC-MODE GIVING RESULT. IF RESULT = 1 THEN CALL CREATEHTTPSESSION USING CLIENT-HANDLE, HOST-HANDLE, SERVER, PORT-NUM, BASE-PATH, KEEP-ALIVE, AUTH-TYPE, CREDENTIALS GIVING RESULT IF RESULT = 1 THEN * * Assing the values to RSP-AIRPORTSAPIV2 payload For * Socket/Request 1 * MOVE "BCN " TO ID OF X-58D8BCB7A9E6240E200CFF25 MOVE 5000 TO REQ-CONTENT-LEN MOVE "X-58D8BCB7A9E6240E200CFF25" TO OPERATIONID MOVE REQ-AIRPORTSAPIV2 TO REQ-CONTENT CALL SENDHTTPREQUEST USING SOCKET-HANDLE-1, CLIENT-HANDLE, HOST-HANDLE, REQUEST-HANDLE-1, OPERATION-ID, REQ-CONTENT, REQ-CONTENT-LEN GIVING RESULT IF RESULT = 1 THEN Display "First Request Succesfull. ID= BCN" ELSE DISPLAY "Call Http request Failed. Error="RESULT END-IF * * Assing the values to RSP-AIRPORTSAPIV2 payload For * Socket/Request 2 * MOVE SPACES TO REQ-AIRPORTSAPIV2 MOVE SPACES TO REQ-CONTENT MOVE "ACE " TO ID OF X-58D8BCB7A9E6240E200CFF25 MOVE 5000 TO REQ-CONTENT-LEN MOVE "X-58D8BCB7A9E6240E200CFF25" TO OPERATIONID MOVE REQ-AIRPORTSAPIV2 TO REQ-CONTENT CALL SENDHTTPREQUEST USING SOCKET-HANDLE-2, CLIENT-HANDLE, HOST-HANDLE, REQUEST-HANDLE-2, OPERATION-ID, REQ-CONTENT, REQ-CONTENT-LEN GIVING RESULT IF RESULT = 1 THEN Display "Second Request Succesfull. ID = ACE" ELSE DISPLAY "Call Http request Failed. Error="RESULT END-IF *Poll for the response to come from Session 1 PERFORM WITH TEST AFTER UNTIL RESULT NOT = -83 CALL RECEIVEHTTPRESPONSE USING SOCKET-HANDLE-2, REQUEST-HANDLE-2, RES-CONTENT, RES-CONTENT-LEN, STATUS-CODE, REASON GIVING RESULT IF RESULT = 1 THEN DISPLAY "Response received." DISPLAY "STATUS-CODE : " STATUS-CODE MOVE RES-CONTENT TO RSP-AIRPORTSAPIV2 IF STATUS-CODE = 200 THEN DISPLAY "DESCRIPTION=" DESCRIPTION OF GET-200-58D8BCB7A9E6240E20-1 DISPLAY "CITY=" CITY OF GET-200-58D8BCB7A9E6240E20-1 DISPLAY "X-CODE=" X-CODE OF GET-200-58D8BCB7A9E6240E20-1 DISPLAY "LATITUDE=" LATITUDE OF GET-200-58D8BCB7A9E6240E20-1 DISPLAY "LONGITUDE=" LONGITUDE OF GET-200-58D8BCB7A9E6240E20-1 ELSE DISPLAY RSP-AIRPORTSAPIV2 END-IF END-IF END-PERFORM CALL DESTROYHTTPREQUEST USING REQUEST-HANDLE-2 GIVING RESULT CALL DESTROYHTTPSOCKET USING SOCKET-HANDLE-2 GIVING RESULT *Clear MOVE SPACES TO RES-CONTENT MOVE SPACES TO RSP-AIRPORTSAPIV2 *Poll for the response to come from Session 2 PERFORM WITH TEST AFTER UNTIL RESULT NOT = -83 CALL RECEIVEHTTPRESPONSE USING SOCKET-HANDLE-1, REQUEST-HANDLE-1, RES-CONTENT, RES-CONTENT-LEN, STATUS-CODE, REASON GIVING RESULT DISPLAY STATUS-CODE IF RESULT = 1 THEN DISPLAY "Response received." DISPLAY "STATUS-CODE : " STATUS-CODE MOVE RES-CONTENT TO RSP-AIRPORTSAPIV2 IF STATUS-CODE = 200 THEN DISPLAY "DESCRIPTION=" DESCRIPTION OF GET-200-58D8BCB7A9E6240E20-1 DISPLAY "CITY=" CITY OF GET-200-58D8BCB7A9E6240E20-1 DISPLAY "X-CODE=" X-CODE OF GET-200-58D8BCB7A9E6240E20-1 DISPLAY "LATITUDE=" LATITUDE OF GET-200-58D8BCB7A9E6240E20-1 DISPLAY "LONGITUDE=" LONGITUDE OF GET-200-58D8BCB7A9E6240E20-1 ELSE DISPLAY RSP-AIRPORTSAPIV2 END-IF END-IF END-PERFORM CALL DESTROYHTTPREQUEST USING REQUEST-HANDLE-1 GIVING RESULT CALL DESTROYHTTPSOCKET USING SOCKET-HANDLE-1 GIVING RESULT ELSE DISPLAY "Failed to Create Session. Error=" RESULT END-IF CALL CLOSEHTTPLIBRARY USING CLIENT-HANDLE, HOST-HANDLE GIVING RESULT ELSE DISPLAY "Intialization of WebAPPSupport Failed. Error=" RESULT END-IF. STOP RUN.