ABAP获取用户登录详细信息并已邮件附件的形式发送给你

老外写的这段代码,从逻辑上看,我没看出问题,但是运行后不见发送邮件出来,请有空的前辈调试解决下,这段代码可以作为新人学习ABAP的一个典型DEMO。

This is a Sample Code for fetching the User Login Details and sending it as an XLS attachment to an Email using the XML method

*&---------------------------------------------------------------------*
*& REPORT  Z_WUWEI_0022
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  Z_WUWEI_0022.

TYPE-POOLS: IXML.

*------------------------------------------------------------------------*
*                           DATA DECLARATIONS                            *
*------------------------------------------------------------------------*

* STRUCTURE FOR FINAL INTERNAL TABLE
TYPES: BEGIN OF TY_FINAL,
        SRNO(3) TYPE N,
        USER_ID TYPE USR02-BNAME,
        FULL_NAME TYPE BAPIADDR3-FULLNAME,
        DEPT TYPE BAPIADDR3-DEPARTMENT,
        LOGIN(3) TYPE C,
       END OF TY_FINAL.

* STRUCTURE FOR USR02
TYPES: BEGIN OF TY_USR02,
        BNAME TYPE USR02-BNAME,
        TRDAT TYPE USR02-TRDAT,
       END OF TY_USR02.

* INTERNAL TABLE & WORK AREA FOR FINAL INTERNAL TABLE
DATA: IT_FINAL TYPE TABLE OF TY_FINAL,
      WA_FINAL TYPE TY_FINAL.

* INTERNAL TABLE & WORK AREA FOR USR02 INTERNAL TABLE
DATA: IT_USR02 TYPE TABLE OF TY_USR02,
      WA_USR02 TYPE TY_USR02.

* WORK AREA FOR ADD3_DATA STRUCTRE
DATA: WA_ADDR TYPE BAPIADDR3.
DATA: IT_RETURN TYPE TABLE OF BAPIRET2.

DATA: LV_DATE TYPE D.
DATA: LV_FILENAME TYPE STRING.

TYPES: BEGIN OF XML_LINE,
        DATA(255) TYPE X,
       END OF XML_LINE.

DATA: L_IXML            TYPE REF TO IF_IXML,
      L_STREAMFACTORY   TYPE REF TO IF_IXML_STREAM_FACTORY,
      L_OSTREAM         TYPE REF TO IF_IXML_OSTREAM,
      L_RENDERER        TYPE REF TO IF_IXML_RENDERER,
      L_DOCUMENT        TYPE REF TO IF_IXML_DOCUMENT.

DATA: L_ELEMENT_ROOT        TYPE REF TO IF_IXML_ELEMENT,
      NS_ATTRIBUTE          TYPE REF TO IF_IXML_ATTRIBUTE,
      R_ELEMENT_PROPERTIES  TYPE REF TO IF_IXML_ELEMENT,
      R_ELEMENT             TYPE REF TO IF_IXML_ELEMENT,
      R_WORKSHEET           TYPE REF TO IF_IXML_ELEMENT,
      R_TABLE               TYPE REF TO IF_IXML_ELEMENT,
      R_COLUMN              TYPE REF TO IF_IXML_ELEMENT,
      R_ROW                 TYPE REF TO IF_IXML_ELEMENT,
      R_CELL                TYPE REF TO IF_IXML_ELEMENT,
      R_DATA                TYPE REF TO IF_IXML_ELEMENT,
      L_VALUE               TYPE STRING,
      L_TYPE                TYPE STRING,
      L_TEXT(100)           TYPE C,
      R_STYLES              TYPE REF TO IF_IXML_ELEMENT,
      R_STYLE               TYPE REF TO IF_IXML_ELEMENT,
      R_STYLE1              TYPE REF TO IF_IXML_ELEMENT,
      R_FORMAT              TYPE REF TO IF_IXML_ELEMENT,
      R_BORDER              TYPE REF TO IF_IXML_ELEMENT,
      NUM_ROWS              TYPE I.

DATA: L_XML_TABLE       TYPE TABLE OF XML_LINE,
      WA_XML            TYPE XML_LINE,
      L_XML_SIZE        TYPE I,
      L_RC              TYPE I.


*------------------------------------------------------------------------*
*                             INITIALIZATION                             *
*------------------------------------------------------------------------*

INITIALIZATION.
  LV_DATE = SY-DATUM - 1.


*------------------------------------------------------------------------*
*                           START OF SELECTION                           *
*------------------------------------------------------------------------*

START-OF-SELECTION.

  PERFORM GET_USER_DATA.
  PERFORM PROCESS_XML_DATA.
  PERFORM SEND_MAIL.


*&---------------------------------------------------------------------*
*&      FORM  GET_USER_DATA
*&---------------------------------------------------------------------*
*       FETCH USER DETAILS FROM USR02
*----------------------------------------------------------------------*

FORM GET_USER_DATA.

  REFRESH IT_FINAL.
  SELECT DISTINCT BNAME TRDAT FROM USR02 INTO TABLE IT_USR02.
  SORT IT_USR02 BY BNAME.

  IF NOT IT_USR02[] IS INITIAL.

    LOOP AT IT_USR02 INTO WA_USR02.

      CLEAR WA_FINAL.
      WA_FINAL-SRNO = SY-TABIX.                   " SERIAL NO.
      WA_FINAL-USER_ID = WA_USR02-BNAME.          " USER ID

      CALL FUNCTION 'BAPI_USER_GET_DETAIL'
        EXPORTING
          USERNAME = WA_USR02-BNAME
        IMPORTING
          ADDRESS  = WA_ADDR
        TABLES
          RETURN   = IT_RETURN.

      IF SY-SUBRC EQ 0.
        WA_FINAL-FULL_NAME = WA_ADDR-FULLNAME.    " FULL NAME
        WA_FINAL-DEPT = WA_ADDR-DEPARTMENT.       " DEPARTMENT
      ENDIF.

      IF WA_USR02-TRDAT EQ LV_DATE.
        WA_FINAL-LOGIN = 'YES'.                   " LOGIN ON PREVIOUS DAY
      ELSE.
        WA_FINAL-LOGIN = 'NO'.
      ENDIF.

      APPEND WA_FINAL TO IT_FINAL.

    ENDLOOP.

  ENDIF.

ENDFORM.                    " GET_USER_DATA


*&---------------------------------------------------------------------*
*&      FORM  SEND_MAIL
*&---------------------------------------------------------------------*
*       SEND EMAIL
*----------------------------------------------------------------------*

FORM SEND_MAIL.

  DATA: OBJPACK   LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.
  DATA: OBJHEAD   LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.
  DATA: OBJBIN    LIKE SOLIX OCCURS 10 WITH HEADER LINE.
  DATA: OBJTXT    LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
  DATA: RECLIST   LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.
  DATA: DOC_CHNG  LIKE SODOCCHGI1.
  DATA: TAB_LINES LIKE SY-TABIX.
  DATA: L_NUM(3).
  DATA: SUBJ_DATE(10) TYPE C.

* MAIL SUBJECT
  CONCATENATE LV_DATE+6(2) '-' LV_DATE+4(2) '-' LV_DATE+0(4) INTO SUBJ_DATE.
  CONCATENATE 'SAP APPLICATION USAGE REPORT ' SUBJ_DATE INTO DOC_CHNG-OBJ_DESCR SEPARATED BY SPACE.

* MAIL CONTENTS
  OBJTXT = 'DEAR USER,'.
  APPEND OBJTXT.

  CLEAR OBJTXT.
  APPEND OBJTXT.

  CONCATENATE 'PLEASE FIND THE ATTACHED SAP APPLICATION USAGE REPORT FOR ' SUBJ_DATE INTO OBJTXT SEPARATED BY SPACE.              " MAIL CONTENTS
  APPEND OBJTXT.

  CLEAR OBJTXT.
  APPEND OBJTXT.

  OBJTXT = 'THANKS & REGARDS,'.
  APPEND OBJTXT.

  OBJTXT = 'HIMANSHU KANEKAR'.
  APPEND OBJTXT.

  DESCRIBE TABLE OBJTXT LINES TAB_LINES.
  READ TABLE OBJTXT INDEX TAB_LINES.
  DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).

* PACKING LIST FOR THE E-MAIL BODY
  OBJPACK-HEAD_START = 1.
  OBJPACK-HEAD_NUM   = 0.
  OBJPACK-BODY_START = 1.
  OBJPACK-BODY_NUM   = TAB_LINES.
  OBJPACK-DOC_TYPE   = 'RAW'.
  APPEND OBJPACK.

* CREATION OF THE DOCUMENT ATTACHMENT
  LOOP AT L_XML_TABLE INTO WA_XML.
    CLEAR OBJBIN.
    OBJBIN-LINE = WA_XML-DATA.
    APPEND OBJBIN.
  ENDLOOP.

  DESCRIBE TABLE OBJBIN LINES TAB_LINES.
  OBJHEAD = 'SAP LOGIN DETAILS'.
  APPEND OBJHEAD.

* PACKING LIST FOR THE E-MAIL ATTACHMENT
  OBJPACK-TRANSF_BIN = 'X'.
  OBJPACK-HEAD_START = 1.
  OBJPACK-HEAD_NUM   = 0.
  OBJPACK-BODY_START = 1.
  OBJPACK-BODY_NUM = TAB_LINES.
  CONCATENATE 'SAP_LOGIN_DETAILS' SUBJ_DATE INTO OBJPACK-OBJ_DESCR SEPARATED BY SPACE.
  OBJPACK-DOC_TYPE = 'XLS'.
  OBJPACK-DOC_SIZE = TAB_LINES * 255.
  APPEND OBJPACK.

* TARGET RECIPENT
  CLEAR RECLIST.
  RECLIST-RECEIVER = 'name@company.com'.
  RECLIST-REC_TYPE = 'U'.
  APPEND RECLIST.

* SENDING THE DOCUMENT
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      DOCUMENT_DATA              = DOC_CHNG
      PUT_IN_OUTBOX              = 'X'
    TABLES
      PACKING_LIST               = OBJPACK
      OBJECT_HEADER              = OBJHEAD
      CONTENTS_TXT               = OBJTXT
      CONTENTS_HEX               = OBJBIN
      RECEIVERS                  = RECLIST
    EXCEPTIONS
      TOO_MANY_RECEIVERS         = 1
      DOCUMENT_NOT_SENT          = 2
      OPERATION_NO_AUTHORIZATION = 4
      OTHERS                     = 99.
   COMMIT WORK AND WAIT.

ENDFORM.                    " SEND_MAIL



*&---------------------------------------------------------------------*
*&      FORM  PROCESS_XML_DATA
*&---------------------------------------------------------------------*
*       PROCESS XML DATA
*----------------------------------------------------------------------*

FORM PROCESS_XML_DATA .

* CREATING A IXML FACTORY
  L_IXML = CL_IXML=>CREATE( ).

* CREATING THE DOM OBJECT MODEL
  L_DOCUMENT = L_IXML->CREATE_DOCUMENT( ).

* CREATE ROOT NODE 'WORKBOOK'
  L_ELEMENT_ROOT  = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'WORKBOOK'  PARENT = L_DOCUMENT ).
  L_ELEMENT_ROOT->SET_ATTRIBUTE( NAME = 'XMLNS'  VALUE = 'URN:SCHEMAS-MICROSOFT-COM:OFFICE:SPREADSHEET' ).

  NS_ATTRIBUTE = L_DOCUMENT->CREATE_NAMESPACE_DECL( NAME = 'SS'  PREFIX = 'XMLNS'  URI = 'URN:SCHEMAS-MICROSOFT-COM:OFFICE:SPREADSHEET' ).
  L_ELEMENT_ROOT->SET_ATTRIBUTE_NODE( NS_ATTRIBUTE ).

  NS_ATTRIBUTE = L_DOCUMENT->CREATE_NAMESPACE_DECL( NAME = 'X'  PREFIX = 'XMLNS'  URI = 'URN:SCHEMAS-MICROSOFT-COM:OFFICE:EXCEL' ).
  L_ELEMENT_ROOT->SET_ATTRIBUTE_NODE( NS_ATTRIBUTE ).

* CREATE NODE FOR DOCUMENT PROPERTIES.
  R_ELEMENT_PROPERTIES = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'TEST_REPORT'  PARENT = L_ELEMENT_ROOT ).
  L_VALUE = SY-UNAME.
  L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'AUTHOR'  VALUE = L_VALUE  PARENT = R_ELEMENT_PROPERTIES  ).

* STYLES
  R_STYLES = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'STYLES'  PARENT = L_ELEMENT_ROOT  ).

* STYLE FOR HEADER
  R_STYLE  = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'STYLE'   PARENT = R_STYLES  ).
  R_STYLE->SET_ATTRIBUTE_NS( NAME = 'ID'  PREFIX = 'SS'  VALUE = 'HEADER' ).

  R_FORMAT  = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'FONT'  PARENT = R_STYLE  ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'BOLD'  PREFIX = 'SS'  VALUE = '1' ).

  R_FORMAT  = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'INTERIOR' PARENT = R_STYLE  ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'COLOR'   PREFIX = 'SS'  VALUE = '#92D050' ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'PATTERN' PREFIX = 'SS'  VALUE = 'SOLID' ).

  R_FORMAT  = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'ALIGNMENT'  PARENT = R_STYLE  ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'VERTICAL'  PREFIX = 'SS'  VALUE = 'CENTER' ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'WRAPTEXT'  PREFIX = 'SS'  VALUE = '1' ).

  R_BORDER  = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'BORDERS'  PARENT = R_STYLE ).
  R_FORMAT  = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'BORDER'   PARENT = R_BORDER  ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'POSITION'  PREFIX = 'SS'  VALUE = 'BOTTOM' ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'LINESTYLE'  PREFIX = 'SS'  VALUE = 'CONTINUOUS' ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'WEIGHT'  PREFIX = 'SS'  VALUE = '1' ).

  R_FORMAT  = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'BORDER'   PARENT = R_BORDER  ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'POSITION'  PREFIX = 'SS'  VALUE = 'LEFT' ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'LINESTYLE'  PREFIX = 'SS'  VALUE = 'CONTINUOUS' ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'WEIGHT'  PREFIX = 'SS'  VALUE = '1' ).

  R_FORMAT  = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'BORDER'   PARENT = R_BORDER  ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'POSITION'  PREFIX = 'SS'  VALUE = 'TOP' ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'LINESTYLE'  PREFIX = 'SS'  VALUE = 'CONTINUOUS' ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'WEIGHT'  PREFIX = 'SS'  VALUE = '1' ).

  R_FORMAT  = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'BORDER'   PARENT = R_BORDER  ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'POSITION'  PREFIX = 'SS'  VALUE = 'RIGHT' ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'LINESTYLE'  PREFIX = 'SS'  VALUE = 'CONTINUOUS' ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'WEIGHT'  PREFIX = 'SS'  VALUE = '1' ).

* STYLE FOR DATA
  R_STYLE1  = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'STYLE'   PARENT = R_STYLES  ).
  R_STYLE1->SET_ATTRIBUTE_NS( NAME = 'ID'  PREFIX = 'SS'  VALUE = 'DATA' ).

  R_BORDER  = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'BORDERS'  PARENT = R_STYLE1 ).
  R_FORMAT  = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'BORDER'   PARENT = R_BORDER  ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'POSITION'  PREFIX = 'SS'  VALUE = 'BOTTOM' ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'LINESTYLE'  PREFIX = 'SS'  VALUE = 'CONTINUOUS' ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'WEIGHT'  PREFIX = 'SS'  VALUE = '1' ).

  R_FORMAT  = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'BORDER'   PARENT = R_BORDER  ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'POSITION'  PREFIX = 'SS'  VALUE = 'LEFT' ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'LINESTYLE'  PREFIX = 'SS'  VALUE = 'CONTINUOUS' ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'WEIGHT'  PREFIX = 'SS'  VALUE = '1' ).

  R_FORMAT  = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'BORDER'   PARENT = R_BORDER  ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'POSITION'  PREFIX = 'SS'  VALUE = 'TOP' ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'LINESTYLE'  PREFIX = 'SS'  VALUE = 'CONTINUOUS' ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'WEIGHT'  PREFIX = 'SS'  VALUE = '1' ).

  R_FORMAT  = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'BORDER'   PARENT = R_BORDER  ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'POSITION'  PREFIX = 'SS'  VALUE = 'RIGHT' ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'LINESTYLE'  PREFIX = 'SS'  VALUE = 'CONTINUOUS' ).
  R_FORMAT->SET_ATTRIBUTE_NS( NAME = 'WEIGHT'  PREFIX = 'SS'  VALUE = '1' ).


* WORKSHEET
  R_WORKSHEET = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'WORKSHEET'  PARENT = L_ELEMENT_ROOT ).
  R_WORKSHEET->SET_ATTRIBUTE_NS( NAME = 'NAME'  PREFIX = 'SS'  VALUE = 'SHEET1' ).

* TABLE
  R_TABLE = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'TABLE'  PARENT = R_WORKSHEET ).
  R_TABLE->SET_ATTRIBUTE_NS( NAME = 'FULLCOLUMNS'  PREFIX = 'X'  VALUE = '1' ).
  R_TABLE->SET_ATTRIBUTE_NS( NAME = 'FULLROWS'     PREFIX = 'X'  VALUE = '1' ).

* COLUMN FORMATTING
  R_COLUMN = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'COLUMN'  PARENT = R_TABLE ).
  R_COLUMN->SET_ATTRIBUTE_NS( NAME = 'WIDTH'  PREFIX = 'SS'  VALUE = '40' ).

  R_COLUMN = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'COLUMN'  PARENT = R_TABLE ).
  R_COLUMN->SET_ATTRIBUTE_NS( NAME = 'WIDTH'  PREFIX = 'SS'  VALUE = '90' ).

  R_COLUMN = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'COLUMN'  PARENT = R_TABLE ).
  R_COLUMN->SET_ATTRIBUTE_NS( NAME = 'WIDTH'  PREFIX = 'SS'  VALUE = '140' ).

  R_COLUMN = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'COLUMN'  PARENT = R_TABLE ).
  R_COLUMN->SET_ATTRIBUTE_NS( NAME = 'WIDTH'  PREFIX = 'SS'  VALUE = '150' ).

  R_COLUMN = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'COLUMN'  PARENT = R_TABLE ).
  R_COLUMN->SET_ATTRIBUTE_NS( NAME = 'WIDTH'  PREFIX = 'SS'  VALUE = '90' ).

* BLANK ROW
  R_ROW = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'ROW'  PARENT = R_TABLE ).

* COLUMN HEADERS ROW
  R_ROW = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'ROW'  PARENT = R_TABLE ).
  R_ROW->SET_ATTRIBUTE_NS( NAME = 'AUTOFITHEIGHT'  PREFIX = 'SS'  VALUE = '1' ).

* SR. NO.
  R_CELL = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'CELL'  PARENT = R_ROW ).
  R_CELL->SET_ATTRIBUTE_NS( NAME = 'STYLEID'  PREFIX = 'SS'  VALUE = 'HEADER' ).
  R_DATA = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'DATA'  VALUE = 'SR. NO.'  PARENT = R_CELL ).
  R_DATA->SET_ATTRIBUTE_NS( NAME = 'TYPE'  PREFIX = 'SS' VALUE = 'STRING' ).

* USER NAME
  R_CELL = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'CELL'  PARENT = R_ROW ).
  R_CELL->SET_ATTRIBUTE_NS( NAME = 'STYLEID'  PREFIX = 'SS'  VALUE = 'HEADER' ).
  R_DATA = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'DATA'  VALUE = 'USER NAME'  PARENT = R_CELL ).
  R_DATA->SET_ATTRIBUTE_NS( NAME = 'TYPE'  PREFIX = 'SS' VALUE = 'STRING' ).

* FULL NAME
  R_CELL = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'CELL'  PARENT = R_ROW ).
  R_CELL->SET_ATTRIBUTE_NS( NAME = 'STYLEID'  PREFIX = 'SS'  VALUE = 'HEADER' ).
  R_DATA = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'DATA'  VALUE = 'FULL NAME'  PARENT = R_CELL ).
  R_DATA->SET_ATTRIBUTE_NS( NAME = 'TYPE'  PREFIX = 'SS' VALUE = 'STRING' ).

* DEPARTMENT
  R_CELL = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'CELL'  PARENT = R_ROW ).
  R_CELL->SET_ATTRIBUTE_NS( NAME = 'STYLEID'  PREFIX = 'SS'  VALUE = 'HEADER' ).
  R_DATA = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'DATA'  VALUE = 'DEPARTMENT'  PARENT = R_CELL ).
  R_DATA->SET_ATTRIBUTE_NS( NAME = 'TYPE'  PREFIX = 'SS' VALUE = 'STRING' ).

* LOGIN
  R_CELL = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'CELL'  PARENT = R_ROW ).
  R_CELL->SET_ATTRIBUTE_NS( NAME = 'STYLEID'  PREFIX = 'SS'  VALUE = 'HEADER' ).
  CONCATENATE 'LOGIN - ' LV_DATE+6(2) '/' LV_DATE+4(2) '/' LV_DATE+0(4) INTO L_VALUE.
  R_DATA = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'DATA'  VALUE = L_VALUE  PARENT = R_CELL ).
  R_DATA->SET_ATTRIBUTE_NS( NAME = 'TYPE'  PREFIX = 'SS' VALUE = 'STRING' ).

* BLANK ROW AFTER COLUMN HEADERS
  R_ROW = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'ROW'  PARENT = R_TABLE ).
  R_CELL = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'CELL'  PARENT = R_ROW ).
  R_CELL->SET_ATTRIBUTE_NS( NAME = 'STYLEID'  PREFIX = 'SS'  VALUE = 'DATA' ).

  R_CELL = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'CELL'  PARENT = R_ROW ).
  R_CELL->SET_ATTRIBUTE_NS( NAME = 'STYLEID'  PREFIX = 'SS'  VALUE = 'DATA' ).

  R_CELL = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'CELL'  PARENT = R_ROW ).
  R_CELL->SET_ATTRIBUTE_NS( NAME = 'STYLEID'  PREFIX = 'SS'  VALUE = 'DATA' ).

  R_CELL = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'CELL'  PARENT = R_ROW ).
  R_CELL->SET_ATTRIBUTE_NS( NAME = 'STYLEID'  PREFIX = 'SS'  VALUE = 'DATA' ).

  R_CELL = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'CELL'  PARENT = R_ROW ).
  R_CELL->SET_ATTRIBUTE_NS( NAME = 'STYLEID'  PREFIX = 'SS'  VALUE = 'DATA' ).

* DATA TABLE
  LOOP AT IT_FINAL INTO WA_FINAL.

    R_ROW = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'ROW'  PARENT = R_TABLE ).

* SR. NO.
    R_CELL = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'CELL'  PARENT = R_ROW ).
    R_CELL->SET_ATTRIBUTE_NS( NAME = 'STYLEID'  PREFIX = 'SS'  VALUE = 'DATA' ).
    L_VALUE = SY-TABIX.
    CONDENSE L_VALUE NO-GAPS.
    R_DATA = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'DATA'  VALUE = L_VALUE   PARENT = R_CELL ).           " DATA
    R_DATA->SET_ATTRIBUTE_NS( NAME = 'TYPE'  PREFIX = 'SS'  VALUE = 'NUMBER' ).                               " CELL FORMAT

* USER NAME
    R_CELL = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'CELL'  PARENT = R_ROW ).
    R_CELL->SET_ATTRIBUTE_NS( NAME = 'STYLEID'  PREFIX = 'SS'  VALUE = 'DATA' ).
    L_VALUE = WA_FINAL-USER_ID.
    R_DATA = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'DATA'  VALUE = L_VALUE   PARENT = R_CELL ).           " DATA
    R_DATA->SET_ATTRIBUTE_NS( NAME = 'TYPE'  PREFIX = 'SS'  VALUE = 'STRING' ).                               " CELL FORMAT

* FULL NAME
    R_CELL = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'CELL'  PARENT = R_ROW ).
    R_CELL->SET_ATTRIBUTE_NS( NAME = 'STYLEID'  PREFIX = 'SS'  VALUE = 'DATA' ).
    L_VALUE = WA_FINAL-FULL_NAME.
    R_DATA = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'DATA'  VALUE = L_VALUE   PARENT = R_CELL ).           " DATA
    R_DATA->SET_ATTRIBUTE_NS( NAME = 'TYPE'  PREFIX = 'SS'  VALUE = 'STRING' ).                               " CELL FORMAT

* DEPARTMENT
    R_CELL = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'CELL'  PARENT = R_ROW ).
    R_CELL->SET_ATTRIBUTE_NS( NAME = 'STYLEID'  PREFIX = 'SS'  VALUE = 'DATA' ).
    L_VALUE = WA_FINAL-DEPT.
    R_DATA = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'DATA'  VALUE = L_VALUE   PARENT = R_CELL ).           " DATA
    R_DATA->SET_ATTRIBUTE_NS( NAME = 'TYPE'  PREFIX = 'SS'  VALUE = 'STRING' ).                               " CELL FORMAT

* LOGIN
    R_CELL = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'CELL'  PARENT = R_ROW ).
    R_CELL->SET_ATTRIBUTE_NS( NAME = 'STYLEID'  PREFIX = 'SS'  VALUE = 'DATA' ).
    L_VALUE = WA_FINAL-LOGIN.
    R_DATA = L_DOCUMENT->CREATE_SIMPLE_ELEMENT( NAME = 'DATA'  VALUE = L_VALUE   PARENT = R_CELL ).          " DATA
    R_DATA->SET_ATTRIBUTE_NS( NAME = 'TYPE'  PREFIX = 'SS'  VALUE = 'STRING' ).                              " CELL FORMAT

  ENDLOOP.

* CREATING A STREAM FACTORY
  L_STREAMFACTORY = L_IXML->CREATE_STREAM_FACTORY( ).

* CONNECT INTERNAL XML TABLE TO STREAM FACTORY
  L_OSTREAM = L_STREAMFACTORY->CREATE_OSTREAM_ITABLE( TABLE = L_XML_TABLE ).

* RENDERING THE DOCUMENT
  L_RENDERER = L_IXML->CREATE_RENDERER( OSTREAM  = L_OSTREAM  DOCUMENT = L_DOCUMENT ).
  L_RC = L_RENDERER->RENDER( ).

* SAVING THE XML DOCUMENT
  L_XML_SIZE = L_OSTREAM->GET_NUM_WRITTEN_RAW( ).

ENDFORM.                    " PROCESS_XML_DATA


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值