2010 Mar 17 4:46 AM
Ladies and Gentlemen,
I have a requiremet to pass (1 at a time) any number of tables into a reuseable method in a custom class. The Method code is as follows:
method CREATE_OUTBOUND_FILE.
*--------------------------------------------------------------------------------*
* Importing VALUE( IV_PATHNAME ) TYPE PATHEXTERN File Destination
* Importing VALUE( IT_FILE_RECORD ) TYPE REF TO DATA Table with Output
* Importing VALUE( IV_RECORD_STRUCTURE ) TYPE STRING OPTIONAL Record Structure
* Importing VALUE( IV_DELIMITER ) TYPE STRING File Delimiter
* Exporting VALUE( EV_RECORD_CNT ) TYPE STRING Record Count
*--------------------------------------------------------------------------------*
Data:
ls_line_cnt(6) type n,
lt_data_struc type zty_ddic_struc_T,
ls_string type string.
field-SYMBOLS: <fs_string> type any.
* Open Dataset for outputting file details
Open dataset iv_pathname for output in text mode encoding default.
Assign ls_string to <fs_string> CASTING TYPE (iv_record_structure).
loop at it_file_record into <fs_string>.
transfer <fs_string> to iv_pathname.
Add 1 to ls_line_cnt.
clear <fs_string>.
endloop.
ev_record_cnt = ls_line_cnt.
where IV_PATHNAME = output destination & filename
IT_FILE_REC = data table
IV_RECORD_STRUCTURE = is ddic structure definition for the data table
IV_DELIMITER = file delimiter, in this case, let's say it's C (for CSV)
and EV_RECORD_CNT is a count of numbe of records processed.
Lets say, for example, I wish to load data from table SFLIGHT into the method when program A is executed. Then another time I wish to excute Program B which is passing in data of table SFLCONN2. I hope that by using the "type ref to data" defintion, I can pass the table contents through. Is this true?
Secondly, I'm getting a syntax error saying that "IT_FILE_RECORD" is not defined as a table (and therefore can't be looped at), and therefore can't be read. How can I access the data in this table in preparation for output.
Any assistance or thoughts would be greatly appreciated.
Regards,
Steve
2010 Mar 17 5:08 AM
Hi Steve,
Yes you can do this.
I would change your interface to remove the IV_RECORD_STRUCTURE parameter and determine the structure of the table at runtime using Runtime Type Services (RTTS).
The reason that you are getting the syntax error is because IT_FILE_RECORD is defined as a reference to a data type, not a table itself.
You will probably need to assign the dereferenced parameter to a field symbol.
Something like..
FIELD-SYMBOLS: <table> TYPE ANY TABLE.
ASSIGN it_file_record->* to <table>.
LOOP AT <table> into <fs_string>.
...
ENDLOOP.I haven't tried this so apologies if you need to tweak the syntax.
Cheers
Graham Robbo
2010 Mar 17 5:08 AM
Hi Steve,
Yes you can do this.
I would change your interface to remove the IV_RECORD_STRUCTURE parameter and determine the structure of the table at runtime using Runtime Type Services (RTTS).
The reason that you are getting the syntax error is because IT_FILE_RECORD is defined as a reference to a data type, not a table itself.
You will probably need to assign the dereferenced parameter to a field symbol.
Something like..
FIELD-SYMBOLS: <table> TYPE ANY TABLE.
ASSIGN it_file_record->* to <table>.
LOOP AT <table> into <fs_string>.
...
ENDLOOP.I haven't tried this so apologies if you need to tweak the syntax.
Cheers
Graham Robbo
2010 Mar 19 4:02 PM
Hi Stephen ,
Graham already gve part of the solution.
If you declare
Importing VALUE( IT_FILE_RECORD ) TYPE REF TO DATAit does not make sense to declare to pass by VALUE because you will not change this refernce in the method. Calling this method, you must pass a refefernce.
data:
lr_ref type ref to data.
get reference of <your itab here> into lr_ref.
CREATE_OUTBOUND_FILE( ...IT_FILE_RECORD = lr_ref ... )In the method, it goes as graham explained.
Anyway, I would declare the table parameter as
Importing IT_FILE_RECORD TYPE TABLEThe your code could work, but you will have troube with any non-character fields in the tables.
Regards,
Clemens
2010 Jun 24 7:17 AM
Thank you all for your assistance. The secret was to build up the table using RTTC methods, then pass out to a parameter defined as 'any table'.