This quickstart shows you how to invoke a function that
publishes a message constructed from the arguments that the function receives,
using the Cloud Run functions API.
Before you begin
Before you run this quickstart, make sure that you or your administrators have
completed the following prerequisites:
Depending on the environment where your SAP system is hosted, set up
authentication for invoking Cloud Run functions. For instructions,
see Authentication to invoke Cloud Run functions. Configure the client keys as follows:
To access the Cloud Run function endpoint, create a client key named DEMO-CF.
To invoke the Cloud Run function, create a client key named DEMO-CF-INVOKER.
In the Google Cloud console, write a 2nd gen HTTP function, cf-gen2-hello-with-args,
that publishes a message using the provided arguments:
exports.helloWorld = (req, res) => {
let name = req.body.name || req.query.name;
let full_name = `${req.body.firstname} ${req.body.lastname}`;
res.status(200).send(`Hello ${name}! Full Name: ${full_name}`);
};
In the SAP system, create an executable program in your
custom namespace (for example, Z or Y) by using transaction SE38.
In the SAP GUI, enter transaction code SE38.
In the Program field, enter a name of your program.
For example, ZDEMO_CLOUDFUNC_INVOKER.
Click Create.
Specify the program attributes:
In the Title field, enter a title of your program,
for example, Invoke Cloud Function using Cloud Function Invoker.
In the Type field, choose Executable Program.
Click Save.
Save the program as a Local Object.
In the ABAP Editor, add the following code:
**********************************************************************
* Copyright 2024 Google LLC *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* https://www.apache.org/licenses/LICENSE-2.0 *
* Unless required by applicable law or agreed to in writing, *
* software distributed under the License is distributed on an *
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, *
* either express or implied. *
* See the License for the specific language governing permissions *
* and limitations under the License. *
**********************************************************************
REPORT zr_qs_cfinvoker.
DATA(lv_cf_name) = CONV string( 'cf-gen2-hello-with-args' ).
DATA(lv_msg) = CONV string( '{"firstname": "John", "lastname" : "Doe"}' ).
TRY.
" Create a Client API stub for Cloud Functions
DATA(lo_cloudfunc_client) = NEW /goog/cl_cloudfunc_v2( iv_key_name = 'DEMO_CF' ).
" Create a Client API stub for Cloud Function Invoker.
" Internally this uses the Cloud Function instance to fetch the cloud function HTTP endpoint
DATA(lo_cfinvoker_client) = NEW /goog/cl_cloudfunc_invoker( iv_key_name = 'DEMO_CF_INVOKER' ).
" Send additional query parameters as inputs to the cloud function.
lo_cfinvoker_client->add_common_qparam( iv_name = 'name'
iv_value = 'Johnny' ).
lo_cfinvoker_client->invoke(
EXPORTING
iv_cf_name = lv_cf_name "Cloud Function Name
iv_cf_location = 'us-central1' "Location where the Cloud Function is hosted
io_cf_instance = lo_cloudfunc_client "Instance of cloud Function Client API Stub
iv_body = lv_msg "Input payload to the Cloud Function
iv_content_type = 'application/json'
iv_method = 'POST'
IMPORTING
es_output = DATA(lv_output)
ev_ret_code = DATA(lv_ret_code)
ev_err_text = DATA(lv_err_text)
es_err_resp = DATA(ls_err_resp)
).
IF lo_cfinvoker_client->is_success( iv_code = lv_ret_code ).
WRITE: / 'HTTP Return Code:', lv_ret_code.
WRITE: / 'Response:', lv_output. "Output of cloud function
ELSE.
WRITE: / 'HTTP Return Code:', lv_ret_code.
WRITE: / 'Error:', lv_err_text.
ENDIF.
CATCH /goog/cx_sdk INTO DATA(lo_exp).
WRITE: / lo_exp->get_text( ).
ENDTRY.
Replace the following:
DEMO_CF: name of the client key that is used to access the Cloud Run function endpoint.
DEMO_CF_INVOKER: name of the client key that is used to invoke the Cloud Run function.
Run your application in SE38. If successful, the following output displays:
HTTP Return Code: 200
Response: Hello Johnny! Full Name: John Doe
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-29 UTC."],[],[],null,["# Invoke Cloud Run functions\n\n\u003cbr /\u003e\n\nThis quickstart shows you how to invoke a function that\npublishes a message constructed from the arguments that the function receives,\nusing the [Cloud Run functions](/functions/docs/concepts/overview) API.\n\nBefore you begin\n----------------\n\n\nBefore you run this quickstart, make sure that you or your administrators have\ncompleted the following prerequisites:\n\n- You have a Google Cloud account and project.\n\n- Billing is enabled for your project. [See how to confirm that billing is enabled for your project](/billing/docs/how-to/verify-billing-enabled).\n\n- The on-premises or any cloud edition of ABAP SDK for Google Cloud is installed and configured. [See how to install and configure the on-premises or any cloud edition of ABAP SDK for Google Cloud](/sap/docs/abap-sdk/on-premises-or-any-cloud/latest/install-config).\n\n\u003cbr /\u003e\n\n- Make sure that the Cloud Run functions API is enabled in your Google Cloud project.\n\n [Go to API library](https://console.cloud.google.com/project/_/apis/library/cloudfunctions.googleapis.com)\n- Depending on the environment where your SAP system is hosted, set up\n authentication for invoking Cloud Run functions. For instructions,\n see [Authentication to invoke Cloud Run functions](/sap/docs/abap-sdk/on-premises-or-any-cloud/latest/authentication-cloud-functions). Configure the client keys as follows:\n\n - To access the Cloud Run function endpoint, create a client key named `DEMO-CF`.\n - To invoke the Cloud Run function, create a client key named `DEMO-CF-INVOKER`.\n- In the Google Cloud console, write a 2nd gen HTTP function, `cf-gen2-hello-with-args`,\n that publishes a message using the provided arguments:\n\n exports.helloWorld = (req, res) =\u003e {\n let name = req.body.name || req.query.name;\n let full_name = `${req.body.firstname} ${req.body.lastname}`;\n res.status(200).send(`Hello ${name}! Full Name: ${full_name}`);\n };\n\n For information about how to write HTTP functions, see [Write Cloud Run functions](/functions/docs/writing).\n\nCreate a program to invoke Cloud Run functions\n----------------------------------------------\n\n1. In the SAP system, create an executable program in your\n custom namespace (for example, `Z` or `Y`) by using transaction `SE38`.\n\n 1. In the SAP GUI, enter transaction code `SE38`.\n\n 2. In the **Program** field, enter a name of your program.\n For example, `ZDEMO_CLOUDFUNC_INVOKER`.\n\n 3. Click **Create**.\n\n 4. Specify the program attributes:\n\n 1. In the **Title** field, enter a title of your program,\n for example, `Invoke Cloud Function using Cloud Function Invoker`.\n\n 2. In the **Type** field, choose `Executable Program`.\n\n 3. Click **Save**.\n\n 5. Save the program as a **Local Object**.\n\n 6. In the **ABAP Editor**, add the following code:\n\n **********************************************************************\n * Copyright 2024 Google LLC *\n * *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); *\n * you may not use this file except in compliance with the License. *\n * You may obtain a copy of the License at *\n * https://www.apache.org/licenses/LICENSE-2.0 *\n * Unless required by applicable law or agreed to in writing, *\n * software distributed under the License is distributed on an *\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, *\n * either express or implied. *\n * See the License for the specific language governing permissions *\n * and limitations under the License. *\n **********************************************************************\n REPORT zr_qs_cfinvoker.\n\n DATA(lv_cf_name) = CONV string( 'cf-gen2-hello-with-args' ).\n DATA(lv_msg) = CONV string( '{\"firstname\": \"John\", \"lastname\" : \"Doe\"}' ).\n\n\n TRY.\n \" Create a Client API stub for Cloud Functions\n DATA(lo_cloudfunc_client) = NEW /goog/cl_cloudfunc_v2( iv_key_name = '\u003cvar translate=\"no\"\u003eDEMO_CF\u003c/var\u003e' ).\n \" Create a Client API stub for Cloud Function Invoker.\n \" Internally this uses the Cloud Function instance to fetch the cloud function HTTP endpoint\n DATA(lo_cfinvoker_client) = NEW /goog/cl_cloudfunc_invoker( iv_key_name = '\u003cvar translate=\"no\"\u003eDEMO_CF_INVOKER\u003c/var\u003e' ).\n\n \" Send additional query parameters as inputs to the cloud function.\n lo_cfinvoker_client-\u003eadd_common_qparam( iv_name = 'name'\n iv_value = 'Johnny' ).\n\n lo_cfinvoker_client-\u003einvoke(\n EXPORTING\n iv_cf_name = lv_cf_name \"Cloud Function Name\n iv_cf_location = 'us-central1' \"Location where the Cloud Function is hosted\n io_cf_instance = lo_cloudfunc_client \"Instance of cloud Function Client API Stub\n iv_body = lv_msg \"Input payload to the Cloud Function\n iv_content_type = 'application/json'\n iv_method = 'POST'\n IMPORTING\n es_output = DATA(lv_output)\n ev_ret_code = DATA(lv_ret_code)\n ev_err_text = DATA(lv_err_text)\n es_err_resp = DATA(ls_err_resp)\n ).\n\n IF lo_cfinvoker_client-\u003eis_success( iv_code = lv_ret_code ).\n WRITE: / 'HTTP Return Code:', lv_ret_code.\n WRITE: / 'Response:', lv_output. \"Output of cloud function\n ELSE.\n WRITE: / 'HTTP Return Code:', lv_ret_code.\n WRITE: / 'Error:', lv_err_text.\n ENDIF.\n\n CATCH /goog/cx_sdk INTO DATA(lo_exp).\n WRITE: / lo_exp-\u003eget_text( ).\n ENDTRY.\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eDEMO_CF\u003c/var\u003e: name of the client key that is used to access the Cloud Run function endpoint.\n - \u003cvar translate=\"no\"\u003eDEMO_CF_INVOKER\u003c/var\u003e: name of the client key that is used to invoke the Cloud Run function.\n2. Run your application in `SE38`. If successful, the following output displays:\n\n HTTP Return Code: 200\n Response: Hello Johnny! Full Name: John Doe\n\nWhat's next\n-----------\n\n\n- Explore other quickstarts available on the GitHub repository, [GoogleCloudPlatform/google-cloud-abap/abap-sdk\n /ZGOOG_SDK_QUICKSTART/](https://github.com/GoogleCloudPlatform/google-cloud-abap/tree/main/abap-sdk/ZGOOG_SDK_QUICKSTART).\n- Read the guide [Application development with the on-premises or any cloud edition of ABAP SDK for Google Cloud](/sap/docs/abap-sdk/on-premises-or-any-cloud/latest/developer).\n- View the [code samples](/sap/docs/abap-sdk/samples/all-samples#on-premises-or-any-cloud-edition).\n- Ask your questions and discuss ABAP SDK for Google Cloud with the community on [Cloud Forums](https://discuss.google.dev/tags/c/google-cloud/14/abap-sdk).\n\n\u003cbr /\u003e"]]