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: 

ZMEDRUCK PO how generate pdf on the server

Former Member
0 Kudos

Good morning experts,

i need to generate a PDF when the PO it's printed and save it on a server.

In the tr. NACE i have already defined ZMEDRUCK: SAPFM06P ENTRY_NEU ZMEDRUCK

The question is, i need also to copy the program SAPFM06P and SAPLMEDRUCK to manage the creation of the PDF via function or it's possible get the spool number outside the program to generate it anda save the PDF on the server.

If it's possible to get the spool id outside the program SAPFM06P i avoid to modify thew standard program creating a Z program.

help please

thanks

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi ,

u can ref this one

regards

P

4 REPLIES 4

Former Member
0 Kudos

hi ,

u can ref this one

regards

P

Former Member
0 Kudos

go to SP02

where you can find spool nos.

and go to se38

execute RSTXPDFT4

give the spool no

and you can get that in pdf

former_member598013
Active Contributor
0 Kudos

Hi,

Can you take the below code as a reference. this will guide you how to fix your problem.



REPORT zxx_viewer_zoom.

*--------------------------------------------------------------------*
* T A B L E S    D E C L A R A T I O N
*--------------------------------------------------------------------*
*---Tables Used.
TABLES: afpo,
        mara,
        marc,
        aufk,
        afko,
        itcoo,
        nast,                          "Messages
        *nast,                         "Messages
        tnapr,                         "Programs & Forms
        addr_key,
        arc_params,                    "Archive parameters
        toa_dara.                      "Archive parameters



*--------------------------------------------------------------------*
* I N T E R N A L    T A B L E S     D E C L A R A T I O N
*--------------------------------------------------------------------*
*--Internal Tables Used.

*--------------------------------------------------------------------*
* D A T A     D E C L A R A T I O N
*--------------------------------------------------------------------*
*--Global Variables Used.
DATA: ws_matnr LIKE afpo-matnr,
      ws_werks LIKE aufk-werks,
      ws_mtart LIKE mara-mtart,
      ws_wrkst LIKE mara-wrkst,
      ws_fname TYPE rs38l_fnam,
      ws_ctrlp TYPE ssfctrlop,
      ws_optns TYPE ssfcompop,
      w_padest LIKE tsp03l-padest.                          "BMC01+

DATA: da_message_printed(1) TYPE c,
      da_preview_processed(1) TYPE c,
      repeat(1) TYPE c,
      da_subrc LIKE sy-subrc.

DATA: w_otfdata  TYPE ssfcrescl.
DATA: BEGIN OF it_itcoo OCCURS 0.
        INCLUDE STRUCTURE itcoo.
DATA: END OF it_itcoo.
DATA: w_otf  TYPE itcoo.

*--Data Declaration for Printing Layout
DATA: ls_itcpo     TYPE itcpo.
DATA: lf_repid     TYPE sy-repid.
DATA: lf_device    TYPE tddevice.
DATA: cf_retcode   TYPE sy-subrc.
DATA: ls_recipient TYPE swotobjid.
DATA: ls_sender    TYPE swotobjid.
DATA: ls_control_param   TYPE ssfctrlop.
DATA: ls_composer_param  TYPE ssfcompop.
DATA: ls_addr_key        LIKE addr_key.
DATA: w_screen(1) TYPE c.
DATA: xscreen(1) TYPE c.

DATA: da_mess LIKE vbfs OCCURS 0 WITH HEADER LINE.
*--------------------------------------------------------------------*
* C O N S T A N T S
*--------------------------------------------------------------------*
CONSTANTS: c_fas1(8)  TYPE c VALUE 'PRINTFAS',
           c_fas2(15) TYPE c VALUE 'PRINTFASDRAWING',
           c_wip1(8)  TYPE c VALUE 'PRINTWIP',
           c_wip2(15) TYPE c VALUE 'PRINTWIPDRAWING'.

*--------------------------------------------------------------------*
* S E L E C T I O N - S C R E E N.
*--------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE text-bl1.
* Production order
PARAMETERS: p_aufnr LIKE afpo-aufnr OBLIGATORY.
SELECTION-SCREEN END OF BLOCK bl1.

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


*--Get Partially processed orders
  MOVE: sy-mandt         TO nast-mandt,
        'V1'             TO nast-kappl,
        p_aufnr          TO nast-objky,
        p_aufnr          TO nast-parnr,
        sy-langu         TO nast-spras,
        sy-datum         TO nast-erdat,
        '1'              TO nast-nacha,
        '3'              TO nast-vsztp,
        'X'              TO nast-manue,
        sy-uname         TO nast-usnam,
        'DFLT'           TO nast-ldest,
        sy-langu         TO nast-tdspras,
        'Shop Floor Papers' TO nast-tdcovtitle,
        '1'              TO nast-tdarmod,
        'BUS2032'        TO nast-objtype.

*--Printer settings
  CALL FUNCTION 'WFMC_PREPARE_SMART_FORM'
    EXPORTING
      pi_nast       = nast
      pi_repid      = sy-repid
    IMPORTING
      pe_returncode = cf_retcode
      pe_itcpo      = ls_itcpo
      pe_device     = lf_device
      pe_recipient  = ls_recipient
      pe_sender     = ls_sender.

  MOVE-CORRESPONDING ls_itcpo TO ls_composer_param.
  ls_control_param-device      = 'PRINTER'.
  ls_control_param-no_dialog   = 'X'.
  ls_control_param-preview     = 'X'.
  ls_control_param-getotf      = ls_itcpo-tdgetotf.
  ls_control_param-langu       = sy-langu.


  CLEAR:   ws_werks.
  SELECT   SINGLE werks
           INTO   ws_werks
           FROM   aufk
           WHERE  aufnr = p_aufnr.

  CLEAR:   ws_matnr.
  SELECT   SINGLE plnbez
           INTO   ws_matnr
           FROM   afko
           WHERE  aufnr = p_aufnr.

  CLEAR:   marc.
  SELECT   SINGLE matgr
           INTO   marc-matgr
           FROM   marc
           WHERE  matnr = ws_matnr
           AND    werks = ws_werks.



*  CHECK NOT ws_matnr IS INITIAL.        
  IF NOT ws_matnr IS INITIAL.           



    SELECT   SINGLE matgr
             INTO   marc-matgr
             FROM   marc
             WHERE  matnr = ws_matnr
             AND    werks = ws_werks.


  ELSE.
    marc-matgr = c_wip1.
  ENDIF.
*--------------------------------------------------------------------*
END-OF-SELECTION.
*--------------------------------------------------------------------*
  PERFORM call_smartform.

*--------------------------------------------------------------------*
* F O R M    R O U T I N E S
*--------------------------------------------------------------------*
*&-------------------------------------------------------------------*
*&      Form  call_smartform
*&-------------------------------------------------------------------*
*       text
*--------------------------------------------------------------------*
FORM call_smartform.

  CLEAR: ws_ctrlp, ws_optns, ws_fname.



  TRANSLATE marc-matgr TO UPPER CASE.
  IF marc-matgr = c_fas1 OR
     marc-matgr = c_fas2.
    PERFORM call_paper_a.
  ELSEIF marc-matgr = c_wip1 OR
         marc-matgr = c_wip2.
    PERFORM call_paper_b.
  ENDIF.




ENDFORM.                    "call_smartform

*&-------------------------------------------------------------------*
*&      Form  call_paper_a
*&-------------------------------------------------------------------*
*       text
*--------------------------------------------------------------------*
FORM call_paper_a.

  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING

      formname           = 'ZPPSF_SHOP_FLOOR_PAPER_C'  


    IMPORTING
      fm_name            = ws_fname
    EXCEPTIONS
      no_form            = 1
      no_function_module = 2
      OTHERS             = 3.

  CHECK NOT ws_fname IS INITIAL.

  CLEAR w_otfdata.
  ls_control_param-getotf = 'X'.

  CALL FUNCTION ws_fname
    EXPORTING
      archive_index      = toa_dara
      archive_parameters = arc_params
      control_parameters = ls_control_param
      mail_recipient     = ls_recipient
      mail_sender        = ls_sender
      output_options     = ls_composer_param
      user_settings      = ' '
      is_nast            = nast
      aufnr              = p_aufnr
      flag_orig          = 'X'
    IMPORTING
      job_output_info    = w_otfdata
    EXCEPTIONS
      formatting_error   = 1
      internal_error     = 2
      send_error         = 3
      user_canceled      = 4
      OTHERS             = 5.

  LOOP AT w_otfdata-otfdata INTO w_otf.

    APPEND w_otf TO it_itcoo.

  ENDLOOP.

  CALL FUNCTION 'HR_IT_DISPLAY_WITH_PDF'
    TABLES
      otf_table = it_itcoo.


ENDFORM.                    "call_paper_a

*&-------------------------------------------------------------------*
*&      Form  call_paper_b
*&-------------------------------------------------------------------*
*       text
*--------------------------------------------------------------------*
FORM call_paper_b.

  DATA: ws_doknr TYPE draw-doknr,
        ws_dokvr TYPE draw-dokvr.

  CLEAR: ws_doknr, ws_dokvr.

  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname           = 'ZPPSF_SHOP_FLOOR_PAPER_B'
    IMPORTING
      fm_name            = ws_fname
    EXCEPTIONS
      no_form            = 1
      no_function_module = 2
      OTHERS             = 3.

  CHECK NOT ws_fname IS INITIAL.

  CLEAR w_otfdata.
  ls_control_param-getotf = 'X'.

  CALL FUNCTION ws_fname
    EXPORTING
      archive_index      = toa_dara
      archive_parameters = arc_params
      control_parameters = ls_control_param
      mail_recipient     = ls_recipient
      mail_sender        = ls_sender
      output_options     = ls_composer_param
      user_settings      = ' '
      is_nast            = nast
      aufnr              = p_aufnr
      doknr              = ws_doknr
      dokvr              = ws_dokvr
      flag_orig          = 'X'
    IMPORTING
      job_output_info    = w_otfdata
    EXCEPTIONS
      formatting_error   = 1
      internal_error     = 2
      send_error         = 3
      user_canceled      = 4
      OTHERS             = 5.

  LOOP AT w_otfdata-otfdata INTO w_otf.

    APPEND w_otf TO it_itcoo.

  ENDLOOP.

  CALL FUNCTION 'HR_IT_DISPLAY_WITH_PDF'
    TABLES
      otf_table = it_itcoo.


ENDFORM.                    "call_paper_b

Thanks,

Chidanand

Former Member
0 Kudos

hi i saw also that is possible genarate the pdf if you copy the program SAPFM06P in ZSAPFM06P and in the entry_neu modify as follow:

----


  • INCLUDE FM06PE02 *

----


form entry_neu using ent_retco ent_screen.

data: l_druvo like t166k-druvo,

l_nast like nast,

l_from_memory,

l_doc type meein_purchase_doc_print.

clear ent_retco.

if nast-aende eq space.

l_druvo = '1'.

else.

l_druvo = '2'.

endif.

call function 'ME_READ_PO_FOR_PRINTING'

exporting

ix_nast = nast

ix_screen = ent_screen

importing

ex_retco = ent_retco

ex_nast = l_nast

doc = l_doc

changing

cx_druvo = l_druvo

cx_from_memory = l_from_memory.

check ent_retco eq 0.

call function 'ME_PRINT_PO'

exporting

ix_nast = l_nast

ix_druvo = l_druvo

doc = l_doc

ix_screen = ent_screen

ix_from_memory = l_from_memory

ix_toa_dara = toa_dara

ix_arc_params = arc_params

ix_fonam = tnapr-fonam "HW 214570

importing

ex_retco = ent_retco.

endform.

  • Get OTF from memory

CLEAR otf.

CALL FUNCTION 'READ_OTF_FROM_MEMORY'

EXPORTING

memory_key = l_nast-objky " PO Number

TABLES

otf = otf

EXCEPTIONS

memory_empty = 1

OTHERS = 2.

IF sy-subrc <> 0.

RAISE otf_error.

ENDIF.

  • Convert Sapscript OTF to PDF file

CALL FUNCTION 'CONVERT_OTF_2_PDF'

IMPORTING

bin_filesize = pdf_bytecount

TABLES

otf = otf

doctab_archive = lt_docs

lines = pdfout

EXCEPTIONS

err_conv_not_possible = 1

err_otf_mc_noendmarker = 2

OTHERS = 3.

call function 'GUI_DOWNLOAD'

exporting

bin_filesize = pdf_bytecount

filename = 'D:\test.pdf'

filetype = 'BIN'

tables

data_tab = pdfout.