You are on page 1of 12

SAP Development Community of Experts

The Development Soap Box

Dynamic Programming in ABAP


Keith Mayerle (Keith.V.Mayerle@Accenture.com)
SAP Development Community of Experts

The Application . The Development Soap Box


SAP Development Community of Experts

SAP Tables with Pricing Conditions The Development Soap Box


SAP Development Community of Experts

The Driver Table The Development Soap Box


SAP Development Community of Experts

One way to do it . The Development Soap Box

case table.
when A951.
select from a951
when A952.
select from a952

etc.
SAP Development Community of Experts

Dynamic Selects The Development Soap Box

SELECT * INTO TABLE <table>


FROM ( condition table from Driver )
WHERE (different qualifiers for customer vs. hierarchy conditions )

We can create our <table> dynamically


data: l_ref type ref to data.
create data l_ref type table of ( condition table from Driver ).
ASSIGN l_ref->* to <table>.

But we need to:


distinguish customer Condition Tables from hierarchy Conditions tables
do extra data formatting such as getting Material descriptions where appropriate
SAP Development Community of Experts

Run Time Type Services (RTTS) The Development Soap Box

cl_abap_typedescr

cl_abap_datadescr

cl_abap_elemdescr

cl_abap_refdescr

cl_abap_complexdescr

cl_abap_structdescr

cl_abap_tabledescr

cl_abap_objectdescr

cl_abap_classdescr

cl_abap_intfdescr
SAP Development Community of Experts

Create an Object to describe our data The Development Soap Box

Debugging our Program .


SAP Development Community of Experts

Drilling down into the Object . The Development Soap Box

The CL_ABAP_STRUCTDESCR Object has an attribute called COMPONENTS


SAP Development Community of Experts

Using an Object to get info on our data The Development Soap Box

Declare the data


data: l_descr type ref to cl_abap_structdescr.

Create the object


l_descr?=cl_abap_typedescr=>describe_by_name(
condition table from Driver ).

Accessing the table of components


loop at l_descr->componentsassigning<comp_wa>.

if <comp_wa>-name = KUNNR.
add KUNNR qualifier to SQL WHERE clause
SAP Development Community of Experts

Using RTTS to create data dynamically The Development Soap Box

Create structure descriptor Object from table of components


go_sdescr = cl_abap_structdescr=>create( gt_components ).

Create table descriptor object from structure descriptor Object


go_tdescr = cl_abap_tabledescr=>create( go_sdescr ).

Create data reference from Object


CREATE DATA gr_tabref TYPE HANDLE go_tdescr.

Produce an itab from the data reference


ASSIGN gr_tabref->* TO <gt_itab>.
SAP Development Community of Experts

Get more info The Development Soap Box

Run Time Type Services (RTTS):


1. Run Time Type Information (RTTI)
2. Run Time Type Creation (RTTC)

Search rtts or rtti on sdn.sap.com especially under Wiki and


Blogs

Book: SAP Press ABAP Objects (Keller and Krger)

You might also like