*&---------------------------------------------------------------------*
*& Report ZR_SAL016
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZR_SAL016.
TYPE-POOLS: SLIS.
TYPE-POOLS: VRM.
DATA LV_TABLENAME TYPE DD02L-TABNAME.
FIELD-SYMBOLS : TYPE ANY TABLE,
TYPE ANY,
TYPE ANY.
SELECTION-SCREEN BEGIN OF BLOCK SO_DOCUMENT WITH FRAME TITLE IIT.
PARAMETERS:
P_TABLE LIKE LV_TABLENAME OBLIGATORY,
P_FILE LIKE RLGRAP-FILENAME OBLIGATORY.
SELECTION-SCREEN END OF BLOCK SO_DOCUMENT.
INITIALIZATION.
IIT = '动态更新表数据'.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
PERFORM SELECT_FILE.
START-OF-SELECTION.
IF SY-UNAME <> 'IBM_02'.
MESSAGE '禁止使用更新数据库表操作!' TYPE 'E'.
EXIT.
ENDIF.
PERFORM LOAD_DATA.
PERFORM PRINT_OUT.
*&---------------------------------------------------------------------*
*& Form select_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM SELECT_FILE .
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
MASK = ',Excel Files,*.xls,*.xlsx,All Files,*.*.'(101)
TITLE = '选择文件'(100)
IMPORTING
FILENAME = P_FILE
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.
IF SY-SUBRC <> 0 AND SY-SUBRC <> 3.
* MESSAGE e100(zdev) WITH '#######'(007).
ENDIF.
ENDFORM. " SELECT_FILE
*&---------------------------------------------------------------------*
*& Form LOAD_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM LOAD_DATA.
DATA: TAB_ZYFYB TYPE ZSSAL003 OCCURS 0 WITH HEADER LINE.
DATA: TAB_HEAD TYPE ZSSAL003 OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'ZALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = P_FILE
I_BEGIN_COL = '1'
I_BEGIN_ROW = '1'
I_END_COL = '25'
I_END_ROW = '50000'
TABLES
INTERN = TAB_ZYFYB
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC <> 0 .
EXIT.
ENDIF.
DATA: IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
IS_FCAT LIKE LINE OF IT_FCAT.
DATA: IT_FIELDCAT TYPE LVC_T_FCAT,
IS_FIELDCAT LIKE LINE OF IT_FIELDCAT.
DATA : LS_TABLE TYPE REF TO DATA ,
LT_TABLE TYPE REF TO DATA .
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = P_TABLE
CHANGING
CT_FIELDCAT = IT_FCAT[]
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
LOOP AT IT_FCAT INTO IS_FCAT .
MOVE-CORRESPONDING IS_FCAT TO IS_FIELDCAT.
IS_FIELDCAT-FIELDNAME = IS_FCAT-FIELDNAME.
IS_FIELDCAT-REF_FIELD = IS_FCAT-FIELDNAME.
IS_FIELDCAT-REF_TABLE = IS_FCAT-REF_TABNAME.
APPEND IS_FIELDCAT TO IT_FIELDCAT.
ENDLOOP.
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_FIELDCAT
IMPORTING
EP_TABLE = LT_TABLE.
ASSIGN LT_TABLE->* TO .
CREATE DATA LS_TABLE LIKE LINE OF .
ASSIGN LS_TABLE->* TO .
LOOP AT TAB_ZYFYB.
IF TAB_ZYFYB-ROW = 1.
APPEND TAB_ZYFYB TO TAB_HEAD.
CONTINUE.
ENDIF.
READ TABLE TAB_HEAD WITH KEY COL = TAB_ZYFYB-COL.
IF SY-SUBRC <> 0.
CONTINUE.
ENDIF.
TRANSLATE TAB_HEAD-VALUE TO UPPER CASE.
ASSIGN COMPONENT TAB_HEAD-VALUE OF STRUCTURE TO .
IF SY-SUBRC <> 0.
CONTINUE.
ENDIF.
= TAB_ZYFYB-VALUE.
AT END OF ROW.
MODIFY (P_TABLE) FROM .
INSERT INTO TABLE .
CLEAR .
ENDAT.
ENDLOOP.
DATA LV_LENGHT TYPE I.
LOOP AT TAB_HEAD .
WRITE : TAB_HEAD-VALUE(11) RIGHT-JUSTIFIED.
ENDLOOP.
ENDFORM. "LOAD_DATA
*&---------------------------------------------------------------------*
*& Form print_out
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM PRINT_OUT.
LOOP AT INTO .
WRITE /.
DO .
ASSIGN COMPONENT SY-INDEX OF STRUCTURE TO .
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
WRITE : .
ENDDO.
ENDLOOP.
ENDFORM. " PRINT_OUT
阅读(984) | 评论(0) | 转发(0) |