Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

PDF RAW data to SAP printer

Former Member
0 Kudos

Hi All,

I have RAW data in my internal table and I can download the data to my PC and save it as PDF . I can send the RAW data as an Email Attachment .

The other Option I need to do is I need to Print the RAW data .

The Options that I have tried.

1)  I tried using F/M RSPO_SX_OUTPUT_DEVICEDATA  it printed the data to printer where the Borders are not coming and the Log is not coming entirely. and the 2nd Page with terms and conditions is coming junk.

2) Used the Function Module ADS_SR_OPEN, ADS_GET_PATH , ADS_SR_CONFIRM and ADS_SR_CLOSE where the output is same as above . But when I go to SP01 to see the spool , I can see the PDF looking correctly but print is not coming .

3) Download the file to Fronted on the PC and used  CL_GUI_FRONTEND_SERVICES=>EXECUTE to print , it printed both the pages correctly but again the Borders are gone and Logo is not complete.

Now when I down load the raw data to front end and if I open that PDF and give it to printer then its working fine.

Now I want your help in printing this RAW data to the printer . As said options above are already tried. So please suggest me with your help and opinions.

Thanks

Venkat.

2 REPLIES 2

Former Member
0 Kudos

Hi ,

Just wanted to know if any one has come across this requirement or have done this type of requirements.

If there are any recommendations it should be great.

Thanks & Regards,

Venkat.

0 Kudos

REPORT  ZTEST.
TYPE-POOLS: abap, srmgs.

PARAMETERS: p_prnds LIKE tsp01-rqdest OBLIGATORY DEFAULT 'LOCL',
            p_fname TYPE file_table-filename OBLIGATORY LOWER CASE,
            p_ncopi TYPE rspocopies OBLIGATORY DEFAULT '1',
            p_immed AS CHECKBOX.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.

  DATA: lv_rc     TYPE i,
        lv_filter TYPE string.

  DATA: lt_files TYPE filetable.
  FIELD-SYMBOLS: <fs_file> LIKE LINE OF lt_files.

  CONCATENATE 'PDF (*.pdf)|*.pdf|' cl_gui_frontend_services=>filetype_all INTO lv_filter.

  CALL METHOD cl_gui_frontend_services=>file_open_dialog

    EXPORTING

      file_filter             = lv_filter

    CHANGING

      file_table              = lt_files

      rc                      = lv_rc

    EXCEPTIONS

      OTHERS                  = 1.

  IF sy-subrc NE 0 AND lv_rc EQ 0.

    MESSAGE 'Error' TYPE 'E' DISPLAY LIKE 'S'.

  ENDIF.

  READ TABLE lt_files ASSIGNING <fs_file> INDEX 1.

  IF sy-subrc EQ 0.

    p_fname = <fs_file>-filename.

  ENDIF.



AT SELECTION-SCREEN.



  DATA: lv_name   TYPE string,

        lv_result TYPE boolean.



  lv_name = p_fname.

  CALL METHOD cl_gui_frontend_services=>file_exist

    EXPORTING

      file                 = lv_name

    RECEIVING

      result               = lv_result

    EXCEPTIONS

      OTHERS               = 1.

  IF sy-subrc NE 0.

    MESSAGE 'Bad file!' TYPE 'E' DISPLAY LIKE 'S'.

  ENDIF.



  IF lv_result NE abap_true.

    MESSAGE 'Bad file!' TYPE 'E' DISPLAY LIKE 'S'.

  ENDIF.



START-OF-SELECTION.



END-OF-SELECTION.



  PERFORM process.



FORM process.



  DATA: lv_name     TYPE string,

        lv_size     TYPE i,

        lv_data     TYPE xstring,

        lv_retcode  TYPE i.



  DATA: lt_file TYPE srmgs_bin_content.



  lv_name = p_fname.

  CALL METHOD cl_gui_frontend_services=>gui_upload

    EXPORTING

      filename                = lv_name

      filetype                = 'BIN'

    IMPORTING

      filelength              = lv_size

    CHANGING

      data_tab                = lt_file

    EXCEPTIONS

      OTHERS                  = 1.

  IF sy-subrc NE 0.

    MESSAGE 'Read file error!' TYPE 'E' DISPLAY LIKE 'S'.

  ENDIF.



  CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'

    EXPORTING

      input_length = lv_size

    IMPORTING

      buffer       = lv_data

    TABLES

      binary_tab   = lt_file

    EXCEPTIONS

      failed       = 1

      OTHERS       = 2.

  IF sy-subrc NE 0.

    MESSAGE 'Binary conversion error!' TYPE 'E' DISPLAY LIKE 'S'.

  ENDIF.



  PERFORM print USING p_prnds lv_data CHANGING lv_retcode.

  IF lv_retcode EQ 0.

    WRITE: / 'Print OK' COLOR COL_POSITIVE.

  ELSE.

    WRITE: / 'Print ERROR' COLOR COL_NEGATIVE.

  ENDIF.



ENDFORM.                    " PROCESS

FORM print USING    iv_prndst  TYPE rspopname

                    iv_content TYPE xstring

           CHANGING ev_retcode TYPE i.



  DATA: lv_handle    TYPE sy-tabix,

        lv_spoolid   TYPE rspoid,

        lv_partname  TYPE adspart,

        lv_globaldir TYPE text1024,

        lv_dstfile   TYPE text1024,

        lv_filesize  TYPE i,

        lv_pages     TYPE i.



  CLEAR: ev_retcode.



  CALL FUNCTION 'ADS_SR_OPEN'

    EXPORTING

      dest            = iv_prndst

      doctype         = 'ADSP'

      copies          = p_ncopi

      immediate_print = p_immed

      auto_delete     = 'X'

    IMPORTING

      handle          = lv_handle

      spoolid         = lv_spoolid

      partname        = lv_partname

    EXCEPTIONS

      OTHERS          = 1.

  IF sy-subrc NE 0.

    ev_retcode = 4.

    RETURN.

  ENDIF.



  CALL FUNCTION 'ADS_GET_PATH'

    IMPORTING

      ads_path = lv_globaldir.



  CONCATENATE lv_globaldir '/' lv_partname '.pdf' INTO lv_dstfile.



  OPEN DATASET lv_dstfile FOR OUTPUT IN BINARY MODE.

  IF sy-subrc NE 0.

    ev_retcode = 4.

    RETURN.

  ENDIF.



  TRANSFER iv_content TO lv_dstfile.

  IF sy-subrc NE 0.

    ev_retcode = 4.

    RETURN.

  ENDIF.



  CLOSE DATASET lv_dstfile.

  IF sy-subrc NE 0.

    ev_retcode = 4.

    RETURN.

  ENDIF.



*  CALL FUNCTION 'ZBAP_RM_PDF_GET_PAGES'

*    EXPORTING

*      iv_content = iv_content

*    IMPORTING

*      ev_pages   = lv_pages.

  perform zbap_rm_pdf_get_pages using iv_content

                                changing lv_pages.



  lv_filesize = XSTRLEN( iv_content ).

  CALL FUNCTION 'ADS_SR_CONFIRM'

    EXPORTING

      handle   = lv_handle

      partname = lv_partname

      size     = lv_filesize

      pages    = lv_pages

      no_pdf   = ' '

    EXCEPTIONS

      OTHERS   = 1.

  IF sy-subrc NE 0.

    ev_retcode = 4.

    RETURN.

  ENDIF.



  CALL FUNCTION 'ADS_SR_CLOSE'

    EXPORTING

      handle = lv_handle

    EXCEPTIONS

      OTHERS = 1.

  IF sy-subrc NE 0.

    ev_retcode = 4.

    RETURN.

  ENDIF.



ENDFORM.                    " PRINT



form zbap_rm_pdf_get_pages  using iv_content

                            changing ev_pages .



DATA: lv_cont  TYPE string,

        lv_lines TYPE i,

        lv_pages TYPE numc5,

        lv_temp  TYPE string.



  DATA: lt_result TYPE match_result_tab.



  FIELD-SYMBOLS: <fs_result> LIKE LINE OF lt_result,

                 <fs_subm>   LIKE LINE OF <fs_result>-submatches.



  ev_pages = 0.



  CALL 'ICT_DISPATCH' ID 'did'    FIELD 'append_xstring_to_string'

                      ID 'source' FIELD iv_content

                      ID 'dest'   FIELD lv_cont.



  FIND REGEX `/N (.{1,5})/` IN lv_cont IGNORING CASE RESULTS lt_result.

  IF sy-subrc NE 0.

    FIND ALL OCCURRENCES OF REGEX `/count (.{1,4})/` IN lv_cont IGNORING CASE RESULTS lt_result.

  ENDIF.

  lv_lines = LINES( lt_result ).

  IF lv_lines IS NOT INITIAL.

    READ TABLE lt_result ASSIGNING <fs_result> INDEX lv_lines.

    IF sy-subrc EQ 0.

      READ TABLE <fs_result>-submatches ASSIGNING <fs_subm> INDEX 1.

      IF sy-subrc EQ 0.

        lv_temp = lv_cont+<fs_subm>-offset(<fs_subm>-length).

        CONDENSE lv_temp NO-GAPS.

        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

          EXPORTING

            input  = lv_temp

          IMPORTING

            output = lv_pages.

        ev_pages = lv_pages.

      ENDIF.

    ENDIF.

  ENDIF.



endform.