Don't mix Z functions with maintenance views!
Today’s hint is not a hint - it’s an advice.
After creating a table, you create its maintenance views. The maintenance views dwell within a group of functions. This group of functions is requested from you at the time of their creation. Since, after all, that’s no more than a set of generated code, and most of it is, nonetheless, standard includes. Loads.
I give you the problem: there are those who create their own Z functions and put them in groups of functions with maintenance views. It’s true. Some do this.
I like LIKE
In the ‘bad old days’ when the ABAP was even more old-fashioned than today, variable statements were all made through LIKE and were referenced to table fields:
DATA: V_KUNNR LIKE KNA1-KUNNR.QUICKINFO: tip on how to give tips.
In my opinion, this tip has arrived a few years too late, as it is now rare to use the WRITE command to directly write things to the screen. Therefore, we can say it’s a retro tip. A vintage tip. But let’s assume we are still in the twentieth century grappling with ABAP’s most Baroque command, WRITE.
Then, imagine yourself sitting in front of SAP, listening to Pearl Jam, wearing black headphones and writing WRITEs of a series of values on the screen, which you would like the user to have more information on. But you don’t have room on the screen to give that information. SAP thought of this:
Is that RFC system alive?
You want to call an RFC function in another system but, because you’re not a carrion eater, you only want to do it if it’s alive.
Hence, you need a way of checking whether that particular destination RFC system is alive.
How do you do that?
Charles Santana does it like this:
DATE: rfcdest TYPE rfcdest,
ping_status TYPE /sdf/e2e_traffic_light_numeric.
CALL FUNCTION '/SDF/RFC_CHECK'
EXPORTING
iv_destination = rfcdest
iv_ping = 'X'
* iv_logon = 'X'
* iv_latency = 'X'
IMPORTING
ev_ping_status = ping_status.
if lv_ping_status <> 1.
* it’s dead.
endif.Thanks Charles.
Does the function exist?
You call a function. Imagine it doesn’t answer. It may be that it’s staying silent. Or it’s shy. Or dumb. Or, of all the misfortunes, it doesn’t exist.
To make sure and put your mind to rest you then do:
Writing money without any decimal worries
Some people read the TCURX to find out the number of decimal places of a CURRENCY when they need to write a money field to an alphanumeric variable.
Are you one of those people? Don’t be.
Finally, expressions can be concatenated
Finally, the SAP NetWeaver 7.0 Enhancement Package 2 makes ABAP start to seem like a normal programming language.
It even allows expressions to be concatenated, no less!
Decimal to alphanumeric without depending on the user
When reading a file with numeric values to an internal table or vice versa, the success of the conversion depends on whether the user has defined the dot or comma as the decimal separator. It is customary to then go and read the user setting and then adjust the values from the file with a dot or a comma as required.
But this is unfortunate and rather inelegant. There should be a way of not making this depend on the user.
And there is.
SORTED instead of STANDARD in the cache tables
Some time ago I wrote a post here showing the advantages of using internal tables with defined indexes instead of simple STANDARD tables.
Confession: that habit is so ingrained that since then, almost all the internal tables I have created have continued to be STANDARD TABLE.
It’s very common to create internal tables to cache data that I know I’ll often use inside LOOPS to avoid having to SELECT SINGLES inside them.
