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: 

HOW TO SUM THE DATA IN FIELD-SYMBOL

Former Member
0 Kudos

HI EXPERTS,

THIS IS SASIDHAR, I HAD CREATED ONE DYNAMICAL INTERNAL TABLE BY USING FIELD-SYMBOL <DYN_TABLE> AND ALSO UPLOADED FLAT FILE INTO <DYN_TABLE>. NOW I HAVE TO SUM THE DATA IN <DYN_TABLE>. WHENEVER I AM TRYIMG TO USE SUM STATEMENT THE SYSTEM IS GIVING ERROR. PLEASE GIVE ME YOUR VALUABLE SUGGESTIONS AND TRY TO SEND SAMPLE CODING. MY CODING IS AS FOLLOWS.

field-symbols: <dyn_table> type standard table,

<dyn_wa>.

DATA: BEGIN OF T_TABLE OCCURS 0,

FIELD_NO(2) TYPE N,

FIELD(10) TYPE C,

DESC(40) TYPE C,

TYPE(6) TYPE C,

LENG(3) TYPE N,

DEC(2) TYPE N,

END OF T_TABLE.

loop at t_table.

clear xfc.

xfc-fieldname = t_table-field .

xfc-datatype = t_table-type.

  • xfc-inttype = t_table-.

xfc-intlen = t_table-leng.

xfc-decimals = t_table-dec.

append xfc to ifc.

"THE INTERNAL TABLE T_TABLE CONTAINS THE NAME TYPE AND LENTH

OF THE FIELD."

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = ifc

importing

ep_table = dy_table.

assign dy_table->* to <dyn_table>.

assign dy_table->* to <table_sum>.

  • Create dynamic work area and assign to FS

create data dy_line like line of <dyn_table>.

assign dy_line->* to <dyn_wa>.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = w_file

FILETYPE = 'ASC'

TABLES

DATA_TAB = <dyn_table>

loop at <dyn_table> into <dyn_wa>.

do.

assign component sy-index

of structure <dyn_wa> to <dyn_field>.

if sy-subrc <> 0.

exit.

endif.

if sy-index = 1.

  • write:/ <dyn_field>.

else.

  • write: <dyn_field>.

endif.

WITH THIS CODING I AM GETTING DATA INTO <DYN_TABLE>. BUT I CAN'T ABLE TO SUM THE DATA.

THANKS & REGARDS

SASIDHAR.V

2 REPLIES 2

andreas_mann3
Active Contributor
0 Kudos

hi,

just try sth like that -:)

 ASSIGN COMPONENT sy-index OF STRUCTURE <dyn_wa> TO <dyn_field>.

    IF sy-subrc <> 0.
      EXIT.
    ENDIF.

    DESCRIBE FIELD <dyn_field> TYPE t.
    IF t <> 'N'.
      FREE <dyn_field>.
    ENDIF.

  ENDDO.

  dy_sum = <dyn_wa>.
  COLLECT dy_sum INTO <table_sum>.

A.

0 Kudos

Thanks Andres mann,

But when i run thiscoding the system giving error like " you can only use the collect command in a table if all of its non-key fields are numaric (type I,P,or F).P or F)." please give the suggestion to overcome this error.

Thanks & Regards

Sasidhar.V