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

Convert internal table to PDF send mail using oops abap

former_member224444
Participant
0 Likes
8,941

Hi Guru's,

I got a requirement to develop a report , i have done it,  they want to send this report as excel attachment after clicking a  button and pdf attachment after clicking a button. I have done excel attachment part, which is working fine. But when i tried below coding for sending PDF attachment i am getting error "adobe reader could not open because it is either not a supported file type or because file has been damaged(for example, it was sent as an email attachment and was'nt correctly decoded".   Below is my code:

DATA: L_SEND_REQUEST TYPE REF TO CL_BCS,

       L_DOCUMENT TYPE REF TO CL_DOCUMENT_BCS,

       L_RECIPIENT TYPE REF TO IF_RECIPIENT_BCS,

       L_SENDER TYPE REF TO IF_SENDER_BCS,

       L_UNAME TYPE SALRTDRCPT,

       L_BCS_EXCEPTION TYPE REF TO CX_DOCUMENT_BCS,

       L_ADDRESS_EXCEPTION TYPE REF TO CX_ADDRESS_BCS,

       L_SENDER_EXCEPTION TYPE REF TO CX_SEND_REQ_BCS.

DATA: L_TEXT(100) TYPE C,

       WA_SUBJECT TYPE SO_OBJ_DES.

DATA: LT_OBJBIN TYPE STRING,

       LT_OBJBIN1 TYPE SOLIX_TAB,

       SIZE TYPE SO_OBJ_LEN,

       I_CONTENT TYPE SOLI_TAB.

DATA: C_TAB(1) TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,

       C_CR(1) TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF,

       C_EXT TYPE SOODK-OBJTP VALUE 'PDF',

       C_BODY TYPE STRING VALUE 'Packing Machine wise confirmation Vs Warehouse Receipt Report',

       c_raw(3) type c value 'RAW',

       C_X(1) TYPE C VALUE 'X',

       C_U(1) TYPE C VALUE 'U'.

CONCATENATE 'ZPP01' ' '

             S_BUDAT-LOW+6(2) '.' S_BUDAT-LOW+4(2) '.' S_BUDAT-LOW(4) '-'

             S_BUDAT-HIGH+6(2) '.' S_BUDAT-HIGH+4(2) '.' S_BUDAT-HIGH(4) INTO  WA_SUBJECT.

             MOVE C_BODY TO L_TEXT.

             APPEND L_TEXT TO I_CONTENT.

             CLEAR L_TEXT.

        WA_MAIL-BUDAT = 'Date'.

        WA_MAIL-PLNBEZ = 'Material'.

        WA_MAIL-MAKTX = 'Material Description'.

        WA_MAIL-GMNGA = 'Packing Machinwise confirmation'.

        WA_MAIL-GMEIN = 'UOM'.

        WA_MAIL-MT    = 'MT'.

        WA_MAIL-MENGE = 'Warehouse Reciept'.

        WA_MAIL-MEINS = 'UOM'.

        WA_MAIL-MT1  = 'MT'.

        WA_MAIL-DIF  = 'Difference'.

        WA_MAIL-MT2  = 'MT'.

        APPEND WA_MAIL TO IT_MAIL.

        CLEAR WA_MAIL.

        LOOP AT IT_FINAL INTO WA_FINAL.

        WA_MAIL-BUDAT = WA_FINAL-BUDAT.

        WA_MAIL-PLNBEZ = WA_FINAL-PLNBEZ.

        WA_MAIL-MAKTX = WA_FINAL-MAKTX.

        WA_MAIL-GMNGA = WA_FINAL-GMNGA.

        WA_MAIL-GMEIN = WA_FINAL-GMEIN.

        WA_MAIL-MT    = WA_FINAL-MT.

        WA_MAIL-MENGE = WA_FINAL-MENGE.

        WA_MAIL-MEINS WA_FINAL-MEINS.

        WA_MAIL-MT1  WA_FINAL-MT1.

        WA_MAIL-DIF  WA_FINAL-DIF.

        WA_MAIL-MT2  WA_FINAL-MT2.

        APPEND WA_MAIL TO IT_MAIL.

        CLEAR: WA_MAIL.

        ENDLOOP.

        LOOP AT IT_MAIL INTO WA_MAIL.

        CONCATENATE LT_OBJBIN WA_MAIL-BUDAT C_TAB

        WA_MAIL-PLNBEZ C_TAB

        WA_MAIL-MAKTX C_TAB

        WA_MAIL-GMNGA C_TAB

        WA_MAIL-GMEIN C_TAB

        WA_MAIL-MT C_TAB

        WA_MAIL-MENGE C_TAB

        WA_MAIL-MEINS C_TAB

        WA_MAIL-MT1 C_TAB

        WA_MAIL-DIF C_TAB

        WA_MAIL-MT2 C_TAB

        C_CR INTO LT_OBJBIN.

        ENDLOOP.

        TRY.

            CALL METHOD CL_BCS_CONVERT=>STRING_TO_SOLIX

          EXPORTING

            IV_STRING   = LT_OBJBIN

            IV_CODEPAGE = '4103'

            IV_ADD_BOM  = 'X'

          IMPORTING

            ET_SOLIX    = LT_OBJBIN1

            EV_SIZE     = SIZE.

         CATCH CX_BCS .

        ENDTRY.

         TRY.

          L_SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).

             L_DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(

                 I_TYPE        = C_RAW

                 I_SUBJECT     = WA_SUBJECT

                 I_TEXT        = I_CONTENT[] ).

              L_DOCUMENT->ADD_ATTACHMENT(

                 I_ATTACHMENT_TYPE     = C_EXT

                 I_ATTACHMENT_SUBJECT  = WA_SUBJECT

                 I_ATTACHMENT_SIZE     = SIZE

                 I_ATT_CONTENT_HEX     = LT_OBJBIN1 ).

              CALL METHOD L_SEND_REQUEST->SET_DOCUMENT( L_DOCUMENT ).

              L_UNAME = SY-UNAME.

              L_SENDER = CL_SAPUSER_BCS=>CREATE( L_UNAME ).

              CALL METHOD L_SEND_REQUEST->SET_SENDER

                EXPORTING

                  I_SENDER = L_SENDER.

              l_recipient = CL_DISTRIBUTIONLIST_BCS=>GETU_PERSISTENT(

                                 I_DLINAME = 'ZPP01'

                                 I_PRIVATE = SPACE ).

              CALL METHOD L_SEND_REQUEST->ADD_RECIPIENT

                EXPORTING

                  I_RECIPIENT  = l_recipient

*                 I_EXPRESS    =

                  I_COPY       = ' '

                  I_BLIND_COPY = ' '

                  I_NO_FORWARD = ' '.

                CLEAR: WA_MAIL.

                 L_SEND_REQUEST->SET_SEND_IMMEDIATELY( C_X ).

                 CALL METHOD L_SEND_REQUEST->SEND( ).

                  COMMIT WORK.

                  IF SY-SUBRC EQ 0.

                    MESSAGE 'Mail sent successfully' TYPE 'S'.

                    ENDIF.

                  CATCH CX_DOCUMENT_BCS INTO L_BCS_EXCEPTION.

                  CATCH CX_ADDRESS_BCS INTO L_ADDRESS_EXCEPTION.

                  CATCH CX_SEND_REQ_BCS INTO L_SENDER_EXCEPTION.

                    ENDTRY.

same code instead of 'PDF' extension i have used as 'XLS' extension it is working fine, it is send attachment as excel, but it is not working for PDF. Please tell me whether am missing any formatting for PDF.

Regards,

Rithika.

1 ACCEPTED SOLUTION
Read only

Aashish28
Contributor
0 Likes
7,979

Hii Rithika ,

                    May i know is it classical means - basic list report or ALV ????

Hi Guru's,

I got a requirement to develop a report , i have done it,  they want to send this report as excel attachment after clicking a  button and pdf attachment after clicking a button. I have done excel attachment part, which is working fine. But when i tried below coding for sending PDF attachment i am getting error "adobe reader could not open because it is either not a supported file type or because file has been damaged(for example, it was sent as an email attachment and was'nt correctly decoded".   Below is my code:

DATA: L_SEND_REQUEST TYPE REF TO CL_BCS,

       L_DOCUMENT TYPE REF TO CL_DOCUMENT_BCS,

       L_RECIPIENT TYPE REF TO IF_RECIPIENT_BCS,

       L_SENDER TYPE REF TO IF_SENDER_BCS,

       L_UNAME TYPE SALRTDRCPT,

       L_BCS_EXCEPTION TYPE REF TO CX_DOCUMENT_BCS,

       L_ADDRESS_EXCEPTION TYPE REF TO CX_ADDRESS_BCS,

       L_SENDER_EXCEPTION TYPE REF TO CX_SEND_REQ_BCS.

DATA: L_TEXT(100) TYPE C,

       WA_SUBJECT TYPE SO_OBJ_DES.

DATA: LT_OBJBIN TYPE STRING,

       LT_OBJBIN1 TYPE SOLIX_TAB,

       SIZE TYPE SO_OBJ_LEN,

       I_CONTENT TYPE SOLI_TAB.

DATA: C_TAB(1) TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,

       C_CR(1) TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF,

       C_EXT TYPE SOODK-OBJTP VALUE 'PDF',

       C_BODY TYPE STRING VALUE 'Packing Machine wise confirmation Vs Warehouse Receipt Report',

       c_raw(3) type c value 'RAW',

       C_X(1) TYPE C VALUE 'X',

       C_U(1) TYPE C VALUE 'U'.

CONCATENATE 'ZPP01' ' '

             S_BUDAT-LOW+6(2) '.' S_BUDAT-LOW+4(2) '.' S_BUDAT-LOW(4) '-'

             S_BUDAT-HIGH+6(2) '.' S_BUDAT-HIGH+4(2) '.' S_BUDAT-HIGH(4) INTO  WA_SUBJECT.

             MOVE C_BODY TO L_TEXT.

             APPEND L_TEXT TO I_CONTENT.

             CLEAR L_TEXT.

        WA_MAIL-BUDAT = 'Date'.

        WA_MAIL-PLNBEZ = 'Material'.

        WA_MAIL-MAKTX = 'Material Description'.

        WA_MAIL-GMNGA = 'Packing Machinwise confirmation'.

        WA_MAIL-GMEIN = 'UOM'.

        WA_MAIL-MT    = 'MT'.

        WA_MAIL-MENGE = 'Warehouse Reciept'.

        WA_MAIL-MEINS = 'UOM'.

        WA_MAIL-MT1  = 'MT'.

        WA_MAIL-DIF  = 'Difference'.

        WA_MAIL-MT2  = 'MT'.

        APPEND WA_MAIL TO IT_MAIL.

        CLEAR WA_MAIL.

        LOOP AT IT_FINAL INTO WA_FINAL.

        WA_MAIL-BUDAT = WA_FINAL-BUDAT.

        WA_MAIL-PLNBEZ = WA_FINAL-PLNBEZ.

        WA_MAIL-MAKTX = WA_FINAL-MAKTX.

        WA_MAIL-GMNGA = WA_FINAL-GMNGA.

        WA_MAIL-GMEIN = WA_FINAL-GMEIN.

        WA_MAIL-MT    = WA_FINAL-MT.

        WA_MAIL-MENGE = WA_FINAL-MENGE.

        WA_MAIL-MEINS WA_FINAL-MEINS.

        WA_MAIL-MT1  WA_FINAL-MT1.

        WA_MAIL-DIF  WA_FINAL-DIF.

        WA_MAIL-MT2  WA_FINAL-MT2.

        APPEND WA_MAIL TO IT_MAIL.

        CLEAR: WA_MAIL.

        ENDLOOP.

        LOOP AT IT_MAIL INTO WA_MAIL.

        CONCATENATE LT_OBJBIN WA_MAIL-BUDAT C_TAB

        WA_MAIL-PLNBEZ C_TAB

        WA_MAIL-MAKTX C_TAB

        WA_MAIL-GMNGA C_TAB

        WA_MAIL-GMEIN C_TAB

        WA_MAIL-MT C_TAB

        WA_MAIL-MENGE C_TAB

        WA_MAIL-MEINS C_TAB

        WA_MAIL-MT1 C_TAB

        WA_MAIL-DIF C_TAB

        WA_MAIL-MT2 C_TAB

        C_CR INTO LT_OBJBIN.

        ENDLOOP.

        TRY.

            CALL METHOD CL_BCS_CONVERT=>STRING_TO_SOLIX

          EXPORTING

            IV_STRING   = LT_OBJBIN

            IV_CODEPAGE = '4103'

            IV_ADD_BOM  = 'X'

          IMPORTING

            ET_SOLIX    = LT_OBJBIN1

            EV_SIZE     = SIZE.

         CATCH CX_BCS .

        ENDTRY.

         TRY.

          L_SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).

             L_DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(

                 I_TYPE        = C_RAW

                 I_SUBJECT     = WA_SUBJECT

                 I_TEXT        = I_CONTENT[] ).

              L_DOCUMENT->ADD_ATTACHMENT(

                 I_ATTACHMENT_TYPE     = C_EXT

                 I_ATTACHMENT_SUBJECT  = WA_SUBJECT

                 I_ATTACHMENT_SIZE     = SIZE

                 I_ATT_CONTENT_HEX     = LT_OBJBIN1 ).

              CALL METHOD L_SEND_REQUEST->SET_DOCUMENT( L_DOCUMENT ).

              L_UNAME = SY-UNAME.

              L_SENDER = CL_SAPUSER_BCS=>CREATE( L_UNAME ).

              CALL METHOD L_SEND_REQUEST->SET_SENDER

                EXPORTING

                  I_SENDER = L_SENDER.

              l_recipient = CL_DISTRIBUTIONLIST_BCS=>GETU_PERSISTENT(

                                 I_DLINAME = 'ZPP01'

                                 I_PRIVATE = SPACE ).

              CALL METHOD L_SEND_REQUEST->ADD_RECIPIENT

                EXPORTING

                  I_RECIPIENT  = l_recipient

*                 I_EXPRESS    =

                  I_COPY       = ' '

                  I_BLIND_COPY = ' '

                  I_NO_FORWARD = ' '.

                CLEAR: WA_MAIL.

                 L_SEND_REQUEST->SET_SEND_IMMEDIATELY( C_X ).

                 CALL METHOD L_SEND_REQUEST->SEND( ).

                  COMMIT WORK.

                  IF SY-SUBRC EQ 0.

                    MESSAGE 'Mail sent successfully' TYPE 'S'.

                    ENDIF.

                  CATCH CX_DOCUMENT_BCS INTO L_BCS_EXCEPTION.

                  CATCH CX_ADDRESS_BCS INTO L_ADDRESS_EXCEPTION.

                  CATCH CX_SEND_REQ_BCS INTO L_SENDER_EXCEPTION.

                    ENDTRY.

same code instead of 'PDF' extension i have used as 'XLS' extension it is working fine, it is send attachment as excel, but it is not working for PDF. Please tell me whether am missing any formatting for PDF.

Regards,

Rithika.

38 REPLIES 38
Read only

Former Member
0 Likes
7,979

Hi,

Go to SU01, Go Default->Spool control. Then select output device and put any printer preference. If this spool request is empty, the pdf will show it corrupt.

Please check the below link related to your problem

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

Thanks

Mani

Read only

0 Likes
7,979

Dear Nagamani,

Thanks for the reply but my output device is not empty, and the link which you have provided explains about converting smartforms to pdf, my case is converting internal table to pdf and send mail.

Regards,

Rithika.

Read only

0 Likes
7,979

Hi Rithika ,

I just gave you the hint not exact solution.

May be this problem is because of settiings only as per above thread i mention it's not a matter of Smartform or Report.

Please Do Some R&D and check.

Thanks

Mani

Read only

0 Likes
7,979

Yes i checked in Default tab of SU01, output device is there so conifigwise it is correct.

Read only

Aashish28
Contributor
0 Likes
7,980

Hii Rithika ,

                    May i know is it classical means - basic list report or ALV ????

Read only

0 Likes
7,979

Dear Ashish,

It is ALV Grid Report.

Read only

0 Likes
7,979

Hiii Rithika,

                   See my below example code - RUN it and see SBWP

Note : In below code is my temp code so that's why it contain some unused variable soo please remove it and also page size also set as per your requirement .

Still you face any problem than you can ask again

TYPE-POOLS:slis.

DATA: lv_buffer TYPE string,
       lt_mess_att TYPE TABLE OF solisti1 ,
       ls_mess_att TYPE solisti1.
CONSTANTS c_container TYPE c LENGTH 30 VALUE 'CC'.
CONSTANTS c_col1 TYPE c LENGTH 2 VALUE ' ~'.
CONSTANTS c_col2 TYPE c LENGTH 2 VALUE '~ '.
CONSTANTS c_255 TYPE i VALUE 255.
data p_recpnt TYPE sy-uname .

  p_recpnt = sy-uname.

DATA : l_ref_bcs TYPE REF TO cl_bcs,
l_ref_document TYPE REF TO cl_document_bcs,
l_ref_recipient TYPE REF TO if_recipient_bcs,
l_ref_bcs_exception TYPE REF TO cx_bcs,
lv_sent_to_all TYPE os_boolean,
lv_filesize TYPE so_obj_len,
lv_doclines TYPE i,
lv_last_line TYPE i,
lv_text TYPE so_obj_des,
lv_data TYPE bcsy_text,
lv_size TYPE i,
gt_fcat TYPE lvc_t_fcat.

TYPES: ty_t_pdf TYPE STANDARD TABLE OF tline.
DATA: lt_pdf_output TYPE ty_t_pdf,
       ls_pdf_output TYPE tline.

DATA:i_t001 TYPE t001 OCCURS 0,
      g_spool   TYPE tsp01-rqident,
      g_program TYPE sy-repid VALUE sy-repid.

DATA: w_print TYPE slis_print_alv,
       w_print_ctrl TYPE alv_s_pctl.


START-OF-SELECTION.
   SELECT * FROM t001 INTO TABLE i_t001 UP TO 100 ROWS.

     CALL FUNCTION 'SET_PRINT_PARAMETERS'
     EXPORTING
       destination = 'LOCL' " Printer
       layout      = 'X_65_512/2' "Format
       line_count  = '65' "Line Count
       line_size   = '1024'. "Line Size

   w_print-print = 'X'.

   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
     EXPORTING
       i_callback_program = g_program
       i_structure_name   = 'T001'
       is_print           = w_print
     TABLES
       t_outtab           = i_t001.
   IF sy-subrc <> 0.
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   ELSE.


  data: GET_SIZE_FROM_FORMAT VALUE 'X'.

     g_spool = sy-spono.

   CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
     EXPORTING
       src_spoolid                    = g_spool "Spool Number
       no_dialog                      = space
       dst_device                     = 'LOCL' "Printer Name
       GET_SIZE_FROM_FORMAT           = GET_SIZE_FROM_FORMAT
       importing
       pdf_bytecount         =        lv_size "Output Size

       tables
         pdf                      = lt_pdf_output "Spool data in PDF Format
       exceptions
         err_no_abap_spooljob = 1
       err_no_spooljob                = 2
       err_no_permission              = 3
       err_conv_not_possible          = 4
       err_bad_destdevice             = 5
       user_cancelled                 = 6
       err_spoolerror                 = 7
       err_temseerror                 = 8
       err_btcjob_open_failed         = 9.
   IF sy-subrc EQ 0.
     LOOP AT lt_pdf_output INTO ls_pdf_output.
       TRANSLATE ls_pdf_output USING c_col1.
       CONCATENATE lv_buffer ls_pdf_output INTO lv_buffer.
       CLEAR ls_pdf_output.
     ENDLOOP.
     TRANSLATE lv_buffer USING c_col2.
     DO.
       ls_mess_att = lv_buffer.
       APPEND ls_mess_att TO lt_mess_att.
       SHIFT lv_buffer LEFT BY c_255 PLACES.
       IF lv_buffer IS INITIAL.
         EXIT.
       ENDIF.
       CLEAR ls_mess_att.
     ENDDO.
   ENDIF.
*--create reference object
   TRY.
       l_ref_bcs = cl_bcs=>create_persistent( ).
       lv_text = 'Mail Subject' .
       APPEND 'Mail Content' TO lv_data.
       l_ref_document = cl_document_bcs=>create_document(
       i_type = 'RAW'
       i_text = lv_data
       i_subject = lv_text ).
* *--create document reference
       lv_filesize = lv_size.
       CALL METHOD l_ref_document->add_attachment
         EXPORTING
           i_attachment_type    = 'PDF'
           i_attachment_size    = lv_filesize
           i_attachment_subject = lv_text
           i_att_content_text   = lt_mess_att[].
* set the document
       l_ref_bcs->set_document( l_ref_document ).
* create recipient
*      p_recpnt = sap INBOX user ID to WHICH the ATTACHMENT is SENT.
       l_ref_recipient = cl_sapuser_bcs=>create( p_recpnt ).
*adding recipient in to section
       l_ref_bcs->add_recipient( l_ref_recipient ).

* send mail
       CALL METHOD l_ref_bcs->send(
       EXPORTING i_with_error_screen = 'X'
       RECEIVING
       result = lv_sent_to_all ).
       IF lv_sent_to_all = 'X'.
       ENDIF.
     CATCH cx_bcs INTO l_ref_bcs_exception.
       IF l_ref_bcs_exception IS NOT INITIAL.
         CLEAR l_ref_bcs_exception.
       ENDIF.
   ENDTRY.

   COMMIT WORK.

   endif.
Read only

0 Likes
7,979

Dear Ashish,

I have used your code, it says error "spool request does not exist" , i am not storing my report as background job, there will not be spool request rite.

Read only

0 Likes
7,979

Hiii,

         it is not for background job,  btw When you run this code in foreground mode one popup will come (printer popup) please enter printer name (ex. - LP01 or take from F4 ) and (have you press ok ?) press enter or ok than you can see status bar PDF conversion is running and you can see in SBWP . t just put break point after REUSE_ALV_GRID_DISPLAY debugg it and see it sy-spono.

Read only

0 Likes
7,979

It is not showing any popup, First i commented 'REUSE_ALV_GRID_DISPLAY' because i already displayed the alv grid using set_table_first_display, now i just uncommented and tested whether popup is coming or not, i got dump error that fiedcat is not assigned.

Read only

0 Likes
7,979

Hiii,

        Yes definitely dump will occur , as you told me you have separate button for sending alv as PDF ok , so on click event of that button

ex. -

if sy-ucomm = 'PDF'.

        w_print-print = 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' " Call this function again
          EXPORTING
            i_callback_program = g_program
            i_structure_name   = 'T001'
           is_print           = w_print       "
but this time with print

          TABLES
            t_outtab           = i_t001.

" rest of process i have already mentioned

perform send_email.

endif.

" Hope now you got it

Read only

0 Likes
7,979

Thanks for your efforst Ashish,

But still am getting the dump error "NO_FIELDCATALOG_AVAILABLE",  for your better understanding i will explain what i did.

1)  After giving input in the selection screen, am displaying the ALV GRID.

2)  I have two buttons "Send as excel" and "Send as PDF"in top of the alv, which i created using 'toolbar' event of cl_gui_alv_grid class.

3) When i click send as excel i call subroutine inside that i wrote the coding which i told above in my first post, extension is 'XLS'.

4)  Same i tried for PDF it is not working, these process happens after alv is displayed, so if call the FM REUSE_ALV_GRID_DISPLAY again without using fiedcat with using w_print, than also it is showing error.

Please help

Read only

0 Likes
7,979

Hiii,

         ok use this code -  just make  PF status ZOF other wise no PF status will set ok

Try hope this time you will get success

TYPE-POOLS:slis.

      DATA: lv_buffer TYPE string,
            lt_mess_att TYPE TABLE OF solisti1 ,
            ls_mess_att TYPE solisti1.
      CONSTANTS c_container TYPE c LENGTH 30 VALUE 'CC'.
      CONSTANTS c_col1 TYPE c LENGTH 2 VALUE ' ~'.
      CONSTANTS c_col2 TYPE c LENGTH 2 VALUE '~ '.
      CONSTANTS c_255 TYPE i VALUE 255.
      data p_recpnt TYPE sy-uname .

       p_recpnt = sy-uname.

      DATA : l_ref_bcs TYPE REF TO cl_bcs,
      l_ref_document TYPE REF TO cl_document_bcs,
      l_ref_recipient TYPE REF TO if_recipient_bcs,
      l_ref_bcs_exception TYPE REF TO cx_bcs,
      lv_sent_to_all TYPE os_boolean,
      lv_filesize TYPE so_obj_len,
      lv_doclines TYPE i,
      lv_last_line TYPE i,
      lv_text TYPE so_obj_des,
      lv_data TYPE bcsy_text,
      lv_size TYPE i,
      gt_fcat TYPE lvc_t_fcat.

      TYPES: ty_t_pdf TYPE STANDARD TABLE OF tline.
      DATA: lt_pdf_output TYPE ty_t_pdf,
            ls_pdf_output TYPE tline.

      DATA:i_t001 TYPE t001 OCCURS 0,
           g_spool   TYPE tsp01-rqident,
           g_program TYPE sy-repid VALUE sy-repid.

      DATA: w_print TYPE slis_print_alv,
            w_print_ctrl TYPE alv_s_pctl.


      START-OF-SELECTION.
        SELECT * FROM t001 INTO TABLE i_t001 UP TO 100 ROWS.

          CALL FUNCTION 'SET_PRINT_PARAMETERS'
          EXPORTING
            destination = 'LOCL' " Printer
            layout      = 'X_65_512/2' "Format
            line_count  = '65' "Line Count
            line_size   = '1024'. "Line Size

        w_print-print = 'X'.

        CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
          EXPORTING
            i_callback_program = g_program
            i_structure_name   = 'T001'
             i_callback_pf_status_set          = 'PF'
             i_callback_user_command           = 'USER_COMMAND' " for User-Command
*           is_print           = w_print
          TABLES
            t_outtab           = i_t001.
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

        endif.

FORM pf USING rt_extab TYPE slis_t_extab.
   SET PF-STATUS 'ZOF'.
ENDFORM.                    "pf

FORM user_command USING lv_okcode LIKE sy-ucomm l_selfield TYPE slis_selfield.

* assign the function code to variable v_okcode
   lv_okcode = sy-ucomm.

* handle the code execution based on the function code encountered
   CASE lv_okcode.

     WHEN 'PDF'. "<--to handle user actions
w_print-PRINT = 'X'.

             CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
          EXPORTING
*           i_callback_program = g_program
            i_structure_name   = 'T001'
             i_callback_user_command           = 'USER_COMMAND' " for User-Command
            is_print           = w_print
          TABLES
            t_outtab           = i_t001.
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ELSE.


       data: GET_SIZE_FROM_FORMAT VALUE 'X'.

          g_spool = sy-spono.

        CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
          EXPORTING
            src_spoolid                    = g_spool "Spool Number
            no_dialog                      = space
            dst_device                     = 'LOCL' "Printer Name
            GET_SIZE_FROM_FORMAT           = GET_SIZE_FROM_FORMAT
            importing
            pdf_bytecount         =        lv_size "Output Size

            tables
              pdf                      = lt_pdf_output "Spool data in PDF Format
            exceptions
              err_no_abap_spooljob = 1
            err_no_spooljob                = 2
            err_no_permission              = 3
            err_conv_not_possible          = 4
            err_bad_destdevice             = 5
            user_cancelled                 = 6
            err_spoolerror                 = 7
            err_temseerror                 = 8
            err_btcjob_open_failed         = 9.
        IF sy-subrc EQ 0.
          LOOP AT lt_pdf_output INTO ls_pdf_output.
            TRANSLATE ls_pdf_output USING c_col1.
            CONCATENATE lv_buffer ls_pdf_output INTO lv_buffer.
            CLEAR ls_pdf_output.
          ENDLOOP.
          TRANSLATE lv_buffer USING c_col2.
          DO.
            ls_mess_att = lv_buffer.
            APPEND ls_mess_att TO lt_mess_att.
            SHIFT lv_buffer LEFT BY c_255 PLACES.
            IF lv_buffer IS INITIAL.
              EXIT.
            ENDIF.
            CLEAR ls_mess_att.
          ENDDO.
        ENDIF.
*--create reference object
        TRY.
            l_ref_bcs = cl_bcs=>create_persistent( ).
            lv_text = 'Mail Subject' .
            APPEND 'Mail Content' TO lv_data.
            l_ref_document = cl_document_bcs=>create_document(
            i_type = 'RAW'
            i_text = lv_data
            i_subject = lv_text ).
* *--create document reference
            lv_filesize = lv_size.
            CALL METHOD l_ref_document->add_attachment
              EXPORTING
                i_attachment_type    = 'PDF'
                i_attachment_size    = lv_filesize
                i_attachment_subject = lv_text
                i_att_content_text   = lt_mess_att[].
*     * set the document
            l_ref_bcs->set_document( l_ref_document ).
*     * create recipient
*     *      p_recpnt = sap INBOX user ID to WHICH the ATTACHMENT is SENT.
            l_ref_recipient = cl_sapuser_bcs=>create( p_recpnt ).
*     *adding recipient in to section
            l_ref_bcs->add_recipient( l_ref_recipient ).

*     * send mail
            CALL METHOD l_ref_bcs->send(
            EXPORTING i_with_error_screen = 'X'
            RECEIVING
            result = lv_sent_to_all ).
            IF lv_sent_to_all = 'X'.
            ENDIF.
          CATCH cx_bcs INTO l_ref_bcs_exception.
            IF l_ref_bcs_exception IS NOT INITIAL.
              CLEAR l_ref_bcs_exception.
            ENDIF.
        ENDTRY.

        COMMIT WORK.

        endif.

   ENDCASE.

ENDFORM.                    "USER_COMMAND

Read only

0 Likes
7,979

Hiiii,

        ok no problem if you use cl_gui_alv_grid method set_table_for_first_display it also contain is_print parameter either you can set it and when you press toolbar button handle  function code of button in method handle_user_command (for ex. see - BCALV_GRID_05 ) and call set_table_for_first_display again but with is_print parameter

or you can use REUSE_ALV_GRID_DISPLAY it depends on you .

if you told earlier than i gave my last replay with cl_gui_alv_grid anyways you can try this with my last reply

Read only

0 Likes
7,979

Sorry Ashish,

Again same error

Exception condition "NO_FIELDCATALOG_AVAILABLE" raised, i have did exactly what you told, it is not accepting reuse_alv_grid_display without fieldcat.

Regards,

Rithika

Read only

0 Likes
7,979

Hiiii,

        Hiiii have you run my code in separate program ????? Please can you show your code ????

Read only

0 Likes
7,979

Hiiii,

         I have checked with cl_gui_alv_grid it is working fine on my system , in debugg mode check your field catalog will be empty when you call this alv again with print on click event . one thing you do

open program - BCALV_GRID_05 make copy ZBCALV_GRID_05  ok and on ok_code  BOOKINGS

comment code and write below code

w_print = 'X'.

          CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
          EXPORTING
*           i_callback_program = g_program
            i_structure_name   = 'SFLIGHT'
            is_print           = w_print
          TABLES
            t_outtab           = gt_sflight.

you can see spool will generate and this alv is not overwrite on previous one , than check what mistake you are doing .

after this code you can write send email code also .


Read only

0 Likes
7,979

Ashish, Same error coming for set_table_for_first_display also, it will also not allow without fieldcat.

Read only

0 Likes
7,979

Hiiii,

        Please can your show your code so that i can find at where you made mistake. please check whether fieldcatalog is empty or not in debug mode ??? or if it is empty then please fill it again before pressing PDF button otherwise you will get same error .

Read only

0 Likes
7,979

Dear Ashish,

Even if we pass and fill the fiedlcat you are not passing the fieldcat to this function module, so surly it will go for dump.

Regards,

Rithika

Read only

0 Likes
7,979

Hiii rithika ,

                   It will work with fieldcatalog also , just copy this code in one new z report and make PF status with one button with fcode - PDF and run this report it will send pdf in SBWP.

And one more thing you are using set_table_for_first_display method ok so when you press PDF button just fill fieldcatalog and pass it to REUSE_ALV_GRID_DISPLAY and follow same code you will get perfect PDF .

Try this meanwhile i am converting this code for cl_gui_alv_grid


TYPE-POOLS:slis.

DATA : fieldcatalog          TYPE slis_t_fieldcat_alv WITH HEADER LINE.    " For Field Catalog

DATA: lv_buffer TYPE string,
       lt_mess_att TYPE TABLE OF solisti1 ,
       ls_mess_att TYPE solisti1.
CONSTANTS c_container TYPE c LENGTH 30 VALUE 'CC'.
CONSTANTS c_col1 TYPE c LENGTH 2 VALUE ' ~'.
CONSTANTS c_col2 TYPE c LENGTH 2 VALUE '~ '.
CONSTANTS c_255 TYPE i VALUE 255.
data p_recpnt TYPE sy-uname .

p_recpnt = sy-uname.

DATA : l_ref_bcs TYPE REF TO cl_bcs,
l_ref_document TYPE REF TO cl_document_bcs,
l_ref_recipient TYPE REF TO if_recipient_bcs,
l_ref_bcs_exception TYPE REF TO cx_bcs,
lv_sent_to_all TYPE os_boolean,
lv_filesize TYPE so_obj_len,
lv_doclines TYPE i,
lv_last_line TYPE i,
lv_text TYPE so_obj_des,
lv_data TYPE bcsy_text,
lv_size TYPE i,
gt_fcat TYPE lvc_t_fcat.

TYPES: ty_t_pdf TYPE STANDARD TABLE OF tline.
DATA: lt_pdf_output TYPE ty_t_pdf,
       ls_pdf_output TYPE tline.

TYPES : BEGIN OF ty_t001,
          BUKRS type  t001-BUKRS  ,
BUTXT type  t001-BUTXT  ,
ORT01 type  t001-ORT01  ,
LAND1 type  t001-LAND1  ,
WAERS type  t001-WAERS  ,
SPRAS type  t001-SPRAS  ,

         END OF ty_t001.

DATA:i_t001 TYPE ty_t001 OCCURS 0,
      g_spool   TYPE tsp01-rqident,
      g_program TYPE sy-repid VALUE sy-repid.

DATA: w_print TYPE slis_print_alv,
       w_print_ctrl TYPE alv_s_pctl.


START-OF-SELECTION.
   SELECT * FROM t001 INTO CORRESPONDING FIELDS OF TABLE i_t001 UP TO 100 ROWS.

   CALL FUNCTION 'SET_PRINT_PARAMETERS'
     EXPORTING
       destination = 'LOCL' " Printer
       layout      = 'X_65_512/2' "Format
       line_count  = '65' "Line Count
       line_size   = '1024'. "Line Size

   w_print-print = 'X'.

   PERFORM fild_cat.

   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
     EXPORTING
       i_callback_program       = g_program
*     i_structure_name         = 'T001'
       i_callback_pf_status_set = 'PF'
       i_callback_user_command  = 'USER_COMMAND' " for User-Command
*     is_print                 = w_print
       it_fieldcat              = fieldcatalog[]
     TABLES
       t_outtab                 = i_t001.
   IF sy-subrc <> 0.
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

   endif.

*&---------------------------------------------------------------------*
*&      Form  pf
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->RT_EXTAB   text
*----------------------------------------------------------------------*
FORM pf USING rt_extab TYPE slis_t_extab.
   SET PF-STATUS 'ZOF'.
ENDFORM.                    "pf

*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->LV_OKCODE  text
*      -->L_SELFIELD text
*----------------------------------------------------------------------*
FORM user_command USING lv_okcode LIKE sy-ucomm l_selfield TYPE slis_selfield.

* assign the function code to variable v_okcode
   lv_okcode = sy-ucomm.

* handle the code execution based on the function code encountered
   CASE lv_okcode.
       BREAK-POINT.
     WHEN 'PDF'. "<--to handle user actions
       w_print-PRINT = 'X'.

       CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
         EXPORTING
           i_callback_program      = g_program
*         i_structure_name        = 'T001'
*         i_callback_user_command = 'USER_COMMAND' " for User-Command
           is_print                = w_print
           it_fieldcat             = fieldcatalog[]
         TABLES
           t_outtab                = i_t001.
       IF sy-subrc <> 0.
         MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
       ELSE.


         data: GET_SIZE_FROM_FORMAT VALUE 'X'.

         g_spool = sy-spono.

         CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
           EXPORTING
             src_spoolid            = g_spool "Spool Number
             no_dialog              = space
             dst_device             = 'LOCL' "Printer Name
             GET_SIZE_FROM_FORMAT   = GET_SIZE_FROM_FORMAT
           IMPORTING
             pdf_bytecount          = lv_size "Output Size
           TABLES
             pdf                    = lt_pdf_output "Spool data in PDF Format
           EXCEPTIONS
             err_no_abap_spooljob   = 1
             err_no_spooljob        = 2
             err_no_permission      = 3
             err_conv_not_possible  = 4
             err_bad_destdevice     = 5
             user_cancelled         = 6
             err_spoolerror         = 7
             err_temseerror         = 8
             err_btcjob_open_failed = 9.
         IF sy-subrc EQ 0.
           LOOP AT lt_pdf_output INTO ls_pdf_output.
             TRANSLATE ls_pdf_output USING c_col1.
             CONCATENATE lv_buffer ls_pdf_output INTO lv_buffer.
             CLEAR ls_pdf_output.
           ENDLOOP.
           TRANSLATE lv_buffer USING c_col2.
           DO.
             ls_mess_att = lv_buffer.
             APPEND ls_mess_att TO lt_mess_att.
             SHIFT lv_buffer LEFT BY c_255 PLACES.
             IF lv_buffer IS INITIAL.
               EXIT.
             ENDIF.
             CLEAR ls_mess_att.
           ENDDO.
         ENDIF.
*--create reference object
         TRY.
             l_ref_bcs = cl_bcs=>create_persistent( ).
             lv_text = 'Mail Subject' .
             APPEND 'Mail Content' TO lv_data.
             l_ref_document = cl_document_bcs=>create_document(
             i_type = 'RAW'
             i_text = lv_data
             i_subject = lv_text ).
* *--create document reference
             lv_filesize = lv_size.
             CALL METHOD l_ref_document->add_attachment
               EXPORTING
                 i_attachment_type    = 'PDF'
                 i_attachment_size    = lv_filesize
                 i_attachment_subject = lv_text
                 i_att_content_text   = lt_mess_att[].
*     * set the document
             l_ref_bcs->set_document( l_ref_document ).
*     * create recipient
*     *      p_recpnt = sap INBOX user ID to WHICH the ATTACHMENT is SENT.
             l_ref_recipient = cl_sapuser_bcs=>create( p_recpnt ).
*     *adding recipient in to section
             l_ref_bcs->add_recipient( l_ref_recipient ).

*     * send mail
             CALL METHOD l_ref_bcs->send(
               EXPORTING
                 i_with_error_screen = 'X'
               RECEIVING
                 result              = lv_sent_to_all ).
             IF lv_sent_to_all = 'X'.
             ENDIF.
           CATCH cx_bcs INTO l_ref_bcs_exception.
             IF l_ref_bcs_exception IS NOT INITIAL.
               CLEAR l_ref_bcs_exception.
             ENDIF.
         ENDTRY.

         COMMIT WORK.

       endif.

   ENDCASE.

ENDFORM.                    "USER_COMMAND
*&---------------------------------------------------------------------*
*&      Form  FILD_CAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FILD_CAT .

   fieldcatalog-fieldname   = 'BUKRS'.
   fieldcatalog-tabname     = 'I_T001'.
   fieldcatalog-REF_TABNAME = 'T001'.
   fieldcatalog-just        = 'L'.
   APPEND fieldcatalog TO fieldcatalog.
   CLEAR  fieldcatalog.

   fieldcatalog-fieldname   = 'BUTXT'.
   fieldcatalog-tabname     = 'I_T001'.
   fieldcatalog-REF_TABNAME = 'T001'.
   fieldcatalog-just        = 'L'.
   APPEND fieldcatalog TO fieldcatalog.
   CLEAR  fieldcatalog.

   fieldcatalog-fieldname   = 'ORT01'.
   fieldcatalog-tabname     = 'I_T001'.
   fieldcatalog-REF_TABNAME = 'T001'.
   fieldcatalog-just        = 'L'.
   APPEND fieldcatalog TO fieldcatalog.
   CLEAR  fieldcatalog.


   fieldcatalog-fieldname   = 'LAND1'.
   fieldcatalog-tabname     = 'I_T001'.
   fieldcatalog-REF_TABNAME = 'T001'.
   fieldcatalog-just        = 'L'.
   APPEND fieldcatalog TO fieldcatalog.
   CLEAR  fieldcatalog.


   fieldcatalog-fieldname   = 'SPRAS'.
   fieldcatalog-tabname     = 'I_T001'.
   fieldcatalog-REF_TABNAME = 'T001'.
   fieldcatalog-just        = 'L'.
   APPEND fieldcatalog TO fieldcatalog.
   CLEAR  fieldcatalog.


ENDFORM.                    " FILD_CAT

Read only

0 Likes
7,979

Hiiii Rithika ,

                     Ok i have done with cl_gui_alv_grid now please check my code in separate report and then change in your actual code -

Note : please remove unnecessary variable and do changes as per your requirement .

Help - Custom container name - CUSTOM

          PF STATUS - ZOF with one button PDF


You can see my output with PDF button-

Hope now you got it

TYPE-POOLS:slis.

DATA : fieldcatalog          TYPE slis_t_fieldcat_alv WITH HEADER LINE.    " For Field Catalog
DATA : c_alv TYPE REF TO cl_gui_alv_grid,
        c_cont TYPE REF TO cl_gui_custom_container.

DATA: gt_layout TYPE lvc_s_layo,
       gt_fieldcat TYPE lvc_t_fcat ,
       gw_fieldcat TYPE lvc_s_fcat.

DATA: lv_buffer TYPE string,
       lt_mess_att TYPE TABLE OF solisti1 ,
       ls_mess_att TYPE solisti1.
CONSTANTS c_container TYPE c LENGTH 30 VALUE 'CC'.
CONSTANTS c_col1 TYPE c LENGTH 2 VALUE ' ~'.
CONSTANTS c_col2 TYPE c LENGTH 2 VALUE '~ '.
CONSTANTS c_255 TYPE i VALUE 255.
data p_recpnt TYPE sy-uname .

p_recpnt = sy-uname.

DATA : l_ref_bcs TYPE REF TO cl_bcs,
l_ref_document TYPE REF TO cl_document_bcs,
l_ref_recipient TYPE REF TO if_recipient_bcs,
l_ref_bcs_exception TYPE REF TO cx_bcs,
lv_sent_to_all TYPE os_boolean,
lv_filesize TYPE so_obj_len,
lv_doclines TYPE i,
lv_last_line TYPE i,
lv_text TYPE so_obj_des,
lv_data TYPE bcsy_text,
lv_size TYPE i,
gt_fcat TYPE lvc_t_fcat.

TYPES: ty_t_pdf TYPE STANDARD TABLE OF tline.
DATA: lt_pdf_output TYPE ty_t_pdf,
       ls_pdf_output TYPE tline.

TYPES : BEGIN OF ty_t001,
          BUKRS type  t001-BUKRS  ,
BUTXT type  t001-BUTXT  ,
ORT01 type  t001-ORT01  ,
LAND1 type  t001-LAND1  ,
WAERS type  t001-WAERS  ,
SPRAS type  t001-SPRAS  ,

         END OF ty_t001.

DATA:i_t001 TYPE ty_t001 OCCURS 0,
      g_spool   TYPE tsp01-rqident,
      g_program TYPE sy-repid VALUE sy-repid.

DATA: w_print TYPE slis_print_alv,
       w_print_ctrl TYPE alv_s_pctl.


START-OF-SELECTION.

   SELECT * FROM t001 INTO CORRESPONDING FIELDS OF TABLE i_t001 UP TO 100 ROWS.

call SCREEN 9000.

*&---------------------------------------------------------------------*
*&      Form  FILD_CAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FILD_CAT .

   fieldcatalog-fieldname   = 'BUKRS'.
   fieldcatalog-tabname     = 'I_T001'.
   fieldcatalog-REF_TABNAME = 'T001'.
   fieldcatalog-just        = 'L'.
   APPEND fieldcatalog TO fieldcatalog.
   CLEAR  fieldcatalog.

   fieldcatalog-fieldname   = 'BUTXT'.
   fieldcatalog-tabname     = 'I_T001'.
   fieldcatalog-REF_TABNAME = 'T001'.
   fieldcatalog-just        = 'L'.
   APPEND fieldcatalog TO fieldcatalog.
   CLEAR  fieldcatalog.

   fieldcatalog-fieldname   = 'ORT01'.
   fieldcatalog-tabname     = 'I_T001'.
   fieldcatalog-REF_TABNAME = 'T001'.
   fieldcatalog-just        = 'L'.
   APPEND fieldcatalog TO fieldcatalog.
   CLEAR  fieldcatalog.


   fieldcatalog-fieldname   = 'LAND1'.
   fieldcatalog-tabname     = 'I_T001'.
   fieldcatalog-REF_TABNAME = 'T001'.
   fieldcatalog-just        = 'L'.
   APPEND fieldcatalog TO fieldcatalog.
   CLEAR  fieldcatalog.


   fieldcatalog-fieldname   = 'SPRAS'.
   fieldcatalog-tabname     = 'I_T001'.
   fieldcatalog-REF_TABNAME = 'T001'.
   fieldcatalog-just        = 'L'.
   APPEND fieldcatalog TO fieldcatalog.
   CLEAR  fieldcatalog.


ENDFORM.                    " FILD_CAT
*&---------------------------------------------------------------------*
*&      Module  STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_9000 OUTPUT.

   SET PF-STATUS 'ZOF'.

     IF c_cont IS INITIAL.

     CREATE OBJECT c_cont
       EXPORTING
         container_name = 'CUSTOM'.
     IF sy-subrc <> 0.
       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
       WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
     ENDIF.

   ENDIF.

   CREATE OBJECT c_alv
     EXPORTING
       i_parent = c_cont.
   IF sy-subrc <> 0.
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
     WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   ENDIF.

   gt_layout-grid_title = 'BankDetail'.
   gt_layout-zebra = 'X'.
   gt_layout-cwidth_opt = 'X'.

    PERFORM get_fcat USING 'BUKRS' .
    PERFORM get_fcat USING 'BUTXT' .
    PERFORM get_fcat USING 'ORT01' .
    PERFORM get_fcat USING 'LAND1' .
    PERFORM get_fcat USING 'SPRAS' .

    CALL METHOD c_alv->set_table_for_first_display
     EXPORTING
*      is_variant      = g_var
       i_save          = 'X'
       i_default       = 'X'
       is_layout       = gt_layout
     CHANGING
       it_outtab       = i_t001[]
       it_fieldcatalog = gt_fieldcat.

   IF sy-subrc <> 0.
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
     WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   ENDIF.



ENDMODULE.                 " STATUS_9000  OUTPUT

FORM get_fcat  USING    fname.

   gw_fieldcat-fieldname = fname.
   gw_fieldcat-REF_TABLE = 'T001'.
   gw_fieldcat-tabname   = 'I_T001'.
   APPEND gw_fieldcat TO gt_fieldcat.
   CLEAR gw_fieldcat.

ENDFORM.                    " GET_FCAT102
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_9000 INPUT.

   CASE sy-ucomm.
       BREAK-POINT.
     WHEN 'PDF'. "<--to handle user actions
       w_print-PRINT = 'X'.

           CALL FUNCTION 'SET_PRINT_PARAMETERS'
     EXPORTING
       destination = 'LOCL' " Printer
       layout      = 'X_65_512/2' "Format
       line_count  = '65' "Line Count
       line_size   = '1024'. "Line Size

   w_print-print = 'X'.

   PERFORM fild_cat.


       CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
         EXPORTING
           i_callback_program      = g_program
*         i_structure_name        = 'T001'
*         i_callback_user_command = 'USER_COMMAND' " for User-Command
           is_print                = w_print
           it_fieldcat             = fieldcatalog[]
         TABLES
           t_outtab                = i_t001.
       IF sy-subrc <> 0.
         MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
       ELSE.


         data: GET_SIZE_FROM_FORMAT VALUE 'X'.

         g_spool = sy-spono.

         CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
           EXPORTING
             src_spoolid            = g_spool "Spool Number
             no_dialog              = space
             dst_device             = 'LOCL' "Printer Name
             GET_SIZE_FROM_FORMAT   = GET_SIZE_FROM_FORMAT
           IMPORTING
             pdf_bytecount          = lv_size "Output Size
           TABLES
             pdf                    = lt_pdf_output "Spool data in PDF Format
           EXCEPTIONS
             err_no_abap_spooljob   = 1
             err_no_spooljob        = 2
             err_no_permission      = 3
             err_conv_not_possible  = 4
             err_bad_destdevice     = 5
             user_cancelled         = 6
             err_spoolerror         = 7
             err_temseerror         = 8
             err_btcjob_open_failed = 9.
         IF sy-subrc EQ 0.
           LOOP AT lt_pdf_output INTO ls_pdf_output.
             TRANSLATE ls_pdf_output USING c_col1.
             CONCATENATE lv_buffer ls_pdf_output INTO lv_buffer.
             CLEAR ls_pdf_output.
           ENDLOOP.
           TRANSLATE lv_buffer USING c_col2.
           DO.
             ls_mess_att = lv_buffer.
             APPEND ls_mess_att TO lt_mess_att.
             SHIFT lv_buffer LEFT BY c_255 PLACES.
             IF lv_buffer IS INITIAL.
               EXIT.
             ENDIF.
             CLEAR ls_mess_att.
           ENDDO.
         ENDIF.
*--create reference object
         TRY.
             l_ref_bcs = cl_bcs=>create_persistent( ).
             lv_text = 'Mail Subject' .
             APPEND 'Mail Content' TO lv_data.
             l_ref_document = cl_document_bcs=>create_document(
             i_type = 'RAW'
             i_text = lv_data
             i_subject = lv_text ).
* *--create document reference
             lv_filesize = lv_size.
             CALL METHOD l_ref_document->add_attachment
               EXPORTING
                 i_attachment_type    = 'PDF'
                 i_attachment_size    = lv_filesize
                 i_attachment_subject = lv_text
                 i_att_content_text   = lt_mess_att[].
*     * set the document
             l_ref_bcs->set_document( l_ref_document ).
*     * create recipient
*     *      p_recpnt = sap INBOX user ID to WHICH the ATTACHMENT is SENT.
             l_ref_recipient = cl_sapuser_bcs=>create( p_recpnt ).
*     *adding recipient in to section
             l_ref_bcs->add_recipient( l_ref_recipient ).

*     * send mail
             CALL METHOD l_ref_bcs->send(
               EXPORTING
                 i_with_error_screen = 'X'
               RECEIVING
                 result              = lv_sent_to_all ).
             IF lv_sent_to_all = 'X'.
             ENDIF.
           CATCH cx_bcs INTO l_ref_bcs_exception.
             IF l_ref_bcs_exception IS NOT INITIAL.
               CLEAR l_ref_bcs_exception.
             ENDIF.
         ENDTRY.

         COMMIT WORK.

       endif.

   ENDCASE.


ENDMODULE.                 " USER_COMMAND_9000  INPUT

Read only

0 Likes
7,979

Dear Ashish,

Thanks a lot, really hats off to your try, at last i got the mail as pdf attachement, i tried your coding in separate program.

And i have made some changes in your coding that is:

                 l_ref_bcs->SET_SEND_IMMEDIATELY( 'X' ). "added this line

                 CALL METHOD l_ref_bcs->SEND( ). "modified this line.

                  COMMIT WORK.

                  IF SY-SUBRC EQ 0.

                    MESSAGE 'Mail sent successfully' TYPE 'S'.

                    ENDIF.

Everything is ok now, but that dialog box for printing is appearing when i click that pdf button and then mail is going, is it possible to stop it from showing.

Regards,

Rithika

Read only

0 Likes
7,979

Hiiii Rithika ,

                 Finally   yes it is possible you just need to change -

wprint-print = 'X'. ->

wprint-print = 'N'.  " This change will hide popup

Note : in my previous example code you can see ( after when 'PDF' ) i write it 2 time please set 'N' to both places

You can add below one also for more control

wprint-no_print_selinfos = 'X'.
wprint-no_coverpage = 'X'.
wprint-no_print_listinfos = 'X'.

wprint-print_ctrl-pri_params-pdest = 'LP01'. " Change as per your printer
wprint-print_ctrl-pri_params-primm = ''.
wprint-print_ctrl-pri_params-armod = ''.

definitely this will solve your problem

Regards

Ashish


Read only

0 Likes
7,979

Dear Ashish,

Now first dialog box in which we select output device is not coming, but print dialog box is coming, in which i select pdf, it opens the pdf, or i cancel it. Anyway my mail  is coming with attachment, really its a big help from you, but dont know why this print dialog box comes after mail is going.

Regards,

Rithika

Read only

0 Likes
7,979

Dear Rithika ,

                      You are most welcome , yes i know that print dialog will come because , in user profile -> output immediate check box will be selected , thats why , see my below screen shot

Here i am unselect  that checkbox , now if you run report that print dialog box will not come but question is how can you tell to user to unselect that check box .

same problem i have also faced so i would suggest you one solution that i had used for avoiding it ,

I have used BAPI_USER_CHANGE to unselect that output immediate check box and my problem has solved

one more thing i would suggest you please  delete spool after PDF conversion otherwise your can see long list in SP02   for this use fm - RSPO_R_RDELETE_SPOOLREQ

hope this idea will help you

Read only

0 Likes
7,979

Dear Ashish,

Thanks a lot , really i gained lot of knowledge from you, these function modules are really helpful for deleting spool request and the bapi is really useful but i dint use the bapi, i used that function module. I have another problem now. When i click and view the attachment from the mail, i can view the PDF 70% zoom, i want to view it little bit bigger, i dont want change zoom size in PDF window, through program is it possible to change the viewing size.

Thanks & Regards,

Rithika

Read only

0 Likes
7,979

Hiii rithika , 

                  You are most welcome , i am just try to help and Changing zoom via program i don't think so because at that time control already gonna to PDF reader   but you can try to set PDF size so that it comes with 100% size

you can try this ,

CALL FUNCTION 'SET_PRINT_PARAMETERS' 

     EXPORTING 

       destination = 'LOCL' " Printer 

       layout      = 'X_65_512/2' "Format " Change this format size as per printer  

        line_count  = '65' "Line Count  

       line_size   = '1024'. "Line Size " Change line size as per printer
 

Read only

0 Likes
7,979

Hiii Ashish,

I have passed all the layout format in my output device to layout parameter in the function module set_print_parameter, for eg i have given

CALL FUNCTION 'SET_PRINT_PARAMETERS'

     EXPORTING

       destination = 'LOCL' " Printer

       layout      = 'X_44_120' "Format " Change this format size as per printer  

        line_count  = '44' "Line Count 

       line_size   = '120'. "Line Size " Change line size as

Format X_44_120 shows good view in pdf format when i checked by print icon manually in the report, but when we send attachment as pdf it is not coming.

Regards,

Rithika

Read only

0 Likes
7,979

Hiiii Rithika ,

                     I think this should not be happen if you change line size than either your PDF output columns will come perfectly or some of them will not come or other ..... but PDF will be generate ,  i have checked here at my end with X_44_120 and pdf is generating perfectly.

Read only

0 Likes
7,979

Dear Ashish,

PDF is generating thats not a problem,  but it is coming as 71% only, that is the problem. This is my code generating PDF,

CALL FUNCTION 'SET_PRINT_PARAMETERS'

      EXPORTING

        destination = 'LOCL' " Printer

        layout      = 'X_44_120'           "'X_65_512/2' "Format

        line_count  '44'   "'65' "Line Count

        line_size   = '120'.     "'1024'. "Line Size

*********************Building the fieldcatalog to use in reuse_alv_grid_display

PERFORM BUILD_ALV1.

********************Passing to neglect the printer dialog box which is appearing*****************

    w_print-print = 'N'.

    w_print-no_print_selinfos = 'X'.

w_print-no_coverpage = 'X'.

w_print-no_print_listinfos = 'X'.

w_print-print_ctrl-pri_params-pdest = 'LOCL'. " Change as per your printer

w_print-print_ctrl-pri_params-primm = ''.

w_print-print_ctrl-pri_params-armod = ''.

*       INSERT WA_FINAL INTO IT_FINAL INDEX 1.

**************************Called to create spool request it create spool request because we pass w_print**************

   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

          EXPORTING

            i_callback_program      = SY-REPID    "g_program

*         i_structure_name        = 'TY_FINAL'

*         i_callback_user_command = 'USER_COMMAND' " for User-Command

            is_print                = w_print

            it_fieldcat             = FIELDCATALOG[]

          TABLES

            t_outtab                = IT_FINAL[].

        IF sy-subrc <> 0.

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

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

ELSE.

    data: GET_SIZE_FROM_FORMAT VALUE 'X'.

          g_spool = sy-spono.

**********************Using spool number we convert background job of this report to pdf

          CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

            EXPORTING

              src_spoolid            = g_spool "Spool Number

              no_dialog              = space

              dst_device             = 'LOCL' "Printer Name

              GET_SIZE_FROM_FORMAT   = GET_SIZE_FROM_FORMAT

            IMPORTING

              pdf_bytecount          = lv_size "Output Size

            TABLES

              pdf                    = lt_pdf_output "Spool data in PDF Format

            EXCEPTIONS

              err_no_abap_spooljob   = 1

              err_no_spooljob        = 2

              err_no_permission      = 3

              err_conv_not_possible  = 4

              err_bad_destdevice     = 5

              user_cancelled         = 6

              err_spoolerror         = 7

              err_temseerror         = 8

              err_btcjob_open_failed = 9.

          IF sy-subrc EQ 0.

G_SPOOL1 = G_SPOOL.

*************After converting we delete the spool request to reduce memory consumtion

            CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'

              EXPORTING

                SPOOLID             = g_spool1

*            IMPORTING

*              RC                  =

*              STATUS              =

*              ERROR_MESSAGE       =

                      .

Regards,

Rithika

Read only

0 Likes
7,979

Hii,

       ok so you can do one thing just comment GET_SIZE_FROM_FORMAT parameter of FM CONVERT_ABAPSPOOLJOB_2_PDF. than check .

Read only

0 Likes
7,979

Dear Ashsih,

Really fantastic, it worked. Thanks for all your help, you solved all my problem.

Regards,

Rithika.

Read only

0 Likes
7,979

Dear Rithika ,

                     You are most welcome yeap i know it will work , because same scenario i have also faced

Regards

Ashish

Read only

0 Likes
7,979

Dear Ashish,

There is another modification in this report, everything working fine now. But now the requirement is when they are subtotalling the columns it is showing subtotal , but for example if i am having unit of measure measure column and in that data are such as BOX, NOS etc it is sub totalling it, but it is showing grand total under that subtotal. They dont want that total.

Another question, i have layout as input in my report, if they give any saved layout , it will display alv in that layout format, if i send mail of that layout, it is not going in that layout format, it going in normal format, what should i do.

Regards,

Rithika.

Read only

surajarafath
Contributor
0 Likes
7,979

This message was moderated.

Read only

0 Likes
7,979

Hi,

I have checked both the links you sent, but it is not working, i have followed exact steps in second link still my problem exist.

Read only

ujjwalraj_singh
Discoverer
0 Likes
7,979

Hi,

Your post is very help full.

It helped me allot.