Skip to Content

I have created a program to send mail to specific mail id when im trying to send that in background im not able to recieve all seperate mails

following is the code:-

   *&———————————————————————*
*&  Include           ZPP_DISP_MAIL_MAIN
*&———————————————————————*
BREAK: KCSSLCONFIG.
*START-OF-SELECTION.
START-OF-SELECTION.
  “P_DATE = SY-DATUM .   ” changed by sachin
*  SY-DATUM = ‘20121202’.
  P_DATE = SY-DATUM – 1 .
*  IF SY-BATCH EQ ‘X’.
  L_PROGRAM_NANE  = SY-REPID .

  SELECT * FROM ZMM_CUST_MAIL
     INTO TABLE IT_ZMM_CUST_MAIL WHERE PROGRAM_NANE = L_PROGRAM_NANE AND ACTIVE = ‘X’ .
  SORT IT_ZMM_CUST_MAIL BY SORTL .

  LOOP AT IT_ZMM_CUST_MAIL INTO WA_ZMM_CUST_MAIL  .
    IF WA_ZMM_CUST_MAIL-SORTL = ‘-‘” Other than 0000100027′,’0000100029

      P_EMAIL1 = WA_ZMM_CUST_MAIL-EMAIL.

      V_DATE = SY-DATUM – 1.

      RANGES : IT_FKART FOR ZMM_CUST_MAIL_I-FKART .
      RANGES : IT_KUNNR FOR ZSD_CUST-KUNNR .

      TYPES  : BEGIN OF TY_FKART1 ,
       FKART TYPE VBRK-FKART ,
             END OF TY_FKART1 .

      DATA : IT_FKART1 TYPE TABLE OF TY_FKART1  WITH HEADER LINE.

      TYPES  : BEGIN OF TY_KUNNR1 ,
                KUNNR TYPE VBRK-KUNAG,“KNA1-KUNNR ,
              END OF TY_KUNNR1 .
      TYPES  : BEGIN OF TY_KUNNR2 ,
                KUNAG TYPE VBRK-KUNAG,
               END OF TY_KUNNR2 .

      DATA : IT_KUNNR1 TYPE TABLE OF TY_KUNNR1  WITH HEADER LINE.
      DATA : IT_KUNNR2 TYPE TABLE OF TY_KUNNR2  WITH HEADER LINE.
      CLEAR : IT_FKART1[] , IT_KUNNR1[] .
      SELECT FKART FROM ZMM_CUST_MAIL_I INTO TABLE IT_FKART1
         WHERE  SORTL EQ WA_ZMM_CUST_MAIL-SORTL .

      IF WA_ZMM_CUST_MAIL-SORTL <> ‘-‘.
        SELECT KUNNR FROM ZSD_CUST INTO TABLE
          IT_KUNNR1 WHERE SORTL = WA_ZMM_CUST_MAIL-SORTL .
        LOOP AT IT_KUNNR1 .

          IT_KUNNR-SIGN  = ‘I’ .
          IT_KUNNR-OPTION = ‘CP’ .
          IT_KUNNR-LOW = IT_KUNNR1-KUNNR.
          APPEND IT_KUNNR TO IT_KUNNR .
        ENDLOOP .
      ELSE.

        SELECT DISTINCT KUNAG FROM VBRK
          INTO CORRESPONDING FIELDS OF TABLE IT_KUNNR2
          WHERE FKDAT = P_DATE
            AND KUNAG NOT IN  (‘0000100027’,‘0000100029’)
            AND FKSTO <> ‘X’
            AND  FKART IN  IT_FKART .
        LOOP AT IT_KUNNR2 .
          IT_KUNNR-SIGN  = ‘I’ .
          IT_KUNNR-OPTION = ‘CP’ .
          IT_KUNNR-LOW = IT_KUNNR2-KUNAG.
          APPEND IT_KUNNR TO IT_KUNNR .
        ENDLOOP .
      ENDIF.
*  LOOP AT IT_KUNNR1 .
*
*    IT_KUNNR-SIGN  = ‘I’ .
*    IT_KUNNR-OPTION = ‘CP’ .
*    IT_KUNNR-LOW = IT_KUNNR1-KUNNR.
*    APPEND IT_KUNNR TO IT_KUNNR .
*  ENDLOOP .

      LOOP AT    IT_FKART1 .
        IT_FKART-SIGN  = ‘I’ .
        IT_FKART-OPTION = ‘CP’ .
        IT_FKART-LOW = IT_FKART1-FKART .
        APPEND IT_FKART TO IT_FKART .
      ENDLOOP .
      SORT IT_KUNNR BY LOW.
      SORT IT_FKART BY LOW .
      DELETE ADJACENT DUPLICATES FROM IT_KUNNR COMPARING LOW .
      DELETE ADJACENT DUPLICATES FROM IT_FKART COMPARING LOW .
      IF P_DELSPL <> ‘X’.
        LOOP AT IT_KUNNR.
          PERFORM GET_DATA1.
*          IF SY-SUBRC <> 0.
*            EXIT.
*          ENDIF.
          PERFORM BUILD_ALV .
          PERFORM GET_JOB_DETAILS.
          PERFORM OBTAIN_SPOOL_ID.
          PERFORM CONVERT_SPOOL_TO_PDF.
          PERFORM PROCESS_EMAIL.

          IF P_DELSPL EQ ‘X’.
            PERFORM DELETE_SPOOL.
          ENDIF.

          IF SY-SYSID = C_DEV.
            WAIT UP TO 5 SECONDS.
            SUBMIT RSCONN01 WITH MODE   = ‘INT’
            WITH OUTPUT = ‘X’
            AND RETURN.
          ENDIF.
*  ELSE.
*    SKIP.
*    WRITE:/ ‘Program must be executed in background in-order for spool’,
*    ‘request to be created.’.
*  ENDIF.
          CLEAR : WA_ZMM_CUST_MAIL , IT_VBRK , IT_VBRP, IT_FINAL.

          REFRESH: IT_VBRK,IT_VBRP,IT1VBRP,IT_FINAL.
        ENDLOOP.
      ELSE.
        LOOP AT IT_KUNNR.
          PERFORM GET_DATA1.
        ENDLOOP.
        IT_FINAL[] = IT_FINAL1[].
        PERFORM BUILD_ALV .

      ENDIF.
    ELSE.
      PERFORM GET_DATA.

      PERFORM BUILD_ALV .

      PERFORM GET_JOB_DETAILS.
      PERFORM OBTAIN_SPOOL_ID.

      PERFORM CONVERT_SPOOL_TO_PDF.
      PERFORM PROCESS_EMAIL.

      IF P_DELSPL EQ ‘X’.
        PERFORM DELETE_SPOOL.
      ENDIF.

      IF SY-SYSID = C_DEV.
        WAIT UP TO 5 SECONDS.
        SUBMIT RSCONN01 WITH MODE   = ‘INT’
        WITH OUTPUT = ‘X’
        AND RETURN.
      ENDIF.
*  ELSE.
*    SKIP.
*    WRITE:/ ‘Program must be executed in background in-order for spool’,
*    ‘request to be created.’.
*  ENDIF.
      CLEAR : WA_ZMM_CUST_MAIL , IT_VBRK[] , IT_VBRP[], IT_FINAL[] .
    ENDIF.
  ENDLOOP .

   *&———————————————————————*
*&  Include           ZPP_DISP_MAIL_LOGIC
*&———————————————————————*
*———————————————————————*
*       FORM obtain_spool_id                                          *
*———————————————————————*
BREAK: KCSSLCONFIG.
*&———————————————————————*
*&      Form  OBTAIN_SPOOL_ID
*&———————————————————————*
*       text
*———————————————————————-*
FORM OBTAIN_SPOOL_ID.
  CHECK NOT ( GD_JOBNAME IS INITIAL ).
  CHECK NOT ( GD_JOBCOUNT IS INITIAL ).

  SELECT * FROM  TBTCP
  INTO TABLE IT_TBTCP
  WHERE      JOBNAME     = GD_JOBNAME
  AND        JOBCOUNT    = GD_JOBCOUNT
  AND        STEPCOUNT   = GD_STEPCOUNT
  AND        LISTIDENT   <> ‘0000000000’
  ORDER BY   JOBNAME
  JOBCOUNT
  STEPCOUNT.

  READ TABLE IT_TBTCP INTO WA_TBTCP INDEX 1.
  IF SY-SUBRC = 0.
    MESSAGE S004(ZDD) WITH GD_SPOOL_NR.
    GD_SPOOL_NR = WA_TBTCP-LISTIDENT.
    MESSAGE S004(ZDD) WITH GD_SPOOL_NR.
  ELSE.
    MESSAGE S005(ZDD).
  ENDIF.
ENDFORM.                    “obtain_spool_id

*———————————————————————*
*       FORM get_job_details                                          *
*———————————————————————*
FORM GET_JOB_DETAILS.
* Get current job details
  CALL FUNCTION ‘GET_JOB_RUNTIME_INFO’
    IMPORTING
      EVENTID                 = GD_EVENTID
      EVENTPARM               = GD_EVENTPARM
      EXTERNAL_PROGRAM_ACTIVE = GD_EXTERNAL_PROGRAM_ACTIVE
      JOBCOUNT                = GD_JOBCOUNT
      JOBNAME                 = GD_JOBNAME
      STEPCOUNT               = GD_STEPCOUNT
    EXCEPTIONS
      NO_RUNTIME_INFO         = 1
      OTHERS                  = 2.
ENDFORM.                    “get_job_details

*———————————————————————*
*       FORM convert_spool_to_pdf                                     *
*———————————————————————*
FORM CONVERT_SPOOL_TO_PDF.

  CALL FUNCTION ‘CONVERT_ABAPSPOOLJOB_2_PDF’
    EXPORTING
      SRC_SPOOLID              = GD_SPOOL_NR
      NO_DIALOG                = C_NO
      DST_DEVICE               = C_DEVICE
    IMPORTING
      PDF_BYTECOUNT            = GD_BYTECOUNT
    TABLES
      PDF                      = IT_PDF_OUTPUT
    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
      ERR_BTCJOB_SUBMIT_FAILED = 10
      ERR_BTCJOB_CLOSE_FAILED  = 11
      OTHERS                   = 12.

  CHECK SY-SUBRC = 0.

* Transfer the 132-long strings to 255-long strings
  LOOP AT IT_PDF_OUTPUT.
    TRANSLATE IT_PDF_OUTPUT USING ‘ ~’.
    CONCATENATE GD_BUFFER IT_PDF_OUTPUT INTO GD_BUFFER.
  ENDLOOP.

  TRANSLATE GD_BUFFER USING ‘~ ‘.

  DO.
    IT_MESS_ATT = GD_BUFFER.
    APPEND IT_MESS_ATT.
    SHIFT GD_BUFFER LEFT BY 255 PLACES.
    IF GD_BUFFER IS INITIAL.
      EXIT.
    ENDIF.
  ENDDO.

ENDFORM.                    “convert_spool_to_pdf

*———————————————————————*
*       FORM process_email                                            *
*———————————————————————*
FORM PROCESS_EMAIL.
  BREAK: KCSSLCONFIG.
  DESCRIBE TABLE IT_MESS_ATT LINES GD_RECSIZE.
  CHECK GD_RECSIZE > 0.
  CHECK V_ITFINAL <> 1.
  PERFORM SEND_EMAIL USING P_EMAIL1.
*  perform send_email using p_email2.
ENDFORM.                    “process_email

*———————————————————————*
*       FORM send_email                                               *
*———————————————————————*
*  –>  p_email                                                       *
*———————————————————————*
FORM SEND_EMAIL USING P_EMAIL.
  BREAK: KCSSLCONFIG.
  CHECK NOT ( P_EMAIL IS INITIAL ).

  REFRESH IT_MESS_BOD.

* Default subject matter
  GD_SUBJECT         = ‘Subject’.
  GD_ATTACHMENT_DESC = ‘Attachment’.
*  CONCATENATE ‘attach_name’ ‘ ‘ INTO gd_attachment_name.
  IT_MESS_BOD        = ‘Dear Sir,’.
  APPEND IT_MESS_BOD.
  IT_MESS_BOD        = ‘Please find attached KCSSL – Despatch Report.’.
  APPEND IT_MESS_BOD.
  IT_MESS_BOD        = ‘Do not reply to this mail. This is an auto generated mail from the system.’.
  APPEND IT_MESS_BOD.

* If no sender specified – default blank
  IF P_SENDER EQ SPACE.
    GD_SENDER_TYPE  = SPACE.
  ELSE.
    GD_SENDER_TYPE  = ‘INT’.
  ENDIF.

* Send file by email as .xls speadsheet
*  READ TABLE IT_FINAL INDEX 1.
  PERFORM SEND_FILE_AS_EMAIL_ATTACHMENT
  TABLES IT_MESS_BOD
  IT_MESS_ATT
  USING P_EMAIL V_CUSTOMER
  ‘PDF’
  GD_ATTACHMENT_NAME
  GD_ATTACHMENT_DESC
  P_SENDER
  GD_SENDER_TYPE
  CHANGING GD_ERROR
  GD_RECIEVER.
ENDFORM.                    “send_email

*———————————————————————*
*       FORM delete_spool                                             *
*———————————————————————*
FORM DELETE_SPOOL.
  DATA: LD_SPOOL_NR TYPE TSP01_SP0R-RQID_CHAR.

  LD_SPOOL_NR = GD_SPOOL_NR.

  CHECK P_DELSPL <> C_NO.
  CALL FUNCTION ‘RSPO_R_RDELETE_SPOOLREQ’
    EXPORTING
      SPOOLID = LD_SPOOL_NR.
ENDFORM.                    “delete_spool

*&———————————————————————*
*&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
*&———————————————————————*
*       Send email
*———————————————————————-*
FORM SEND_FILE_AS_EMAIL_ATTACHMENT TABLES IT_MESSAGE
IT_ATTACH
USING P_EMAIL
P_MTITLE
P_FORMAT
P_FILENAME
P_ATTDESCRIPTION
P_SENDER_ADDRESS
P_SENDER_ADDRES_TYPE
CHANGING P_ERROR
P_RECIEVER.

  DATA: LD_ERROR    TYPE SY-SUBRC,
  LD_RECIEVER TYPE SY-SUBRC,
  LD_MTITLE LIKE SODOCCHGI1-OBJ_DESCR,
  LD_EMAIL LIKE  SOMLRECI1-RECEIVER,
  LD_FORMAT TYPE  SO_OBJ_TP ,
  LD_ATTDESCRIPTION TYPE  SO_OBJ_NAM ,
  LD_ATTFILENAME TYPE  SO_OBJ_DES ,
  LD_SENDER_ADDRESS LIKE  SOEXTRECI1-RECEIVER,
  LD_SENDER_ADDRESS_TYPE LIKE  SOEXTRECI1-ADR_TYP,
  LD_RECEIVER LIKE  SY-SUBRC.

  DATA:   T_PACKING_LIST LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,
  T_CONTENTS LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
  T_RECEIVERS LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,
  T_ATTACHMENT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
  T_OBJECT_HEADER LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
  W_CNT TYPE I,
  W_SENT_ALL(1) TYPE C,
  W_DOC_DATA LIKE SODOCCHGI1.

  LD_EMAIL   = P_EMAIL.
  LD_MTITLE = P_MTITLE.
  LD_FORMAT              = P_FORMAT.
  LD_ATTDESCRIPTION      = P_ATTDESCRIPTION.
  LD_ATTFILENAME         = P_FILENAME.
  LD_SENDER_ADDRESS      = P_SENDER_ADDRESS.
  LD_SENDER_ADDRESS_TYPE = P_SENDER_ADDRES_TYPE.

* Fill the document data.
  W_DOC_DATA-DOC_SIZE = 1.

* Populate the subject/generic message attributes
  W_DOC_DATA-OBJ_LANGU = SY-LANGU.
  W_DOC_DATA-OBJ_NAME  = ‘SAPRPT’.
  W_DOC_DATA-OBJ_DESCR = LD_MTITLE .
  W_DOC_DATA-SENSITIVTY = ‘F’.

* Fill the document data and get size of attachment
  CLEAR W_DOC_DATA.
  READ TABLE IT_ATTACH INDEX W_CNT.
  W_DOC_DATA-DOC_SIZE = ( W_CNT – 1 ) * 255 + STRLEN( IT_ATTACH ).
  W_DOC_DATA-OBJ_LANGU  = SY-LANGU.
  W_DOC_DATA-OBJ_NAME   = ‘SAPRPT’.
  W_DOC_DATA-OBJ_DESCR  = LD_MTITLE.
  W_DOC_DATA-SENSITIVTY = ‘F’.
  CLEAR T_ATTACHMENT.
  REFRESH T_ATTACHMENT.
  T_ATTACHMENT[] = IT_ATTACH[].

* Describe the body of the message
  CLEAR T_PACKING_LIST.
  REFRESH T_PACKING_LIST.
  T_PACKING_LIST-TRANSF_BIN = SPACE.
  T_PACKING_LIST-HEAD_START = 1.
  T_PACKING_LIST-HEAD_NUM = 0.
  T_PACKING_LIST-BODY_START = 1.
  DESCRIBE TABLE IT_MESSAGE LINES T_PACKING_LIST-BODY_NUM.
  T_PACKING_LIST-DOC_TYPE = ‘RAW’.
  APPEND T_PACKING_LIST.

* Create attachment notification
  T_PACKING_LIST-TRANSF_BIN = ‘X’.
  T_PACKING_LIST-HEAD_START = 1.
  T_PACKING_LIST-HEAD_NUM   = 1.
  T_PACKING_LIST-BODY_START = 1.

  DESCRIBE TABLE T_ATTACHMENT LINES T_PACKING_LIST-BODY_NUM.
  T_PACKING_LIST-DOC_TYPE   =  LD_FORMAT.
  T_PACKING_LIST-OBJ_DESCR  =  LD_ATTDESCRIPTION.
  T_PACKING_LIST-OBJ_NAME   =  LD_ATTFILENAME.
  T_PACKING_LIST-DOC_SIZE   =  T_PACKING_LIST-BODY_NUM * 255.
  APPEND T_PACKING_LIST.

* Add the recipients email address
  CLEAR T_RECEIVERS.
  REFRESH T_RECEIVERS.
  T_RECEIVERS-RECEIVER = LD_EMAIL.
  T_RECEIVERS-REC_TYPE = ‘U’.
  T_RECEIVERS-COM_TYPE = ‘INT’.
  T_RECEIVERS-NOTIF_DEL = ‘X’.
  T_RECEIVERS-NOTIF_NDEL = ‘X’.
  APPEND T_RECEIVERS.

  CALL FUNCTION ‘SO_DOCUMENT_SEND_API1’
    EXPORTING
      DOCUMENT_DATA              = W_DOC_DATA
      PUT_IN_OUTBOX              = ‘X’
*     SENDER_ADDRESS             = ‘no-reply@kspl.co.in‘ “LD_SENDER_ADDRESS
*     SENDER_ADDRESS_TYPE        = ‘U’ “LD_SENDER_ADDRESS_TYPE
      COMMIT_WORK                = ‘X’
    IMPORTING
      SENT_TO_ALL                = W_SENT_ALL
    TABLES
      PACKING_LIST               = T_PACKING_LIST
      CONTENTS_BIN               = T_ATTACHMENT
      CONTENTS_TXT               = IT_MESSAGE
      RECEIVERS                  = T_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 S027(VV) WITH ‘E-mail has been sent’.

    COMMIT WORK.

*-  buffered emails can be released via rsconn01.

    SUBMIT RSCONN01 USING SELECTION-SET ‘SAP&CONNECTINT’ AND RETURN.

  ELSE.

    MESSAGE S027(VV) WITH ‘E-mail not sent’.

  ENDIF.

* Populate zerror return code
  LD_ERROR = SY-SUBRC.

* Populate zreceiver return code
  LOOP AT T_RECEIVERS.
    LD_RECEIVER = T_RECEIVERS-RETRN_CODE.
  ENDLOOP.
ENDFORM.                    “send_file_as_email_attachment
*&———————————————————————*
*&      Form  GET_DATA
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*
FORM GET_DATA .

  P_EMAIL1 = WA_ZMM_CUST_MAIL-EMAIL.

  V_DATE = SY-DATUM – 1.

  RANGES : IT_FKART FOR ZMM_CUST_MAIL_I-FKART .
  RANGES : IT_KUNNR FOR ZSD_CUST-KUNNR .

  TYPES  : BEGIN OF TY_FKART1 ,
   FKART TYPE VBRK-FKART ,
         END OF TY_FKART1 .

  DATA : IT_FKART1 TYPE TABLE OF TY_FKART1  WITH HEADER LINE.

  TYPES  : BEGIN OF TY_KUNNR1 ,
            KUNNR TYPE VBRK-KUNAG,“KNA1-KUNNR ,
          END OF TY_KUNNR1 .
  TYPES  : BEGIN OF TY_KUNNR2 ,
            KUNAG TYPE VBRK-KUNAG,
           END OF TY_KUNNR2 .

  DATA : IT_KUNNR1 TYPE TABLE OF TY_KUNNR1  WITH HEADER LINE.
  DATA : IT_KUNNR2 TYPE TABLE OF TY_KUNNR2  WITH HEADER LINE.
  CLEAR : IT_FKART1[] , IT_KUNNR1[] .
  SELECT FKART FROM ZMM_CUST_MAIL_I INTO TABLE IT_FKART1
     WHERE  SORTL EQ WA_ZMM_CUST_MAIL-SORTL .

  IF WA_ZMM_CUST_MAIL-SORTL <> ‘-‘.
    SELECT KUNNR FROM ZSD_CUST INTO TABLE
      IT_KUNNR1 WHERE SORTL = WA_ZMM_CUST_MAIL-SORTL .
    LOOP AT IT_KUNNR1 .

      IT_KUNNR-SIGN  = ‘I’ .
      IT_KUNNR-OPTION = ‘CP’ .
      IT_KUNNR-LOW = IT_KUNNR1-KUNNR.
      APPEND IT_KUNNR TO IT_KUNNR .
    ENDLOOP .
  ELSE.

    SELECT DISTINCT KUNAG FROM VBRK
      INTO CORRESPONDING FIELDS OF TABLE IT_KUNNR2
      WHERE FKDAT = P_DATE
        AND KUNAG NOT IN  (‘0000100027’,‘0000100029’)
        AND FKSTO <> ‘X’
        AND  FKART IN  IT_FKART .
    LOOP AT IT_KUNNR2 .
      IT_KUNNR-SIGN  = ‘I’ .
      IT_KUNNR-OPTION = ‘CP’ .
      IT_KUNNR-LOW = IT_KUNNR2-KUNAG.
      APPEND IT_KUNNR TO IT_KUNNR .
    ENDLOOP .
  ENDIF.
*  LOOP AT IT_KUNNR1 .
*
*    IT_KUNNR-SIGN  = ‘I’ .
*    IT_KUNNR-OPTION = ‘CP’ .
*    IT_KUNNR-LOW = IT_KUNNR1-KUNNR.
*    APPEND IT_KUNNR TO IT_KUNNR .
*  ENDLOOP .

  LOOP AT    IT_FKART1 .
    IT_FKART-SIGN  = ‘I’ .
    IT_FKART-OPTION = ‘CP’ .
    IT_FKART-LOW = IT_FKART1-FKART .
    APPEND IT_FKART TO IT_FKART .
  ENDLOOP .
  SORT IT_KUNNR BY LOW.
  SORT IT_FKART BY LOW .
  DELETE ADJACENT DUPLICATES FROM IT_KUNNR COMPARING LOW .
  DELETE ADJACENT DUPLICATES FROM IT_FKART COMPARING LOW .

  SELECT * FROM VBRK
              INTO CORRESPONDING FIELDS OF TABLE IT_VBRK
              WHERE FKDAT = P_DATE
                AND KUNAG  IN  IT_KUNNR
                AND FKSTO <> ‘X’
                AND  FKART IN  IT_FKART .
  “( FKART = ‘ZF2’ OR FKART = ‘ZJOR’ OR FKART = ‘ZRE’ ) .
*CLEAR FKART[] .
  IF IT_VBRK[] IS NOT INITIAL.
    SELECT * FROM VBRP
                 INTO CORRESPONDING FIELDS OF TABLE IT_VBRP
                  FOR ALL ENTRIES IN IT_VBRK
                  WHERE VBELN = IT_VBRK-VBELN
                    AND WERKS = ‘1100’.
  ENDIF.
  IF IT_VBRP[] IS NOT INITIAL.

    IT1VBRP[] = IT_VBRP[].
    SORT IT1VBRP ASCENDING BY MATNR.
    DELETE ADJACENT DUPLICATES FROM IT1VBRP COMPARING MATNR.
    LOOP AT IT1VBRP.

      SELECT SINGLE MAKTX FROM MAKT
                    INTO IT_FINAL-MAKTX
                    WHERE MATNR = IT1VBRP-MATNR.

      READ TABLE IT_VBRK INTO IT_VBRK WITH KEY VBELN = IT1VBRP-VBELN.
      IF SY-SUBRC = 0.
        IT_FINAL-KUNAG = IT_VBRK-KUNAG.
        SELECT SINGLE NAME1 ORT01 INTO (V_NAME1,V_ORT01) FROM KNA1
          WHERE KUNNR = IT_VBRK-KUNAG.
      ENDIF.

      CONCATENATE V_NAME1 V_ORT01 INTO IT_FINAL-CUSTOMER SEPARATED BY ‘,’.
      IT_FINAL-FKART = IT_VBRK-FKART .

      SELECT SINGLE VTEXT FROM TVFKT INTO IT_FINAL-VTEXT WHERE FKART = IT_FINAL-FKART AND SPRAS = ‘EN’ .
      SELECT SINGLE TESHEETNO INTO IT_FINAL-TESHEETNO
        FROM VBAP
      WHERE VBELN = IT1VBRP-AUBEL
        AND POSNR = IT1VBRP-AUPOS.

      SELECT SINGLE LENGTH INTO IT_FINAL-MLLENGTH
        FROM VBAP
      WHERE VBELN = IT1VBRP-AUBEL
        AND POSNR = IT1VBRP-AUPOS.

      CONCATENATE ‘ML-‘ IT_FINAL-MLLENGTH ‘ MM ‘ INTO IT_FINAL-MLLENGTH.

      SELECT SINGLE DIENO INTO IT_FINAL-DIENO1 FROM ZTESHEET
        WHERE TE_SHEET =  IT_FINAL-TESHEETNO.

      LOOP AT IT_VBRP WHERE MATNR = IT1VBRP-MATNR.

        IT_FINAL-QTY = IT_FINAL-QTY + IT_VBRP-FKIMG.                   “qty
        IT_FINAL-MATNR = IT1VBRP-MATNR.

      ENDLOOP.

      DATA: V_NAME1 TYPE KNA1-NAME1.
      SELECT SINGLE NAME1 FROM KNA1 INTO V_NAME1 WHERE KUNNR = IT_FINAL-KUNAG.
      CONCATENATE ‘KCSSL Daily Despatch Report for ‘ V_NAME1 INTO V_CUSTOMER SEPARATED BY ‘- ‘.

      APPEND IT_FINAL.
      CLEAR:  IT_FINAL.
    ENDLOOP.
  ENDIF.
ENDFORM.                    ” GET_DATA

*&———————————————————————*
*&      Form  BUILD_ALV
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*
FORM BUILD_ALV .

*  FCT-SELTEXT_M = ‘Heat No.’.
*  FCT-SELTEXT_L = ‘Heat No.’.
*  FCT-TABNAME = ‘IT_FINAL’.
*  FCT-FIELDNAME = ‘HEAT_NO’.
*  FCT-OUTPUTLEN = ’10’.
*  APPEND FCT TO IT_FCT.
*  CLEAR FCT.
*
*  FCT-SELTEXT_M = ‘Billing Date’.
*  FCT-SELTEXT_L = ‘Billing Date’.
*  FCT-TABNAME = ‘IT_FINAL’.
*  FCT-FIELDNAME = ‘BILLDT’.
*  FCT-OUTPUTLEN = ’10’.
*  APPEND FCT TO IT_FCT.
*  CLEAR FCT.

  FCT-SELTEXT_M = ‘Customer’.
  FCT-SELTEXT_L = ‘Customer’.
  FCT-TABNAME = ‘IT_FINAL’.
  FCT-FIELDNAME = ‘CUSTOMER’.
  FCT-OUTPUTLEN = ’50’.
  APPEND FCT TO IT_FCT.
  CLEAR FCT.

*  FCT-SELTEXT_M = ‘INV Type’.
*  FCT-SELTEXT_L = ‘INV Type’.
*  FCT-TABNAME = ‘IT_FINAL’.
*  FCT-FIELDNAME = ‘FKART’.
*  FCT-OUTPUTLEN = ‘4’.
*  APPEND FCT TO IT_FCT.
*  CLEAR FCT.

  FCT-SELTEXT_M = ‘Type Desc.’.
  FCT-SELTEXT_L = ‘Type Desc’.
  FCT-TABNAME = ‘IT_FINAL’.
  FCT-FIELDNAME = ‘VTEXT’.
  FCT-OUTPUTLEN = ’20’.
  APPEND FCT TO IT_FCT.
  CLEAR FCT.

  FCT-SELTEXT_M = ‘Mat. Desc.’.
  FCT-SELTEXT_L = ‘Mat. Desc.’.
  FCT-TABNAME = ‘IT_FINAL’.
  FCT-FIELDNAME = ‘MAKTX’.
  FCT-OUTPUTLEN = ’40’.
  APPEND FCT TO IT_FCT.
  CLEAR FCT.

  FCT-SELTEXT_M = ‘ML-Length’.
  FCT-SELTEXT_L = ‘ML-Length’.
  FCT-TABNAME = ‘IT_FINAL’.
  FCT-FIELDNAME = ‘MLLENGTH’.
  FCT-OUTPUTLEN = ’15’.
  APPEND FCT TO IT_FCT.
  CLEAR FCT.

  FCT-SELTEXT_M = ‘Die-No.’.
  FCT-SELTEXT_L = ‘Die-No.’.
  FCT-TABNAME = ‘IT_FINAL’.
  FCT-FIELDNAME = ‘DIENO1’.
  FCT-OUTPUTLEN = ’10’.
  APPEND FCT TO IT_FCT.
  CLEAR FCT.

  FCT-SELTEXT_M = ‘Qty.’.
  FCT-SELTEXT_L = ‘Qty.’.
  FCT-TABNAME = ‘IT_FINAL’.
  FCT-FIELDNAME = ‘QTY’.
  FCT-OUTPUTLEN = ’15’.
  FCT-DO_SUM    = ‘X’.
  APPEND FCT TO IT_FCT.
  CLEAR FCT.

*  FCT-SELTEXT_M = ‘Pcs.’.
*  FCT-SELTEXT_L = ‘Pcs.’.
*  FCT-TABNAME = ‘IT_FINAL’.
*  FCT-FIELDNAME = ‘NOPCS’.
*  FCT-OUTPUTLEN = ’10’.
*  APPEND FCT TO IT_FCT.
*  CLEAR FCT.

*  FCT-SELTEXT_M = ‘Inv. No.’.
*  FCT-SELTEXT_L = ‘Inv. No.’.
*  FCT-TABNAME = ‘IT_FINAL’.
*  FCT-FIELDNAME = ‘INVNO’.
*  FCT-OUTPUTLEN = ’12’.
*  APPEND FCT TO IT_FCT.
*  CLEAR FCT.
*
*  FCT-SELTEXT_M = ‘Del. No.’.
*  FCT-SELTEXT_L = ‘Del. No.’.
*  FCT-TABNAME = ‘IT_FINAL’.
*  FCT-FIELDNAME = ‘DELNO’.
*  FCT-OUTPUTLEN = ’12’.
*  APPEND FCT TO IT_FCT.
*  CLEAR FCT.
*
*  FCT-SELTEXT_M = ‘Ref. Doc.’.
*  FCT-SELTEXT_L = ‘Ref. Doc.’.
*  FCT-TABNAME = ‘IT_FINAL’.
*  FCT-FIELDNAME = ‘REFDOCNO’.
*  FCT-OUTPUTLEN = ’12’.
*  APPEND FCT TO IT_FCT.
*  CLEAR FCT.
*
*  FCT-SELTEXT_M = ‘T. E. Sheet No.’.
*  FCT-SELTEXT_L = ‘T. E. Sheet No.’.
*  FCT-TABNAME = ‘IT_FINAL’.
*  FCT-FIELDNAME = ‘TESHEETNO’.
*  FCT-OUTPUTLEN = ’15’.
*  APPEND FCT TO IT_FCT.
*  CLEAR FCT.
*
*  FCT-SELTEXT_M = ‘Transporter Name’.
*  FCT-SELTEXT_L = ‘Transporter Name’.
*  FCT-TABNAME = ‘IT_FINAL’.
*  FCT-FIELDNAME = ‘TRANSPORT_NAME’.
*  FCT-OUTPUTLEN = ’40’.
*  APPEND FCT TO IT_FCT.
*  CLEAR FCT.
*
*  FCT-SELTEXT_M = ‘Truck No.’.
*  FCT-SELTEXT_L = ‘Truck No.’.
*  FCT-TABNAME = ‘IT_FINAL’.
*  FCT-FIELDNAME = ‘LORRY_NO’.
*  FCT-OUTPUTLEN = ’30’.
*  APPEND FCT TO IT_FCT.
*  CLEAR FCT.
*
*  FCT-SELTEXT_M = ‘Truck Type’.
*  FCT-SELTEXT_L = ‘Truck Type’.
*  FCT-TABNAME = ‘IT_FINAL’.
*  FCT-FIELDNAME = ‘SHIPMENT’.
*  FCT-OUTPUTLEN = ’30’.
*  APPEND FCT TO IT_FCT.
*  CLEAR FCT.

*  DELETE IT_FINAL WHERE KUNAG NOT IN P_KUNNR.

  DATA : GT_SORT TYPE   SLIS_T_SORTINFO_ALV  ,
         WA_SORT TYPE   SLIS_SORTINFO_ALV  .
  REFRESH GT_SORT.
  CLEAR WA_SORT.
  WA_SORT-FIELDNAME = ‘CUSTOMER’.
  WA_SORT-UP = ‘X’.
  WA_SORT-SUBTOT = ‘X’.
  WA_SORT-TABNAME = ‘IT_OUT’.
  APPEND WA_SORT TO GT_SORT.
  WA_SORT-FIELDNAME = ‘VTEXT’.
  WA_SORT-UP = ‘X’.
  WA_SORT-SUBTOT = ‘X’.
  WA_SORT-TABNAME = ‘IT_OUT’.
  APPEND WA_SORT TO GT_SORT.

  DATA :IS_PRINT TYPE  SLIS_PRINT_ALV .

  IS_PRINT-NO_PRINT_SELINFOS = ‘X’  .
  IS_PRINT-NO_PRINT_LISTINFOS = ‘X’ .

  CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
   EXPORTING
*     I_INTERFACE_CHECK                 = ‘X’
*     I_BYPASSING_BUFFER                = ‘ ‘
*     I_BUFFER_ACTIVE                   = ‘ ‘
     I_CALLBACK_PROGRAM                = ‘ZPP_DISP_MAIL’
*     I_CALLBACK_PF_STATUS_SET          = ‘ ‘
*     I_CALLBACK_USER_COMMAND           = ‘ ‘
     I_CALLBACK_TOP_OF_PAGE            = ‘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                         = LOUT
     IT_FIELDCAT                       = IT_FCT
*     IT_EXCLUDING                      =
*     IT_SPECIAL_GROUPS                 =
     IT_SORT                           = GT_SORT
*     IT_FILTER                         =
*     IS_SEL_HIDE                       =
*     I_DEFAULT                         = ‘X’
     I_SAVE                            = ‘X’
*     IS_VARIANT                        =
*     IT_EVENTS                         =
*     IT_EVENT_EXIT                     =
     IS_PRINT                          =  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_FINAL
   EXCEPTIONS
     PROGRAM_ERROR                     = 1
     OTHERS                            = 2    .
*  DATA: G_S_PRINT              TYPE      SLIS_PRINT_ALV.
*  G_S_PRINT-NO_PRINT_SELINFOS   = ‘X’.
*  G_S_PRINT-NO_PRINT_LISTINFOS = ‘X’.”

*  CALL FUNCTION ‘REUSE_ALV_LIST_DISPLAY’
*   EXPORTING
**   I_INTERFACE_CHECK              = ‘ ‘
**   I_BYPASSING_BUFFER             =
**   I_BUFFER_ACTIVE                = ‘ ‘
*     I_CALLBACK_PROGRAM             = ‘ZDESPMAILBFL’
*     I_CALLBACK_PF_STATUS_SET       = ‘STATUS’
**   I_CALLBACK_USER_COMMAND        = ‘ ‘
**   I_STRUCTURE_NAME               =
*     IS_LAYOUT                      =  LOUT
*     IT_FIELDCAT                    =  IT_FCT
**   IT_EXCLUDING                   =
**   IT_SPECIAL_GROUPS              =
**   IT_SORT                        =
**   IT_FILTER                      =
**   IS_SEL_HIDE                    =
**   I_DEFAULT                      = ‘X’
**   I_SAVE                         = ‘ ‘
**   IS_VARIANT                     =
**   IT_EVENTS                      =
**   IT_EVENT_EXIT                  =
*     IS_PRINT                       = G_S_PRINT
**   IS_REPREP_ID                   =
**   I_SCREEN_START_COLUMN          = 0
**   I_SCREEN_START_LINE            = 0
**   I_SCREEN_END_COLUMN            = 0
**   I_SCREEN_END_LINE              = 0
**   IR_SALV_LIST_ADAPTER           =
**   IT_EXCEPT_QINFO                =
**   I_SUPPRESS_EMPTY_DATA          = ABAP_FALSE
** IMPORTING
**   E_EXIT_CAUSED_BY_CALLER        =
**   ES_EXIT_CAUSED_BY_USER         =
*    TABLES
*      T_OUTTAB                       = IT_FINAL
** EXCEPTIONS
**   PROGRAM_ERROR                  = 1
**   OTHERS                         = 2
*            .
*  IF SY-SUBRC <> 0.
** Implement suita ble error handling here
*  ENDIF.

  CLEAR: IT_FINAL[]  ,GT_SORT[] ,IT_FCT[], LOUT ,IT1VBRP[].
**************************************************************************************************************
*  TYPES: TY_T_PDF TYPE STANDARD TABLE OF TLINE.
*
*  DATA: LV_BUFFER     TYPE STRING,
*        LV_SPOOL_NR   TYPE TSP01-RQIDENT,
*        LW_MESS_ATT   TYPE SOLISTI1,
*        LI_PDF_OUTPUT TYPE TY_T_PDF,
*        LW_PDF_OUTPUT TYPE TLINE.
*
*
*
*  DATA : T_TSP01 TYPE TABLE OF TSP01 WITH HEADER LINE .
*
*  SELECT RQIDENT
*  INTO (T_TSP01-RQIDENT)
*  FROM TSP01
*  WHERE RQOWNER EQ SY-UNAME
*    AND RQCLIENT EQ SY-MANDT.
*    APPEND T_TSP01.
*  ENDSELECT.

*********************

* DATA : fp_size TYPE i .
**    DATA: li_pdf_output TYPE TABLE OF TLINE .
**    DATA : lw_pdf_output TYPE Tline .
*
**lv_spool_nr = sy-spono.
*    CALL FUNCTION ‘CONVERT_ABAPSPOOLJOB_2_PDF’
*    EXPORTING
*      src_spoolid            = T_TSP01-RQIDENT “Spool Number
*      no_dialog              = space
*      dst_device             = ‘LP01’ “Printer Name
*    IMPORTING
*      pdf_bytecount          = fp_size “Output Size
*    TABLES
*      pdf                    = li_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.

ENDFORM.                    ” BUILD_ALV
*&———————————————————————*
*&      Form  TOP-OF-PAGE
*&———————————————————————*
*       text
*———————————————————————-*
FORM TOP-OF-PAGE.
*ALV Header declarations
  DATA: T_HEADER TYPE SLIS_T_LISTHEADER,
        WA_HEADER TYPE SLIS_LISTHEADER,
        T_LINE LIKE WA_HEADER-INFO,
        LD_LINES TYPE I,
        LD_LINESC(10) TYPE C.

  V_DATE = P_DATE – .
*  Title
  WA_HEADER-TYP  = ‘H’.
  V_DATE = P_DATE.
  WA_HEADER-INFO = ‘KCSSL – Daily Shipment Report For :-‘.
  CONCATENATE WA_HEADER-INFO V_DATE+6(2) ‘.’ V_DATE+4(2) ‘.’ V_DATE(4) INTO WA_HEADER-INFO.
  APPEND WA_HEADER TO T_HEADER.
  CLEAR WA_HEADER.
*  Date
  WA_HEADER-TYP  = ‘S’.
  WA_HEADER-KEY = ‘Date: ‘.

  CONCATENATE  SY-DATUM+6(2) ‘.’
               SY-DATUM+4(2) ‘.’
               SY-DATUM(4)
                INTO WA_HEADER-INFO.   “todays date
  APPEND WA_HEADER TO T_HEADER.
  CLEAR: WA_HEADER.
  CALL FUNCTION ‘REUSE_ALV_COMMENTARY_WRITE’
    EXPORTING
      IT_LIST_COMMENTARY = T_HEADER.
ENDFORM.                    “top-of-page

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply