Skip to Content
0
Dec 16, 2015 at 07:27 AM

smartform mailing

18 Views

Hello Experts,

I have created a SF as per user requirement.

Now I want to mail to the Vendor entered on input screen, to activate email option I have given checkbox for it.

When Checkbox is blank regular SF output should be created.

My code is as follows where SF is getting printed in any case.

also after checking email option dump is being generated.

Program :

TYPES: BEGIN OF TY_FINAL,

EBELN TYPE EBELN,

* AEDAT TYPE AEDAT, "

LIFNR TYPE ELIFN,

NAME1 TYPE NAME1_GP,

EBELP TYPE EBELP,

MATNR TYPE MATNR,

MAKTX TYPE MAKTX,

REVLV TYPE REVLV,

EINDT TYPE EINDT,

MENGE TYPE EKET-MENGE,

TOTAL_QTY TYPE EKET-MENGE,

END OF TY_FINAL.

DATA: IT_FINAL TYPE STANDARD TABLE OF TY_FINAL,

WA_FINAL TYPE TY_FINAL.

DATA : IT_EKKO TYPE STANDARD TABLE OF EKKO,

WA_EKKO TYPE EKKO.

DATA : IT_EKPO TYPE STANDARD TABLE OF EKPO,

WA_EKPO TYPE EKPO.

DATA : IT_EKET TYPE STANDARD TABLE OF EKET,

WA_EKET TYPE EKET.

DATA : IT_LFA1 TYPE STANDARD TABLE OF LFA1,

WA_LFA1 TYPE LFA1.

DATA : IT_MAKT TYPE TABLE OF MAKT,

WA_MAKT TYPE MAKT.

DATA: V_ITEM_NO TYPE EKPO-EBELP.

DATA: V_FROM TYPE EKKO-AEDAT,

V_TO TYPE EKKO-AEDAT,

V_LIFNR TYPE LIFNR.

DATA : FM_NAME TYPE RS38L_FNAM .

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001 .

SELECT-OPTIONS : SO_WERKS FOR EKBE-WERKS OBLIGATORY DEFAULT '1000',

SO_AEDAT FOR EKKO-AEDAT OBLIGATORY,

SO_EBELN FOR EKKO-EBELN. "OBLIGATORY,

PARAMETERS: P_LIFNR TYPE EKKO-LIFNR OBLIGATORY.

PARAMETERS : EMAIL AS CHECKBOX.

SELECTION-SCREEN END OF BLOCK B1 .

START-OF-SELECTION .

PERFORM MAIL.

PERFORM GET_DATA .

PERFORM EXPORT.

PERFORM SF_CALL.

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

*& FORM GET_DATA

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

* TEXT

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

FORM GET_DATA .

* *******GET DATA FOR OUTPUT TO SF************************************************

IF P_LIFNR IS NOT INITIAL.

SELECT * FROM EKKO INTO TABLE IT_EKKO WHERE EBELN IN SO_EBELN AND BSART EQ 'LP'

AND LIFNR EQ P_LIFNR. "AND AEDAT IN SO_AEDAT

ELSE.

SELECT * FROM EKKO INTO TABLE IT_EKKO WHERE EBELN IN SO_EBELN AND BSART EQ 'LP'. "AND AEDAT IN SO_AEDAT

ENDIF.

IF IT_EKKO[] IS NOT INITIAL.

SELECT * FROM EKPO INTO TABLE IT_EKPO FOR ALL ENTRIES IN IT_EKKO

WHERE EBELN = IT_EKKO-EBELN AND WERKS IN SO_WERKS.

SELECT * FROM LFA1 INTO TABLE IT_LFA1 FOR ALL ENTRIES IN IT_EKKO

WHERE LIFNR = IT_EKKO-LIFNR.

ENDIF.

IF IT_EKPO[] IS NOT INITIAL.

SELECT * FROM MAKT INTO TABLE IT_MAKT FOR ALL ENTRIES IN IT_EKPO

WHERE MATNR = IT_EKPO-MATNR.

SELECT * FROM EKET INTO TABLE IT_EKET FOR ALL ENTRIES IN IT_EKPO

WHERE EBELN = IT_EKPO-EBELN AND EBELP = IT_EKPO-EBELP.

ENDIF.

*******ORGANISE DATA FOR OUTPUT************************************************

LOOP AT IT_EKET INTO WA_EKET WHERE BEDAT IN SO_AEDAT.

****** HEADER DETAILS

READ TABLE IT_EKKO INTO WA_EKKO WITH KEY EBELN = WA_EKET-EBELN BINARY SEARCH.

IF SY-SUBRC = 0.

WA_FINAL-EBELN = WA_EKKO-EBELN.

* WA_FINAL-AEDAT = WA_EKKO-AEDAT.

WA_FINAL-LIFNR = WA_EKKO-LIFNR.

ENDIF.

READ TABLE IT_LFA1 INTO WA_LFA1 WITH KEY LIFNR = WA_EKKO-LIFNR BINARY SEARCH.

IF SY-SUBRC = 0.

WA_FINAL-NAME1 = WA_LFA1-NAME1.

ENDIF.

****** ITEM DETAILS

READ TABLE IT_EKPO INTO WA_EKPO WITH KEY EBELN = WA_EKET-EBELN EBELP = WA_EKET-EBELP

BINARY SEARCH.

IF SY-SUBRC = 0.

WA_FINAL-EBELP = WA_EKPO-EBELP.

WA_FINAL-MATNR = WA_EKPO-MATNR.

WA_FINAL-REVLV = WA_EKPO-REVLV.

ENDIF.

READ TABLE IT_MAKT INTO WA_MAKT WITH KEY MATNR = WA_EKPO-MATNR BINARY SEARCH.

IF SY-SUBRC = 0.

WA_FINAL-MAKTX = WA_MAKT-MAKTX.

ENDIF.

WA_FINAL-EINDT = WA_EKET-EINDT.

IF WA_EKET-MENGE NE WA_EKET-WEMNG.

WA_FINAL-MENGE = WA_EKET-MENGE - WA_EKET-WEMNG.

APPEND WA_FINAL TO IT_FINAL.

ELSE.

DELETE IT_EKET.

ENDIF.

CLEAR: WA_FINAL, WA_EKET, WA_EKKO, WA_EKPO, WA_LFA1, WA_MAKT.

ENDLOOP.

SORT IT_FINAL BY EBELN.

DELETE ADJACENT DUPLICATES FROM IT_FINAL COMPARING EBELN EBELP.

LOOP AT IT_FINAL INTO WA_FINAL.

LOOP AT IT_EKET INTO WA_EKET WHERE EBELN = WA_FINAL-EBELN AND EBELP = WA_FINAL-EBELP.

* IF WA_EKET-MENGE NE WA_EKET-WEMNG.

WA_EKET-MENGE = WA_EKET-MENGE - WA_EKET-WEMNG.

* ENDIF.

WA_FINAL-TOTAL_QTY = WA_FINAL-TOTAL_QTY + WA_EKET-MENGE.

CLEAR: WA_EKET.

ENDLOOP.

MODIFY IT_FINAL FROM WA_FINAL TRANSPORTING TOTAL_QTY.

CLEAR: WA_FINAL.

ENDLOOP.

V_FROM = SO_AEDAT-LOW. "FROM DATE

V_TO = SO_AEDAT-HIGH. "TO DATE

V_LIFNR = P_LIFNR.

ENDFORM . "GET_DATA

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

*& FORM SF_CALL

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

* TEXT

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

* --> P1 TEXT

* <-- P2 TEXT

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

FORM SF_CALL .

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

FORMNAME = 'ZMM_PURCHASE_ORDER_SHED_LINES'

IMPORTING

FM_NAME = FM_NAME.

IF SY-SUBRC <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CALL FUNCTION FM_NAME " '/1BCDWB/SF00000135'

EXPORTING

* ARCHIVE_INDEX =

* ARCHIVE_INDEX_TAB =

* ARCHIVE_PARAMETERS =

* CONTROL_PARAMETERS =

* MAIL_APPL_OBJ =

* MAIL_RECIPIENT =

* MAIL_SENDER =

* OUTPUT_OPTIONS =

* USER_SETTINGS = 'X'

* IMPORTING

* DOCUMENT_OUTPUT_INFO =

* JOB_OUTPUT_INFO =

* JOB_OUTPUT_OPTIONS =

* P_MBLNR = P_MBLNR

V_FROM = V_FROM

V_TO = V_TO

V_LIFNR = V_LIFNR

* TABLES

* IT_FINAL = IT_FINAL.

* EXCEPTIONS

* FORMATTING_ERROR = 1

* INTERNAL_ERROR = 2

* SEND_ERROR = 3

* USER_CANCELED = 4

* OTHERS = 5

.

IF SY-SUBRC <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " SF_CALL

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

*& FORM EXPORT

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

* TEXT

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

* --> P1 TEXT

* <-- P2 TEXT

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

FORM EXPORT .

EXPORT IT_FINAL TO MEMORY ID 'ZMM_PO_SL_FINAL'.

EXPORT IT_EKET TO MEMORY ID 'ZMM_PO_SL_EKET'.

ENDFORM. " EXPORT

FORM MAIL.

IF EMAIL = 'X'.

PERFORM GET_DATA .

PERFORM SF_CALL.

PERFORM EXPORT.

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.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

FORMNAME = 'ZMM_PURCHASE_ORDER_SHED_LINES'

IMPORTING

FM_NAME = FM_NAME

EXCEPTIONS

NO_FORM = 1

NO_FUNCTION_MODULE = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

W_CTRLOP-GETOTF = 'X'.

W_CTRLOP-NO_DIALOG = 'X'.

W_COMPOP-TDNOPREV = 'X'.

CALL FUNCTION FM_NAME

EXPORTING

CONTROL_PARAMETERS = W_CTRLOP

OUTPUT_OPTIONS = W_COMPOP

USER_SETTINGS = 'X'

IMPORTING

JOB_OUTPUT_INFO = W_RETURN

EXCEPTIONS

FORMATTING_ERROR = 1

INTERNAL_ERROR = 2

SEND_ERROR = 3

USER_CANCELED = 4

OTHERS = 5.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

I_OTF[] = W_RETURN-OTFDATA[].

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

FORMAT = 'PDF'

MAX_LINEWIDTH = 132

IMPORTING

BIN_FILESIZE = V_LEN_IN

TABLES

OTF = I_OTF

LINES = I_TLINE

EXCEPTIONS

ERR_MAX_LINEWIDTH = 1

ERR_FORMAT = 2

ERR_CONV_NOT_POSSIBLE = 3

OTHERS = 4.

IF SY-SUBRC <> 0.

ENDIF.

LOOP AT I_TLINE.

TRANSLATE I_TLINE USING '~'.

CONCATENATE WA_BUFFER I_TLINE 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 = 'TEST WITH PDF-ATTACHMENT!'.

APPEND I_OBJTXT.

DESCRIBE TABLE I_OBJTXT LINES V_LINES_TXT.

READ TABLE I_OBJTXT INDEX V_LINES_TXT.

WA_DOC_CHNG-OBJ_NAME = 'SMARTFORM'.

WA_DOC_CHNG-EXPIRY_DAT = SY-DATUM + 10.

WA_DOC_CHNG-OBJ_DESCR = '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 = 'TEST'.

APPEND I_OBJPACK.

CLEAR I_RECLIST.

I_RECLIST-RECEIVER = 'abc23@GMAIL.COM'.

I_RECLIST-REC_TYPE = 'U'.

APPEND 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.

WRITE:/ 'ERROR WHEN SENDING THE FILE', SY-SUBRC.

ELSE.

WRITE:/ 'MAIL SENT'.

ENDIF.

ELSE.

EXIT.

ENDIF.

ENDFORM.

Please help me to achieve it.

Regards,

Arpit