标签:
写了一个alv,其中一个字段是长文本,点进去这个字段是长文本界面,输入长文本后保存可将输入内容保存在数据库表中。
用来保存长文本的自建表结构:
数据:
选择屏幕(数据都是随便找的):
alv界面(屏幕9000):
点击longtext图标进入的长文本界面(屏幕9001):
主程序代码:
REPORT YLONGTEXT NO STANDARD PAGE HEADING. *********************************************************************** *** INCLUDE *********************************************************************** INCLUDE YLONGTEXTTOP. INCLUDE YLONGTEXTC01. INCLUDE YLONGTEXTC02. INCLUDE YLONGTEXTO01. INCLUDE YLONGTEXTI01. INCLUDE YLONGTEXTF01. INCLUDE YLONGTEXTF02. *********************************************************************** *** START-OF-SELECTION *********************************************************************** START-OF-SELECTION. PERFORM F_MAIN_PROC. *********************************************************************** *** END-OF-SELECTION *********************************************************************** END-OF-SELECTION. PERFORM F_OUTPUT_PROC.
INCLUDE YLONGTEXTTOP:
*********************************************************************** * TABLES & INCLUDE ************************************************************************ TYPE-POOLS : SLIS,ICON. INCLUDE <ICON>. TABLES :BKPF. ************************************************************************ * The Declaration of CLASS ************************************************************************ CLASS : LCL_ALV_GRID DEFINITION DEFERRED. CLASS : LCL_EVENT_RECEIVER DEFINITION DEFERRED. ************************************************************************ * CONSTANTS * ************************************************************************ CONSTANTS : GC_A(1) TYPE C VALUE ‘A‘, GC_C(1) TYPE C VALUE ‘C‘, GC_D(1) TYPE C VALUE ‘D‘, GC_L(1) TYPE C VALUE ‘L‘, GC_R(1) TYPE C VALUE ‘R‘, GC_X(1) TYPE C VALUE ‘X‘, GC_SPACE(1) TYPE C VALUE ‘ ‘. ************************************************************************ * GLOBAL VARIABLE * ************************************************************************ DATA : GV_GTITLE TYPE LVC_TITLE, "GRID TITLE TEXT GV_SAVE(1), GV_REPID TYPE SY-REPID, GV_LINE TYPE I, GV_COLPOS TYPE I VALUE 2, GV_OKCODE LIKE SY-UCOMM, GV_SAVEOK LIKE SY-UCOMM. DATA : GV_UCOMM LIKE SY-UCOMM. ************************************************************************ *** ALV OBJECT ************************************************************************ DATA : GO_ALV_GRID1 TYPE REF TO LCL_ALV_GRID, GO_DOCKING1 TYPE REF TO CL_GUI_DOCKING_CONTAINER, GO_DOCKING2 TYPE REF TO CL_GUI_DOCKING_CONTAINER, GO_EVENT1 TYPE REF TO LCL_EVENT_RECEIVER, GO_TXTEDITOR TYPE REF TO CL_GUI_TEXTEDIT. ************************************************************************ *** ALV STRUCTURE ************************************************************************ DATA : GS_FIELDCAT TYPE LVC_S_FCAT, GS_LAYOUT1 TYPE LVC_S_LAYO, "ALV Layout GS_VARIANT TYPE DISVARIANT, "Variant GS_EXCLUDE TYPE UI_FUNC. ************************************************************************ *** ALV INTERNAL TABLE ************************************************************************ DATA : GT_FIELDCAT1 TYPE LVC_T_FCAT, "ALV Field catalog GT_EXCLUDE TYPE UI_FUNCTIONS. ************************************************************************ * INTERNAL TABLE * ************************************************************************ DATA : BEGIN OF GT_MAIN OCCURS 0, BUKRS LIKE BSEG-BUKRS, BELNR LIKE BSEG-BELNR, BUZEI LIKE BSEG-BUZEI, GJAHR LIKE BSEG-GJAHR, TICON LIKE ICON-ID, LTEXT TYPE STRING, ERNAM TYPE YTESTTAB-ERNAM, ERDAT TYPE YTESTTAB-ERDAT, ERZET TYPE YTESTTAB-ERZET, AENAM TYPE YTESTTAB-AENAM, AEDAT TYPE YTESTTAB-AEDAT, AEZET TYPE YTESTTAB-AEZET, END OF GT_MAIN. ************************************************************************ * SELECT OPTIONS * ************************************************************************ SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-B01. SELECTION-SCREEN BEGIN OF LINE. *-- company code SELECTION-SCREEN COMMENT 1(21) TEXT-C01 FOR FIELD P_BUKRS. PARAMETERS : P_BUKRS TYPE YTESTTAB-BUKRS OBLIGATORY DEFAULT ‘0654‘. SELECTION-SCREEN END OF LINE. SELECTION-SCREEN BEGIN OF LINE. *-- Accountig document SELECTION-SCREEN COMMENT 1(18) TEXT-C02 FOR FIELD S_BUDAT. SELECT-OPTIONS: S_BUDAT FOR BKPF-BUDAT DEFAULT ‘20140901‘. SELECTION-SCREEN END OF LINE. SELECTION-SCREEN END OF BLOCK B1. SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-B02. SELECTION-SCREEN BEGIN OF LINE. *-- Variant SELECTION-SCREEN COMMENT 1(21) TEXT-C03 FOR FIELD P_VARI. PARAMETERS : P_VARI LIKE DISVARIANT-VARIANT. SELECTION-SCREEN POSITION 27. SELECTION-SCREEN END OF LINE. SELECTION-SCREEN END OF BLOCK B2.
INCLUDE YLONGTEXTC01:
*---------------------------------------------------------------------* * CLASS LCL_ALV_GRID DEFINITION *----------------------------------------------------------------------* CLASS LCL_ALV_GRID DEFINITION INHERITING FROM CL_GUI_ALV_GRID. PUBLIC SECTION . METHODS: M_SET_FIXED_COLS "#EC CALLED IMPORTING IV_COLS TYPE I, M_OPTIMIZE_ALL_COLS, "#EC CALLED M_OPTIMIZE_COL_ID "#EC CALLED IMPORTING IO_COL_ID TYPE LVC_S_COL, M_SET_RESIZE_ROWS, "#EC CALLED M_SET_CURRENT_CELL_BASE "#EC CALLED IMPORTING IV_ROW TYPE I IV_COL TYPE I. ENDCLASS. "LCL_ALV_GRID DEFINITION *----------------------------------------------------------------------* * CLASS LCL_ALV_GRID IMPLEMENTATION *----------------------------------------------------------------------* CLASS LCL_ALV_GRID IMPLEMENTATION. METHOD M_SET_FIXED_COLS. *-- Sets Number of Fixed Columns CALL METHOD ME->SET_FIXED_COLS EXPORTING COLS = IV_COLS. ENDMETHOD. "M_SET_FIXED_COLS METHOD M_OPTIMIZE_ALL_COLS. *-- Optimizes the Column Width of all Columns CALL METHOD ME->OPTIMIZE_ALL_COLS EXPORTING INCLUDE_HEADER = 1. ENDMETHOD. "M_OPTIMIZE_ALL_COLS METHOD M_OPTIMIZE_COL_ID. *-- Optimizes the Column Width of the Column CALL METHOD ME->OPTIMIZE_COL_ID EXPORTING INCLUDE_HEADER = 1 COL_ID = IO_COL_ID. ENDMETHOD. "M_OPTIMIZE_COL_ID METHOD M_SET_RESIZE_ROWS. *-- Controls Row Height Modification CALL METHOD ME->SET_RESIZE_ROWS EXPORTING ENABLE = 1. ENDMETHOD. "M_SET_RESIZE_ROWS METHOD M_SET_CURRENT_CELL_BASE. *-- Sets Focus Cell CALL METHOD ME->SET_CURRENT_CELL_BASE EXPORTING ROW = IV_ROW COL = IV_COL. ENDMETHOD. "M_SET_CURRENT_CELL_BASE ENDCLASS. "LCL_ALV_GRID IMPLEMENTATION
INCLUDE YLONGTEXTC02:
*---------------------------------------------------------------------* * CLASS LCL_EVENT_RECEIVER DEFINITION *---------------------------------------------------------------------* CLASS LCL_EVENT_RECEIVER DEFINITION. PUBLIC SECTION. METHODS : HANDLE_HOTSPOT_CLICK FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID IMPORTING E_ROW_ID E_COLUMN_ID. ENDCLASS. "LCL_EVENT_RECEIVER DEFINITION *---------------------------------------------------------------------* * CLASS LCL_EVENT_RECEIVER IMPLEMENTATION *---------------------------------------------------------------------* CLASS LCL_EVENT_RECEIVER IMPLEMENTATION. METHOD HANDLE_HOTSPOT_CLICK. PERFORM HANDLE_HOTSPOT_CLICK USING E_ROW_ID E_COLUMN_ID. ENDMETHOD. "HANDLE_HOTSPOT_CLICK ENDCLASS. "LCL_EVENT_RECEIVER IMPLEMENTATION
INCLUDE YLONGTEXTO01:
*&---------------------------------------------------------------------* *& Include YLONGTEXTO01 *&---------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Module STATUS_9000 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE STATUS_9000 OUTPUT. SET PF-STATUS ‘9000‘. ENDMODULE. " STATUS_9000 OUTPUT *&---------------------------------------------------------------------* *& Module INITIALIZE_9000 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE INITIALIZE_9000 OUTPUT. IF GO_ALV_GRID1 IS INITIAL. PERFORM F_INIT_ALV_GRID_PROC. ELSE. PERFORM F_REFRESH_CONTAINER_PROC USING GV_COLPOS GS_LAYOUT1 CHANGING GO_ALV_GRID1. ENDIF. ENDMODULE. " INITIALIZE_9000 OUTPUT *&---------------------------------------------------------------------* *& Module STATUS_9001 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE STATUS_9001 OUTPUT. SET PF-STATUS ‘9001‘. ENDMODULE. " STATUS_9001 OUTPUT *&---------------------------------------------------------------------* *& Module INITIALIZATION_9001 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE INITIALIZATION_9001 OUTPUT. IF GO_TXTEDITOR IS INITIAL. "CREATE another DOCKING CREATE OBJECT GO_DOCKING2 EXPORTING REPID = SY-REPID DYNNR = SY-DYNNR SIDE = CL_GUI_DOCKING_CONTAINER=>DOCK_AT_TOP EXTENSION = 1500. "CREATE EDITOR CREATE OBJECT GO_TXTEDITOR EXPORTING PARENT = GO_DOCKING2. ENDIF. CALL METHOD GO_TXTEDITOR->SET_TEXTSTREAM EXPORTING TEXT = GT_MAIN-LTEXT. ENDMODULE. " INITIALIZATION_9001 OUTPUT
INCLUDE YLONGTEXTI01:
*&---------------------------------------------------------------------* *& Include YLONGTEXTI01 *&---------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Module USER_COMMAND_9000 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE USER_COMMAND_9000 INPUT. CLEAR : GV_SAVEOK. GV_SAVEOK = GV_OKCODE. CLEAR : GV_OKCODE. CASE GV_SAVEOK. WHEN ‘BACK‘ OR ‘CANC‘. * IF GO_ALV_GRID1 IS NOT INITIAL. * CALL METHOD GO_ALV_GRID1->FREE. * CLEAR GO_ALV_GRID1. * ENDIF. LEAVE TO SCREEN 0. ENDCASE. ENDMODULE. " USER_COMMAND_9000 INPUT *&---------------------------------------------------------------------* *& Module USER_COMMAND_9001 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE USER_COMMAND_9001 INPUT. CLEAR : GV_SAVEOK. GV_SAVEOK = GV_OKCODE. CLEAR : GV_OKCODE. CASE GV_SAVEOK. WHEN ‘BACK‘ OR ‘CANC‘. LEAVE TO SCREEN 0. WHEN ‘EXIT‘. LEAVE PROGRAM. WHEN ‘SAVE‘. PERFORM F_9001SAVE. ENDCASE. ENDMODULE. " USER_COMMAND_9001 INPUT
INCLUDE YLONGTEXTF01:
*&---------------------------------------------------------------------* *& Include YLONGTEXTF01 *&---------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Form F_MAIN_PROC *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM F_MAIN_PROC . DATA : BEGIN OF LT_BKPF OCCURS 0, BUKRS TYPE YTESTTAB-BUKRS, BELNR TYPE YTESTTAB-BELNR, GJAHR TYPE YTESTTAB-GJAHR, BUDAT TYPE BKPF-BUDAT, END OF LT_BKPF. DATA LT_YTAB TYPE TABLE OF YTESTTAB WITH HEADER LINE . SELECT BUKRS BELNR GJAHR INTO CORRESPONDING FIELDS OF TABLE LT_BKPF FROM BKPF WHERE BUKRS EQ P_BUKRS AND BUDAT IN S_BUDAT. SORT LT_BKPF BY BUKRS BELNR GJAHR. DELETE ADJACENT DUPLICATES FROM LT_BKPF COMPARING BUKRS BELNR GJAHR. CHECK LT_BKPF[] IS NOT INITIAL . SELECT BUKRS BELNR GJAHR BUZEI INTO CORRESPONDING FIELDS OF TABLE GT_MAIN FROM BSEG FOR ALL ENTRIES IN LT_BKPF WHERE BUKRS = LT_BKPF-BUKRS AND BELNR = LT_BKPF-BELNR AND GJAHR = LT_BKPF-GJAHR. CHECK GT_MAIN[] IS NOT INITIAL. SELECT BUKRS BELNR GJAHR BUZEI LTEXT INTO CORRESPONDING FIELDS OF TABLE LT_YTAB FROM YTESTTAB FOR ALL ENTRIES IN LT_BKPF WHERE BUKRS = LT_BKPF-BUKRS AND BELNR = LT_BKPF-BELNR AND GJAHR = LT_BKPF-GJAHR. SORT LT_YTAB BY BUKRS BELNR GJAHR BUZEI. DELETE ADJACENT DUPLICATES FROM LT_YTAB COMPARING BUKRS BELNR GJAHR BUZEI. LOOP AT GT_MAIN. IF LT_YTAB[] IS NOT INITIAL. READ TABLE LT_YTAB WITH KEY BUKRS = GT_MAIN-BUKRS BELNR = GT_MAIN-BELNR GJAHR = GT_MAIN-GJAHR BUZEI = GT_MAIN-BUZEI. IF SY-SUBRC EQ 0. GT_MAIN-LTEXT = LT_YTAB-LTEXT. ENDIF. ENDIF. IF GT_MAIN-TICON IS INITIAL. GT_MAIN-TICON = ICON_CREATE_TEXT. ENDIF. MODIFY GT_MAIN TRANSPORTING TICON LTEXT. ENDLOOP. ENDFORM. " F_MAIN_PROC *&---------------------------------------------------------------------* *& Form F_OUTPUT_PROC *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM F_OUTPUT_PROC . CHECK SY-BATCH IS INITIAL. IF GT_MAIN[] IS INITIAL. MESSAGE ‘Data not found.‘ TYPE ‘S‘ DISPLAY LIKE ‘E‘. ELSE. CALL SCREEN 9000. ENDIF. ENDFORM. " F_OUTPUT_PROC *&---------------------------------------------------------------------* *& Form HANDLE_HOTSPOT_CLICK *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_E_ROW_ID text * -->P_E_COLUMN_ID text *----------------------------------------------------------------------* FORM HANDLE_HOTSPOT_CLICK USING P_ROW_ID TYPE LVC_S_ROW P_COLUMN_ID TYPE LVC_S_COL. CASE P_COLUMN_ID-FIELDNAME . WHEN ‘TICON‘. GV_LINE = P_ROW_ID-INDEX. READ TABLE GT_MAIN INDEX P_ROW_ID-INDEX. CALL SCREEN 9001. ENDCASE. ENDFORM. " HANDLE_HOTSPOT_CLICK *&---------------------------------------------------------------------* *& Form F_9001SAVE *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM F_9001SAVE . DATA: BEGIN OF LT_TAB OCCURS 0, CONT(2014) TYPE C, END OF LT_TAB. DATA LV_STR TYPE STRING. DATA LT_UPDAT TYPE TABLE OF YTESTTAB WITH HEADER LINE. CALL METHOD GO_TXTEDITOR->GET_TEXT_AS_R3TABLE IMPORTING TABLE = LT_TAB[] EXCEPTIONS ERROR_DP = 1 ERROR_CNTL_CALL_METHOD = 2 ERROR_DP_CREATE = 3 POTENTIAL_DATA_LOSS = 4 OTHERS = 5. LOOP AT LT_TAB. CONCATENATE LV_STR LT_TAB-CONT CL_ABAP_CHAR_UTILITIES=>CR_LF INTO LV_STR. CLEAR LT_TAB. ENDLOOP. GT_MAIN-LTEXT = LV_STR. GT_MAIN-ERNAM = SY-UNAME. GT_MAIN-ERDAT = SY-DATUM. GT_MAIN-ERZET = SY-UZEIT. GT_MAIN-AENAM = SY-UNAME. GT_MAIN-AEDAT = SY-DATUM. GT_MAIN-AEZET = SY-UZEIT. MODIFY GT_MAIN INDEX GV_LINE TRANSPORTING ERNAM ERDAT ERZET AENAM AEDAT AEZET LTEXT. MOVE-CORRESPONDING GT_MAIN TO LT_UPDAT. LT_UPDAT-BUDAT = S_BUDAT-LOW. APPEND LT_UPDAT. MODIFY YTESTTAB FROM TABLE LT_UPDAT. IF SY-SUBRC EQ 0. COMMIT WORK . MESSAGE ‘Save Data Successful ! ‘ TYPE ‘S‘. ELSE. ROLLBACK WORK. MESSAGE ‘Save Data Failed ! ‘ TYPE ‘S‘ DISPLAY LIKE ‘E‘. ENDIF. ENDFORM. " F_9001SAVE
INCLUDE YLONGTEXTF02:
*&---------------------------------------------------------------------* *& Include YLONGTEXTF02 *&---------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Form F_REFRESH_CONTAINER_PROC *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_GC_COLS_INT1 text * -->P_GS_LAYOUT1 text * <--P_GO_ALV_GRID1 text *----------------------------------------------------------------------* FORM F_REFRESH_CONTAINER_PROC USING PV_COL TYPE I PS_LAYOUT TYPE LVC_S_LAYO CHANGING PO_ALV_GRID TYPE REF TO LCL_ALV_GRID. PERFORM F_REFRESH_GRID_CBO_PROC USING PS_LAYOUT CHANGING PO_ALV_GRID. PERFORM F_BASIC_GRID_PROC USING PV_COL CHANGING PO_ALV_GRID. CALL METHOD CL_GUI_CFW=>FLUSH. ENDFORM. " F_REFRESH_CONTAINER_PROC *&---------------------------------------------------------------------* *& Form F_REFRESH_GRID_CBO_PROC *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_PS_LAYOUT text * <--P_PO_ALV_GRID text *----------------------------------------------------------------------* FORM F_REFRESH_GRID_CBO_PROC USING PS_LAYOUT TYPE LVC_S_LAYO CHANGING PO_ALV_GRID TYPE REF TO LCL_ALV_GRID. DATA : LS_STABLE TYPE LVC_S_STBL, LS_S_COL TYPE LVC_S_COL. CLEAR : LS_STABLE. LS_STABLE-ROW = GC_X. LS_STABLE-COL = GC_X. CALL METHOD PO_ALV_GRID->SET_FRONTEND_LAYOUT EXPORTING IS_LAYOUT = PS_LAYOUT. CALL METHOD PO_ALV_GRID->REFRESH_TABLE_DISPLAY EXPORTING I_SOFT_REFRESH = ‘ ‘ IS_STABLE = LS_STABLE. ENDFORM. " F_BASIC_GRID_PROC *&---------------------------------------------------------------------* *& Form F_INIT_ALV_GRID_PROC *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM F_INIT_ALV_GRID_PROC . *>> Docking Custom container CREATE OBJECT GO_DOCKING1 EXPORTING REPID = GV_REPID DYNNR = SY-DYNNR SIDE = CL_GUI_DOCKING_CONTAINER=>DOCK_AT_TOP EXTENSION = 500 EXCEPTIONS CNTL_ERROR = 1 CNTL_SYSTEM_ERROR = 2 CREATE_ERROR = 3 LIFETIME_ERROR = 4 LIFETIME_DYNPRO_DYNPRO_LINK = 5 OTHERS = 6. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. *-- Docking Grid CREATE OBJECT GO_ALV_GRID1 EXPORTING I_PARENT = GO_DOCKING1 EXCEPTIONS ERROR_CNTL_CREATE = 1 ERROR_CNTL_INIT = 2 ERROR_CNTL_LINK = 3 ERROR_DP_CREATE = 4 OTHERS = 5. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. PERFORM F_BUILD_LAYOUT_PROC USING GC_D ‘‘ ‘‘ GC_X GC_X GV_GTITLE ‘ ‘ CHANGING GS_LAYOUT1. PERFORM F_EXCLUDE_FUNCTIONS_PROC. PERFORM F_EVENT_HANDLER_PROC CHANGING GO_EVENT1 GO_ALV_GRID1. PERFORM F_BUILD_FIELDCATALOG_PROC USING ‘GT_MAIN‘ CHANGING GT_FIELDCAT1. PERFORM F_CALL_ALV_LIST_PROC USING ‘GT_MAIN‘ GS_LAYOUT1 CHANGING GT_FIELDCAT1 GO_ALV_GRID1. PERFORM F_BASIC_GRID_PROC USING GV_COLPOS CHANGING GO_ALV_GRID1. ENDFORM. " F_INIT_ALV_GRID_PROC *&---------------------------------------------------------------------* *& Form F_BUILD_LAYOUT_PROC *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_GC_D text * -->P_0222 text * -->P_0223 text * -->P_GC_X text * -->P_GC_X text * -->P_GV_GTITLE text * -->P_0227 text * <--P_GS_LAYOUT1 text *----------------------------------------------------------------------* FORM F_BUILD_LAYOUT_PROC USING PV_SEL_MODE TYPE ANY PV_NO_ROWMARK TYPE ANY PV_NO_ROWINS TYPE ANY PV_CWIDTH_OPT TYPE ANY PV_ZEBRA TYPE ANY PV_GRID_TITLE TYPE ANY PV_CTAB_FNAME TYPE ANY CHANGING PS_LAYOUT TYPE LVC_S_LAYO. CLEAR PS_LAYOUT. PS_LAYOUT-SEL_MODE = PV_SEL_MODE. PS_LAYOUT-NO_ROWMARK = PV_NO_ROWMARK. PS_LAYOUT-NO_ROWINS = PV_NO_ROWINS. PS_LAYOUT-CWIDTH_OPT = PV_CWIDTH_OPT. PS_LAYOUT-ZEBRA = PV_ZEBRA. PS_LAYOUT-GRID_TITLE = PV_GRID_TITLE. IF NOT PV_CTAB_FNAME IS INITIAL. PS_LAYOUT-CTAB_FNAME = PV_CTAB_FNAME. ENDIF. ENDFORM. "F_BUILD_LAYOUT_PROC *&---------------------------------------------------------------------* *& Form F_EXCLUDE_FUNCTIONS_PROC *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM F_EXCLUDE_FUNCTIONS_PROC . REFRESH GT_EXCLUDE. GS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_INSERT_ROW. APPEND GS_EXCLUDE TO GT_EXCLUDE. GS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_DELETE_ROW. APPEND GS_EXCLUDE TO GT_EXCLUDE. GS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE. APPEND GS_EXCLUDE TO GT_EXCLUDE. GS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE_NEW_ROW. APPEND GS_EXCLUDE TO GT_EXCLUDE. GS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_UNDO. APPEND GS_EXCLUDE TO GT_EXCLUDE. GS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_CUT. APPEND GS_EXCLUDE TO GT_EXCLUDE. GS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY_ROW. APPEND GS_EXCLUDE TO GT_EXCLUDE. GS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY. APPEND GS_EXCLUDE TO GT_EXCLUDE. GS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_APPEND_ROW. APPEND GS_EXCLUDE TO GT_EXCLUDE. GS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_REFRESH. APPEND GS_EXCLUDE TO GT_EXCLUDE. ENDFORM. " F_EXCLUDE_FUNCTIONS_PROC *&---------------------------------------------------------------------* *& Form F_EVENT_HANDLER_PROC *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * <--P_GO_EVENT1 text * <--P_GO_ALV_GRID1 text *----------------------------------------------------------------------* FORM F_EVENT_HANDLER_PROC CHANGING PO_EVENT TYPE REF TO LCL_EVENT_RECEIVER PO_ALV_GRID TYPE REF TO LCL_ALV_GRID. CALL METHOD PO_ALV_GRID->SET_READY_FOR_INPUT EXPORTING I_READY_FOR_INPUT = 1. CALL METHOD PO_ALV_GRID->REGISTER_EDIT_EVENT EXPORTING I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_ENTER. CALL METHOD PO_ALV_GRID->REGISTER_EDIT_EVENT EXPORTING I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED. CREATE OBJECT PO_EVENT. SET HANDLER PO_EVENT->HANDLE_HOTSPOT_CLICK FOR PO_ALV_GRID. ENDFORM. " F_EVENT_HANDLER_PROC *&---------------------------------------------------------------------* *& Form F_BUILD_FIELDCATALOG_PROC *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_0240 text * <--P_GT_FIELDCAT1 text *----------------------------------------------------------------------* FORM F_BUILD_FIELDCATALOG_PROC USING PV_TNAME TYPE ANY CHANGING PT_FIELDCAT TYPE LVC_T_FCAT. DATA : LV_TABNAME TYPE SLIS_TABNAME, LS_SLIS_ALV TYPE SLIS_FIELDCAT_ALV, LS_FIELDCAT LIKE GS_FIELDCAT, LT_SLIS_ALV TYPE SLIS_T_FIELDCAT_ALV. LV_TABNAME = PV_TNAME. CALL FUNCTION ‘REUSE_ALV_FIELDCATALOG_MERGE‘ EXPORTING I_PROGRAM_NAME = SY-REPID I_INTERNAL_TABNAME = LV_TABNAME I_INCLNAME = SY-REPID I_BYPASSING_BUFFER = GC_X CHANGING CT_FIELDCAT = LT_SLIS_ALV[] EXCEPTIONS INCONSISTENT_INTERFACE = 1 PROGRAM_ERROR = 2 OTHERS = 3. CHECK SY-SUBRC = 0. REFRESH PT_FIELDCAT. LOOP AT LT_SLIS_ALV INTO LS_SLIS_ALV. MOVE-CORRESPONDING LS_SLIS_ALV TO LS_FIELDCAT. MOVE : LS_SLIS_ALV-SELTEXT_L TO LS_FIELDCAT-SCRTEXT_L, LS_SLIS_ALV-SELTEXT_M TO LS_FIELDCAT-SCRTEXT_M, LS_SLIS_ALV-SELTEXT_S TO LS_FIELDCAT-SCRTEXT_S, LS_SLIS_ALV-DDICTXT TO LS_FIELDCAT-COLDDICTXT, LS_SLIS_ALV-DDICTXT TO LS_FIELDCAT-SELDDICTXT, LS_SLIS_ALV-DDICTXT TO LS_FIELDCAT-TIPDDICTXT, LS_SLIS_ALV-REF_FIELDNAME TO LS_FIELDCAT-REF_FIELD, LS_SLIS_ALV-REF_TABNAME TO LS_FIELDCAT-REF_TABLE, LS_SLIS_ALV-ROUNDFIELDNAME TO LS_FIELDCAT-ROUNDFIELD, LS_SLIS_ALV-DECIMALSFIELDNAME TO LS_FIELDCAT-DECMLFIELD, LS_SLIS_ALV-DECIMALS_OUT TO LS_FIELDCAT-DECIMALS_O, LS_SLIS_ALV-TEXT_FIELDNAME TO LS_FIELDCAT-TXT_FIELD, LS_SLIS_ALV-REPTEXT_DDIC TO LS_FIELDCAT-REPTEXT, LS_SLIS_ALV-DDIC_OUTPUTLEN TO LS_FIELDCAT-DD_OUTLEN. CASE LS_FIELDCAT-FIELDNAME. WHEN ‘BELNR‘. LS_FIELDCAT-SCRTEXT_M = TEXT-H01. LS_FIELDCAT-SCRTEXT_L = TEXT-H01. LS_FIELDCAT-SCRTEXT_S = TEXT-H01. LS_FIELDCAT-REPTEXT = TEXT-H01. LS_FIELDCAT-COLTEXT = TEXT-H01. LS_FIELDCAT-JUST = GC_C. LS_FIELDCAT-KEY = GC_X. LS_FIELDCAT-COL_POS = 1. WHEN ‘BUZEI‘. LS_FIELDCAT-SCRTEXT_M = TEXT-H02. LS_FIELDCAT-SCRTEXT_L = TEXT-H02. LS_FIELDCAT-SCRTEXT_S = TEXT-H02. LS_FIELDCAT-COLTEXT = TEXT-H02. LS_FIELDCAT-REPTEXT = TEXT-H02. LS_FIELDCAT-JUST = GC_C. LS_FIELDCAT-KEY = GC_SPACE. LS_FIELDCAT-COL_POS = 2. WHEN ‘GJAHR‘. LS_FIELDCAT-SCRTEXT_M = TEXT-H03. LS_FIELDCAT-SCRTEXT_L = TEXT-H03. LS_FIELDCAT-SCRTEXT_S = TEXT-H03. LS_FIELDCAT-REPTEXT = TEXT-H03. LS_FIELDCAT-COLTEXT = TEXT-H03. LS_FIELDCAT-JUST = GC_C. LS_FIELDCAT-KEY = GC_SPACE. LS_FIELDCAT-COL_POS = 3. WHEN ‘TICON‘. LS_FIELDCAT-SCRTEXT_M = TEXT-H04. LS_FIELDCAT-SCRTEXT_L = TEXT-H04. LS_FIELDCAT-SCRTEXT_S = TEXT-H04. LS_FIELDCAT-REPTEXT = TEXT-H04. LS_FIELDCAT-COLTEXT = TEXT-H04. LS_FIELDCAT-JUST = GC_C. LS_FIELDCAT-KEY = GC_SPACE. LS_FIELDCAT-HOTSPOT = GC_X. LS_FIELDCAT-COL_POS = 4. WHEN OTHERS. LS_FIELDCAT-NO_OUT = GC_X. LS_FIELDCAT-TECH = GC_X. ENDCASE. APPEND LS_FIELDCAT TO PT_FIELDCAT. CLEAR : LS_SLIS_ALV, LS_FIELDCAT. ENDLOOP. ENDFORM. " F_BUILD_FIELDCATALOG_PROC *&---------------------------------------------------------------------* *& Form F_CALL_ALV_LIST_PROC *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_LV_NAME text * -->P_GS_LAYOUT1 text * <--P_GT_FIELDCAT1 text * <--P_GO_ALV_GRID1 text *----------------------------------------------------------------------* FORM F_CALL_ALV_LIST_PROC USING PV_TNAME TYPE ANY PS_LAYOUT TYPE LVC_S_LAYO CHANGING PT_FIELDCAT TYPE LVC_T_FCAT PO_ALV_GRID TYPE REF TO LCL_ALV_GRID. DATA LV_TABLE LIKE FELD-NAME. FIELD-SYMBOLS <LT_TABLE> TYPE STANDARD TABLE. CONCATENATE PV_TNAME ‘[]‘ INTO LV_TABLE. ASSIGN (LV_TABLE) TO <LT_TABLE>. CHECK NOT PT_FIELDCAT[] IS INITIAL. CALL METHOD PO_ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY EXPORTING IS_VARIANT = GS_VARIANT I_SAVE = GV_SAVE IS_LAYOUT = PS_LAYOUT IT_TOOLBAR_EXCLUDING = GT_EXCLUDE[] CHANGING IT_OUTTAB = <LT_TABLE> IT_FIELDCATALOG = PT_FIELDCAT[] EXCEPTIONS INVALID_PARAMETER_COMBINATION = 1 PROGRAM_ERROR = 2 TOO_MANY_LINES = 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. ENDIF. ENDFORM. " F_CALL_ALV_LIST_PROC *&---------------------------------------------------------------------* *& Form F_BASIC_GRID_PROC *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_GC_COLS_INT1 text * <--P_GO_ALV_GRID1 text *----------------------------------------------------------------------* FORM F_BASIC_GRID_PROC USING PV_COL TYPE I CHANGING PO_ALV_GRID TYPE REF TO LCL_ALV_GRID. *-- Sets Number of Fixed Columns CALL METHOD PO_ALV_GRID->M_SET_FIXED_COLS EXPORTING IV_COLS = PV_COL. CALL METHOD CL_GUI_CONTROL=>SET_FOCUS EXPORTING CONTROL = PO_ALV_GRID. ENDFORM. " F_BASIC_GRID_PROC
将自建表建好,代码应该可以直接用。
标签:
原文地址:http://www.cnblogs.com/fieldcatalog/p/5441298.html