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

assign field name dynamically

Former Member
0 Likes
2,430

Hi!

I got a problem that I can not solve for the moment and would be happy for some input.

We would like to mapp a value of an inputfield to an output field. But the problem is that we do not know the actual value of the infield name until running the program. We have a mapping table looking like this.

ZMAPPING

tablein TYPE CHAR20

INFIELD TYPE CHAR20

OUTFIELD TYPE CHAR20

The values of the table could look like this:

ZMAPPING-TABLEIN could contain the value BFKKZK

ZMAPPING-INFIELD could contain a fieldname e.g DATE

ZMAPPING-OUTFIELD could contain a fieldname e.g L_DATE_PARAM

The program gets a string into the program.

Depending of the first two positions of the string there is a table defining what kind of structure that should be used.

Tabstruc:

rec typ having for example the value 01

tablename having for example the value BFKKZK

so when the string is coming into the program I read this table in order to get the value of which structure I should store the stringfield.

Then I would like to move the string to this dynamic structure, meaning that sometimes the string is moved to structure BFKKZK and somethings to BFKKZP.

Then I would like to get all the entries in the table zmapping having the value of tabstruc-tabname e.g BFKKZK

For this entries I would like to read the value of the field in the string e.g BFKKZK-DATE and store it to the output field e.g L_DATE_PARAM

Hopefully anyone understands what I am trying to do and what the problem is, first it is to assign a string to a structure dynamically and then I would like to read the value of the field BFKKZK-DATE in the dynamically stored table.

Many thanks to you coming with ideas

Lena

Hi!

I got a problem that I can not solve for the moment and would be happy for some input.

We would like to mapp a value of an inputfield to an output field. But the problem is that we do not know the actual value of the infield name until running the program. We have a mapping table looking like this.

ZMAPPING

tablein TYPE CHAR20

INFIELD TYPE CHAR20

OUTFIELD TYPE CHAR20

The values of the table could look like this:

ZMAPPING-TABLEIN could contain the value BFKKZK

ZMAPPING-INFIELD could contain a fieldname e.g DATE

ZMAPPING-OUTFIELD could contain a fieldname e.g L_DATE_PARAM

The program gets a string into the program.

Depending of the first two positions of the string there is a table defining what kind of structure that should be used.

Tabstruc:

rec typ having for example the value 01

tablename having for example the value BFKKZK

so when the string is coming into the program I read this table in order to get the value of which structure I should store the stringfield.

Then I would like to move the string to this dynamic structure, meaning that sometimes the string is moved to structure BFKKZK and somethings to BFKKZP.

Then I would like to get all the entries in the table zmapping having the value of tabstruc-tabname e.g BFKKZK

For this entries I would like to read the value of the field in the string e.g BFKKZK-DATE and store it to the output field e.g L_DATE_PARAM

Hopefully anyone understands what I am trying to do and what the problem is, first it is to assign a string to a structure dynamically and then I would like to read the value of the field BFKKZK-DATE in the dynamically stored table.

Many thanks to you coming with ideas

Lena

5 REPLIES 5
Read only

Former Member
0 Likes
1,724

Unfortunately, I did not get your complete requirement..just lost on the way. But feel that field symbols should be able to help you.

Example :

lval <= 'BFKKZK'.

select * from zmapping into table imap

where tablein = lval.

loop at imap.

concatenate imap-tablein imap-infield into lfield

separated by '-'.

assingn (lfield) to <FI>.

assign (imap-outfield) to <FO>.

<FO> = <FI>.

Endloop.

Note : There is one thing that needs to be added in the loop is to read the particular table..but here I am not sure of the key etc

Regards

Anurag

Read only

Former Member
0 Likes
1,724

Hi

If I understand:

DATA: MY_STRUCTUTURE TYPE REF TO DATA.

FIELD-SYMBOLS: <MY_STRUCT> TYPE ANY,

<INPUT> TYPE ANY,

<OUTPUT> TYPE ANY.

DATA: TABLE(30), FIELDNAME.

CREATE DATA MY_STRUCTUTURE TYPE (ZMAPPING-TABLEIN).

ASSIGN MY_STRUCTUTURE->* TO <MY_STRUCT>.

ASSIGN COMPONENT ZMAPPING-INFIELD OF STRUCTURE <MY_STRUCT> TO <INPUT>.

ASSIGN (ZMAPPING-INFIELD) TO <OUTPUT>.

<OUTPUT> = <INPUT>.

Max

Read only

Former Member
0 Likes
1,724

If you know the source structure you can use:

DATA: l_LineType TYPE string,

l_Ref TYPE REF TO DATA.

FIELD-SYMBOLS: <row>

.

l_LineType = 'SURCESTRUC'.

CREATE DATA l_ItabRef TYPE (l_LineType).

ASSIGN l_Ref->* TO <row>.

<row> = l_inputstring.

And than you can do the mapping to access dynamically a field in a structure you can use:

ASSIGN COMPONENT lv_fieldname OF STRUCTURE row TO <fs>.

I didn't test this, but it should work.

OK OK I was too slow

Message was edited by: Tobias Ohm

Read only

Former Member
0 Likes
1,724

Hi,

check table nametab_get to get all fields of

table.

Regards

Amole

Read only

Former Member
0 Likes
1,724

Hi miroslav,

1. There are two things

a) dynamic name which we get for the structure-field to read

b) actual structure

2. Do like this :

<b>DATA : VARNAME(50) TYPE C.

FIELD-SYMBOLS : <FS>

VARNAME = 'MYDYNAMICFIELDNAME'

ASSIGN (VARNAME) TO <FS>.

WRITE <FS>.</b>

regards,

amit m.