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

change field data in a dynamic internal table

Former Member
0 Likes
4,841

Hi folks,

Need some help in the code. I am trying to update a field coming from a dynamic internal table. While doing so, I am losing the rest of the data.

Any thoughts? Thanks in advance.

VG

field-symbols: <fs_wa> TYPE ANY,

<fs_var> TYPE ANY,

<gi_data> TYPE STANDARD TABLE.

loop at <gi_data> assigning <fs_wa>.

assign component 1 of structure <fs_wa> to <fs_var>.

<fs_var> = sy-mandt. ......> change of the data field

need to modify <fs_wa>....??

tried something like this...

assign <fs_var> to <fs_wa>. --- rest of the data field is blank.

modify (v_tabname) from <fs_wa>.----


**** modify database table (v_tbname) dynamically

if sy-subrc = 0.

commit work.

endif.

endloop.

1 ACCEPTED SOLUTION
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
3,546

PARAMETERS:p_table TYPE tabname.

DATA:lr_data TYPE REF TO data,
     lr_line TYPE REF TO data.

FIELD-SYMBOLS:<fs_table> TYPE STANDARD TABLE,
              <fs_s>  TYPE ANY,
              <fs_line>  TYPE ANY.

CREATE DATA lr_data TYPE TABLE OF (p_table).
ASSIGN lr_data->* TO <fs_table>.
CREATE DATA lr_line LIKE LINE OF <fs_table>.
ASSIGN lr_line->* TO <fs_line>.

SELECT * FROM (p_table) INTO TABLE <fs_table> UP TO 20 ROWS.

LOOP AT <fs_table> ASSIGNING <fs_line>.
  ASSIGN COMPONENT 1 OF STRUCTURE <fs_line> TO <fs_s>.
  IF sy-subrc = 0.
    <fs_s> = sy-mandt.
  ENDIF.
ENDLOOP.

MODIFY (p_table) FROM TABLE <fs_table>.

Hi folks,

Need some help in the code. I am trying to update a field coming from a dynamic internal table. While doing so, I am losing the rest of the data.

Any thoughts? Thanks in advance.

VG

field-symbols: <fs_wa> TYPE ANY,

<fs_var> TYPE ANY,

<gi_data> TYPE STANDARD TABLE.

loop at <gi_data> assigning <fs_wa>.

assign component 1 of structure <fs_wa> to <fs_var>.

<fs_var> = sy-mandt. ......> change of the data field

need to modify <fs_wa>....??

tried something like this...

assign <fs_var> to <fs_wa>. --- rest of the data field is blank.

modify (v_tabname) from <fs_wa>.----


**** modify database table (v_tbname) dynamically

if sy-subrc = 0.

commit work.

endif.

endloop.

6 REPLIES 6
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
3,546

Is your requirement only to change the client field ?

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
3,547

PARAMETERS:p_table TYPE tabname.

DATA:lr_data TYPE REF TO data,
     lr_line TYPE REF TO data.

FIELD-SYMBOLS:<fs_table> TYPE STANDARD TABLE,
              <fs_s>  TYPE ANY,
              <fs_line>  TYPE ANY.

CREATE DATA lr_data TYPE TABLE OF (p_table).
ASSIGN lr_data->* TO <fs_table>.
CREATE DATA lr_line LIKE LINE OF <fs_table>.
ASSIGN lr_line->* TO <fs_line>.

SELECT * FROM (p_table) INTO TABLE <fs_table> UP TO 20 ROWS.

LOOP AT <fs_table> ASSIGNING <fs_line>.
  ASSIGN COMPONENT 1 OF STRUCTURE <fs_line> TO <fs_s>.
  IF sy-subrc = 0.
    <fs_s> = sy-mandt.
  ENDIF.
ENDLOOP.

MODIFY (p_table) FROM TABLE <fs_table>.
Read only

Former Member
0 Likes
3,546

Hello Vinu,

you don't need to modify <fs_wa>. Field-Symbols are just pointers. At to moment you change <fs_var>, you change the component of <fs_wa> and with this the compenent in the acual line of <gi_data>. And you don't loose any data, you just change the object <fs_wa> is pointing to. Data are still in <gi_data> (in fact they are in the object <gi_data> is pointing to.

See conding below.

Best regards

Maximilian

REPORT test.

PARAMETERS v_tabnam TYPE char30 DEFAULT 'KNA1'.

DATA: r_tab TYPE REF TO data.

FIELD-SYMBOLS: <fs_wa> TYPE ANY,

<fs_var> TYPE ANY,

<gi_data> TYPE STANDARD TABLE.

CREATE DATA r_tab TYPE TABLE OF (v_tabnam).

ASSIGN r_tab->* TO <gi_data>.

SELECT * FROM (v_tabnam) INTO CORRESPONDING FIELDS OF TABLE <gi_data>

UP TO 5 ROWS.

LOOP AT <gi_data> ASSIGNING <fs_wa>.

ASSIGN COMPONENT 1 OF STRUCTURE <fs_wa> TO <fs_var>.

<fs_var> = sy-mandt. "......> change of the data field

"need to modify <fs_wa>....??

"tried something like this...

"ASSIGN <fs_var> TO <fs_wa>. "--- rest of the data field is blank.

MODIFY (v_tabnam) FROM <fs_wa>. "----


**** modify database table (v_tbname) dynamically

IF sy-subrc = 0.

COMMIT WORK.

ENDIF.

ENDLOOP.

Read only

0 Likes
3,546

Thanks for the response. Yes. I need to change only the client field and rest should be same.

Keshav - in your code you change the field value in <f_s> and then you modify the database table from <fs_table>. But how to transfer the chnaged value in <f_s> to <fs_table> without losing the rest of the line record. I did not get that part. As you know I am trying to do everything dynamically.

Please advise.

Thanks once again, learning to work with Filed symbols and definitely is an interesting aspect.

VG

Read only

0 Likes
3,546

Hi Vinu,

You don't need to explictly assign the value of <f_s> to <fs_table>. You will be having the latest Client field value in the <fs_table> as Component 1 of <fs_table> is pointing to <f_s>. If you want you can check the value of <fs_table> in debugging mode. This is an advantage of field symbol.

Let me know in case of any.

Regards,

Srinivas

Read only

0 Likes
3,546

Thanks a lot for inputs. Yes it works. diving into field symbols definitely understanding a lot better.

Thanks once again,

VG