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: 

Trigger Smartform automatically

Former Member
0 Kudos

Hi All,

I have a requirement where i need to trigger SMARTFORM automatically through ABAP editor and get the PDF/XML format in my internal table.

The Smartform is configured in VA02 --> 'Issue to Output'.

if any one knows please let me know.

Thanks,

Sri.

19 REPLIES 19

Former Member
0 Kudos

Hi,

what does mean " SMARTFORM automatically through ABAP editor"; can you elaborate more details.

Generally form will be based on the output type config ( NACE). So you  have a option to provide your own print program and FORM entry.   In side the program you can convert all your internal table data to XML or PDF for your desire requirement.

BG,

Kiran

0 Kudos

Hi Kiran,

Thanks for the reply.

let me elaborate it.

i need to call the t-code VA02 and get the smartform output for the quotation number.

this smartform PDF/XML output i need to send the attachment through e-Mail.

here my question is how to trigger it and get the output?

Thanks & Regards,

Sri.

0 Kudos

Hi,

By anychance can write a small BDC and try ???

Regards,

VS


0 Kudos

Hi VS,

Not a Bad Idea.

Ok. Now how to get the Smartform data(PDF/XML) into internal table or as an attachment?

Thanks & Regards,

Sri.

0 Kudos

Hi,

I already mentioned, first you need to configure the NACE for your output type.

-  when you call VA02 the program will trigger the output type and your program. Write the logic in your own program.

- convert OTF to PDF

- Use the FM to send the mail for required customers

Rg,

Kiran

0 Kudos

Hi Kiran,

I Know the NACE settings. this was done already and working perfect when we run VA02.

in a new program i want to use the existing one.

in Print preview i get the PDF format of the smartform.

I wanted to capture this SMARTFORM output.

then i can go ahead.

BR,

Sri.

0 Kudos

You can get the smartform output data as below:

In Smart FM , If you pass the ctrlop-getotf = 'X'. 

the smart FM will return the OTF data

CALL FUNCTION '/1BCDWB/XXXXX'

  EXPORTING

    control_parameters = ctrlop

    output_options     = wa_outopt

    user_settings      = 'X'

  IMPORTING

   job_output_info    = otfdata

  EXCEPTIONS

    formatting_error   = 1

    internal_error     = 2

    send_error         = 3

    user_canceled      = 4.

This OTF data you can use further processing !!!!

0 Kudos

hi sri kanth...

u want smart form output in PDF format another way is there,

after print preview u can use these t-code PDF!  you can use these t-code the output will be download automatically...

regards,

roopa

0 Kudos

Hello Sri,

Create a new output typt with medium 5 and also check the communication statgy as Immidate.Then write the code in deriver program to convert the smartform to PDF and send that smartforms as an attachemt through function module 'SO_NEW_*'OR USE CLESS CL_BCS.

Thanks

Sam

0 Kudos

Hi Kiran,

As said earlier, i cant modify/change the existing driver program & form.

i wanted to create a new program in which it should capture the form data and send in mail.

BR,

Sri.

0 Kudos

Hello sri,

Try to find the enhancment point it must b there in the std. driver program.Presently which drv.prg u are using.

Thanks

Sam

0 Kudos

Hi Roopa,

No. i want to capture the smartform output.

BR,

Sri.

dibyajeeban_jena
Active Participant
0 Kudos


Hi,

In Tcode-NACE , assign your Program, Smartform and Entry form name for a the specified output type . It will give you the output form from 'Issue to Output' .

Now in the program where u are calling FM for the SF, u will get a standard Import parameter (JOB_OUTPUT_INFO) .

In the parameter , take field  OTFDATA to a internal table .  Use  FM-'CONVERT_OTF' to convert it to PDF format .

Now pass this to the FM for attachment in your mailing prog, which u need to code after the SF call in the main prog .

Regards

DJ

former_member202818
Active Contributor
0 Kudos

Hi Sri,

To get the internal table(OTF data) from a program(here va02) to anther program(your progrm), can use EXPORT and IMPORT statement. Do a small enhancement in va02 and write EXPORT statement for internal table.

Then you can IMPORT the same table from another program which is called in the same session.

Regards

Sreekanth

0 Kudos

U can achieve this through NACE with the help of functinal consultant

Former Member
0 Kudos

Hi Sri,

You might have done the NACE configuration and if not kindly let me know.

Please follow following code in your driver program:-

With in the FORM ENTRY

call your smartform for pdf output to mail:-

CALL FUNCTION SM_FUNC"'/1BCDWB/SF00000005'

     EXPORTING

*   ARCHIVE_INDEX              =

*   ARCHIVE_INDEX_TAB          =

*   ARCHIVE_PARAMETERS         =

    CONTROL_PARAMETERS         = CPARAM

*   MAIL_APPL_OBJ              =

*   MAIL_RECIPIENT             =

*   MAIL_SENDER                =

    OUTPUT_OPTIONS             = OUTOP

    USER_SETTINGS              = ' '

       WA_HEAD                    = WA_HEAD

       LV_VSTAT                   = LV_VSTAT

*      text2                      = text

       ZYEAR                   = YEAR

       REGION                  = ZREGION

  IMPORTING

    DOCUMENT_OUTPUT_INFO       = ST_DOCUMENT_OUTPUT_INFO

    JOB_OUTPUT_INFO            = ST_JOB_OUTPUT_INFO

    JOB_OUTPUT_OPTIONS         = ST_JOB_OUTPUT_OPTIONS

     TABLES

       GT_VBRP                    = GT_VBRP

    EXCEPTIONS

      FORMATTING_ERROR           = 1

      INTERNAL_ERROR             = 2

      SEND_ERROR                 = 3

      USER_CANCELED              = 4

      OTHERS                     = 5

             .

   IF SY-SUBRC <> 0.

* Implement suitable error handling here

   ENDIF.

**********appending the otf data into the final table**********************

   IT_OTF[] = ST_JOB_OUTPUT_INFO-OTFDATA[].


CALL FUNCTION 'CONVERT_OTF_2_PDF'

*    EXPORTING

"      format                 = 'PDF'

"      max_linewidth          = 132

     IMPORTING

       BIN_FILESIZE           = V_BIN_FILESIZE"lv_filesize

     TABLES

       OTF                    = IT_OTF"st_job_output_info-otfdata[]"ls_info-otfdata[]

       DOCTAB_ARCHIVE         = IT_DOCS[]"lt_docs[]

       LINES                  = IT_LINES[]"lt_lines[]

     EXCEPTIONS

       ERR_CONV_NOT_POSSIBLE  = 1

       ERR_OTF_MC_NOENDMARKER = 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.

   DATA: FILE_SIZE TYPE I,

    BIN_FILESIZE TYPE I,

    PDF_TAB LIKE TLINE OCCURS 0 WITH HEADER LINE.

   DATA FILENAME TYPE RCGIEDIAL-IEFILE.

   DATA BUKRS TYPE BUKRS.

   DATA RETURN TYPE CHAR1.

   DATA MESSAGE TYPE CHAR255.

   DATA TITLE TYPE CHAR255.

   CLEAR:FILENAME,BUKRS,RETURN,MESSAGE.

********Code for email**********

   DATA: I_OTF TYPE ITCOO OCCURS 0 WITH HEADER LINE,

  I_TLINE TYPE TABLE OF TLINE WITH HEADER LINE,

  I_RECEIVERS TYPE TABLE OF SOMLRECI1 WITH HEADER LINE,

  I_RECORD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

*Objects to send mail.

  I_OBJPACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,

  I_OBJTXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

  I_OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

  I_RECLIST LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,

*Work Area declarations

  WA_OBJHEAD TYPE SOLI_TAB,

  W_CTRLOP TYPE SSFCTRLOP,

  W_COMPOP TYPE SSFCOMPOP,

  W_RETURN TYPE SSFCRESCL,

  WA_DOC_CHNG TYPE SODOCCHGI1,

  W_DATA TYPE SODOCCHGI1,

  WA_BUFFER TYPE STRING, "To convert from 132 to 255

*Variables declarations

  V_FORM_NAME TYPE RS38L_FNAM,

*V_LEN_IN LIKE SOOD-OBJLEN,

  V_LEN_OUT LIKE SOOD-OBJLEN,

  V_LEN_OUTN TYPE I,

  V_LINES_TXT TYPE I,

  V_LINES_BIN TYPE I.

   LOOP AT IT_LINES.

     TRANSLATE IT_LINES USING '~'.

     CONCATENATE WA_BUFFER IT_LINES INTO WA_BUFFER.

   ENDLOOP.

   TRANSLATE WA_BUFFER USING '~'.

   DO.

     I_RECORD = WA_BUFFER.

     APPEND I_RECORD.

     SHIFT WA_BUFFER LEFT BY 255 PLACES.

     IF WA_BUFFER IS INITIAL.

       EXIT.

     ENDIF.

   ENDDO.

*Attachment

   REFRESH: I_RECLIST,

   I_OBJTXT,

   I_OBJBIN,

   I_OBJPACK.

   CLEAR WA_OBJHEAD.

   I_OBJBIN[] = I_RECORD[].

*Create Message Body Title and Description

   I_OBJTXT = 'Invoice'.

   APPEND I_OBJTXT.

   DESCRIBE TABLE I_OBJTXT LINES V_LINES_TXT.

   READ TABLE I_OBJTXT INDEX V_LINES_TXT.

   DATA: SUB(50),

         V_TEXT TYPE TVFKT-VTEXT .

   IF WA_HEAD-FKART IS NOT INITIAL .

     SELECT SINGLE VTEXT FROM TVFKT INTO V_TEXT

       WHERE SPRAS EQ 'E' AND

             FKART EQ WA_HEAD-FKART .

     CONCATENATE V_TEXT 'NO.:' WA_HEAD-VBELN INTO SUB SEPARATED BY SPACE .

   ELSE.

     CONCATENATE 'TAX INVOICE NO.:' WA_HEAD-VBELN INTO SUB.

   ENDIF .

   WA_DOC_CHNG-OBJ_NAME = SUB."'smartform'.

   WA_DOC_CHNG-EXPIRY_DAT = SY-DATUM + 10.

   WA_DOC_CHNG-OBJ_DESCR = SUB."'smartform'.

   WA_DOC_CHNG-SENSITIVTY = 'F'.

   WA_DOC_CHNG-DOC_SIZE = V_LINES_TXT * 255.

*Main Text

   CLEAR I_OBJPACK-TRANSF_BIN.

   I_OBJPACK-HEAD_START = 1.

   I_OBJPACK-HEAD_NUM = 0.

   I_OBJPACK-BODY_START = 1.

   I_OBJPACK-BODY_NUM = V_LINES_TXT.

   I_OBJPACK-DOC_TYPE = 'RAW'.

   APPEND I_OBJPACK.

*Attachment (pdf-Attachment)

   I_OBJPACK-TRANSF_BIN = 'X'.

   I_OBJPACK-HEAD_START = 1.

   I_OBJPACK-HEAD_NUM = 0.

   I_OBJPACK-BODY_START = 1.

   DESCRIBE TABLE I_OBJBIN LINES V_LINES_BIN.

   READ TABLE I_OBJBIN INDEX V_LINES_BIN.

   I_OBJPACK-DOC_SIZE = V_LINES_BIN * 255 .

   I_OBJPACK-BODY_NUM = V_LINES_BIN.

   I_OBJPACK-DOC_TYPE = 'PDF'.

   I_OBJPACK-OBJ_NAME = 'smart'.

   I_OBJPACK-OBJ_DESCR = NAST-OBJKY.

   APPEND I_OBJPACK.

   CLEAR I_RECLIST.

IF WA_ADR6P-SMTP_ADDR IS NOT INITIAL.

     I_RECLIST-RECEIVER  = WA_ADR6P-SMTP_ADDR.

     I_RECLIST-REC_TYPE = 'U'.

     APPEND I_RECLIST.

     CLEAR I_RECLIST.

   ENDIF.

   IF WA_ADR6S-SMTP_ADDR IS NOT INITIAL.

     I_RECLIST-RECEIVER  = WA_ADR6S-SMTP_ADDR.

     I_RECLIST-REC_TYPE = 'U'.

     APPEND I_RECLIST.

     CLEAR I_RECLIST.

   ENDIF.

   I_RECLIST-RECEIVER  = G_ADDRESS-E_MAIL.

   I_RECLIST-REC_TYPE = 'U'.

   APPEND I_RECLIST.

   CLEAR I_RECLIST.


CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

       EXPORTING

         DOCUMENT_DATA              = WA_DOC_CHNG

         PUT_IN_OUTBOX              = 'X'

                                                                                                                                                                                                                     "        commit_work                = 'X'

       TABLES

         PACKING_LIST               = I_OBJPACK

         OBJECT_HEADER              = WA_OBJHEAD

         CONTENTS_BIN               = I_OBJBIN

         CONTENTS_TXT               = I_OBJTXT

         RECEIVERS                  = I_RECLIST

       EXCEPTIONS

         TOO_MANY_RECEIVERS         = 1

         DOCUMENT_NOT_SENT          = 2

         DOCUMENT_TYPE_NOT_EXIST    = 3

         OPERATION_NO_AUTHORIZATION = 4

         PARAMETER_ERROR            = 5

         X_ERROR                    = 6

         ENQUEUE_ERROR              = 7

         OTHERS                     = 8.

     IF SY-SUBRC <> 0.

     ENDIF.

Kidnly see to it for your reference and let me know in case of any concern.

This will be done once you use issue output to from VA02

0 Kudos

Hi Ravi,

Thanks for the reply.

i cant change/modify the existing form and program which was configured in VA02.

so now i created a simple BDC and get the output. i want to capture the smartform output.

can you please let me know how to achieve this.

BR,

Sri.

0 Kudos

trigger the program and let it goto spool(or you may trigger the output type itself via nast processing fms and the capture the spool), retrieve the spool  and  convert it into PDF.(use fm CONVERT_ABAPSPOOLJOB_2_PDF)

you'll have to check how to get your spool, this can be done by triggering the smartform from your report and then getting spool based on user id. I'm giving a direction you can think abt it and research further.

Former Member
0 Kudos

Hi srikanth,

   Try this its working i have tried..Please do follow following code in your driver program:

REPORT  ZSD_SMARTFORM.

PARAMETERS: P_EBELN TYPE EBELN.

DATA: WA_EKKO TYPE EKKO,

      WA_EKPO TYPE EKPO,

      IT_EKKO TYPE TABLE OF EKKO,

      IT_EKPO TYPE TABLE OF EKPO.

*DATA: V_COUNT TYPE I,

*      V_LINES TYPE I.

data:FUN_NAME TYPE CHAR30.

START-OF-SELECTION.

PERFORM GET_DATA.

PERFORM STD_FUN.

*&---------------------------------------------------------------------*

*&      Form  GET_DATA

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

form GET_DATA .

SELECT SINGLE * FROM EKKO INTO WA_EKKO WHERE EBELN = P_EBELN.

IF SY-SUBRC EQ 0.

  SELECT * FROM EKPO INTO TABLE IT_EKPO WHERE EBELN = P_EBELN.

    ENDIF.

endform.                    " GET_DATA

FORM STD_FUN.

  DATA: LW_SSFCTRLOP TYPE SSFCTRLOP.

*data:FU_NAME TYPE CHAR30.

DATA:LT_SSFCRESCL TYPE SSFCRESCL.

DATA:L_BINSIZE TYPE I.

DATA:LT_LINES TYPE TABLE OF TLINE.

*DATA: IT_DOCS TYPE TABLE OF DOCS.

DATA:V_FUN_NAME TYPE RS38L_FNAM.

DATA:V_FNAME TYPE RLGRAP-FILENAME,

      L_FNAME TYPE STRING.

  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

  EXPORTING

    formname                 = 'ZDEMO_SMARTFORM21'

**   VARIANT                  = ' '

**   DIRECT_CALL              = ' '

IMPORTING

   FM_NAME                  = FUN_NAME

EXCEPTIONS

   NO_FORM                  = 1

   NO_FUNCTION_MODULE       = 2

   OTHERS                   = 3

          .

IF sy-subrc <> 0.

* Implement suitable error handling here

ENDIF.

*

LW_SSFCTRLOP = 'X'.

LW_SSFCTRLOP-NO_DIALOG = 'X'.

CALL FUNCTION FUN_NAME

  EXPORTING

*   ARCHIVE_INDEX              =

*   ARCHIVE_INDEX_TAB          =

*   ARCHIVE_PARAMETERS         =

   CONTROL_PARAMETERS         =  LW_SSFCTRLOP

*   MAIL_APPL_OBJ              =

*   MAIL_RECIPIENT             =

*   MAIL_SENDER                =

*   OUTPUT_OPTIONS             =

*   USER_SETTINGS              = 'X'

    WA_EKKO                    = WA_EKKO

IMPORTING

*   DOCUMENT_OUTPUT_INFO       =

   JOB_OUTPUT_INFO            = LT_SSFCRESCL

*   JOB_OUTPUT_OPTIONS         =

  TABLES

    IT_EKPO                    = IT_EKPO

EXCEPTIONS

   FORMATTING_ERROR           = 1

   INTERNAL_ERROR             = 2

   SEND_ERROR                 = 3

   USER_CANCELED              = 4

   OTHERS                     = 5

          .

IF SY-SUBRC <> 0.

* Implement suitable error handling here

ENDIF.

*

*CALL FUNCTION FUN_NAME

*  EXPORTING

**CONTROL_PARAMETERS             = LW_SSFCTRLOP

*    wa_ekko                    = WA_EKKO

*IMPORTING

**  JOB_OUTPUT_INFO              = LT_SSFCRESCL

**  tables

*    it_ekpo                    = IT_EKPO

* EXCEPTIONS

*   FORMATTING_ERROR           = 1

*   INTERNAL_ERROR             = 2

*   SEND_ERROR                 = 3

*   USER_CANCELED              = 4

*   OTHERS                     = 5

*          .

*IF sy-subrc <> 0.

** Implement suitable error handling here

*ENDIF.

ENDFORM.

*" FOR GOING TO PRINT

*

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

   FORMAT                      = 'PDF'

*

IMPORTING

   BIN_FILESIZE                = L_BINSIZE

*

  TABLES

    OTF                         = LT_SSFCRESCL-OTFDATA

    LINES                       = LT_LINES

EXCEPTIONS

   ERR_MAX_LINEWIDTH           = 1

   ERR_FORMAT                  = 2

   ERR_CONV_NOT_POSSIBLE       = 3

   ERR_BAD_OTF                 = 4

   OTHERS                      = 5

         .

IF SY-SUBRC <> 0.

* Implement suitable error handling here

ENDIF.

CALL FUNCTION 'F4_FILENAME'

IMPORTING

  FILE_NAME           = V_FNAME

          .

L_FNAME = V_FNAME.

CALL FUNCTION 'GUI_DOWNLOAD'

  EXPORTING

  BIN_FILESIZE                     = L_BINSIZE

    FILENAME                        = L_FNAME

   FILETYPE                        = 'BIN '

*   APPEND                          = ' '

*   WRITE_FIELD_SEPARATOR           = ' '

*   HEADER                          = '00'

*   TRUNC_TRAILING_BLANKS           = ' '

*   WRITE_LF                        = 'X'

*   COL_SELECT                      = ' '

*   COL_SELECT_MASK                 = ' '

*   DAT_MODE                        = ' '

*   CONFIRM_OVERWRITE               = ' '

*   NO_AUTH_CHECK                   = ' '

*   CODEPAGE                        = ' '

*   IGNORE_CERR                     = ABAP_TRUE

*   REPLACEMENT                     = '#'

*   WRITE_BOM                       = ' '

*   TRUNC_TRAILING_BLANKS_EOL       = 'X'

*   WK1_N_FORMAT                    = ' '

*   WK1_N_SIZE                      = ' '

*   WK1_T_FORMAT                    = ' '

*   WK1_T_SIZE                      = ' '

*   WRITE_LF_AFTER_LAST_LINE        = ABAP_TRUE

*   SHOW_TRANSFER_STATUS            = ABAP_TRUE

*   VIRUS_SCAN_PROFILE              = '/SCET/GUI_DOWNLOAD'

* IMPORTING

*   FILELENGTH                      =

  TABLES

    DATA_TAB                        = LT_LINES

*   FIELDNAMES                      =

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.

* Implement suitable error handling here

ENDIF.

ENDFORM.

*form STD_FUN .

*CALL FUNCTION  '/1BCDWB/SF00000289'

*  EXPORTING

*

*    wa_ekko                    = WA_EKKO

*

*  tables

*    it_ekpo                    = IT_EKPO[]

* EXCEPTIONS

*   FORMATTING_ERROR           = 1

*   INTERNAL_ERROR             = 2

*   SEND_ERROR                 = 3

*   USER_CANCELED              = 4

*   OTHERS                     = 5

*          .

*IF sy-subrc <> 0.

** Implement suitable error handling here

*ENDIF.

*ENDFORM.

Hope it is helpful for you..

Regards,

Srilatha S