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: 

Somebody clarify me about Hexadecimal data conversion to create A PDF and send it to mail

kirankumark2
Participant
0 Kudos

I got a requirement to send spool output as PDF attachment to the group of mails. This spool is generating from a program which is scheduled using JOB_OPEN, JOB_SUBMIT and JOB_CLOSE.

I got the Spool request from Background job, I have passed this to CONVERT_ABAPSPOOLTO_PDF Function module, this function module returns an internal table. In debugging I checked the content of the internal table which is in Hexadecimal format. Can someone help me to clarify below..

1. This internal table data is in Hexadecimal format.. When I refer a sample logic in Google it was mentioned that we need to convert 135 length to 255.. What does it mean?

2. How can I convert this data and send as an PDF attachment.. If any sample logic is helpful.

3. Need help for mailer logic to send above PDF as an attachment to a distribution list.

8 REPLIES 8

Sandra_Rossi
Active Contributor

"data in hexadecimal format" doesn't represent the reality. The reality is that the data is stored as bytes and that the debugger shows them as hexadecimal because it's the simpler known way to display bytes.

Use the class CL_BCS to send emails. There are lots of examples in the web and SAP provides lots of demo programs.

NB: CONVERT_ABAPSPOOLTO_PDF does not exist.

kirankumark2
Participant
0 Kudos

Hi Rossi,

Thanks for your reply.

Data of my internal table is like attached format (Refer attached screenshotpdf.png). I think it is not in Hexadecimal. Could you please correct me if something wrong in the below FM Call.

1. I am not passing Destination Device to the FM call. Does it mandatory?

2. From below FM call I am getting data into GT_PDF in attached format. Could you please suggest me what I need to change to get into Hexadecimal...?

P_SPOOL = Spool Number

GV_NODIA = SPACE.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
SRC_SPOOLID = P_SPOOL
NO_DIALOG = GV_NODIA
* DST_DEVICE =
* PDF_DESTINATION =
* NO_BACKGROUND =
* GET_SIZE_FROM_FORMAT = 'U'
* USE_CASCADING = ' '
* IMPORTING
* PDF_BYTECOUNT =
* PDF_SPOOLID =
* LIST_PAGECOUNT =
* BTC_JOBNAME =
* BTC_JOBCOUNT =
* BIN_FILE =
TABLES
PDF = GT_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
OTHERS = 12.
I

pdf.png

RAF
Active Contributor
0 Kudos

Hi,

for conversion check out class

cl_rmps_general_functions=>

i used this method

convert_1024_to_255( EXPORTING im_tab_1024 = lt_doc RECEIVING re_tab_255 = lt_content ).

Send logic as following

DATA(lo_send_request) = cl_bcs=>create_persistent( ).
DATA(lo_document) = cl_document_bcs=>create_document( i_type = 'RAW' i_subject = 'your subject' ).
DATA(lo_sender) = cl_sapuser_bcs=>create( sy-uname ).
lo_send_request->set_sender( i_sender = lo_sender ).
DATA(lo_recipient) = cl_cam_address_bcs=>create_internet_address( 'distributionlist@yourcompany.com' ).
lo_send_request->add_recipient( i_recipient = lo_recipient i_express = 'X' i_copy = ' ' i_blind_copy = ' ' i_no_forward = ' ' ).

lo_document->add_attachment( EXPORTING i_attachment_type = 'PDF' i_attachment_subject = lv_subject i_att_content_hex = lt_content ).
lo_send_request->set_document( lo_document ).

lo_send_request->send( ).
COMMIT WORK.

0 Kudos

Hi Robert,

Thanks for your reply...

My Question is i am getting data into PDF internal table [IT_PDF] in attached format with 132 length. Does it correct or Any error.

1. If it is correct Further how can i proceed like how can i convert 132 to 255.

2. If Error, what correction is required.

3. For your information i am using Function module (SO_NEW_DOCUMENT_SEND_API1) to send mail, i am not using any class like CL_BCS.

Please refer the attached screenshot and let me know.132.png

Sandra_Rossi
Active Contributor
0 Kudos

You were talking about hexadecimal, so I just wanted to tell you that hexadecimal means nothing in ABAP programming.

I suggest you to use CL_BCS, and to find some existing examples in the web, or some demo programs provided by SAP.

FredericGirod
Active Contributor
0 Kudos

all the explaination how to send an email with attachment ...

https://blogs.sap.com/2013/05/29/sending-mail-using-oo/

start to search on SCN before asking

jozsef_hegyi
Active Participant

Hi,

you can sue as an example bcs_example_8. It use cl_bcs and sends pdf as attachment.

PDF is generated with ADS, but the principe is the same for any other PDF.

Best regards

JozsefH

kirankumark2
Participant
0 Kudos

Hi Rossi,

Thanks for your reply...

My Question is i am getting data into PDF internal table [IT_PDF] in attached format with 132 length. Does it correct or Any error.

1. If it is correct Further how can i proceed like how can i convert 132 to 255.

2. If Error, what correction is required.

3. For your information i am using Function module (SO_NEW_DOCUMENT_SEND_API1) to send mail, i am not using any class like CL_BCS.

4. I am following below Link to Achieve my requirement but i am unable to understand the Logic and Purpose.

https://wiki.scn.sap.com/wiki/display/Snippets/Convert+Spool+request+to+PDF+and+send+as+e-mail

5. In the Above Link i don't understand below Logic about data conversion

*---------------------------------------------------------------------*
*       FORM convert_spool_to_pdf                                     *
*---------------------------------------------------------------------*
FORM convert_spool_to_pdf.

  CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
    EXPORTING
      src_spoolid              = gd_spool_nr
      no_dialog                = c_no
      dst_device               = c_device
    IMPORTING
      pdf_bytecount            = gd_bytecount
    TABLES
      pdf                      = it_pdf_output
    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
      OTHERS                   = 12.

  CHECK sy-subrc = 0.

* Transfer the 132-long strings to 255-long strings
  LOOP AT it_pdf_output.
    TRANSLATE it_pdf_output USING ' ~'.
    CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
  ENDLOOP.

  TRANSLATE gd_buffer USING '~ '.

  DO.
    it_mess_att = gd_buffer.
    APPEND it_mess_att.
    SHIFT gd_buffer LEFT BY 255 PLACES.
    IF gd_buffer IS INITIAL.
      EXIT.
    ENDIF.
  ENDDO.
ENDFORM.                    "convert_spool_to_pdf

Please refer the attached screenshot and let me know.132.png