Hello Friends:
I would like to share my knowledge about SD – Billing Invoice should send to multiple customer via email from SAP environment in PDF format. I know it may possible that to achieve this there may be a variety of option are available, but I would like to share my work knowledge which I had proceed for this business requirement.
Business Context:
In Standard SAP environment, we can send the mail to multiple recipient with standard format. But business required an custom program should trigger the mail with some additional column information along with custom message which can be easily understood by the business end user.
To overcome we need to go with Techno-Functional Configuration as per below steps:
Functional Configuration:
Transaction Code: NACE
Select V3 Application and click on Output types button.
Create any custom output as shown in below snap shot with the following below setups.
I had selected option # 3 under Dispatch time field, because the Invoice will trigger on the basis of business requirement, i.e. it would be on their dependencies.
Along with that , I also created separate custom communication strategy and assign it with our created custom output type.
Remark: Time Tab and Sort Order Tab is not applicable to filled for this scenario.
After completion of all the details under required tabs, click on “Mail title and texts” option.
After completion of Mail title and text structure, click on “Processing Routines” structure.
Note: We have created an custom program ZRLB_INVOICE with required coding logic for our output source.
In Partner Functions structure, update the data as shown in above snap shot.
Once all above functional configuration is done, save it.
Now, Output Type is created and now we need to assign it under Billing Output Procedure as shown in below snap shot.
Save it.
Maintained Condition Record: VV31
Save it.
Technical Coding:
*———————————————————————-*
* Print of a invoice by SAPscript SMART FORMS *
*———————————————————————-*
REPORT ZRLB_INVOICE.
**************************************************************************
* MODULE : Sales & Distribution
****************************************************************************
TABLES : ADR6.
* declaration of data
INCLUDE RLB_INVOICE_DATA_DECLARE.
* definition of forms
INCLUDE RLB_INVOICE_FORM01.
INCLUDE RLB_PRINT_FORMS.
*———————————————————————*
* FORM ENTRY
*———————————————————————*
FORM ENTRY USING RETURN_CODE US_SCREEN.
DATA: LF_RETCODE TYPE SY-SUBRC.
CLEAR RETCODE.
XSCREEN = US_SCREEN.
PERFORM PROCESSING USING US_SCREEN
CHANGING LF_RETCODE.
IF LF_RETCODE NE 0.
RETURN_CODE = 1.
ELSE.
RETURN_CODE = 0.
ENDIF.
ENDFORM. “ENTRY
*———————————————————————*
* FORM PROCESSING *
*———————————————————————*
FORM PROCESSING USING PROC_SCREEN
CHANGING CF_RETCODE.
DATA: LS_PRINT_DATA_TO_READ TYPE LBBIL_PRINT_DATA_TO_READ.
DATA: LS_BIL_INVOICE TYPE LBBIL_INVOICE.
DATA: LF_FM_NAME TYPE RS38L_FNAM.
DATA: LS_CONTROL_PARAM TYPE SSFCTRLOP.
DATA: LS_COMPOSER_PARAM TYPE SSFCOMPOP.
DATA: LS_RECIPIENT TYPE SWOTOBJID.
DATA: LS_SENDER TYPE SWOTOBJID.
DATA: LF_FORMNAME TYPE TDSFNAME.
DATA: LS_ADDR_KEY LIKE ADDR_KEY.
DATA: LS_DLV-LAND LIKE VBRK-LAND1.
DATA: LS_JOB_INFO TYPE SSFCRESCL,
LS_DOC_INFO TYPE SSFCRESPD,
LS_JOB_OUTPUT TYPE SSFCRESOP.
* SmartForm from customizing table TNAPR
LF_FORMNAME = TNAPR-SFORM.
* determine print data
PERFORM SET_PRINT_DATA_TO_READ USING LF_FORMNAME
CHANGING LS_PRINT_DATA_TO_READ
CF_RETCODE.
IF CF_RETCODE = 0.
* select print data
PERFORM GET_DATA USING LS_PRINT_DATA_TO_READ
CHANGING LS_ADDR_KEY
LS_DLV-LAND
LS_BIL_INVOICE
CF_RETCODE.
ENDIF.
*********************************************
TYPES : BEGIN OF TY_ADR6,
ADDRNUMBER TYPE AD_ADDRNUM,
SMTP_ADDR TYPE AD_SMTPADR,
END OF TY_ADR6.
DATA : WA_ADR6 TYPE TY_ADR6,
IT_ADR6 TYPE TABLE OF TY_ADR6,
S_EMAIL TYPE TABLE OF ADR6-SMTP_ADDR WITH HEADER LINE.
SELECT ADDRNUMBER SMTP_ADDR FROM ADR6 INTO CORRESPONDING FIELDS OF TABLE IT_ADR6 WHERE ADDRNUMBER = LS_ADDR_KEY-ADDRNUMBER.
IF SY-SUBRC = 0.
LOOP AT IT_ADR6 INTO WA_ADR6.
S_EMAIL = WA_ADR6-SMTP_ADDR.
APPEND S_EMAIL.
ENDLOOP.
ENDIF.
*************************************************
IF CF_RETCODE = 0.
PERFORM SET_PRINT_PARAM USING LS_ADDR_KEY
LS_DLV-LAND
CHANGING LS_CONTROL_PARAM
LS_COMPOSER_PARAM
LS_RECIPIENT
LS_SENDER
CF_RETCODE.
ENDIF.
IF CF_RETCODE = 0.
* determine smartform function module for invoice
CALL FUNCTION ‘SSF_FUNCTION_MODULE_NAME’
EXPORTING FORMNAME = LF_FORMNAME
* variant = ‘ ‘
* direct_call = ‘ ‘
IMPORTING FM_NAME = LF_FM_NAME
EXCEPTIONS NO_FORM = 1
NO_FUNCTION_MODULE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
* error handling
CF_RETCODE = SY-SUBRC.
PERFORM PROTOCOL_UPDATE.
ENDIF.
ENDIF.
IF CF_RETCODE = 0.
PERFORM CHECK_REPEAT.
IF LS_COMPOSER_PARAM-TDCOPIES EQ 0.
NAST_ANZAL = 1.
ELSE.
NAST_ANZAL = LS_COMPOSER_PARAM-TDCOPIES.
ENDIF.
LS_COMPOSER_PARAM-TDCOPIES = 1.
* BEGIN: Country specific extension for Hungary
DATA: LV_CCNUM TYPE IDHUCCNUM.
* If a valid entry exists for the form in customizing view
* IDHUBILLINGOUT then the localized output shall be used.
SELECT SINGLE CCNUM INTO LV_CCNUM FROM IDHUBILLINGOUT WHERE
KSCHL = NAST-KSCHL.
IF SY-SUBRC EQ 0.
IF LV_CCNUM IS INITIAL.
LV_CCNUM = 1.
ENDIF.
ELSE.
CLEAR LV_CCNUM.
ENDIF.
* END: Country specific extension for Hungary
DO NAST_ANZAL TIMES.
* In case of repetition only one time archiving
IF SY-INDEX > 1 AND NAST-TDARMOD = 3.
NAST_TDARMOD = NAST-TDARMOD.
NAST-TDARMOD = 1.
LS_COMPOSER_PARAM-TDARMOD = 1.
ENDIF.
IF SY-INDEX NE 1 AND REPEAT IS INITIAL.
REPEAT = ‘X’.
ENDIF.
* BEGIN: Country specific extension for Hungary
IF LV_CCNUM IS NOT INITIAL.
IF NAST-REPID IS INITIAL.
NAST-REPID = 1.
ELSE.
NAST-REPID = NAST-REPID + 1.
ENDIF.
NAST-PFLD1 = LV_CCNUM.
ENDIF.
* END: Country specific extension for Hungary
***************************************************
IF LS_CONTROL_PARAM-PREVIEW = ‘ ‘.
LS_CONTROL_PARAM-GETOTF = ‘X’.
ENDIF.
****************************************************
* call smartform invoice
CALL FUNCTION LF_FM_NAME
EXPORTING
ARCHIVE_INDEX = TOA_DARA
ARCHIVE_PARAMETERS = ARC_PARAMS
CONTROL_PARAMETERS = LS_CONTROL_PARAM
* mail_appl_obj =
MAIL_RECIPIENT = LS_RECIPIENT
MAIL_SENDER = LS_SENDER
OUTPUT_OPTIONS = LS_COMPOSER_PARAM
USER_SETTINGS = SPACE
IS_BIL_INVOICE = LS_BIL_INVOICE
IS_NAST = NAST
IS_REPEAT = REPEAT
IMPORTING JOB_OUTPUT_INFO = LS_JOB_INFO
DOCUMENT_OUTPUT_INFO = LS_DOC_INFO
JOB_OUTPUT_OPTIONS = LS_JOB_OUTPUT
EXCEPTIONS FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5.
IF SY-SUBRC <> 0.
* error handling
CF_RETCODE = SY-SUBRC.
PERFORM PROTOCOL_UPDATE.
* get SmartForm protocoll and store it in the NAST protocoll
PERFORM ADD_SMFRM_PROT.
ENDIF.
ENDDO.
* get SmartForm spoolid and store it in the NAST protocoll
DATA LS_SPOOLID LIKE LINE OF LS_JOB_INFO-SPOOLIDS.
LOOP AT LS_JOB_INFO-SPOOLIDS INTO LS_SPOOLID.
IF LS_SPOOLID NE SPACE.
PERFORM PROTOCOL_UPDATE_SPOOL USING ‘342’ LS_SPOOLID
SPACE SPACE SPACE.
ENDIF.
ENDLOOP.
LS_COMPOSER_PARAM-TDCOPIES = NAST_ANZAL.
IF NOT NAST_TDARMOD IS INITIAL.
NAST-TDARMOD = NAST_TDARMOD.
CLEAR NAST_TDARMOD.
ENDIF.
ENDIF.
* get SmartForm protocoll and store it in the NAST protocoll
* PERFORM ADD_SMFRM_PROT.
***************************************************
IF LS_CONTROL_PARAM-PREVIEW = ‘ ‘.
DATA : V_BIN_FILESIZE TYPE I,
IT_LINES TYPE STANDARD TABLE OF TLINE WITH HEADER LINE,
IT_OTF_FINAL TYPE ITCOO OCCURS 0 WITH HEADER LINE,
PDF_BIN TYPE XSTRING,
PDF_CONTENT TYPE SOLIX_TAB.
IT_OTF_FINAL[] = LS_JOB_INFO-OTFDATA[].
CALL FUNCTION ‘CONVERT_OTF’
EXPORTING
FORMAT = ‘PDF’
MAX_LINEWIDTH = 132
* ARCHIVE_INDEX = ‘ ‘
* COPYNUMBER = 0
* ASCII_BIDI_VIS2LOG = ‘ ‘
* PDF_DELETE_OTFTAB = ‘ ‘
* PDF_USERNAME = ‘ ‘
IMPORTING
BIN_FILESIZE = V_BIN_FILESIZE
BIN_FILE = PDF_BIN
TABLES
OTF = IT_OTF_FINAL[]
LINES = IT_LINES[]
EXCEPTIONS
ERR_MAX_LINEWIDTH = 1
ERR_FORMAT = 2
ERR_CONV_NOT_POSSIBLE = 3
ERR_BAD_OTF = 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.
PDF_CONTENT = CL_DOCUMENT_BCS=>XSTRING_TO_SOLIX( PDF_BIN ).
*********************************************************************
* Email *
*********************************************************************
TYPES: TY_DOCUMENT_DATA TYPE SODOCCHGI1,
TY_PACKING_LIST TYPE SOPCKLSTI1,
TY_ATTACHMENT TYPE SOLISTI1,
TY_BODY_MSG TYPE SOLISTI1,
TY_RECEIVERS TYPE SOMLRECI1.
DATA: IT_DOCUMENT_DATA TYPE STANDARD TABLE OF TY_DOCUMENT_DATA,
IT_PACKING_LIST TYPE STANDARD TABLE OF TY_PACKING_LIST,
IT_ATTACHMENT TYPE STANDARD TABLE OF TY_ATTACHMENT,
IT_BODY_MSG TYPE STANDARD TABLE OF TY_BODY_MSG,
IT_RECEIVERS TYPE STANDARD TABLE OF TY_RECEIVERS,
GT_ATTCH TYPE STANDARD TABLE OF SOLISTI1.
DATA :WA_DOCUMENT_DATA TYPE TY_DOCUMENT_DATA,
WA_PACKING_LIST TYPE TY_PACKING_LIST,
WA_ATTACHMENT TYPE TY_ATTACHMENT,
WA_BODY_MSG TYPE TY_BODY_MSG,
WA_RECEIVERS TYPE TY_RECEIVERS,
GS_ATTCH TYPE SOLISTI1,
GS_SOLI TYPE SOLI.
DATA: G_TAB_LINES TYPE I,
G_SENT_TO_ALL TYPE SONV-FLAG,
LV_DATE(10) TYPE C,
LV_TIME(8) TYPE C,
LV_MAT_DES TYPE MAKTX.
DATA: IT_EMAIL TYPE STANDARD TABLE OF ZSD_EMAIL_DLIST,
WA_EMAIL TYPE ZSD_EMAIL_DLIST.
CONSTANTS: C_TAB TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,
C_CRET TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF,
COMMA TYPE C VALUE ‘,’,
C_1 VALUE ‘1’,
C_0 VALUE ‘0’.
* SUBJECT OF THE MAIL.
CLEAR: LV_DATE, LV_TIME, WA_DOCUMENT_DATA-OBJ_DESCR.
* CONCATENATE SY-DATUM+4(2) ‘_’ SY-DATUM+6(2) ‘_’ SY-DATUM(4) INTO LV_DATE.
* CONCATENATE SY-UZEIT(2) ‘_’ SY-UZEIT+2(2) ‘_’ SY-UZEIT+4(2) INTO LV_TIME.
* CONCATENATE ‘ XXX Invoice(s)’ LV_DATE ‘_’ LV_TIME INTO WA_DOCUMENT_DATA-OBJ_DESCR.
WA_DOCUMENT_DATA-OBJ_DESCR = ‘XXX Invoice(s)’.
* BODY OF THE MAIL
WA_BODY_MSG = SPACE.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = ‘Dear Valued Customer:’.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = SPACE.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = ‘Attached please find invoice(s) for XXX products provided by XXX. If you have any questions, please’.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = ‘contact us at xxx-xxx-xxxx or at [email protected].’.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = SPACE.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = ‘Thank you in advance for choosing XXX products to be sold at your locations.’.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = SPACE.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = ‘Sincerely,’.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = SPACE.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = ‘XXX’.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = SPACE.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = SPACE.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = ‘Please do not respond to this message. This email account is not monitored. This message was distributed by XXX,’.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = ‘XXX and related trademarks are registered trademarks and’.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = ‘trademarks in the United States and/or other countries, used under license from XXX. This electronic message is’.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = ‘not an advertisement or solicitation.’.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
CLEAR WA_BODY_MSG.
WA_DOCUMENT_DATA-OBJ_NAME = ‘SMARTFORM’.
* WRITE PACKING LIST FOR BODY
DESCRIBE TABLE IT_BODY_MSG LINES G_TAB_LINES.
WA_PACKING_LIST-HEAD_START = 1.
WA_PACKING_LIST-HEAD_NUM = 0.
WA_PACKING_LIST-BODY_START = 1.
WA_PACKING_LIST-BODY_NUM = G_TAB_LINES.
WA_PACKING_LIST-DOC_TYPE = ‘RAW’.
APPEND WA_PACKING_LIST TO IT_PACKING_LIST.
CLEAR WA_PACKING_LIST.
“Write Packing List for Attachment
WA_PACKING_LIST-TRANSF_BIN = ‘X’.
WA_PACKING_LIST-HEAD_START = 1.
WA_PACKING_LIST-HEAD_NUM = 1.
WA_PACKING_LIST-BODY_START = 1.
DESCRIBE TABLE PDF_CONTENT LINES G_TAB_LINES.
WA_PACKING_LIST-DOC_TYPE = ‘PDF’.
WA_PACKING_LIST-OBJ_DESCR = WA_DOCUMENT_DATA-OBJ_DESCR.
WA_PACKING_LIST-OBJ_NAME = ‘PDF_ATTACHMENT’.
WA_PACKING_LIST-BODY_NUM = G_TAB_LINES.
WA_PACKING_LIST-DOC_SIZE = WA_PACKING_LIST-BODY_NUM * 255.
APPEND WA_PACKING_LIST TO IT_PACKING_LIST.
CLEAR WA_PACKING_LIST.
“Fill the document data and get size of attachment
WA_DOCUMENT_DATA-OBJ_LANGU = SY-LANGU.
WA_DOCUMENT_DATA-DOC_SIZE = ( G_TAB_LINES – 1 ) * 255.
“Receivers List.
LOOP AT S_EMAIL.
WA_RECEIVERS-REC_TYPE = ‘U’. “Internet address
WA_RECEIVERS-RECEIVER = S_EMAIL.
WA_RECEIVERS-COM_TYPE = ‘INT’.
WA_RECEIVERS-NOTIF_DEL = ‘X’.
WA_RECEIVERS-NOTIF_NDEL = ‘X’.
APPEND WA_RECEIVERS TO IT_RECEIVERS .
CLEAR:WA_RECEIVERS.
ENDLOOP.
“Function module to send mail to Recipients
CALL FUNCTION ‘SO_DOCUMENT_SEND_API1’
EXPORTING
DOCUMENT_DATA = WA_DOCUMENT_DATA
PUT_IN_OUTBOX = ‘X’
* SENDER_ADDRESS = SY-UNAME
* SENDER_ADDRESS_TYPE = ‘B’
COMMIT_WORK = ‘X’
IMPORTING
SENT_TO_ALL = G_SENT_TO_ALL
* NEW_OBJECT_ID =
* SENDER_ID =
TABLES
PACKING_LIST = IT_PACKING_LIST
* OBJECT_HEADER =
* CONTENTS_BIN =
CONTENTS_TXT = IT_BODY_MSG
CONTENTS_HEX = PDF_CONTENT
* OBJECT_PARA =
* OBJECT_PARB =
RECEIVERS = IT_RECEIVERS
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 .
MESSAGE S303(ME) WITH ‘Mail has been Successfully Sent.’.
ELSE.
MESSAGE S303(ME) WITH ‘Mail has not been Successfully Sent.’.
ENDIF.
ENDIF.
ENDFORM. “PROCESSING ”
Code Logic for Custom Program:
*&———————————————————————*
*& Report ZR_INVOICE_SEND_EMAIL
*&———————————————————————*
*&———————————————————————*
REPORT ZR_INVOICE_SEND_EMAIL NO STANDARD PAGE HEADING.
TABLES : VBRK.
TYPE-POOLS : SLIS.
*&———————————————————————*
*& Declarations *&
*&———————————————————————*
TYPES : BEGIN OF TY_FINAL,
CHECK TYPE CHECKBOX,
VBELN TYPE VBELN_VF,
FKART TYPE FKART,
VKORG TYPE VKORG,
VTWEG TYPE VTWEG,
SPART TYPE SPART,
FKDAT TYPE FKDAT,
ERNAM TYPE ERNAM,
KUNRG TYPE KUNRG,
KUNAG TYPE KUNNR,
FLAG TYPE C,
END OF TY_FINAL,
BEGIN OF TY_ADR6,
ADDRNUMBER TYPE AD_ADDRNUM,
SMTP_ADDR TYPE AD_SMTPADR,
END OF TY_ADR6,
BEGIN OF TY_ADR61,
EMAIL1 TYPE AD_SMTPADR,
EMAIL2 TYPE AD_SMTPADR,
EMAIL3 TYPE AD_SMTPADR,
EMAIL4 TYPE AD_SMTPADR,
EMAIL5 TYPE AD_SMTPADR,
END OF TY_ADR61,
BEGIN OF TY_OUTPUT,
CHECK TYPE CHECKBOX,
VBELN TYPE VBELN_VF,
FKART TYPE FKART,
VKORG TYPE VKORG,
VTWEG TYPE VTWEG,
SPART TYPE SPART,
FKDAT TYPE FKDAT,
ERNAM TYPE ERNAM,
KUNRG TYPE KUNRG,
KUNAG TYPE KUNNR,
VTEXT TYPE BEZEI20,
NAME1_P TYPE NAME1_GP,
NAME1_S TYPE NAME1_GP,
VSTAT TYPE NA_VSTAT,
EMAIL1 TYPE AD_SMTPADR,
EMAIL2 TYPE AD_SMTPADR,
EMAIL3 TYPE AD_SMTPADR,
EMAIL4 TYPE AD_SMTPADR,
EMAIL5 TYPE AD_SMTPADR,
FLAG TYPE C,
END OF TY_OUTPUT.
*&———————————————————————*
*& Internal Table Declarations *&
*&———————————————————————*
DATA : IT_FINAL TYPE TABLE OF TY_FINAL,
IT_FINAL1 TYPE TABLE OF TY_FINAL,
IT_OUTPUT TYPE TABLE OF TY_OUTPUT,
IT_VBPA TYPE STANDARD TABLE OF VBPA,
IT_TVFKT TYPE STANDARD TABLE OF TVFKT,
IT_ADR6 TYPE STANDARD TABLE OF TY_ADR6,
IT_ADR61 TYPE STANDARD TABLE OF TY_ADR61,
IT_FINAL2 TYPE STANDARD TABLE OF TY_FINAL,
IT_FINAL3 TYPE STANDARD TABLE OF TY_FINAL,
IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
IT_BDCMSG TYPE TABLE OF BDCMSGCOLL,
IT_NAST TYPE STANDARD TABLE OF NAST,
*&———————————————————————*
*& Work Area Declarations *&
*&———————————————————————*
WA_OUTPUT TYPE TY_OUTPUT,
WA_TVFKT TYPE TVFKT,
WA_VBPA TYPE VBPA,
WA_KNA1 TYPE KNA1,
WA_ADR6 TYPE TY_ADR6,
WA_ADR61 TYPE TY_ADR61,
WA_NAST TYPE NAST,
WA_FINAL TYPE TY_FINAL,
WA_FINAL3 TYPE TY_FINAL,
WA_FINAL2 TYPE TY_FINAL,
WA_FINAL1 TYPE TY_FINAL,
WA_FCAT TYPE SLIS_FIELDCAT_ALV,
S_LAYOUT TYPE SLIS_LAYOUT_ALV,
BDCDATA TYPE BDCDATA OCCURS 1 WITH HEADER LINE,
WA_BDCMSG TYPE BDCMSGCOLL,
CURR_LINE TYPE SY-TABIX,
WA_CTUPARAMS TYPE CTU_PARAMS.
FIELD-SYMBOLS : <FS> TYPE ANY,
<FS2> TYPE ANY.
*&———————————————————————*
*& Select-Options *&
*&———————————————————————*
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_VBELN FOR VBRK-VBELN,
S_FKDAT FOR VBRK-FKDAT OBLIGATORY,
S_ERNAM FOR VBRK-ERNAM,
S_FKART FOR VBRK-FKART DEFAULT ‘F2’,
S_VKORG FOR VBRK-VKORG,
S_VTWEG FOR VBRK-VTWEG,
S_SPART FOR VBRK-SPART,
S_KUNRG FOR VBRK-KUNRG,
S_KUNAG FOR VBRK-KUNAG.
SELECTION-SCREEN END OF BLOCK B1.
*&———————————————————————*
*& Start-of-Selection *&
*&———————————————————————*
START-OF-SELECTION.
PERFORM GET_DISPLAY_DATA.
*&———————————————————————*
*& Form GET_DISPLAY_DATA
*&———————————————————————*
* text
*———————————————————————-*
FORM GET_DISPLAY_DATA .
SELECT VBELN
FKART
VKORG
VTWEG
SPART
FKDAT
ERNAM
KUNRG
KUNAG FROM VBRK
INTO CORRESPONDING FIELDS OF TABLE IT_FINAL
WHERE VBELN IN S_VBELN
AND FKART IN S_FKART
AND VKORG IN S_VKORG
AND VTWEG IN S_VTWEG
AND SPART IN S_SPART
AND FKDAT IN S_FKDAT
AND ERNAM IN S_ERNAM
AND KUNRG IN S_KUNRG
AND KUNAG IN S_KUNAG.
* SELECT OBJKY ERUHR VSTAT FROM NAST INTO CORRESPONDING FIELDS OF TABLE IT_NAST
* FOR ALL ENTRIES IN IT_FINAL
* WHERE OBJKY = IT_FINAL-VBELN
* AND KSCHL = ‘ZEMA’
* ORDER BY ERUHR DESCENDING.
* ENDSELECT.
** SORT DESCENDING BY WA_NAST-ERUHR.
* IF SY-SUBRC = 0.
* IF WA_NAST-VSTAT = 0.
* WA_OUTPUT-VSTAT = ‘N’.
* ELSEIF WA_NAST-VSTAT = 1.
* WA_OUTPUT-VSTAT = ‘Y’.
* ENDIF.
* ELSE.
* WA_OUTPUT-VSTAT = ‘N’.
* WA_OUTPUT-FLAG = ‘X’.
* ENDIF.
IF IT_FINAL IS NOT INITIAL.
SELECT FKART VTEXT FROM TVFKT INTO CORRESPONDING FIELDS OF TABLE IT_TVFKT
FOR ALL ENTRIES IN IT_FINAL
WHERE FKART = IT_FINAL-FKART
AND SPRAS = ‘E’.
LOOP AT IT_FINAL INTO WA_FINAL.
MOVE-CORRESPONDING WA_FINAL TO WA_OUTPUT.
READ TABLE IT_TVFKT INTO WA_TVFKT WITH KEY FKART = WA_FINAL-FKART.
IF SY-SUBRC = 0.
WA_OUTPUT-VTEXT = WA_TVFKT-VTEXT.
ENDIF.
SELECT SINGLE KUNNR NAME1 FROM KNA1 INTO CORRESPONDING FIELDS OF WA_KNA1
WHERE KUNNR = WA_FINAL-KUNRG.
IF SY-SUBRC = 0.
WA_OUTPUT-NAME1_P = WA_KNA1-NAME1.
CLEAR : WA_KNA1.
ENDIF.
SELECT SINGLE KUNNR NAME1 FROM KNA1 INTO CORRESPONDING FIELDS OF WA_KNA1
WHERE KUNNR = WA_FINAL-KUNAG.
IF SY-SUBRC = 0.
WA_OUTPUT-NAME1_S = WA_KNA1-NAME1.
CLEAR : WA_KNA1.
ENDIF.
SELECT OBJKY ERDAT ERUHR VSTAT FROM NAST INTO CORRESPONDING FIELDS OF TABLE IT_NAST
* FOR ALL ENTRIES IN WA_FINAL
WHERE OBJKY = WA_FINAL-VBELN
AND KSCHL = ‘ZEMA’.
” ORDER BY ERDAT DESCENDING
SORT IT_NAST BY ERUHR DESCENDING.
SORT IT_NAST BY ERDAT DESCENDING.
*DATA : INDEX TYPE SY-INDEX.
IF SY-SUBRC = 0.
READ TABLE IT_NAST INTO WA_NAST WITH KEY OBJKY = WA_FINAL-VBELN.
IF SY-SUBRC = 0.
IF WA_NAST-VSTAT = 0.
WA_OUTPUT-VSTAT = ‘N’.
ELSEIF WA_NAST-VSTAT = 1.
WA_OUTPUT-VSTAT = ‘Y’.
ELSEIF WA_NAST-VSTAT = 2.
WA_OUTPUT-VSTAT = ‘N’.
WA_OUTPUT-FLAG = ‘X’.
ENDIF.
ENDIF.
ELSE.
WA_OUTPUT-VSTAT = ‘N’.
WA_OUTPUT-FLAG = ‘X’.
ENDIF.
SELECT SINGLE VBELN PARVW KUNNR ADRNR FROM VBPA INTO CORRESPONDING FIELDS OF WA_VBPA
WHERE VBELN = WA_FINAL-VBELN
AND KUNNR = WA_FINAL-KUNRG
AND PARVW = ‘AG’.
IF SY-SUBRC = 0.
SELECT SMTP_ADDR FROM ADR6 INTO CORRESPONDING FIELDS OF TABLE IT_ADR6
WHERE ADDRNUMBER = WA_VBPA-ADRNR.
DELETE ADJACENT DUPLICATES FROM IT_ADR6 COMPARING ALL FIELDS.
LOOP AT IT_ADR6 INTO WA_ADR6.
CLEAR WA_ADR61.
ASSIGN COMPONENT SY-TABIX OF STRUCTURE WA_ADR61 TO <FS>.
CURR_LINE = SY-TABIX.
DO.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE WA_ADR6 TO <FS2>.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
IF CURR_LINE = 1.
<FS> = <FS2>.
APPEND WA_ADR61 TO IT_ADR61 .
ELSE.
READ TABLE IT_ADR61 INTO WA_ADR61 INDEX SY-INDEX.
<FS> = <FS2>.
MODIFY IT_ADR61 FROM WA_ADR61 INDEX SY-INDEX.
ENDIF.
ENDDO.
ENDLOOP.
LOOP AT IT_ADR61 INTO WA_ADR61.
IF SY-SUBRC = 0.
WA_OUTPUT-EMAIL1 = WA_ADR61-EMAIL1.
WA_OUTPUT-EMAIL2 = WA_ADR61-EMAIL2.
WA_OUTPUT-EMAIL3 = WA_ADR61-EMAIL3.
WA_OUTPUT-EMAIL4 = WA_ADR61-EMAIL4.
WA_OUTPUT-EMAIL5 = WA_ADR61-EMAIL5.
ENDIF.
ENDLOOP.
ENDIF.
APPEND WA_OUTPUT TO IT_OUTPUT.
CLEAR : WA_OUTPUT.
REFRESH : IT_ADR61.
ENDLOOP.
PERFORM SUB_POPULATE USING : ‘1’ ‘CHECK’ ‘ ‘ ‘X’ ‘X’,
‘2’ ‘VBELN’ ‘Billing Doc.No.’ ‘ ‘ ‘ ‘ ,
‘3’ ‘FKART’ ‘Billing Type’ ‘ ‘ ‘ ‘ ,
‘4’ ‘VTEXT’ ‘Billing Type Desc.’ ‘ ‘ ‘ ‘,
‘4’ ‘VKORG’ ‘Sales Organization’ ‘ ‘ ‘ ‘,
‘5’ ‘VTWEG’ ‘Distribution Channel’ ‘ ‘ ‘ ‘,
‘6’ ‘SPART’ ‘Division’ ‘ ‘ ‘ ‘,
‘7’ ‘FKDAT’ ‘Billing Date’ ‘ ‘ ‘ ‘,
‘8’ ‘ERNAM’ ‘Created By’ ‘ ‘ ‘ ‘,
‘9’ ‘KUNRG’ ‘Payer’ ‘ ‘ ‘ ‘,
’10’ ‘NAME1_P’ ‘Payer Name’ ‘ ‘ ‘ ‘,
’11’ ‘KUNAG’ ‘Sold-to Party’ ‘ ‘ ‘ ‘,
’12’ ‘NAME1_S’ ‘Sold-to Party Name’ ‘ ‘ ‘ ‘,
’13’ ‘VSTAT’ ‘Email Sent(Y/N)’ ‘ ‘ ‘ ‘,
’14’ ‘EMAIL1’ ‘E-mail Address 1’ ‘ ‘ ‘ ‘,
’15’ ‘EMAIL2’ ‘E-mail Address 2’ ‘ ‘ ‘ ‘,
’16’ ‘EMAIL3’ ‘E-mail Address 3’ ‘ ‘ ‘ ‘,
’17’ ‘EMAIL4’ ‘E-mail Address 4’ ‘ ‘ ‘ ‘,
’18’ ‘EMAIL5’ ‘E-mail Address 5’ ‘ ‘ ‘ ‘.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
* I_INTERFACE_CHECK = ‘ ‘
* I_BYPASSING_BUFFER = ‘ ‘
* I_BUFFER_ACTIVE = ‘ ‘
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_PF_STATUS_SET = ‘PF’
I_CALLBACK_USER_COMMAND = ‘USER_COMMAND’
* I_CALLBACK_TOP_OF_PAGE = ‘ ‘
* I_CALLBACK_HTML_TOP_OF_PAGE = ‘ ‘
* I_CALLBACK_HTML_END_OF_LIST = ‘ ‘
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ‘ ‘
* I_GRID_TITLE =
* I_GRID_SETTINGS =
IS_LAYOUT = S_LAYOUT
IT_FIELDCAT = IT_FCAT
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
I_DEFAULT = ‘X’
I_SAVE = ‘A’
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = IT_OUTPUT
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ELSE.
MESSAGE ‘No records found for the selection criteria’ TYPE ‘S’ DISPLAY LIKE ‘E’.
ENDIF.
ENDFORM. ” GET_DISPLAY_DATA
*&———————————————————————*
*& Form SUB_POPULATE
*&———————————————————————*
* text
*———————————————————————-*
FORM SUB_POPULATE USING COL_POS
FIELDNAME
SELTEXT_M
* JUST.
* INPUT
CHECKBOX
EDIT.
WA_FCAT-COL_POS = COL_POS.
WA_FCAT-FIELDNAME = FIELDNAME.
WA_FCAT-SELTEXT_M = SELTEXT_M.
* WA_FCAT-INPUT = INPUT.
WA_FCAT-CHECKBOX = CHECKBOX.
WA_FCAT-EDIT = EDIT.
APPEND WA_FCAT TO IT_FCAT.
CLEAR : WA_FCAT.
S_LAYOUT-ZEBRA = ‘X’.
S_LAYOUT-COLWIDTH_OPTIMIZE = ‘X’.
ENDFORM. ” SUB_POPULATE
*&———————————————————————*
*& Form PF
*&———————————————————————*
*
*———————————————————————-*
FORM PF USING RT_EXTAB TYPE SLIS_T_EXTAB.
SET PF-STATUS ‘ZSTANDARD’.” EXCLUDING RT_EXTAB.
ENDFORM. “PF
*&———————————————————————*
*& Form PF
*&———————————————————————*
*
*———————————————————————-*
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
DATA REF_GRID TYPE REF TO CL_GUI_ALV_GRID.
IF REF_GRID IS INITIAL.
CALL FUNCTION ‘GET_GLOBALS_FROM_SLVC_FULLSCR’
IMPORTING
E_GRID = REF_GRID.
ENDIF.
IF NOT REF_GRID IS INITIAL.
CALL METHOD REF_GRID->CHECK_CHANGED_DATA.
ENDIF.
IF R_UCOMM = ‘&EXE’.
* CLEAR : FLAG.
DATA : WA_NAST TYPE NAST.
LOOP AT IT_OUTPUT INTO WA_OUTPUT.
IF WA_OUTPUT-CHECK = ‘X’ AND WA_OUTPUT-FLAG = ‘ ‘.
REFRESH BDCDATA.
PERFORM BDC_DYNPRO USING ‘SD70AV3A’ ‘1000’.
PERFORM BDC_FIELD USING ‘BDC_CURSOR’
‘PM_VERMO’.
PERFORM BDC_FIELD USING ‘BDC_OKCODE’
‘=ONLI’.
PERFORM BDC_FIELD USING ‘RG_KSCHL-LOW’
‘ZEMA’.
PERFORM BDC_FIELD USING ‘RG_NACHA-LOW’
‘5’.
PERFORM BDC_FIELD USING ‘PM_NSORT’
’01’.
IF WA_OUTPUT-VSTAT = ‘N’.
PERFORM BDC_FIELD USING ‘PM_VERMO’
‘1’.
ELSEIF WA_OUTPUT-VSTAT = ‘Y’.
PERFORM BDC_FIELD USING ‘PM_VERMO’
‘2’.
ENDIF.
PERFORM BDC_FIELD USING ‘RG_VBELN-LOW’
WA_OUTPUT-VBELN.
PERFORM BDC_FIELD USING ‘PM_ALLEL’
‘X’.
PERFORM BDC_FIELD USING ‘PM_ALLEA’
‘X’.
PERFORM BDC_FIELD USING ‘N_SELECT’
‘X’.
PERFORM BDC_DYNPRO USING ‘SAPMSSY0’ ‘0120’.
PERFORM BDC_FIELD USING ‘BDC_CURSOR’
’04/03′.
PERFORM BDC_FIELD USING ‘BDC_OKCODE’
‘=&ALL’.
PERFORM BDC_DYNPRO USING ‘SAPMSSY0’ ‘0120’.
PERFORM BDC_FIELD USING ‘BDC_CURSOR’
’04/03′.
PERFORM BDC_FIELD USING ‘BDC_OKCODE’
‘=PROC’.
*
WA_CTUPARAMS-DISMODE = ‘N’.
WA_CTUPARAMS-UPDMODE = ‘A’.
WA_CTUPARAMS-CATTMODE = ‘ ‘.
WA_CTUPARAMS-RACOMMIT = ‘X’.
WA_CTUPARAMS-DEFSIZE = ‘X’.
WA_CTUPARAMS-NOBINPT = ‘ ‘.
WA_CTUPARAMS-NOBIEND = ‘ ‘.
CALL TRANSACTION ‘VF31’ USING BDCDATA “MODE ‘N’ UPDATE ‘S’
OPTIONS FROM WA_CTUPARAMS
MESSAGES INTO IT_BDCMSG.
IF SY-SUBRC = 0 OR SY-SUBRC = ‘1001’.
APPEND WA_OUTPUT TO IT_FINAL1.
CLEAR : WA_OUTPUT.
ELSE.
APPEND WA_OUTPUT TO IT_FINAL2.
CLEAR : WA_OUTPUT.
ENDIF.
LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.
SET PF-STATUS SPACE.
SUPPRESS DIALOG.
NEW-PAGE NO-TITLE NO-HEADING.
ENDIF.
IF WA_OUTPUT-CHECK = ‘X’ AND WA_OUTPUT-FLAG = ‘X’.
APPEND WA_OUTPUT TO IT_FINAL3.
LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.
SET PF-STATUS SPACE.
SUPPRESS DIALOG.
NEW-PAGE NO-TITLE NO-HEADING.
ENDIF.
ENDLOOP.
IF IT_FINAL1 IS NOT INITIAL.
LOOP AT IT_FINAL1 INTO WA_FINAL1.
WRITE :/ ‘E-mail has been sent for Invoice Number’,WA_FINAL1-VBELN.
ENDLOOP.
ENDIF.
IF IT_FINAL2 IS NOT INITIAL.
LOOP AT IT_FINAL2 INTO WA_FINAL2.
WRITE :/ ‘E-mail has not been sent for Invoice Number’,WA_FINAL2-VBELN.
ENDLOOP.
ENDIF.
IF IT_FINAL3 IS NOT INITIAL.
LOOP AT IT_FINAL3 INTO WA_FINAL3.
WRITE :/ ‘E-mail cannot be sent for the Invoice Number’,WA_FINAL3-VBELN.
ENDLOOP.
ENDIF.
ELSEIF R_UCOMM = ‘&IC1’.
CASE RS_SELFIELD-FIELDNAME.
WHEN ‘VBELN’.
SET PARAMETER ID ‘VF’ FIELD RS_SELFIELD-VALUE.
CALL TRANSACTION ‘VF03’ AND SKIP FIRST SCREEN.
WHEN ‘KUNAG’.
SET PARAMETER ID ‘KUN’ FIELD RS_SELFIELD-VALUE.
CALL TRANSACTION ‘XD03’ AND SKIP FIRST SCREEN.
ENDCASE.
ENDIF.
ENDFORM. “USER_COMMAND
*&———————————————————————*
*& Form bdc_dynpro
*&———————————————————————*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = ‘X’.
APPEND BDCDATA.
ENDFORM. “bdc_dynpro
*&———————————————————————*
*& Form BDC_FIELD
*&———————————————————————*
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL <> SPACE.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM. “BDC_FIELD
Document Completed.
I hope you will like this document. If any suggestion, please let me know. I would like to have you guidance and suggestion.
Thanks,
Kundan Vishwakarma
Okumaya devam et...
I would like to share my knowledge about SD – Billing Invoice should send to multiple customer via email from SAP environment in PDF format. I know it may possible that to achieve this there may be a variety of option are available, but I would like to share my work knowledge which I had proceed for this business requirement.
Business Context:
In Standard SAP environment, we can send the mail to multiple recipient with standard format. But business required an custom program should trigger the mail with some additional column information along with custom message which can be easily understood by the business end user.
To overcome we need to go with Techno-Functional Configuration as per below steps:
Functional Configuration:
Transaction Code: NACE
Select V3 Application and click on Output types button.
Create any custom output as shown in below snap shot with the following below setups.
I had selected option # 3 under Dispatch time field, because the Invoice will trigger on the basis of business requirement, i.e. it would be on their dependencies.
Along with that , I also created separate custom communication strategy and assign it with our created custom output type.
Remark: Time Tab and Sort Order Tab is not applicable to filled for this scenario.
After completion of all the details under required tabs, click on “Mail title and texts” option.
After completion of Mail title and text structure, click on “Processing Routines” structure.
Note: We have created an custom program ZRLB_INVOICE with required coding logic for our output source.
In Partner Functions structure, update the data as shown in above snap shot.
Once all above functional configuration is done, save it.
Now, Output Type is created and now we need to assign it under Billing Output Procedure as shown in below snap shot.
Save it.
Maintained Condition Record: VV31
Save it.
Technical Coding:
*———————————————————————-*
* Print of a invoice by SAPscript SMART FORMS *
*———————————————————————-*
REPORT ZRLB_INVOICE.
**************************************************************************
* MODULE : Sales & Distribution
****************************************************************************
TABLES : ADR6.
* declaration of data
INCLUDE RLB_INVOICE_DATA_DECLARE.
* definition of forms
INCLUDE RLB_INVOICE_FORM01.
INCLUDE RLB_PRINT_FORMS.
*———————————————————————*
* FORM ENTRY
*———————————————————————*
FORM ENTRY USING RETURN_CODE US_SCREEN.
DATA: LF_RETCODE TYPE SY-SUBRC.
CLEAR RETCODE.
XSCREEN = US_SCREEN.
PERFORM PROCESSING USING US_SCREEN
CHANGING LF_RETCODE.
IF LF_RETCODE NE 0.
RETURN_CODE = 1.
ELSE.
RETURN_CODE = 0.
ENDIF.
ENDFORM. “ENTRY
*———————————————————————*
* FORM PROCESSING *
*———————————————————————*
FORM PROCESSING USING PROC_SCREEN
CHANGING CF_RETCODE.
DATA: LS_PRINT_DATA_TO_READ TYPE LBBIL_PRINT_DATA_TO_READ.
DATA: LS_BIL_INVOICE TYPE LBBIL_INVOICE.
DATA: LF_FM_NAME TYPE RS38L_FNAM.
DATA: LS_CONTROL_PARAM TYPE SSFCTRLOP.
DATA: LS_COMPOSER_PARAM TYPE SSFCOMPOP.
DATA: LS_RECIPIENT TYPE SWOTOBJID.
DATA: LS_SENDER TYPE SWOTOBJID.
DATA: LF_FORMNAME TYPE TDSFNAME.
DATA: LS_ADDR_KEY LIKE ADDR_KEY.
DATA: LS_DLV-LAND LIKE VBRK-LAND1.
DATA: LS_JOB_INFO TYPE SSFCRESCL,
LS_DOC_INFO TYPE SSFCRESPD,
LS_JOB_OUTPUT TYPE SSFCRESOP.
* SmartForm from customizing table TNAPR
LF_FORMNAME = TNAPR-SFORM.
* determine print data
PERFORM SET_PRINT_DATA_TO_READ USING LF_FORMNAME
CHANGING LS_PRINT_DATA_TO_READ
CF_RETCODE.
IF CF_RETCODE = 0.
* select print data
PERFORM GET_DATA USING LS_PRINT_DATA_TO_READ
CHANGING LS_ADDR_KEY
LS_DLV-LAND
LS_BIL_INVOICE
CF_RETCODE.
ENDIF.
*********************************************
TYPES : BEGIN OF TY_ADR6,
ADDRNUMBER TYPE AD_ADDRNUM,
SMTP_ADDR TYPE AD_SMTPADR,
END OF TY_ADR6.
DATA : WA_ADR6 TYPE TY_ADR6,
IT_ADR6 TYPE TABLE OF TY_ADR6,
S_EMAIL TYPE TABLE OF ADR6-SMTP_ADDR WITH HEADER LINE.
SELECT ADDRNUMBER SMTP_ADDR FROM ADR6 INTO CORRESPONDING FIELDS OF TABLE IT_ADR6 WHERE ADDRNUMBER = LS_ADDR_KEY-ADDRNUMBER.
IF SY-SUBRC = 0.
LOOP AT IT_ADR6 INTO WA_ADR6.
S_EMAIL = WA_ADR6-SMTP_ADDR.
APPEND S_EMAIL.
ENDLOOP.
ENDIF.
*************************************************
IF CF_RETCODE = 0.
PERFORM SET_PRINT_PARAM USING LS_ADDR_KEY
LS_DLV-LAND
CHANGING LS_CONTROL_PARAM
LS_COMPOSER_PARAM
LS_RECIPIENT
LS_SENDER
CF_RETCODE.
ENDIF.
IF CF_RETCODE = 0.
* determine smartform function module for invoice
CALL FUNCTION ‘SSF_FUNCTION_MODULE_NAME’
EXPORTING FORMNAME = LF_FORMNAME
* variant = ‘ ‘
* direct_call = ‘ ‘
IMPORTING FM_NAME = LF_FM_NAME
EXCEPTIONS NO_FORM = 1
NO_FUNCTION_MODULE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
* error handling
CF_RETCODE = SY-SUBRC.
PERFORM PROTOCOL_UPDATE.
ENDIF.
ENDIF.
IF CF_RETCODE = 0.
PERFORM CHECK_REPEAT.
IF LS_COMPOSER_PARAM-TDCOPIES EQ 0.
NAST_ANZAL = 1.
ELSE.
NAST_ANZAL = LS_COMPOSER_PARAM-TDCOPIES.
ENDIF.
LS_COMPOSER_PARAM-TDCOPIES = 1.
* BEGIN: Country specific extension for Hungary
DATA: LV_CCNUM TYPE IDHUCCNUM.
* If a valid entry exists for the form in customizing view
* IDHUBILLINGOUT then the localized output shall be used.
SELECT SINGLE CCNUM INTO LV_CCNUM FROM IDHUBILLINGOUT WHERE
KSCHL = NAST-KSCHL.
IF SY-SUBRC EQ 0.
IF LV_CCNUM IS INITIAL.
LV_CCNUM = 1.
ENDIF.
ELSE.
CLEAR LV_CCNUM.
ENDIF.
* END: Country specific extension for Hungary
DO NAST_ANZAL TIMES.
* In case of repetition only one time archiving
IF SY-INDEX > 1 AND NAST-TDARMOD = 3.
NAST_TDARMOD = NAST-TDARMOD.
NAST-TDARMOD = 1.
LS_COMPOSER_PARAM-TDARMOD = 1.
ENDIF.
IF SY-INDEX NE 1 AND REPEAT IS INITIAL.
REPEAT = ‘X’.
ENDIF.
* BEGIN: Country specific extension for Hungary
IF LV_CCNUM IS NOT INITIAL.
IF NAST-REPID IS INITIAL.
NAST-REPID = 1.
ELSE.
NAST-REPID = NAST-REPID + 1.
ENDIF.
NAST-PFLD1 = LV_CCNUM.
ENDIF.
* END: Country specific extension for Hungary
***************************************************
IF LS_CONTROL_PARAM-PREVIEW = ‘ ‘.
LS_CONTROL_PARAM-GETOTF = ‘X’.
ENDIF.
****************************************************
* call smartform invoice
CALL FUNCTION LF_FM_NAME
EXPORTING
ARCHIVE_INDEX = TOA_DARA
ARCHIVE_PARAMETERS = ARC_PARAMS
CONTROL_PARAMETERS = LS_CONTROL_PARAM
* mail_appl_obj =
MAIL_RECIPIENT = LS_RECIPIENT
MAIL_SENDER = LS_SENDER
OUTPUT_OPTIONS = LS_COMPOSER_PARAM
USER_SETTINGS = SPACE
IS_BIL_INVOICE = LS_BIL_INVOICE
IS_NAST = NAST
IS_REPEAT = REPEAT
IMPORTING JOB_OUTPUT_INFO = LS_JOB_INFO
DOCUMENT_OUTPUT_INFO = LS_DOC_INFO
JOB_OUTPUT_OPTIONS = LS_JOB_OUTPUT
EXCEPTIONS FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5.
IF SY-SUBRC <> 0.
* error handling
CF_RETCODE = SY-SUBRC.
PERFORM PROTOCOL_UPDATE.
* get SmartForm protocoll and store it in the NAST protocoll
PERFORM ADD_SMFRM_PROT.
ENDIF.
ENDDO.
* get SmartForm spoolid and store it in the NAST protocoll
DATA LS_SPOOLID LIKE LINE OF LS_JOB_INFO-SPOOLIDS.
LOOP AT LS_JOB_INFO-SPOOLIDS INTO LS_SPOOLID.
IF LS_SPOOLID NE SPACE.
PERFORM PROTOCOL_UPDATE_SPOOL USING ‘342’ LS_SPOOLID
SPACE SPACE SPACE.
ENDIF.
ENDLOOP.
LS_COMPOSER_PARAM-TDCOPIES = NAST_ANZAL.
IF NOT NAST_TDARMOD IS INITIAL.
NAST-TDARMOD = NAST_TDARMOD.
CLEAR NAST_TDARMOD.
ENDIF.
ENDIF.
* get SmartForm protocoll and store it in the NAST protocoll
* PERFORM ADD_SMFRM_PROT.
***************************************************
IF LS_CONTROL_PARAM-PREVIEW = ‘ ‘.
DATA : V_BIN_FILESIZE TYPE I,
IT_LINES TYPE STANDARD TABLE OF TLINE WITH HEADER LINE,
IT_OTF_FINAL TYPE ITCOO OCCURS 0 WITH HEADER LINE,
PDF_BIN TYPE XSTRING,
PDF_CONTENT TYPE SOLIX_TAB.
IT_OTF_FINAL[] = LS_JOB_INFO-OTFDATA[].
CALL FUNCTION ‘CONVERT_OTF’
EXPORTING
FORMAT = ‘PDF’
MAX_LINEWIDTH = 132
* ARCHIVE_INDEX = ‘ ‘
* COPYNUMBER = 0
* ASCII_BIDI_VIS2LOG = ‘ ‘
* PDF_DELETE_OTFTAB = ‘ ‘
* PDF_USERNAME = ‘ ‘
IMPORTING
BIN_FILESIZE = V_BIN_FILESIZE
BIN_FILE = PDF_BIN
TABLES
OTF = IT_OTF_FINAL[]
LINES = IT_LINES[]
EXCEPTIONS
ERR_MAX_LINEWIDTH = 1
ERR_FORMAT = 2
ERR_CONV_NOT_POSSIBLE = 3
ERR_BAD_OTF = 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.
PDF_CONTENT = CL_DOCUMENT_BCS=>XSTRING_TO_SOLIX( PDF_BIN ).
*********************************************************************
* Email *
*********************************************************************
TYPES: TY_DOCUMENT_DATA TYPE SODOCCHGI1,
TY_PACKING_LIST TYPE SOPCKLSTI1,
TY_ATTACHMENT TYPE SOLISTI1,
TY_BODY_MSG TYPE SOLISTI1,
TY_RECEIVERS TYPE SOMLRECI1.
DATA: IT_DOCUMENT_DATA TYPE STANDARD TABLE OF TY_DOCUMENT_DATA,
IT_PACKING_LIST TYPE STANDARD TABLE OF TY_PACKING_LIST,
IT_ATTACHMENT TYPE STANDARD TABLE OF TY_ATTACHMENT,
IT_BODY_MSG TYPE STANDARD TABLE OF TY_BODY_MSG,
IT_RECEIVERS TYPE STANDARD TABLE OF TY_RECEIVERS,
GT_ATTCH TYPE STANDARD TABLE OF SOLISTI1.
DATA :WA_DOCUMENT_DATA TYPE TY_DOCUMENT_DATA,
WA_PACKING_LIST TYPE TY_PACKING_LIST,
WA_ATTACHMENT TYPE TY_ATTACHMENT,
WA_BODY_MSG TYPE TY_BODY_MSG,
WA_RECEIVERS TYPE TY_RECEIVERS,
GS_ATTCH TYPE SOLISTI1,
GS_SOLI TYPE SOLI.
DATA: G_TAB_LINES TYPE I,
G_SENT_TO_ALL TYPE SONV-FLAG,
LV_DATE(10) TYPE C,
LV_TIME(8) TYPE C,
LV_MAT_DES TYPE MAKTX.
DATA: IT_EMAIL TYPE STANDARD TABLE OF ZSD_EMAIL_DLIST,
WA_EMAIL TYPE ZSD_EMAIL_DLIST.
CONSTANTS: C_TAB TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,
C_CRET TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF,
COMMA TYPE C VALUE ‘,’,
C_1 VALUE ‘1’,
C_0 VALUE ‘0’.
* SUBJECT OF THE MAIL.
CLEAR: LV_DATE, LV_TIME, WA_DOCUMENT_DATA-OBJ_DESCR.
* CONCATENATE SY-DATUM+4(2) ‘_’ SY-DATUM+6(2) ‘_’ SY-DATUM(4) INTO LV_DATE.
* CONCATENATE SY-UZEIT(2) ‘_’ SY-UZEIT+2(2) ‘_’ SY-UZEIT+4(2) INTO LV_TIME.
* CONCATENATE ‘ XXX Invoice(s)’ LV_DATE ‘_’ LV_TIME INTO WA_DOCUMENT_DATA-OBJ_DESCR.
WA_DOCUMENT_DATA-OBJ_DESCR = ‘XXX Invoice(s)’.
* BODY OF THE MAIL
WA_BODY_MSG = SPACE.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = ‘Dear Valued Customer:’.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = SPACE.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = ‘Attached please find invoice(s) for XXX products provided by XXX. If you have any questions, please’.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = ‘contact us at xxx-xxx-xxxx or at [email protected].’.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = SPACE.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = ‘Thank you in advance for choosing XXX products to be sold at your locations.’.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = SPACE.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = ‘Sincerely,’.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = SPACE.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = ‘XXX’.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = SPACE.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = SPACE.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = ‘Please do not respond to this message. This email account is not monitored. This message was distributed by XXX,’.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = ‘XXX and related trademarks are registered trademarks and’.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = ‘trademarks in the United States and/or other countries, used under license from XXX. This electronic message is’.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
WA_BODY_MSG = ‘not an advertisement or solicitation.’.
APPEND WA_BODY_MSG TO IT_BODY_MSG.
CLEAR WA_BODY_MSG.
WA_DOCUMENT_DATA-OBJ_NAME = ‘SMARTFORM’.
* WRITE PACKING LIST FOR BODY
DESCRIBE TABLE IT_BODY_MSG LINES G_TAB_LINES.
WA_PACKING_LIST-HEAD_START = 1.
WA_PACKING_LIST-HEAD_NUM = 0.
WA_PACKING_LIST-BODY_START = 1.
WA_PACKING_LIST-BODY_NUM = G_TAB_LINES.
WA_PACKING_LIST-DOC_TYPE = ‘RAW’.
APPEND WA_PACKING_LIST TO IT_PACKING_LIST.
CLEAR WA_PACKING_LIST.
“Write Packing List for Attachment
WA_PACKING_LIST-TRANSF_BIN = ‘X’.
WA_PACKING_LIST-HEAD_START = 1.
WA_PACKING_LIST-HEAD_NUM = 1.
WA_PACKING_LIST-BODY_START = 1.
DESCRIBE TABLE PDF_CONTENT LINES G_TAB_LINES.
WA_PACKING_LIST-DOC_TYPE = ‘PDF’.
WA_PACKING_LIST-OBJ_DESCR = WA_DOCUMENT_DATA-OBJ_DESCR.
WA_PACKING_LIST-OBJ_NAME = ‘PDF_ATTACHMENT’.
WA_PACKING_LIST-BODY_NUM = G_TAB_LINES.
WA_PACKING_LIST-DOC_SIZE = WA_PACKING_LIST-BODY_NUM * 255.
APPEND WA_PACKING_LIST TO IT_PACKING_LIST.
CLEAR WA_PACKING_LIST.
“Fill the document data and get size of attachment
WA_DOCUMENT_DATA-OBJ_LANGU = SY-LANGU.
WA_DOCUMENT_DATA-DOC_SIZE = ( G_TAB_LINES – 1 ) * 255.
“Receivers List.
LOOP AT S_EMAIL.
WA_RECEIVERS-REC_TYPE = ‘U’. “Internet address
WA_RECEIVERS-RECEIVER = S_EMAIL.
WA_RECEIVERS-COM_TYPE = ‘INT’.
WA_RECEIVERS-NOTIF_DEL = ‘X’.
WA_RECEIVERS-NOTIF_NDEL = ‘X’.
APPEND WA_RECEIVERS TO IT_RECEIVERS .
CLEAR:WA_RECEIVERS.
ENDLOOP.
“Function module to send mail to Recipients
CALL FUNCTION ‘SO_DOCUMENT_SEND_API1’
EXPORTING
DOCUMENT_DATA = WA_DOCUMENT_DATA
PUT_IN_OUTBOX = ‘X’
* SENDER_ADDRESS = SY-UNAME
* SENDER_ADDRESS_TYPE = ‘B’
COMMIT_WORK = ‘X’
IMPORTING
SENT_TO_ALL = G_SENT_TO_ALL
* NEW_OBJECT_ID =
* SENDER_ID =
TABLES
PACKING_LIST = IT_PACKING_LIST
* OBJECT_HEADER =
* CONTENTS_BIN =
CONTENTS_TXT = IT_BODY_MSG
CONTENTS_HEX = PDF_CONTENT
* OBJECT_PARA =
* OBJECT_PARB =
RECEIVERS = IT_RECEIVERS
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 .
MESSAGE S303(ME) WITH ‘Mail has been Successfully Sent.’.
ELSE.
MESSAGE S303(ME) WITH ‘Mail has not been Successfully Sent.’.
ENDIF.
ENDIF.
ENDFORM. “PROCESSING ”
Code Logic for Custom Program:
*&———————————————————————*
*& Report ZR_INVOICE_SEND_EMAIL
*&———————————————————————*
*&———————————————————————*
REPORT ZR_INVOICE_SEND_EMAIL NO STANDARD PAGE HEADING.
TABLES : VBRK.
TYPE-POOLS : SLIS.
*&———————————————————————*
*& Declarations *&
*&———————————————————————*
TYPES : BEGIN OF TY_FINAL,
CHECK TYPE CHECKBOX,
VBELN TYPE VBELN_VF,
FKART TYPE FKART,
VKORG TYPE VKORG,
VTWEG TYPE VTWEG,
SPART TYPE SPART,
FKDAT TYPE FKDAT,
ERNAM TYPE ERNAM,
KUNRG TYPE KUNRG,
KUNAG TYPE KUNNR,
FLAG TYPE C,
END OF TY_FINAL,
BEGIN OF TY_ADR6,
ADDRNUMBER TYPE AD_ADDRNUM,
SMTP_ADDR TYPE AD_SMTPADR,
END OF TY_ADR6,
BEGIN OF TY_ADR61,
EMAIL1 TYPE AD_SMTPADR,
EMAIL2 TYPE AD_SMTPADR,
EMAIL3 TYPE AD_SMTPADR,
EMAIL4 TYPE AD_SMTPADR,
EMAIL5 TYPE AD_SMTPADR,
END OF TY_ADR61,
BEGIN OF TY_OUTPUT,
CHECK TYPE CHECKBOX,
VBELN TYPE VBELN_VF,
FKART TYPE FKART,
VKORG TYPE VKORG,
VTWEG TYPE VTWEG,
SPART TYPE SPART,
FKDAT TYPE FKDAT,
ERNAM TYPE ERNAM,
KUNRG TYPE KUNRG,
KUNAG TYPE KUNNR,
VTEXT TYPE BEZEI20,
NAME1_P TYPE NAME1_GP,
NAME1_S TYPE NAME1_GP,
VSTAT TYPE NA_VSTAT,
EMAIL1 TYPE AD_SMTPADR,
EMAIL2 TYPE AD_SMTPADR,
EMAIL3 TYPE AD_SMTPADR,
EMAIL4 TYPE AD_SMTPADR,
EMAIL5 TYPE AD_SMTPADR,
FLAG TYPE C,
END OF TY_OUTPUT.
*&———————————————————————*
*& Internal Table Declarations *&
*&———————————————————————*
DATA : IT_FINAL TYPE TABLE OF TY_FINAL,
IT_FINAL1 TYPE TABLE OF TY_FINAL,
IT_OUTPUT TYPE TABLE OF TY_OUTPUT,
IT_VBPA TYPE STANDARD TABLE OF VBPA,
IT_TVFKT TYPE STANDARD TABLE OF TVFKT,
IT_ADR6 TYPE STANDARD TABLE OF TY_ADR6,
IT_ADR61 TYPE STANDARD TABLE OF TY_ADR61,
IT_FINAL2 TYPE STANDARD TABLE OF TY_FINAL,
IT_FINAL3 TYPE STANDARD TABLE OF TY_FINAL,
IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
IT_BDCMSG TYPE TABLE OF BDCMSGCOLL,
IT_NAST TYPE STANDARD TABLE OF NAST,
*&———————————————————————*
*& Work Area Declarations *&
*&———————————————————————*
WA_OUTPUT TYPE TY_OUTPUT,
WA_TVFKT TYPE TVFKT,
WA_VBPA TYPE VBPA,
WA_KNA1 TYPE KNA1,
WA_ADR6 TYPE TY_ADR6,
WA_ADR61 TYPE TY_ADR61,
WA_NAST TYPE NAST,
WA_FINAL TYPE TY_FINAL,
WA_FINAL3 TYPE TY_FINAL,
WA_FINAL2 TYPE TY_FINAL,
WA_FINAL1 TYPE TY_FINAL,
WA_FCAT TYPE SLIS_FIELDCAT_ALV,
S_LAYOUT TYPE SLIS_LAYOUT_ALV,
BDCDATA TYPE BDCDATA OCCURS 1 WITH HEADER LINE,
WA_BDCMSG TYPE BDCMSGCOLL,
CURR_LINE TYPE SY-TABIX,
WA_CTUPARAMS TYPE CTU_PARAMS.
FIELD-SYMBOLS : <FS> TYPE ANY,
<FS2> TYPE ANY.
*&———————————————————————*
*& Select-Options *&
*&———————————————————————*
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_VBELN FOR VBRK-VBELN,
S_FKDAT FOR VBRK-FKDAT OBLIGATORY,
S_ERNAM FOR VBRK-ERNAM,
S_FKART FOR VBRK-FKART DEFAULT ‘F2’,
S_VKORG FOR VBRK-VKORG,
S_VTWEG FOR VBRK-VTWEG,
S_SPART FOR VBRK-SPART,
S_KUNRG FOR VBRK-KUNRG,
S_KUNAG FOR VBRK-KUNAG.
SELECTION-SCREEN END OF BLOCK B1.
*&———————————————————————*
*& Start-of-Selection *&
*&———————————————————————*
START-OF-SELECTION.
PERFORM GET_DISPLAY_DATA.
*&———————————————————————*
*& Form GET_DISPLAY_DATA
*&———————————————————————*
* text
*———————————————————————-*
FORM GET_DISPLAY_DATA .
SELECT VBELN
FKART
VKORG
VTWEG
SPART
FKDAT
ERNAM
KUNRG
KUNAG FROM VBRK
INTO CORRESPONDING FIELDS OF TABLE IT_FINAL
WHERE VBELN IN S_VBELN
AND FKART IN S_FKART
AND VKORG IN S_VKORG
AND VTWEG IN S_VTWEG
AND SPART IN S_SPART
AND FKDAT IN S_FKDAT
AND ERNAM IN S_ERNAM
AND KUNRG IN S_KUNRG
AND KUNAG IN S_KUNAG.
* SELECT OBJKY ERUHR VSTAT FROM NAST INTO CORRESPONDING FIELDS OF TABLE IT_NAST
* FOR ALL ENTRIES IN IT_FINAL
* WHERE OBJKY = IT_FINAL-VBELN
* AND KSCHL = ‘ZEMA’
* ORDER BY ERUHR DESCENDING.
* ENDSELECT.
** SORT DESCENDING BY WA_NAST-ERUHR.
* IF SY-SUBRC = 0.
* IF WA_NAST-VSTAT = 0.
* WA_OUTPUT-VSTAT = ‘N’.
* ELSEIF WA_NAST-VSTAT = 1.
* WA_OUTPUT-VSTAT = ‘Y’.
* ENDIF.
* ELSE.
* WA_OUTPUT-VSTAT = ‘N’.
* WA_OUTPUT-FLAG = ‘X’.
* ENDIF.
IF IT_FINAL IS NOT INITIAL.
SELECT FKART VTEXT FROM TVFKT INTO CORRESPONDING FIELDS OF TABLE IT_TVFKT
FOR ALL ENTRIES IN IT_FINAL
WHERE FKART = IT_FINAL-FKART
AND SPRAS = ‘E’.
LOOP AT IT_FINAL INTO WA_FINAL.
MOVE-CORRESPONDING WA_FINAL TO WA_OUTPUT.
READ TABLE IT_TVFKT INTO WA_TVFKT WITH KEY FKART = WA_FINAL-FKART.
IF SY-SUBRC = 0.
WA_OUTPUT-VTEXT = WA_TVFKT-VTEXT.
ENDIF.
SELECT SINGLE KUNNR NAME1 FROM KNA1 INTO CORRESPONDING FIELDS OF WA_KNA1
WHERE KUNNR = WA_FINAL-KUNRG.
IF SY-SUBRC = 0.
WA_OUTPUT-NAME1_P = WA_KNA1-NAME1.
CLEAR : WA_KNA1.
ENDIF.
SELECT SINGLE KUNNR NAME1 FROM KNA1 INTO CORRESPONDING FIELDS OF WA_KNA1
WHERE KUNNR = WA_FINAL-KUNAG.
IF SY-SUBRC = 0.
WA_OUTPUT-NAME1_S = WA_KNA1-NAME1.
CLEAR : WA_KNA1.
ENDIF.
SELECT OBJKY ERDAT ERUHR VSTAT FROM NAST INTO CORRESPONDING FIELDS OF TABLE IT_NAST
* FOR ALL ENTRIES IN WA_FINAL
WHERE OBJKY = WA_FINAL-VBELN
AND KSCHL = ‘ZEMA’.
” ORDER BY ERDAT DESCENDING
SORT IT_NAST BY ERUHR DESCENDING.
SORT IT_NAST BY ERDAT DESCENDING.
*DATA : INDEX TYPE SY-INDEX.
IF SY-SUBRC = 0.
READ TABLE IT_NAST INTO WA_NAST WITH KEY OBJKY = WA_FINAL-VBELN.
IF SY-SUBRC = 0.
IF WA_NAST-VSTAT = 0.
WA_OUTPUT-VSTAT = ‘N’.
ELSEIF WA_NAST-VSTAT = 1.
WA_OUTPUT-VSTAT = ‘Y’.
ELSEIF WA_NAST-VSTAT = 2.
WA_OUTPUT-VSTAT = ‘N’.
WA_OUTPUT-FLAG = ‘X’.
ENDIF.
ENDIF.
ELSE.
WA_OUTPUT-VSTAT = ‘N’.
WA_OUTPUT-FLAG = ‘X’.
ENDIF.
SELECT SINGLE VBELN PARVW KUNNR ADRNR FROM VBPA INTO CORRESPONDING FIELDS OF WA_VBPA
WHERE VBELN = WA_FINAL-VBELN
AND KUNNR = WA_FINAL-KUNRG
AND PARVW = ‘AG’.
IF SY-SUBRC = 0.
SELECT SMTP_ADDR FROM ADR6 INTO CORRESPONDING FIELDS OF TABLE IT_ADR6
WHERE ADDRNUMBER = WA_VBPA-ADRNR.
DELETE ADJACENT DUPLICATES FROM IT_ADR6 COMPARING ALL FIELDS.
LOOP AT IT_ADR6 INTO WA_ADR6.
CLEAR WA_ADR61.
ASSIGN COMPONENT SY-TABIX OF STRUCTURE WA_ADR61 TO <FS>.
CURR_LINE = SY-TABIX.
DO.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE WA_ADR6 TO <FS2>.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
IF CURR_LINE = 1.
<FS> = <FS2>.
APPEND WA_ADR61 TO IT_ADR61 .
ELSE.
READ TABLE IT_ADR61 INTO WA_ADR61 INDEX SY-INDEX.
<FS> = <FS2>.
MODIFY IT_ADR61 FROM WA_ADR61 INDEX SY-INDEX.
ENDIF.
ENDDO.
ENDLOOP.
LOOP AT IT_ADR61 INTO WA_ADR61.
IF SY-SUBRC = 0.
WA_OUTPUT-EMAIL1 = WA_ADR61-EMAIL1.
WA_OUTPUT-EMAIL2 = WA_ADR61-EMAIL2.
WA_OUTPUT-EMAIL3 = WA_ADR61-EMAIL3.
WA_OUTPUT-EMAIL4 = WA_ADR61-EMAIL4.
WA_OUTPUT-EMAIL5 = WA_ADR61-EMAIL5.
ENDIF.
ENDLOOP.
ENDIF.
APPEND WA_OUTPUT TO IT_OUTPUT.
CLEAR : WA_OUTPUT.
REFRESH : IT_ADR61.
ENDLOOP.
PERFORM SUB_POPULATE USING : ‘1’ ‘CHECK’ ‘ ‘ ‘X’ ‘X’,
‘2’ ‘VBELN’ ‘Billing Doc.No.’ ‘ ‘ ‘ ‘ ,
‘3’ ‘FKART’ ‘Billing Type’ ‘ ‘ ‘ ‘ ,
‘4’ ‘VTEXT’ ‘Billing Type Desc.’ ‘ ‘ ‘ ‘,
‘4’ ‘VKORG’ ‘Sales Organization’ ‘ ‘ ‘ ‘,
‘5’ ‘VTWEG’ ‘Distribution Channel’ ‘ ‘ ‘ ‘,
‘6’ ‘SPART’ ‘Division’ ‘ ‘ ‘ ‘,
‘7’ ‘FKDAT’ ‘Billing Date’ ‘ ‘ ‘ ‘,
‘8’ ‘ERNAM’ ‘Created By’ ‘ ‘ ‘ ‘,
‘9’ ‘KUNRG’ ‘Payer’ ‘ ‘ ‘ ‘,
’10’ ‘NAME1_P’ ‘Payer Name’ ‘ ‘ ‘ ‘,
’11’ ‘KUNAG’ ‘Sold-to Party’ ‘ ‘ ‘ ‘,
’12’ ‘NAME1_S’ ‘Sold-to Party Name’ ‘ ‘ ‘ ‘,
’13’ ‘VSTAT’ ‘Email Sent(Y/N)’ ‘ ‘ ‘ ‘,
’14’ ‘EMAIL1’ ‘E-mail Address 1’ ‘ ‘ ‘ ‘,
’15’ ‘EMAIL2’ ‘E-mail Address 2’ ‘ ‘ ‘ ‘,
’16’ ‘EMAIL3’ ‘E-mail Address 3’ ‘ ‘ ‘ ‘,
’17’ ‘EMAIL4’ ‘E-mail Address 4’ ‘ ‘ ‘ ‘,
’18’ ‘EMAIL5’ ‘E-mail Address 5’ ‘ ‘ ‘ ‘.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
* I_INTERFACE_CHECK = ‘ ‘
* I_BYPASSING_BUFFER = ‘ ‘
* I_BUFFER_ACTIVE = ‘ ‘
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_PF_STATUS_SET = ‘PF’
I_CALLBACK_USER_COMMAND = ‘USER_COMMAND’
* I_CALLBACK_TOP_OF_PAGE = ‘ ‘
* I_CALLBACK_HTML_TOP_OF_PAGE = ‘ ‘
* I_CALLBACK_HTML_END_OF_LIST = ‘ ‘
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ‘ ‘
* I_GRID_TITLE =
* I_GRID_SETTINGS =
IS_LAYOUT = S_LAYOUT
IT_FIELDCAT = IT_FCAT
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
I_DEFAULT = ‘X’
I_SAVE = ‘A’
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = IT_OUTPUT
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ELSE.
MESSAGE ‘No records found for the selection criteria’ TYPE ‘S’ DISPLAY LIKE ‘E’.
ENDIF.
ENDFORM. ” GET_DISPLAY_DATA
*&———————————————————————*
*& Form SUB_POPULATE
*&———————————————————————*
* text
*———————————————————————-*
FORM SUB_POPULATE USING COL_POS
FIELDNAME
SELTEXT_M
* JUST.
* INPUT
CHECKBOX
EDIT.
WA_FCAT-COL_POS = COL_POS.
WA_FCAT-FIELDNAME = FIELDNAME.
WA_FCAT-SELTEXT_M = SELTEXT_M.
* WA_FCAT-INPUT = INPUT.
WA_FCAT-CHECKBOX = CHECKBOX.
WA_FCAT-EDIT = EDIT.
APPEND WA_FCAT TO IT_FCAT.
CLEAR : WA_FCAT.
S_LAYOUT-ZEBRA = ‘X’.
S_LAYOUT-COLWIDTH_OPTIMIZE = ‘X’.
ENDFORM. ” SUB_POPULATE
*&———————————————————————*
*& Form PF
*&———————————————————————*
*
*———————————————————————-*
FORM PF USING RT_EXTAB TYPE SLIS_T_EXTAB.
SET PF-STATUS ‘ZSTANDARD’.” EXCLUDING RT_EXTAB.
ENDFORM. “PF
*&———————————————————————*
*& Form PF
*&———————————————————————*
*
*———————————————————————-*
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
DATA REF_GRID TYPE REF TO CL_GUI_ALV_GRID.
IF REF_GRID IS INITIAL.
CALL FUNCTION ‘GET_GLOBALS_FROM_SLVC_FULLSCR’
IMPORTING
E_GRID = REF_GRID.
ENDIF.
IF NOT REF_GRID IS INITIAL.
CALL METHOD REF_GRID->CHECK_CHANGED_DATA.
ENDIF.
IF R_UCOMM = ‘&EXE’.
* CLEAR : FLAG.
DATA : WA_NAST TYPE NAST.
LOOP AT IT_OUTPUT INTO WA_OUTPUT.
IF WA_OUTPUT-CHECK = ‘X’ AND WA_OUTPUT-FLAG = ‘ ‘.
REFRESH BDCDATA.
PERFORM BDC_DYNPRO USING ‘SD70AV3A’ ‘1000’.
PERFORM BDC_FIELD USING ‘BDC_CURSOR’
‘PM_VERMO’.
PERFORM BDC_FIELD USING ‘BDC_OKCODE’
‘=ONLI’.
PERFORM BDC_FIELD USING ‘RG_KSCHL-LOW’
‘ZEMA’.
PERFORM BDC_FIELD USING ‘RG_NACHA-LOW’
‘5’.
PERFORM BDC_FIELD USING ‘PM_NSORT’
’01’.
IF WA_OUTPUT-VSTAT = ‘N’.
PERFORM BDC_FIELD USING ‘PM_VERMO’
‘1’.
ELSEIF WA_OUTPUT-VSTAT = ‘Y’.
PERFORM BDC_FIELD USING ‘PM_VERMO’
‘2’.
ENDIF.
PERFORM BDC_FIELD USING ‘RG_VBELN-LOW’
WA_OUTPUT-VBELN.
PERFORM BDC_FIELD USING ‘PM_ALLEL’
‘X’.
PERFORM BDC_FIELD USING ‘PM_ALLEA’
‘X’.
PERFORM BDC_FIELD USING ‘N_SELECT’
‘X’.
PERFORM BDC_DYNPRO USING ‘SAPMSSY0’ ‘0120’.
PERFORM BDC_FIELD USING ‘BDC_CURSOR’
’04/03′.
PERFORM BDC_FIELD USING ‘BDC_OKCODE’
‘=&ALL’.
PERFORM BDC_DYNPRO USING ‘SAPMSSY0’ ‘0120’.
PERFORM BDC_FIELD USING ‘BDC_CURSOR’
’04/03′.
PERFORM BDC_FIELD USING ‘BDC_OKCODE’
‘=PROC’.
*
WA_CTUPARAMS-DISMODE = ‘N’.
WA_CTUPARAMS-UPDMODE = ‘A’.
WA_CTUPARAMS-CATTMODE = ‘ ‘.
WA_CTUPARAMS-RACOMMIT = ‘X’.
WA_CTUPARAMS-DEFSIZE = ‘X’.
WA_CTUPARAMS-NOBINPT = ‘ ‘.
WA_CTUPARAMS-NOBIEND = ‘ ‘.
CALL TRANSACTION ‘VF31’ USING BDCDATA “MODE ‘N’ UPDATE ‘S’
OPTIONS FROM WA_CTUPARAMS
MESSAGES INTO IT_BDCMSG.
IF SY-SUBRC = 0 OR SY-SUBRC = ‘1001’.
APPEND WA_OUTPUT TO IT_FINAL1.
CLEAR : WA_OUTPUT.
ELSE.
APPEND WA_OUTPUT TO IT_FINAL2.
CLEAR : WA_OUTPUT.
ENDIF.
LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.
SET PF-STATUS SPACE.
SUPPRESS DIALOG.
NEW-PAGE NO-TITLE NO-HEADING.
ENDIF.
IF WA_OUTPUT-CHECK = ‘X’ AND WA_OUTPUT-FLAG = ‘X’.
APPEND WA_OUTPUT TO IT_FINAL3.
LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.
SET PF-STATUS SPACE.
SUPPRESS DIALOG.
NEW-PAGE NO-TITLE NO-HEADING.
ENDIF.
ENDLOOP.
IF IT_FINAL1 IS NOT INITIAL.
LOOP AT IT_FINAL1 INTO WA_FINAL1.
WRITE :/ ‘E-mail has been sent for Invoice Number’,WA_FINAL1-VBELN.
ENDLOOP.
ENDIF.
IF IT_FINAL2 IS NOT INITIAL.
LOOP AT IT_FINAL2 INTO WA_FINAL2.
WRITE :/ ‘E-mail has not been sent for Invoice Number’,WA_FINAL2-VBELN.
ENDLOOP.
ENDIF.
IF IT_FINAL3 IS NOT INITIAL.
LOOP AT IT_FINAL3 INTO WA_FINAL3.
WRITE :/ ‘E-mail cannot be sent for the Invoice Number’,WA_FINAL3-VBELN.
ENDLOOP.
ENDIF.
ELSEIF R_UCOMM = ‘&IC1’.
CASE RS_SELFIELD-FIELDNAME.
WHEN ‘VBELN’.
SET PARAMETER ID ‘VF’ FIELD RS_SELFIELD-VALUE.
CALL TRANSACTION ‘VF03’ AND SKIP FIRST SCREEN.
WHEN ‘KUNAG’.
SET PARAMETER ID ‘KUN’ FIELD RS_SELFIELD-VALUE.
CALL TRANSACTION ‘XD03’ AND SKIP FIRST SCREEN.
ENDCASE.
ENDIF.
ENDFORM. “USER_COMMAND
*&———————————————————————*
*& Form bdc_dynpro
*&———————————————————————*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = ‘X’.
APPEND BDCDATA.
ENDFORM. “bdc_dynpro
*&———————————————————————*
*& Form BDC_FIELD
*&———————————————————————*
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL <> SPACE.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM. “BDC_FIELD
Document Completed.
I hope you will like this document. If any suggestion, please let me know. I would like to have you guidance and suggestion.
Thanks,
Kundan Vishwakarma
Okumaya devam et...