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

Populating created Dynamic table for alv

Former Member
0 Likes
743

Hi Experts,

I have created a dynamic table as below :

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = i_lvc_cat

IMPORTING

ep_table = new_table.

  • Create internal Table

ASSIGN new_table->* TO <f_itab>.

  • Create workarea of type dynamic table

CREATE DATA new_table LIKE LINE OF <f_itab>.

ASSIGN new_table->* TO <f_wa>.

Also, I have internal table which is like : ITAB

WERKS BTRTL TEXT BONUSAMT LTC_AMT

3001 300A ADMIN 100.00 150.00

3001 300B FINANCE 200.00 250.00

3001 300C HR 300.00 350.00

3002 300D Bus Del 400.00 450.00

3002 300E Comp 500.00 550.00

Now, data in column TEXT would be the columns created dynamically in table <f_itab> i created above.

Depending on WERKS column data, I have to populate dynamic created table <f_itab> with values of table ITAB.

Eg : Column1 WERKS ADMIN FINANCE HR Bus Del Comp Total

BONUSAMT 3001 100.00 200.00 300.00 0.00 0.00 600.00

BONUSAMT 3002 0.00 0.00 0.00 400.00 500.00 900.00

LTC_AMT 3001 150.00 250.00 350.00 0.00 0.00 750.00

LTC_AMT 3002 0.00 0.00 0.00 450.00 550.00 1000.00

Please help me in coding this.

Thanks a lottt.

Regards,

Shital.

Moderator message - Please do not use words like "urgenttt" in your posts

Edited by: Rob Burbank on Jul 27, 2010 1:59 PM

Hi Experts,

I have created a dynamic table as below :

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = i_lvc_cat

IMPORTING

ep_table = new_table.

  • Create internal Table

ASSIGN new_table->* TO <f_itab>.

  • Create workarea of type dynamic table

CREATE DATA new_table LIKE LINE OF <f_itab>.

ASSIGN new_table->* TO <f_wa>.

Also, I have internal table which is like : ITAB

WERKS BTRTL TEXT BONUSAMT LTC_AMT

3001 300A ADMIN 100.00 150.00

3001 300B FINANCE 200.00 250.00

3001 300C HR 300.00 350.00

3002 300D Bus Del 400.00 450.00

3002 300E Comp 500.00 550.00

Now, data in column TEXT would be the columns created dynamically in table <f_itab> i created above.

Depending on WERKS column data, I have to populate dynamic created table <f_itab> with values of table ITAB.

Eg : Column1 WERKS ADMIN FINANCE HR Bus Del Comp Total

BONUSAMT 3001 100.00 200.00 300.00 0.00 0.00 600.00

BONUSAMT 3002 0.00 0.00 0.00 400.00 500.00 900.00

LTC_AMT 3001 150.00 250.00 350.00 0.00 0.00 750.00

LTC_AMT 3002 0.00 0.00 0.00 450.00 550.00 1000.00

Please help me in coding this.

Thanks a lottt.

Regards,

Shital.

Moderator message - Please do not use words like "urgenttt" in your posts

Edited by: Rob Burbank on Jul 27, 2010 1:59 PM

3 REPLIES 3
Read only

bbalci
Contributor
0 Likes
704

Hello shital chheda ,

Try this code :

FIELD-SYMBOLS <f_werks> TYPE ANY.

FIELD-SYMBOLS <f_text> TYPE ANY.

DATA wa_itab LIKE LINE OF itab.

*1 Loop on your dynamic internal table :

LOOP AT <f_itab> ASSIGNING <f_wa>.

*2 Point werks field of current record in field-symbol <f_werks>

ASSIGN COMPONENT 'WERKS' OF STRUCTURE <f_wa> TO <f_werks>.

  • 3 Read corresponding line from itab matching field werks :

READ TABLE itab INTO wa_itab WITH KEY werks = <f_werks>.

IF sy-subrc EQ 0.

*4 Point TEXT field of current record in field-symbol <f_text>

ASSIGN COMPONENT 'TEXT' OF STRUCTURE <f_wa> TO <f_text>.

<f_text> = wa_itab-text.

  • You don't need to use MODIFY command

ENDIF.

ENDLOOP.

I hope it helps you.

Edited by: Rob Burbank on Jul 27, 2010 2:00 PM

Read only

former_member585060
Active Contributor
0 Likes
704

Hi,

You can try with below code,

DATA : lv_field TYPE fieldname,
         lv_tot   TYPE umxxh.

FIELD-SYMBOLS:   <v_field>  TYPE ANY.              " For Field

  LOOP AT i_itab INTO wa_itab.
 
    ASSIGN COMPONENT 'WERKS' OF STRUCTURE <wa_line> TO <v_field>.
    <v_field> = wa_itab-werks.

    CASE wa_itab-text.

      WHEN 'ADMIN'.
        ASSIGN COMPONENT 'ADMIN' OF STRUCTURE <wa_line> TO <v_field>.
        <v_field> = wa_itab-bonusamt.
        lv_tot = lv_tot + wa_itab-bonusamt.

      WHEN 'FINANCE'.
        ASSIGN COMPONENT 'FINANCE' OF STRUCTURE <wa_line> TO <v_field>.
        <v_field> = wa_itab-bonusamt.
        lv_tot = lv_tot + wa_itab-bonusamt.

      WHEN 'HR'.
        ASSIGN COMPONENT 'HR' OF STRUCTURE <wa_line> TO <v_field>.
        <v_field> = wa_itab-bonusamt.
        lv_tot = lv_tot + wa_itab-bonusamt.

      WHEN 'BUSDEL'.
        ASSIGN COMPONENT 'BUSDEL' OF STRUCTURE <wa_line> TO <v_field>.
        <v_field> = wa_itab-bonusamt.
        lv_tot = lv_tot + wa_itab-bonusamt.

      WHEN 'COMP'.
        ASSIGN COMPONENT 'COMP' OF STRUCTURE <wa_line> TO <v_field>.
        <v_field> = wa_itab-bonusamt.
        lv_tot = lv_tot + wa_itab-bonusamt.

      WHEN OTHERS.
    ENDCASE.

    AT END OF werks.

      ASSIGN COMPONENT 'TOTAL' OF STRUCTURE <wa_line> TO <v_field>.
      <v_field> = lv_tot.

      INSERT <wa_line> INTO TABLE <i_table>.

      CLEAR : <wa_line>, <v_field>, lv_tot .

    ENDAT.

  ENDLOOP.

For LTC_AMT you have to loop itab again and replace wa_itab-bonusamt with wa_itab-ltc_amt.

Regards

Bala Krishna

Read only

0 Likes
704

Hi,

Instead of second loop on itab for LTC_AMT,

Declare another field symbol of dynamic internal table type same as <wa_line>,

Another field symbol of type any,

Fill it above loop and endloop.

Instead of hard coding the Dynamic fields in ASSIGN COMPONENT statement, declare a internal table to hold just internal table fields, so that it can be used in ASSING COMPONENT statement.

DATA : lv_field TYPE fieldname,
              lv_tot   TYPE umxxh,
              lv_to11   TYPE umxxh.
 
FIELD-SYMBOLS:   <v_field>  TYPE ANY,
                               <v_field1> TYPE ANY,
                               <wa_line1> TYPE <i_table>.
 
  LOOP AT i_itab INTO wa_itab.
 
    ASSIGN COMPONENT 'WERKS' OF STRUCTURE <wa_line> TO <v_field>.
    <v_field> = wa_itab-werks.
 
    ASSIGN COMPONENT 'WERKS' OF STRUCTURE <wa_line1> TO <v_field1>.
    <v_field1> = wa_itab-werks.

    CASE wa_itab-text.
 
      WHEN 'ADMIN'.
        ASSIGN COMPONENT 'ADMIN' OF STRUCTURE <wa_line> TO <v_field>.
        <v_field> = wa_itab-bonusamt.
        lv_tot = lv_tot + wa_itab-bonusamt.
 
        ASSIGN COMPONENT 'ADMIN' OF STRUCTURE <wa_line1> TO <v_field1>.
        <v_field1> = wa_itab-bonusamt.
        lv_tot1 = lv_tot1 + wa_itab-ltc_amt.

      WHEN 'FINANCE'.
        ASSIGN COMPONENT 'FINANCE' OF STRUCTURE <wa_line> TO <v_field>.
        <v_field> = wa_itab-bonusamt.
        lv_tot = lv_tot + wa_itab-bonusamt.
 
        ASSIGN COMPONENT 'FINANCE' OF STRUCTURE <wa_line1> TO <v_field1>.
        <v_field1> = wa_itab-bonusamt.
        lv_tot1 = lv_tot1 + wa_itab-ltc_amt.

     " Similarly for others
 
      WHEN OTHERS.
    ENDCASE.
 
    AT END OF werks.
 
      ASSIGN COMPONENT 'TOTAL' OF STRUCTURE <wa_line> TO <v_field>.
      <v_field> = lv_tot.
 
      ASSIGN COMPONENT 'TOTAL' OF STRUCTURE <wa_line1> TO <v_field1>.
      <v_field1> = lv_tot1.

      INSERT <wa_line> INTO TABLE <i_table>.
 
      INSERT <wa_line1> INTO TABLE <i_table>.

      CLEAR : <wa_line>, <v_field>, lv_tot,
                      <wa_line1>, <v_field1>, lv_tot1.
 
    ENDAT.
 
  ENDLOOP.

After this Sort the table <i_table>.

Regards

Bala Krishna

Edited by: Bala Krishna on Jul 28, 2010 9:23 AM