이전에 썼던 소스는 stateful처럼 쓰기위하여 임시 테이블을 쓴것이었다.
stateless로 쓴다면 다음과 같이 적으면 된다.
Layout
<%@page language="abap"%>
<%@extension name="htmlb" prefix="htmlb"%>
<script language="JavaScript">
function check_upload() {
var arg_myFileUpload1 = document.forms[0].myFileUpload1.value ;
if ( arg_myFileUpload1 == "") {
alert("No Upload file exist");
}
else {
return true;
}
return false;
}
</script>
<%
DATA : TEMP_STRING TYPE STRING.
DATA : WA_ZM0069 TYPE ZM0069.
DATA : IT_ZM0069 TYPE STANDARD TABLE OF ZM0069.
%>
<htmlb:content design="design2003">
<htmlb:page title="File Upload"
marginTop="0"
marginLeft="0"
marginRight="0"
marginBottom="0"
scrolling="YES">
<htmlb:form method = "post"
encodingType = "multipart/form-data" >
<table bgcolor="white" cellpadding="0" cellspacing="0" width="100%" height="100%" >
<tr>
<td>
<table bgcolor="white" cellpadding="0" cellspacing="0" width="100%" height="100%">
<tr>
<td width="100%" height="100%">
<table cellpadding="0" cellspacing="0" width="100%" height="100%">
<tr>
<td height="28">File Upload
</td>
</tr>
<tr>
<td valign="top">
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>
<!-- start attached file-->
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>Attached file(s)
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td><br>
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="30%">
<htmlb:fileUpload id = "myFileUpload1"
size = "50" />
</td>
<td width="5">
</td>
<td>
<htmlb:button id = "submitButton"
text = "Upload"
width = "75"
onClick = "HandleUpload"
onClientClick = "javascript:htmlbevent.cancelSubmit=!check_upload();"/>
</td>
<td width="100%">
</td>
</tr>
<tr>
<td colspan="4" height="5">
</td>
</td>
<tr>
<td colspan="4">
<img src="img/common/ico_att.gif">
<font color="#ff0000"><%=OTR(ZVIVA/TXT_ATTACH_WARING)%></font>
</td>
</td>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<!-- start board table -->
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr height="22">
<td width="10">
</td>
<td width="20%">No.
</td>
<td width="55%">File name
</td>
<td width="15%">Size(Bytes)
</td>
<td width="10%">Delete
</td>
</tr>
<%
SELECT *
INTO CORRESPONDING FIELDS OF TABLE IT_FILE_HEADER
FROM FILE_HEADER
WHERE KEY_FIELD EQ IPF_KEY_FIELD.
IF IT_FILE_HEADER[] IS NOT INITIAL.
LOOP AT IT_FILE_HEADER INTO WA_FILE_HEADER.
%>
<tr>
<td>
</td>
<td><%=SY-TABIX%>
</td>
<td>
<%
CONCATENATE 'LINK' WA_FILE_HEADER-SNO INTO TEMP_STRING.
%>
<htmlb:link id = "<%=TEMP_STRING%>"
text = "<%=WA_ZM0069-FILENAME%>"
onClick = "MyLinkClick"/>
</td>
<td><%=WA_ZM0069-LENGTH%>
</td>
<td>
<%
CONCATENATE 'DEL' WA_FILE_HEADER-SNO INTO TEMP_STRING.
%>
<htmlb:image id = "<%=TEMP_STRING%>"
src = "img/common/ico_del2.gif"
onClick = "MyLinkClick"/>
</td>
</tr>
<%
ENDLOOP.
ENDIF.
%>
<tr>
<td colspan="5" height="5">
</td>
</tr>
<tr>
<td colspan="5" align="right">
<!--start button-->
<table cellpadding="0" cellspacing="0">
<tr>
<td>
<htmlb:button id = "Close"
text = "Close"
onClientClick = "javascript:window.close();"
width = "75"
onClick = "HandleUpload" />
</td>
</tr>
</table>
<!--end button-->
</td>
</tr>
</table>
<!-- end board table -->
</td>
</tr>
</table>
<!--end attached file-->
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</htmlb:form>
</htmlb:page>
</htmlb:content>
일딴 레이아웃 부분에서는 화면을 불러올때마다 목록을 다시 작성한다.
OnRequest부분에는 특별히 쓸것은 없다.
OnInputProcessing는
*--------------------------------------------------------------------*
* Event Data
*--------------------------------------------------------------------*
CLASS CL_HTMLB_MANAGER DEFINITION LOAD. "이부분이 빠지면 실행이 안됨
DATA : EVENT TYPE REF TO IF_HTMLB_DATA.
DATA : TABLE_EVENT TYPE REF TO CL_HTMLB_EVENT_TABLEVIEW.
DATA : IDOFEVENT TYPE STRING.
DATA : DATA TYPE REF TO CL_HTMLB_FILEUPLOAD.
*--------------------------------------------------------------------*
* Tables
*--------------------------------------------------------------------*
DATA : WA_FILE_HEADER TYPE FILE_HEADER.
*--------------------------------------------------------------------*
* Internal Table
*--------------------------------------------------------------------*
DATA : WA_FILE_DETAIL TYPE FILE_DETAIL.
DATA : IT_FILE_DETAIL TYPE STANDARD TABLE OF FILE_DETAIL.
*--------------------------------------------------------------------*
* Variable Defintion
*--------------------------------------------------------------------*
DATA : CONTENT_TYPE TYPE STRING.
DATA : FILE_CONTENT TYPE XSTRING.
DATA : TEMP_INT1 TYPE I.
DATA : TEMP_INT2 TYPE I.
DATA : TEMP_INT3 TYPE I.
DATA : TEMP_C(21) TYPE C.
DATA : TEMP1 TYPE STRING,
TEMP2 TYPE STRING.
DATA : CONTENT_DISPOSITION TYPE STRING,
CONTENT_LENGTH TYPE STRING.
*--------------------------------------------------------------------*
* Ranges
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
* Event Casting
*--------------------------------------------------------------------*
EVENT = CL_HTMLB_MANAGER=>GET_EVENT_EX( REQUEST ).
IF EVENT_ID = CL_HTMLB_MANAGER=>EVENT_ID.
IF EVENT IS NOT INITIAL
AND EVENT->EVENT_NAME = HTMLB_EVENTS=>TABLEVIEW.
TABLE_EVENT ?= EVENT.
ENDIF.
ENDIF.
* Read tableview from manager.
DATA: TV TYPE REF TO CL_HTMLB_TABLEVIEW.
DATA: TV_DATA TYPE REF TO CL_HTMLB_EVENT_TABLEVIEW.
TV ?= CL_HTMLB_MANAGER=>GET_DATA( REQUEST = REQUEST
NAME = 'tableView'
ID = 'tv1' ).
TV_DATA = TV->DATA.
IF EVENT IS NOT INITIAL.
IDOFEVENT = EVENT->EVENT_ID.
ENDIF.
CASE IDOFEVENT.
*--File Upload(On Screen)
WHEN 'submitButton'. "업로드 버튼을 눌렀을때
*--Casting
DATA ?= CL_HTMLB_MANAGER=>GET_DATA(
REQUEST = RUNTIME->SERVER->REQUEST
NAME = 'fileUpload'
ID = 'myFileUpload1'
). "파일주소 캐스팅
IF DATA IS NOT INITIAL.
CLEAR : WA_FILE_HEADER, WA_FILE_DETAIL.
*--Contents parts
FILE_CONTENT = DATA->FILE_CONTENT. "htmlb:FileUpload에서 읽은 파일을 따로 담는다.
*--Key Field
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
NR_RANGE_NR = '01'
OBJECT = 'ZFILEKEY'
IMPORTING
NUMBER = WA_FILE_HEADER-SNO.
*--File pass
CALL FUNCTION 'AIPC_CONVERT_TO_UPPERCASE'
EXPORTING
I_INPUT = DATA->FILE_NAME
IMPORTING
E_OUTPUT = WA_FILE_HEADER-FILENAME.
DO.
CLEAR : TEMP1, TEMP2.
SPLIT WA_FILE_HEADER-FILENAME AT '\' INTO TEMP1 TEMP2.
IF TEMP2 CA '\'.
WA_FILE_HEADER-FILENAME = TEMP2.
ELSE.
WA_FILE_HEADER-FILENAME = TEMP2.
EXIT.
ENDIF.
ENDDO.
SPLIT WA_FILE_HEADER-FILENAME AT '.' INTO TEMP1 TEMP2. "TEMP1:파일 이름 TEMP2:파일 타입
WA_FILE_HEADER-FILETYPE = TEMP2.
*--File Length
WA_FILE_HEADER-KEY_FIELD = IPF_KEY_FIELD.
WA_FILE_HEADER-LENGTH = DATA->FILE_LENGTH. "파일 사이즈 byte단위로 나타난다.
INSERT FILE_HEADER FROM WA_FILE_HEADER.
*--Screen View
CLEAR : TEMP_INT1, TEMP_INT2, TEMP_INT3.
DO.
IF FILE_CONTENT IS NOT INITIAL.
WA_FILE_DETAIL-KEY_FIELD = WA_FILE_HEADER-KEY_FIELD.
WA_FILE_DETAIL-SERNO = SY-INDEX.
TEMP_INT2 = WA_FILE_DETAIL-SERNO * 255.
IF TEMP_INT2 > WA_FILE_HEADER-LENGTH.
TEMP_INT2 = TEMP_INT1 * 255.
TEMP_INT3 = WA_FILE_HEADER-LENGTH - TEMP_INT2.
WA_FILE_DETAIL-CONTENT = FILE_CONTENT+TEMP_INT2(TEMP_INT3).
INSERT FILE_DETAIL FROM WA_FILE_DETAIL. "마지막 인서트부분
EXIT.
ELSE.
TEMP_INT2 = TEMP_INT1 * 255.
WA_FILE_DETAIL-CONTENT = FILE_CONTENT+TEMP_INT2(255).
INSERT FILE_DETAIL FROM WA_FILE_DETAIL. "255자리씩 짤라서 데이터를 채운다.
ENDIF.
TEMP_INT1 = TEMP_INT1 + 1.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
WHEN OTHERS.
*--File Download
IF IDOFEVENT+0(4) EQ 'LINK'.
TEMP_C = IDOFEVENT+4(10).
*--Contents Load
SELECT SINGLE *
INTO WA_FILE_HEADER
FROM FILE_HEADER
WHERE KEY_FIELD EQ IPF_KEY_FILED.
IF SY-SUBRC EQ 0.
SELECT *
INTO TABLE IT_FILE_DETAIL
FROM FILE_DETAIL
WHERE KEY_FIELD EQ IPF_KEY_FILED.
*--Sort
SORT IT_FILE_DETAIL BY KEY_FIELD.
CLEAR : FILE_CONTENT.
*--Contents collect
LOOP AT IT_FILE_DETAIL INTO WA_FILE_DETAIL.
CONCATENATE FILE_CONTENT WA_FILE_DETAIL-CONTENT INTO FILE_CONTENT
IN BYTE MODE.
ENDLOOP.
*--Save File Name
SPLIT WA_FILE_HEADER-FILENAME AT '.' INTO TEMP1 TEMP2.
CASE TEMP2.
WHEN 'ZIP'.
CONTENT_TYPE = 'application/x-zip-compressed'.
WHEN 'DOC'.
CONTENT_TYPE = 'application/msword'.
WHEN 'TXT'.
CONTENT_TYPE = 'text/plain'.
WHEN 'PPT' OR 'PPS'.
CONTENT_TYPE = 'application/vnd.ms-powerpoint'.
WHEN 'XLS' OR 'EXE'.
CONTENT_TYPE = 'application/octet-stream'.
WHEN 'GIF'.
CONTENT_TYPE = 'image/gif'.
WHEN 'JPG' OR 'JPEG'.
CONTENT_TYPE = 'image/pjpeg'.
WHEN 'HTM' OR 'HTML'.
CONTENT_TYPE = 'text/html'.
ENDCASE.
*set response data to be the file content
RUNTIME->SERVER->RESPONSE->SET_DATA( FILE_CONTENT ).
RUNTIME->SERVER->RESPONSE->SET_HEADER_FIELD(
NAME = 'Content-Type'
VALUE = CONTENT_TYPE ).
CONCATENATE 'attachment; filename=' WA_FILE_HEADER-FILENAME INTO CONTENT_DISPOSITION.
RUNTIME->SERVER->RESPONSE->SET_HEADER_FIELD(
NAME = 'Content-Disposition'
VALUE = CONTENT_DISPOSITION ).
*set the file size in the response
CONTENT_LENGTH = XSTRLEN( FILE_CONTENT ).
RUNTIME->SERVER->RESPONSE->SET_HEADER_FIELD(
NAME = 'Content-Length'
VALUE = CONTENT_LENGTH ).
RUNTIME->SERVER->RESPONSE->DELETE_HEADER_FIELD(
NAME = 'Cache-Control' ).
RUNTIME->SERVER->RESPONSE->DELETE_HEADER_FIELD(
NAME = 'Expires' ).
NAVIGATION->RESPONSE_COMPLETE( ).
ENDIF.
ENDIF.
IF IDOFEVENT+0(3) EQ 'DEL'.
TEMP_C = IDOFEVENT+3(10).
DELETE FROM FILE_HEADER WHERE KEY_FIELD EQ IPF_KEY_FIELD.
IF SY-SUBRC EQ 0.
DELETE FROM FILE_DETAIL WHERE KEY_FIELD EQ IPF_KEY_FIELD.
ENDIF.
ENDIF.
ENDCASE.
위와같이 적으시면 따른 파일 서버가 없어도 테이블에 데이터셋을 담아서 입출력 할수 있다.
테이블 중요필드의 구성은 다음과 같다.
FILE_HEADER
KEY_FIELD TYPE ANY
FILENAME TYPE CHAR 250
LENGTH TYPE INT4 10
FILETYPE TYPE CHAR 3
FILE_DETAIL
KEY_FIELD TYPE ANY
SERNO TYPE INT4 10
CONTENT TYPE RAW 255
'SAP > BSP' 카테고리의 다른 글
BSP - BSP Table & File Location (0) | 2008.02.25 |
---|---|
BSP - 화면 접기와 펼치기 (0) | 2008.02.25 |
BSP - BSP에서의 일반적인 팝업 띄우는 소스 (0) | 2008.02.25 |
BSP - 띄워지는 화면 최대화 (0) | 2008.02.25 |
BSP - BSP에서의 LONG TEXT 입출력.. (0) | 2008.02.25 |