简体   繁体   中英

How to read ABAP code using a java client

I have a requirement were I need to read ABAP code written by SAP developers. I want to write my own client using Java/Python which can integrate with SAP system and get me the ABAP code.

What I understand that ABAP code is stored in SAP database like HANA, mysql etc. So is there a way which SAP provides where we can read the code like we can do in Git/SVN etc.

You can access tables with below techniques:

  • Using SAP Connectors via RFC (RFC_READ_TABLE)
  • Using SOAP Web Service with same function (RFC_READ_TABLE)
  • Using custom web services with existing functions which are reading report, functions, etc.

You can use both Java or Pyhton for RFC, there is already exits github repo for python .

If you will select reading directly in db table, you need to know structure of saved data. It has own mechanism for OOP objects. Daniel Berlin try to implement binary parser in C++ in sap-reposrc-decompressor project. Never forget this source depended with SAP version.

I think using ADT (ABAP Development Tools) plugin is good for updated systems. There is already Eclipse plugin exists for ADT. ADT not exists in old systems.

If you are planning to use your solution in old system (after 7.01), you can build your own solution with abapGit and custom web services.

NOTE : Keep in mind, report and data elements (variables, tables, types) saved in separate tables. Dynpro objects (screens etc), reports (Smartforms) hard things to decompile.

我已经通过 perl NWRFC 包装器/库使用 RFC 调用RPY_FUNCTIONMODULE_READRPY_FUNCTIONMODULE_READ_NEW来检索 ABAP 代码。

Before you re-invent a wheel, Take a look at:

If you want JUST the source code, You could expose a very simple rest service/ Endpoint in SAP.
This service would just read the raw code and return it as plain text. Every abaper could create this for you. BUT is the raw source only. There is much more to a complete development and why tools like ABAPGIT exist.

In SICF, create a new endpoint / service. EG ZCODE_MONKEY with the class below as an example.

SICF 条目

Now activate the service.

Call the endpoint http://server:PORT/zcode_monkey?name=ZCODE_MONKEY

Sample implementation

CLASS zcode_monkey DEFINITION
  PUBLIC
  CREATE PUBLIC .
  PUBLIC SECTION.
  INTERFACES: if_http_extension.
ENDCLASS.
CLASS zcode_monkey IMPLEMENTATION.
  METHOD if_http_extension~handle_request.
      DATA: lo_src type ref to CL_OO_SOURCE,
            l_name TYPE string,
            l_repname type c length 30,
            l_clskey type seoclskey ,
            l_source type rswsourcet,
            resultcode TYPE string.
      FIELD-SYMBOLS: <line> TYPE LINE OF rswsourcet.

    l_name =    server->request->get_form_field(  name    = 'NAME' ).

    l_clskey = l_name.
    l_repname = l_name.

    create OBJECT lo_src
      EXPORTING
        clskey             = l_clskey
      EXCEPTIONS
        class_not_existing = 1
        others             = 2      .

    IF sy-subrc <> 0.
       read REPORT l_repname into l_source.
    else.
      lo_src->read( ).
      lo_src->if_oo_clif_source~get_source(  IMPORTING source = l_source   ).
    ENDIF.


    LOOP AT l_source ASSIGNING <line>.

      CONCATENATE  resultCode
                   cl_abap_char_utilities=>cr_lf
                   <line>
            INTO   resultCode   RESPECTING BLANKS. " always show respect ;)


    ENDLOOP.

    SErver->response->set_content_type( content_type = 'text/plain' ).
    server->response->set_cdata( EXPORTING  data   = resultcode ).
    server->response->set_status(
      EXPORTING
        code   = 200
        reason = 'this is a 3.50 piece of code. Dont ask...its a demo ' ).
  ENDMETHOD.

ENDCLASS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM