[ABAP] 인터널테이블 HTML로 변환 후 메일 전송

SAPWISE·2023년 9월 7일
0

인터널테이블(GT_DATA) HTML로 변환
발신 메일주소들은 테이블로 관리하면 편함

if gt_data[] is not initial.

  data : iv_subjct type string value '[SAP] 입고 경과일 3년 이상 자재 확인 알림 메일',
         iv_head type w3head-text,
*         iv_head TYPE w3head-text VALUE '입고 경과일 3년이상 자재 리스트' ,
         iv_footer type string value '※ 본 메일은 시스템에서 자동으로 발송합니다.'.

  data : gt_recip type table of zrecip with header line.
  data : it_fcat  type lvc_t_fcat with header line. " Fieldcatalog

  data : lv_aufnr type aufnr.

*-& Header
  clear lv_aufnr.
  call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
    exporting
      input  = header_table-aufnr
    importing
      output = lv_aufnr.
*  CLEAR iv_head.
  concatenate '생산오더 '
              lv_aufnr '/' header_table-werks
              '입고 경과일 3년 이상 자재 리스트'
              into iv_head separated by space.

*-& 인터널 테이블 필드명, 레이아웃 설정
  it_fcat-coltext = '플랜트'.
  append it_fcat.
  clear : it_fcat.
  it_fcat-coltext = '자재 코드'.
  append it_fcat.
  clear : it_fcat.
  it_fcat-coltext = '자재 내역'.
  append it_fcat.
  clear : it_fcat.
  it_fcat-coltext = '자재 그룹'.
  append it_fcat.
  clear : it_fcat.
  it_fcat-coltext = '전기일'.
  append it_fcat.
  clear : it_fcat.
  it_fcat-coltext = '입고 경과일'.
  it_fcat-just = 'RIGHT'.
  append it_fcat.
  clear : it_fcat.

*-& 수신자 메일 설정
  select mail
    into gt_recip-mail
    from zrecip
    where tcode = sy-tcode.
    append gt_recip.
  endselect.

  if gt_recip[] is not initial.     "수신자 없으면 실행X
    call function 'ZMAIL_ZRDATE' in background task
*    CALL FUNCTION 'ZMAIL_ZRDATE'
      exporting
        iv_subjct = iv_subjct
        iv_head   = iv_head
        iv_footer = iv_footer
      tables
        gt_data   = gt_data
        gt_recip  = gt_recip
        gt_fcat   = it_fcat.
  endif.

endif.

ZMAIL_ZRDATE

  • 양식을 내 맘대로 바꾸기 위해 WWW_ITAB_TO_HTML 펑션ZWWW_ITAB_TO_HTML로 커스터마이징
function zmail_zrdate.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(IV_SUBJCT) TYPE  STRING OPTIONAL
*"     VALUE(IV_HEAD) TYPE  W3HEAD-TEXT OPTIONAL
*"     VALUE(IV_FOOTER) TYPE  STRING OPTIONAL
*"  TABLES
*"      GT_DATA STRUCTURE  Z01MMS091 OPTIONAL
*"      GT_RECIP STRUCTURE  ZRECIP OPTIONAL
*"      GT_FCAT TYPE  LVC_T_FCAT OPTIONAL
*"----------------------------------------------------------------------

  loop at gt_fcat.

    "레이아웃 정렬기준 IMPORT
    case gt_fcat-just.
      when 'R'.
        t_fields-just = 'RIGHT'.
      when 'L'.
        t_fields-just = 'LEFT'.
      when others.
        t_fields-just = 'CENTER'.
    endcase.

*-Populate the Column Headings
    w_head-text = gt_fcat-coltext.
    call function 'WWW_ITAB_TO_HTML_HEADERS'
      exporting
        field_nr = sy-tabix
        text     = w_head-text
        fgcolor  = 'black'
        bgcolor  = '#f5f6f5'
      tables
        header   = t_header.

*-Populate Column Properties
    call function 'WWW_ITAB_TO_HTML_LAYOUT'
      exporting
        field_nr  = sy-tabix
        fgcolor   = 'black'
        size      = '2.5'
        justified = t_fields-just
      tables
        fields    = t_fields.
  endloop.

**********************************************************************
**********************************************************************
*-& 테이블 헤더 및, 인터널 테이블 html 테이블로 변환
*--------------------------------------------------------------------*
  wa_header-text = iv_head.  "테이블 헤더
  wa_header-font = 'Arial'.
  wa_header-size = '2'.
  refresh t_html.

  call function 'ZWWW_ITAB_TO_HTML'
    exporting
      table_header = wa_header
      table_footer = iv_footer
    tables
      html         = t_html_x
      fields       = t_fields
      row_header   = t_header
      itable       = gt_data.
**********************************************************************
  "수신자 설정
  loop at gt_recip.
    rev_list-receiver = gt_recip-mail.  "수신자 메일
    rev_list-rec_type = 'U'.
    rev_list-rec_date = sy-datum.
    append rev_list.
    clear rev_list.
  endloop.

  "메일 제목 설정
  clear : doc_data.
  doc_data-obj_descr  = iv_subjct.   "메일 제목
  doc_data-obj_langu  = sy-langu.

  "수신자 리스트를 loop하며 메일 발송
  call function 'SO_NEW_DOCUMENT_SEND_API1'
    exporting
      document_data              = doc_data  "메일제목
      document_type              = 'HTM'
      put_in_outbox              = 'X'
      commit_work                = 'X'
    tables
      object_content             = t_html_x  "html 본문
      receivers                  = rev_list  "수신자 메일
    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.

  submit rsconn01 with mode = 'INT'
*WITH output = 'X'
  and return.
endfunction.
profile
SAP, ERP, ABAP

0개의 댓글