Skip to Content

RTTS/RTTI/RTTC along with factory pattern

Oct 17, 2017 at 05:43 PM


avatar image
Former Member


I had a requirement for file upload and using the contents of the file for updating article master.

So I thought I would make it a little interesting by creating an abstract class which would take the file path and file type (along with the delimeter) and create a factory pattern by creating child classes(each of which would be for a specific location. Eg 1 subclass for handling files from AL11 and another subclass for files from local desktop).

As a part of this, I wanted to use RTTS, so that the application can return the contents of the file in the i/p format required by the application. So I started by doing the following.

1. Create a DDIC structure for the i/p file. This way every application that wants to use the reusable class, will first create a DDIC structure and pass the name of the structure to the main class.

2. The main class will determine which subclass to instantiate and get back the contents in the form of a string table.

3. The main class would then use RTTI using the name of the structure to create an internal table dynamically.

After all the necessary steps for ITAB creation is done, I have a data reference variable, go_tab.

Now, I want to loop thru the string table where the contents are comma separated( let's assume 3 columns a. MATNR b. COLOR c. VALUE eg: 12345,10,ABCD) and add them to my go_tab using a simple SPLIT statement.

data : go_data typre ref to data.

field-symbols: <fs_tab> type standard table.

ASSIGN : go_tab->* TO <fs_tab>.

DATA ref_wa TYPE REF TO data.

LOOP AT string_tab INTO lv_string.

SPLIT lv_string AT gv_delimeter INTO
ref_wa->satnr ref_wa->color


append ref_wa->* to <fs_tab>.


But the above split statement returns the error "You cannot dereference (->) a generic reference in the current statement". How do I move the contents from the lv_string into my dynamic internal table?Any help would be much appreciated.



10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Mike Pokraka Oct 17, 2017 at 06:02 PM

With create like ... a standard table, you have an unknown line type. So instead of

append ref_wa->* to <fs_tab>.


append initial line to <fs_tab> assigning field-symbol(<row>). 
<row> = ref_wa->*.
Show 6 Share
10 |10000 characters needed characters left characters exceeded
Former Member


The problem is with the split statement. I am not able to split the string delimited by a comma into respective columns of the table/work area.




Sorry, skim-read and missed the split bit, but I would expect it to complain about the append as well.

Nevertheless, it's the same issue as I described, the split target refers to fields that are unknown. You can only do this with field symbols.

I am not sure you even need the ref_wa. Just use the append statement above and split into <row>-satnr <row>-color etc.

Failing that you may need to hack about with individual components.

ASSIGN COMPONENT 'SATNR' of <row> to field-symbol(<satnr>).

and so on.

Former Member

Mike, can you please throw a little more light on the "individual components" part?

As a part of RTTS, I do have an internal table with the list of component names but please note that this list can change based on the client/application. I can have 1 application with a structure which has 10 fields and I can have another application with a structure which has 'n' fields.

With the above in mind can you suggest how to get the data separated by ',' into my dynamic internal table? A code snapshot would really help if you have the time.




Well, assuming you’ve got the itab creation part done (as you say), then you just need to loop over your fields.

I don’t have any code or system handy, but to give you an idea:

field symbol <itab> type standard table. 
assign table_ref->* to <itab>.
loop at <source_strings> assigning field-symbol(<source_row>).
  “...split your string into a table source_fields, then:
  append initial line to <itab> assigning field-symbol(<target_row>).
  loop at field_list into data(fieldname). 
    assign component (fieldname) of structure <target_row> to field_symbol(<target_field>). 
    <target_field> = source_fields[ sy-tabix ].
Former Member

Mike, I have a couple of questions:

1. “...split your string into a table source_fields, then:

This is where I have the issue as the line type while using the split can be different for every calling application.

Below is the code that I till now and need some help completing the same.

The calling application uses and i/p structure that as 3 fields( Another application that calls this class can have different input structure and different # of fields).




I have a table of type string within which I have a record


I create an internal table dynamically using RTTI/RTTC.

The variable go_tab refers to the dynamic itab.

the table comp_tab has the list of components returned from get_components of cl_abap_structdescr. This has the 3 columns SATNR,COLOR,VALUE

the table stringtab contains a single record `908765,COLOR1,XYZ`

I need to split the string at ',' into the columns SATNR, COLOR and VALUE

code lines.

assign go_tab->* to <fs_tab> (<fs_tab> is type standard table)

loop stringtab into string.
" How do I split the contents of string into components:
VALUE (I cant use a static type since this structure will be different based on the calling aplication)

" Once split how do I move the data into <fs_tab>


any and all help would be much appreciated.




You misunderstood. The comment line meant ‘insert your own procedure here to perform your split’.

In other words, split each line into generic fields whichever way you like (remember we are inside the loop at this point). The easiest way for me, and the way I assumed in my example, would be to split into a simple table of strings. So you go from


To an itab source_fields containing rows




The code that follows the comment is to put the generic field contents into named fields of a defined structure. The outer loop processes each row, and the inner loop processes each field.

Horst Keller
Oct 20, 2017 at 07:01 PM

Simply assign ref_wa->* to a field symbol and append that. This is a kind of ridiculous but documented.

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

HK, I am not sure if I understand this correctly. Below is a screen shot of the data that I am working with.

data :go_tab type ref to data. " dynamically created table 

field-symbols: <fs_tab> type standard table.

assign go_tab->* to <fs_tab>

loop at string_tab into lv_string.

append initial line to <fs_tab> assigning <fs_line>.
" contents of lv_string = 'article1,color1,value1"
" Cannot use a split statement here since the target structure can vary by the calling application
" Hence will use a find statement and assume the I will adjust strign after every find.

loop at comp_tab in
clear: temp_data, gv_len.
FIND ',' IN lv_string MATCH OFFSET gv_len.
temp_data = lv_string+0(gv_len).

" Question - How do I move the contents of temp_data to the 1st component of <fs_line> in the first loop of comp_tab and so on so forth.


capture.jpg (33.9 kB)