Domanda

I want to make a function module that make the same query, for example:

Select column_id from table_name where column_name = name_value.

I want to pass the table_name, column name and name_value, so, no matter what table is, I can get the id of the provided name. Could you lead me in how to do that in abap using function modules?

È stato utile?

Soluzione

Let's say you took the following parameters as input.

DATA: table_name  TYPE string VALUE 'MARA',
      column_id   TYPE string VALUE 'MATNR',
      column_name TYPE string VALUE 'MTART',
      name_value  TYPE string VALUE 'HALB'.

First, dynamically create a table of the type you will select into.

DATA: results TYPE REF TO data,
      tablety TYPE string.
FIELD-SYMBOLS <results> TYPE STANDARD TABLE.

tablety = table_name && '-' && column_id.
CREATE DATA results TYPE TABLE OF (tablety).
ASSIGN results->* TO <results>.

Then use a dynamic query to fill the table.

DATA: condition TYPE string.
condition = column_name && ` = name_value`.

SELECT (column_id) FROM (table_name)
  INTO TABLE results
  WHERE (condition).

Pass back the generically-typed reference to the calling program.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top