├── .github └── dco.yml ├── src ├── package.devc.xml ├── zibmx_dom_stringvalue.doma.xml ├── zif_ibmx_service_arch.intf.xml ├── zibmx_ty_stringvalue.dtel.xml ├── zcx_ibmx_service_exception.clas.xml ├── zibmx_ty_instance_uid.dtel.xml ├── zcl_ibmx_util.clas.xml ├── zcx_ibmx_service_exception.clas.abap ├── zibmx_config.tabl.xml ├── zcl_ibmx_service_ext.clas.xml ├── zibmx_token.tabl.xml ├── zcl_ibmx_service_arch.clas.xml ├── zif_ibmx_service_arch.intf.abap ├── zcl_ibmx_service.clas.xml ├── zibmx.msag.xml ├── zcl_ibmx_watsonx_ai_ml_v1.clas.xml ├── zcl_ibmx_wml_v4.clas.xml └── zcl_ibmx_util.clas.abap ├── docs ├── ABAPDoc │ ├── readme.txt │ ├── htmldesign │ │ └── stylesheet.css │ └── abapdoc │ │ └── zibmx │ │ ├── classes │ │ ├── zcx_ibmx_service_exception.html │ │ ├── zcl_ibmx_util.html │ │ ├── zcl_ibmx_service_ext.html │ │ └── zcl_ibmx_service_arch.html │ │ └── interfaces │ │ └── zif_ibmx_service_arch.html └── index.html ├── .abapgit.xml ├── MIGRATION-V1.5.0.md ├── LICENSE └── README.md /.github/dco.yml: -------------------------------------------------------------------------------- 1 | # This enables DCO bot for you, please take a look https://github.com/probot/dco 2 | # for more details. 3 | require: 4 | members: false 5 | -------------------------------------------------------------------------------- /src/package.devc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ABAP SDK for IBM watsonx 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /docs/ABAPDoc/readme.txt: -------------------------------------------------------------------------------- 1 | Content of this folder: 2 | 3 | ./abapdoc/ 4 | 5 | Contains the exported documentation for the selected classes and interfaces. Each object is stored in its ABAP package e.g. 6 | 7 | +---package 8 | \---subpackage 9 | \---classes 10 | \---cl_abap_class 11 | 12 | 13 | ./htmldesign/ 14 | 15 | Contains the html stylesheet. It can be used to change the design of the generated documentation. -------------------------------------------------------------------------------- /src/zibmx_dom_stringvalue.doma.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ZIBMX_DOM_STRINGVALUE 7 | E 8 | STRG 9 | X 10 | Case-sensitive string value 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/zif_ibmx_service_arch.intf.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ZIF_IBMX_SERVICE_ARCH 7 | E 8 | IBM Watson SDK Platform-specifics 9 | 2 10 | 1 11 | X 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /.abapgit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | E 6 | /src/ 7 | PREFIX 8 | 9 | /.gitignore 10 | /LICENSE 11 | /README.md 12 | /package.json 13 | /.travis.yml 14 | /.gitlab-ci.yml 15 | /abaplint.json 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/zibmx_ty_stringvalue.dtel.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ZIBMX_TY_STRINGVALUE 7 | E 8 | ZIBMX_DOM_STRINGVALUE 9 | 55 10 | 10 11 | 20 12 | 40 13 | Case-sensitive string value 14 | Value 15 | Value 16 | Value 17 | Value 18 | E 19 | D 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/zcx_ibmx_service_exception.clas.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ZCX_IBMX_SERVICE_EXCEPTION 7 | E 8 | IBM Cloud Service Exception 9 | 40 10 | 1 11 | X 12 | X 13 | X 14 | 15 | 16 | 17 | ZCX_IBMX_SERVICE_EXCEPTION 18 | CONSTRUCTOR 19 | E 20 | CONSTRUCTOR 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/zibmx_ty_instance_uid.dtel.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ZIBMX_TY_INSTANCE_UID 7 | E 8 | 55 9 | 10 10 | 20 11 | 40 12 | Instance GUI 13 | Instance UID 14 | Instance 15 | Instance UID 16 | Instance UID 17 | E 18 | CHAR 19 | 000032 20 | 000032 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Reference ABAP SDK for IBM watsonx 6 | 7 | 8 | 9 |

ABAP SDK for IBM watsonx: API Reference

10 |
11 | The ABAP® SDK is used to consume IBM® 12 | watsonx cognitive services with the SAP® Business 13 | Suite, SAP S/4HANA® and the SAP BTP ABAP 14 | Environment.
15 |
16 |
17 | It wraps the IBM watsonx service REST API into regular ABAP 18 | classes and delivers ABAP data types that exactly fit the IBM 19 | watsonx interface. 20 |
21 |
22 |
23 | The table below provides an overview of the supported IBM 24 | watsonx services. Click the ABAP class name to navigate to the 25 | corresponding methods and data types reference. 26 |
27 |

28 | 29 | 30 | 31 | 32 |
watsonx ServiceVersionABAP Class Name
watsonx.ai Runtime (formerly: Watson Machine Learning)V4ZCL_IBMX_WML_V4
watsonx.aiV1ZCL_IBMX_WATSONX_AI_ML_V1
33 | 34 | 35 | -------------------------------------------------------------------------------- /MIGRATION-V1.5.0.md: -------------------------------------------------------------------------------- 1 | # Upgrading to ABAP SDK version 1.5.0 2 | 3 | **Note**: If migrating from a version less than v1.4.0, also see 4 | [Upgrading to ABAP SDK version 1.4.0](https://github.com/IBM/abap-sdk-nwas-x/blob/1.4.0/MIGRATION-V1.4.0.md). 5 | 6 |
7 | Table of Contents 8 | 9 | - [Breaking changes by service](#breaking-changes-by-service) 10 | - [New features by service](#new-features-by-service) 11 | - [watsonx.ai](#watsonxai) 12 | - [watsonx.ai Runtime](#watsonxai-runtime) 13 | 14 |
15 | 16 | ## Breaking changes by service 17 | 18 | - None 19 | 20 | ## New features by service 21 | 22 | ### watsonx.ai 23 | 24 | - Support for new category *Notebooks* 25 | - Methods `Notebooks_Create`, `Notebooks_Delete`, `Notebooks_List`, `Notebooks_Revert`, `Notebooks_Update` 26 | 27 | - Support for new category *Notebook Versions* 28 | - Methods `Notebook_Versions_Create`, `Notebook_Versions_Delete`, `Notebook_Versions_Get`, `Notebook_Versions_List` 29 | 30 | > **Note** 31 | > *Notebooks* and *Notebook Versions* API operations use a different 32 | > endpoint than API operations of the other categories (see [Endpoint 33 | > URLs](https://cloud.ibm.com/apidocs/watsonx-ai#endpoint-url)). If 34 | > you use *Notebooks* and *Notebook Versions* API operations with API 35 | > operations of the other categories in the same program, you need to 36 | > create two separate instances of the watsonx service wrapper ABAP 37 | > class with the respective endpoint URLs and use the instances 38 | > accordingly in your program (see also [Usage](README.md#usage)). 39 | 40 | ### watsonx.ai Runtime 41 | 42 | - None 43 | -------------------------------------------------------------------------------- /docs/ABAPDoc/htmldesign/stylesheet.css: -------------------------------------------------------------------------------- 1 | body { font-family:arial; font-size:13px; background-color: white; margin: 0px; } 2 | table { border: 1px solid black; border-spacing: 0px; border-collapse: collapse; text-align: left; vertical-align: top; width: 100%; } 3 | tr { vertical-align: top; } 4 | th { border: 1px solid black; padding: 4px; background-color: #EBEBEB; text-align: left; } 5 | td { border: 1px solid black; padding: 3px; } 6 | h2 { font-size: 22px; } 7 | h4 { font-size: 18px; } 8 | h5 { font-size: 13px; font-weight: bold; margin-bottom: 5px; } 9 | a { color: black; } 10 | #header { border-bottom: 3px solid grey; background-color: ghostwhite; width: 100%; padding: 4px; padding-left: 8px; } 11 | #headerTitle { padding: 5px; font-size: 22px } 12 | #content { margin: 8px; } 13 | #footer { font-size: 11px; padding-bottom: 8px; padding-left: 8px; } 14 | .identifier { font-weight: bold; text-transform: lowercase; } 15 | .methodSignature { border: 0px; margin: 1px; width: auto; } 16 | .methodSignature tr { text-align: left; vertical-align: top; } 17 | .methodSignature td { border: 0px; padding-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 5px; } 18 | .methodParametersDocumentation { border: 0px; margin-left: 5px; width: auto; } 19 | .methodParametersDocumentation td { border: 0px; padding-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 5px; } 20 | .parametersTable { border: 0px; } 21 | .fieldName {} 22 | .methodName {} 23 | .parameterName {} 24 | .exceptionName {} 25 | .objectName { text-transform: uppercase; } 26 | .interfaceName { font-weight: normal; } 27 | .exceptions { border: 0px; width: auto; } 28 | .exceptions td { border: 0px; padding: 0px; padding-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 5px; } 29 | .abapDocComment p { margin-top: 0px; } 30 | .shorttext { margin-top: 0px; } -------------------------------------------------------------------------------- /src/zcl_ibmx_util.clas.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ZCL_IBMX_UTIL 7 | E 8 | Utilities to connect to IBM Watson 9 | 1 10 | X 11 | X 12 | X 13 | 14 | 15 | 16 | ZCL_IBMX_UTIL 17 | CONVERT_DATETIME_TO_TIMESTAMP 18 | E 19 | Converts a DATETIME String to type TIMESTAMP 20 | 21 | 22 | ZCL_IBMX_UTIL 23 | CONVERT_TIMESTAMP_TO_DATETIME 24 | E 25 | Converts a DATETIME String to type TIMESTAMP 26 | 27 | 28 | ZCL_IBMX_UTIL 29 | CONVERT_TIMESTAMP_TO_LOCAL 30 | E 31 | Converts a UTF timestamp to a local timestamp 32 | 33 | 34 | ZCL_IBMX_UTIL 35 | GET_MIMETYPE_FROM_EXTENSION 36 | E 37 | Returns mime type for a given extension 38 | 39 | 40 | ZCL_IBMX_UTIL 41 | ITAB_TO_TABLESCHEMA 42 | E 43 | Converts an internal table to table schema JSON format 44 | 45 | 46 | ZCL_IBMX_UTIL 47 | TABLESCHEMA_TO_ITAB 48 | E 49 | Converts a JSON string in table schema format to an itab 50 | 51 | 52 | ZCL_IBMX_UTIL 53 | UTC_TO_TIMEZONE 54 | E 55 | Converts an UTC timestamp to the specified timezone 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /src/zcx_ibmx_service_exception.clas.abap: -------------------------------------------------------------------------------- 1 | * Copyright 2019, 2025 IBM Corp. All Rights Reserved. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | class ZCX_IBMX_SERVICE_EXCEPTION definition 15 | public 16 | inheriting from CX_STATIC_CHECK 17 | final 18 | create public . 19 | 20 | public section. 21 | 22 | interfaces IF_T100_DYN_MSG . 23 | interfaces IF_T100_MESSAGE . 24 | 25 | data P_MSG_JSON type STRING . 26 | data P_HTTP_STATUS type STRING . 27 | data P_HTTP_REASON type STRING . 28 | 29 | methods CONSTRUCTOR 30 | importing 31 | !TEXTID like IF_T100_MESSAGE=>T100KEY optional 32 | !PREVIOUS like PREVIOUS optional 33 | !P_MSG_JSON type STRING optional 34 | !P_HTTP_STATUS type STRING optional 35 | !P_HTTP_REASON type STRING optional . 36 | 37 | methods IF_MESSAGE~GET_LONGTEXT 38 | redefinition . 39 | methods IF_MESSAGE~GET_TEXT 40 | redefinition . 41 | protected section. 42 | private section. 43 | ENDCLASS. 44 | 45 | 46 | 47 | CLASS ZCX_IBMX_SERVICE_EXCEPTION IMPLEMENTATION. 48 | 49 | 50 | method CONSTRUCTOR. 51 | CALL METHOD SUPER->CONSTRUCTOR 52 | EXPORTING 53 | PREVIOUS = PREVIOUS. 54 | me->P_MSG_JSON = P_MSG_JSON . 55 | me->P_HTTP_STATUS = P_HTTP_STATUS . 56 | me->P_HTTP_REASON = P_HTTP_REASON . 57 | clear me->textid. 58 | if textid is initial. 59 | IF_T100_MESSAGE~T100KEY = IF_T100_MESSAGE=>DEFAULT_TEXTID. 60 | else. 61 | IF_T100_MESSAGE~T100KEY = TEXTID. 62 | endif. 63 | endmethod. 64 | 65 | 66 | method if_message~get_longtext. 67 | call method super->if_message~get_longtext 68 | exporting 69 | preserve_newlines = preserve_newlines 70 | receiving 71 | result = result. 72 | endmethod. 73 | 74 | 75 | method if_message~get_text. 76 | call method super->if_message~get_text 77 | receiving 78 | result = result. 79 | endmethod. 80 | ENDCLASS. 81 | -------------------------------------------------------------------------------- /docs/ABAPDoc/abapdoc/zibmx/classes/zcx_ibmx_service_exception.html: -------------------------------------------------------------------------------- 1 | Class ZCX_IBMX_SERVICE_EXCEPTION

Class ZCX_IBMX_SERVICE_EXCEPTION

public inheriting from CX_STATIC_CHECK final create public

Documentation

IBM Cloud Service Exception

Interfaces

if_t100_dyn_msg
if_t100_message

Attributes

Visibility and LevelNameDocumentation
public instancep_http_reason type STRING  
public instancep_http_status type STRING  
public instancep_msg_json type STRING  

Methods

Visibility and LevelNameDocumentation
public instance
constructor
importingtextidlike IF_T100_MESSAGE=>T100KEY optional
previouslike PREVIOUS optional
p_msg_jsontype STRING optional
p_http_statustype STRING optional
p_http_reasontype STRING optional
CONSTRUCTOR
public instanceif_message~get_longtext redefinition 
public instanceif_message~get_text redefinition 
-------------------------------------------------------------------------------- /src/zibmx_config.tabl.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ZIBMX_CONFIG 7 | E 8 | TRANSP 9 | X 10 | IBM Cloud Service Integration - Configuration 11 | X 12 | C 13 | 1 14 | 15 | 16 | ZIBMX_CONFIG 17 | A 18 | 2 19 | APPL2 20 | X 21 | X 22 | 23 | 24 | 25 | ZIBMX_CONFIG 26 | CLIENT 27 | E 28 | 0001 29 | X 30 | 0 31 | C 32 | 000006 33 | X 34 | CLNT 35 | 000003 36 | CLNT 37 | 38 | 39 | ZIBMX_CONFIG 40 | SERVICE 41 | E 42 | 0002 43 | X 44 | 0 45 | C 46 | 000060 47 | X 48 | CHAR 49 | 000030 50 | CHAR 51 | 52 | 53 | ZIBMX_CONFIG 54 | INSTANCE_UID 55 | 0003 56 | X 57 | ZIBMX_TY_INSTANCE_UID 58 | 0 59 | X 60 | E 61 | 62 | 63 | ZIBMX_CONFIG 64 | PARAM 65 | E 66 | 0004 67 | X 68 | 0 69 | C 70 | 000064 71 | X 72 | CHAR 73 | 000032 74 | CHAR 75 | 76 | 77 | ZIBMX_CONFIG 78 | VALUE 79 | 0005 80 | ZIBMX_TY_STRINGVALUE 81 | 0 82 | E 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /docs/ABAPDoc/abapdoc/zibmx/interfaces/zif_ibmx_service_arch.html: -------------------------------------------------------------------------------- 1 | Interface ZIF_IBMX_SERVICE_ARCH

Interface ZIF_IBMX_SERVICE_ARCH

public

Documentation

IBM Watson SDK Platform-specifics

Types

Visibility and LevelNameDocumentation
publicboolean (typing) 
publicchar (typing) 
publicts_access_token (structured type) 
publicts_form_part (structured type) 
publicts_header (structured type) 
publicts_http_status (structured type) 
publicts_request_prop (structured type) 
publicts_url (structured type) 
publictt_form_part TYPE standard table of TS_FORM_PART with non-unique default key 
publictt_header TYPE standard table of ts_header with non-unique default key 
publictt_string TYPE standard table of string with non-unique default key 
publicty_communication_scenario (typing) 
publicty_http_destination (typing) 
publicty_ssl_id (typing) 
publicty_timezone (typing) 

Constants

Visibility and LevelNameDocumentation
public staticc_datatype (structured type)  
public staticc_header_accept type STRING value 'Accept' 
public staticc_header_content_disposition type STRING value 'Content-Disposition' 
public staticc_header_content_type type STRING value 'Content-Type' 
public staticc_mediatype (structured type)  
public staticc_method_create type CHAR value 'c' 
public staticc_method_delete type CHAR value 'd' 
public staticc_method_get type CHAR value 'g' 
public staticc_method_patch type CHAR value 'm' 
public staticc_method_post type CHAR value 'p' 
public staticc_method_put type CHAR value 'u' 
public staticc_not_supported type STRING value 'not supported' 
-------------------------------------------------------------------------------- /src/zcl_ibmx_service_ext.clas.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ZCL_IBMX_SERVICE_EXT 7 | E 8 | Extended REST API service class 9 | 1 10 | X 11 | X 12 | X 13 | 14 | 15 | 16 | ZCL_IBMX_SERVICE_EXT 17 | ADD_CONFIG_PROP 18 | E 19 | Method for internal use. 20 | 21 | 22 | ZCL_IBMX_SERVICE_EXT 23 | ADD_IMAGE_TO_ZIP 24 | E 25 | Method for internal use. 26 | 27 | 28 | ZCL_IBMX_SERVICE_EXT 29 | C_FIELD_NONE 30 | E 31 | Field Name 32 | 33 | 34 | ZCL_IBMX_SERVICE_EXT 35 | C_FORMAT_ALL 36 | E 37 | Image encoding (jpg, png, ...) 38 | 39 | 40 | ZCL_IBMX_SERVICE_EXT 41 | C_FORMAT_GIF 42 | E 43 | Image encoding (jpg, png, ...) 44 | 45 | 46 | ZCL_IBMX_SERVICE_EXT 47 | C_FORMAT_JPG 48 | E 49 | Image encoding (jpg, png, ...) 50 | 51 | 52 | ZCL_IBMX_SERVICE_EXT 53 | C_FORMAT_PNG 54 | E 55 | Image encoding (jpg, png, ...) 56 | 57 | 58 | ZCL_IBMX_SERVICE_EXT 59 | C_FORMAT_TIF 60 | E 61 | Image encoding (jpg, png, ...) 62 | 63 | 64 | ZCL_IBMX_SERVICE_EXT 65 | C_FORMAT_UNKNOWN 66 | E 67 | Image encoding (jpg, png, ...) 68 | 69 | 70 | ZCL_IBMX_SERVICE_EXT 71 | C_FORMAT_ZIP 72 | E 73 | Image encoding (jpg, png, ...) 74 | 75 | 76 | ZCL_IBMX_SERVICE_EXT 77 | GET_BEARER_TOKEN 78 | E 79 | Returns the bearer token, if available. 80 | 81 | 82 | ZCL_IBMX_SERVICE_EXT 83 | GET_CONFIG_VALUE 84 | E 85 | Retrieves a value of a configuration parameter 86 | 87 | 88 | ZCL_IBMX_SERVICE_EXT 89 | GET_FIELD_DATA 90 | E 91 | Method for internal use. 92 | 93 | 94 | ZCL_IBMX_SERVICE_EXT 95 | GET_INSTANCE 96 | E 97 | Factory method to instantiate a service specific wrapper cla 98 | 99 | 100 | ZCL_IBMX_SERVICE_EXT 101 | GET_SDK_VERSION_DATE 102 | E 103 | Returns the SDK built date. 104 | 105 | 106 | ZCL_IBMX_SERVICE_EXT 107 | GET_ZIPDATA 108 | E 109 | Compresses multiple images from an internal table 110 | 111 | 112 | ZCL_IBMX_SERVICE_EXT 113 | SET_BEARER_TOKEN 114 | E 115 | Method for internal use. 116 | 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /src/zibmx_token.tabl.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ZIBMX_TOKEN 7 | E 8 | TRANSP 9 | X 10 | IAM tokens 11 | X 12 | L 13 | 4 14 | 15 | 16 | ZIBMX_TOKEN 17 | A 18 | 2 19 | APPL2 20 | P 21 | X 22 | 23 | 24 | 25 | ZIBMX_TOKEN 26 | CLIENT 27 | E 28 | 0001 29 | X 30 | 0 31 | C 32 | 000006 33 | X 34 | CLNT 35 | 000003 36 | CLNT 37 | 38 | 39 | ZIBMX_TOKEN 40 | SERVICE 41 | E 42 | 0002 43 | X 44 | 0 45 | C 46 | 000060 47 | X 48 | CHAR 49 | 000030 50 | CHAR 51 | 52 | 53 | ZIBMX_TOKEN 54 | INSTANCE_UID 55 | 0003 56 | X 57 | ZIBMX_TY_INSTANCE_UID 58 | 0 59 | X 60 | E 61 | 62 | 63 | ZIBMX_TOKEN 64 | ACCESS_TOKEN 65 | E 66 | 0004 67 | 0 68 | g 69 | 000008 70 | STRG 71 | STRG 72 | 73 | 74 | ZIBMX_TOKEN 75 | REFRESH_TOKEN 76 | E 77 | 0005 78 | 0 79 | g 80 | 000008 81 | STRG 82 | STRG 83 | 84 | 85 | ZIBMX_TOKEN 86 | TOKEN_TYPE 87 | E 88 | 0006 89 | 0 90 | C 91 | 000060 92 | CHAR 93 | 000030 94 | CHAR 95 | 96 | 97 | ZIBMX_TOKEN 98 | EXPIRES_IN 99 | E 100 | 0007 101 | 0 102 | X 103 | 000004 104 | INT4 105 | 000010 106 | INT4 107 | 108 | 109 | ZIBMX_TOKEN 110 | EXPIRES_TS 111 | 0008 112 | TIMESTAMP 113 | 0 114 | E 115 | 116 | 117 | ZIBMX_TOKEN 118 | EXPIRATION 119 | E 120 | 0009 121 | 0 122 | X 123 | 000004 124 | INT4 125 | 000010 126 | INT4 127 | 128 | 129 | ZIBMX_TOKEN 130 | SCOPE 131 | E 132 | 0010 133 | 0 134 | C 135 | 000060 136 | CHAR 137 | 000030 138 | CHAR 139 | 140 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /src/zcl_ibmx_service_arch.clas.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ZCL_IBMX_SERVICE_ARCH 7 | E 8 | IBM Watson SDK Platform-specifics 9 | 1 10 | X 11 | X 12 | X 13 | 14 | 15 | 16 | ZCL_IBMX_SERVICE_ARCH 17 | ADD_FORM_PART 18 | E 19 | Generates a multi-part request body. 20 | 21 | 22 | ZCL_IBMX_SERVICE_ARCH 23 | BASE64_DECODE 24 | E 25 | Decodes base64 encoded data to binary. 26 | 27 | 28 | ZCL_IBMX_SERVICE_ARCH 29 | CONVERT_STRING_TO_UTF8 30 | E 31 | Converts STRING data to UTF8 encoded XSTRING. 32 | 33 | 34 | ZCL_IBMX_SERVICE_ARCH 35 | CREATE_CLIENT_BY_URL 36 | E 37 | Returns a HTTP/REST client based on an URL. 38 | 39 | 40 | ZCL_IBMX_SERVICE_ARCH 41 | CREATE_CLIENT_BY_DESTINATION 42 | E 43 | Returns a HTTP/REST client based on an DESTINATION. 44 | 45 | 46 | ZCL_IBMX_SERVICE_ARCH 47 | EXECUTE 48 | E 49 | Executes a HTTP request. 50 | 51 | 52 | ZCL_IBMX_SERVICE_ARCH 53 | FIND_REGEX 54 | E 55 | Finds (and replaces) a regular expression. 56 | 57 | 58 | ZCL_IBMX_SERVICE_ARCH 59 | GET_DEFAULT_PROXY 60 | E 61 | Returns the default proxy host and port. 62 | 63 | 64 | ZCL_IBMX_SERVICE_ARCH 65 | GET_HTTP_STATUS 66 | E 67 | Returns the status of a REST response. 68 | 69 | 70 | ZCL_IBMX_SERVICE_ARCH 71 | GET_PROGNAME 72 | E 73 | Returns an ABAP module identifier. 74 | 75 | 76 | ZCL_IBMX_SERVICE_ARCH 77 | GET_RESPONSE_BINARY 78 | E 79 | Reads binary data from a HTTP response. 80 | 81 | 82 | ZCL_IBMX_SERVICE_ARCH 83 | GET_RESPONSE_HEADER 84 | E 85 | Returns a HTTP response header. 86 | 87 | 88 | ZCL_IBMX_SERVICE_ARCH 89 | GET_RESPONSE_STRING 90 | E 91 | Reads character data from a HTTP response. 92 | 93 | 94 | ZCL_IBMX_SERVICE_ARCH 95 | GET_REST_REQUEST 96 | E 97 | Returns a request object from a HTTP client object. 98 | 99 | 100 | ZCL_IBMX_SERVICE_ARCH 101 | GET_TIMEZONE 102 | E 103 | Returns the user's time zone. 104 | 105 | 106 | ZCL_IBMX_SERVICE_ARCH 107 | SET_AUTHENTICATION_BASIC 108 | E 109 | Sets request header for basic authentication. 110 | 111 | 112 | ZCL_IBMX_SERVICE_ARCH 113 | SET_REQUEST_BODY_CDATA 114 | E 115 | Set character data for the body of a HTTP request. 116 | 117 | 118 | ZCL_IBMX_SERVICE_ARCH 119 | SET_REQUEST_BODY_XDATA 120 | E 121 | Set binary data for the body of a HTTP request. 122 | 123 | 124 | ZCL_IBMX_SERVICE_ARCH 125 | SET_REQUEST_HEADER 126 | E 127 | Sets a HTTP header. 128 | 129 | 130 | ZCL_IBMX_SERVICE_ARCH 131 | SET_REQUEST_URI 132 | E 133 | Sets the URI for a HTTP request. 134 | 135 | 136 | ZCL_IBMX_SERVICE_ARCH 137 | TO_HTTP_CLIENT 138 | E 139 | HTTP Client Control Block 140 | 141 | 142 | ZCL_IBMX_SERVICE_ARCH 143 | TO_REST_CLIENT 144 | E 145 | REST HTTP Client 146 | 147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /src/zif_ibmx_service_arch.intf.abap: -------------------------------------------------------------------------------- 1 | * Copyright 2019, 2025 IBM Corp. All Rights Reserved. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | interface ZIF_IBMX_SERVICE_ARCH 15 | public . 16 | 17 | 18 | types: 19 | boolean(1) type c . 20 | types: 21 | char(1) type c . 22 | types: 23 | begin of ts_http_status, 24 | code type string, 25 | reason type string, 26 | json type string, 27 | end of ts_http_status . 28 | types: 29 | begin of ts_header, 30 | name type string, 31 | value type string, 32 | end of ts_header . 33 | types: 34 | tt_header type standard table of ts_header with non-unique default key . 35 | types: 36 | begin of ts_url, 37 | protocol type string, 38 | host type string, 39 | path_base type string, 40 | path type string, 41 | querystring type string, 42 | end of ts_url . 43 | types: 44 | begin of ts_access_token, 45 | access_token type string, 46 | token_type(32) type c, 47 | expires_ts type timestamp, 48 | end of ts_access_token . 49 | types: 50 | ty_timezone(6) type c . 51 | types: 52 | ty_ssl_id(6) type c . 53 | types: 54 | ty_http_destination(32) type c . 55 | types: 56 | ty_communication_scenario(30) type c. 57 | types: 58 | begin of ts_request_prop, 59 | url type ts_url, 60 | destination type ty_http_destination, 61 | scenario type ty_communication_scenario, 62 | proxy_host type string, 63 | proxy_port type string, 64 | auth_name type string, 65 | auth_type type string, 66 | auth_headername type string, 67 | auth_basic type boolean, 68 | auth_oauth type boolean, 69 | auth_apikey type boolean, 70 | auth_query type boolean, 71 | auth_header type boolean, 72 | auth_body type boolean, 73 | header_accept type string, 74 | header_content_type type string, 75 | headers type tt_header, 76 | body type string, 77 | body_bin type xstring, 78 | username type string, 79 | password type string, 80 | apikey type string, 81 | access_token type ts_access_token, 82 | ssl_id type ty_ssl_id, 83 | end of ts_request_prop . 84 | types: 85 | tt_string type standard table of string with non-unique default key . 86 | types: 87 | begin of TS_FORM_PART, 88 | CONTENT_TYPE type STRING, 89 | CONTENT_DISPOSITION type STRING, 90 | CDATA type STRING, 91 | XDATA type XSTRING, 92 | end of TS_FORM_PART . 93 | types: 94 | TT_FORM_PART type standard table of TS_FORM_PART with non-unique default key . 95 | 96 | 97 | constants C_METHOD_GET type CHAR value 'g' ##NO_TEXT. 98 | constants C_METHOD_POST type CHAR value 'p' ##NO_TEXT. 99 | constants C_METHOD_PATCH type CHAR value 'm' ##NO_TEXT. 100 | constants C_METHOD_CREATE type CHAR value 'c' ##NO_TEXT. 101 | constants C_METHOD_PUT type CHAR value 'u' ##NO_TEXT. 102 | constants C_METHOD_DELETE type CHAR value 'd' ##NO_TEXT. 103 | constants C_NOT_SUPPORTED type STRING value 'not supported' ##NO_TEXT. 104 | constants C_HEADER_CONTENT_TYPE type STRING value 'Content-Type' ##NO_TEXT. 105 | constants C_HEADER_ACCEPT type STRING value 'Accept' ##NO_TEXT. 106 | constants C_HEADER_CONTENT_DISPOSITION type STRING value 'Content-Disposition' ##NO_TEXT. 107 | constants: 108 | begin of c_mediatype, 109 | all type string value '*/*', 110 | appl_gzip type string value 'application/gzip', 111 | appl_html type string value 'application/html', 112 | appl_json type string value 'application/json', 113 | appl_octet_stream type string value 'application/octet-stream', 114 | appl_pdf type string value 'application/pdf', 115 | appl_www_form_urlencoded type string value 'application/x-www-form-urlencoded', 116 | appl_xml type string value 'application/xml', 117 | appl_xhtml_xml type string value 'application/xhtml+xml', 118 | atom_xml type string value 'application/atom+xml', 119 | appl_zip type string value 'application/zip', 120 | audio_all type string value 'audio/*', 121 | audio_mpeg type string value 'audio/mpeg', 122 | audio_ogg type string value 'audio/ogg', 123 | audio_wav type string value 'audio/wav', 124 | image_all type string value 'image/*', 125 | image_bmp type string value 'image/bmp', 126 | image_gif type string value 'image/gif', 127 | image_jpeg type string value 'image/jpeg', 128 | image_png type string value 'image/png', 129 | image_tiff type string value 'image/tiff', 130 | multipart_all type string value 'multipart/*', 131 | multipart_form_data type string value 'multipart/form-data', 132 | multipart_mixed type string value 'multipart/mixed', 133 | text_all type string value 'text/*', 134 | text_css type string value 'text/css', 135 | text_csv type string value 'text/csv', 136 | text_html type string value 'text/html', 137 | text_javascript type string value 'text/javascript', 138 | text_plain type string value 'text/plain', 139 | video_all type string value 'video/*', 140 | video_mp4 type string value 'video/mp4', 141 | video_mpeg type string value 'video/mpeg', 142 | end of c_mediatype . 143 | constants: 144 | begin of c_datatype, 145 | i type char value 'I', 146 | int8 type char value '8', 147 | p type char value 'P', 148 | f type char value 'F', 149 | c type char value 'C', 150 | n type char value 'N', 151 | string type char value 'g', 152 | x type char value 'X', 153 | xstring type char value 'y', 154 | dataref type char value 'l', 155 | objectref type char value 'r', 156 | struct type char value 'u', 157 | struct_deep type char value 'v', 158 | itab type char value 'h', 159 | end of c_datatype . 160 | endinterface. 161 | -------------------------------------------------------------------------------- /src/zcl_ibmx_service.clas.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ZCL_IBMX_SERVICE 7 | E 8 | ABAP SDK for IBM Watson - Service Class 9 | 1 10 | X 11 | X 12 | X 13 | 14 | 15 | 16 | ZCL_IBMX_SERVICE 17 | ABAP_TO_JSON 18 | E 19 | Extracts a JSON string from an ABAP structure. 20 | 21 | 22 | ZCL_IBMX_SERVICE 23 | ADD_HEADER_PARAMETER 24 | E 25 | Method for internal use. 26 | 27 | 28 | ZCL_IBMX_SERVICE 29 | ADD_QUERY_PARAMETER 30 | E 31 | Method for internal use. 32 | 33 | 34 | ZCL_IBMX_SERVICE 35 | ADJUST_REQUEST_PROP 36 | E 37 | Method for internal use. 38 | 39 | 40 | ZCL_IBMX_SERVICE 41 | CHECK_HTTP_RESPONSE 42 | E 43 | Throws an exception, if HTTP response indicates an error. 44 | 45 | 46 | ZCL_IBMX_SERVICE 47 | CONSTRUCTOR 48 | E 49 | Class constructor. 50 | 51 | 52 | ZCL_IBMX_SERVICE 53 | DATETIME 54 | E 55 | DateTime type, format 2018-10-23T15:18:18.914xxxZ 56 | 57 | 58 | ZCL_IBMX_SERVICE 59 | GET_ACCESS_TOKEN 60 | E 61 | Method for internal use. 62 | 63 | 64 | ZCL_IBMX_SERVICE 65 | GET_APPNAME 66 | E 67 | Returns the service name. 68 | 69 | 70 | ZCL_IBMX_SERVICE 71 | GET_COMPONENTS 72 | E 73 | Returns component names of a given structure. 74 | 75 | 76 | ZCL_IBMX_SERVICE 77 | GET_DATATYPE 78 | E 79 | Returns data type of a given parameter. 80 | 81 | 82 | ZCL_IBMX_SERVICE 83 | GET_FIELD_TYPE 84 | E 85 | Returns field type and length of a given parameter. 86 | 87 | 88 | ZCL_IBMX_SERVICE 89 | GET_FILE_EXTENSION 90 | E 91 | Returns the file extension for a mime type 92 | 93 | 94 | ZCL_IBMX_SERVICE 95 | GET_FULL_URL 96 | E 97 | Method for internal use. 98 | 99 | 100 | ZCL_IBMX_SERVICE 101 | GET_REQUEST_PROP 102 | E 103 | Method for internal use. 104 | 105 | 106 | ZCL_IBMX_SERVICE 107 | GET_REST_CLIENT 108 | E 109 | Method for internal use. 110 | 111 | 112 | ZCL_IBMX_SERVICE 113 | HTTP_DELETE 114 | E 115 | Sends a HTTP DELETE request. 116 | 117 | 118 | ZCL_IBMX_SERVICE 119 | HTTP_GET 120 | E 121 | Sends a HTTP GET request. 122 | 123 | 124 | ZCL_IBMX_SERVICE 125 | HTTP_POST 126 | E 127 | Sends a HTTP POST request. 128 | 129 | 130 | ZCL_IBMX_SERVICE 131 | HTTP_PATCH 132 | E 133 | Sends a HTTP PATCH request. 134 | 135 | 136 | ZCL_IBMX_SERVICE 137 | HTTP_POST_MULTIPART 138 | E 139 | Sends a HTTP POST request with multipart body. 140 | 141 | 142 | ZCL_IBMX_SERVICE 143 | HTTP_PUT 144 | E 145 | Sends a HTTP PUT request. 146 | 147 | 148 | ZCL_IBMX_SERVICE 149 | MERGE_STRUCTURE 150 | E 151 | Method for internal use. 152 | 153 | 154 | ZCL_IBMX_SERVICE 155 | MOVE_DATA_REFERENCE_TO_ABAP 156 | E 157 | Moves a referenced data structure to an ABAP structure. 158 | 159 | 160 | ZCL_IBMX_SERVICE 161 | NORMALIZE_URL 162 | E 163 | Method for internal use. 164 | 165 | 166 | ZCL_IBMX_SERVICE 167 | PARSE_JSON 168 | E 169 | Parses a JSON string into an ABAP structure. 170 | 171 | 172 | ZCL_IBMX_SERVICE 173 | RAISE_EXCEPTION 174 | E 175 | Raises an exception. 176 | 177 | 178 | ZCL_IBMX_SERVICE 179 | SET_ACCESS_TOKEN 180 | E 181 | Sets an access token explicitly. 182 | 183 | 184 | ZCL_IBMX_SERVICE 185 | SET_DEFAULT_QUERY_PARAMETERS 186 | E 187 | Method for internal use. 188 | 189 | 190 | ZCL_IBMX_SERVICE 191 | SET_URI_AND_AUTHORIZATION 192 | E 193 | Method for internal use. 194 | 195 | 196 | ZCL_IBMX_SERVICE 197 | UNESCAPE_UNICODE 198 | E 199 | Unescape unicode codepoints to characters in a string 200 | 201 | 202 | 203 | 204 | -------------------------------------------------------------------------------- /docs/ABAPDoc/abapdoc/zibmx/classes/zcl_ibmx_util.html: -------------------------------------------------------------------------------- 1 | Class ZCL_IBMX_UTIL

Class ZCL_IBMX_UTIL

public final create public

Documentation

Utilities to connect to IBM Watson

Methods

Visibility and LevelNameDocumentation
public static
convert_datetime_to_timestamp
importingi_datetimetype ZCL_IBMX_SERVICE=>DATETIME
returningvalue(e_timestamp)type TIMESTAMP
Converts datetime format to a timestamp, i.e. yyyy-mm-ddThh:mm:ssZ -> YYYYMMDDHHMMSS 2 | 3 |
Parameters
i_datetime Input in datetime format. 4 |
e_timestamp Timestamp. 5 |
public static
convert_timestamp_to_datetime
importingi_timestamptype TIMESTAMP
returningvalue(e_datetime)type ZCL_IBMX_SERVICE=>DATETIME
Converts a timestamp to datetime format, i.e. YYYYMMDDHHMMSS -> yyyy-mm-ddThh:mm:ssZ 6 | 7 |
Parameters
i_timestamp Timestamp. 8 |
e_datetime Datetime format. 9 |
public static
convert_timestamp_to_local
importingiv_timestamptype TIMESTAMP
returningvalue(ev_local)type STRING
Converts a timestamp in UTC to a timestamp in local time. 10 | 11 |
Parameters
iv_timestamp Timestamp (UTC). 12 |
ev_local Timestamp (local time). 13 |
public static
get_mimetype_from_extension
importingi_filenametype STRING
returningvalue(e_mimetype)type STRING
Determine MIME type from a file name, e.g. 'docu.txt' -> 'text_/plain'. 14 | 15 |
Parameters
i_filename Filename with extension. 16 |
e_mimetype MIME type. 17 |
public static
itab_to_tableschema
importingi_itabtype ANY TABLE
i_dictionarytype ANY optional
i_lower_casetype ZCL_IBMX_SERVICE=>BOOLEAN default ZCL_IBMX_SERVICE=>C_BOOLEAN_FALSE
it_excluded_fieldstype ZCL_IBMX_SERVICE=>TT_STRING optional
returningvalue(e_json)type STRING
Converts an internal table to JSON string in table schema format. 18 | E.g.: '{"fields": ["PET", "NUMBER"], "values": [["Cat",5],["Rabbit",2]]}' 19 | 20 |
Parameters
i_itab Internal table to be converted. 21 |
i_dictionary Dictionary to be used for mapping ABAP identifiers to JSON keys. 22 |
i_lower_case If set to C_BOOLEAN_TRUE all keys in JSON string will be lower case. 23 |
it_excluded_fields Internal table of table fields in I_ITAB that should not occur in result. 24 |
e_json JSON string. 25 |
public static
tableschema_to_itab
importingi_jsontype STRING
i_tableschema_keytype STRING optional
exportinge_itabtype ANY TABLE
Converts a JSON string in table schema format to an internal table. 26 | E.g.: '{"tableschema_key": {"fields": ["PET", "NUMBER"], "values": [["Cat",5],["Rabbit",2]]}}' 27 | 28 |
Parameters
i_json JSON string. 29 |
i_tableschema_key Key in JSON string that holds the table schema. 30 |
e_itab Internal table containing converted data. 31 |
public static
utc_to_timezone
importingi_timestamptype TIMESTAMP
i_timezonetype ZIF_IBMX_SERVICE_ARCH=>TY_TIMEZONE optional
returningvalue(e_timestamp)type TIMESTAMP
Converts a timestamp in UTC to a timestamp in another timezone. 32 | 33 |
Parameters
i_timestamp Timestamp (UTC). 34 |
i_timezone Time zone 35 |
e_timestamp Timestamp in give time zone. 36 |
-------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /src/zibmx.msag.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ZIBMX 7 | E 8 | 9 | 10 | 11 | E 12 | ZIBMX 13 | 000 14 | &1 15 | 16 | 17 | E 18 | ZIBMX 19 | 001 20 | &1: return code &2 21 | 22 | 23 | E 24 | ZIBMX 25 | 002 26 | An exception has occurred, reason code &1. 27 | 28 | 29 | E 30 | ZIBMX 31 | 003 32 | HTTP Status: &1 (&2) 33 | 34 | 35 | E 36 | ZIBMX 37 | 004 38 | Malformated url: &1 39 | 40 | 41 | E 42 | ZIBMX 43 | 005 44 | HTTP &1 request failed: &2 45 | 46 | 47 | E 48 | ZIBMX 49 | 006 50 | HTTP client cannot be created, return code &1. 51 | 52 | 53 | E 54 | ZIBMX 55 | 007 56 | Parameter &1 not set 57 | 58 | 59 | E 60 | ZIBMX 61 | 008 62 | Either parameter &1 or parameter &2 must be specified. 63 | 64 | 65 | E 66 | ZIBMX 67 | 020 68 | Cannot parse JSON string, see short dump. 69 | 70 | 71 | E 72 | ZIBMX 73 | 030 74 | Decoding of base64 string failed. 75 | 76 | 77 | E 78 | ZIBMX 79 | 040 80 | &1 81 | 82 | 83 | E 84 | ZIBMX 85 | 050 86 | Missing field &1 in input structure. 87 | 88 | 89 | E 90 | ZIBMX 91 | 051 92 | Input image is missing or ambiguous. 93 | 94 | 95 | E 96 | ZIBMX 97 | 052 98 | base64 decoding of image &1 failed with return code &2. 99 | 100 | 101 | E 102 | ZIBMX 103 | 053 104 | Classifier &1 has status &2. Operation terminated. 105 | 106 | 107 | E 108 | ZIBMX 109 | 054 110 | Field &1 is missing or has incompatible type. 111 | 112 | 113 | E 114 | ZIBMX 115 | 055 116 | Input structure meta data is not available. 117 | 118 | 119 | E 120 | ZIBMX 121 | 056 122 | Cannot add image to ZIP file without filename. 123 | 124 | 125 | 126 | 127 | 128 | NA 129 | ZIBMX003 130 | E 131 | E 132 | 0018 133 | X 134 | 00005 135 | 136 | 137 | DOKU 138 | ZIBMX003 139 | NA 140 | E 141 | S_DOCU_SHOW 142 | S_DOCUS1 143 | 00018 144 | 072 145 | 146 | 147 | 148 | AS 149 | The HTTP Request received status "&V1&": "&V2&" 150 | 151 | 152 | U1 153 | &SYSTEM_RESPONSE& 154 | 155 | 156 | AS 157 | Access point: &V3& 158 | 159 | 160 | AS 161 | Detailed Information reported by the service: 162 | 163 | 164 | AS 165 | &V4& 166 | 167 | 168 | U1 169 | &WHAT_TO_DO& 170 | 171 | 172 | AS 173 | ,,Correct the error and restart the process. 174 | 175 | 176 | 177 | 178 | 179 | NA 180 | ZIBMX004 181 | E 182 | E 183 | 0002 184 | X 185 | 00004 186 | 187 | 188 | DOKU 189 | ZIBMX004 190 | NA 191 | E 192 | S_DOCU_SHOW 193 | S_DOCUS1 194 | 00002 195 | 072 196 | 197 | 198 | 199 | U1 200 | &CAUSE& 201 | 202 | 203 | AS 204 | The format of URL "&V1&" is not correct. 205 | 206 | 207 | U1 208 | &SYSTEM_RESPONSE& 209 | 210 | 211 | AS 212 | The request has been terminated. 213 | 214 | 215 | U1 216 | &WHAT_TO_DO& 217 | 218 | 219 | AS 220 | Correct the URL. Format of the URL must comply with schema http(s):// 221 | 222 | 223 | = 224 | <host>/<api path> 225 | 226 | 227 | U1 228 | &SYS_ADMIN& 229 | 230 | 231 | AS 232 | 233 | 234 | 235 | 236 | 237 | NA 238 | ZIBMX040 239 | E 240 | E 241 | 0004 242 | X 243 | 00004 244 | 245 | 246 | DOKU 247 | ZIBMX040 248 | NA 249 | E 250 | S_DOCU_SHOW 251 | S_DOCUS1 252 | 00004 253 | 072 254 | 255 | 256 | 257 | U1 258 | &CAUSE& 259 | 260 | 261 | AS 262 | Error 263 | 264 | 265 | U1 266 | &SYSTEM_RESPONSE& 267 | 268 | 269 | AS 270 | JSON comes here. 271 | 272 | 273 | AS 274 | <(>&<)>1 275 | 276 | 277 | AS 278 | &V1& 279 | 280 | 281 | U1 282 | &WHAT_TO_DO& 283 | 284 | 285 | AS 286 | 287 | 288 | U1 289 | &SYS_ADMIN& 290 | 291 | 292 | AS 293 | 294 | 295 | 296 | 297 | 298 | NA 299 | ZIBMX050 300 | E 301 | E 302 | 0003 303 | X 304 | 00004 305 | 306 | 307 | DOKU 308 | ZIBMX050 309 | NA 310 | E 311 | S_DOCU_SHOW 312 | S_DOCUS1 313 | 00003 314 | 072 315 | 316 | 317 | 318 | U1 319 | &CAUSE& 320 | 321 | 322 | AS 323 | watsonx.ai Runtime scoring endpoint requires input field &V1& 324 | 325 | 326 | which is not present in the input structure. 327 | 328 | 329 | U1 330 | &SYSTEM_RESPONSE& 331 | 332 | 333 | AS 334 | watsonx.ai Runtime refuses the scoring request. 335 | 336 | 337 | U1 338 | &WHAT_TO_DO& 339 | 340 | 341 | AS 342 | Add field &V1& to the input structure. 343 | 344 | 345 | U1 346 | &SYS_ADMIN& 347 | 348 | 349 | AS 350 | 351 | 352 | 353 | 354 | 355 | NA 356 | ZIBMX051 357 | E 358 | E 359 | 0001 360 | X 361 | 00005 362 | 363 | 364 | DOKU 365 | ZIBMX051 366 | NA 367 | E 368 | S_DOCU_SHOW 369 | S_DOCUS1 370 | 00001 371 | 072 372 | 373 | 374 | 375 | U1 376 | &CAUSE& 377 | 378 | 379 | AS 380 | The image to be classified is not specified or its specification is 381 | 382 | 383 | ambiguous. 384 | 385 | 386 | U1 387 | &SYSTEM_RESPONSE& 388 | 389 | 390 | AS 391 | The image is not being classified. 392 | 393 | 394 | U1 395 | &WHAT_TO_DO& 396 | 397 | 398 | AS 399 | Specify the image either as binary data (type XSTRING) or as base64 400 | 401 | 402 | encoded character data (type STRING), but not both. 403 | 404 | 405 | U1 406 | &SYS_ADMIN& 407 | 408 | 409 | AS 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | -------------------------------------------------------------------------------- /docs/ABAPDoc/abapdoc/zibmx/classes/zcl_ibmx_service_ext.html: -------------------------------------------------------------------------------- 1 | Class ZCL_IBMX_SERVICE_EXT

Class ZCL_IBMX_SERVICE_EXT

public inheriting from ZCL_IBMX_SERVICE create public

Documentation

Extended REST API service class

Types

Visibility and LevelNameDocumentation
publicts_oauth_prop (structured type) 
publicty_image_class type STRING 
publicty_image_format (typing) 
publicty_instance_id (typing) 
publicty_servicename (typing) 

Constants

Visibility and LevelNameDocumentation
public staticc_field_none type FIELDNAME value '###'Field Name
public staticc_format_all type TY_IMAGE_FORMAT value '*'Image encoding (jpg, png, ...)
public staticc_format_gif type TY_IMAGE_FORMAT value 'gif'Image encoding (jpg, png, ...)
public staticc_format_jpg type TY_IMAGE_FORMAT value 'jpg'Image encoding (jpg, png, ...)
public staticc_format_png type TY_IMAGE_FORMAT value 'png'Image encoding (jpg, png, ...)
public staticc_format_tif type TY_IMAGE_FORMAT value 'tif'Image encoding (jpg, png, ...)
public staticc_format_unknown type TY_IMAGE_FORMAT value '###'Image encoding (jpg, png, ...)
public staticc_format_zip type TY_IMAGE_FORMAT value 'zip'Image encoding (jpg, png, ...)
public staticc_iam_token_host type STRING value 'iam.cloud.ibm.com' 
public staticc_iam_token_path type STRING value '/identity/token' 
public staticc_icp4d_token_path type STRING value '/v1/preauth/validateAuth' 
public staticc_token_generation_always type CHAR value 'A' 
public staticc_token_generation_auto type CHAR value SPACE 
public staticc_token_generation_never type CHAR value 'N' 
public staticc_watsonx_token_path type STRING value '/icp4d-api/v1/authorize' 

Attributes

Visibility and LevelNameDocumentation
public instancep_instance_id type TY_INSTANCE_ID  
public instancep_servicename type TY_SERVICENAME  

Methods

Visibility and LevelNameDocumentation
public static
get_instance
importingi_instance_idtype TY_INSTANCE_ID optional
i_urltype STRING optional
i_hosttype STRING optional
i_scenariotype ZIF_IBMX_SERVICE_ARCH=>TY_COMMUNICATION_SCENARIO default C_DEFAULT_SCENARIO
i_usernametype STRING optional
i_passwordtype STRING optional
i_proxy_hosttype STRING optional
i_proxy_porttype STRING optional
i_apikeytype STRING optional
i_auth_methodtype STRING default C_DEFAULT
i_oauth_proptype TS_OAUTH_PROP optional
i_access_tokentype TS_ACCESS_TOKEN optional
i_token_generationtype CHAR default C_TOKEN_GENERATION_AUTO
i_request_headerstype STRING optional
i_versiontype STRING optional
exportingvalue(eo_instance)type ANY

Factory method to instantiate a service wrapper class.

2 | 3 |
Parameters
i_instance_id 4 | Value of field INSTANCE_UID in table ZIBMX_CONFIG. 5 | Service credentials are read from table ZIBMX_CONFIG with key SERVICE = Name of service wrapper class without prefix ZCL_IBMX_ and INSTANCE_UID. 6 |
i_url URL of the service. 7 |
i_host Host of the service. I_URL and I_HOST can be used synonymously. 8 |
i_scenario Communication scenario. 9 |
i_username User password to authenticate on service. 10 |
i_password User password to authenticate on service. 11 |
i_proxy_host Proxy server, not applicable on SAP Cloud Platform. 12 |
i_proxy_port Proxy server port, not applicable on SAP Cloud Platform. 13 |
i_apikey API key password to authenticate on service. 14 |
i_auth_method Authentication method. Possible values are "IAM", "ICP4D", "basicAuth", "NONE". 15 |
i_oauth_prop Credentials to generate token for OAuth authentication. 16 |
i_token_generation Method for access token refresh:
17 | C_TOKEN_GENERATION_NEVER - Access token is not refreshed. 18 | C_TOKEN_GENERATION_ALWAYS - Access to token is refreshed for each service call. 19 | C_TOKEN_GENERATION_AUTO - Access to token is refreshed just before it expires. 20 |
i_request_headers List of headers sent with every request, format 'Header1=Value1;Header2=Value2'. 21 |
i_version Value of query parameter VERSION. 22 |
public static
get_zipdata
importingit_examplestype ANY TABLE
iv_field_classtype FIELDNAME default C_FIELD_NONE
iv_field_filenametype FIELDNAME optional
iv_field_imagetype FIELDNAME optional
iv_image_formattype TY_IMAGE_FORMAT optional
iv_image_nametype STRING optional
exportinget_zipdatatype TT_MAP_FILE
raisingzcx_ibmx_service_exception

Compresses multiple images from an internal table

to a one or more xstrings in ZIP format. 23 | 24 |
Parameters
it_examples Internal table of images. 25 |
iv_field_class 26 | Field in IT_EXAMPLES that contains the file class. 27 | All records in IT_EXAMPLES with same class will be compress into one ZIP xstring. 28 |
iv_field_filename Field in IT_EXAMPLES that contains the filename for the image. 29 |
iv_field_image Field in IT_EXAMPLES that contains the image. 30 |
iv_image_format Format of the image. Possible values are 31 | C_FORMAT_JPG, C_FORMAT_PNG, C_FORMAT_GIF, C_FORMAT_TIF, C_FORMAT_ALL. 32 |
iv_image_name Name of the image. 33 |
et_zipdata Internal table containing a compressed ZIP xstring for each image class. 34 |
Class-based Exceptions
zcx_ibmx_service_exception Exception being raised in case of an error. 35 |
public instanceget_access_token redefinition 
public instance
get_bearer_token
returningvalue(e_bearer_token)type STRING

Returns the bearer token, if available.

36 | 37 |
Parameters
e_bearer_token Access token. 38 |
public instance
get_config_value
importingi_defaulttype ZIBMX_CONFIG-VALUE optional
i_paramtype ZIBMX_CONFIG-PARAM
returningvalue(e_value)type ZIBMX_CONFIG-VALUE
raisingzcx_ibmx_service_exception

Retrieves a value of a configuration parameter

from table ZIBMX_CONFIG. 39 | 40 |
Parameters
i_default Default value, if configuration parameter is not found. 41 |
i_param Configuration parameter name. 42 |
public instanceget_request_prop redefinition 
public instance
get_sdk_version_date
returningvalue(e_sdk_version_date)type STRING

Returns the SDK built date.

43 | 44 |
Parameters
e_sdk_version_date Built data in format YYYYMMDD. 45 |
public instance
set_bearer_token
importingi_bearer_tokentype STRING

Method for internal use.

46 |
-------------------------------------------------------------------------------- /src/zcl_ibmx_watsonx_ai_ml_v1.clas.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ZCL_IBMX_WATSONX_AI_ML_V1 7 | E 8 | watsonx.ai 9 | 1 10 | X 11 | X 12 | X 13 | 14 | 15 | 16 | ZCL_IBMX_WATSONX_AI_ML_V1 17 | AI_SERVICES_CREATE 18 | E 19 | Create a new AI service 20 | 21 | 22 | ZCL_IBMX_WATSONX_AI_ML_V1 23 | AI_SERVICES_CREATE_REVISION 24 | E 25 | Create a new AI service revision 26 | 27 | 28 | ZCL_IBMX_WATSONX_AI_ML_V1 29 | AI_SERVICES_DELETE 30 | E 31 | Delete the AI service 32 | 33 | 34 | ZCL_IBMX_WATSONX_AI_ML_V1 35 | AI_SERVICES_DOWNLOAD_CODE 36 | E 37 | Download the AI service code 38 | 39 | 40 | ZCL_IBMX_WATSONX_AI_ML_V1 41 | AI_SERVICES_GET 42 | E 43 | Retrieve the AI service 44 | 45 | 46 | ZCL_IBMX_WATSONX_AI_ML_V1 47 | AI_SERVICES_LIST 48 | E 49 | Retrieve the AI services 50 | 51 | 52 | ZCL_IBMX_WATSONX_AI_ML_V1 53 | AI_SERVICES_LIST_REVISIONS 54 | E 55 | Retrieve the AI service revisions 56 | 57 | 58 | ZCL_IBMX_WATSONX_AI_ML_V1 59 | AI_SERVICES_UPDATE 60 | E 61 | Update the AI service 62 | 63 | 64 | ZCL_IBMX_WATSONX_AI_ML_V1 65 | AI_SERVICES_UPLOAD_CODE 66 | E 67 | Upload the AI service code 68 | 69 | 70 | ZCL_IBMX_WATSONX_AI_ML_V1 71 | CREATE_AUTOAI_RAGS 72 | E 73 | Create a new AutoAI RAG run 74 | 75 | 76 | ZCL_IBMX_WATSONX_AI_ML_V1 77 | CREATE_DEPLOYMENT 78 | E 79 | Create a new watsonx.ai deployment 80 | 81 | 82 | ZCL_IBMX_WATSONX_AI_ML_V1 83 | DELETE_AUTOAI_RAGS 84 | E 85 | Cancel or delete an AutoAI RAG run 86 | 87 | 88 | ZCL_IBMX_WATSONX_AI_ML_V1 89 | DELETE_PROMPT 90 | E 91 | Delete a prompt 92 | 93 | 94 | ZCL_IBMX_WATSONX_AI_ML_V1 95 | DELETE_PROMPT_SESSION 96 | E 97 | Delete a prompt session 98 | 99 | 100 | ZCL_IBMX_WATSONX_AI_ML_V1 101 | DELETE_PROMPT_SESSION_ENTRY 102 | E 103 | Delete a prompt session entry 104 | 105 | 106 | ZCL_IBMX_WATSONX_AI_ML_V1 107 | DEPLOYMENTS_DELETE 108 | E 109 | Delete the deployment 110 | 111 | 112 | ZCL_IBMX_WATSONX_AI_ML_V1 113 | DEPLOYMENTS_GET 114 | E 115 | Retrieve the deployment details 116 | 117 | 118 | ZCL_IBMX_WATSONX_AI_ML_V1 119 | DEPLOYMENTS_TEXT_CHAT 120 | E 121 | Infer text chat 122 | 123 | 124 | ZCL_IBMX_WATSONX_AI_ML_V1 125 | DEPLOYMENTS_TEXT_CHAT_STREAM 126 | E 127 | Infer text chat event stream 128 | 129 | 130 | ZCL_IBMX_WATSONX_AI_ML_V1 131 | DEPLOYMENTS_TEXT_GENERATION 132 | E 133 | Infer text 134 | 135 | 136 | ZCL_IBMX_WATSONX_AI_ML_V1 137 | DEPLOYMENTS_TEXT_GEN_STREAM 138 | E 139 | Infer text event stream 140 | 141 | 142 | ZCL_IBMX_WATSONX_AI_ML_V1 143 | DEPLOYMENTS_UPDATE 144 | E 145 | Update the deployment metadata 146 | 147 | 148 | ZCL_IBMX_WATSONX_AI_ML_V1 149 | GET_AUTOAI_RAGS 150 | E 151 | Get an AutoAI RAG run 152 | 153 | 154 | ZCL_IBMX_WATSONX_AI_ML_V1 155 | GET_PROMPT 156 | E 157 | Get a prompt 158 | 159 | 160 | ZCL_IBMX_WATSONX_AI_ML_V1 161 | GET_PROMPT_INPUT 162 | E 163 | Get the inference input string for a given prompt 164 | 165 | 166 | ZCL_IBMX_WATSONX_AI_ML_V1 167 | GET_PROMPT_LOCK 168 | E 169 | Get current prompt lock status 170 | 171 | 172 | ZCL_IBMX_WATSONX_AI_ML_V1 173 | GET_PROMPT_SESSION 174 | E 175 | Get a prompt session 176 | 177 | 178 | ZCL_IBMX_WATSONX_AI_ML_V1 179 | GET_PROMPT_SESSION_ENTRIES 180 | E 181 | Get entries for a prompt session 182 | 183 | 184 | ZCL_IBMX_WATSONX_AI_ML_V1 185 | GET_PROMPT_SESSION_ENTRY 186 | E 187 | Get a prompt session entry 188 | 189 | 190 | ZCL_IBMX_WATSONX_AI_ML_V1 191 | GET_PROMPT_SESSION_LOCK 192 | E 193 | Get current prompt session lock status 194 | 195 | 196 | ZCL_IBMX_WATSONX_AI_ML_V1 197 | LIST_AUTOAI_RAGS 198 | E 199 | Retrieve the AutoAI RAG runs 200 | 201 | 202 | ZCL_IBMX_WATSONX_AI_ML_V1 203 | LIST_DEPLOYMENTS 204 | E 205 | Retrieve the deployments 206 | 207 | 208 | ZCL_IBMX_WATSONX_AI_ML_V1 209 | LIST_FOUNDATION_MODEL_SPECS 210 | E 211 | List the available foundation models 212 | 213 | 214 | ZCL_IBMX_WATSONX_AI_ML_V1 215 | LIST_FOUNDATION_MODEL_TASKS 216 | E 217 | List the supported tasks 218 | 219 | 220 | ZCL_IBMX_WATSONX_AI_ML_V1 221 | LIST_TEXT_EXTRACTIONS 222 | E 223 | Retrieve the text extraction requests 224 | 225 | 226 | ZCL_IBMX_WATSONX_AI_ML_V1 227 | NOTEBOOKS_CREATE 228 | E 229 | Create a new notebook 230 | 231 | 232 | ZCL_IBMX_WATSONX_AI_ML_V1 233 | NOTEBOOKS_DELETE 234 | E 235 | Delete a particular notebook, including the notebook asset 236 | 237 | 238 | ZCL_IBMX_WATSONX_AI_ML_V1 239 | NOTEBOOKS_LIST 240 | E 241 | Retrieve the details of a large number of notebooks inside a project 242 | 243 | 244 | ZCL_IBMX_WATSONX_AI_ML_V1 245 | NOTEBOOKS_REVERT 246 | E 247 | Revert the main notebook to a version 248 | 249 | 250 | ZCL_IBMX_WATSONX_AI_ML_V1 251 | NOTEBOOKS_UPDATE 252 | E 253 | Update a particular notebook 254 | 255 | 256 | ZCL_IBMX_WATSONX_AI_ML_V1 257 | NOTEBOOK_VERSIONS_CREATE 258 | E 259 | Create a new version 260 | 261 | 262 | ZCL_IBMX_WATSONX_AI_ML_V1 263 | NOTEBOOK_VERSIONS_DELETE 264 | E 265 | Delete a notebook version 266 | 267 | 268 | ZCL_IBMX_WATSONX_AI_ML_V1 269 | NOTEBOOK_VERSIONS_GET 270 | E 271 | Retrieve a notebook version 272 | 273 | 274 | ZCL_IBMX_WATSONX_AI_ML_V1 275 | NOTEBOOK_VERSIONS_LIST 276 | E 277 | List the versions of a notebook 278 | 279 | 280 | ZCL_IBMX_WATSONX_AI_ML_V1 281 | PATCH_PROMPT 282 | E 283 | Update a prompt 284 | 285 | 286 | ZCL_IBMX_WATSONX_AI_ML_V1 287 | PATCH_PROMPT_SESSION 288 | E 289 | Update a prompt session 290 | 291 | 292 | ZCL_IBMX_WATSONX_AI_ML_V1 293 | POST_PROMPT 294 | E 295 | Create a new prompt / prompt template 296 | 297 | 298 | ZCL_IBMX_WATSONX_AI_ML_V1 299 | POST_PROMPT_CHAT_ITEM 300 | E 301 | Add a new chat item to a prompt 302 | 303 | 304 | ZCL_IBMX_WATSONX_AI_ML_V1 305 | POST_PROMPT_SESSION 306 | E 307 | Create a new prompt session 308 | 309 | 310 | ZCL_IBMX_WATSONX_AI_ML_V1 311 | POST_PROMPT_SESSION_ENTRY 312 | E 313 | Add a new prompt to a prompt session 314 | 315 | 316 | ZCL_IBMX_WATSONX_AI_ML_V1 317 | PST_PRMPT_SSSN_ENTRY_CHAT_ITEM 318 | E 319 | Add a new chat item to a prompt session entry 320 | 321 | 322 | ZCL_IBMX_WATSONX_AI_ML_V1 323 | PUT_PROMPT_LOCK 324 | E 325 | Prompt lock modifications 326 | 327 | 328 | ZCL_IBMX_WATSONX_AI_ML_V1 329 | PUT_PROMPT_SESSION_LOCK 330 | E 331 | Prompt session lock modifications 332 | 333 | 334 | ZCL_IBMX_WATSONX_AI_ML_V1 335 | TEXT_CHAT 336 | E 337 | Infer text 338 | 339 | 340 | ZCL_IBMX_WATSONX_AI_ML_V1 341 | TEXT_CHAT_STREAM 342 | E 343 | Infer text event stream 344 | 345 | 346 | ZCL_IBMX_WATSONX_AI_ML_V1 347 | TEXT_EMBEDDINGS 348 | E 349 | Generate embeddings 350 | 351 | 352 | ZCL_IBMX_WATSONX_AI_ML_V1 353 | TEXT_EXTRACTION 354 | E 355 | Start a text extraction request 356 | 357 | 358 | ZCL_IBMX_WATSONX_AI_ML_V1 359 | TEXT_EXTRACTION_DELETE 360 | E 361 | Delete the request 362 | 363 | 364 | ZCL_IBMX_WATSONX_AI_ML_V1 365 | TEXT_EXTRACTION_GET 366 | E 367 | Get the results of the request 368 | 369 | 370 | ZCL_IBMX_WATSONX_AI_ML_V1 371 | TEXT_GENERATION 372 | E 373 | Infer text 374 | 375 | 376 | ZCL_IBMX_WATSONX_AI_ML_V1 377 | TEXT_GENERATION_STREAM 378 | E 379 | Infer text event stream 380 | 381 | 382 | ZCL_IBMX_WATSONX_AI_ML_V1 383 | TEXT_RERANK 384 | E 385 | Generate rerank 386 | 387 | 388 | ZCL_IBMX_WATSONX_AI_ML_V1 389 | TEXT_TOKENIZATION 390 | E 391 | Text tokenization 392 | 393 | 394 | ZCL_IBMX_WATSONX_AI_ML_V1 395 | TIME_SERIES_FORECAST 396 | E 397 | Time series forecast 398 | 399 | 400 | ZCL_IBMX_WATSONX_AI_ML_V1 401 | TRAININGS_CREATE 402 | E 403 | Create a new watsonx.ai training 404 | 405 | 406 | ZCL_IBMX_WATSONX_AI_ML_V1 407 | TRAININGS_DELETE 408 | E 409 | Cancel or delete the training 410 | 411 | 412 | ZCL_IBMX_WATSONX_AI_ML_V1 413 | TRAININGS_GET 414 | E 415 | Retrieve the training 416 | 417 | 418 | ZCL_IBMX_WATSONX_AI_ML_V1 419 | TRAININGS_LIST 420 | E 421 | Retrieve the list of trainings 422 | 423 | 424 | 425 | 426 | 427 | -------------------------------------------------------------------------------- /src/zcl_ibmx_wml_v4.clas.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ZCL_IBMX_WML_V4 7 | E 8 | watsonx.ai Runtime 9 | 1 10 | X 11 | X 12 | X 13 | 14 | 15 | 16 | ZCL_IBMX_WML_V4 17 | DEPLOYMENTS_COMPUTE_PREDICT 18 | E 19 | Execute a synchronous deployment prediction 20 | 21 | 22 | ZCL_IBMX_WML_V4 23 | DEPLOYMENTS_CREATE 24 | E 25 | Create a new WML deployment 26 | 27 | 28 | ZCL_IBMX_WML_V4 29 | DEPLOYMENTS_DELETE 30 | E 31 | Delete the deployment 32 | 33 | 34 | ZCL_IBMX_WML_V4 35 | DEPLOYMENTS_GET 36 | E 37 | Retrieve the deployment details 38 | 39 | 40 | ZCL_IBMX_WML_V4 41 | DEPLOYMENTS_LIST 42 | E 43 | Retrieve the deployments 44 | 45 | 46 | ZCL_IBMX_WML_V4 47 | DEPLOYMENTS_UPDATE 48 | E 49 | Update the deployment metadata 50 | 51 | 52 | ZCL_IBMX_WML_V4 53 | DEPLOYMENT_JOBS_CREATE 54 | E 55 | Start an asynchronous deployment job 56 | 57 | 58 | ZCL_IBMX_WML_V4 59 | DEPLOYMENT_JOBS_DELETE 60 | E 61 | Cancel the deployment job 62 | 63 | 64 | ZCL_IBMX_WML_V4 65 | DEPLOYMENT_JOBS_GET 66 | E 67 | Retrieve the deployment job 68 | 69 | 70 | ZCL_IBMX_WML_V4 71 | DEPLOYMENT_JOBS_LIST 72 | E 73 | Retrieve the deployment jobs 74 | 75 | 76 | ZCL_IBMX_WML_V4 77 | DEPLOYMENT_JOB_DEFINITIONS_GET 78 | E 79 | Retrieve the deployment job definition 80 | 81 | 82 | ZCL_IBMX_WML_V4 83 | DEPLOYMENT_JOB_DEF_CREATE 84 | E 85 | Create a new deployment job definition 86 | 87 | 88 | ZCL_IBMX_WML_V4 89 | DEPLOYMENT_JOB_DEF_CRE_REV 90 | E 91 | Create a new deployment job definition revision 92 | 93 | 94 | ZCL_IBMX_WML_V4 95 | DEPLOYMENT_JOB_DEF_DELETE 96 | E 97 | Delete the deployment job definition 98 | 99 | 100 | ZCL_IBMX_WML_V4 101 | DEPLOYMENT_JOB_DEF_LIST 102 | E 103 | Retrieve the deployment job definitions 104 | 105 | 106 | ZCL_IBMX_WML_V4 107 | DEPLOYMENT_JOB_DEF_LST_REV 108 | E 109 | Retrieve the deployment job definition revisions 110 | 111 | 112 | ZCL_IBMX_WML_V4 113 | DEPLOYMENT_JOB_DEF_UPDATE 114 | E 115 | Update the deployment job definition 116 | 117 | 118 | ZCL_IBMX_WML_V4 119 | EXPERIMENTS_CREATE 120 | E 121 | Create a new experiment 122 | 123 | 124 | ZCL_IBMX_WML_V4 125 | EXPERIMENTS_CREATE_REVISION 126 | E 127 | Create a new experiment revision 128 | 129 | 130 | ZCL_IBMX_WML_V4 131 | EXPERIMENTS_DELETE 132 | E 133 | Delete the experiment 134 | 135 | 136 | ZCL_IBMX_WML_V4 137 | EXPERIMENTS_GET 138 | E 139 | Retrieve the experiment 140 | 141 | 142 | ZCL_IBMX_WML_V4 143 | EXPERIMENTS_LIST 144 | E 145 | Retrieve the experiments 146 | 147 | 148 | ZCL_IBMX_WML_V4 149 | EXPERIMENTS_LIST_REVISIONS 150 | E 151 | Retrieve the experiment revisions 152 | 153 | 154 | ZCL_IBMX_WML_V4 155 | EXPERIMENTS_UPDATE 156 | E 157 | Update the experiment 158 | 159 | 160 | ZCL_IBMX_WML_V4 161 | FUNCTIONS_CREATE 162 | E 163 | Create a new function 164 | 165 | 166 | ZCL_IBMX_WML_V4 167 | FUNCTIONS_CREATE_REVISION 168 | E 169 | Create a new function revision 170 | 171 | 172 | ZCL_IBMX_WML_V4 173 | FUNCTIONS_DELETE 174 | E 175 | Delete the function 176 | 177 | 178 | ZCL_IBMX_WML_V4 179 | FUNCTIONS_DOWNLOAD_CODE 180 | E 181 | Download the function code 182 | 183 | 184 | ZCL_IBMX_WML_V4 185 | FUNCTIONS_GET 186 | E 187 | Retrieve the function 188 | 189 | 190 | ZCL_IBMX_WML_V4 191 | FUNCTIONS_LIST 192 | E 193 | Retrieve the functions 194 | 195 | 196 | ZCL_IBMX_WML_V4 197 | FUNCTIONS_LIST_REVISIONS 198 | E 199 | Retrieve the function revisions 200 | 201 | 202 | ZCL_IBMX_WML_V4 203 | FUNCTIONS_UPDATE 204 | E 205 | Update the function 206 | 207 | 208 | ZCL_IBMX_WML_V4 209 | FUNCTIONS_UPLOAD_CODE 210 | E 211 | Upload the function code 212 | 213 | 214 | ZCL_IBMX_WML_V4 215 | INSTANCES_GET 216 | E 217 | Retrieve the service instance 218 | 219 | 220 | ZCL_IBMX_WML_V4 221 | INSTANCES_LIST 222 | E 223 | Retrieve the service instances 224 | 225 | 226 | ZCL_IBMX_WML_V4 227 | MODELS_CREATE 228 | E 229 | Create a new model 230 | 231 | 232 | ZCL_IBMX_WML_V4 233 | MODELS_CREATE_REVISION 234 | E 235 | Create a new model revision 236 | 237 | 238 | ZCL_IBMX_WML_V4 239 | MODELS_DELETE 240 | E 241 | Delete the model 242 | 243 | 244 | ZCL_IBMX_WML_V4 245 | MODELS_DELETE_CONTENT 246 | E 247 | Delete the model content 248 | 249 | 250 | ZCL_IBMX_WML_V4 251 | MODELS_DOWNLOAD_CONTENT 252 | E 253 | Download the model content 254 | 255 | 256 | ZCL_IBMX_WML_V4 257 | MODELS_FILTERED_DOWNLOAD 258 | E 259 | Download the model content that matches a certain criteria 260 | 261 | 262 | ZCL_IBMX_WML_V4 263 | MODELS_GET 264 | E 265 | Retrieve the model 266 | 267 | 268 | ZCL_IBMX_WML_V4 269 | MODELS_LIST 270 | E 271 | Retrieve the models 272 | 273 | 274 | ZCL_IBMX_WML_V4 275 | MODELS_LIST_ATTACHMENTS 276 | E 277 | Retrieve the model content metadata list 278 | 279 | 280 | ZCL_IBMX_WML_V4 281 | MODELS_LIST_REVISIONS 282 | E 283 | Retrieve the model revisions 284 | 285 | 286 | ZCL_IBMX_WML_V4 287 | MODELS_UPDATE 288 | E 289 | Update the model 290 | 291 | 292 | ZCL_IBMX_WML_V4 293 | MODELS_UPLOAD_CONTENT 294 | E 295 | Upload the model content 296 | 297 | 298 | ZCL_IBMX_WML_V4 299 | MODEL_DEFINITIONS_CREATE 300 | E 301 | Create a new model definition 302 | 303 | 304 | ZCL_IBMX_WML_V4 305 | MODEL_DEFINITIONS_DELETE 306 | E 307 | Delete the model definition 308 | 309 | 310 | ZCL_IBMX_WML_V4 311 | MODEL_DEFINITIONS_GET 312 | E 313 | Retrieve the model definition 314 | 315 | 316 | ZCL_IBMX_WML_V4 317 | MODEL_DEFINITIONS_LIST 318 | E 319 | Retrieve the model definitions 320 | 321 | 322 | ZCL_IBMX_WML_V4 323 | MODEL_DEFINITIONS_UPDATE 324 | E 325 | Update the model definition 326 | 327 | 328 | ZCL_IBMX_WML_V4 329 | MODEL_DEFINITIONS_UPLOAD_MODEL 330 | E 331 | Upload the model definition model 332 | 333 | 334 | ZCL_IBMX_WML_V4 335 | MODEL_DEF_CREATE_REVISION 336 | E 337 | Create a new model definition revision 338 | 339 | 340 | ZCL_IBMX_WML_V4 341 | MODEL_DEF_DOWNLOAD_MODEL 342 | E 343 | Download the model definition model 344 | 345 | 346 | ZCL_IBMX_WML_V4 347 | MODEL_DEF_LIST_REVISIONS 348 | E 349 | Retrieve the model definition revisions 350 | 351 | 352 | ZCL_IBMX_WML_V4 353 | PIPELINES_CREATE 354 | E 355 | Create a new pipeline 356 | 357 | 358 | ZCL_IBMX_WML_V4 359 | PIPELINES_CREATE_REVISION 360 | E 361 | Create a new pipeline revision 362 | 363 | 364 | ZCL_IBMX_WML_V4 365 | PIPELINES_DELETE 366 | E 367 | Delete the pipeline 368 | 369 | 370 | ZCL_IBMX_WML_V4 371 | PIPELINES_GET 372 | E 373 | Retrieve the pipeline 374 | 375 | 376 | ZCL_IBMX_WML_V4 377 | PIPELINES_LIST 378 | E 379 | Retrieve the pipelines 380 | 381 | 382 | ZCL_IBMX_WML_V4 383 | PIPELINES_LIST_REVISIONS 384 | E 385 | Retrieve the pipeline revisions 386 | 387 | 388 | ZCL_IBMX_WML_V4 389 | PIPELINES_UPDATE 390 | E 391 | Update the pipeline 392 | 393 | 394 | ZCL_IBMX_WML_V4 395 | REMOTE_TRAINING_SYSTEMS_CREATE 396 | E 397 | Create a new remote training system 398 | 399 | 400 | ZCL_IBMX_WML_V4 401 | REMOTE_TRAINING_SYSTEMS_DELETE 402 | E 403 | Delete the remote training system 404 | 405 | 406 | ZCL_IBMX_WML_V4 407 | REMOTE_TRAINING_SYSTEMS_GET 408 | E 409 | Retrieve the remote training system 410 | 411 | 412 | ZCL_IBMX_WML_V4 413 | REMOTE_TRAINING_SYSTEMS_LIST 414 | E 415 | Retrieve the remote training systems 416 | 417 | 418 | ZCL_IBMX_WML_V4 419 | REMOTE_TRAINING_SYSTEMS_UPDATE 420 | E 421 | Update the remote training system 422 | 423 | 424 | ZCL_IBMX_WML_V4 425 | REMOTE_TRAIN_SYS_CRE_REVISION 426 | E 427 | Create a new remote training system revision 428 | 429 | 430 | ZCL_IBMX_WML_V4 431 | REMOTE_TRAIN_SYS_LST_REVISIONS 432 | E 433 | Retrieve the remote training system revisions 434 | 435 | 436 | ZCL_IBMX_WML_V4 437 | TRAININGS_CREATE 438 | E 439 | Create a new WML training 440 | 441 | 442 | ZCL_IBMX_WML_V4 443 | TRAININGS_DELETE 444 | E 445 | Cancel the training 446 | 447 | 448 | ZCL_IBMX_WML_V4 449 | TRAININGS_GET 450 | E 451 | Retrieve the training 452 | 453 | 454 | ZCL_IBMX_WML_V4 455 | TRAININGS_LIST 456 | E 457 | Retrieve the list of trainings 458 | 459 | 460 | ZCL_IBMX_WML_V4 461 | TRAINING_DEFINITIONS_CREATE 462 | E 463 | Create a new training definition 464 | 465 | 466 | ZCL_IBMX_WML_V4 467 | TRAINING_DEFINITIONS_DELETE 468 | E 469 | Delete the training definition 470 | 471 | 472 | ZCL_IBMX_WML_V4 473 | TRAINING_DEFINITIONS_GET 474 | E 475 | Retrieve the training definition 476 | 477 | 478 | ZCL_IBMX_WML_V4 479 | TRAINING_DEFINITIONS_LIST 480 | E 481 | Retrieve the training definitions 482 | 483 | 484 | ZCL_IBMX_WML_V4 485 | TRAINING_DEFINITIONS_UPDATE 486 | E 487 | Update the training definition 488 | 489 | 490 | ZCL_IBMX_WML_V4 491 | TRAIN_DEF_CREATE_REVISION 492 | E 493 | Create a new training definition revision 494 | 495 | 496 | ZCL_IBMX_WML_V4 497 | TRAIN_DEF_LIST_REVISIONS 498 | E 499 | Retrieve the training definition revisions 500 | 501 | 502 | 503 | 504 | 505 | -------------------------------------------------------------------------------- /src/zcl_ibmx_util.clas.abap: -------------------------------------------------------------------------------- 1 | * Copyright 2019, 2025 IBM Corp. All Rights Reserved. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | class ZCL_IBMX_util definition 15 | public 16 | final 17 | create public . 18 | 19 | public section. 20 | 21 | 22 | "! Converts an internal table to JSON string in table schema format. 23 | "! E.g.: '{"fields": ["PET", "NUMBER"], "values": [["Cat",5],["Rabbit",2]]}' 24 | "! 25 | "! @parameter I_ITAB | Internal table to be converted. 26 | "! @parameter I_DICTIONARY | Dictionary to be used for mapping ABAP identifiers to JSON keys. 27 | "! @parameter I_LOWER_CASE | If set to C_BOOLEAN_TRUE all keys in JSON string will be lower case. 28 | "! @parameter IT_EXCLUDED_FIELDS | Internal table of table fields in I_ITAB that should not occur in result. 29 | "! @parameter E_JSON | JSON string. 30 | "! 31 | class-methods itab_to_tableschema 32 | importing 33 | !i_itab type any table 34 | !i_dictionary type any optional 35 | !i_lower_case type ZCL_IBMX_service=>boolean default ZCL_IBMX_service=>c_boolean_false 36 | !it_excluded_fields type ZCL_IBMX_service=>tt_string optional 37 | returning 38 | value(e_json) type string . 39 | "! Converts a JSON string in table schema format to an internal table. 40 | "! E.g.: '{"tableschema_key": {"fields": ["PET", "NUMBER"], "values": [["Cat",5],["Rabbit",2]]}}' 41 | "! 42 | "! @parameter I_JSON | JSON string. 43 | "! @parameter I_TABLESCHEMA_KEY | Key in JSON string that holds the table schema. 44 | "! @parameter E_ITAB | Internal table containing converted data. 45 | "! 46 | class-methods tableschema_to_itab 47 | importing 48 | !i_json type string 49 | !i_tableschema_key type string optional 50 | exporting 51 | !e_itab type any table . 52 | "! Converts a timestamp in UTC to a timestamp in local time. 53 | "! 54 | "! @parameter IV_TIMESTAMP | Timestamp (UTC). 55 | "! @parameter EV_LOCAL | Timestamp (local time). 56 | "! 57 | class-methods convert_timestamp_to_local 58 | importing 59 | !iv_timestamp type timestamp 60 | returning 61 | value(ev_local) type string . 62 | "! Determine MIME type from a file name, e.g. 'docu.txt' -> 'text_/plain'. 63 | "! 64 | "! @parameter I_FILENAME | Filename with extension. 65 | "! @parameter E_MIMETYPE | MIME type. 66 | "! 67 | class-methods get_mimetype_from_extension 68 | importing 69 | !i_filename type string 70 | returning 71 | value(e_mimetype) type string . 72 | "! Converts a timestamp in UTC to a timestamp in another timezone. 73 | "! 74 | "! @parameter I_TIMESTAMP | Timestamp (UTC). 75 | "! @parameter I_TIMEZONE | Time zone 76 | "! @parameter E_TIMESTAMP | Timestamp in give time zone. 77 | "! 78 | class-methods utc_to_timezone 79 | importing 80 | !i_timestamp type timestamp 81 | !i_timezone type ZIF_IBMX_service_arch=>ty_timezone optional 82 | returning 83 | value(e_timestamp) type timestamp . 84 | "! Converts datetime format to a timestamp, i.e. yyyy-mm-ddThh:mm:ssZ -> YYYYMMDDHHMMSS 85 | "! 86 | "! @parameter I_DATETIME | Input in datetime format. 87 | "! @parameter E_TIMESTAMP | Timestamp. 88 | "! 89 | class-methods convert_datetime_to_timestamp 90 | importing 91 | !i_datetime type ZCL_IBMX_service=>datetime 92 | returning 93 | value(e_timestamp) type timestamp . 94 | "! Converts a timestamp to datetime format, i.e. YYYYMMDDHHMMSS -> yyyy-mm-ddThh:mm:ssZ 95 | "! 96 | "! @parameter I_TIMESTAMP | Timestamp. 97 | "! @parameter E_DATETIME | Datetime format. 98 | "! 99 | class-methods convert_timestamp_to_datetime 100 | importing 101 | !i_timestamp type timestamp 102 | returning 103 | value(e_datetime) type ZCL_IBMX_service=>datetime . 104 | protected section. 105 | private section. 106 | ENDCLASS. 107 | 108 | 109 | 110 | CLASS ZCL_IBMX_UTIL IMPLEMENTATION. 111 | 112 | 113 | * ---------------------------------------------------------------------------------------+ 114 | * | Static Public Method ZCL_IBMX_UTIL=>CONVERT_DATETIME_TO_TIMESTAMP 115 | * +-------------------------------------------------------------------------------------------------+ 116 | * | [--->] I_DATETIME TYPE ZCL_IBMX_SERVICE=>DATETIME 117 | * | [<-()] E_TIMESTAMP TYPE TIMESTAMP 118 | * +-------------------------------------------------------------------------------------- 119 | method convert_datetime_to_timestamp. 120 | 121 | constants: 122 | c_zero type timestamp value '0'. " avoid conversion at runtime 123 | 124 | " check if input string applies to schema yyyy-mm-ddThh:mm:ssZ 125 | if i_datetime cp '++++-++-++T++:++:++*'. 126 | try. 127 | e_timestamp = 128 | i_datetime(4) * 10000000000 + i_datetime+5(2) * 100000000 + i_datetime+8(2) * 1000000 + 129 | i_datetime+11(2) * 10000 + i_datetime+14(2) * 100 + i_datetime+17(2). 130 | catch cx_sy_conversion_no_number. 131 | " invalid input 132 | e_timestamp = c_zero. 133 | endtry. 134 | else. 135 | " invalid input 136 | e_timestamp = c_zero. 137 | endif. 138 | 139 | endmethod. 140 | 141 | 142 | * ---------------------------------------------------------------------------------------+ 143 | * | Static Public Method ZCL_IBMX_UTIL=>CONVERT_TIMESTAMP_TO_DATETIME 144 | * +-------------------------------------------------------------------------------------------------+ 145 | * | [--->] I_TIMESTAMP TYPE TIMESTAMP 146 | * | [<-()] E_DATETIME TYPE ZCL_IBMX_SERVICE=>DATETIME 147 | * +-------------------------------------------------------------------------------------- 148 | method convert_timestamp_to_datetime. 149 | 150 | data: 151 | lv_year(4) type n, 152 | lv_month(2) type n, 153 | lv_day(2) type n, 154 | lv_hour(2) type n, 155 | lv_min(2) type n, 156 | lv_sec(2) type n, 157 | lv_rest type timestamp. 158 | 159 | lv_rest = i_timestamp. 160 | lv_year = lv_rest div 10000000000. 161 | lv_rest = lv_rest - ( lv_year * 10000000000 ). 162 | lv_month = lv_rest div 100000000. 163 | lv_rest = lv_rest - ( lv_month * 100000000 ). 164 | lv_day = lv_rest div 1000000. 165 | lv_rest = lv_rest - ( lv_day * 1000000 ). 166 | lv_hour = lv_rest div 10000. 167 | lv_rest = lv_rest - ( lv_hour * 10000 ). 168 | lv_min = lv_rest div 100. 169 | lv_rest = lv_rest - ( lv_min * 100 ). 170 | lv_sec = lv_rest div 1. " type conversion 171 | 172 | concatenate lv_year '-' lv_month '-' lv_day 'T' lv_hour ':' lv_min ':' lv_sec 'Z' into e_datetime. 173 | 174 | endmethod. 175 | 176 | 177 | * ---------------------------------------------------------------------------------------+ 178 | * | Static Public Method ZCL_IBMX_UTIL=>CONVERT_TIMESTAMP_TO_LOCAL 179 | * +-------------------------------------------------------------------------------------------------+ 180 | * | [--->] IV_TIMESTAMP TYPE TIMESTAMP 181 | * | [<-()] EV_LOCAL TYPE STRING 182 | * +-------------------------------------------------------------------------------------- 183 | method convert_timestamp_to_local. 184 | 185 | data: 186 | lv_dats type d, 187 | lv_tims type t, 188 | lv_timezone type ZIF_IBMX_service_arch=>ty_timezone, 189 | lv_datc(10) type c, 190 | lv_timc(8) type c. 191 | 192 | " split timestamp to date and time according to time zone 193 | lv_timezone = ZCL_IBMX_service_arch=>get_timezone( ). 194 | convert time stamp iv_timestamp time zone lv_timezone 195 | into date lv_dats time lv_tims. 196 | 197 | " write date and time to string using local date/time format 198 | lv_datc = conv #( lv_dats ). 199 | lv_timc = conv #( lv_tims ). 200 | concatenate lv_datc lv_timc into ev_local separated by space. 201 | 202 | endmethod. 203 | 204 | 205 | * ---------------------------------------------------------------------------------------+ 206 | * | Static Public Method ZCL_IBMX_UTIL=>GET_MIMETYPE_FROM_EXTENSION 207 | * +-------------------------------------------------------------------------------------------------+ 208 | * | [--->] I_FILENAME TYPE STRING 209 | * | [<-()] E_MIMETYPE TYPE STRING 210 | * +-------------------------------------------------------------------------------------- 211 | method get_mimetype_from_extension. 212 | data: 213 | l_extension type string. 214 | 215 | if i_filename is initial. 216 | e_mimetype = ZIF_IBMX_service_arch=>c_mediatype-all. 217 | exit. 218 | endif. 219 | 220 | "find regex '\.([^\.]*)$' in i_filename submatches l_extension. 221 | data(l_subrc) = ZCL_IBMX_service=>find_regex( 222 | exporting 223 | i_regex = '\.([^\.]*)$' 224 | i_in = i_filename 225 | changing 226 | c_submatch1 = l_extension ). 227 | if l_subrc <> 0. 228 | l_extension = i_filename. 229 | endif. 230 | 231 | translate l_extension to lower case. 232 | 233 | case l_extension. 234 | when 'jpg' or 'jpeg'. e_mimetype = ZIF_IBMX_service_arch=>c_mediatype-image_jpeg. 235 | when 'png'. e_mimetype = ZIF_IBMX_service_arch=>c_mediatype-image_png. 236 | when 'txt'. e_mimetype = ZIF_IBMX_service_arch=>c_mediatype-text_plain. 237 | when 'csv'. e_mimetype = ZIF_IBMX_service_arch=>c_mediatype-text_csv. 238 | when others. e_mimetype = `application/` && l_extension ##NO_TEXT. 239 | endcase. 240 | 241 | endmethod. 242 | 243 | 244 | * ---------------------------------------------------------------------------------------+ 245 | * | Static Public Method ZCL_IBMX_UTIL=>ITAB_TO_TABLESCHEMA 246 | * +-------------------------------------------------------------------------------------------------+ 247 | * | [--->] I_ITAB TYPE ANY TABLE 248 | * | [--->] I_DICTIONARY TYPE ANY(optional) 249 | * | [--->] I_LOWER_CASE TYPE ZCL_IBMX_SERVICE=>BOOLEAN (default =ZCL_IBMX_SERVICE=>C_BOOLEAN_FALSE) 250 | * | [--->] IT_EXCLUDED_FIELDS TYPE ZCL_IBMX_SERVICE=>TT_STRING(optional) 251 | * | [<-()] E_JSON TYPE STRING 252 | * +-------------------------------------------------------------------------------------- 253 | method itab_to_tableschema. 254 | " Converts an internal table to a JSON object string with keys "fields" and "values". 255 | " Example: I_ITAB = | PET | NUMBER | 256 | " ------------------- 257 | " | Cat | 5 | 258 | " | Rabbit | 2 | 259 | " --> E_JSON = '{"fields": ["PET", "NUMBER"], "values": [["Cat",5],["Rabbit",2]]}' 260 | " Field names are mapped according to I_DICTIONARY. 261 | " Example: BEGIN OF i_dictionary, 262 | " PET type string value 'MyPet', 263 | " END OF i_dictionary. 264 | " --> E_JSON = '{"fields": ["MyPet", "NUMBER"], "values": [["Cat",5],["Rabbit",2]]}' 265 | " Field names are translated to lower case, if I_LOWER_CASE = ZCL_IBMX_service=>c_boolean_true. 266 | " Field types must be elementary or table of elementary. 267 | " Field names in table IT_EXCLUDED_FIELDS are skipped and will not appear in the JSON string. 268 | 269 | data: 270 | lt_comp type cl_abap_structdescr=>component_table, 271 | ls_comp like line of lt_comp, 272 | lo_datadescr type ref to cl_abap_datadescr, 273 | lo_tabledesc type ref to cl_abap_tabledescr, 274 | lo_struct type ref to cl_abap_structdescr, 275 | lv_fieldname type string, 276 | lv_sep1(1) type c, 277 | lv_sep2(1) type c, 278 | lv_sep3(1) type c. 279 | 280 | field-symbols: 281 | type any, 282 | type any, 283 | type any table, 284 | type string. 285 | 286 | " the following data type are character-like, thus the according values must be quoted 287 | data(lc_character_types) = 288 | cl_abap_datadescr=>typekind_char && 289 | cl_abap_datadescr=>typekind_clike && 290 | cl_abap_datadescr=>typekind_csequence && 291 | cl_abap_datadescr=>typekind_string && 292 | cl_abap_datadescr=>typekind_date && 293 | cl_abap_datadescr=>typekind_time && 294 | cl_abap_datadescr=>typekind_num. 295 | 296 | " get internal table fields 297 | lo_tabledesc ?= cl_abap_tabledescr=>describe_by_data( i_itab ). 298 | lo_struct ?= lo_tabledesc->get_table_line_type( ). 299 | lt_comp = lo_struct->get_components( ). 300 | 301 | " append field names to JSON string 302 | e_json = `{"fields": [` ##NO_TEXT. 303 | clear lv_sep1. 304 | loop at lt_comp into ls_comp. 305 | read table it_excluded_fields with key table_line = ls_comp-name transporting no fields. 306 | if sy-subrc = 0. continue. endif. 307 | lv_fieldname = ls_comp-name. 308 | if i_dictionary is supplied. 309 | assign component ls_comp-name of structure i_dictionary to . 310 | if sy-subrc = 0. 311 | lv_fieldname = . 312 | endif. 313 | endif. 314 | if i_lower_case eq ZCL_IBMX_service=>c_boolean_true. 315 | translate lv_fieldname to lower case. 316 | endif. 317 | e_json = e_json && lv_sep1 && `"` && lv_fieldname && `"`. 318 | lv_sep1 = `,`. 319 | endloop. 320 | 321 | " append values to JSON string 322 | e_json = e_json && `], "values": [` ##NO_TEXT. 323 | 324 | clear lv_sep1. 325 | loop at i_itab assigning . " loop on itab records 326 | clear lv_sep2. 327 | e_json = e_json && lv_sep1 && `[`. 328 | loop at lt_comp into ls_comp. " loop on record fields 329 | read table it_excluded_fields with key table_line = ls_comp-name transporting no fields. 330 | if sy-subrc = 0. continue. endif. 331 | 332 | if ls_comp-type->type_kind eq cl_abap_datadescr=>typekind_table. 333 | 334 | " field type is subtable, get line type 335 | assign component ls_comp-name of structure to . 336 | lo_tabledesc ?= cl_abap_tabledescr=>describe_by_data( ). 337 | lo_datadescr = lo_tabledesc->get_table_line_type( ). 338 | 339 | " add field values of subtable to JSON string 340 | clear lv_sep3. 341 | e_json = e_json && lv_sep2 && `[`. 342 | loop at assigning . 343 | if lo_datadescr->type_kind ca lc_character_types. 344 | e_json = e_json && lv_sep3 && `"` && && `"`. 345 | else. 346 | e_json = e_json && lv_sep3 && . 347 | endif. 348 | lv_sep3 = `,`. 349 | endloop. 350 | e_json = e_json && `]`. 351 | 352 | else. 353 | 354 | " field type is elementary, add field value to JSON string 355 | assign component ls_comp-name of structure to . 356 | if ls_comp-type->type_kind ca lc_character_types. 357 | e_json = e_json && lv_sep2 && `"` && && `"`. 358 | else. 359 | e_json = e_json && lv_sep2 && . 360 | endif. 361 | 362 | endif. 363 | 364 | lv_sep2 = `,`. 365 | endloop. 366 | 367 | e_json = e_json && `]`. 368 | lv_sep1 = `,`. 369 | endloop. 370 | 371 | e_json = e_json && `]}` ##NO_TEXT. 372 | 373 | endmethod. 374 | 375 | 376 | * ---------------------------------------------------------------------------------------+ 377 | * | Static Public Method ZCL_IBMX_UTIL=>TABLESCHEMA_TO_ITAB 378 | * +-------------------------------------------------------------------------------------------------+ 379 | * | [--->] I_JSON TYPE STRING 380 | * | [--->] I_TABLESCHEMA_KEY TYPE STRING(optional) 381 | * | [<---] E_ITAB TYPE ANY TABLE 382 | * +-------------------------------------------------------------------------------------- 383 | method tableschema_to_itab. 384 | 385 | data: 386 | lt_comp type cl_abap_structdescr=>component_table, 387 | ls_comp like line of lt_comp, 388 | lv_field type string, 389 | lt_field type standard table of string, 390 | lv_fieldname type string, 391 | lv_tabix type i, 392 | lv_tableschema_key type string, 393 | lo_structdescr type ref to cl_abap_structdescr, 394 | lo_datadescr type ref to cl_abap_datadescr, 395 | lo_tabledescr type ref to cl_abap_tabledescr, 396 | lr_values type ref to data, 397 | lr_comp type ref to data, 398 | lr_data type ref to data, 399 | lv_json type string. 400 | 401 | field-symbols: 402 | type ref to data, 403 | type any table, 404 | type any, 405 | type any, 406 | type any table, 407 | type any, 408 | type any, 409 | type ref to data, 410 | type any table, 411 | type any table, 412 | type any, 413 | type any table, 414 | type any table. 415 | 416 | " dynamically create data structure: 417 | " begin of , 418 | " tableschema_key type ref to data, 419 | " end of . 420 | if i_tableschema_key is initial. 421 | lv_json = `{ "tableschema_key": ` && i_json && ` }` ##NO_TEXT. 422 | lv_tableschema_key = `tableschema_key` ##NO_TEXT. 423 | else. 424 | lv_json = i_json. 425 | lv_tableschema_key = i_tableschema_key. 426 | endif. 427 | ls_comp-name = lv_tableschema_key. 428 | ls_comp-type ?= cl_abap_datadescr=>describe_by_data( lr_data ). 429 | append ls_comp to lt_comp. 430 | lo_structdescr = cl_abap_structdescr=>create( lt_comp ). 431 | create data lr_data type handle lo_structdescr. 432 | assign lr_data->* to . 433 | 434 | " parse JSON 435 | try. 436 | ZCL_IBMX_service=>parse_json( 437 | exporting 438 | i_json = lv_json 439 | "i_dictionary = c_abapname_dictionary 440 | changing 441 | c_abap = ). 442 | catch ZCX_IBMX_service_exception. 443 | return. 444 | endtry. 445 | assign component lv_tableschema_key of structure to . 446 | assign ->* to . 447 | 448 | 449 | 450 | unassign . 451 | assign component 'VALUES' of structure to . 452 | 453 | " I_JSON does not have table schema on highest level, check if any subkey has 454 | " check all components 455 | lo_structdescr ?= cl_abap_structdescr=>describe_by_data( ). 456 | clear lt_comp[]. 457 | lt_comp = lo_structdescr->get_components( ). 458 | 459 | loop at lt_comp into ls_comp. 460 | assign component ls_comp-name of structure to . 461 | lo_datadescr ?= cl_abap_datadescr=>describe_by_data_ref( ). 462 | if lo_datadescr->type_kind eq cl_abap_datadescr=>typekind_table. 463 | assign ->* to . 464 | loop at assigning ##GEN_OK. 465 | exit. 466 | endloop. 467 | endif. 468 | assign ->* to . 469 | assign component 'VALUES' of structure to . 470 | if sy-subrc = 0. 471 | assign to . 472 | exit. 473 | endif. 474 | 475 | endloop. 476 | 477 | 478 | if not is assigned. 479 | return. 480 | endif. 481 | 482 | assign ->* to . 483 | assign component 'FIELDS' of structure to . 484 | if sy-subrc = 0. 485 | assign ->* to . 486 | loop at assigning ##GEN_OK. 487 | assign ->* to . 488 | append to lt_field. 489 | endloop. 490 | else. 491 | data(lv_count) = lines( ). 492 | data(lv_index) = 0. 493 | while lv_index < lv_count. 494 | lv_fieldname = `FIELD` && lv_index. 495 | lv_index = lv_index + 1. 496 | append lv_fieldname to lt_field. 497 | endwhile. 498 | endif. 499 | 500 | 501 | " get data fields; read first values for reference 502 | if lines( ) < 1. return. endif. 503 | loop at into lr_data. 504 | assign lr_data->* to . 505 | exit. 506 | endloop. 507 | 508 | clear lt_comp[]. 509 | loop at into lr_values. 510 | 511 | " field name 512 | lv_tabix = lv_tabix + 1. 513 | read table lt_field index lv_tabix into lv_field. 514 | if sy-subrc <> 0. 515 | lv_field = `C` && lv_tabix. 516 | endif. 517 | ls_comp-name = lv_field. 518 | 519 | " read data type 520 | assign lr_values->* to . 521 | lo_datadescr ?= cl_abap_datadescr=>describe_by_data( ). 522 | 523 | if lo_datadescr->type_kind = cl_abap_structdescr=>typekind_table. 524 | 525 | " data type is internal table (of references) 526 | " -> create new internal table layout w/o references 527 | lo_tabledescr ?= cl_abap_tabledescr=>describe_by_data( ). 528 | lo_datadescr = lo_tabledescr->get_table_line_type( ). 529 | if lo_datadescr->type_kind = cl_abap_datadescr=>typekind_dref. 530 | assign to . 531 | loop at into lr_comp. exit. endloop. " read first table record 532 | lo_datadescr ?= cl_abap_datadescr=>describe_by_data_ref( lr_comp ). 533 | endif. 534 | ls_comp-type = cl_abap_tabledescr=>create( p_line_type = lo_datadescr ). 535 | 536 | else. 537 | ls_comp-type = lo_datadescr. 538 | endif. 539 | 540 | append ls_comp to lt_comp. 541 | endloop. 542 | 543 | " create data structure 544 | lo_structdescr = cl_abap_structdescr=>create( lt_comp ). 545 | create data lr_data type handle lo_structdescr. 546 | assign lr_data->* to . 547 | create data lr_data like table of . 548 | assign lr_data->* to . 549 | 550 | 551 | " populate data structure 552 | loop at into lr_data. 553 | assign lr_data->* to . 554 | if not is assigned. 555 | create data lr_data type handle lo_structdescr. 556 | assign lr_data->* to . 557 | endif. 558 | lv_tabix = 0. 559 | loop at into lr_values. 560 | lv_tabix = lv_tabix + 1. 561 | read table lt_comp index lv_tabix into ls_comp. 562 | case ls_comp-type->type_kind. 563 | when cl_abap_structdescr=>typekind_table. 564 | assign component ls_comp-name of structure to . 565 | assign lr_values->* to . 566 | loop at into lr_data. 567 | assign lr_data->* to . 568 | insert into table . 569 | endloop. 570 | when others. 571 | assign component ls_comp-name of structure to . 572 | assign lr_values->* to . 573 | = . 574 | endcase. 575 | endloop. 576 | 577 | insert into table . 578 | unassign . " force data creation at next loop step 579 | 580 | endloop. 581 | 582 | move-corresponding to e_itab. 583 | 584 | endmethod. 585 | 586 | 587 | * ---------------------------------------------------------------------------------------+ 588 | * | Static Public Method ZCL_IBMX_UTIL=>UTC_TO_TIMEZONE 589 | * +-------------------------------------------------------------------------------------------------+ 590 | * | [--->] I_TIMESTAMP TYPE TIMESTAMP 591 | * | [--->] I_TIMEZONE TYPE ZIF_IBMX_SERVICE_ARCH=>TY_TIMEZONE(optional) 592 | * | [<-()] E_TIMESTAMP TYPE TIMESTAMP 593 | * +-------------------------------------------------------------------------------------- 594 | method utc_to_timezone. 595 | 596 | data: 597 | lv_timezone type ZIF_IBMX_service_arch=>ty_timezone, 598 | lv_date type d, 599 | lv_time type t. 600 | 601 | if i_timezone is initial. 602 | lv_timezone = ZCL_IBMX_service_arch=>get_timezone( ). 603 | else. 604 | lv_timezone = i_timezone. 605 | endif. 606 | 607 | convert time stamp i_timestamp time zone lv_timezone into date lv_date time lv_time. 608 | convert date lv_date time lv_time into time stamp e_timestamp time zone 'UTC'. 609 | 610 | endmethod. 611 | ENDCLASS. 612 | -------------------------------------------------------------------------------- /docs/ABAPDoc/abapdoc/zibmx/classes/zcl_ibmx_service_arch.html: -------------------------------------------------------------------------------- 1 | Class ZCL_IBMX_SERVICE_ARCH

Class ZCL_IBMX_SERVICE_ARCH

public create public

Documentation

IBM Watson SDK Platform-specifics

Interfaces

zif_ibmx_service_arch

Types

Visibility and LevelNameDocumentation
publicto_form_part type ref to IF_HTTP_ENTITY 
publicto_http_client type ref to IF_HTTP_CLIENTHTTP Client Control Block
publicto_http_entity type ref to IF_HTTP_ENTITY 
publicto_rest_client type ref to CL_REST_HTTP_CLIENTREST HTTP Client
publicto_rest_entity type ref to IF_REST_ENTITY 
publicto_rest_request type ref to IF_REST_ENTITY 
publicto_rest_response type ref to IF_REST_ENTITY 
publicts_access_token type ZIF_IBMX_SERVICE_ARCH~TS_ACCESS_TOKEN 
publicts_client (structured type) 
publicts_header type ZIF_IBMX_SERVICE_ARCH~TS_HEADER 
publicts_http_status type ZIF_IBMX_SERVICE_ARCH~TS_HTTP_STATUS 
publicts_request_prop type ZIF_IBMX_SERVICE_ARCH~TS_REQUEST_PROP 
publicts_url type ZIF_IBMX_SERVICE_ARCH~TS_URL 
publictt_header type ZIF_IBMX_SERVICE_ARCH~TT_HEADER 

Methods

Visibility and LevelNameDocumentation
public static
base64_decode
importingi_base64type STRING
returningvalue(e_binary)type XSTRING
raisingzcx_ibmx_service_exception

Decodes base64 encoded data to binary.

2 | 3 |
Parameters
i_base64 Base64-encoded binary 4 |
e_binary Binary data 5 |
Class-based Exceptions
zcx_ibmx_service_exception Exception being raised in case of an error. 6 |
public static
base64_encode
importingi_unencodedtype STRING
returningvalue(e_encoded)type STRING

Encodes a string to base64 format.

7 | 8 |
Parameters
i_unencoded String, unencoded 9 |
e_encoded Base64-encoded string 10 |
public static
convert_string_to_utf8
importingi_stringtype STRING
returningvalue(e_utf8)type XSTRING
raisingzcx_ibmx_service_exception

Converts STRING data to UTF8 encoded XSTRING.

11 | 12 |
Parameters
i_string STRING data 13 |
e_utf8 UTF8-encoded data 14 |
public static
create_client_by_destination
importingi_request_proptype TS_REQUEST_PROP
exportinge_clienttype TS_CLIENT
raisingzcx_ibmx_service_exception

Returns a HTTP/REST client based on an DESTINATION.

15 | 16 |
Parameters
i_request_prop Request parameters 17 |
e_client HTTP/REST client 18 |
Class-based Exceptions
zcx_ibmx_service_exception Exception being raised in case of an error. 19 |
public static
create_client_by_scenario
importingi_request_proptype TS_REQUEST_PROP
exportinge_clienttype TS_CLIENT
raisingzcx_ibmx_service_exception

Returns a HTTP/REST client based on COMMUNICATION SCENARIO.

20 | 21 |
Parameters
i_request_prop Request parameters 22 |
e_client HTTP/REST client 23 |
Class-based Exceptions
zcx_ibmx_service_exception Exception being raised in case of an error. 24 |
public static
create_client_by_url
importingi_urltype STRING
i_request_proptype TS_REQUEST_PROP
exportinge_clienttype TS_CLIENT
raisingzcx_ibmx_service_exception

Returns a HTTP/REST client based on an URL.

25 | 26 |
Parameters
i_url URL 27 |
i_request_prop Request parameters 28 |
e_client HTTP/REST client 29 |
Class-based Exceptions
zcx_ibmx_service_exception Exception being raised in case of an error. 30 |
public static
execute
importingi_clienttype TS_CLIENT
i_methodtype ZIF_IBMX_SERVICE_ARCH~CHAR default ZIF_IBMX_SERVICE_ARCH~C_METHOD_GET
returningvalue(e_response)type TO_REST_RESPONSE
raisingzcx_ibmx_service_exception

Executes a HTTP request.

31 | 32 |
Parameters
i_client HTTP/REST client 33 |
i_method HTTP method (GET,POST,PUT,DELETE) 34 |
e_response Response of the request 35 |
Class-based Exceptions
zcx_ibmx_service_exception Exception being raised in case of an error. 36 |
public static
find_regex
importingi_regextype STRING
i_withtype STRING optional
i_all_occurrencestype ZIF_IBMX_SERVICE_ARCH=>BOOLEAN default 'X'
i_ignoring_casetype ZIF_IBMX_SERVICE_ARCH=>BOOLEAN optional
i_intype STRING optional
exportinge_offsettype INT4
changingc_submatch1type STRING optional
c_submatch2type STRING optional
c_submatch3type STRING optional
c_intype STRING optional
returningvalue(e_subrc)type SYSUBRC

Finds (and replaces) a regular expression.

37 | 38 |
Parameters
i_regex Regular expression 39 |
i_with Replacement (if omitted, FIND is performed) 40 |
i_all_occurrences 'X' if ALL OCCURRENCES OF should be used 41 |
i_ignoring_case 'X', if IGNORING CASE should be used 42 |
i_in String to be searched 43 |
e_offset Returns position of occurrence 44 |
c_submatch1 1st submatch 45 |
c_submatch2 2nd submatch 46 |
c_submatch3 3rd submatch 47 |
c_in String to be searched and returned 48 |
e_subrc sy-subrc of FIND / REPLACE 49 |
public static
get_default_proxy
importingi_urltype TS_URL optional
exportinge_proxy_hosttype STRING
e_proxy_porttype STRING

Returns the default proxy host and port.

50 | 51 |
Parameters
i_url target URL 52 |
e_proxy_host Proxy host 53 |
e_proxy_port Proxy port 54 |
public static
get_http_status
importingi_rest_responsetype TO_REST_RESPONSE
returningvalue(e_status)type TS_HTTP_STATUS

Returns the status of a REST response.

55 | 56 |
Parameters
i_rest_response HTTP/REST response 57 |
e_status HTTP status 58 |
public static
get_progname
returningvalue(e_progname)type STRING

Returns an ABAP module identifier.

59 | 60 |
Parameters
e_progname ABAP module identifier 61 |
public static
get_response_binary
importingi_responsetype TO_REST_RESPONSE
returningvalue(e_data)type XSTRING

Reads binary data from a HTTP response.

62 | 63 |
Parameters
i_response HTTP response 64 |
e_data Binary data 65 |
public static
get_response_header
importingi_responsetype TO_REST_RESPONSE
i_header_fieldtype STRING
returningvalue(e_value)type STRING

Returns a HTTP response header.

66 | 67 |
Parameters
i_response HTTP/REST response 68 |
i_header_field Header field name 69 |
e_value Header field value 70 |
public static
get_response_string
importingi_responsetype TO_REST_RESPONSE
returningvalue(e_data)type STRING

Reads character data from a HTTP response.

71 | 72 |
Parameters
i_response HTTP response 73 |
e_data Character data 74 |
public static
get_rest_request
importingi_clienttype TS_CLIENT
returningvalue(e_rest_request)type TO_REST_REQUEST

Returns a request object from a HTTP client object.

75 | 76 |
Parameters
i_client HTTP/REST client 77 |
e_rest_request REST request object 78 |
public static
get_timezone
returningvalue(e_timezone)type ZIF_IBMX_SERVICE_ARCH~TY_TIMEZONE

Returns the user's time zone.

79 | 80 |
Parameters
e_timezone user's time zone 81 |
public static
set_authentication_basic
importingi_clienttype TS_CLIENT
i_usernametype STRING
i_passwordtype STRING

Sets request header for basic authentication.

82 | 83 |
Parameters
i_client HTTP/REST client 84 |
i_username User name 85 |
i_password Password 86 |
public static
set_request_body_cdata
importingi_clienttype TS_CLIENT
i_datatype STRING

Set character data for the body of a HTTP request.

87 | 88 |
Parameters
i_client HTTP/REST client 89 |
i_data Character data 90 |
public static
set_request_body_xdata
importingi_clienttype TS_CLIENT
i_datatype XSTRING

Set binary data for the body of a HTTP request.

91 | 92 |
Parameters
i_client HTTP/REST client 93 |
i_data Binary data 94 |
public static
set_request_header
importingi_clienttype TS_CLIENT
i_nametype STRING
i_valuetype STRING

Sets a HTTP header.

95 | 96 |
Parameters
i_client HTTP/REST client 97 |
i_name Header field name 98 |
i_value Header field value 99 |
public static
set_request_uri
importingi_clienttype TS_CLIENT
i_uritype STRING

Sets the URI for a HTTP request.

100 | 101 |
Parameters
i_client HTTP/REST client 102 |
i_uri URI 103 |
public instance
add_form_part
importingi_clienttype TS_CLIENT
it_form_parttype ZIF_IBMX_SERVICE_ARCH=>TT_FORM_PART
raisingzcx_ibmx_service_exception

Generates a multi-part request body.

104 | 105 |
Parameters
i_client HTTP/REST client 106 |
it_form_part Table of form parts 107 |
Class-based Exceptions
zcx_ibmx_service_exception Exception being raised in case of an error. 108 |
-------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 15 | 16 | # ABAP SDK for IBM watsonx, using SAP NetWeaver 17 | 18 | [![License](https://img.shields.io/badge/License-Apache2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0) 19 | 20 | ABAP® client library to use the [watsonx.ai Runtime][wml] (formerly 21 | Watson Machine Learning) and the [watsonx.ai][wxai] APIs. 22 | 23 | This is a community SDK written by ABAPers for the ABAPers in the Open 24 | Source community, to provide easy usage of IBM® 25 | watsonx services in innovation initiatives combined with 26 | any SAP® application which is run on SAP 27 | NetWeaver® 7.50 and above, such as SAP Business Suite or 28 | SAP S/4HANA® on-premises edition. It is the choice and 29 | responsibility of application developers how this community SDK is 30 | used. 31 | 32 | Additionally, as the ABAP SDK is a community release it is not updated 33 | with the same schedule as IBM-supported SDKs. Please see more 34 | information in [Support and Feedback](#support-and-feedback). 35 | 36 | # Choose ABAP SDK release for the applicable ABAP Runtime 37 | 38 | | **abap-sdk-nwas-x** | [abap-sdk-btp-x](https://github.com/IBM/abap-sdk-btp-x) | 39 | |---|---| 40 | | for SAP NetWeaver® AS ABAP 7.50+ | for SAP BTP ABAP Environment | 41 | | tested on SAP Business Suite and SAP S/4HANA on-premises edition | tested with SAP BTP ABAP Environment 2405 | 42 | | `this repository` | | 43 | 44 | --- 45 | 46 |
47 | Table of Contents 48 | 49 | - [Announcements](#announcements) 50 | - [Version 1.5.0 released](#version-150-released) 51 | - [Before you begin](#before-you-begin) 52 | - [Installation](#installation) 53 | - [SAP System Configuration](#sap-system-configuration) 54 | - [SAP Profile Parameters](#sap-profile-parameters) 55 | - [Proxy configuration](#proxy-configuration) 56 | - [SSL Certificates](#ssl-certificates) 57 | - [Determine required certificate](#determine-required-certificate) 58 | - [Add an SSL certificate to the PSE](#add-an-ssl-certificate-to-the-pse) 59 | - [Restart the ICM (Internet Communication Manager)](#restart-the-icm-internet-communication-manager) 60 | - [Credentials](#credentials) 61 | - [Configuration table](#configuration-table) 62 | - [IAM Authentication](#iam-authentication) 63 | - [Usage](#usage) 64 | - [Examples](#examples) 65 | - [API Reference](#api-reference) 66 | - [Support and Feedback](#support-and-feedback) 67 | - [License](#license) 68 | 69 |
70 | 71 | ## Announcements 72 | 73 | ### Version 1.5.0 released 74 | 75 | Version v1.5.0 of the SDK has been released - see what's changed in 76 | the [migration guide](MIGRATION-V1.5.0.md). 77 | 78 | ## Before you begin 79 | 80 | * You need an [IBM Cloud][ibm_cloud_onboarding] account. 81 | 82 | ## Installation 83 | 84 | The client library is provided as abapGit repository. Proceed as 85 | follows to clone the ABAP SDK code to your SAP system. 86 | 87 | 1. Install [abapGit][abapgit], using the [abapGit Docs][abapgit_docs] 88 | 2. Use abapGit to clone the ABAP SDK Git repository into your SAP 89 | system. 90 | 3. Assign the ABAP SDK to the package `ZIBMX` when performing setup of 91 | the abapGit repository. 92 | 93 | ## SAP System Configuration 94 | 95 | ### SAP Profile Parameters 96 | 97 | The following SAP profile parameter settings are recommended. 98 | 99 | ``` 100 | icm/HTTPS/client_sni_enabled = TRUE 101 | ssl/ciphersuites = 135:PFS:HIGH::EC_P256:EC_HIGH 102 | ssl/client_ciphersuites = 150:PFS:HIGH::EC_P256:EC_HIGH 103 | ``` 104 | 105 | ### Proxy configuration 106 | 107 | The client library respects the ABAP proxy settings. If you are using 108 | a central proxy server that is not already configured in your SAP 109 | system, proceed as follows. 110 | 111 | 1. Logon to the SAP system and call transaction SICF. 112 | 2. Click *Execute* (or press F8). 113 | 3. Select menu item *Client* → *Proxy Settings*. 114 | 4. On tab *Global Settings*: Select *Proxy Setting is Active* and *No 115 | Proxy Setting for Local Server*. 116 | 5. On tabs *HTTP Protocol* and *HTTPS Protocol* specify the proxy 117 | *Host Name* and *Port*. If the proxy server requires logon 118 | credentials, also specify *User Name* and *Password*. 119 | 6. Click *Execute (F8)* and *OK*. 120 | 121 | ### SSL Certificates 122 | 123 | Communication between SAP and the IBM Cloud is secured by the 124 | Transport Layer Security (TLS) protocol, also known as Secure Sockets 125 | Layer (SSL). SSL requires certificates that must be stored on the SAP 126 | application server in the Personal Security Environment 127 | (PSE). Transaction STRUST is used to maintain the PSE. 128 | 129 | #### Determine required certificate 130 | 131 | If a call to an IBM Cloud service failed due to a missing SSL 132 | certificate, check the ICM trace file to find the required 133 | certificate. To do so, call transaction SMICM and select menu item 134 | *Goto* → *Trace File* → *Display End*. Alternatively, call 135 | transaction AL11 and navigate to file DIR_HOME/dev_icm. Find last 136 | entry in trace file that indicates error 137 | *SSSLERR_PEER_CERT_UNTRUSTED*, as shown in the example below. 138 | 139 | ``` 140 | [Thr nn] Peer not trusted 141 | [Thr nn] Certificate: 142 | [Thr nn] Certificate: 143 | [Thr nn] Subject: CN=*.watsonplatform.net, O=INTERNATIONAL BUSINESS MACHINES CORPORATION, L=Armonk, SP=New York, C=US 144 | [Thr nn] Issuer: CN=GeoTrust RSA CA 2018, OU=www.digicert.com, O=DigiCert Inc, C=US 145 | [Thr nn] Serial Number: 05:1C:46:1B:6E:C2:29:48:BD:F0:03:B3:A6:87:1A:5B 146 | [Thr nn] Verification result: 147 | [...] 148 | [Thr nn] SignerCert: 149 | [Thr nn] Certificate: 150 | [Thr nn] Subject: CN=GeoTrust RSA CA 2018, OU=www.digicert.com, O=DigiCert Inc, C=US 151 | [Thr nn] Issuer: CN=DigiCert Global Root CA, OU=www.digicert.com, O=DigiCert Inc, C=US 152 | [Thr nn] Serial Number: 05:46:FE:18:23:F7:E1:94:1D:A3:9F:CE:14:C4:61:73 153 | [Thr nn] Verification result: 154 | [...] 155 | [Thr nn] SignerCert: 156 | [Thr nn] Certificate: 157 | [Thr nn] Subject: CN=DigiCert Global Root CA, OU=www.digicert.com, O=DigiCert Inc, C=US 158 | [...] 159 | [Thr nn] << ---------- End of Secu-SSL Errorstack ---------- 160 | [Thr nn] Target Hostname="stream.watsonplatform.net" 161 | [Thr nn] SSL NI-hdl 463: local=9.152.20.145:56542 peer=169.48.115.62:443 162 | [Thr nn] <<- ERROR: SapSSLSessionStartNB(sssl_hdl=3fef0000c70)==SSSLERR_PEER_CERT_UNTRUSTED 163 | [Thr nn] *** ERROR => SSL handshake with stream.watsonplatform.net:443 failed: SSSLERR_PEER_CERT_UNTRUSTED (-102) 164 | [Thr nn] The peer's X.509 Certificate (chain) is untrusted 165 | ``` 166 | 167 | The SSL error stack shows the SSL certificate chain, which in the 168 | example above looks like follows: 169 | 170 | | Certificate Authority Type | Certificate Authority (CA) | 171 | |:--------------------------:|:-------------------------- | 172 | | end-user | *.watsonplatform.net | 173 | | intermediate | GeoTrust RSA CA 2018 | 174 | | root | DigiCert Global Root CA | 175 | 176 | You can install any of these SSL certificates. However, it is 177 | recommended to install the root CA certificate.
Download the 178 | appropriate SSL certificate from the provider's website, for example 179 | https://www.digicert.com/digicert-root-certificates.htm. Store the 180 | certificate file on your computer. 181 | 182 | #### Add an SSL certificate to the PSE 183 | 184 | Proceed as follows to add the downloaded SSL certificate to your SAP 185 | system's *Standard SSL Client PSE*. 186 | 187 | 1. Logon to the SAP system and call transaction STRUST. 188 | 2. Switch to edit mode (press according tool bar icon). 189 | 3. If a local PSE file does not exist already, create it by 190 | right-clicking on `SSL client SSL Client (Standard)` and selecting 191 | *Create* from context menu. Keep all default settings in next popup 192 | dialog. 193 | 4. In *Certificate* section, click *Import* (alternatively select menu 194 | item *Certificate* → *Import*). Choose the certificate file 195 | that you have downloaded and import the certificate. 196 | 5. Click button *Add to Certificate List*. 197 | 6. Click *Save (F3)*. 198 | 199 | #### Restart the ICM (Internet Communication Manager) 200 | 201 | It is recommended to restart the ICM after a new SSL certificate has 202 | been applied to the PSE. To do so, proceed as follows. 203 | 204 | 1. Logon to the SAP system and start transaction SMICM. 205 | 3. If applicable, ensure that the ICM is restarted automatically when ended: 206 | *Administration* → *ICM* → *Restart* → *Yes*. 207 | 4. Select menu item *Administration* → *ICM* → *Exit Soft* 208 | → *Global*. 209 | 210 | ## Credentials 211 | 212 | Before you can access a specific service from your SAP system, you 213 | must create a service instance in the IBM Cloud and 214 | [obtain an API key](https://cloud.ibm.com/docs/account?topic=account-userapikey&interface=ui). 215 | The API key can be shared among multiple end users of the SAP system, but 216 | you must ensure that the selected plan is sufficient to support the expected 217 | number of calls or the expected data volume. 218 | 219 | All currently supported services support IAM authentication (see 220 | below). Service credentials consist of an API key and a URL. Both the 221 | API key and the URL are character values that need to be provided as parameters 222 | `i_apikey` and `i_url` to method `zcl_ibmx_service_ext=>get_instance`. 223 | 224 | You can store the values with your application, but it is suggested to 225 | do that in an encrypted format. Using cloud services usually creates 226 | costs based on usage for the owner of the service instance, and anyone 227 | with the credentials can use the service instance at the owner's 228 | expenses. If you want to distribute the costs over multiple cost 229 | centers, you need to create a service instance and provide service 230 | credentials for each cost center separately. 231 | 232 | ## Configuration table 233 | 234 | Service credentials and other parameters that must be specified at 235 | watsonx service wrapper ABAP class instantiation can also be provided 236 | in table `ZIBMX_CONFIG`. This table has three keys: 237 | 238 | | Table Key | Description | 239 | |:------------ |:-------------------------------------------------------------------------------------------------------------------------------------- | 240 | | SERVICE | The ABAP class name without prefix ZCL_IBMX_ | 241 | | INSTANCE_UID | ID chosen by application developer that must be provided by application as parameter to method `zcl_ibmx_service_ext=>get_instance()` | 242 | | PARAM | The parameter name | 243 | 244 |
245 | List of configuration parameters in table ZIBMX_CONFIG 246 | 247 | | Parameter Name | Default Value | Description | 248 | |:----------------- |:----------------- |:--------------------------------------------------------------------------- | 249 | | URL | service-dependent | watsonx service url | 250 | | APIKEY | | watsonx service API keys | 251 | | PROXY_HOST | | Proxy server | 252 | | PROXY_PORT | | Proxy server port | 253 | | AUTH_NAME | service-dependent | Authorization, `IAM` or `basicAuth` | 254 | | SSL_ID | CLIENT | SSL identity, defines PSE for SSL certificates: `CLIENT` or `ANONYM` | 255 | 256 |
257 | 258 | ## IAM Authentication 259 | 260 | Identity and Access Management (IAM) is a bearer-token based 261 | authentication method. Token management is either performed by the 262 | ABAP SDK or must be implemented by the SDK user.
If a value for 263 | `i_apikey` is provided by the caller in method 264 | `zcl_ibmx_service_ext=>get_instance()`, the ABAP SDK generates a 265 | bearer-token under the cover when needed and refreshes it when it is 266 | about to expire.
If `i_apikey` is not provided for method 267 | `zcl_ibmx_service_ext=>get_instance()`, the ABAP SDK user must 268 | implement an individual token management. Before a service method is 269 | called the first time, a valid bearer-token must be provided to the 270 | watsonx service wrapper ABAP class instance as follows: 271 | 272 | ```abap 273 | lo_service_class->set_bearer_token( i_bearer_token = '...' ). 274 | ``` 275 | 276 | Afterwards, service methods can be called as long as the provided 277 | token is valid. When the token has expired, the method above must be 278 | called again with a new (refreshed) bearer-token as parameter. 279 | 280 | ## Usage 281 | 282 | The client library is delivered as package *ZIBMX*. Once the Git 283 | repository has been cloned to the SAP system, a watsonx service 284 | instance is wrapped by an ABAP class instance.
The following 285 | watsonx services are currently supported: 286 | 287 | | Service | ABAP Class Name | 288 | |:------------------------------ |:----------------------------------- | 289 | | watsonx.ai Runtime | ZCL_IBMX_WML_V4 | 290 | | watsonx.ai | ZCL_IBMX_WATSONX_AI_ML_V1 | 291 | 292 | Using the client library requires two steps: 293 | 294 | 1. Create an instance of the watsonx service wrapper ABAP class by 295 | calling method `zcl_ibmx_service_ext=>get_instance`. 296 | 297 | ```abap 298 | data: 299 | lo_service_class type . 300 | 301 | zcl_ibmx_service_ext=>get_instance( 302 | exporting 303 | i_url = 304 | i_apikey = 305 | ... 306 | importing 307 | eo_instance = lo_service_class ). 308 | ``` 309 | 310 | > **Note** 311 | > Depending on the API operation, the `` parameter may vary as 312 | > described in 313 | > [Endpoint URLs](https://cloud.ibm.com/apidocs/watsonx-ai#endpoint-url). 314 | > If you use API operations with different endpoint URLs in the same 315 | > program, you need to create an instance of the watsonx service 316 | > wrapper ABAP class for each endpoint URL and use the instances 317 | > accordingly in your program. 318 | 319 | 2. Call the watsonx service API endpoint by invoking the corresponding 320 | class method. 321 | 322 | ```abap 323 | try. 324 | lo_service_class->method( 325 | exporting 326 | is_input = ... 327 | importing 328 | es_output = ... ). 329 | catch zcx_ibmx_service_exception into data(lo_service_exception). 330 | ... 331 | endtry. 332 | ``` 333 | 334 | ### Examples 335 | 336 |
337 | watsonx.ai Example (AI Sevices) 338 | 339 | ```abap 340 | * Z_WATSONX_AI_SERVICES_DEMO 341 | * This sample code deploys arbitrary Python code as Python AI Service on a watsonx deployment space 342 | * and calls the deployed function. 343 | * It also returns a CURL command that can be called to invoke the function endpoint url. 344 | * 345 | * Copy this code into 346 | * - an ABAP report and remove all comment prefixes "[PRG] 347 | * - a Console Application (RAP) and remove all comment prefixes "[RAP] 348 | * Adjust credentials and run code. 349 | 350 | constants: 351 | " Prerequisite: watsonx deployment space must be created and id specified here: 352 | c_url type string value `https://eu-de.ml.cloud.ibm.com`, " <- ADJUST 353 | c_apikey type string value `KHds7uuH...A7892Gt6`, " <- ADJUST 354 | c_space_id type string value `c3a99662...21349082`, " <- ADJUST 355 | c_function_name type string value `demo-ai-service-function`, 356 | c_serving_name type string value `abapsdk_test`, 357 | c_version type string value `2024-03-14`. 358 | 359 | " convert Python function code to GZIP file (ZIP with file header 0x04034b50 is not supported) 360 | try. 361 | " some Python code that bounces the received data (http method, path parameter, payload (= json request body)) as response body 362 | data(lx_code) = zcl_ibmx_service=>convert_string_to_utf8( 363 | i_string = 364 | `def ai_service_function(context):` && cl_abap_char_utilities=>newline && 365 | ` def generate(context) -> dict:` && cl_abap_char_utilities=>newline && 366 | ` payload = context.get_json()` && cl_abap_char_utilities=>newline && 367 | ` path_suffix = context.get_path_suffix()` && cl_abap_char_utilities=>newline && 368 | ` method = context.get_method()` && cl_abap_char_utilities=>newline && 369 | ` return {'body': {'method': method, 'path': path_suffix, 'payload': payload}}` && cl_abap_char_utilities=>newline && 370 | ` return generate` 371 | ). 372 | cl_abap_gzip=>compress_binary_with_header( 373 | exporting 374 | raw_in = lx_code 375 | importing 376 | gzip_out = data(lx_gzipfile) 377 | ). 378 | catch cx_root into data(lo_zip_exception). 379 | "[RAP] out->write( lo_zip_exception->get_longtext( ) ). exit. 380 | "[PRG] message lo_zip_exception type 'E'. 381 | endtry. 382 | 383 | " instantiate watsonx.ai wrapper class (explicit type declaration is required) 384 | data: lo_watsonx_ai type ref to zcl_ibmx_watsonx_ai_ml_v1. 385 | zcl_ibmx_service_ext=>get_instance( 386 | exporting 387 | i_url = c_url 388 | i_apikey = c_apikey 389 | i_version = c_version 390 | importing 391 | eo_instance = lo_watsonx_ai ). 392 | 393 | " create Python function as asset in watsonx deployment space 394 | try. 395 | lo_watsonx_ai->ai_services_create( 396 | exporting 397 | i_aiservicerequest = value zcl_ibmx_watsonx_ai_ml_v1=>t_aiservice_request( 398 | space_id = c_space_id 399 | name = c_function_name 400 | description = 'demo' 401 | software_spec = value zcl_ibmx_watsonx_ai_ml_v1=>t_software_spec_rel( 402 | name = `runtime-24.1-py3.11` 403 | ) 404 | ) 405 | importing 406 | e_response = data(ls_result_create) 407 | ). 408 | 409 | catch zcx_ibmx_service_exception into data(lo_create_exception). 410 | "[RAP] out->write( lo_create_exception->get_longtext( ) ). exit. 411 | "[PRG] message lo_create_exception type 'E'. 412 | endtry. 413 | data(lv_aiservice_id) = ls_result_create-metadata-id. 414 | 415 | " upload AI Service Python function code 416 | try. 417 | lo_watsonx_ai->ai_services_upload_code( 418 | exporting 419 | i_id = lv_aiservice_id 420 | i_space_id = c_space_id 421 | i_upload_code = lx_gzipfile 422 | i_contenttype = 'application/gzip' 423 | importing 424 | e_response = data(ls_result_upload) 425 | ). 426 | catch zcx_ibmx_service_exception into data(lo_upload_exception). 427 | "[RAP] out->write( lo_upload_exception->get_longtext( ) ). exit. 428 | "[PRG] message lo_upload_exception type 'E'. 429 | endtry. 430 | 431 | " deploy AI Service Python function 432 | try. 433 | lo_watsonx_ai->create_deployment( 434 | exporting 435 | i_deploymentresourceprototype = value zcl_ibmx_watsonx_ai_ml_v1=>t_deployment_resrc_prototype( 436 | space_id = c_space_id 437 | name = `Deployment for ` && c_function_name 438 | asset = value zcl_ibmx_watsonx_ai_ml_v1=>t_rel( 439 | id = lv_aiservice_id 440 | ) 441 | hardware_spec = value zcl_ibmx_watsonx_ai_ml_v1=>t_hardware_spec( 442 | name = 'S' 443 | ) 444 | online = value zcl_ibmx_watsonx_ai_ml_v1=>t_online_deployment( 445 | parameters = value zcl_ibmx_watsonx_ai_ml_v1=>t_online_deployment_parameters( 446 | serving_name = c_serving_name 447 | ) 448 | ) 449 | ) 450 | importing 451 | e_response = data(ls_deployment_result) 452 | ). 453 | catch zcx_ibmx_service_exception into data(lo_deployment_exception). 454 | " http status 400 (bad request) -> delete existing deployment, if exists, and retry 455 | "[RAP] out->write( lo_deployment_exception->get_longtext( ) ). exit. 456 | "[PRG] message lo_deployment_exception type 'E'. 457 | endtry. 458 | data(lv_deployment_id) = ls_deployment_result-metadata-id. 459 | 460 | " wait until deployment is complete 461 | do 20 times. 462 | try. 463 | lo_watsonx_ai->deployments_get( 464 | exporting 465 | i_space_id = c_space_id 466 | i_deployment_id = lv_deployment_id 467 | importing 468 | e_response = data(ls_deployment) 469 | ). 470 | catch zcx_ibmx_service_exception into data(lo_deployment_get_exception). 471 | "[RAP] out->write( lo_deployment_get_exception->get_longtext( ) ). exit. 472 | "[PRG] message lo_deployment_get_exception type 'E'. 473 | endtry. 474 | if not ls_deployment-entity-status-state eq 'initializing'. 475 | exit. 476 | endif. 477 | wait up to 5 seconds. 478 | enddo. 479 | 480 | 481 | " INFERENCE 482 | 483 | " declare structure of request response 484 | data: 485 | begin of lv_response, 486 | begin of payload, 487 | message type string, 488 | end of payload, 489 | path type string, 490 | method type string, 491 | end of lv_response. 492 | 493 | " call AI Service function endpoint and parse response 494 | data(lv_url) = `/ml/v4/deployments/` && c_serving_name && `/ai_service/mypath`. 495 | data(ls_request_prop) = value zcl_ibmx_service=>ts_request_prop( 496 | url = value zcl_ibmx_service=>ts_url( 497 | path = lv_url 498 | ) 499 | body = `{ "message": "This message was sent via ABAP" }` 500 | header_content_type = 'application/json' 501 | ). 502 | try. 503 | data(lo_response) = lo_watsonx_ai->http_post( i_request_prop = ls_request_prop ). 504 | data(lv_json) = zcl_ibmx_service=>get_response_string( lo_response ). 505 | zcl_ibmx_service=>parse_json( 506 | exporting 507 | i_json = lv_json 508 | changing 509 | c_abap = lv_response ). 510 | catch zcx_ibmx_service_exception into data(lo_inference_exception). 511 | "[RAP] out->write( lo_inference_exception->get_longtext( ) ). exit. 512 | "[PRG] message lo_inference_exception type 'E'. 513 | endtry. 514 | 515 | " compile CURL command to test deployment endpoint 516 | data(lv_curl_command) = 517 | `curl -X POST -H "Authorization: Bearer ${IAM_ACCESS_TOKEN}" ` 518 | && `-d '{ "message": "This message was sent via CURL" }' ` 519 | && `"` && ls_deployment-entity-status-inference[ 1 ]-url && `/mypath"`. 520 | 521 | " write success message 522 | data(lv_msg) = `Received message "` && lv_response-payload-message && `" from deployed AI Service function. Try CURL command below.`. 523 | "[RAP] out->write( lv_msg ). 524 | "[RAP] out->write( lv_curl_command ). 525 | "[PRG] write: lv_msg. 526 | "[PRG] write: / lv_curl_command. 527 | ``` 528 | 529 |
530 | 531 |
532 | watsonx.ai Example (Text Generation) 533 | 534 | ```abap 535 | * Z_WATSONX_AI_DEMO 536 | * This sample code runs text generation with a watsonx.ai foundation model. 537 | * 538 | * Copy this code into 539 | * - an ABAP report and remove all comment prefixes "[PRG] 540 | * - a Console Application (RAP) and remove all comment prefixes "[RAP] 541 | * Adjust credentials and run code. 542 | 543 | " instantiate watsonx.ai wrapper class (explicit type declaration is required) 544 | data: lo_watsonx_ai type ref to zcl_ibmx_watsonx_ai_ml_v1. 545 | zcl_ibmx_service_ext=>get_instance( 546 | exporting 547 | i_url = 'https://eu-de.ml.cloud.ibm.com' " <- ADJUST 548 | i_apikey = 'X7Ziqsan...FfOAtAno' " <- ADJUST 549 | i_version = '2023-05-29' 550 | importing 551 | eo_instance = lo_watsonx_ai ). 552 | 553 | " run text generation 554 | try. 555 | data(lv_prompt) = `The highest mountain in Europe is`. 556 | lo_watsonx_ai->text_generation( 557 | exporting 558 | i_textgenrequest = value zcl_ibmx_watsonx_ai_ml_v1=>t_text_gen_request( 559 | 560 | " prompt 561 | input = lv_prompt 562 | 563 | " model parameters 564 | model_id = 'ibm/granite-13b-chat-v2' 565 | parameters = value zcl_ibmx_watsonx_ai_ml_v1=>t_text_gen_parameters( 566 | decoding_method = 'greedy' 567 | max_new_tokens = 20 568 | repetition_penalty = '1.05' 569 | stop_sequences = value #( ( `. ` ) ) " stop after first sentence 570 | ) 571 | 572 | project_id = '3e606d0c...459b7c38' " <- ADJUST 573 | ) 574 | importing 575 | e_response = data(ls_generated_document) ). 576 | catch zcx_ibmx_service_exception into data(lo_service_exception). 577 | "[RAP] out->write( lo_service_exception->get_longtext( ) ). exit. 578 | "[PRG] message lo_service_exception type 'E'. 579 | endtry. 580 | 581 | " display generated text 582 | "[RAP] out->write( lv_prompt ). 583 | "[PRG] write lv_prompt. 584 | loop at ls_generated_document-results into data(ls_result). 585 | "[RAP] out->write( ls_result-generated_text ). 586 | "[PRG] write / ls_result-generated_text. 587 | endloop. 588 | ``` 589 | 590 |
591 | 592 | ## API Reference 593 | 594 | GitHub Pages contain the [ABAP Client Library for watsonx API Reference](https://IBM.github.io/abap-sdk-nwas-x/). 595 | 596 | ## Support and Feedback 597 | 598 | The ABAP SDK is a community SDK for IBM watsonx, created by the IBM watsonx 599 | development community and SAP's ABAP development community – written by 600 | ABAPers from IBM Systems. Therefore, as a community release it is not 601 | updated with the same schedule as IBM-supported SDKs and does not include 602 | support by IBM. 603 | 604 | The code in this repository is generated from the OpenAPI specs of the 605 | supported services. Hence, pull requests must not be integrated directly 606 | into the code. If you would like to request a new feature or report a 607 | bug, please raise an issue instead of sending a pull request. 608 | 609 | ## License 610 | 611 | This library is licensed under the [Apache 2.0 license][license]. 612 | 613 | [wml]: https://cloud.ibm.com/apidocs/machine-learning 614 | [wxai]: https://cloud.ibm.com/apidocs/watsonx-ai 615 | [ibm_cloud]: https://cloud.ibm.com/ 616 | [ibm_cloud_onboarding]: https://cloud.ibm.com/registration?target=/developer/watson&cm_sp=WatsonPlatform-WatsonServices-_-OnPageNavLink-IBMWatson_SDKs-_-ABAP 617 | [license]: http://www.apache.org/licenses/LICENSE-2.0 618 | [abapgit]: https://github.com/larshp/abapGit 619 | [abapgit_docs]: https://docs.abapgit.org/ 620 | --------------------------------------------------------------------------------