Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

What is wrong in my select statement (using dynamic tables in BAPI)

Former Member
0 Likes
605

Hello SAP gurus

I am trying to write a bapi that accepts table name, fields, where to condition dynamically and returns the result

When I use the following statements, I keep getting errors.

In the following staments please note that SELECTCOL, TABNAME, WHERECOL and VALUE ARE ALL DYNAMICALLY SENT VIA BAPI IMPORT TABS.

First I tried

-


STATEMENT 1 and THE ERROR I got were as follows

SELECT (SELECTCOL)

from (TABNAME)

WHERE (WHERECOL) = (VALUE)

into corresponding fields of table <dyn_table>.

ERROR 1

If the name of the database table is not

determined until runtime, you must specify

an out put area with "INTO.."

=========================================================

STATEMENT 2 and the error I got were as follows

SELECT (SELECTCOL)

INTO CORRESPONDING FIELDS OF TABLE <dyn_table>

FROM (TABNAME)

WHERE (WHERECOL) = (VALUE).

incorrect expression "=" in logical condition.

-


THe select statement works with '*" which gets everything, but I want only the columns that meets the condtion

specified with WHERE Clause.

Any feedback or suggestions will be highly appreciated.

Thanks

Ram

Edited by: Prasad Ram on Mar 27, 2010 6:31 AM

1 ACCEPTED SOLUTION
Read only

faisalatsap
Active Contributor
0 Likes
539

Hi, Prasad

Please check the following Sample Code hope this will help you to solve out your problem,

DATA: itab_ref TYPE REF TO data,
      tabname like RSRD1-TBMA_VAL VALUE 'pa0001',
      fields TYPE string,
      where TYPE string.

CREATE DATA itab_ref TYPE STANDARD TABLE OF (tabname).
FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE.
ASSIGN itab_ref->* TO <itab>.

DEFINE dselect.
  SELECT (&1) FROM (&2) INTO CORRESPONDING FIELDS OF TABLE &3 WHERE (&4).
END-OF-DEFINITION.

START-OF-SELECTION.
  fields = 'pernr begda endda'.
  where = 'pernr = ''1000'''.
  dselect fields tabname <itab> where.

Please Reply in case of any Issue,

Best Regards,

Faisal

Hello SAP gurus

I am trying to write a bapi that accepts table name, fields, where to condition dynamically and returns the result

When I use the following statements, I keep getting errors.

In the following staments please note that SELECTCOL, TABNAME, WHERECOL and VALUE ARE ALL DYNAMICALLY SENT VIA BAPI IMPORT TABS.

First I tried

-


STATEMENT 1 and THE ERROR I got were as follows

SELECT (SELECTCOL)

from (TABNAME)

WHERE (WHERECOL) = (VALUE)

into corresponding fields of table <dyn_table>.

ERROR 1

If the name of the database table is not

determined until runtime, you must specify

an out put area with "INTO.."

=========================================================

STATEMENT 2 and the error I got were as follows

SELECT (SELECTCOL)

INTO CORRESPONDING FIELDS OF TABLE <dyn_table>

FROM (TABNAME)

WHERE (WHERECOL) = (VALUE).

incorrect expression "=" in logical condition.

-


THe select statement works with '*" which gets everything, but I want only the columns that meets the condtion

specified with WHERE Clause.

Any feedback or suggestions will be highly appreciated.

Thanks

Ram

Edited by: Prasad Ram on Mar 27, 2010 6:31 AM

2 REPLIES 2
Read only

faisalatsap
Active Contributor
0 Likes
540

Hi, Prasad

Please check the following Sample Code hope this will help you to solve out your problem,

DATA: itab_ref TYPE REF TO data,
      tabname like RSRD1-TBMA_VAL VALUE 'pa0001',
      fields TYPE string,
      where TYPE string.

CREATE DATA itab_ref TYPE STANDARD TABLE OF (tabname).
FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE.
ASSIGN itab_ref->* TO <itab>.

DEFINE dselect.
  SELECT (&1) FROM (&2) INTO CORRESPONDING FIELDS OF TABLE &3 WHERE (&4).
END-OF-DEFINITION.

START-OF-SELECTION.
  fields = 'pernr begda endda'.
  where = 'pernr = ''1000'''.
  dselect fields tabname <itab> where.

Please Reply in case of any Issue,

Best Regards,

Faisal

Read only

Former Member
0 Likes
539

Thanks for the help. It solved my problem.