Skip to content

SAP-samples/tier2-rfc-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

REUSE status

Tier2 RFC proxy generator

Description

This repository contains a helper class and a report that helps you to generate a custom wrapper for the ABAP Cloud enablement of an non-released RFC based SAP API.

It basically uses the same API used by transaction ACO_PROXY. It takes the code that is generated by this API and creates an interface and a factory class and C1-releases those objects. So it basically automates most of the steps described in this repository RAP640 - Using ABAP Cloud to Build Extensions for SAP S/4HANA Cloud, Private Edition - Mitigating Missing Released SAP APIs in the 3-tier Extensibility Model.

The transaction ACO_PROXY and its underlying API now also check if a data element that is used by a non released function module itself has been released. If this is the case, no shadow type will be generated.

Blog Post in SAP Community

Blog Post: How to generate a wrapper for function modules (BAPIs) in tier 2

Requirements

Future Outlook

In future the idea is to provide such a generator as well in the ABAP development tools for Eclipse. This will be possible with the next S/4HANA release and the ADT generator framework.    

How to section

The tool can be used in short as follows:

  1. Start report zr_gen_rfc_tier2_proxy using transaction SE38.

  2. Select one or more function modules that shall be wrapped for the use in ABAP Cloud.

    Select function modules
  3. Select remaining parameters

    Select remaining parameters

    3.1 Target Package : Here you have to select the package in which the wrapper objects shall be generated

    3.2 Intf., class and fact.class: When you select this option the generator will generate a wrapper class, an interface and a factory class (this is recommended) Only wrapper class: When you select this option the generator will only generate a wrapper class, for those that do not want to generate 3 wrapper objects 3.3 Here you have to specify the repository object names that shall be generated. Depending on the option you have chosen you have to specify the names of three objects or just for one class. 3.4 You can specify whether the objects if they already exist are being overwritten

  4. Start the report and check the output.

    Check output of report
  5. Check the generated objects in the target package.

    Check generated objects
  6. What is now left to do is that the developer has to implement the public methods with a call of the respective private methods.

    Here it is possible to change the signature of the public method e.g. by reducing the number of parameters that are exposed.

    By default the public and private methods use the same signature.

     METHOD zif_wrap_test_003~bapi_pr_create.
     "add call to private method bapi_pr_create
     "e.g. me->bapi_pr_create( ... )
     ENDMETHOD.

Generated code

Wrapper Interface

INTERFACE zif_wrap_test_003
 PUBLIC .

  TYPES:
    banfn                          TYPE c LENGTH 000010 ##TYPSHADOW .
  TYPES:
    bsart TYPE c LENGTH 000004 ##TYPSHADOW .
  TYPES:
    bsakz TYPE c LENGTH 000001 ##TYPSHADOW .
  TYPES:
    gsfrg TYPE c LENGTH 000001 ##TYPSHADOW .
  TYPES:
    estkz TYPE c LENGTH 000001 ##TYPSHADOW .

....

TYPES:
    BEGIN OF bapimereqheader               ,
      preq_no         TYPE banfn,
      pr_type         TYPE bsart,
      ctrl_ind        TYPE bsakz,
      general_release TYPE gsfrg,
      create_ind      TYPE estkz,
      item_intvl      TYPE pincr,
      last_item       TYPE lponr,
      auto_source     TYPE kzzuo,
      memory          TYPE membf,
      hold_complete   TYPE bapimereqpostflag,
      hold_uncomplete TYPE bapimereqpostflag,
      park_complete   TYPE bapimereqpostflag,
      park_uncomplete TYPE bapimereqpostflag,
      memorytype      TYPE memorytype,
    END OF bapimereqheader                ##TYPSHADOW .
  TYPES:
    BEGIN OF bapimereqheaderx              ,
      preq_no         TYPE bapiupdate,

...

 METHODS bapi_pr_create
    IMPORTING
      !prheader               TYPE bapimereqheader OPTIONAL
      !prheaderx              TYPE bapimereqheaderx OPTIONAL
      !testrun                TYPE char1 OPTIONAL
      !_dest_                 TYPE rfcdest DEFAULT 'NONE'
    EXPORTING
      !number                 TYPE banfn
      !prheaderexp            TYPE bapimereqheader
    CHANGING
      !allversions            TYPE _bapimedcm_allversions OPTIONAL
      !extensionin            TYPE _bapiparex OPTIONAL
      !extensionout           TYPE _bapiparex OPTIONAL
      !praccount              TYPE _bapimereqaccount OPTIONAL
      !praccountproitsegment  TYPE _bapimereqaccountprofitseg OPTIONAL
      !praccountx             TYPE _bapimereqaccountx OPTIONAL
      !praddrdelivery         TYPE _bapimerqaddrdelivery OPTIONAL
      !prcomponents           TYPE _bapimereqcomponent OPTIONAL
      !prcomponentsx          TYPE _bapimereqcomponentx OPTIONAL
      !prheadertext           TYPE _bapimereqheadtext OPTIONAL
      !pritem                 TYPE _bapimereqitemimp
      !pritemexp              TYPE _bapimereqitem OPTIONAL
      !pritemsource           TYPE _bapimereqsource OPTIONAL
      !pritemtext             TYPE _bapimereqitemtext OPTIONAL
      !pritemx                TYPE _bapimereqitemx OPTIONAL
      !prversion              TYPE _bapimereqdcm OPTIONAL
      !prversionx             TYPE _bapimereqdcmx OPTIONAL
      !return                 TYPE _bapiret2 OPTIONAL
      !serialnumber           TYPE _bapimereqserialno OPTIONAL
      !serialnumberx          TYPE _bapimereqserialnox OPTIONAL
      !serviceaccount         TYPE _bapi_srv_acc_data OPTIONAL
      !serviceaccountx        TYPE _bapi_srv_acc_datax OPTIONAL
      !servicecontractlimits  TYPE _bapi_srv_contract_limits OPTIONAL
      !servicecontractlimitsx TYPE _bapi_srv_contract_limitsx OPTIONAL
      !servicelimit           TYPE _bapi_srv_limit_data OPTIONAL
      !servicelimitx          TYPE _bapi_srv_limit_datax OPTIONAL
      !servicelines           TYPE _bapi_srv_service_line OPTIONAL
      !servicelinesx          TYPE _bapi_srv_service_linex OPTIONAL
      !servicelongtexts       TYPE _bapi_srv_longtexts OPTIONAL
      !serviceoutline         TYPE _bapi_srv_outline OPTIONAL
      !serviceoutlinex        TYPE _bapi_srv_outlinex OPTIONAL
    RAISING
      cx_aco_application_exception
      cx_aco_communication_failure
      cx_aco_system_failure .
ENDINTERFACE.

Wrapper Class

CLASS zcl_wrap_test_003 DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
  PUBLIC SECTION.
    INTERFACES zif_wrap_test_003.
  PROTECTED SECTION.
  PRIVATE SECTION.
    
 METHODS bapi_pr_create
      IMPORTING
        !prheader               TYPE zif_wrap_test_003~bapimereqheader OPTIONAL
        !prheaderx              TYPE zif_wrap_test_003~bapimereqheaderx OPTIONAL
        !testrun                TYPE zif_wrap_test_003~char1 OPTIONAL
        !_dest_                 TYPE rfcdest DEFAULT 'NONE'
      EXPORTING
        !number                 TYPE zif_wrap_test_003~banfn
        !prheaderexp            TYPE zif_wrap_test_003~bapimereqheader

...

...

CLASS zcl_wrap_test_003 IMPLEMENTATION.

  METHOD bapi_pr_create.
    DATA: _rfc_message_ TYPE aco_proxy_msg_type.
    CALL FUNCTION 'BAPI_PR_CREATE' DESTINATION space
      EXPORTING
        prheader               = prheader
        prheaderx              = prheaderx
        testrun                = testrun
      IMPORTING
        number                 = number
        prheaderexp            = prheaderexp
      TABLES
        allversions            = allversions
        extensionin            = extensionin
        extensionout           = extensionout
        praccount              = praccount
...
        serviceoutlinex        = serviceoutlinex
      EXCEPTIONS
        communication_failure  = 1 MESSAGE _rfc_message_
        system_failure         = 2 MESSAGE _rfc_message_
        OTHERS                 = 3.
    IF sy-subrc NE 0.
      DATA __sysubrc TYPE sy-subrc.
      DATA __textid TYPE aco_proxy_textid_type.
      __sysubrc = sy-subrc.
      __textid-msgid = sy-msgid.
      __textid-msgno = sy-msgno.
      __textid-attr1 = sy-msgv1.
      __textid-attr2 = sy-msgv2.
      __textid-attr3 = sy-msgv3.
      __textid-attr4 = sy-msgv4.
      CASE __sysubrc.
        WHEN 1 .
          RAISE EXCEPTION TYPE cx_aco_communication_failure
            EXPORTING
              rfc_msg = _rfc_message_.
        WHEN 2 .
          RAISE EXCEPTION TYPE cx_aco_system_failure
            EXPORTING
              rfc_msg = _rfc_message_.
        WHEN 3 .
          RAISE EXCEPTION TYPE cx_aco_application_exception
            EXPORTING
              exception_id = 'OTHERS'
              textid       = __textid.
      ENDCASE.
    ENDIF.

  ENDMETHOD.


  METHOD zif_wrap_test_003~bapi_pr_create.
    "add call to private method bapi_pr_create
    "e.g. me->bapi_pr_create( ... )
  ENDMETHOD.
ENDCLASS.

Factory Class

CLASS zcl_fact_test_003 DEFINITION
PUBLIC
FINAL
CREATE PRIVATE .
  PUBLIC SECTION.
    CLASS-METHODS create_instance
      RETURNING VALUE(result) TYPE REF TO zif_wrap_test_003.
  PROTECTED SECTION.
  PRIVATE SECTION.
    METHODS constructor.
ENDCLASS.

CLASS zcl_fact_test_003 IMPLEMENTATION.
  METHOD constructor.
  ENDMETHOD.
  METHOD create_instance.
    result = NEW zcl_wrap_test_003(  ).
  ENDMETHOD.
ENDCLASS.

Background

This report uses under the hood the API's that are used by transaction ACO_PROXY.

In principle you can achieve the same result by running the transaction ACO_PROXY which will generated a wrapper class and then perform the following steps:

  • create an interface
  • copy the code of the definition part of the class generated by ACO_PROXY to the interface
  • replace the CLASS-METHODS statements with METHODS statements in the interface
  • replace the defintion part of the wrapper class generated by ACO_PROXY with an INTERFACE statement
  • change the dest statements with space statements.
  • create a factory class that instantiates the wrapper class
  • C1 release the interface and the factory class

Further information

Download and Installation

Known Issues

No known issues.

How to obtain support

Create an issue in this repository if you find a bug or have questions about the content.

For additional support, ask a question in SAP Community.

Contributing

If you wish to contribute code, offer fixes or improvements, please send a pull request. Due to legal reasons, contributors will be asked to accept a DCO when they create the first pull request to this project. This happens in an automated fashion during the submission process. SAP uses the standard DCO text of the Linux Foundation.

License

Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved. This project is licensed under the Apache Software License, version 2.0 except as noted otherwise in the LICENSE file.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages