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

Split Into Table

Former Member
0 Likes
1,715

Hello,

how can i append data into internal table when spliting a record ?

The following code gets me an error : gt_fee has no header line, if i do not append only the las line stays inside the itab.

I tried doing it with a work area but couldn't make it work

TYPES : BEGIN OF ts_fee,
          date	TYPE	zz_date	,
          id_prod	TYPE	zz_id_	,
          id_abonne	TYPE	bu_id_number	,
          code_postal	TYPE	post_code	,
          .......
  END OF ts_fee.
TYPES : tt_fee TYPE TABLE OF ts_fee.
DATA : gt_fee TYPE tt_fee.
DATA : wa_fee LIKE LINE OF gt_fee.

OPEN DATASET file FOR INPUT IN TEXT MODE ENCODING DEFAULT.

DO.
  READ DATASET file INTO ligne.
  IF sy-subrc = 0.
    SPLIT ligne AT ';' INTO table gt_fee.
    append gt_fee.
    ASSIGN gt_fee TO <fs_fee>.
  ELSE.
    EXIT.
  ENDIF.
ENDDO.
CLOSE DATASET file.

Thanks for your help.

Tom

Edited by: Matt on Dec 15, 2008 8:17 PM changed title

1 ACCEPTED SOLUTION
Read only

former_member156446
Active Contributor
0 Likes
949

Hi there

DATA : gt_fee TYPE standard table of tt_fee.

and try to use

data: wa_fee type gt_fee.

4 REPLIES 4
Read only

former_member194669
Active Contributor
0 Likes
949

Try this way


DO.
  READ DATASET file INTO ligne.
  IF sy-subrc = 0.
    SPLIT ligne AT ';' INTO table gt_fee.
    append gt_fee to tt_fee. "<<<<<< ----
    ASSIGN gt_fee TO <fs_fee>.
  ELSE.
    EXIT.
  ENDIF.
ENDDO.

Read only

former_member156446
Active Contributor
0 Likes
950

Hi there

DATA : gt_fee TYPE standard table of tt_fee.

and try to use

data: wa_fee type gt_fee.

Read only

0 Likes
949

Tables with header lines has been seen by SAP, in the last ten years, to be very bad programming practice - this is why it isn't allowed in Object Oriented contexts. It seems to me that you are getting confused because you are used to tables with header lines. Do yourself a favour and totally forget about tables with header lines.

TYPES : BEGIN OF ts_fee,
          date	TYPE	zz_date	,
          id_prod	TYPE	zz_id_	,
          id_abonne	TYPE	bu_id_number	,
          code_postal	TYPE	post_code	,
          .......
  END OF ts_fee.  " You've now defined a structure type

TYPES : tt_fee TYPE TABLE OF ts_fee. " You've now defined a type that is a table of your structure

DATA : gt_fee TYPE tt_fee. "  Now you have a variable that is a table
DATA : wa_fee LIKE LINE OF gt_fee. " Now you have a work area - its type is like  record of the table
 
OPEN DATASET file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
 
DO.
  READ DATASET file INTO ligne.
  IF sy-subrc = 0.
    SPLIT ligne AT ';' INTO table gt_fee. " You've split the ligne, so each field is a seperate RECORD of gt_fee
    append gt_fee.  " gt_fee is a TABLE, what are you wanting to append it to?
    ASSIGN gt_fee TO <fs_fee>.
  ELSE.
    EXIT.
  ENDIF.
ENDDO.
CLOSE DATASET file.

You must go and READ the F1 help on SPLIT ... AT ... INTO TABLE... see what type the table should have. It's really really important to know and understand at all times what the structure of your data is. Try to visualise it.

If you've split "ligne" into a table, then you'll have to loop through that table to find out what the value of each field on that line is. Before you continue with this problem, read the F1 Help, the ABAP HELP on SPLIT, and play around with the command. Until you understand how it works, fully, don't try to fix your problem.

matt

Read only

0 Likes
949

Thanks,

i allready looked at the F1 Help but while testing the split instruction i understood that it was spliting my line in several table lines and not columns as i thought