Chunkyy Garg
Chunkyy Garg

Reputation: 117

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.

Upvotes: 2

Views: 953

Answers (3)

phil soady
phil soady

Reputation: 11338

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 entry

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.

Upvotes: 1

mkysoft
mkysoft

Reputation: 5758

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.

Upvotes: 1

ranga
ranga

Reputation: 380

I've used RFC calls RPY_FUNCTIONMODULE_READ and RPY_FUNCTIONMODULE_READ_NEW through the perl NWRFC wrapper/library to retreive ABAP code.

Upvotes: 1

Related Questions