상세 컨텐츠

본문 제목

ABAP 메일링 기능 정리 1 - 단순 텍스트 LOOP

ABAP

by Kiroc 2022. 6. 13. 17:13

본문

* 참고사항 : BC에서 설정이 필요함(TCD : SOST).

현고객사에는 MAIL기능이 운영서버에만 적용되어서 운영까지 프로그램을 넘겨 테스트했다

 

 

1. 소스코드

REPORT ZTEST MESSAGE-ID ZPPMC10.  " 해당 모듈의 메세지 ID입력

INCLUDE ZTEST_TOP.
INCLUDE ZTEST_SEL.

START-OF-SELECTION.

* MAIL 내용 생성 - LOOP로 여러줄 보내기 가능
  LS_MAIL-TEXT '20220613 TEST'.
  APPEND LS_MAIL TO LT_MAIL.


  LS_MAIL-TEXT '20220612 TEST'.
  APPEND LS_MAIL TO LT_MAIL.

* 옵션 SET
  EMAIL_DATA-OBJ_NAME '메일링 테스트'.             "문서, 폴더 또는 분배 리스트의 이름
  EMAIL_DATA-OBJ_DESCR '[SAP] MAIL 테스트 - 심플'"TITLE
*EMAIL_DATA-OBJ_LANGU = 'E'.                         "생성된 문서의 언어
  EMAIL_DATA-SENSITIVTY 'P'.                       "메일 종류 - P(기밀), F(기능), O(표준), G(비즈니스), E(개인)
  EMAIL_DATA-OBJ_PRIO '1'.                         "문서우선순위 - 1(최우선)~9(최하순위)
  EMAIL_DATA-NO_CHANGE 'X'.                        "문서 변경 불가
  EMAIL_DATA-PRIORITY '1'.                         "문서우선순위 - 1(최우선)~9(최하순위)

*수신인 SET - LOOP로 여러줄 보내기 가능
  LS_EMAIL_SEND-RECEIVER '아이디@NAVER.COM'.
  LS_EMAIL_SEND-REC_TYPE 'U'.              "수신자 유형 - U(인터넷 주소)
  LS_EMAIL_SEND-EXPRESS 'X'.               "속달 발신
  APPEND LS_EMAIL_SEND TO LT_EMAIL_SEND.

  LS_EMAIL_SEND-RECEIVER '아이디@회사.COM'.
  LS_EMAIL_SEND-REC_TYPE 'U'.
  LS_EMAIL_SEND-EXPRESS 'X'.
  APPEND LS_EMAIL_SEND TO LT_EMAIL_SEND.

*MAIL SEND
  CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
    EXPORTING
      DOCUMENT_DATA              EMAIL_DATA
      DOCUMENT_TYPE              'RAW'
      PUT_IN_OUTBOX              'X'
      COMMIT_WORK                'X'
*     IP_ENCRYPT                 =
*     IP_SIGN                    =
* IMPORTING
*     SENT_TO_ALL                =
*     NEW_OBJECT_ID              =
    TABLES
*     OBJECT_HEADER              =
      OBJECT_CONTENT             LT_MAIL
*     CONTENTS_HEX               =
*     OBJECT_PARA                =
*     OBJECT_PARB                =
      RECEIVERS                  LT_EMAIL_SEND
    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 E000 WITH 'ERROR'.
  ENDIF.

  LEAVE PROGRAM.

 

2. INCLUDE ZTEST_TOP.

*메일 내용부 타입 선언
TYPES BEGIN OF CONTENTS,
  TEXT(255TYPE C,
  END OF CONTENTS.

DATA EMAIL_DATA TYPE SODOCCHGI1,            "메일 옵션
       LS_MAIL TYPE CONTENTS,                 "메일 내용 - STRUCTURE
       LT_MAIL TYPE TABLE OF CONTENTS,        "메일 내용 - TABLE
       LT_EMAIL_SEND TYPE TABLE OF SOMLRECI1"수신자 정보 - TABLE
       LS_EMAIL_SEND TYPE SOMLRECI1.          "수신자 정보 - STRUCTURE

관련글 더보기