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

Modifying dynamic internal table

former_member210857
Participant
0 Likes
1,407

Hi Experts ,

I have a requirement to modify dynamic internal table..

Eg:

In the below screen grab there is two consulting Exp .I want to make it a single row and modify values accordingly.I have checked in forums and everywhere it is showing how  to append a dynamic internal table. I want to modify internal table

Thanks and Regards,

Subeesh Kannottil

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,289

Debug below snippet and observe how internal table changes.

  1. TYPES:
  2. BEGIN OF ty,
  3.   name TYPE char10,
  4.   val1 TYPE i,
  5.   val2 TYPE i,
  6. END OF ty.
  7. DATA: lt TYPE TABLE OF ty,
  8.       ls TYPE ty.
  9. ls-name = 'consulting'.
  10. ls-val1 = 1.
  11. APPEND ls TO lt.
  12. CLEAR ls-val1.
  13. ls-val2 = 5.
  14. APPEND ls TO lt.
  15. DATA lv_value TYPE i.
  16. PERFORM get_value USING lt 2 3 lv_value.
  17. PERFORM modify_record USING lt 1 3 lv_value.
  18. PERFORM delete_record USING lt 2.
  19. *----------------------------------------------------------------------*
  20. FORM get_value  USING    pt TYPE STANDARD TABLE
  21.                          pv_index
  22.                          pv_column
  23.                          pv_value.
  24.   FIELD-SYMBOLS: <fs_record> TYPE ANY,
  25.                  <fs_value> TYPE ANY.
  26.   READ TABLE pt ASSIGNING <fs_record> INDEX pv_index.
  27.   CHECK sy-subrc EQ 0.
  28.   ASSIGN COMPONENT pv_column OF STRUCTURE <fs_record> TO <fs_value>.
  29.   CHECK sy-subrc EQ 0.
  30.   pv_value = <fs_value>.
  31. ENDFORM.                    " GET_VALUE
  32. *----------------------------------------------------------------------*
  33. FORM modify_record  USING    pt TYPE STANDARD TABLE
  34.                              pv_index
  35.                              pv_column
  36.                              pv_value.
  37.   FIELD-SYMBOLS: <fs_record> TYPE ANY,
  38.                  <fs_value> TYPE ANY.
  39.   READ TABLE pt ASSIGNING <fs_record> INDEX pv_index.
  40.   CHECK sy-subrc EQ 0.
  41.   ASSIGN COMPONENT pv_column OF STRUCTURE <fs_record> TO <fs_value>.
  42.   CHECK sy-subrc EQ 0.
  43.   <fs_value> = pv_value.
  44. ENDFORM.                    " MODIFY_RECORD
  45. *----------------------------------------------------------------------*
  46. FORM delete_record  USING    pt TYPE STANDARD TABLE
  47.                              pv_index.
  48.   DELETE pt INDEX pv_index.
  49. ENDFORM.                    " DELETE_RECORD

/.

7 REPLIES 7
Read only

custodio_deoliveira
Active Contributor
0 Likes
1,289

If you want to summarize values, why dont you use COLLECT statement?

Read only

Former Member
0 Likes
1,289

please search for the use of COLLECT before the real use (as it is not always clear, how and which columns will be summarized). For me a simple copy of the internal table with reading / appending lines is a better approach as for the clearness of the code.

Read only

former_member210857
Participant
0 Likes
1,289

Thanks for the reply,

I dont want to add the values in the fields,

As you can see in the picture Consulting expenses comes twice ,

First one got value in the first column and second one in the 5 th column .

I want consulting expenses as one row filled with '555 ' in the first column and '13000' in the fifth row

thanks and regards ,

Subeesh Kannottil

Read only

0 Likes
1,289

then probably you do not want to add the row but search for an existing one? Our response is probably still the same

Read only

Former Member
0 Likes
1,289

If I'm not wrong, I think that he needs to merge the records DINAMICALLY field by field.

I'm trying to find a solution!!!

Read only

Former Member
0 Likes
1,289

I've tried to find a solution but unfortunately there is no ABAP STATEMENT (like COLLECT) / FUNCTION MODULE that could allow you to make this operation.

I think that you have to make a routine form to manage this type of situation properly.

Hope that someone could light up this post.

Finger crossed.

Read only

Former Member
0 Likes
1,290

Debug below snippet and observe how internal table changes.

  1. TYPES:
  2. BEGIN OF ty,
  3.   name TYPE char10,
  4.   val1 TYPE i,
  5.   val2 TYPE i,
  6. END OF ty.
  7. DATA: lt TYPE TABLE OF ty,
  8.       ls TYPE ty.
  9. ls-name = 'consulting'.
  10. ls-val1 = 1.
  11. APPEND ls TO lt.
  12. CLEAR ls-val1.
  13. ls-val2 = 5.
  14. APPEND ls TO lt.
  15. DATA lv_value TYPE i.
  16. PERFORM get_value USING lt 2 3 lv_value.
  17. PERFORM modify_record USING lt 1 3 lv_value.
  18. PERFORM delete_record USING lt 2.
  19. *----------------------------------------------------------------------*
  20. FORM get_value  USING    pt TYPE STANDARD TABLE
  21.                          pv_index
  22.                          pv_column
  23.                          pv_value.
  24.   FIELD-SYMBOLS: <fs_record> TYPE ANY,
  25.                  <fs_value> TYPE ANY.
  26.   READ TABLE pt ASSIGNING <fs_record> INDEX pv_index.
  27.   CHECK sy-subrc EQ 0.
  28.   ASSIGN COMPONENT pv_column OF STRUCTURE <fs_record> TO <fs_value>.
  29.   CHECK sy-subrc EQ 0.
  30.   pv_value = <fs_value>.
  31. ENDFORM.                    " GET_VALUE
  32. *----------------------------------------------------------------------*
  33. FORM modify_record  USING    pt TYPE STANDARD TABLE
  34.                              pv_index
  35.                              pv_column
  36.                              pv_value.
  37.   FIELD-SYMBOLS: <fs_record> TYPE ANY,
  38.                  <fs_value> TYPE ANY.
  39.   READ TABLE pt ASSIGNING <fs_record> INDEX pv_index.
  40.   CHECK sy-subrc EQ 0.
  41.   ASSIGN COMPONENT pv_column OF STRUCTURE <fs_record> TO <fs_value>.
  42.   CHECK sy-subrc EQ 0.
  43.   <fs_value> = pv_value.
  44. ENDFORM.                    " MODIFY_RECORD
  45. *----------------------------------------------------------------------*
  46. FORM delete_record  USING    pt TYPE STANDARD TABLE
  47.                              pv_index.
  48.   DELETE pt INDEX pv_index.
  49. ENDFORM.                    " DELETE_RECORD

/.