Wednesday, December 21, 2011
SAP ABAP upload an include into any system ( insert report )
This one is really simple and trivial, but it is worth checking out.
It must be used very cautiosly, because it might cause a lot of harm.
But put in the right hands, specially when there is big trouble (no one to do a transport when your calc is abending at night and your pay date is affected by the delay etc) it can save you.
Dynamic code generation (insert report and generate subroutine pool) are a very powerful abap feature, and are really worth checking out.
For example we realized a consistency check on the payroll output which is fully customizable, and generateas validation rules in abap form directly from the customizing. I would like to write on that in a future post.
Here is the coding.
REPORT zupload_code .
PARAMETERS: pfile TYPE rlgrap-filename DEFAULT 'c:\code.txt'.
PARAMETERS: progr TYPE programm DEFAULT 'Z_CODE'.
TYPES t_code(72) TYPE c.
DATA lt_code TYPE TABLE OF t_code.
START-OF-SELECTION.
CALL FUNCTION 'HR_99S_UPLOAD'
EXPORTING
p_initial_directory = ''
p_filename = pfile
* DEFAULT_EXTENSION =
* P_FILETYPE_NO_SHOW = ' '
* P_FILETYPE = 'ASC'
p_fsdialog = ' '
* P_ITEM = ' '
* P_HAS_FIELD_SEPARATOR = ' '
* IMPORTING
* P_FILELENGTH =
TABLES
data_tab = lt_code
EXCEPTIONS
upload_error = 1
OTHERS = 2
.
IF sy-subrc <> 0.
WRITE: / 'Error in upload'.
EXIT.
ENDIF.
INSERT REPORT progr FROM lt_code.
IF sy-subrc <> 0.
WRITE: / 'Error in insert'.
EXIT.
ENDIF.