Application Development 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: 

Dynamic Internal Table - Issue with assignment of values in specific format

Former Member
0 Kudos

I have an internal table (refer Table 1 below) from which I need to pass certain values to a dynamic Internal table.

I have managed to build the dynamic internal table required, but the issue I face is how to transfer the values in the format as seen in Table 2 below.

When I do the below I am able to get the specific values required, but then I am not sure how I should proceed after this.

LOOP AT it_table1 ASSIGNING <fs_it1>.

     ASSIGN COMPONENT 2 OF STRUCTURE <fs_it1> TO <fs1>.

     ASSIGN COMPONENT 4 OF STRUCTURE <fs_it1> TO <fs2>.

ENDLOOP.

I did quite an extensive search in this & other forums, but couldn't manage to find a clue.

If this query has been addressed before please help to point me to the right thread or if further clarification is needed let me know.

Table 1:

CategoryTypeSubjectValue - 1Value - 2Value - 3Value - 4Value - 5Total
AAXX01A10 10 20
ABXY02B 5 15525
ACXX03C15 5 20
AAXX01D20 15 35

Table 2:

Dynamic Table for Value - 1 (dynamic table created based on column - Type of main internal table)
CategoryXX01XY02XX03XX01Total
AA10 10
AB 0
AC 15 15
AA20 20
1 ACCEPTED SOLUTION

SuhaSaha
Advisor
Advisor
0 Kudos

This is what your code should look like

LOOP AT gt_static INTO wa_static.

   APPEND INITIAL LINE TO <gt_dyn> ASSIGNING <gwa_dyn>.

* Category

   ASSIGN COMPONENT 'CATEGORY' OF STRUCTURE <gwa_dyn> TO <gv_cat>.

   <gv_cat> = wa_static-category.

* Type - XX01, XY02, XX03 etc

   ASSIGN COMPONENT wa_static-type OF STRUCTURE <gwa_dyn> TO <gv_type>.

   <gv_type> = wa_static-value1.

ENDLOOP.

A couple of points to note:

  1. Check SY-SUBRC (or IS ASSIGNED) after every ASSIGN statement.
  2. The column TOTAL can be calculated later (shouldn't be a big deal )

BR,

Suhas

2 REPLIES 2

SuhaSaha
Advisor
Advisor
0 Kudos

This is what your code should look like

LOOP AT gt_static INTO wa_static.

   APPEND INITIAL LINE TO <gt_dyn> ASSIGNING <gwa_dyn>.

* Category

   ASSIGN COMPONENT 'CATEGORY' OF STRUCTURE <gwa_dyn> TO <gv_cat>.

   <gv_cat> = wa_static-category.

* Type - XX01, XY02, XX03 etc

   ASSIGN COMPONENT wa_static-type OF STRUCTURE <gwa_dyn> TO <gv_type>.

   <gv_type> = wa_static-value1.

ENDLOOP.

A couple of points to note:

  1. Check SY-SUBRC (or IS ASSIGNED) after every ASSIGN statement.
  2. The column TOTAL can be calculated later (shouldn't be a big deal )

BR,

Suhas

Former Member
0 Kudos

Suhas appreciate your quick help. That definitely addressed the issue faced by me.

Keep the good work going.