‎2008 Dec 15 6:42 PM
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
‎2008 Dec 15 6:48 PM
Hi there
DATA : gt_fee TYPE standard table of tt_fee.and try to use
data: wa_fee type gt_fee.
‎2008 Dec 15 6:47 PM
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.
‎2008 Dec 15 6:48 PM
Hi there
DATA : gt_fee TYPE standard table of tt_fee.and try to use
data: wa_fee type gt_fee.
‎2008 Dec 15 7:27 PM
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
‎2008 Dec 16 3:47 PM
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