Upload PDF from Application Server(AL11)

If you wish to upload the pdf file from AL11 you can refer the below code which will be helpful.

DATA : lv_dir_name TYPE eps2filnam,
lv_vbeln TYPE vbrk-vbeln,
lv_fname TYPE eps2filnam,
ls_list TYPE eps2fili,
ls_drao TYPE drao,
lt_drao TYPE TABLE OF drao,
lt_dir_list TYPE TABLE OF eps2fili.

TYPES: BEGIN OF hex_record,
field(1024) TYPE x,
END OF hex_record.

DATA: lt_tab_ex2 TYPE STANDARD TABLE OF hex_record WITH HEADER LINE.

TYPES: BEGIN OF zst_ts_raw_line,
line(2550) TYPE x,
END OF zst_ts_raw_line.

DATA : lv_pdf_str TYPE xstring, “PDF String of Form
lv_bin_l TYPE i, “Binary Length
ls_bintab TYPE zst_ts_raw_line, “needed for HTTP response
lt_bintab TYPE TABLE OF zst_ts_raw_line.

lv_dir_name = ‘\usr\sap\foldername’.

CALL FUNCTION ‘EPS2_GET_DIRECTORY_LISTING’
EXPORTING
iv_dir_name = lv_dir_name

  • FILE_MASK = ‘ ‘
  • IMPORTING
  • DIR_NAME =
  • FILE_COUNTER =
  • ERROR_COUNTER =
    TABLES
    dir_list = lt_dir_list
    EXCEPTIONS
    invalid_eps_subdir = 1
    sapgparam_failed = 2
    build_directory_failed = 3
    no_authorization = 4
    read_directory_failed = 5
    too_many_read_errors = 6
    empty_directory_list = 7
    OTHERS = 8.

LOOP AT lt_dir_list INTO ls_list.
CONCATENATE lv_dir_name ‘\’ ls_list-name INTO lv_fname.

lv_vbeln = ls_list-name+0(10). “Invoice Number

OPEN DATASET lv_fname FOR INPUT IN BINARY MODE.
IF sy-subrc EQ 0.
DO.
READ DATASET lv_fname INTO lt_tab_ex2-field.
IF sy-subrc EQ 0.
APPEND lt_tab_ex2.
ELSE.
APPEND lt_tab_ex2.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET lv_fname.

BREAK-POINT.

lv_bin_l = ls_list-size.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
  EXPORTING
    input_length = lv_bin_l
  IMPORTING
    buffer       = lv_pdf_str
  TABLES
    binary_tab   = lt_tab_ex2
  EXCEPTIONS
    failed       = 1
    OTHERS       = 2.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
  EXPORTING
    buffer        = lv_pdf_str           "ls_pdf_file-pdf
  IMPORTING
    output_length = lv_bin_l
  TABLES
    binary_tab    = lt_bintab.

LOOP AT lt_bintab INTO ls_bintab.
  CLEAR ls_drao.
  ls_drao-orblk = ls_bintab-line.
  ls_drao-orln = lv_bin_l.
  APPEND ls_drao TO lt_drao.
ENDLOOP.

ENDIF.
ENDLOOP.

Leave a Reply

Your email address will not be published. Required fields are marked *