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

Value Assignment From A Dynamic Field

Former Member
0 Likes
1,533

First I will do:

CONCATENATE 'itab-field' counter_value INTO <b>dynamic_field</b>.

Here the <i>counter_value</i> can be anything! So, dynamic_field can have any of the follwing: itab-field1, itab-field2,...itab-fieldn.

Then I have to do:

<b>output = contents of <b>dynamic_field</b>.</b>

I tried to use field-symbols but it is duplicating some values. Any help will be appreciated!

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,514

Here is some sample code. If this doesn't help, post some relevant code.



report zrich_0001.


data: begin of itab occurs 0,
      field1 type c,
      field2 type c,
      field3 type c,
      end of itab.

field-symbols: <fs>.
data: output type string.
data: dyn_field type string.
data: index(4) type c.

start-of-selection.

  itab = 'ABC'.     append itab.
  itab = 'DEF'.     append itab.
  itab = 'GHI'.     append itab.

  loop at itab.

    do .
      index = sy-index.
      concatenate 'itab-field' index into dyn_field.
      condense dyn_field no-gaps.
      assign (dyn_field) to <fs>.
      if sy-subrc <> 0.
        exit.
      endif.
      output = <fs>.
      write:/ output.
    enddo.

  endloop.

Regards,

Rich Heilman

17 REPLIES 17
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,515

Here is some sample code. If this doesn't help, post some relevant code.



report zrich_0001.


data: begin of itab occurs 0,
      field1 type c,
      field2 type c,
      field3 type c,
      end of itab.

field-symbols: <fs>.
data: output type string.
data: dyn_field type string.
data: index(4) type c.

start-of-selection.

  itab = 'ABC'.     append itab.
  itab = 'DEF'.     append itab.
  itab = 'GHI'.     append itab.

  loop at itab.

    do .
      index = sy-index.
      concatenate 'itab-field' index into dyn_field.
      condense dyn_field no-gaps.
      assign (dyn_field) to <fs>.
      if sy-subrc <> 0.
        exit.
      endif.
      output = <fs>.
      write:/ output.
    enddo.

  endloop.

Regards,

Rich Heilman

Read only

0 Likes
1,514

Ok, I did:



WHILE ( l_extensions > 0 ). "l_extension will be >= 1

 l_offset = 3 + sy-index. "offset type c

 CONCATENATE 'wa_input-value_00' l_offset INTO l_buffer.
 CONDENSE l_buffer NO-GAPS.

 ASSIGN (l_buffer) TO <dest_plant>.
 IF sy-subrc = 0.
   l_plant = <dest_plant>.
 ENDIF.

l_extensions = l_extensions - 1.
ENDWHILE.

It is assigning value from the first loop for every other loop.

Message was edited by: Sam

Read only

0 Likes
1,514

Declare offset as type n with length whatever.

Read only

0 Likes
1,514

When you are looping around this WHILE statement are you filling values in WA.


LOOP AT itab into wa_input.

Regards,

Rich Heilman

Read only

0 Likes
1,514

Yes, there is an outer loop:

LOOP AT i_input INTO wa_input.
..
...
  WHILE (l_extensions > 0)
  ..
  ...
  ENDWHILE.
..
...
ENDLOOP.

Read only

0 Likes
1,514

Can you please post the data declarations of the variables that are used in the WHILE loop?

Read only

0 Likes
1,514

> Declare offset as type n with length whatever.

Tried it...didn't work.

Read only

0 Likes
1,514

A code like this works for me.


DATA: l_extensions TYPE i,
      l_offset     TYPE n,
      l_buffer(40) TYPE c,
      l_plant      LIKE marc-werks.

DATA: BEGIN OF wa_input OCCURS 0,
        value_001(4),
        value_002(4),
        value_003(4).
DATA: END OF wa_input.


FIELD-SYMBOLS: <dest_plant>.

MOVE: '0001' TO wa_input-value_001,
      '0002' TO wa_input-value_002,
      '0003' TO wa_input-value_003.
APPEND wa_input.

l_extensions = 3.

WHILE ( l_extensions > 0 ). "l_extension will be >= 1

  l_offset = sy-index.

  CONCATENATE 'wa_input-value_00' l_offset INTO l_buffer.
  CONDENSE l_buffer NO-GAPS.

  ASSIGN (l_buffer) TO <dest_plant>.
  IF sy-subrc = 0.
    l_plant = <dest_plant>.
  ENDIF.
  WRITE:/ l_plant.
  l_extensions = l_extensions - 1.
ENDWHILE.

Read only

0 Likes
1,514

> Can you please post the data declarations of the

> variables that are used in the WHILE loop?



  DATA: l_plant     TYPE mard-werks,
        l_offset(2) TYPE n,
        l_exts      TYPE i.

  FIELD-SYMBOLS: <dest_plant>.

LOOP AT i_input INTO wa_input.

    g_totrec = g_totrec + 1.

    READ TABLE i_no_of_extensions INTO wa_no_of_extensions WITH KEY matl_no = wa_input-value_0001.
    IF sy-subrc = 0.
      l_exts = wa_no_of_extensions-exts.
    ENDIF.

    WHILE ( l_exts > 0 ).

      l_offset = 3 + sy-index + wa_mat_mast-extension.

      CONCATENATE 'wa_input-value_00' l_offset INTO l_buffer.
      CONDENSE l_buffer NO-GAPS.
      ASSIGN (l_buffer) TO <dest_plant>.
      IF sy-subrc = 0.
        l_plant = <dest_plant>.
      ENDIF.

      PERFORM standard_conversion USING l_plant CHANGING wa_mat_mast-dest_plant.

      MOVE: g_totrec TO wa_mat_mast-rec_no,
            sy-index TO wa_mat_mast-extension.

      APPEND wa_mat_mast TO i_mat_mast.
      l_exts = l_exts - 1.

    ENDWHILE.

ENDLOOP.

Read only

0 Likes
1,514

What is the length of <b>l_buffer</b>? It should be atleast 19 characters(17 characters of the string 'wa_input-value_00' and 2 for the l_offset)?

Will l_offset be two digit always and your 'wa_input'

'value_00' fields are like value_0001, value_0002,... value_0010..?

Srinivas

Read only

0 Likes
1,514

I have declared l_buffer as STRING

i_input is a standard table of type:

BEGIN OF t_input,
 value_0001(50) TYPE c,
 value_0002(50) TYPE c,
 value_0003(50) TYPE c,
 value_0004(50) TYPE c,
 value_0005(50) TYPE c,
 value_0006(50) TYPE c,
 value_0007(50) TYPE c,
 value_0008(50) TYPE c,
 value_0009(50) TYPE c,
 value_0010(50) TYPE c,
 value_0011(50) TYPE c,
 value_0012(50) TYPE c,
 value_0013(50) TYPE c,
 value_0014(50) TYPE c,
 value_0015(50) TYPE c,
 value_0016(50) TYPE c,
 value_0017(50) TYPE c,
 value_0018(50) TYPE c,
 value_0019(50) TYPE c,
 value_0020(50) TYPE c,
 value_0021(50) TYPE c,
 value_0022(50) TYPE c,
 value_0023(50) TYPE c,
END OF t_input.

Message was edited by: Sam

Read only

0 Likes
1,514

and where is this coming from "wa_mat_mast-extension"?

Read only

0 Likes
1,514

> and where is this coming from "wa_mat_mast-extension"?

Basically, it will have the previous sy-index value. It will be zero for the first iteration of while loop.

Read only

0 Likes
1,514

But I don't see it getting assigned to the previous sy-index value within that 'while' loop.

Read only

0 Likes
1,514

There is a move statement before endwhile command.

MOVE: g_totrec TO wa_mat_mast-rec_no,
      <b>sy-index TO wa_mat_mast-extension</b>.

Read only

0 Likes
1,514

The string l_buffer is changing as per logic but the corresponding value is not assigned to the field symbol!

Read only

0 Likes
1,514

Ok, it seems to be working now......v.strange...I just created a new excel input! Thanks for your help!