Skip to Content
avatar image
Former Member

RTTS/RTTI/RTTC along with factory pattern

Hi,

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.
CREATE DATA ref_wa LIKE LINE OF <FS_TAB>.

LOOP AT string_tab INTO lv_string.

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

ref_wa->value.

append ref_wa->* to <fs_tab>.

ENDLOOP.

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.

Thanks,

Vikram.M

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • 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>.

    try

    append initial line to <fs_tab> assigning field-symbol(<row>). 
    <row> = ref_wa->*.
    Add comment
    10|10000 characters needed characters exceeded

    • 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

      a,b,c

      To an itab source_fields containing rows

      a

      b

      c

      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.

  • 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.

    https://help.sap.com/http.svc/rc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abendata_reference_type.htm

    Add comment
    10|10000 characters needed 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.
      
      
      endloop.

      capture.jpg (33.9 kB)