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

Move Fm To Class Method

Former Member
0 Likes
2,217

Hi,

i want to copy Fm that i use to Method and build Class and i need help because i new in this topic.

i wont to build global class in se24

from my code below ,what is recommended for using attributes,and where to put the types (of table)?

TYPES: BEGIN OF t_costcenter,
         nodeid TYPE  rshienodid,
         iobjnm  TYPE rsiobjnm,
         nodename TYPE   rsshnodename,
         tlevel TYPE  rstlevel,
         link  TYPE rslink,
         parentid  TYPE rsparent,
         childid  TYPE rschild,
          nextid  TYPE rsnext,
    END OF t_costcenter.


  DATA: cost_id TYPE TABLE OF t_costcenter .
  FIELD-SYMBOLS: <fs_id> LIKE LINE OF cost_id .
  DATA: wa_cost_id LIKE LINE OF cost_id.

  LOOP AT node_tab ASSIGNING <fs_node>.
    SELECT SINGLE *
      FROM /bi0/hcostcenter
      INTO CORRESPONDING FIELDS  OF wa_cost_id
      WHERE nodename = <fs_node>-znodename .
    IF sy-subrc = 0.
      APPEND wa_cost_id TO cost_id.
      CLEAR wa_cost_id.
    ENDIF.
  ENDLOOP.

Regards

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,172

Hi Cosmo,

You need to declare the internal tables in the implementation of the class in SE19.

In the implementation, one cannot declare an internal table with header line and hence you need to declare the

internal table with types.

Example of declaring an internal table is :

TYPES : BEGIN OF ty_kunnr,

kunnr TYPE knvv-kunnr,

END OF ty_kunnr.

DATA :tb_kunnr TYPE TABLE OF ty_kunnr,

wa_kunnr TYPE ty_kunnr.

Thanks and Regards,

Sriranjani Chimakurthy.

Hi,

i want to copy Fm that i use to Method and build Class and i need help because i new in this topic.

i wont to build global class in se24

from my code below ,what is recommended for using attributes,and where to put the types (of table)?

TYPES: BEGIN OF t_costcenter,
         nodeid TYPE  rshienodid,
         iobjnm  TYPE rsiobjnm,
         nodename TYPE   rsshnodename,
         tlevel TYPE  rstlevel,
         link  TYPE rslink,
         parentid  TYPE rsparent,
         childid  TYPE rschild,
          nextid  TYPE rsnext,
    END OF t_costcenter.


  DATA: cost_id TYPE TABLE OF t_costcenter .
  FIELD-SYMBOLS: <fs_id> LIKE LINE OF cost_id .
  DATA: wa_cost_id LIKE LINE OF cost_id.

  LOOP AT node_tab ASSIGNING <fs_node>.
    SELECT SINGLE *
      FROM /bi0/hcostcenter
      INTO CORRESPONDING FIELDS  OF wa_cost_id
      WHERE nodename = <fs_node>-znodename .
    IF sy-subrc = 0.
      APPEND wa_cost_id TO cost_id.
      CLEAR wa_cost_id.
    ENDIF.
  ENDLOOP.

Regards

19 REPLIES 19
Read only

Former Member
0 Likes
2,172

Hi Cosmo,

the signaturer of a method and a class are rather similar. The biggest difference are indeed the tables.

You could add them as changing parameters.

When creating a global class, it might make sense to use global DDIC-datatypes for the structures and tables as well.

Kind regards,

Silke

Read only

0 Likes
2,172

Hi Silke Eng ,

thanks , u say that i have to use the table t_costcenter in global Structure , but what if i have to use internal tables where i put the declaration of it in calss?

i now that in FM i do that in the top.

Regards

TYPES: BEGIN OF t_costcenter,

nodeid TYPE rshienodid,

iobjnm TYPE rsiobjnm,

nodename TYPE rsshnodename,

tlevel TYPE rstlevel,

link TYPE rslink,

parentid TYPE rsparent,

childid TYPE rschild,

nextid TYPE rsnext,

END OF t_costcenter.

Read only

0 Likes
2,172

Hi Cosmo,

Did I get that right: you want to create a global class in TA se24? Or is the goal to create a local class?

i wont to build global class in se24

Silke

Read only

0 Likes
2,172

..in the case of global classes:

In the class builder there is a "card" called "Types". Enter the name of the type and click on the yellow arrow, that will lead you to the coding area for entering types for this class. Silke

Read only

0 Likes
2,172

Hi Silke Eng ,

Thanks,

types i now that i declare in types tab in se24,

my question is where i have to declare the internal tables.

Regards

Read only

0 Likes
2,172

The internatl table can be declared as an attribute of the class. Is it that what you meant? Silke

Read only

0 Likes
2,172

Hi Silke Eng ,

Are u sure ?

how i do that.

Regards

Read only

0 Likes
2,172

In the class builder -> card "attributes"

GT_YOUR_INTERNAL_TABLE Instance Attribute Protected Type YOURDECLARED_TAB_TYPE

The table type needs to be declared in the card "types" if it is not a global datatype.

Example:

YOURDECLARED_TAB_TYPE type sorted table of YOURDECLARED_TYPE

with unique key YOURKEY.

Read only

0 Likes
2,172

Hi Silke Eng ,

Thanks for all your replays u helping me a lot.

i new to oo in abap so plz maybe u can give me example how to declare this simple internal table in se 24

step by step.

types : begin of emp_tab,
           pernr type pernr_d,
           employee_name type char20,
           employee_id type numc9,
          end of emp_tab.

data: employee_table type table of emp_tab." in fm or progarm i declare internal table  like this.

Best Regards

Read only

0 Likes
2,172

>

>

types : begin of emp_tab,
>            pernr type pernr_d,
>            employee_name type char20,
>            employee_id type numc9,
>           end of emp_tab.
> 
> data: employee_table type table of emp_tab." in fm or progarm i declare internal table  like this.

If you want to use the internal tables in a global class I suggest you create the structures and tabletypes in the dictionary and not just locally in the class type definitions.

Otherwise, all you are missing is an addtional type for the table.

types: tt_empl_tab type standard table of emp_tab.
data: lt_emploqyee type tt_empl_tab.

Read only

Former Member
0 Likes
2,173

Hi Cosmo,

You need to declare the internal tables in the implementation of the class in SE19.

In the implementation, one cannot declare an internal table with header line and hence you need to declare the

internal table with types.

Example of declaring an internal table is :

TYPES : BEGIN OF ty_kunnr,

kunnr TYPE knvv-kunnr,

END OF ty_kunnr.

DATA :tb_kunnr TYPE TABLE OF ty_kunnr,

wa_kunnr TYPE ty_kunnr.

Thanks and Regards,

Sriranjani Chimakurthy.

Read only

0 Likes
2,172

Hi Sriranjani ,

thanks ,

se19 i badi builder how i buield thier internal table? and how i link it to class?

Regards

Read only

0 Likes
2,172

When you create a Badi Implementation, the only thing that would make sense is to declare your internal table in the method you are using. Look at previous posts on how to do that.

If this Badi has more than one methods and you are planning on using them all (or at least more than one), it might be better to declare your internal table in the implementing class. How to declare an internal table in a class is also explained in one of the previous posts.

Read only

0 Likes
2,172

Hi Micky,

Thanks but i don't wont to build Badi,

i wont to Build Class in SE24 and i wont to now where and how i declare internal table e.g. like this.

types : begin of emp_tab,
           pernr type pernr_d,
           employee_name type char20,
           employee_id type numc9,
          end of emp_tab.
 
data: employee_table type table of emp_tab." in fm or progarm i declare internal table  like this in the *top* .

Regards

Read only

0 Likes
2,172

thanks ,

se19 i badi builder how i buield thier internal table? and how i link it to class?

Isn't that what you were asking the last time: SE19 and BadI builder? The rest was already explained in the previous posts, right? Or is there still something you don't quite understand?

Read only

0 Likes
2,172

Hi Micky,

Thanks but Sriranjani Chim in post before suggest to do it in se19 so i ask him how?

this is what he write :

You need to declare the internal tables in the implementation of the class in SE19.

In the implementation, one cannot declare an internal table with header line and hence you need to declare the

internal table with types.

Example of declaring an internal table is :

TYPES : BEGIN OF ty_kunnr,

kunnr TYPE knvv-kunnr,

END OF ty_kunnr.

DATA :tb_kunnr TYPE TABLE OF ty_kunnr,

wa_kunnr TYPE ty_kunnr.

Read only

0 Likes
2,172

I also posted a reply on your other message in which I am asking you to tell us a bit more about your requirement. That wil be the only way in which we will be able to help you. Declaring an internal table within a method is possible, but in that case you can only use it within this particular method (it is declared locally like for example in a subroutine PERFORM / FORM).

In this case you can just use the types statement, like mentioned before and declare the internal table typing that TYPES. If you were to copy the following coding into a method (so declaring it locally in the method itself) it will work:

TYPES : BEGIN OF ty_kunnr,

kunnr TYPE knvv-kunnr,

END OF ty_kunnr.

DATA :tb_kunnr TYPE TABLE OF ty_kunnr,

wa_kunnr TYPE ty_kunnr.

But like I said, it will only be available in this method.

Read only

0 Likes
2,172

Thanks Micky,

This is the Recommended way to do that,locally?

Regards

Read only

0 Likes
2,172

I'm not saying this is recommended, but if you only want to use it locally within the method, than I would recommend it. If however you want to use it more often (in several methods) you should declare it as a local type. If however you want to use it to call methods from outside the class (just like calling a FM) you have to declare it globally in SE11.

Tell me how you want to use it?