Open nangnangchuai opened 5 years ago
*&---------------------------------------------------------------------*
*& Report ZTEST_LTT_TEST3
*&
*&---------------------------------------------------------------------*
*&使用alv来输出表单信息
*&---------------------------------------------------------------------*
REPORT ZTEST_LTT_TEST3.
DATA GT_TAB TYPE TABLE OF SFLIGHT.
SELECT * FROM SFLIGHT INTO TABLE GT_TAB
UP TO 25 ROWS.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_STRUCTURE_NAME = 'SFLIGHT'
TABLES
t_outtab = GT_TAB
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
*&---------------------------------------------------------------------*
*& Report ZTEST_LTT_TEST3
*&
*&---------------------------------------------------------------------*
*&将标准的全的gui status赋值给用户
*&
*&---------------------------------------------------------------------*
REPORT ZTEST_LTT_TEST3.
TYPE-POOLS:SLIS.
DATA GT_EVENTS TYPE SLIS_T_EVENT.
DATA GS_EVENT TYPE SLIS_ALV_EVENT.
DATA GT_TAB TYPE TABLE OF SFLIGHT.
SELECT * FROM SFLIGHT INTO TABLE GT_TAB
UP TO 25 ROWS.
MOVE 'PF_STATUS_SET' TO GS_EVENT-NAME.
MOVE 'ALV_STATUS_SET' TO GS_EVENT-FORM.
APPEND GS_EVENT TO GT_EVENTS.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
I_STRUCTURE_NAME = 'SFLIGHT'
it_events = GT_EVENTS
i_callback_user_command = 'ALV_USER_COMMAND'
TABLES
t_outtab = GT_TAB
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
FORM ALV_USER_COMMAND USING p_ucomm like sy-ucomm
p_selfield TYPE SLIS_selfield.
case p_ucomm. "当点击页面上的退出的按妞
when 'CLOSE'.
LEAVE PROGRAM.
WHEN OTHERS.
ENDCASE.
ENDFORM.
FORM ALV_STATUS_SET USING PT_EXTAB TYPE SLIS_T_EXTAB.
CLEAR :PT_EXTAB[].
* SET PF-STATUS 'ALV_STATUS'.
SET PF-STATUS 'STANDARD_FULLSCREEN'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Report ZTEST_LTT_TEST3
*&
*&---------------------------------------------------------------------*
*&可以显示alv画面,但是点击求和按钮报错
*&
*&---------------------------------------------------------------------*
REPORT ztest_ltt_test3.
TYPE-POOLS:slis.
DATA gt_fieldcat TYPE slis_t_fieldcat_alv.
DATA gs_fieldcat TYPE slis_fieldcat_alv.
DATA gt_events TYPE slis_t_event.
DATA gs_event TYPE slis_alv_event.
DATA gs_layout TYPE slis_layout_alv.
DATA gs_glay TYPE lvc_s_glay.
TYPES BEGIN OF t_line.
INCLUDE STRUCTURE sflight.
TYPES checbox TYPE c.
TYPES END OF t_line.
DATA gt_itab TYPE TABLE OF t_line WITH HEADER LINE.
SELECT * FROM sflight
INTO CORRESPONDING FIELDS OF TABLE gt_itab
UP TO 25 ROWS.
MOVE 'PF_STATUS_SET' TO gs_event-name.
MOVE 'ALV_STATUS_SET' TO gs_event-form.
APPEND gs_event TO gt_events.
*MOVE 'DATA_CHANGED' TO gs_event-name.
*MOVE 'ALV_DATA_CHANGED' TO gs_event-form.
*APPEND gs_event TO gt_events.
CLEAR: gs_fieldcat ,gt_fieldcat.
gs_fieldcat-col_pos = 1 .
gs_fieldcat-fieldname = 'checbox'.
gs_fieldcat-checkbox = 'X' .
gs_fieldcat-edit = 'X'.
gs_fieldcat-seltext_m = 'SEL'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR: gs_fieldcat.
gs_fieldcat-col_pos = 2 .
gs_fieldcat-fieldname = 'CARRID'.
gs_fieldcat-seltext_m = 'Airline Code'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR: gs_fieldcat .
gs_fieldcat-col_pos = 3 .
gs_fieldcat-fieldname = 'CONNID'.
gs_fieldcat-seltext_m = 'Connection Number'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR: gs_fieldcat .
gs_fieldcat-col_pos = 4 .
gs_fieldcat-fieldname = 'FLDATE'.
gs_fieldcat-seltext_m = '起飞时间'.
APPEND gs_fieldcat TO gt_fieldcat.
*gs_glay-edt_cll_cb = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
i_callback_user_command = 'ALV_USER_COMMAND '
i_grid_settings = gs_glay
is_layout = gs_layout
it_fieldcat = gt_fieldcat
i_default = 'X'
it_events = gt_events
TABLES
t_outtab = gt_itab
EXCEPTIONS
program_error = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
*&---------------------------------------------------------------------*
*& Form alv_user_command
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_UCOMM text
* -->P_SELFIELD text
*----------------------------------------------------------------------*
FORM alv_user_command USING p_ucomm LIKE sy-ucomm
p_selfield TYPE slis_selfield.
CASE p_ucomm.
WHEN '&ICI'.
* READ TABLE gt_itab INDEX p_selfield-tabindex.
* gt_itab-checbox = 'X'.
* MODIFY gt_itab INDEX p_selfield-tabindex.
WHEN 'SAVE' .
MODIFY sflight FROM TABLE gt_itab.
IF sy-subrc = 0.
COMMIT WORK.
ELSE.
ROLLBACK WORK.
ENDIF.
ENDCASE.
ENDFORM. "alv_user_command
*&---------------------------------------------------------------------*
*& Form alv_status_set
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
* -->PT_EXTAB text
*----------------------------------------------------------------------*
FORM alv_status_set USING pt_extab TYPE slis_t_extab.
CLEAR pt_extab[].
SET PF-STATUS 'STANDARD_FULLSCREEN'.
ENDFORM. "alv_status_set
必须要用endselect结尾使用
SELECT carrid connid FROM spfli INTO CORRESPONDING FIELDS OF TABLE gt_itab PACKAGE SIZE 5. LOOP AT gt_itab INTO gs_wa. write : / gs_wa-carrid,gs_wa-connid.
ENDLOOP. ENDSELECT.
DATA gt_sflight type TABLE OF sflight.
DATA gs_sflight TYPE sflight.
SELECT-OPTIONS: s_carrid FOR gs_sflight-carrid.
INITIALIZATION.
s_carrid-sign = 'I'.
s_carrid-OPTION = 'EQ'.
s_carrid-LOW = 'AA'.
APPEND s_carrid.
START-OF-SELECTION.
SELECT carrid connid
FROM sflight
INTO CORRESPONDING FIELDS OF TABLE gt_sflight
WHERE carrid IN s_carrid.
END-OF-SELECTION.
LOOP AT gt_sflight INTO gs_sflight.
WRITE :/ gs_sflight-carrid,gs_sflight-connid.
ENDLOOP.
DATA :BEGIN OF gs_ren,
name(20) VALUE 'kim sung joon',
country(10) VALUE 'china',
city(20) VALUE 'beijign',
END OF gs_ren.
DATA:BEGIN OF gs_info,
name(20),
city(20),
phone(10) VALUE '12345',
END OF gs_info.
MOVE-CORRESPONDING gs_ren to gs_info.
MOVE gs_ren to gs_info.
write :/ gs_info-name,
gs_info-city,
gs_info-phone.
TYPES:BEGIN OF t_str,
col1 TYPE c,
col2 TYPE i,
END OF t_str.
TYPES :i_itab TYPE TABLE OF t_str.
DATA :gs_str TYPE t_str.
DATA: gt_itab TYPE I_itab.
gs_str-col1 = 'A'.
gs_str-col2 = 1.
APPEND gs_str to gt_itab.
gs_str-col1 = 'B'.
gs_str-col2 = 2.
APPEND gs_str to gt_itab.
PERFORM test_itab USING gt_itab.
FORM test_itab USING pt_itab TYPE I_itab.
READ TABLE gt_itab WITH KEY col1 = 'A' INTO gs_str.
IF sy-subrc = 0.
WRITE :/ gs_str-col1,gs_str-col2.
ENDIF.
ENDFORM.
TYPES : BEGIN OF t_line,
col1 TYPE i,
col2 TYPE i,
END OF t_line.
DATA: gt_itab1 TYPE STANDARD TABLE OF t_line WITH HEADER LINE,
gt_itab2 TYPE STANDARD TABLE OF t_line,
gs_wa LIKE LINE OF gt_itab2.
DO 5 TIMES.
gt_itab1-col1 = sy-index.
gt_itab1-col2 = sy-index * 2.
INSERT TABLE gt_itab1.
ENDDO.
MOVE gt_itab1[] to gt_itab2.
LOOP AT gt_itab2 INTO gs_wa.
WRITE:/ gs_wa-col1,gs_wa-col2.
ENDLOOP.
DATA:BEGIN OF gt_data OCCURS 0,
emp_name TYPE zemp-emp_name,
END OF gt_data.
DATA: gt_rtntab LIKE ddshretval OCCURS 0 WITH HEADER LINE. "接口结构搜索帮助 <-> 帮助系统
DATA:gt_dynpread LIKE dynpread OCCURS 0 WITH HEADER LINE. "当前屏幕的字段(含有值)
PARAMETERS:p_emp_no LIKE zemp-emp_no, "EMP_NO是主键
p_name LIKE zemp-emp_name.
INITIALIZATION.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_name.
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
dyname = sy-cprog "程序名称
dynumb = sy-dynnr "屏幕编号
translate_to_upper = ' X' "字段内容的超级事件转换
request = 'A' "Return ready-for-input ,'A' - Output all fields
TABLES
dynpfields = gt_dynpread. "读当前屏幕数值的表格
READ TABLE gt_dynpread WITH KEY fieldname = 'p_emp_no'.
SELECT DISTINCT emp_name INTO TABLE gt_data
FROM zemp
WHERE emp_no = gt_dynpread-fieldvalue.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'p_name'
dynpprog = sy-cprog
dynpnr = sy-dynnr
window_title = 'EMP_NAME'
value_org = 'S'
TABLES
value_tab = gt_data
return_tab = gt_rtntab.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
READ TABLE gt_rtntab INDEX 1.
p_name = gt_rtntab-fieldval.
DATA:BEGIN OF gs_line,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
carrname TYPE scarr-carrname,
END OF gs_line.
DATA gt_itab LIKE TABLE OF gs_line. "gt_itab是个内表的结构有三列。
*
* SELECT carrid connid ”不报错,影响效率
* INTO CORRESPONDING FIELDS OF TABLE gt_itab
* FROM sflight.
SELECT carrid connid "不报错,因为顺序一致
INTO TABLE gt_itab
FROM sflight.
**
* SELECT connid carrid "报错,当字段的顺序和定义时候的顺序不一致会报错
* INTO TABLE gt_itab
* FROM sflight.
LOOP at gt_itab INTO gs_line. "根据内表的gs_line-carrid作为查找的条件,将得到的carrname的值填入内表gt_itab中
SELECT SINGLE carrname INTO gs_line-carrname
FROM scarr WHERE carrid = gs_line-carrid.
MODIFY gt_itab FROM gs_line.
ENDLOOP.
使用list输出一个表单