Sandra Rossi
Sandra Rossi

Reputation: 13628

How to make ABAP code work in any ABAP-based system

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:

Upvotes: 5

Views: 1472

Answers (5)

MrSamael
MrSamael

Reputation: 5

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.

Upvotes: 0

drakth
drakth

Reputation: 1

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.

Upvotes: 0

Ela
Ela

Reputation: 325

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

Upvotes: 0

phil soady
phil soady

Reputation: 11308

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

Upvotes: 1

Florian
Florian

Reputation: 5051

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.

Upvotes: 3

Related Questions