‎2006 Jan 10 8:57 PM
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!
‎2006 Jan 10 9:04 PM
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
‎2006 Jan 10 9:04 PM
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
‎2006 Jan 10 9:29 PM
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
‎2006 Jan 10 9:36 PM
‎2006 Jan 10 9:41 PM
‎2006 Jan 10 9:46 PM
Yes, there is an outer loop:
LOOP AT i_input INTO wa_input.
..
...
WHILE (l_extensions > 0)
..
...
ENDWHILE.
..
...
ENDLOOP.
‎2006 Jan 10 9:47 PM
Can you please post the data declarations of the variables that are used in the WHILE loop?
‎2006 Jan 10 9:50 PM
> Declare offset as type n with length whatever.
Tried it...didn't work.
‎2006 Jan 10 9:56 PM
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.
‎2006 Jan 10 10:04 PM
> 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.
‎2006 Jan 10 10:19 PM
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
‎2006 Jan 10 10:32 PM
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
‎2006 Jan 10 10:39 PM
‎2006 Jan 10 10:40 PM
> 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.
‎2006 Jan 10 10:46 PM
But I don't see it getting assigned to the previous sy-index value within that 'while' loop.
‎2006 Jan 10 10:49 PM
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>.
‎2006 Jan 10 10:55 PM
The string l_buffer is changing as per logic but the corresponding value is not assigned to the field symbol!
‎2006 Jan 10 11:25 PM
Ok, it seems to be working now......v.strange...I just created a new excel input! Thanks for your help!