How to send fax in ABAP?

Question:
Can I write my own ABAP report, get fax numbers from the master data, then send to Winfax directly? I don't want to go through the SP01, and enter fax number manually each time. Thanks.
Answer:
Yes, you can!
0) add one output device ZFAX in SPAD
1) install software such as WINFAX
2) maintain customer/vendor master with Fax number
3) Ask functional consultant add one more output type which use '2 - Fax' as output method
or
4) in Your own abap code, in FM 'OPEN_FORM', set 'TELEFAX' as device...
_________________
Good luck!
Answer:
Thanks! Two more quick questions:
1) I can specify a fax number other than the one in the Vendor Master in the field of "Options" when calling "Open_form", right?
2) If it is only a normal ABAP report, not Sapscript, then without "Open_form", how to transfer the fax number to Winfax directly?
Thanks.
Answer:
Hi,
I believe the enclosed code will be of some help to you.It enables Fax to be sent from List output.Try it as a Local object,understand and implement it for your code.The concept is after END-OF-SELECTION,Export List to memory and import it before sending to fax.
The function module to be used is SO_NEW_DOCUMENT_ATT_SEND_API1.
If this does not work,Go to OSS and put the Search text as Fax and search
for Applcable notes.
Thanks,
Zephyr
REPORT SENDLIST LINE-SIZE 71 NO STANDARD PAGE HEADING.
SELECTION-SCREEN BEGIN OF BLOCK MODE WITH FRAME TITLE TITLE.
PARAMETERS: SUBMIT RADIOBUTTON GROUP MODE.
PARAMETERS: REPORT LIKE RS38M-PROGRAMM DEFAULT 'RSWTTR01'.
SELECTION-SCREEN SKIP.
PARAMETERS: WRITE RADIOBUTTON GROUP MODE DEFAULT 'X'.
PARAMETERS: SPOOL RADIOBUTTON GROUP MODE.
SELECTION-SCREEN END OF BLOCK MODE.
* global data
DATA COMPRESSED_LIST LIKE SOLI OCCURS 0.
DATA G_DOC_TYPE LIKE SOODK-OBJTP VALUE 'ALI'.
*--- initialization ----------------------------------------------------
INITIALIZATION.
TITLE = 'Select Mode'.
*---- start-of-selection -----------------------------------------------
START-OF-SELECTION.
*********************************************************************
*1st possibility - use "submit <report> exporting list to memory" *
*********************************************************************
IF SUBMIT = 'X'.
PERFORM USE_SUBMIT TABLES COMPRESSED_LIST.
ENDIF.
*********************************************************************
* 2nd possibility - Create a new list within this report. *
*********************************************************************
IF WRITE = 'X'.
PERFORM WRITE_A_LIST TABLES COMPRESSED_LIST.
ENDIF.
*********************************************************************
* 3rd possibility - Get list from spool *
*********************************************************************
IF SPOOL = 'X'.
PERFORM GET_LIST_FROM_SPOOL TABLES COMPRESSED_LIST.
ENDIF.
*********************************************************************
* Now prepare the list for sending - you will find
* more information in the function module documentation of
* SO_NEW_DOCUMENT_ATT_SEND_API1 in SE37
*********************************************************************
PERFORM SEND TABLES COMPRESSED_LIST.
************************************************************************
* Form routines *
************************************************************************
*&---------------------------------------------------------------------*
*& Form USE_SUBMIT
*&---------------------------------------------------------------------*
* Use "submit <report> exporting list to memory"
*----------------------------------------------------------------------*
FORM USE_SUBMIT TABLES COMPRESSED_LIST STRUCTURE SOLI.
* The listobject
DATA: LISTOBJECT LIKE ABAPLIST OCCURS 0 WITH HEADER LINE.
******call report without displaying it on the screen********
* the created list is stored in the memory
* (e.g. report rswttr01, a list of sapconnect Traces)
SUBMIT (REPORT) EXPORTING LIST TO MEMORY AND RETURN.
*************************************************************
******Or via selection-screen. Press EXECUTE and BACK********
* (e.g. report balvhd01)
* SUBMIT (REPORT) VIA SELECTION-SCREEN
* EXPORTING LIST TO MEMORY AND RETURN.
*************************************************************
******Or specify selection explicitely***********************
* (e.g. report balvhd01)
* REPORT = 'balvhd01'.
* SUBMIT (REPORT)*
* WITH CARRID EQ 'LH'
* EXPORTING LIST TO MEMORY AND RETURN.
*
* --> With F1 on submit you will find more possibilities
*************************************************************
* Import the list from memory and store it in table listobject
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
LISTOBJECT = LISTOBJECT
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
WRITE 'Error in list_from_memory.'.
ENDIF.
* Free memory
CALL FUNCTION 'LIST_FREE_MEMORY'
TABLES
LISTOBJECT = LISTOBJECT
EXCEPTIONS
OTHERS = 1.
IF SY-SUBRC <> 0.
WRITE 'Error in list_free_memory.'.
ENDIF.
* It's always necessary to compress the list
* SAPconnect will decompress it
CALL FUNCTION 'TABLE_COMPRESS'
TABLES
IN = LISTOBJECT
OUT = COMPRESSED_LIST
EXCEPTIONS
COMPRESS_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
WRITE: 'Error in table_compress.'.
ENDIF.
ENDFORM. " USE_SUBMIT
*&---------------------------------------------------------------------*
*& Form WRITE_A_LIST
*&---------------------------------------------------------------------*
* Create a new list within this report.
*----------------------------------------------------------------------*
FORM WRITE_A_LIST TABLES COMPRESSED_LIST STRUCTURE SOLI.
* The listobject
DATA: LISTOBJECT LIKE ABAPLIST OCCURS 0 WITH HEADER LINE.
* For example take the conversion rules used by SAPconnect.
PERFORM WRITE_LIST.
* Save the list and store table listobject
CALL FUNCTION 'SAVE_LIST'
EXPORTING
LIST_INDEX = SY-LSIND
TABLES
LISTOBJECT = LISTOBJECT
EXCEPTIONS
LIST_INDEX_INVALID = 1.
IF SY-SUBRC = 1.
WRITE: 'Error in save_list.'.
ENDIF.
* It's always necessary to compress the list
* SAPconnect will decompress it
CALL FUNCTION 'TABLE_COMPRESS'
TABLES
IN = LISTOBJECT
OUT = COMPRESSED_LIST
EXCEPTIONS
COMPRESS_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
WRITE: 'Error in table_compress.'.
ENDIF.
ENDFORM. " WRITE_A_LIST
*&---------------------------------------------------------------------*
*& Form GET_LIST_FROM_SPOOL
*&---------------------------------------------------------------------*
* Get list from spool
*----------------------------------------------------------------------*
FORM GET_LIST_FROM_SPOOL TABLES COMPRESSED_LIST STRUCTURE SOLI.
DATA SPOOL_NUMBER LIKE TSP01-RQIDENT.
*******Write a list into spool*********************
NEW-PAGE PRINT ON LIST NAME 'Testlist'.
PERFORM WRITE_LIST.
NEW-PAGE PRINT OFF.
SPOOL_NUMBER = SY-SPONO.
***************************************************
*******Or choose your own spooljob*****************
* DATA FIELDS LIKE SVAL OCCURS 1 WITH HEADER LINE.
* FIELDS-TABNAME = 'TSP01'.
* FIELDS-FIELDNAME = 'RQIDENT'.
* APPEND FIELDS.
*
* CALL FUNCTION 'POPUP_GET_VALUES'
* EXPORTING
* POPUP_TITLE = 'Spoolnumber'
* TABLES
* FIELDS = FIELDS.
*
* SPOOL_NUMBER = FIELDS-VALUE.
****************************************************
* You can also send SAPscript documents from spool with this function
* module. G_DOC_TYPE will have value 'OTF' in this case. For an ABAP
* list it will have value 'ALI'.
* The function module itself decides wether to compress the table
* (if it's ALI) or not (if it's OTF). Of course table name
* 'COMPRESSED_LIST' does not make sense in the latter case.
CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
EXPORTING
RQIDENT = SPOOL_NUMBER
IMPORTING
REAL_TYPE = G_DOC_TYPE
TABLES
BUFFER = COMPRESSED_LIST
EXCEPTIONS
NO_SUCH_JOB = 1
JOB_CONTAINS_NO_DATA = 2
SELECTION_EMPTY = 3
NO_PERMISSION = 4
CAN_NOT_ACCESS = 5
READ_ERROR = 6
TYPE_NO_MATCH = 7
OTHERS = 8.
IF SY-SUBRC <> 0.
WRITE: 'Error in RSPO_RETURN_SPOOLJOB. Rcode ', SY-SUBRC.
ENDIF.
ENDFORM. " GET_LIST_FROM_SPOOL
*&---------------------------------------------------------------------*
*& Form WRITE_LIST
*&---------------------------------------------------------------------*
* Write a list of SAPconnect conversion rules
*----------------------------------------------------------------------*
FORM WRITE_LIST.
DATA: SXCONVERT_TAB LIKE SXCONVERT OCCURS 0.
DATA: SXCONVERT_WA LIKE SXCONVERT.
SELECT * FROM SXCONVERT INTO TABLE SXCONVERT_TAB.
WRITE: 'Conversion rules for SAPconnect'.
ULINE.
WRITE: / SY-VLINE,
'Mandt', SY-VLINE,
'Format', SY-VLINE,
'To Format', SY-VLINE,
'Ranking', SY-VLINE,
'Function Module', 71 SY-VLINE.
ULINE.
LOOP AT SXCONVERT_TAB INTO SXCONVERT_WA.
WRITE: / SY-VLINE,
SXCONVERT_WA-MANDT, 9 SY-VLINE,
SXCONVERT_WA-FORMAT_SRC, 18 SY-VLINE,
SXCONVERT_WA-FORMAT_DST, 30 SY-VLINE,
SXCONVERT_WA-RATING, 40 SY-VLINE,
SXCONVERT_WA-FUNCNAME, 71 SY-VLINE.
ENDLOOP.
ULINE.
* Finish the list with new-line. Otherwise the last character
* of the list might get lost.
NEW-LINE.
ENDFORM. " WRITE_LIST
*&---------------------------------------------------------------------*
*& Form SEND
*&---------------------------------------------------------------------*
* Create the list-document and send it via FAX, Mail and RML
*----------------------------------------------------------------------*
FORM SEND TABLES COMPRESSED_LIST STRUCTURE SOLI.
* Structures for recipient addresses
DATA: RECIPIENT_FAX LIKE SADRFD.
DATA: RECIPIENT_INT LIKE SADRUD.
DATA: RECIPIENT_RML LIKE SADR7D.
* Structures and internal tables for the send data
DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.
DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.
DATA: OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.
DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.
DATA: DOC_CHNG LIKE SODOCCHGI1.
DATA: TAB_LINES LIKE SY-TABIX.
* Data for the status output after sending
DATA: USER_ADDRESS LIKE SOUSRADRI1 OCCURS 1 WITH HEADER LINE.
DATA: SENT_TO_ALL LIKE SONV-FLAG.
*move list to office table objbin
MOVE COMPRESSED_LIST[] TO OBJBIN[].
* Create the document which is to be sent
DOC_CHNG-OBJ_NAME = 'List'.
DOC_CHNG-OBJ_DESCR = 'ABAPlist'.
* We may write additional text to the main document
* For faxing this will be the cover page. Like sending from SAPoffice
* the layout set Office-Telefax will be used.
OBJTXT = 'This is additional text.'.
APPEND OBJTXT.
DESCRIBE TABLE OBJTXT LINES TAB_LINES.
READ TABLE OBJTXT INDEX TAB_LINES.
DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
* Fill the fields of the packing_list for the main document:
* It is a text document
CLEAR OBJPACK-TRANSF_BIN.
* The document needs no header (head_num = 0)
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 0.
* but it has a body
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
* of type RAW
OBJPACK-DOC_TYPE = 'RAW'.
APPEND OBJPACK.
* Create the attachment (the list itself)
DESCRIBE TABLE OBJBIN LINES TAB_LINES.
* Fill the fields of the packing_list for the attachment:
* It is binary document
OBJPACK-TRANSF_BIN = 'X'.
* we need no header
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 0.
* but a body
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
* of type G_DOC_TYPE
OBJPACK-DOC_TYPE = G_DOC_TYPE.
OBJPACK-OBJ_NAME = 'Attachment'.
OBJPACK-OBJ_DESCR = 'An ABAPlist'.
OBJPACK-DOC_SIZE = TAB_LINES * 255.
APPEND OBJPACK.
********************************************
* FAX - Fill the fax recipient list *
********************************************
RECIPIENT_FAX-REC_FAX = '000000000'.
RECIPIENT_FAX-REC_STATE = 'DE'.
RECIPIENT_FAX-REC_TITLE = 'Mrs.'.
RECIPIENT_FAX-REC_NAME1 = 'Ann Recipient'.
RECIPIENT_FAX-SEND_NAM = 'Tom Sender'.
RECIPIENT_FAX-SEND_COMP = 'SAP AG'.
* Additional text should appear on the cover and not on a 2nd page
RECIPIENT_FAX-SEND_COVER = 'X'.
RECLIST-RECEIVER = RECIPIENT_FAX.
* It's a fax recipient
RECLIST-REC_TYPE = 'F'.
APPEND RECLIST.
********************************************
* INT - Fill the mail recipient list *
********************************************
RECIPIENT_INT-ADDRESS = 'hugo@company.com'.
RECLIST-RECEIVER = RECIPIENT_INT.
* It's a mail recipient
RECLIST-REC_TYPE = 'U'.
APPEND RECLIST.
********************************************
* RML - Fill the mail recipient list *
********************************************
RECIPIENT_RML-SDEST = 'C11'.
RECIPIENT_RML-UMAND = '001'.
RECIPIENT_RML-UNAME = 'MYUSER'.
RECLIST-RECEIVER = RECIPIENT_RML.
* It's a remote SAP recipient
RECLIST-REC_TYPE = 'R'.
APPEND RECLIST.
*********************************************************************
* Send the document by calling the SAPoffice API1 module *
* for sending documents with attachments *
*********************************************************************
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOC_CHNG
PUT_IN_OUTBOX = 'X'
IMPORTING
SENT_TO_ALL = SENT_TO_ALL
TABLES
PACKING_LIST = OBJPACK
OBJECT_HEADER = OBJHEAD
CONTENTS_BIN = OBJBIN
CONTENTS_TXT = OBJTXT
RECEIVERS = RECLIST
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
OPERATION_NO_AUTHORIZATION = 4
OTHERS = 99.
CASE SY-SUBRC.
WHEN 0.
WRITE: / 'Result of the sendprocess:'.
IF NOT SENT_TO_ALL IS INITIAL.
WRITE: / 'Successfully sent to all recipients.'.
ELSE.
LOOP AT RECLIST WHERE RETRN_CODE NE 0.
REFRESH USER_ADDRESS.
CLEAR USER_ADDRESS.
USER_ADDRESS-USERID = RECLIST-REC_ID.
APPEND USER_ADDRESS.
CALL FUNCTION 'SO_USER_ADDRESS_READ_API1'
TABLES
USER_ADDRESS = USER_ADDRESS
EXCEPTIONS
ENQUEUE_ERRROR = 1
PARAMETER_ERROR = 2
X_ERROR = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
USER_ADDRESS-LONG_NAME = RECLIST-REC_ID.
ENDIF.
WRITE: / 'Could not send to: '.
WRITE: USER_ADDRESS-LONG_NAME(4.
ENDLOOP.
LOOP AT RECLIST WHERE RETRN_CODE EQ 0.
ENDLOOP.
IF SY-SUBRC = 0.
WRITE: / 'Successfully sent to all other recipients.'.
ENDIF.
ENDIF.
WHEN 1.
WRITE: / 'No permission to sent to the specified ',
'amount of recipients !'.
WHEN 2.
WRITE: / 'Document could not be sent to any recipient !'.
WHEN 4.
WRITE: / 'No permission to send !'.
WHEN OTHERS.
WRITE: / 'Error while sending !'.
ENDCASE.
ENDFORM. " SEND

More Articles:

Event is not triggered in ALV?
How to decide which BADI to use?
auto refresh display outside of a dialog step?
Batch Input?
SELECT SQL with EXEC SQL multirows DESPERATE !?
Table creation error?