5

I often share ABAP code via forums, github and so on, which is often intended to work on any ABAP-based system. Unfortunately, it often happens that some of the objects I use (database tables, types and so on) only exist in the solution I am working with (for instance SAP CRM which works on an ABAP system).

It's important to understand that there are several solutions developed by SAP, which are independent from other solutions, but are to be installed on an ABAP system, which includes the ABAP language itself and closely-linked external objects like those in the ABAP dictionary. Such SAP solutions are SAP R/3, SAP CRM, SAP SRM, SAP SCM/APO, SAP BW, S/4HANA, BW/4HANA, SAP Solution Manager, etc.

For instance, let's say I want to ask a question about the join in ABAP and I provide the following example (that I developed on an SAP CRM system, but the question doesn't concern S/4HANA):

REPORT.
DATA gt_partner TYPE TABLE OF crmd_order_index-partner_no.
SELECT DISTINCT a~partner_no
    INTO TABLE gt_partner
    FROM crmd_order_index AS a INNER JOIN crm_jest AS b
    ON a~header = b~objnr
    UP TO 10 ROWS.
cl_demo_output=>write( crmd_order_index ).

Many people have S/4HANA, not SAP CRM, so the code won't compile on their system because the database table crmd_order_index exists only in SAP CRM. Probably those people won't answer or they won't be able to verify their answer, so I think I could make an effort to improve the example and make it work on any ABAP system. This is of course a very simple example, but imagine that you have tens or hundreds of lines.

I know that one solution is to install an ABAP Developer Edition on our own laptop, because it contains the minimal ABAP configuration, and test the ABAP code on it. But it's relatively complex and long to install, occupies a lot of disk space, just to check a "simple thing".

Is there another way to check easily and quickly whether the ABAP code compiles in any ABAP-based system? Or any other idea?

I would also like that this solution applies to code as big as abapGit for instance.

For information:

  • One well-known ABAP tool which works in any ABAP-based system is abapGit.
  • The question is not about the versions (for instance for checking that ABAP code made on an ABAP 7.52 system compiles on ABAP 7.0 systems) because I think it's a much more complex problem.
  • In Stack Overflow, an ABAP question whose code doesn't work on any ABAP system weakens the principle of Minimal, Reproducible Examples.
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • 1
    I don't see here any problem at all. The fact that you don't have a particular table in one of the systems is not connected to the ABAP language itself but rather to a missing package or in general a software component. You would have the same situation in any other programming language for example Java if you do not have particular dependencies like packages that come from .jar files installed. – Jagger Dec 01 '19 at 13:01
  • 1
    @Jagger If I make a basis tool (like abapGit) on a C/4HANA system which should be deployed on my S/4HANA, SRM, BW and other systems, isn't there an efficient and quick way to detect and repair all objects which are not basis? – Sandra Rossi Dec 01 '19 at 13:08
  • 1
    I don't think that there is such function in SAP. ( or as mentioned by jagger, in any other programming language ). In my old company, we had a tool, developed be my colleague, for code exchanging ( based on abapgit ). It checked all tables, classes, etc. which are used in the given code - checked the installed components and if they are installed in the other system. I think, you could build something like that, only that you take the components which are installed on every SAP System. ( you might have a look into an ABAP Developer Edition System for that ) – Sasku Dec 02 '19 at 07:13
  • Asked for feedback in SAP's internal company-wide agile ABAP discussion group #sap-dev-ase-abap. – Florian Dec 02 '19 at 08:43
  • 2
    As a side-note, abapGit actually doesn't work on any system. It needs release 702 as a minimum. – Legxis Dec 02 '19 at 09:50
  • if it is a basis tool, the chances of missing dependent objects should be very low. – Haojie Dec 02 '19 at 10:00
  • 1
    @haojie. Very low if, each time you call a class method or a function module, or use an ABAP dictionary object, you check that it belongs to the basis layer. Let's admit that you develop a tool without checking each object and that you want to check everything in the end (anyway, you probably missed one). – Sandra Rossi Dec 02 '19 at 10:22
  • May the best solution would be developing a custom-rule for the code-inspector or for the ATC, which checks the application component of the dependencies. abapOpenChecks (https://github.com/larshp/abapOpenChecks) implemented a lot of custom rules. Maybe we could use this as template. – J.Gerbershagen Dec 23 '19 at 09:25
  • That's why I have to develop on 46C T-T – Ela Dec 08 '20 at 08:31
  • The [Cloud Platform ABAP Environment](https://www.sap.com/products/cloud-platform/capabilities/enterprise-extensions.abap.html?btp=08729df4-1cc5-4b07-babf-c135d4a83c0e) has some free trials, code that runs there should (don't know for sure) run everywhere (with newer versions) – Jonas Wilms Dec 21 '20 at 13:31

5 Answers5

3

The cleanest way to share a piece of ABAP sample code seems to be this:

  1. create a local package such as $MY_SAMPLE,
  2. copy all sample code and dependencies in,
  3. push it to a new, clean https://www.github.com repository with abapGit, and
  4. add a README that provides the ABAP version the code was written for.

With these best practices:

  • Reduce the code and dependencies to the minimum required to make the sample work. Remove calls to other development objects not directly related to the problem. Restrict yourself as much as possible to the functions and APIs available from the ABAP platform.

  • If there are dependencies that form part of the problem, for example in "How do I use the CRM function module XYZ?", or that cannot be copied for size or copyright(!) reasons, identify the SAP software component they are a part of, and list it as dependency in the README.

  • Verify that the example compiles and works by executing it. This is not reliable, as it may accidentally still access un-copied dependencies you forgot to copy, but it will at least give you an idea.

ABAP is not really special here. Providing minimal working examples is always an effort, in any development language. It requires disentangling the affected code from unnecessary dependencies, and replacing the required ones with minimal working stubs. This is part of why asking good questions is hard work, and why StackOverflow appreciates good questions with reputation.

Florian
  • 4,821
  • 2
  • 19
  • 44
  • 1
    Thank you. I guess my question was not clear enough. The question is not about how to share ABAP code, but if ABAP code is to be a basis tool, how to make sure all the objects it uses are basis so that the deployment will not fail on a CRM, ERP, SRM, BW, etc. system. In fact, I'd like to automate your best practice #2 ("identify the SAP software component") as far as possible. Eventually, please edit my question to clarify it. – Sandra Rossi Dec 02 '19 at 10:35
1

Sandra I dont think there is a good nor easy answer to this problem. We have been suffering for years with this problem. I got burnt so often with ABAP language across releases. Especially SQL and ABAP unit Tests. Even good old char02 burnt us last week. Yeah Char02 is an industry specific data element no longer supported in s/4 Hana. You need to have every possible release of sap abap be sure all is ok. There is a remote syntax check option, which sounded good at first. However it starts with 7.02 SP14 . So its no good for 7.0 And you need access to these releases in the first place. Who can afford that? Why cant 1 ABAP system be able to do downward compatible checks. :( No Big surprise to me ABAPGit has settled on a recent but not latest abap version as "current version". We have to support code for 7.0 to 7.5+ since we have customers from S/4 hana to 7.0 with 1 code base. We also have a common code base with a SolMan/ CRM and SAP gateway and ECC Business suite. Keeping that code base clean for all environments is easier said than done.

As far as examples go Sticking to strictly ABAP NW examples sounds easy, but unless you limit yourself SFLIGHT or tables like T002 / T006 it is harder than people realize.

A basic but not perfect solution is to check the development class of all objects in a transport before release. We have been doing that for some time. tracking what is a valid Basis object for what purpose is HARD. I have used basis objects that dont exist on 7.2 systems and Failed on import. You can then add a TADIR date to your checks.

At the end of the day I just import into the oldest (7.0) system as a smoke test.

Ill be watching to see if someone has a magic bullet solution :) Good luck

phil soady
  • 11,043
  • 5
  • 50
  • 95
0

Since the releases are downwards compatible you can set up a system with a very low release and develop your code on this. ABAP OO was introduced with release 4.6C

Ela
  • 325
  • 1
  • 3
  • 13
0

Usually when I'm writing an example, for posting in my blog or somewhere online, I use the travel objects, tables like: sflight, spfli, scarr, etc, which usually are present in most systems, I don't know if they are present in C/4, solution manager or some other solutions, but I think that's probably the best objects to use.

Also another thing that's probably a good idea is to use classic ABAP, and by classic ABAP I mean not using sentences that are only compatible with ABAP >7.40, because in my experience there are still systems on SAP BASIS 7.31.

It's also probably a good idea to use classics reports, unless you are obviously writing about OOPs or the new ABAP 7.40 like sentences.

drakth
  • 1
  • 2
0

Your question in not simple as that seems. As you see, the abap code depends on customer repository so you need to have a knowledge of every system to get your code simple and fast. For the select, you have to know all type of abap possible select. Best ways is to declare your Types wich contains all of your table so you can select in database without a select distinct. If you have to use a Function or, a class or any kind of object that does not exist on that system, you can create it. Sometimes create is not a best way, so you can search and memorize the oldest functions/calss/object. For example, the function conv_exit_alpha_input you can use now a simple row wich do the same. So if you want to implement an example abap code, you have to respect the KISS rule and declare as much as you can like readme or creating view or table ect.

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
MrSamael
  • 5
  • 2