sap abap螢幕程式設計中使用的table 和call子程式的

dicksonjyl560101發表於2015-04-25
今天下午顧問在和使用者談需求呢,趁這個時間寫了個螢幕中使用table 和如何call 子程式的例子,放在這裡,有人看也好,沒有人看也罷,權當自己練連手.

*&---------------------------------------------------------------------*
*& Module pool ZCHOUER1 *
*& this program is test for chouer
*&---------------------------------------------------------------------*
PROGRAM ZCHOUER1.

**---tables
TABLES ZEKKP.

**---workaera
DATA BEGIN OF WA_ZEKKP.
INCLUDE STRUCTURE ZEKKP.
DATA END OF WA_ZEKKP.
DATA WA_ZEKK LIKE WA_ZEKKP.

**---Initial table
DATA IT_ZEKKP LIKE TABLE OF WA_ZEKKP.

**---data define
DATA OK_CODE LIKE SY-UCOMM.

**---tables controls
CONTROLS MY_TABLE_CONTROL TYPE TABLEVIEW USING SCREEN '0201'.
DATA WA_COLS LIKE LINE OF MY_TABLE_CONTROL-COLS.

**---start-of-selection
START-OF-SELECTION.
CALL SCREEN 100.

*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'.
SET TITLEBAR 'TITLE_0100'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
CASE OK_CODE.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'CANCEL'.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'BOOK'.
PERFORM GET_DATA.
SORT IT_ZEKKP BY EBELN.
DESCRIBE TABLE IT_ZEKKP LINES MY_TABLE_CONTROL-LINES.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Module CLEAR_OK_CODE OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE CLEAR_OK_CODE OUTPUT.
CLEAR OK_CODE.
ENDMODULE. " CLEAR_OK_CODE OUTPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0200 OUTPUT.
SET PF-STATUS 'STATUS_0200'.
SET TITLEBAR 'TITLE_0200'.

ENDMODULE. " STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0200 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0200 INPUT.
CASE OK_CODE.
WHEN 'CANCEL'.
LEAVE TO SCREEN 0.
WHEN 'BACK'.
SET SCREEN 100.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'SRTD'.
READ TABLE MY_TABLE_CONTROL-COLS WITH KEY SELECTED = 'X' INTO
WA_COLS.
IF SY-SUBRC = 0.
SORT IT_ZEKKP BY (WA_COLS-SCREEN-NAME+6) DESCENDING.
ENDIF.
ENDCASE.
ENDMODULE. " USER_COMMAND_0200 INPUT

*&---------------------------------------------------------------------*
*& Form get_Data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --&gt p1 text
* *----------------------------------------------------------------------*
FORM GET_DATA .
SELECT * FROM EKKO
INTO CORRESPONDING FIELDS OF TABLE IT_ZEKKP
WHERE BUKRS = WA_ZEKKP-BUKRS.
ENDFORM. " get_Data
*&---------------------------------------------------------------------*
*& Module trans_to_0200 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE TRANS_TO_0200 OUTPUT.
MOVE-CORRESPONDING WA_ZEKKP TO ZEKKP.
ENDMODULE. " trans_to_0200 OUTPUT
*&---------------------------------------------------------------------*
*& Module trans_from_tc_fields INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE TRANS_FROM_TC_FIELDS INPUT.
MOVE ZEKKP-MARK TO WA_ZEKKP-MARK.
MODIFY IT_ZEKKP INDEX MY_TABLE_CONTROL-CURRENT_LINE FROM WA_ZEKKP.
ENDMODULE. " trans_from_tc_fields INPUT
*&---------------------------------------------------------------------*
*& Module trans_to_tc_fields OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE TRANS_TO_TC_FIELDS OUTPUT.
MOVE-CORRESPONDING WA_ZEKKP TO ZEKKP.
ENDMODULE. " trans_to_tc_fields OUTPUT
*&---------------------------------------------------------------------*
*& Module check_zekkp INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE CHECK_ZEKKP INPUT.
SELECT SINGLE * FROM EKKO
INTO CORRESPONDING FIELDS OF WA_ZEKKP
WHERE EBELN = ZEKKP-EBELN
AND BUKRS = ZEKKP-BUKRS.
ENDMODULE. " check_zekkp INPUT

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29829936/viewspace-1598574/,如需轉載,請註明出處,否則將追究法律責任。

相關文章