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: 

how to read the name of a PDF file? - function module

Former Member
0 Kudos
601

Hi,

I have <b>some individual pdf documents in my desktop</b>.I need to <b>bulk-upload it to the content server and document related information to the SAP-DB</b>.

Need your guidance.

Regards,

John.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
129

try this code it will convert file to PDF file

REPORT ZWARUN_CONVERSION_PDF .

***********Tables***************

TABLES:VBRK.

***********Data Declaration***************

DATA: LV_NUMBYTES TYPE I,

LV_SPOOLNO TYPE TSP01-RQIDENT.

DATA:C_LAYOUT LIKE PRI_PARAMS-PAART VALUE 'X_65_132', "Layout

C_X TYPE C VALUE 'X'.

DATA: NUMBYTES TYPE I,

CANCEL.

***************Internal table of Pdf************

DATA: IT_PDF LIKE TLINE OCCURS 10 WITH HEADER LINE.

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

DATA:BEGIN OF IT_VBRK OCCURS 2,

FKART LIKE VBRK-FKART,

FKTYP LIKE VBRK-FKTYP,

VBTYP LIKE VBRK-VBTYP,

END OF IT_VBRK.

SELECTION-SCREEN BEGIN OF BLOCK BLK WITH FRAME.

SELECT-OPTIONS: S_BUKRS FOR VBRK-BUKRS,

S_GJAHR FOR VBRK-GJAHR.

SELECTION-SCREEN END OF BLOCK BLK .

PARAMETERS:

  • spoolno like tsp01-rqident,

DOWNLOAD AS CHECKBOX DEFAULT 'X',

P_FILE LIKE RLGRAP-FILENAME DEFAULT 'C:\warun1.pdf'.

START-OF-SELECTION.

SELECT FKART

FKTYP

VBTYP

INTO TABLE IT_VBRK

FROM VBRK

WHERE BUKRS IN S_BUKRS

AND GJAHR IN S_GJAHR.

END-OF-SELECTION.

DATA: LK_PARAMS TYPE PRI_PARAMS,

LV_VALID.

  • if not p_mailid is initial.

  • All the parameters passed are constants, so exceptions

  • doesn't get raised

CALL FUNCTION 'GET_PRINT_PARAMETERS'

EXPORTING

IMMEDIATELY = ' '

LAYOUT = C_LAYOUT "'X_65_132'

NO_DIALOG = C_X

IMPORTING

OUT_PARAMETERS = LK_PARAMS

VALID = LV_VALID.

IF LV_VALID <> SPACE .

NEW-PAGE PRINT ON PARAMETERS LK_PARAMS NO DIALOG.

*--To display the final report

PERFORM PRINT_REPORT.

NEW-PAGE PRINT OFF.

*---To convert the download to PDF

PERFORM CONV_TO_PDF_DOWNLOAD.

PERFORM DOWNLOAD.

ENDIF.

  • endif.

*--To display the final report

PERFORM PRINT_REPORT.

&----


*& Form print_report

&----


FORM PRINT_REPORT .

*write:/ 'I will do it' color 4.

  • write:/ 'Yes' color 4.

  • write:/ 'we will do it' color 4.

  • write:/ 'lets talk abt changing life style' color 4.

*

  • write:/'By warun'.

LOOP AT IT_VBRK.

WRITE:/ IT_VBRK-FKART,IT_VBRK-FKTYP,IT_VBRK-VBTYP.

ENDLOOP.

ENDFORM. " print_report

&----


*& Form conv_to_pdf_download

&----


FORM CONV_TO_PDF_DOWNLOAD .

CLEAR IT_VBRK.

WAIT UP TO 2 SECONDS.

LV_SPOOLNO = SY-SPONO.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

SRC_SPOOLID = LV_SPOOLNO

NO_DIALOG = ''

  • DST_DEVICE =

  • PDF_DESTINATION =

IMPORTING

PDF_BYTECOUNT = LV_NUMBYTES

  • PDF_SPOOLID = pdfspoolid

  • LIST_PAGECOUNT =

  • BTC_JOBNAME = jobname

  • BTC_JOBCOUNT = jobcount

TABLES

PDF = IT_PDF.

ENDFORM. " conv_to_pdf_download

&----


*& Form download

&----


FORM DOWNLOAD .

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

CHECK DOWNLOAD = 'X'.

CALL FUNCTION 'DOWNLOAD'

EXPORTING

BIN_FILESIZE = LV_NUMBYTES

FILENAME = P_FILE

FILETYPE = 'BIN'

IMPORTING

ACT_FILENAME = P_FILE

FILESIZE = LV_NUMBYTES

CANCEL = CANCEL

TABLES

DATA_TAB = IT_PDF.

IF CANCEL = SPACE.

WRITE: / LV_NUMBYTES, P_FILE.

ENDIF.

ENDFORM. " download

3 REPLIES 3

Former Member
0 Kudos
129

If u want to read a file from presentation server, try like this:

PARAMETERS : p_fname LIKE rlgrap-filename.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.

*-- Browse Presentation Server

PERFORM f4_presentation_file.

*&----


*& Form f4_presentation_file

*&----


*& F4 Help for presentation server

*&----


FORM f4_presentation_file .

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

def_path = c_path

mask = c_mask

mode = c_mode

title = text-001

IMPORTING

filename = p_fname

EXCEPTIONS

inv_winsys = 1

no_batch = 2

selection_cancel = 3

selection_error = 4

OTHERS = 5.

IF sy-subrc <> 0.

  • MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

  • WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. " f4_presentation_file

Then use any FM to upload PDF to SAP system.

Regards,

PRakash.

Message was edited by: Prakash Ramu

0 Kudos
129

Thanx for the reply.

As you said if this fn. mod. reads all the 18 lakh pdf files,i need to know how to load all these files to another fn. mod.?

Regards,

john.

Former Member
0 Kudos
130

try this code it will convert file to PDF file

REPORT ZWARUN_CONVERSION_PDF .

***********Tables***************

TABLES:VBRK.

***********Data Declaration***************

DATA: LV_NUMBYTES TYPE I,

LV_SPOOLNO TYPE TSP01-RQIDENT.

DATA:C_LAYOUT LIKE PRI_PARAMS-PAART VALUE 'X_65_132', "Layout

C_X TYPE C VALUE 'X'.

DATA: NUMBYTES TYPE I,

CANCEL.

***************Internal table of Pdf************

DATA: IT_PDF LIKE TLINE OCCURS 10 WITH HEADER LINE.

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

DATA:BEGIN OF IT_VBRK OCCURS 2,

FKART LIKE VBRK-FKART,

FKTYP LIKE VBRK-FKTYP,

VBTYP LIKE VBRK-VBTYP,

END OF IT_VBRK.

SELECTION-SCREEN BEGIN OF BLOCK BLK WITH FRAME.

SELECT-OPTIONS: S_BUKRS FOR VBRK-BUKRS,

S_GJAHR FOR VBRK-GJAHR.

SELECTION-SCREEN END OF BLOCK BLK .

PARAMETERS:

  • spoolno like tsp01-rqident,

DOWNLOAD AS CHECKBOX DEFAULT 'X',

P_FILE LIKE RLGRAP-FILENAME DEFAULT 'C:\warun1.pdf'.

START-OF-SELECTION.

SELECT FKART

FKTYP

VBTYP

INTO TABLE IT_VBRK

FROM VBRK

WHERE BUKRS IN S_BUKRS

AND GJAHR IN S_GJAHR.

END-OF-SELECTION.

DATA: LK_PARAMS TYPE PRI_PARAMS,

LV_VALID.

  • if not p_mailid is initial.

  • All the parameters passed are constants, so exceptions

  • doesn't get raised

CALL FUNCTION 'GET_PRINT_PARAMETERS'

EXPORTING

IMMEDIATELY = ' '

LAYOUT = C_LAYOUT "'X_65_132'

NO_DIALOG = C_X

IMPORTING

OUT_PARAMETERS = LK_PARAMS

VALID = LV_VALID.

IF LV_VALID <> SPACE .

NEW-PAGE PRINT ON PARAMETERS LK_PARAMS NO DIALOG.

*--To display the final report

PERFORM PRINT_REPORT.

NEW-PAGE PRINT OFF.

*---To convert the download to PDF

PERFORM CONV_TO_PDF_DOWNLOAD.

PERFORM DOWNLOAD.

ENDIF.

  • endif.

*--To display the final report

PERFORM PRINT_REPORT.

&----


*& Form print_report

&----


FORM PRINT_REPORT .

*write:/ 'I will do it' color 4.

  • write:/ 'Yes' color 4.

  • write:/ 'we will do it' color 4.

  • write:/ 'lets talk abt changing life style' color 4.

*

  • write:/'By warun'.

LOOP AT IT_VBRK.

WRITE:/ IT_VBRK-FKART,IT_VBRK-FKTYP,IT_VBRK-VBTYP.

ENDLOOP.

ENDFORM. " print_report

&----


*& Form conv_to_pdf_download

&----


FORM CONV_TO_PDF_DOWNLOAD .

CLEAR IT_VBRK.

WAIT UP TO 2 SECONDS.

LV_SPOOLNO = SY-SPONO.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

SRC_SPOOLID = LV_SPOOLNO

NO_DIALOG = ''

  • DST_DEVICE =

  • PDF_DESTINATION =

IMPORTING

PDF_BYTECOUNT = LV_NUMBYTES

  • PDF_SPOOLID = pdfspoolid

  • LIST_PAGECOUNT =

  • BTC_JOBNAME = jobname

  • BTC_JOBCOUNT = jobcount

TABLES

PDF = IT_PDF.

ENDFORM. " conv_to_pdf_download

&----


*& Form download

&----


FORM DOWNLOAD .

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

CHECK DOWNLOAD = 'X'.

CALL FUNCTION 'DOWNLOAD'

EXPORTING

BIN_FILESIZE = LV_NUMBYTES

FILENAME = P_FILE

FILETYPE = 'BIN'

IMPORTING

ACT_FILENAME = P_FILE

FILESIZE = LV_NUMBYTES

CANCEL = CANCEL

TABLES

DATA_TAB = IT_PDF.

IF CANCEL = SPACE.

WRITE: / LV_NUMBYTES, P_FILE.

ENDIF.

ENDFORM. " download