Application Development 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: 

access work area fields dynamically

Former Member
0 Kudos

Hi!

In my ABAP Report I'm uploading a csv file via function module. From that I get an internal table containing the rows as Strings which I have to split afterwards into the fields of the structure I'm using.

so what I do is something like:

loop at itab into wa.

  split wa-string at ';' into mystructure-field1 mystructure-field2 ... 

enloop.

my problem is that "mystructure" has 82 fields (BSIS). Do I really have to code all 82 field or is there an easier (faster) way to write that?

thanks,

Margit

1 ACCEPTED SOLUTION

valter_oliveira
Active Contributor
0 Kudos

Try SPLIT ... INTO TABLE. It will split each occurence into one record into this table. Then, you can LOOP at that table and dynamicaly assing the rows to your work area.

Regards,

Valter Oliveira.

6 REPLIES 6

valter_oliveira
Active Contributor
0 Kudos

Try SPLIT ... INTO TABLE. It will split each occurence into one record into this table. Then, you can LOOP at that table and dynamicaly assing the rows to your work area.

Regards,

Valter Oliveira.

0 Kudos

Check this example:


TYPES: BEGIN OF ty_data,
         string TYPE char255,
       END OF ty_data.

DATA: itab TYPE STANDARD TABLE OF ty_data.
DATA: fields TYPE STANDARD TABLE OF ty_data.
DATA: count TYPE i.
DATA: wa TYPE ty_data.
DATA: wa2 TYPE ty_data.
DATA: wa_bsis TYPE bsis.

FIELD-SYMBOLS: <fs> TYPE any.

wa-string = '100;INCM;20000001;...'. "mandt-bukrs-hkont-...
APPEND wa TO itab.

LOOP AT itab INTO wa.
  SPLIT wa-string AT ';' INTO TABLE fields.
  CLEAR count.
  LOOP AT fields INTO wa2.
    ADD 1 TO count.
    ASSIGN COMPONENT count OF STRUCTURE wa_bsis TO <fs>.
    <fs> = wa2-string.
  ENDLOOP.
  INSERT zbsis FROM wa_bsis.
ENDLOOP.

Regards,

Valter Oliveira.

Former Member
0 Kudos

Yes but than I have a table row for each value. What I need is to write the values into the structure (type BSIS) to insert the data into a ZBSIS dbtab afterwards.

regards

Former Member
0 Kudos

Try this:

  • Original Table

data: begin of t_tab occurs 0,

matnr type matnr,

etc..

end of t_tab.

  • Work Area with sequential column names

types: begin of wa_struct,

field1 type matnr,

field2 type xxxx,

etc..

end of wa_struct.

data: col_name(30).

field-symbols: <column_ref>. type any.

SPLIT string at ';' INTO TABLE t_split.

loop at t_split into wa_split.

concatenate 'WA_STRUCT-FIELD' sy-tabix into col_name.

condense col_name no-gaps.

assign (col_name) to <column_ref>.

<column_ref>. = wa_split.

endloop.

t_tab = wa_struct. "U can move data from one character area to other character area

append t_tab.

Thanks

Amol Lohade

Former Member
0 Kudos

Hi,

Here is an excerpt from the documentation :

Splits f wherever the separator g occurs and places the resulting sections into the fields h1 ... hn (n >= 2). Note that if g has type C, the field is used in its defined and not its occupied length.

The field is split using the following procedure: f is split internally into a set of target fields k1 to kn with the same type as f. These are then transferred into the actual target fields h1 to hn using MOVE semantics.

So I think , there is no way but to give all 82 fields.

regards,

Advait

Former Member
0 Kudos

Thanks Valter! That's what I was looking for...