Application Development 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: 

ABAP table fileds

Former Member
0 Kudos

hi,

I have this custom table that has the following fields

belnr

trans_type

debit_fieldname

in the table t095 I need to get the the value of whichever filed name

I have in the custom table

example.

Custome Table

BELNR = 1000

TRANS_TYPE = Z09

DEBIT_FIELDNAME = KTANSG

now I have assigned the values of T095 in an internal table t_t095 which has the value for all the fields but the only field i need to get is the

field KTANSG.

what code should I use to get the value of KTANSG,

note the DEBIT_FIELDNAME can change anytime depending on the trans type

please help,.

thanks

2 REPLIES 2

Former Member
0 Kudos

let's say your work area for t_t095 is wa_t095

such that


wa_t095-BELNR = 1000
wa_t095-TRANS_TYPE = Z09
wa_t095-DEBIT_FIELDNAME = KTANSG

You can use parentheses. It's pretty straightforward. But your problem will be the destination variable. Since you said you can get any field you want, the destination variable must also support any data type you put into it.

The first thing I thought was to use a string.



DATA: fieldname TYPE DD03L-FIELDNAME.
DATA: fieldvalue TYPE STRING.

fieldname = 'KTANSG'.

SELECT (fieldname) FROM t059 INTO fieldvalue.
    WRITE: / fieldvalue.
ENDSELECT.

But this does not work all the time. For example, if you tried to get a date field.

Please wait. I'm still testing the use of field symbols...I'll edit this later once done.

0 Kudos

here it is.

a fully dynamic field query. (I used AFKO-GLTRP: a date type. just random field from a random table). Just adapt it to your requirements and your code.



DATA:
    tablename TYPE DD03L-TABNAME,
    fieldname TYPE DD03L-FIELDNAME,

    fieldvalue TYPE REF TO DATA,
    tablefield TYPE STRING
.
FIELD-SYMBOLS:
    <fs_val> TYPE ANY
.

tablename = 'AFKO'.
fieldname = 'GLTRP'. " Date type

CONCATENATE tablename '-' fieldname INTO tablefield.
CREATE DATA fieldvalue TYPE (tablefield).          " allocate memory space
ASSIGN fieldvalue->* TO <fs_val>.                  " create a pointer to that space

SELECT (fieldname) FROM (tablename) INTO <fs_val>. " store value using pointer
    WRITE: / <fs_val>.                             " print value using pointer
ENDSELECT.

This is better since STRING data type can't hold all data types (according to my testing).

<removed by moderator>

Edited by: Thomas Zloch on Jul 13, 2010 11:56 AM - please do not ask for ...