Application Development and Automation 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: 
Read only

CONVERTING INTO PDF

Former Member
0 Likes
878

Hi All,

I need to convert a ALV GRID display in to PDF. Is it possible to convert an ALV GRID into PDF.

Display contains nearly 25 fields. so, pdf comverter is not accepting more than 132 characters.

If there is any possibileties. Please help me out.

Thanks in advance.

Regards,

HARISH

6 REPLIES 6
Read only

gouravkumar64
Active Contributor
0 Likes
832

Hi,

RSTXPDFT4 hope u know,this standard report.,here from spool u can convert to pdf,but leave it now.

with the help of function module

convert_abapspooljob_2_pdf u can do it.

then use gui_download.

Search for information.

there are many threads in ur question.

Hope it helps.

Thnaks

Gourav.

Read only

former_member195270
Active Participant
0 Likes
832

I think PDF convertor should accept 255 characters.check may be there will be space character inside.

Read only

Former Member
0 Likes
832

Hi Umar,

you are right, it will accept only 255 characters, but in grid display it is having more then that. Is it possible to convert it into PDF. My Requirement is to send this PDF file as an attachment to the vendors mail id.

Regards,

HARISH

Read only

0 Likes
832

It is possible to convert into PDF but if you have more than 255 characters then it will be difficult and you have to do some work around for that.

Read only

Former Member
0 Likes
832
Read only

Former Member
0 Likes
832

Hi Harish,

Try this code.

*---------------------------------------------------------------------*

* Declaration for Tables

*---------------------------------------------------------------------*

TABLES: mara,eban.

TYPES: BEGIN OF t_var,

        report  TYPE vari_reprt, " Report name

        variant TYPE variant,    " Variant name

       END OF t_var.

*---------------------------------------------------------------------*

* Declaration for Variables

*---------------------------------------------------------------------*

DATA: numbytes   TYPE i,

      lv_c_dev   TYPE sy-sysid,

      pdfspoolid LIKE tsp01-rqident,

      jobname    LIKE tbtcjob-jobname,

      jobcount   LIKE tbtcjob-jobcount,

      l_spool_c  LIKE tsp01_sp0r-rqid_char,

      spoolno    LIKE tsp01-rqident,

      lv_buffer  TYPE string,

      lv_subj    TYPE so_obj_des,

      tab_lines  TYPE sy-tabix,

      lv_valid   TYPE c,

      lv_spool   TYPE p,

      n          TYPE i.

*---------------------------------------------------------------------*

* Declaration of Structures

*---------------------------------------------------------------------*

DATA: x_pdf          TYPE tline,

      x_var          TYPE t_var,

      x_reclist      TYPE somlreci1,

      x_objbin_final TYPE solisti1,

      x_objtxt       TYPE solisti1,

      x_attachment   TYPE solisti1,

      x_mess_att     TYPE solisti1,

      x_docdata      TYPE sodocchgi1,

      x_objpack      TYPE sopcklsti1,

      x_params       TYPE pri_params,

      x_arcpar       TYPE arc_params.

*---------------------------------------------------------------------*

* Declaration for Internal tables

*---------------------------------------------------------------------*

DATA: it_pdf          TYPE TABLE OF tline,

      it_var          TYPE TABLE OF t_var,

      it_reclist      TYPE TABLE OF somlreci1,

      it_objbin_final TYPE TABLE OF solisti1,

      it_objpack      TYPE TABLE OF sopcklsti1,

      it_objtxt       TYPE TABLE OF solisti1,

      it_attachment   TYPE TABLE OF solisti1,

      it_mess_att     TYPE TABLE OF solisti1.

***********************************************************************

* P A R A M E T E R S - Input                                         *

***********************************************************************

PARAMETERS: p_pnam  TYPE rs38m-programm. " Report name

PARAMETERS: p_vari  TYPE varid-variant.  " Variant name

***********************************************************************

* AT SELECTION-SCREEN                                                 *

***********************************************************************

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vari.

  REFRESH: it_var.

  SELECT report

         variant

    FROM varid

    INTO TABLE it_var

    WHERE report = p_pnam.

  IF sy-subrc = 0.

    SORT it_var BY variant.

  ENDIF.

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'

    EXPORTING

      retfield    = 'VARIANT'

      dynpprog    = sy-cprog

      dynpnr      = sy-dynnr

      dynprofield = 'P_VARI'

      value_org   = 'S'

    TABLES

      value_tab   = it_var.

  IF sy-subrc <> 0.

    REFRESH: it_var.

  ENDIF.

***********************************************************************

* START-OF-SELECTION                                                  *

***********************************************************************

START-OF-SELECTION.

  CLEAR: x_params, lv_valid.

  CALL FUNCTION 'GET_PRINT_PARAMETERS'

    EXPORTING

      in_parameters          = x_params

      layout                 = 'X_657'

      line_count             = 65

      line_size              = 255

      no_dialog              = 'X'

    IMPORTING

      out_parameters         = x_params

      out_archive_parameters = x_arcpar

      valid                  = lv_valid

    EXCEPTIONS

      archive_info_not_found = 1

      invalid_print_params   = 2

      invalid_archive_params = 3

      OTHERS                 = 4.

  SUBMIT (p_pnam) TO SAP-SPOOL

    SPOOL   PARAMETERS x_params

    ARCHIVE PARAMETERS x_arcpar

    WITHOUT SPOOL DYNPRO

    USING SELECTION-SET p_vari AND RETURN.

  GET PARAMETER ID 'SPI' FIELD l_spool_c.

  CALL FUNCTION 'MOVE_CHAR_TO_NUM'

    EXPORTING

      chr             = l_spool_c

    IMPORTING

      num             = lv_spool

    EXCEPTIONS

      convt_no_number = 1

      convt_overflow  = 2

      OTHERS          = 3.

  MOVE lv_spool TO spoolno.

  CHECK spoolno IS NOT INITIAL.

  CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

    EXPORTING

      src_spoolid              = spoolno

      no_dialog                = space

      dst_device               = 'LOCL'

    IMPORTING

      pdf_bytecount            = numbytes

      pdf_spoolid              = pdfspoolid

      btc_jobname              = jobname

      btc_jobcount             = jobcount

    TABLES

      pdf                      = it_pdf

    EXCEPTIONS

      err_no_abap_spooljob     = 1

      err_no_spooljob          = 2

      err_no_permission        = 3

      err_conv_not_possible    = 4

      err_bad_destdevice       = 5

      user_cancelled           = 6

      err_spoolerror           = 7

      err_temseerror           = 8

      err_btcjob_open_failed   = 9

      err_btcjob_submit_failed = 10

      err_btcjob_close_failed  = 11.

**************************** send file ************************************

  LOOP AT it_pdf INTO x_pdf.

    TRANSLATE x_pdf USING '~'.

    CONCATENATE lv_buffer x_pdf INTO lv_buffer.

  ENDLOOP.

  TRANSLATE lv_buffer USING '~'.

  DO.

    x_mess_att = lv_buffer.

    APPEND x_mess_att TO it_mess_att.

    CLEAR: x_mess_att.

    SHIFT lv_buffer LEFT BY 255 PLACES.

    IF lv_buffer IS INITIAL.

      EXIT.

    ENDIF.

  ENDDO.

* Passing it to the final internal table

  LOOP AT it_mess_att INTO x_mess_att.

    MOVE x_mess_att-line TO x_objbin_final-line.

    CLEAR: x_mess_att.

    APPEND x_objbin_final TO it_objbin_final.

  ENDLOOP.

  IF it_objbin_final IS NOT INITIAL.

    CONCATENATE '(' sy-datum+4(2) '/'  sy-datum+6(2) '/' sy-datum+2(2)')' INTO lv_subj.

* Preparing Body

    CONCATENATE 'Report' lv_subj INTO lv_subj SEPARATED BY space.

    x_docdata-obj_name        = 'Mail'.

    x_docdata-obj_langu       = sy-langu.

    x_docdata-obj_descr       = lv_subj.

    x_docdata-sensitivty      = 'F'.

    x_objtxt                  = space.

    APPEND x_objtxt TO it_objtxt.

    CLEAR: x_objtxt.

    DESCRIBE TABLE it_objtxt LINES tab_lines.

    READ TABLE it_objtxt INTO x_objtxt INDEX tab_lines.

    x_docdata-doc_size        = ( tab_lines - 1 ) * 255 + strlen( x_objtxt ).

    CLEAR x_objpack-transf_bin.

    x_objpack-head_start      = 1.

    x_objpack-head_num        = 0.

    x_objpack-body_start      = 1.

    x_objpack-body_num        = tab_lines.

    x_objpack-doc_type        = 'RAW'.                      "text-111.

    APPEND x_objpack TO it_objpack.

    CLEAR: x_objpack.

    REFRESH: it_attachment.

    it_attachment[]         = it_mess_att[].

    n = n + tab_lines.

    CLEAR tab_lines.

    DESCRIBE TABLE it_attachment LINES tab_lines.

    x_objpack-doc_size        = tab_lines * 255.

    x_objpack-transf_bin      = 'X'.

    x_objpack-head_start      = 2.

    x_objpack-head_num        = 1.

    x_objpack-body_start      = n.

    x_objpack-body_num        = tab_lines.

    x_objpack-doc_type        = 'PDF'.

    x_docdata-obj_name        = 'Report'.

    x_objpack-obj_descr       = 'Report'.

    APPEND x_objpack TO it_objpack.

    CLEAR: x_objpack.

*Create the list of recipients

    x_reclist-receiver        = 'ZRAV'.

    x_reclist-rec_type        = 'C'.

    x_reclist-express         = 'X'.

    APPEND x_reclist TO it_reclist.

    CLEAR: x_reclist.

*Send the e-mail

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

      EXPORTING

        document_data              = x_docdata

        put_in_outbox              = 'X'

        commit_work                = 'X'

      TABLES

        packing_list               = it_objpack

        contents_bin               = it_objbin_final

        contents_txt               = it_objtxt

        receivers                  = it_reclist

      EXCEPTIONS

        too_many_receivers         = 1

        document_not_sent          = 2

        document_type_not_exist    = 3

        operation_no_authorization = 4

        parameter_error            = 5

        x_error                    = 6

        enqueue_error              = 7

        OTHERS                     = 8.

    COMMIT WORK.

    lv_c_dev = sy-sysid.

    IF sy-sysid = lv_c_dev.

      WAIT UP TO 5 SECONDS.

      SUBMIT rsconn01 WITH mode = 'INT'

                      WITH output = 'X'

                      AND RETURN.

      " SUBMIT Program to process the mails instead of keeping in queue.

      IF sy-subrc = 0.

        WRITE : 'Message sent Success'.

      ELSE.

        WRITE : 'Message Sent failed'.

      ENDIF.

    ENDIF.

  ENDIF.

*************** download PDF file ***********

check download = 'X'.

IF NOT ( jobname IS INITIAL ).

  PERFORM bd_textbox_var2_msg(rstxpdft) USING 80

   'Konvertierung per Hintergrundjob'(008)

   jobname

   jobcount.

  EXIT.

ENDIF.

DATA: p_file TYPE rlgrap-filename.

p_file = 'C:\temp\file.pdf'.

PERFORM download_w_ext(rstxpdft) TABLES pdf

                                 USING p_file

                                       '.pdf'

                                       'BIN'

                                       numbytes

                                       cancel.

IF cancel = space.

  DATA: s(80).

  s = numbytes. CONDENSE s.

  CONCATENATE s 'Bytes heruntergeladen in Datei'(009)

    INTO s SEPARATED BY space.

  PERFORM bd_textbox_var1_msg(rstxpdft) USING 80

                                    s

                                    p_file.

ENDIF.