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

Custom solution to send PDF

Former Member
0 Likes
1,298

We currently use Jetform to generate our outputs in SAP. Since this is no longer supported we have to move out from Jetform. Being a full project in itself, we have to, on short term, find a way to email jetform generate outputs(in unix) to our customers.

I don't know what suggestions you could have on this but on our side we are currently able to have Jetform generate PDF files. So I guess what remains is to be able to somehow import those PDF in SAP. For that, we are looking into 2 options.

1-Add some code in the Jetform unix script that would RFC the PDF back to SAP: we found some code examples that seems to be doing similar but that need to be tested.

2-Not do anything in unix but instead use some functions(that I dont know yet so if you know them, please suggest them to me) in a abap program that would upload them into memory for email send or into some cluster table to later bundle and send all at once.

Any ideas will be greatly welcomed.

Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,222

Hi Patrick,

You can upload the files into application server and send it via email in foreground or background.

Take a look at transaction CG3Z for uploading files from Presentation server to application server or you can use FM GUI_UPLOAD to upload the PDF files.

You can find many articles on sending mails from SAP in SCN.

Sample code for uploading PDF to application server:

data : it_binary type solix_tab,

        wa_binary type solix.




data : lv_length type i.



CALL FUNCTION 'GUI_UPLOAD'

   EXPORTING

     FILENAME                      = 'C:\Desktop\test.pdf'

    FILETYPE                      = 'BIN'

  IMPORTING

    FILELENGTH                    = lv_length

   TABLES

     DATA_TAB                      = it_binary

  EXCEPTIONS

    FILE_OPEN_ERROR               = 1

    FILE_READ_ERROR               = 2

    NO_BATCH                      = 3

    GUI_REFUSE_FILETRANSFER       = 4

    INVALID_TYPE                  = 5

    NO_AUTHORITY                  = 6

    UNKNOWN_ERROR                 = 7

    BAD_DATA_FORMAT               = 8

    HEADER_NOT_ALLOWED            = 9

    SEPARATOR_NOT_ALLOWED         = 10

    HEADER_TOO_LONG               = 11

    UNKNOWN_DP_ERROR              = 12

    ACCESS_DENIED                 = 13

    DP_OUT_OF_MEMORY              = 14

    DISK_FULL                     = 15

    DP_TIMEOUT                    = 16

    OTHERS                        = 17

           .

IF SY-SUBRC <> 0.


ENDIF.



* create a file on the application server to store this binary file.



data : lv_app type rlgrap-filename value '/usr/sap/tmp/test.pdf'.

open dataset lv_app for output in binary mode.


loop at it_binary into wa_binary.

   transfer wa_binary to lv_app.

   endloop.

close dataset lv_app.



clear wa_binary.

refresh it_binary.


Thanks,

Shambu

8 REPLIES 8
Read only

Former Member
0 Likes
1,223

Hi Patrick,

You can upload the files into application server and send it via email in foreground or background.

Take a look at transaction CG3Z for uploading files from Presentation server to application server or you can use FM GUI_UPLOAD to upload the PDF files.

You can find many articles on sending mails from SAP in SCN.

Sample code for uploading PDF to application server:

data : it_binary type solix_tab,

        wa_binary type solix.




data : lv_length type i.



CALL FUNCTION 'GUI_UPLOAD'

   EXPORTING

     FILENAME                      = 'C:\Desktop\test.pdf'

    FILETYPE                      = 'BIN'

  IMPORTING

    FILELENGTH                    = lv_length

   TABLES

     DATA_TAB                      = it_binary

  EXCEPTIONS

    FILE_OPEN_ERROR               = 1

    FILE_READ_ERROR               = 2

    NO_BATCH                      = 3

    GUI_REFUSE_FILETRANSFER       = 4

    INVALID_TYPE                  = 5

    NO_AUTHORITY                  = 6

    UNKNOWN_ERROR                 = 7

    BAD_DATA_FORMAT               = 8

    HEADER_NOT_ALLOWED            = 9

    SEPARATOR_NOT_ALLOWED         = 10

    HEADER_TOO_LONG               = 11

    UNKNOWN_DP_ERROR              = 12

    ACCESS_DENIED                 = 13

    DP_OUT_OF_MEMORY              = 14

    DISK_FULL                     = 15

    DP_TIMEOUT                    = 16

    OTHERS                        = 17

           .

IF SY-SUBRC <> 0.


ENDIF.



* create a file on the application server to store this binary file.



data : lv_app type rlgrap-filename value '/usr/sap/tmp/test.pdf'.

open dataset lv_app for output in binary mode.


loop at it_binary into wa_binary.

   transfer wa_binary to lv_app.

   endloop.

close dataset lv_app.



clear wa_binary.

refresh it_binary.


Thanks,

Shambu

Read only

0 Likes
1,222

I may have said it wrong. The pdf files are on the app server(Unix) and need to be brought back into SAP.

So I guess my only question is what would be a function to read a PDF file that sits on the app server(unix) and bring it into SAP(into a cluster table) via an ABAP.

Thank you.

Read only

0 Likes
1,222

Hi,

You can use OPEN and CLOSE DATASET to read the file from Unix server.

http://scn.sap.com/thread/851766

http://www.erpgenie.com/sap/abap/unixfile.htm

Thanks,

Shambu

Read only

0 Likes
1,222

That's perfect with text files but what about reding binary files like PDF and store it into tables?

Read only

0 Likes
1,222

Hi Patrick,

You can use BINARY mode for that.

open dataset dsn for input in binary mode.

do.

read dataset dsn into contents_bin-line.

if sy-subrc ne 0.

exit.

endif.

append contents_bin.

enddo.

close dataset dsn.

After this you can store these data into some database table.

Check this link, this has the same requirement.

http://scn.sap.com/thread/988559

Thanks,

Shambu

Read only

0 Likes
1,222

I did this short program

  DATA: BEGIN OF itab OCCURS 0,

                field(255) TYPE x,

            END OF itab.

  DATA: dsn(200)   TYPE c,

        dsn1(200)   TYPE c,

        wa_indx  TYPE zdenis1.

  dsn = '/xxxx/R38/central/r38/forms/Control.pdf'.

  OPEN DATASET dsn

    FOR INPUT IN BINARY MODE.

  DO.

    READ DATASET dsn INTO itab-field.

    IF sy-subrc = 0.

      APPEND itab.

    ELSE.

      EXIT.

    ENDIF.

  ENDDO.

  CLOSE DATASET dsn.

   

             

  CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

      filename                        = 'x:\monpdf.pdf'

      filetype                        = 'BIN'

    TABLES

      data_tab                        = itab.

  .

  IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

  ENDIF.

When I try to open the PDF on the desktop, it says it is corrupted.

Any idea why? (you can test it you ftp a pdf to your app server, run the program and try to open the transfered pdf on your computer.)

Thanks

Read only

0 Likes
1,222

Hi,

If you want to download the file from Application to Presentation server, you can also use

DATA:  source TYPE SAPB-SAPPFAD,

            dest       TYPE SAPB-SAPPFAD.

source = '/xxxx/R38/central/r38/forms/Control.pdf'.

dest = ' x:\monpdf.pdf'.

CALL FUNCTION 'ARCHIVFILE_SERVER_TO_CLIENT'

    EXPORTING

      path             = source

     TARGETPATH        = dest

EXCEPTIONS

   ERROR_FILE       = 1

   OTHERS           = 2

Thanks,
Shambu

Read only

0 Likes
1,222

BINGO!!!!!

I was able to have my program working, not with function ARCHIVFILE_SERVER_TO_CLIENT but with sub function contained in it.

Thanks.