‎2009 Sep 16 4:02 PM
Hello,
i want to create a program wich have as parameters :
The name of database table
The name of variant.
The program have to download data from this table with the variant specified and transfert the result to a server file.
Anybody know a FM wich takes the name of table and the variant in input and generate the data correspending of this on output.
Thanks,
‎2009 Sep 16 5:05 PM
Hi,
I suppose by "variant" you mean a WHERE condition to specify which data you want.
I don't know whether there is a standard function for this, but the thing is very easy to write. Here is a sample report (with just the basics, you'll have to add code to scure the server file, etc.):
REPORT zloadtab NO STANDARD PAGE HEADING.
PARAMETERS:
p_table TYPE tabname OBLIGATORY,
p_where TYPE char255,
p_file TYPE char128 LOWER CASE OBLIGATORY.
DATA:
reftab TYPE REF TO data,
condition TYPE string,
file_error TYPE string.
FIELD-SYMBOLS:
<t> TYPE ANY TABLE,
<line> TYPE ANY.
START-OF-SELECTION.
TRY.
CREATE DATA reftab TYPE STANDARD TABLE OF (p_table).
ASSIGN reftab->* TO <t>.
condition = p_where.
SELECT * FROM (p_table) INTO TABLE <t> WHERE (condition).
IF sy-dbcnt = 0.
MESSAGE s002(sy) WITH 'No qualifing records found'.
STOP.
ENDIF.
CATCH cx_sy_dynamic_osql_semantics.
MESSAGE i002(sy) WITH 'Wrong syntax in WHERE clause'.
STOP.
CATCH cx_sy_create_data_error.
MESSAGE i002(sy) WITH 'No such table exists'.
ENDTRY.
OPEN DATASET p_file FOR OUTPUT IN TEXT MODE
ENCODING DEFAULT MESSAGE file_error.
IF sy-subrc <> 0.
WRITE: / 'Cannot open:', p_file, / file_error.
STOP.
ENDIF.
LOOP AT <t> ASSIGNING <line>.
TRANSFER <line> TO p_file.
ENDLOOP.
CLOSE DATASET p_file.Have fun,
Mark
‎2009 Sep 16 5:05 PM
Hi,
I suppose by "variant" you mean a WHERE condition to specify which data you want.
I don't know whether there is a standard function for this, but the thing is very easy to write. Here is a sample report (with just the basics, you'll have to add code to scure the server file, etc.):
REPORT zloadtab NO STANDARD PAGE HEADING.
PARAMETERS:
p_table TYPE tabname OBLIGATORY,
p_where TYPE char255,
p_file TYPE char128 LOWER CASE OBLIGATORY.
DATA:
reftab TYPE REF TO data,
condition TYPE string,
file_error TYPE string.
FIELD-SYMBOLS:
<t> TYPE ANY TABLE,
<line> TYPE ANY.
START-OF-SELECTION.
TRY.
CREATE DATA reftab TYPE STANDARD TABLE OF (p_table).
ASSIGN reftab->* TO <t>.
condition = p_where.
SELECT * FROM (p_table) INTO TABLE <t> WHERE (condition).
IF sy-dbcnt = 0.
MESSAGE s002(sy) WITH 'No qualifing records found'.
STOP.
ENDIF.
CATCH cx_sy_dynamic_osql_semantics.
MESSAGE i002(sy) WITH 'Wrong syntax in WHERE clause'.
STOP.
CATCH cx_sy_create_data_error.
MESSAGE i002(sy) WITH 'No such table exists'.
ENDTRY.
OPEN DATASET p_file FOR OUTPUT IN TEXT MODE
ENCODING DEFAULT MESSAGE file_error.
IF sy-subrc <> 0.
WRITE: / 'Cannot open:', p_file, / file_error.
STOP.
ENDIF.
LOOP AT <t> ASSIGNING <line>.
TRANSFER <line> TO p_file.
ENDLOOP.
CLOSE DATASET p_file.Have fun,
Mark