Categories: ABAP

A nifty way to define runtime data in ABAP

You may be familiar with the CREATE DATA statement in ABAP, which allows you to create data in a program by specifying the name of the type at runtime. What you may not be familiar with, is the concept of absolute type names in ABAP.

Absolute type names are described in the ABAP Keyword documentation, under “ABAP – The SAP Programming Language -> ABAP – By Theme -> Declarative Statements -> Data Types and Data Objects -> Types and Objects – Overview -> Data Types -> Absolute Type Names“. (You will find the keyword documentation on an ABAP system by going to SE38 -> Utilities -> Keyword Documentation or pressing F1 in an ABAP editor).

What is basically says is that certain repository objects such as programs can also be considered types, which in turn contain other types. As such, you can refer to the type TP_PAYM defined in include MP004510 of program MP004500 on an ECC system as \PROGRAM=MP004500\TYPE=TP_PAYM. (Sorry, I was hoping to find a Basis example that you could find on any system, but you get the idea).

If you feed this absolute type name into parameter P_NAME of the method CL_ABAP_TYPEDESCR=>DESCRIBE_BY_NAME (you can try it in SE24), you will get back a description of the type with its components etc. Very nice.

You can go even a step further though, by using the CREATE DATA statement in a program and feeding it the same absolute name, as follows:

data: tv type ref to data.
create data tv TYPE table of ('\PROGRAM=MP004500\TYPE=TP_PAYM').

Now you can dereference this data object and assign a field symbol to it, and then treat it like it was the type itself, refer to components of the type, and whatever else you want to:

field-symbols <t> type standard table.
assign tv->* to <t>.
PERFORM fill_gt_paym(MP004500) TABLES <t> "further code ommitted...

This is a great way of referring to locally defined data types in other programs without having to copy their definition into yours, thus safeguarding you from changes due to upgrades, etc., and of course making your code easier on the eyes.

P.S. You will find the Absolute Type Names page from the ABAP keyword documentation on (I’m not familiar with the site, so I don’t know if this information is published there legally etc. etc.).

Update 2008.10.06:

For reference purposes, I am including the list of components that are used to define absolute type names:


Article info

Leave a Reply

Your email address will not be published. Required fields are marked *