February 27, 2015

Table Maintenance options and ABAP

One of the traits I like about SAP is that you have several facilities to achieve more. One of those characteristics is in transaction ‘SE11’. This transaction is used to create tables and it comes with a feature where you can generate it’s own screen (dynpro) and basic validations, like, unique index and others.

This screen(s) can be modified with our own logic and validations and even the layout. You can add more detail as you wish. Maybe you could make this maintenance screen making a module pool in SE80 however the point here is that with transaction ‘SE11’ you don’t start from zero. This trait is very important because you can have a lot of features incorporated.

Let’s begin creating a table.

1. Execute transaction ‘SE11’ and name the table whatever you want but remember to use ‘Z’ or ‘Y’ as first letter.

2. Click on ‘Create’ button.

3. Add a description to table (This step is mandatory). Choose ‘A’ option for 'Delivery class' and ‘Display/Maintenance allowed‘ on the 'Delivery and maintenance’ tab. Check image.


4. Select ‘Fields’ tab
  1. Add the following fields:
    1. Add as a first field ‘MANDT’ with type ‘MANDT’.
    2. Add field ‘CODE’ type CHAR08.
    3. Add field ‘NAME’ type STRING.
    4. Add field ERNAM type ERNAM
    5. Add field ‘ERDAT’ type ‘ERDAT’
    6. Add field ‘AENAM’ type ‘AENAM’
    7. Add field ‘LAEDA’ type ‘LAEDA’.


5. Setup the ‘Technical Settings’ where you will set 'Data class' will be 'APP0L' and 'Size Category '0'. Also check 'Log data changes' and 'Write access only with JAVA', these 2 options are optional. Here you'll be asked to save and a package before this screen, I suggest to click on 'Local object' button.



6. Choose the 'Enhancement Category' in Extras menu. Select 'Can be enhanced (character-type or numeric)' option.



7. Activate.


The next thing we should do is to generate the maintenance screen. The option we need here is in ‘Utilities’ menu where you select the ‘Table Maintenance Generator’ option. Here we have some things to configure;


First you need to indicate the authorization group, here it depends on what kind of restriction you would like this program to make, for this example type ‘&NC&’ which means ‘w/o auth. group’. The second thing to set is the function group, personally I would recommend to use the table name, however is up to you which name you set here.



The third thing would be to set the screens of the block ‘Maintenance screens’. In this section you have two options:
  • One step
  • Two step
And the difference is that in the first option you make inserts and modifications in only one dynpro, here SAP sets you a grid to make all the actions on your data. The second option consists in specifying 2 dynpros; one for the grid and the second for issuing the data. The first dynpro shows you the data but in order to make inserts or changes you must make a double click to show you the data.

In our example select the first option (One step) and type '100' in the ‘Overview screen’.


Now, click on 'Create' button or press 'F6'.


The next step is to make use of events. This option is found in the menu ‘Environment’/’Events’.


If you get the following message box click the 'Ok' button.


You will get through the following screen where you must choose what events are going to be raised.

01 Before saving the data in the database
02 After saving the data in the database
03 Before deleting the data displayed
04 After deleting the data displayed
05 Creating a new entry
06 After completely performing the function 'Get original'
07 Before correcting the contents of a selected field
08 After correcting the contents of a selected field
09 After getting the original of an entry
10 After creating the header entries for the change task (E071)
11 After changing a key entry for the change task (E071K)
12 After changing the key entries for the change task (E071K)
13 Exit editing (exit main function module)
14 After lock/unlock in the main function module
15 Before retrieving deleted entries
16 After retrieving deleted entries
17 Do not use. Before print: Event 26
18 After checking whether the data has changed
19 After initializing global variables, field symbols, etc.
20 after input in date subscreen (time-dep. tab./views)
21 Fill hidden fields
22 Go to long text maintenance for other languages
23 Before calling address maintenence screen
24 After restricting an entry (time-dep. tab./views)
25 Individual authorization checks
26 Before creating a list
27 After creation or copying a GUID (not a key field)
28 After entering a date restriction for time-dep. views
AA Instead of the standard data read routine
AB Instead of the standard database change routine
AC Instead of the standard 'Get original' routine
AD Instead of the standard RO field read routine
AE Instead of standard positioning coding
AF Instead of reading texts in other languages

Just for example let’s use the events ‘05’ (Creating new entry) and ‘21’ (Fill hidden fields). Let’s say we want to put the user name and the date when the record is created and modified it.

  1. Type event ‘05’ and on the ‘FORM Routine’ column type ‘on_create’.
  2. Type event ‘21’ and on the ‘FORM Routine’ column type ‘on_change’.


3. Next, click on column editor the button to type the code. You’ll be asked to make a PAI include. Click on button ‘OK’.



4. Paste the following code.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
form on_create.
  ztesttab-ernam = sy-uname.
  ztesttab-erdat = sy-datum.
  ztesttab-aenam = sy-uname.
  ztesttab-laeda = sy-datum.
endform.

form on_change.
  ztesttab-aenam = sy-uname.
  ztesttab-laeda = sy-datum.
endform.

5. Return to the event entries screen and click the save button and go back to the ‘Table Maintenance’ screen and also save the configuration.

If you have the following message box ‘Function group ZTESTTAB cannot be processed’ then go to transaction ‘SE80’ and select the function group ‘ZTESTTAB’ and activate it but first change the ‘Change’ state of the table to ‘Display’. Check the images below.



6. Create entries. Go to 'Utilities'/'Table contents'/'Create Entries' menu.


7. Finally click on button ‘New Entries’, fill the fields ‘+’ and ‘Last Name’ and press enter. And you’ll see that fields ‘Created by’, ‘Created On’, ‘Changed by’ and ‘Changed on’ now have the values we set in the ‘Creating a new entry’ event. The same will occur when you change it with another user.



One last comment is that in order to protect those fields from being modified you must edit the dynpro '100' you set in the 'Utilities'/'Table Maintenance Generator' menu and set the ‘Input‘ column to ‘Not possible’ value in the ‘Special Attributes’ tab on the columns ‘ERNAM’, ‘ERDAT’, ‘AENAM’ and ‘LAEDA’.


Hope it helps. See you on the next.

February 7, 2015

Introduction

Why SAP? well, SAP has been mostly my day-to-day since 2011. I was fortunate to be part of the implementation team and my main task was to prepare the master data which was an advantage to me because I learned a lot about the SAP internals, at least the tables.

During that time I could access the development environment and using SAP/ABAP tutorials from internet I (secretly) began to practice and rapidly learned to program in ABAP. At those times SAP accesses were in some kind of custody because only consultants could make things on it.

Finally when we went into production I started to make reports and send them to production environment. It was not long before my boss gave me assignments to make programs and eventually I reached the point where I was assigned to make not only reports, but enhancements, implement BADis, BAPIs, classes, correct bugs from the implementation, apply SAP notes, modify smartforms, module pools, function modules , ZY tables, and everything that could be done in SAP. Well, not everything but a lot.

These tasks were very helpful because of this I debugged a lot (and I mean a lot) of ABAP code in order to know what to make, what to enhance, what to do, those where harsh and fun times at the same time and boosted a lot my knowledge. As far as I learned, the more I wanted to know, the more I wanted to accomplish. I found a lot of richness about the internals of SAP in those early days nonetheless there's a lot to know and learn there. I can certainly say that after all these years I still learn everyday of SAP and I’m sure that this will not finish soon, I don’t even know if it has an ending. Also in all this journey I have made a lot of mistakes, I’ve had to correct even my own bugs, all for good.

One of the very things I learned from SAP was that is not enough to take a course or take a tutorial, it is necessary to dive inside of it to know the “SAP way”, is not enough to know about the structures and commands but also the functional knowledge which is very important. It’s also very importante to know why SAP does something in a certain way and why it’s implemented in a given way. Those issues are necessary to be productive and efficient and lucky me I found myself in a very nice circumstance where I took advantage of that. Besides all the above it’s a matter of time and hard work, the more experience one get, the more valuable you become.

I always wanted to make a blog on this issue to expose all this discoverings and I regret I didn't start before and I'm really grateful to find John Sonmez blog which has inspired me very much on this issue. 

I have a dairy in Trello which I use to organize and document my activities and I use it since 2012 for SAP and I’d have like to post all those things but I was some kind of afraid (I’m a little now) because I’m writing on my own experience on SAP (my discoveries, my mistakes) and I’m sure that there are better blogs about this theme that would surpass by a long path this one.

Before SAP I worked (and still work) on C#, VB.Net and ASP.Net, I’ve been involved in several projects but my main development work since 2011 has been SAP/ABAP.

Hope this blog helps you in some way.