目录
一、程序源代码
*&---------------------------------------------------------------------*
*& Report ZFIU025
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZFIU029.
TABLES: SSCRFIELDS.
SELECTION-SCREEN FUNCTION KEY 1.
TYPES: BEGIN OF TYP_UPLOAD,
AGR_NAME TYPE STR_AGRS-AGR_NAME,"角色
ZSEL TYPE CHAR1,
ICON TYPE ICON-NAME,
ZTYPE TYPE C,
ZMESSAGE TYPE CHAR255,
END OF TYP_UPLOAD.
DATA: WA_UPLOAD TYPE TYP_UPLOAD,
IT_UPLOAD LIKE STANDARD TABLE OF WA_UPLOAD.
DATA: L_AGR_NAME TYPE STR_AGRS-AGR_NAME.
DATA: L_CHECK TYPE C.
DATA: G_DO TYPE C.
DATA: IS_LAYOUT TYPE SLIS_LAYOUT_ALV, "ALV输出样式
IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, "ALV输出的头项目(内表)
WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV, "ALV输出的头项目(工作区)
WA_REPID LIKE SY-REPID."程序名
PARAMETERS: P_FILE TYPE RLGRAP-FILENAME OBLIGATORY.
INITIALIZATION.
PERFORM FRM_INIT.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
PERFORM FRM_FILE_F4.
AT SELECTION-SCREEN.
CASE SY-UCOMM.
WHEN 'FC01'.
PERFORM FRM_DOWNLOAD_TEM_XLS.
ENDCASE.
START-OF-SELECTION.
PERFORM FRM_GET_DATA.
END-OF-SELECTION.
PERFORM FRM_SHOW_DATA.
*&---------------------------------------------------------------------*
*& Form FRM_INIT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_INIT .
SSCRFIELDS-FUNCTXT_01 = '下载上载模板'.
ENDFORM. " FRM_INIT
*&---------------------------------------------------------------------*
*& Form FRM_FILE_F4
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_FILE_F4 .
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
MASK = ' Excel(*.xls)|*.xls|Excel(*.xlsx)|*.xlsx|全部文件 (*.*)|*.*|'
TITLE = '选择文件'
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 E015(ZMM) WITH '选择文件出错!'.
ENDIF.
ENDFORM. " FRM_FILE_F4
*&---------------------------------------------------------------------*
*& Form FRM_DOWNLOAD_TEM_XLS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_DOWNLOAD_TEM_XLS .
DATA: FILENAME TYPE STRING VALUE 'ZFIU029.xls',
PATH TYPE STRING VALUE 'C:\',
FULLPATH TYPE STRING VALUE 'C:\ZFIU029.xls'.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
EXPORTING
* WINDOW_TITLE =
* DEFAULT_EXTENSION =
DEFAULT_FILE_NAME = FILENAME
* WITH_ENCODING =
FILE_FILTER = 'Excel(*.xls)|*.xls|Excel(*.xlsx)|*.xlsx|全部文件 (*.*)|*.*|'
INITIAL_DIRECTORY = PATH
* PROMPT_ON_OVERWRITE = 'X'
CHANGING
FILENAME = FILENAME
PATH = PATH
FULLPATH = FULLPATH
* USER_ACTION =
* FILE_ENCODING =
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
IF FULLPATH IS INITIAL.
ELSE.
PERFORM DOWNLOAD_EXCEL_FROMSERVER USING FULLPATH.
P_FILE = FULLPATH.
"MESSAGE '模板导出成功' TYPE 'S'.
ENDIF.
ENDIF.
ENDFORM. " FRM_DOWNLOAD_TEM_XLS
*&---------------------------------------------------------------------*
*& Form DOWNLOAD_EXCEL_FROMSERVER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_FULLPATH text
*----------------------------------------------------------------------*
FORM DOWNLOAD_EXCEL_FROMSERVER USING P_DEST.
DATA: LO_OBJDATA LIKE WWWDATATAB,
LS_DESTINATION LIKE RLGRAP-FILENAME.
LS_DESTINATION = P_DEST.
LO_OBJDATA-RELID = 'MI'.
LO_OBJDATA-OBJID = 'ZFIU029'.
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
EXPORTING
KEY = LO_OBJDATA
DESTINATION = LS_DESTINATION
* IMPORTING
* RC =
* CHANGING
* TEMP =
.
ENDFORM. " DOWNLOAD_EXCEL_FROMSERVER
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_GET_DATA .
PERFORM FRM_UPLOAD_FILE_XLS.
PERFORM FRM_CHECK_DATA.
ENDFORM. " FRM_GET_DATA
*&---------------------------------------------------------------------*
*& Form FRM_UPLOAD_FILE_XLS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_UPLOAD_FILE_XLS .
DATA: IT_RAW TYPE TRUXS_T_TEXT_DATA.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
I_LINE_HEADER = 'X'
I_TAB_RAW_DATA = IT_RAW " WORK TABLE
I_FILENAME = P_FILE
TABLES
I_TAB_CONVERTED_DATA = IT_UPLOAD "ACTUAL DATA
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2.
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 IT_UPLOAD IS INITIAL.
MESSAGE '上载文档空请检查' TYPE 'S' DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ELSE.
*************设置标识的初始状态
LOOP AT IT_UPLOAD INTO WA_UPLOAD.
WA_UPLOAD-ICON = ICON_YELLOW_LIGHT.
WA_UPLOAD-ZMESSAGE = ''.
MODIFY IT_UPLOAD FROM WA_UPLOAD TRANSPORTING ICON ZMESSAGE.
ENDLOOP.
ENDIF.
ENDFORM. " FRM_UPLOAD_FILE_XLS
*&---------------------------------------------------------------------*
*& Form FRM_CHECK_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_CHECK_DATA .
L_CHECK = 'S'.
LOOP AT IT_UPLOAD INTO WA_UPLOAD.
SELECT SINGLE AGR_NAME
FROM AGR_DEFINE
INTO L_AGR_NAME
WHERE AGR_NAME EQ WA_UPLOAD-AGR_NAME.
IF SY-SUBRC <> 0.
L_CHECK = 'E'.
WA_UPLOAD-ICON = ICON_RED_LIGHT.
WA_UPLOAD-ZTYPE = 'E'.
WA_UPLOAD-ZMESSAGE = '角色不存在'.
MODIFY IT_UPLOAD FROM WA_UPLOAD TRANSPORTING ICON ZTYPE ZMESSAGE.
CONTINUE.
ENDIF.
WA_UPLOAD-ICON = ICON_YELLOW_LIGHT.
WA_UPLOAD-ZTYPE = 'W'.
WA_UPLOAD-ZMESSAGE = '检查通过'.
MODIFY IT_UPLOAD FROM WA_UPLOAD TRANSPORTING ICON ZTYPE ZMESSAGE.
ENDLOOP.
ENDFORM. " FRM_CHECK_DATA
*&---------------------------------------------------------------------*
*& Form FRM_SHOW_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_SHOW_DATA .
WA_REPID = SY-REPID. "得到程序名
IS_LAYOUT-ZEBRA = 'X'. "颜色相间显示
IS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'. "优化列宽选项
IS_LAYOUT-BOX_FIELDNAME = 'ZSEL'. "优化列宽选项
DATA: DE_POS TYPE I.
DE_POS = DE_POS + 1.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-COL_POS = DE_POS.
* WA_FIELDCAT-KEY = 'X'.
WA_FIELDCAT-FIELDNAME = 'ICON'.
WA_FIELDCAT-ICON = 'X'.
WA_FIELDCAT-SELTEXT_L = ''.
WA_FIELDCAT-SELTEXT_M = ''.
WA_FIELDCAT-SELTEXT_S = ''.
WA_FIELDCAT-DDICTXT = 'L'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
DE_POS = DE_POS + 1.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-COL_POS = DE_POS.
* WA_FIELDCAT-KEY = 'X'.
WA_FIELDCAT-FIELDNAME = 'AGR_NAME'.
WA_FIELDCAT-REF_TABNAME = 'STR_AGRS'.
WA_FIELDCAT-REF_FIELDNAME = 'AGR_NAME'.
WA_FIELDCAT-SELTEXT_L = '角色'.
WA_FIELDCAT-SELTEXT_M = '角色'.
WA_FIELDCAT-SELTEXT_S = '角色'.
WA_FIELDCAT-DDICTXT = 'L'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
DE_POS = DE_POS + 1.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-COL_POS = DE_POS.
* WA_FIELDCAT-KEY = 'X'.
WA_FIELDCAT-FIELDNAME = 'ZMESSAGE'.
WA_FIELDCAT-SELTEXT_L = '消息'.
WA_FIELDCAT-SELTEXT_M = '消息'.
WA_FIELDCAT-SELTEXT_S = '消息'.
WA_FIELDCAT-DDICTXT = 'L'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = WA_REPID
I_CALLBACK_PF_STATUS_SET = 'SET_STATUS'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
IS_LAYOUT = IS_LAYOUT
IT_FIELDCAT = IT_FIELDCAT
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
I_SAVE = 'A'
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = IT_UPLOAD
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " FRM_SHOW_DATA
*&---------------------------------------------------------------------*
*& FORM SET_STATUS
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* -->RT_EXTAB TEXT
*----------------------------------------------------------------------*
FORM SET_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.
SET PF-STATUS 'ZFIU025' EXCLUDING RT_EXTAB.
ENDFORM. "SET_STATUS
*&---------------------------------------------------------------------*
*& FORM USER_COMMAND
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* -->RF_UCOMM TEXT
* -->RS_SELFIELD TEXT
*----------------------------------------------------------------------*
FORM USER_COMMAND USING RF_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
CASE RF_UCOMM.
WHEN 'ZDO'.
IF L_CHECK = 'E'.
MESSAGE '上载数据有错,不能保存' TYPE 'E'.
ENDIF.
IF G_DO = 'X'.
MESSAGE '修改操作已执行' TYPE 'E'.
ENDIF.
G_DO = 'X'.
PERFORM FRM_GO..
ENDCASE.
*如果前面把内表的数据修改了,通过这个就会自到更新数据
RS_SELFIELD-REFRESH = 'X'.
ENDFORM. "USER_COMMAND
*&---------------------------------------------------------------------*
*& Form FRM_GO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_GO .
DATA: L_ZTYPE TYPE C.
DATA: L_ZMESSAGE TYPE CHAR255.
DATA: AGR_ROLENAME TYPE AGR_DEFINE-AGR_NAME." 角色
DATA: WA_ROLESON TYPE AGR_TXT,
IT_ROLESON LIKE STANDARD TABLE OF WA_ROLESON.
DATA: WA_RETURN TYPE BAPIRET2,
IT_RETURN LIKE STANDARD TABLE OF WA_RETURN.
LOOP AT IT_UPLOAD INTO WA_UPLOAD.
CLEAR: L_ZTYPE,
L_ZMESSAGE.
CLEAR: WA_ROLESON,
IT_ROLESON,
IT_RETURN,
WA_RETURN.
AGR_ROLENAME = WA_UPLOAD-AGR_NAME.
CALL FUNCTION 'PRGN_AUTO_GENERATE_PROFILE_NEW'
EXPORTING
ACTIVITY_GROUP = AGR_ROLENAME
* PROFILE_NAME =
* PROFILE_TEXT =
NO_DIALOG = 'X'
* REBUILD_AUTH_DATA = 'X'
* ORG_LEVELS_WITH_STAR = ' '
* FILL_EMPTY_FIELDS_WITH_STAR = 'X'
* TEMPLATE = ' '
* CHECK_PROFGEN_TABLES = 'X'
* GENERATE_PROFILE = 'X'
* AUTHORITY_CHECK_PFCG = 'X'
EXCEPTIONS
ACTIVITY_GROUP_DOES_NOT_EXIST = 1
ACTIVITY_GROUP_ENQUEUED = 2
PROFILE_NAME_EXISTS = 3
PROFILE_NOT_IN_NAMESPACE = 4
NO_AUTH_FOR_PROF_CREATION = 5
NO_AUTH_FOR_ROLE_CHANGE = 6
NO_AUTH_FOR_AUTH_MAINT = 7
NO_AUTH_FOR_GEN = 8
NO_AUTHS = 9
OPEN_AUTHS = 10
TOO_MANY_AUTHS = 11
PROFGEN_TABLES_NOT_UPDATED = 12
ERROR_WHEN_GENERATING_PROFILE = 13
OTHERS = 14.
IF SY-SUBRC <> 0.
L_ZTYPE = 'E'.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4
INTO L_ZMESSAGE.
CONCATENATE '失败:'
L_ZMESSAGE
INTO
L_ZMESSAGE.
ROLLBACK WORK.
ELSE.
LOOP AT IT_RETURN INTO WA_RETURN WHERE TYPE = 'E'
OR TYPE = 'A'.
ENDLOOP.
IF SY-SUBRC = 0.
CONCATENATE '失败:'
WA_RETURN-MESSAGE
INTO
L_ZMESSAGE.
ROLLBACK WORK.
ELSE.
L_ZTYPE = 'S'.
L_ZMESSAGE = '成功'.
COMMIT WORK AND WAIT.
ENDIF.
ENDIF.
CASE L_ZTYPE.
WHEN 'S'.
WA_UPLOAD-ICON = ICON_GREEN_LIGHT.
WHEN 'E'.
WA_UPLOAD-ICON = ICON_RED_LIGHT.
ENDCASE.
WA_UPLOAD-ZTYPE = L_ZTYPE.
WA_UPLOAD-ZMESSAGE = L_ZMESSAGE.
MODIFY IT_UPLOAD FROM WA_UPLOAD TRANSPORTING ICON ZTYPE ZMESSAGE.
ENDLOOP.
ENDFORM. " FRM_GO
二、数据模版
角色 |
ZTEST_012 |