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

Passing any internal table to class method for processing

Former Member
0 Likes
533

Hi guys,

I'm trying to pass an internal table from a report to a class method so that it can be processed and converted to binary content for sending as an email attachment in Excel format.

Before converting to binary content the internal table must be looped through and have tabs and carriage returns inserted betweens fields and rows before appended to a string.

The problem is that I want to make this a generic method that can accept any type of internal table so the class can be used with any report.

I have searched on the forums and can't seem to find anything related to this.

Please help!

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
499

use field symbol.

search "dynamic internal table creation"

4 REPLIES 4
Read only

Former Member
0 Likes
500

use field symbol.

search "dynamic internal table creation"

Read only

0 Likes
499

I don't think there's any need for dynamic internal table creation. If I understand the OP correctly, the table is there, it's just a matter of passing it to a method, and then looping over the fields in each line. It is possible to have generic types for method parameters. Like so:

METHODS test
  IMPORTING
    it_mytable TYPE STANDARD TABLE .
   
     
METHOD test.
  DATA:
    lv_index TYPE i,
    lv_comp_as_string TYPE string.

  FIELD-SYMBOLS:
    <fs_line> TYPE ANY,
    <fs_comp> TYPE ANY.

  LOOP AT it_mytable ASSIGNING <fs_line>.
    lv_index = 1.
    DO.
      ASSIGN COMPONENT lv_index OF STRUCTURE <fs_line> TO <fs_comp>.
      IF sy-subrc <> 0.
        EXIT. " DO-loop
      ENDIF.
      " Convert field value to string. May generate runtime error.
      MOVE <fs_comp> TO lv_comp_as_string.
      " Do whatever you need to do with the string
    ENDDO.
  ENDLOOP.
ENDMETHOD. 

-- Sebastian

Read only

0 Likes
499

Hi Sebastian,

Your code has helped!

Thanks.

Read only

0 Likes
499

hi,

similar situation for me as well in my case i am concatenating all the fields to a string.

will the same logic works? i mean some times the field symbol( work area) may have 2 fields or 7 fields.

please suggest.thannks alot.

Anil