Code: Alles auswählen.
DATA: file_path TYPE string VALUE
'/usr/sap/trans/tmp/test123.pdf'.
OPEN DATASET file_path FOR OUTPUT IN BINARY MODE.
IF sy-subrc = 0.
TRANSFER gv_xpdf TO file_path.
ENDIF.
CLOSE DATASET file_path.
Folgende Benutzer bedankten sich beim Autor Lukas Sanders für den Beitrag:
STDIN
Code: Alles auswählen.
METHOD file_write_bin.
DATA l_len TYPE i.
DATA l_all_lines_len TYPE i.
DATA l_diff_len TYPE i.
DATA l_subrc LIKE sy-subrc.
DATA rc TYPE sy-subrc.
DATA ls_data TYPE solix.
DATA e_file_size TYPE drao-orln.
DATA i_lines TYPE i.
DATA i_file TYPE rcgiedial-iefile.
i_file = file.
* check if file exists if we arn't allowed to overwrite file
IF i_file_overwrite = ' '. " apap_FALSE'.
CLEAR l_subrc.
CATCH SYSTEM-EXCEPTIONS open_dataset_no_authority = 1
dataset_too_many_files = 2
OTHERS = 4.
OPEN DATASET i_file FOR INPUT IN BINARY MODE.
l_subrc = sy-subrc.
ENDCATCH.
IF l_subrc <> 0.
* nothing
ELSE.
CATCH SYSTEM-EXCEPTIONS OTHERS = 4.
CLOSE DATASET i_file.
ENDCATCH.
RAISE ap_file_exists.
ENDIF.
CATCH SYSTEM-EXCEPTIONS OTHERS = 4.
CLOSE DATASET i_file.
ENDCATCH.
ENDIF.
i_lines = lines( data ).
* open dataset for writing
OPEN DATASET i_file FOR OUTPUT IN BINARY MODE.
IF NOT sy-subrc IS INITIAL.
RAISE open_failed.
ELSE.
l_len = lg_max_len.
LOOP AT data INTO ls_data.
* last line is shorter perhaps
IF sy-tabix = i_lines.
l_all_lines_len = lg_max_len * ( i_lines - 1 ).
l_diff_len = i_file_size - l_all_lines_len.
l_len = l_diff_len.
ENDIF.
* write data in file
CATCH SYSTEM-EXCEPTIONS dataset_write_error = 1
OTHERS = 4.
TRANSFER ls_data TO i_file LENGTH l_len.
ENDCATCH.
IF NOT sy-subrc IS INITIAL.
RAISE write_failed.
ENDIF.
ENDLOOP.
ENDIF.
* close the dataset
CATCH SYSTEM-EXCEPTIONS dataset_cant_close = 1
OTHERS = 4.
CLOSE DATASET i_file.
ENDCATCH.
IF NOT sy-subrc IS INITIAL.
RAISE close_failed.
ENDIF.
ENDMETHOD.