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

Selecting specific data from a table define in a customized table

Former Member
0 Likes
450

Hi all,

I am wondering if there is a way to make a select out from a settings.

Scenario

-


I have a transparent table created as below:

MANDT

TABNAME

FIELDNAME

QUESTION

The purpose of the above transparent table is to store the question and answer. The answer is store in the specific field in the specific table.

Sample scenario will be:

-


Transparent table value:

TABNAME = PA0002

FIELDNAME = NACHN

QUESTION = 'What is your last name?'.

Programming logic:

1) Base on the question, the program will go to the field of the table specify above and look for the value and match with the answer key in.

Is there a way to do this? I would like to avoid using 'case' or 'if' statement.

I have tried to use field-symbols to do it but I failed. Any advice is appreciated

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
429

Hi,

Try this,

data : c_table(10) type c value 'MARA'.

data : c_field(10) type c value 'MATNR'.

data : c_CONDITION(25) type c value 'MATNR = ''AH0904001EN'''.

data : itab_mara like mara occurs 0 with header line.

select (C_FIELD) from (c_TABLE) into table itab_mara WHERE (C_CONDITION).

write itab_mara-matnr.

the same way you write as per your requirement

the above code working fine in 4.7 version.

Cheers,

Sasi

3 REPLIES 3
Read only

Clemenss
Active Contributor
0 Likes
429

Can u give an example?

.. don't understand.

C,

Read only

Former Member
0 Likes
429

You can use a dynamic select:


REPORT ztest LINE-SIZE 132 MESSAGE-ID zc.
TABLES: ztest1.
DATA: BEGIN OF fields OCCURS 0,
        field(80),
      END   OF fields.
DATA: BEGIN OF condition OCCURS 0,
        field(80),
      END   OF condition.
DATA :answer(80).
SELECT  * FROM  ztest1 UP TO 1 ROWS.
* Here you need some logic to ask a question and return
* the answer - probably calling another screen. For now, 
* we'll just fill it in. Then do some logic to format the
* answer into the proper format.
  MOVE 'Smith' TO answer.
  fields-field = ztest1-zz_xfield.
  APPEND fields.
  CONCATENATE ztest1-zz_xfield '= &'
    INTO condition-field SEPARATED BY space.
  CONCATENATE condition answer '&' INTO condition.
  TRANSLATE condition USING '&'''.
  APPEND condition.
  SELECT (fields) FROM (ztest1-zz_table)
    INTO answer
   WHERE (condition).
  ENDSELECT.
ENDSELECT.

Read only

Former Member
0 Likes
430

Hi,

Try this,

data : c_table(10) type c value 'MARA'.

data : c_field(10) type c value 'MATNR'.

data : c_CONDITION(25) type c value 'MATNR = ''AH0904001EN'''.

data : itab_mara like mara occurs 0 with header line.

select (C_FIELD) from (c_TABLE) into table itab_mara WHERE (C_CONDITION).

write itab_mara-matnr.

the same way you write as per your requirement

the above code working fine in 4.7 version.

Cheers,

Sasi