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

How to fill table fields dynamically

Former Member
0 Likes
1,176

Hi everybody,

small question: We take a

transparant

table. This table has the following fields:

mandt
matnr
text
batchchar1
batchchar2
batchchar3

Now we obtain batchcharacteristics using a function. This function returns the following

internal

table:

matnr - atnam - atwrt


1234567 - batchchar1 - 5
1234567 - batchchar2 - 7
1234567 - batchchar3 - bla

My question is: is there an easy way to move the values of the characteristics batchchar1, 2 and 3 to there equivalent fields in our transparant table? Please note that 'batchchar1' is a value in our

internal

table of field atnam,

ánd

it is a field in our transparant table in which we would like to place the value 5.

The main point is that I'd like to fill the values 5, 7 and bla into the corresponding fieldnames of the batchcharacteristics in our transparant table.

Any ideas?

Cheers and thanks

Laurens

ps: because of the large amount of fields of the batchcharacteristics, a hardcoded definition of the transparant table fields isn't really an option.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
696

Here is a small piece of code.

<b>TABLES: zzzz. "transparent table

DATA: t_matnr TYPE zzzz OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF t_values OCCURS 0, "Batch Characteristics

matnr TYPE ausp-objek,

atnam TYPE cabn-atnam,

atwrt TYPE ausp-atwrt,

END OF t_values.

DATA: w_field(60) TYPE c.

FIELD-SYMBOLS: <tablefield>.

  • Insert logic for populating t_values here

SORT t_values BY matnr.

LOOP AT t_values.

AT NEW matnr.

CLEAR t_matnr.

t_matnr-matnr = t_values-matnr.

ENDAT.

CONCATENATE 'T_VALUES-' t_values-atnam INTO w_field.

TRANSLATE w_field TO UPPER CASE.

ASSIGN (w_field) TO <tablefield>.

<tablefield> = t_values-atwrt.

AT END OF matnr.

APPEND t_matnr.

ENDAT.

ENDLOOP.

MODIFY zzzz FROM TABLE t_matnr.</b>

Rishi

replace ZZZZ with your transparent table

3 REPLIES 3
Read only

ssimsekler
Product and Topic Expert
Product and Topic Expert
0 Likes
696

Hi Laurens

You can use field symbols for this purpose.

e.g.

FIELD-SYMBOLS <field> .

ASSIGN (itab-atnam) TO <field> .
IF sy-subrc = 0 .
  <field> = itab-atwrt .
ENDIF .

Regards

*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>

Read only

Former Member
0 Likes
697

Here is a small piece of code.

<b>TABLES: zzzz. "transparent table

DATA: t_matnr TYPE zzzz OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF t_values OCCURS 0, "Batch Characteristics

matnr TYPE ausp-objek,

atnam TYPE cabn-atnam,

atwrt TYPE ausp-atwrt,

END OF t_values.

DATA: w_field(60) TYPE c.

FIELD-SYMBOLS: <tablefield>.

  • Insert logic for populating t_values here

SORT t_values BY matnr.

LOOP AT t_values.

AT NEW matnr.

CLEAR t_matnr.

t_matnr-matnr = t_values-matnr.

ENDAT.

CONCATENATE 'T_VALUES-' t_values-atnam INTO w_field.

TRANSLATE w_field TO UPPER CASE.

ASSIGN (w_field) TO <tablefield>.

<tablefield> = t_values-atwrt.

AT END OF matnr.

APPEND t_matnr.

ENDAT.

ENDLOOP.

MODIFY zzzz FROM TABLE t_matnr.</b>

Rishi

replace ZZZZ with your transparent table

Read only

0 Likes
696

I've used field symbols for this purpose but I think I did a few things wrong. I'll try this first thing in the morning!

Cheers and thanks!

Laurens