cancel
Showing results for 
Search instead for 
Did you mean: 

Exporting Tables from BSP to Class Methods

Former Member
0 Kudos

Afternoon Everybody,

in true SAP OSS Message style I post this question on it's own thread to enable maximum value from the reward points.

Question:

I have a BSP, in an event in my BSP I call a method in my class.

I have mastered Exporting parameters to the methods from the BSP and Importing parameters back to the BSP from the methods, but now, I need so Export a table to the method and I don't know how to.

Also, in combination with this, when I create the method I am able to setup the importing parameters, but how can create/define the importing table ?

If this is not clear I will add more info.

Thanks for your help,

Tomas.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Tomas,

first of all you have to create an Tabletyp

with help of the Transaction SE11. Use here the datatype-field and key in a name for your Tabletype and press create.Than choose tabletype. Now key in a short description and under linetype enter the name of the structure for your table.

(If you dont have a structure in the DDIC you can create it the same way you create the tabletype)

After that is finished you can create a new parameter for your method with refereing to your new created Tabletype.

Thats should be all

1.) Se11 ->field datatype ->enter name of your tabletype

2.) press create -> choose tabletype

3.) short description and name of the structure

4.) save

5.) create parameter for your method with "type my_new_table_type

Thorsten

Former Member
0 Kudos

Hi Thorsten,

thanks for your quick reply.

I don't think that is my problem.

I give some more information...

In my BSP I fill an internal table: ContentData with rows of data.

The internal table ContentData is derived from the dictionary table solisti1.

In my method I have the parameter:

TextFromBSP Importing Type Solisti1

In my BSP when I make the method call I try to have:

Class=>Method( TextFromBSP = ContentData ).

When I 'check' the BSP I get the message:

"ContentData" is not type-compatible with formal parameter "TextFromBSP".

I think I have done all that you describe.

If I break my text into three or four strings of 255 and pass those to String method importing parameters and then in the method append these strings to the internal table it works - but lacks flexibility hence my motivation and question to pass a table of data to the method.

Thanks,

Tomas.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

The problem here is that Solisti1 is a structure. You need a table type that uses Solisti1 as its structure.

If you do a where used on the structure Solisti1 and only search for table types you will find SWUOCONTTAB. This is the type for your parameter in your method.

I assume that when you defined ContentData you did the following or some slight variation of:

data: ContentData type table of Solisti1.

By doing this you are telling abap to create an internal table with a structure of Solisti1. However when you define a parameter in your method call you can't just specifiy type table of. Therefore a type of Solisti1 is just a flat one record structure. The table type SWUOCONTTAB really just predefines the same thing that the table of statement is doing.

Message was edited by: Thomas Jung

Former Member
0 Kudos

I think that there is no more to say.

Answers (3)

Answers (3)

former_member181879
Active Contributor
0 Kudos

Tomas,

The key to problem is always to learn a few "nice" things defined in the system. So let me see. The first problem you have is that methods are declared of the form:


method <parm> <direction> TYPE [REF TO] <t>
 
parm = the name of the paramter
direction = IMPORTING|EXPORTING|CHANGING|RETURNING
t = type of parm

However, in this type it is not possible to write that you want "type of table". You can only use predefined types (either internal or indictionary).

Having said this, most people with extensive ABAP experience before the OO-wave, tend to use character types all the time. However, we nearly always use only type string. And exactly for this type there is a type string_table.

So the code would be:


<u>Declaration:</u>
  method lines changing type string_table
 
<u>Calling:</u>
  DATA: t TYPE string_table.
  APPEND 'Hello' TO t.
  APPEND 'World' TO t.
  class=>method( CHANGING lines = t ).

<u>Method Implementation:</u>
  DATA: line LIKE LINE OF lines.
  LOOP AT lines INTO line.
    TRANSLATE line TO UPPER CASE.
    MODIFY lines FROM line. " write back
  ENDLOOP.

<u>Better Method Implementation (works directly on row):</u>
  FIELD-SYMBOLS: <line> LIKE LINE OF lines.
  LOOP AT lines ASSIGNING <line>.
    TRANSLATE <line> TO UPPER CASE.
  ENDLOOP.

These two types <b>string</b> and <b>string_table</b> goes a long way. The other two types that I often use are <b>ihttpvnp</b> and <b>Tihttpvnp</b> (table): they are good for name/value pairs of strings.

Now is the time that you should invest 30 minutes reading each time that you run into a problem. You have the framework, just check up on one aspect each time. (I usually use online help, for example to understand MODIFY for writing this text.)

rainer_liebisch
Contributor
0 Kudos

Hi Tomas,

at this point I can only advise to read a good book about this topic. Playing around with databases can be dangerous. It's not really difficult to create the database table, but you have different choices that have an influence on the size of the table and it's behaviour (and of course on the performance). You should know for example what a key column is. Stuff like this can increase (or decrease) the performance in factors of 10. You also have to define a structure and a table type (and you should know why you have to do this).

Regards,

Rainer

Oh, the answer tokk to long. Sorry.

Message was edited by: Rainer Liebisch

Former Member
0 Kudos

Hello Thomas and Thorsten,

many thanks for your input and answers, problem is indeed solved.

Rainer, you are correct, the amazing thing is it doesn't matter how many years we have all worked in the SAP field, everyday we can be humbled by just what we don't know.

I thank you all for your help, and continue on my journey.

Tomas.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Just don't get discouraged. I used to tell people that you can learn the ABAP syntax in a week, but it takes a year of actual coding experience to learn the ABAP environment (at least enough to not be dangerous anymore). And that was back in the pre-BSP/XML/OO days.

Those of us that have a few years under our belts sometimes tend to forget what we didn't know at one point and how painful it can be to get there.

Former Member
0 Kudos

no, no, I won't get discouraged though I try my best not to waste the time of your time served experts with my questions.

Re: your post above, I scanned your blog two or three times while trying to solve my problem to see if you had an example in there, but sometimes we can stare at something for hours without seeing what we are looking for.

Thank you again.

Soon I will make another little blog of top tips for BSP newbies in the area of interacting with OO Abap.

Tomas.

rainer_liebisch
Contributor
0 Kudos

Hi Tomas,

my last reply wasn't intended to discourage you. I have misunderstood your question and wanted to say that things like creating a db table are complex topics which can't be covered in detail in a thread (well, not really).

It's a good idea to write a blog with tips for newbies in ABAP OO. Your experiences are not restricted to BSP.

Regards,

Rainer

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Tables are no problem. I assume you mean ABAP Internal Tables. They pass in and out of method calls just like any other variable.

I generally create a table type in the data dictionary and use that as the type for my importing or exporting parameter.

Let's do a little exercise. Go to SE80. Hit the other Object button. Choose the dictionary tab. Then choose the Data Type Radio Button. In the input field next to the radio button type string_table. Now hit the display button.

What you should see is a very simple SAP Delivered Table type. This is just the definition for an internal table made up of lines of strings. You could have a more complex table type where you use a structure definition as the line type. But lets start with this simple table type first.

Now the easiest way to show you this is to point you to a weblog that I wrote the other day. Ignore what the weblog is actually about. Just focus on a few of the class methods that I showed in this weblog. These methods have importing and exporting parameters that are internal tables (specifically this string_table and one that I created).

/people/thomas.jung3/blog/2005/02/23/bsp-and-microsoft-excel--learning-to-live-together-part-2

At the beginning of each method I cut and past in the definition of the importing and exporting parameters. However if a screen shot would help, I can add it to the weblog for you.

It sounds like you are really getting into this ABAP OO stuff. Let me know if this helps or not.