Skip to end of metadata
Go to start of metadata

Layout:

 <%@page language="abap" %>

<%@extension name="htmlb" prefix="htmlb" %>
<htmlb:content id               = "content"
               design           = "classic+design2002+design2003"
               controlRendering = "sap"
               rtlAutoSwitch    = "true" >
  <htmlb:page title="Create Attachment " >
    <htmlb:form method       = "post"
                encodingType = "multipart/form-data">

          <htmlb:textView text   = "File:"
                          design = "STANDARD" />

          <htmlb:fileUpload id          = "uploadID"
                            onUpload    = "UploadFile"
                            upload_text ="Upload Files"/>

    </htmlb:form>
  </htmlb:page>
</htmlb:content>

 onInputProcessing:

 onInputProcessing

DATA: EVENT TYPE REF TOIF_HTMLB_DATA,
      DATA TYPEREF TO CL_HTMLB_FILEUPLOAD,
      LV_OUTPUT_LENGTH TYPE I,
      LV_TEXT_BUFFER TYPE STRING,
      FILE_NAME TYPE STRING,
      FILE_PATH TYPE STRING ,
      INTERN TYPE TABLEOF  ALSMEX_TABLINE.
DATA: LT_BINARY_TAB TYPE TABLE OFSDOKCNTBIN .

TYPES: BEGIN OF TY_TAB,
       FIELD1(2) TYPEC,
       FIELD2(2) TYPEC,
       FIELD3(2) TYPEC,
       FIELD4(2) TYPEC,
       FIELD5(2) TYPEC,
       END OFTY_TAB.
DATA:  WA_TAB TYPE TY_TAB,
       IT_TAB TYPE TABLEOF TY_TAB.
TYPESBEGINOF TY_LINE,
       LINE(255)TYPE C,
       END OFTY_LINE.
DATA:  WA_LINE TYPE TY_LINE,
       IT_LINE TYPE TABLE OFTY_LINE.
EVENT = CL_HTMLB_MANAGER=>GET_EVENT_EX( REQUEST ).
IF EVENT IS NOT INITIALAND EVENT->EVENT_NAME = HTMLB_EVENTS=>FILEUPLOAD.
  DATA ?= CL_HTMLB_MANAGER=>GET_DATA( REQUEST = RUNTIME->SERVER->REQUEST NAME = 'fileUpload' ID= 'uploadID' ).

  FILE_NAME = DATA->FILE_NAME.
  FILE_PATH = FILE_NAME.
* CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
*    EXPORTING
*      FILENAME                      = FILE_PATH
*      {}I_BEGIN_COL                   = 1
*      {}I_BEGIN_ROW                   = 2
*      {}I_END_COL                     = 100
*      {}I_END_ROW                     = 100
*    TABLES
*      INTERN                        = INTERN
*  EXCEPTIONS
*     INCONSISTENT_PARAMETERS       = 1
*     UPLOAD_OLE                    = 2
*     OTHERS                        = 3
*            .
* IF SY-SUBRC <> 0.
** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
**         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
* ENDIF.

  IF DATAIS NOT INITIAL.
    CALL FUNCTION'SCMS_XSTRING_TO_BINARY'
     EXPORTING BUFFER = DATA->FILE_CONTENT
     IMPORTING OUTPUT_LENGTH = LV_OUTPUT_LENGTH
     TABLES BINARY_TAB = LT_BINARY_TAB .

    CALL FUNCTION'SCMS_BINARY_TO_STRING'
    EXPORTING INPUT_LENGTH = LV_OUTPUT_LENGTH
     IMPORTING TEXT_BUFFER = LV_TEXT_BUFFER
     TABLES
     BINARY_TAB = LT_BINARY_TAB.
    IF SY-SUBRC = 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    SPLIT LV_TEXT_BUFFER AT CL_ABAP_CHAR_UTILITIES=>CR_LF INTO TABLEIT_LINE.
    IF SY-SUBRC = 0.
      LOOP ATIT_LINE INTO WA_LINE.
*        SPLIT WA_LINE AT CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB
        split wa_line at ','
        INTO WA_TAB-FIELD1 WA_TAB-FIELD2 WA_TAB-FIELD3 WA_TAB-FIELD4 WA_TAB-FIELD5.
        append wa_tab to it_tab.
      ENDLOOP.
    ENDIF.
  ENDIF.

ENDIF.