Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
lukas_dietzsch
Explorer
0 Kudos

The SAP NetWeaver has a considerably wide range of functions. But in its current version this powerful SAP tool works in comparison with other Integrated Development Environments (IDE) pretty wooden. There are missing simple getter and setter generators for example, as it is known from the Eclipse IDE for years. The conceptual background, advantages and benefits of clean encapsulated object attribute access is not the topic of this article.

Such a getter and setter generator has been implemented and this is demonstrated in this article. In the SAP it is useful to create the getters and setters on basis of an existing object from the Data Dictionary (DDIC).

In the first stage of this generator an existing DDIC is specified and its detailed structure is read generic. For this purpose a new separate class is created in which each column represents the DDIC as an attribute. The preferred example DDIC is table "SPFLI" from the common SAP practice examples.

The structure of the SPFLI table:


The new created class has a corresponding class attribute for each of the above column (field). These attributes are marked directly by the generator as a private one. The attribute access is to be made via the following to create getter and setter methods. The report is now called, and offers the following input options:

The report get the desired source table (DDIC) and the checkboxes for getter and/or setter methods. Additionally the target class name should be defined. In this example, as already mentioned, will be a new class for the SPFLI table created. The target class is created only in the Z namespace and will be called ZCL_MY_OWN_SPFLI. After confirming these entries the report starts with the generation.

The user will have the option to designate the target package, in which the class should be created. In the example case, there is the $ TMP package:


The result can now be seen in Repository Browser for the new class Z_MY_OWN_SPFLI. The aim was to have a class attribute for each column of SPFLI:

Each column was added as an attribute. All columns? No! The client column is missing and was not added. In most cases it is not recommended to set an client field manually. Therefore every client column will be ignored by the generator.

After class generation, the reports reads the new structure again and generates depending on getter and settter choice the new methods. In this example both checkboxes on start screen are checked, see the result:

The example implementation of the getter method for the SPFLI attribute "AIPFROM" is shown here:

And here you can see the new generated setter method. It has instead of returning parameters (cp. getter method) an importing parameter:

This tool is used in present dnsgroup projects and provides good service even at this stage of development. It is not yet final stage. We welcome feedback and feature requests.

For questions and advices we are always happy to help and offer advice and assistance.

kind regards,

Lukas

5 Comments