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: 

function module for script to PDF

Former Member
0 Kudos

hi,

Is there any standard program or function module where i can convert my purchase order into PDF format.

i tried ECP_PDF_DISPLAY throughing dump.

regards

prabhu

8 REPLIES 8

Former Member
0 Kudos

Hi,

you can use FM CONVERT_OTFSPOOLJOB_2_PDF.

regards

Nicola

Former Member
0 Kudos

Hi,

Check the Program RSTXCPDF.

Sudheer.A

Former Member
0 Kudos

An example, where the function module is used, is report RSTXPDFT4.

Regards

Nicola

Former Member
0 Kudos

U can use the standard program RSTXPDFT4

Former Member
0 Kudos

Hi,

Use standard report...RSTXPDFT4

regards,

Omkar.

0 Kudos

hi,

i tried that program, i am unable to execute,it is throwing an error

"report can only started with a variant".

please help how to overcome this.

send some sample code.

regards

prabhu

0 Kudos

Regards

Peram

Former Member
0 Kudos

Hi,

Just check out my code..

I hav converted my smartform to PDF.

think u can use the same Function Module.

TABLES: pernr.


*---------------------------------------------------------------------*
*                            INFOTYPES                                *
*---------------------------------------------------------------------*
INFOTYPES : 0000, "HR Master Record: Infotype 0000 (Actions)
            0001, "HR Master Record: Infotype 0001 (Org. Assignment)
            0002, "HR Master Record: Infotype 0002 (Personal Data)
            0008, "HR Master Record: Infotype 0008 (Basic Pay)
            9025. "HR Master Record for Infotype 9025


*---------------------------------------------------------------------*
*                            NODES                                    *
*---------------------------------------------------------------------*

NODES : peras.

***---------------------------------------------------------------------*
***                           TYPES - TY_                               *
***---------------------------------------------------------------------*
**
TYPES:    BEGIN OF ty_month,
          mnr TYPE fcmnr,
          ktx TYPE fcltx,
          END OF ty_month,

          BEGIN OF ty_sti,
          zempno TYPE zcm25_sal_incr-zempno,
          zsti   TYPE zcm25_sal_incr-zsti,
          END OF ty_sti,

          BEGIN OF ty_t522t,
          anred  TYPE t522t-anred,
          atext  TYPE t522t-atext,
          END OF ty_t522t,


          BEGIN OF ty_t500p,
          persa            TYPE t500p-persa , "Personnel area
          adrnr            TYPE t500p-adrnr,  "Address Number
          END OF ty_t500p,

         BEGIN OF ty_adrc,
         addrnumber       TYPE adrc-addrnumber,
         name1            TYPE adrc-name1,
         name2            TYPE adrc-name2,
         name3            TYPE adrc-name3,
         name4            TYPE adrc-name4,
         END OF ty_adrc.

*&--------------------------------------------------------------------*
*&      CONSTANTS -> C_                                               *
*&--------------------------------------------------------------------*

CONSTANTS: c_one TYPE i VALUE 1,
           c_title type string value 'FILE PATH'.

*---------------------------------------------------------------------*
*          Internal table IT_                                         *
*---------------------------------------------------------------------*

DATA :  it_01     TYPE TABLE OF pa0001,
        it_02     TYPE TABLE OF pa0002,
        it_08     TYPE TABLE OF pa0008,
        it_t500p  TYPE TABLE OF ty_t500p,
        it_tadrc  TYPE TABLE OF ty_adrc,
        it_t522t  TYPE TABLE OF ty_t522t,
        it_sti    TYPE TABLE OF ty_sti,
        it_sti1   TYPE TABLE OF zcm25_sal_incr,
        it_otf    TYPE itcoo OCCURS 0 WITH HEADER LINE,
        it_tline  TYPE tline OCCURS 0 WITH HEADER LINE,
        it_files  type filetable.
*---------------------------------------------------------------------*
*                    Workarea WA_                                     *
*---------------------------------------------------------------------*

DATA :  wa_01     TYPE pa0001,
        wa_02     TYPE pa0002,
        wa_08     TYPE pa0008,
        wa_t500p  TYPE ty_t500p,
        wa_tadrc  TYPE ty_adrc,
        wa_t522t  TYPE ty_t522t,
        wa_sti    TYPE ty_sti,
        wa_sti1   TYPE zcm25_sal_incr.
*---------------------------------------------------------------------*
*                    Workfields                                       *
*---------------------------------------------------------------------*

DATA : w_ltx(10)   TYPE c,
       w_mnr(2)    TYPE c,
       w_date      TYPE string,
       w_func_name TYPE rs38l_fnam,
       w_return    TYPE ssfcrescl,
       outop       TYPE ssfcompop,
       cparam      TYPE ssfctrlop,
       w_binsize   TYPE i,
       pr_pass     TYPE string.  "for PDF conversion


*---------------------------------------------------------------------*
*                PARAMETERS pr_*                                      *
*---------------------------------------------------------------------*


SELECTION-SCREEN: BEGIN OF BLOCK sect WITH FRAME TITLE text-003.
PARAMETERS : pr_sect  TYPE  pa9025-sector obligatory.
SELECTION-SCREEN END OF BLOCK sect.

SELECTION-SCREEN: BEGIN OF BLOCK fold WITH FRAME TITLE text-005.
PARAMETERS : pr_file(128) TYPE c OBLIGATORY.         "File Name
SELECTION-SCREEN END OF BLOCK fold.

SELECTION-SCREEN: BEGIN OF BLOCK rb WITH FRAME TITLE text-004 .
PARAMETERS : r1 RADIOBUTTON GROUP g1 DEFAULT 'X' USER-COMMAND cli1,
             r2 RADIOBUTTON GROUP g1 .
SELECTION-SCREEN END OF BLOCK rb.

**Calling Sub-Screen for AI and STI selection criterions
SELECTION-SCREEN: BEGIN OF TABBED BLOCK sub FOR 10 LINES,
                  END OF BLOCK sub.

* SUBSCREEN 1 (For STI)
SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECT-OPTIONS so_per FOR pnpbegda.

PARAMETERS: pr_yrsti(7) TYPE c,  "Year of STI
            pr_fint(4)  TYPE n,  "First Interim
            pr_sint(4)  TYPE n,  "Second Interim
            pr_dat      TYPE sy-datum.

SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN END OF SCREEN 100.

* SUBSCREEN 2 (For AI)
SELECTION-SCREEN BEGIN OF SCREEN 200 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.

SELECT-OPTIONS so_peri FOR pnpbegda.
PARAMETERS : pr_date TYPE sy-datum.

SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN END OF SCREEN 200.

************************************************************************
*             AT SELECTION-SCREEN ON VALUE-REQUEST                     *
*                                                                      *
************************************************************************

 AT SELECTION-SCREEN ON VALUE-REQUEST for pr_file.

 data : la type i.

***F4 help for Folder Selection
CALL METHOD cl_gui_frontend_services=>file_open_dialog
  EXPORTING
    WINDOW_TITLE             = c_title

  CHANGING
    file_table              = it_files
    rc                      = la
        .
IF sy-subrc <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.


else.

            read table it_files into pr_file index 1.

ENDIF.

AT SELECTION-SCREEN ON RADIOBUTTON GROUP g1.
  IF r1 = 'X'.
    sub-dynnr = 200.
  ELSEIF r2 = 'X'.
    sub-dynnr = 100.
  ENDIF.

AT SELECTION-SCREEN .

INITIALIZATION.

  sub-prog = sy-repid.

  IF r1 = 'X'.
    sub-dynnr = 200.
  ELSEIF r2 = 'X'.
    sub-dynnr = 100.
  ENDIF.

************************************************************************
*             AT SELECTION-SCREEN OUTPUT                               *
*                                                                      *
************************************************************************
AT SELECTION-SCREEN OUTPUT.


  LOOP AT SCREEN.
    IF screen-name     ='PNPWERKS-LOW'.
      screen-required  = c_one.
      MODIFY SCREEN.
    ENDIF.                         "IF screen-name     = c_abkrs.

  ENDLOOP.

************************************************************************
*                     START-OF-SELECTION.                              *
*                                                                      *
************************************************************************

START-OF-SELECTION.



GET peras.

  rp_provide_from_last p9025 space pn-begda pn-endda .
  if p9025-sector = pr_sect.

  rp_provide_from_last p0001 space pn-begda pn-endda .
  IF pnp-sw-found = 1.
    IF p0001-werks IN pnpwerks.
      wa_01-werks  = p0001-werks.
      wa_01-pernr  = p0001-pernr.

      rp_provide_from_last p0002 space pn-begda pn-endda .
      IF pnp-sw-found = 1.
        wa_02-anred  = p0002-anred.
        wa_02-gesch  = p0002-gesch.
        wa_02-vorna  = p0002-vorna.
        wa_02-nachn  = p0002-nachn.
        wa_02-pernr  = p0002-pernr.

        IF r1 = 'X'.

          rp_provide_from_last p0008 space pn-begda pn-endda .
          IF pnp-sw-found = 1.
            PERFORM f001_wage_1000.

          ENDIF.
        ENDIF.
        APPEND wa_02 TO it_02.
      ENDIF.
      APPEND wa_01 TO it_01.
    ENDIF.
  ENDIF.
endif.
END-OF-SELECTION.

  PERFORM f002_fetch_ai_data.
  IF r1 = 'X'.
    PERFORM f003_call_smartform USING 'ZCML024_AI_LETTER'.
    PERFORM f004_call_fmname_ai.

  ELSE.
    PERFORM f003_call_smartform USING 'ZCML024_STI_LETTER'.
    PERFORM f005_call_fmname_sti.
  ENDIF.

*---------------------------------------------------------------------*
*      Form  f001_wage_1000
*---------------------------------------------------------------------*
*      Fetching Salary Amount for wage type 1000
*---------------------------------------------------------------------*
FORM f001_wage_1000 .

  CONSTANTS : lc_lgart(4) TYPE c VALUE '1000'.

  CASE lc_lgart.
    WHEN p0008-lga01.
      wa_08-bet01 =  p0008-bet01.
    WHEN p0008-lga02.
      wa_08-bet01 =  p0008-bet02.
    WHEN p0008-lga03.
      wa_08-bet01 =  p0008-bet03.
    WHEN p0008-lga04.
      wa_08-bet01 =  p0008-bet04.
    WHEN p0008-lga05.
      wa_08-bet01 =  p0008-bet05.
    WHEN p0008-lga06.
      wa_08-bet01 =  p0008-bet06.
    WHEN p0008-lga07.
      wa_08-bet01 =  p0008-bet07.
    WHEN p0008-lga08.
      wa_08-bet01 =  p0008-bet08.
    WHEN p0008-lga09.
      wa_08-bet01 =  p0008-bet09.
    WHEN p0008-lga10.
      wa_08-bet01 =  p0008-bet10.
    WHEN p0008-lga11.
      wa_08-bet01 =  p0008-bet11.
    WHEN p0008-lga12.
      wa_08-bet01 =  p0008-bet12.
    WHEN p0008-lga13.
      wa_08-bet01 =  p0008-bet13.
    WHEN p0008-lga14.
      wa_08-bet01 =  p0008-bet14.
    WHEN p0008-lga15.
      wa_08-bet01 =  p0008-bet15.
    WHEN p0008-lga16.
      wa_08-bet01 =  p0008-bet16.
    WHEN p0008-lga17.
      wa_08-bet01 =   p0008-bet17.
    WHEN p0008-lga18.
      wa_08-bet01 =  p0008-bet18.
    WHEN p0008-lga19.
      wa_08-bet01 =   p0008-bet19.
    WHEN p0008-lga20.
      wa_08-bet01 =   p0008-bet20.
    WHEN p0008-lga21.
      wa_08-bet01 =  p0008-bet21.
    WHEN p0008-lga22.
      wa_08-bet01 =   p0008-bet22.
    WHEN p0008-lga23.
      wa_08-bet01 =  p0008-bet23.
    WHEN p0008-lga24.
      wa_08-bet01 =   p0008-bet24.
    WHEN p0008-lga25.
      wa_08-bet01 =  p0008-bet25.
    WHEN p0008-lga26.
      wa_08-bet01 =   p0008-bet26.
    WHEN p0008-lga27.
      wa_08-bet01 =  p0008-bet27.
    WHEN p0008-lga28.
      wa_08-bet01 =  p0008-bet28.
    WHEN p0008-lga29.
      wa_08-bet01 =  p0008-bet29.
    WHEN p0008-lga30.
      wa_08-bet01 =   p0008-bet30.
    WHEN p0008-lga31.
      wa_08-bet01 =  p0008-bet31.
    WHEN p0008-lga32.
      wa_08-bet01 =  p0008-bet32.
    WHEN p0008-lga33.
      wa_08-bet01 =  p0008-bet33.
    WHEN p0008-lga34.
      wa_08-bet01 =  p0008-bet34.
    WHEN p0008-lga35.
      wa_08-bet01 =  p0008-bet35.
    WHEN p0008-lga36.
      wa_08-bet01 =  p0008-bet36.
    WHEN p0008-lga37.
      wa_08-bet01 =  p0008-bet37.
    WHEN p0008-lga38.
      wa_08-bet01 =   p0008-bet38.
    WHEN p0008-lga39.
      wa_08-bet01 =  p0008-bet39.
    WHEN p0008-lga40.
      wa_08-bet01 =  p0008-bet40.
  ENDCASE.
  wa_08-pernr = p0008-pernr.
  APPEND wa_08 TO it_08.
ENDFORM.                    "f001_wage_1000

*&---------------------------------------------------------------------*
*&      Form  f002_fetch_AI_data
*&---------------------------------------------------------------------*
*       Selecting Pers.Area Full text and other details for AI letter
*----------------------------------------------------------------------*
FORM f002_fetch_ai_data.

**..... Fetches persa adrnr from t500p for all fetched employees
  LOOP AT it_02 INTO wa_02.
    READ TABLE it_01 INTO wa_01 WITH KEY pernr = wa_02-pernr.
    IF sy-subrc IS INITIAL.
      wa_02-zz_lang = wa_01-werks.
      MODIFY it_02 FROM wa_02 TRANSPORTING zz_lang.
    ENDIF.
  ENDLOOP.

  SELECT persa
         adrnr
  FROM t500p
 INTO TABLE it_t500p
 FOR ALL ENTRIES IN it_01
 WHERE persa = it_01-werks.

  IF  it_t500p IS NOT INITIAL.

    LOOP AT it_02 INTO wa_02.
      READ TABLE it_t500p INTO wa_t500p WITH KEY persa = wa_02-zz_lang.
      IF sy-subrc IS INITIAL.
        wa_02-inits = wa_t500p-adrnr.
        MODIFY it_02 FROM wa_02 TRANSPORTING inits.
      ENDIF.
    ENDLOOP.



**..... Fetches name1 name2 name3 name4 from adrc for all fetched employees

    SELECT addrnumber
           name1
           name2
           name3
           name4
    FROM adrc
    INTO TABLE it_tadrc
    FOR ALL ENTRIES IN it_t500p
    WHERE addrnumber EQ it_t500p-adrnr.

    IF sy-subrc IS INITIAL.
      LOOP AT it_02 INTO wa_02.
        READ TABLE it_tadrc INTO wa_tadrc WITH KEY addrnumber = wa_02-inits.
        wa_02-name2 = wa_tadrc-name1.
        wa_02-nach2 = wa_tadrc-name2.
        wa_02-rufnm = wa_tadrc-name3.
        wa_02-midnm = wa_tadrc-name4.
        MODIFY it_02 FROM wa_02 TRANSPORTING name2 nach2 rufnm midnm.
      ENDLOOP.
    ENDIF.
  ENDIF.
***Fetches the Gender (Mr. or MS) for the PERNR and assingning that to zz_lang2
  SELECT anred
         atext
  FROM t522t
  INTO TABLE it_t522t
  FOR ALL ENTRIES IN it_02
  WHERE anred = it_02-anred
    AND sprsl =  sy-langu.

  IF it_t522t IS NOT INITIAL.
    LOOP AT it_02 INTO wa_02.
      READ TABLE it_t522t INTO wa_t522t WITH KEY anred = wa_02-anred.
      IF sy-subrc IS INITIAL.
        wa_02-zz_lang2 = wa_t522t-atext.
        MODIFY it_02 FROM wa_02 TRANSPORTING zz_lang2.
      ENDIF.
    ENDLOOP.
  ENDIF.

  IF r1 = 'X'.

    w_mnr = pr_date+4(2).

*--> Month Text for AI letter
    SELECT SINGLE ltx
    FROM t247
    INTO w_ltx
    WHERE spras = sy-langu
      AND   mnr = w_mnr.

    CONCATENATE pr_date+6(2) w_ltx pr_date(4) INTO w_date separated by space.

  ELSE.

    w_mnr = pr_dat+4(2).

*--> Month Text for STI letter
    SELECT SINGLE ltx
    FROM t247
    INTO w_ltx
    WHERE spras = sy-langu
      AND   mnr = w_mnr.

    CONCATENATE pr_dat+6(2) w_ltx pr_dat(4) INTO w_date.

***fecthes the STI amount from the ztable.
    SELECT zempno
           zsti
    FROM zcm25_sal_incr
    INTO CORRESPONDING FIELDS OF TABLE it_sti
    FOR ALL ENTRIES IN it_02
    WHERE zempno = it_02-pernr
      AND begda GE so_per-low
      AND endda LE so_per-high.

    LOOP AT it_sti INTO wa_sti.

      wa_sti1-zempno = wa_sti-zempno.
      wa_sti1-zsti   = wa_sti-zsti.
      APPEND wa_sti1 TO it_sti1.
      CLEAR wa_sti1.

    ENDLOOP.

  ENDIF.



ENDFORM.                    "f002_fetch_AI_data

*&---------------------------------------------------------------------*
*&      Form  f003_call_smartform
*&---------------------------------------------------------------------*
*       Calls the smartform
*----------------------------------------------------------------------*

FORM f003_call_smartform  USING  w_formname TYPE tdsfname.

*To call the smart form using the function module.

  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname           = w_formname
    IMPORTING
      fm_name            = w_func_name
    EXCEPTIONS
      no_form            = 1
      no_function_module = 2
      OTHERS             = 3.
  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.                    "f003_call_smartform

*&---------------------------------------------------------------------*
*&      Form  f004_call_fmname
*&---------------------------------------------------------------------*
*       Calls the Function Module generated dynamically for AI letter
*----------------------------------------------------------------------*
FORM f004_call_fmname_ai .


  outop-tddest     = 'LP01'.
  cparam-getotf    = 'X'.
  cparam-preview   = space.
  cparam-no_dialog = 'X'.

  CALL FUNCTION w_func_name
    EXPORTING
      control_parameters = cparam
      output_options     = outop
      user_settings      = ''
      w_date             = w_date
    IMPORTING
      job_output_info    = w_return
    TABLES
      it_02              = it_02
      it_08              = it_08
    EXCEPTIONS
      formatting_error   = 1
      internal_error     = 2
      send_error         = 3
      user_canceled      = 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.
  PERFORM f006_otf_to_pdf.
ENDFORM.                    " f003_call_smartform

*&---------------------------------------------------------------------*
*&      Form  f005_call_fmname1                                        *
*&---------------------------------------------------------------------*
*      Calls the Function Module generated dynamically for STI letter  *
*----------------------------------------------------------------------*
FORM f005_call_fmname_sti.

  DATA : lw_fint TYPE string,
         lw_sint TYPE string,
         lw_yrsti TYPE string.

  outop-tddest     = 'LP01'.
  cparam-getotf    = 'X'.
  cparam-preview   = space.
  cparam-no_dialog = 'X'.

  lw_fint  = pr_fint.
  lw_sint  = pr_sint.
  lw_yrsti = pr_yrsti.

  CALL FUNCTION w_func_name
    EXPORTING
      control_parameters = cparam
      output_options     = outop
      user_settings      = ''
      w_date             = w_date
      w_fint             = lw_fint
      w_sint             = lw_sint
      w_yrsti            = lw_yrsti
    IMPORTING
      job_output_info    = w_return
    TABLES
      it_02              = it_02
      it_sti             = it_sti1
    EXCEPTIONS
      formatting_error   = 1
      internal_error     = 2
      send_error         = 3
      user_canceled      = 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.
  PERFORM f006_otf_to_pdf.
ENDFORM.                    "f005_call_fmname

<b>*&---------------------------------------------------------------------*
*&      Form  f006_OTF_to_pdf
*&---------------------------------------------------------------------*
*       Converts OTF to PDF format
*----------------------------------------------------------------------*
FORM f006_otf_to_pdf.
  it_otf[] = w_return-otfdata[].

*Converting smart form to PDF
  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      format                = 'PDF'
    IMPORTING
      bin_filesize          = w_binsize
    TABLES
      otf                   = it_otf
      lines                 = it_tline
    EXCEPTIONS
      err_max_linewidth     = 1
      err_format            = 2
      err_conv_not_possible = 3
      err_bad_otf           = 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.

*  l_path = 'C:Documents and Settingsics001181Desktop'.


*Downloading the PDF to the presentation server


  CONCATENATE pr_file sy-uzeit '.pdf' INTO pr_pass.

***To download the PDF
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      bin_filesize            = w_binsize
      filename                = pr_pass
      filetype                = 'BIN'
    TABLES
      data_tab                = it_tline
    EXCEPTIONS
      file_write_error        = 1
      no_batch                = 2
      gui_refuse_filetransfer = 3
      invalid_type            = 4
      no_authority            = 5
      unknown_error           = 6
      header_not_allowed      = 7
      separator_not_allowed   = 8
      filesize_not_allowed    = 9
      header_too_long         = 10
      dp_error_create         = 11
      dp_error_send           = 12
      dp_error_write          = 13
      unknown_dp_error        = 14
      access_denied           = 15
      dp_out_of_memory        = 16
      disk_full               = 17
      dp_timeout              = 18
      file_not_found          = 19
      dataprovider_exception  = 20
      control_flush_error     = 21
      OTHERS                  = 22.

  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.              </b>      "f006_OTF_to_pdf

Hope this helps.

****Reawrd points if helpful