【ABAP】知识点
1.RANGES:
RANGES: ra_ebeln FOR ekpo- ebeln .
SELECT ebeln
INTO CORRESPONDING FIELDS OF TABLE lt_ebeln
FROM ztfc_mm030_his
WHERE pltyp = 'Z'
AND ebeln <> ''.
IF s_ebeln[] IS NOT INITIAL .
DELETE lt_ebeln WHERE ebeln NOT IN s_ebeln.
ENDIF.
IF lt_ebeln[] IS NOT INITIAL .
LOOP AT lt_ebeln.
CLEAR ra_ebeln.
ra_ebeln- sign = 'I' .
ra_ebeln- option = 'EQ' .
ra_ebeln- low = lt_ebeln-ebeln.
APPEND ra_ebeln.
ENDLOOP .
ENDIF.
INTO CORRESPONDING FIELDS OF TABLE lt_ebeln
FROM ztfc_mm030_his
WHERE pltyp = 'Z'
AND ebeln <> ''.
IF s_ebeln[] IS NOT INITIAL .
DELETE lt_ebeln WHERE ebeln NOT IN s_ebeln.
ENDIF.
IF lt_ebeln[] IS NOT INITIAL .
LOOP AT lt_ebeln.
CLEAR ra_ebeln.
ra_ebeln- sign = 'I' .
ra_ebeln- option = 'EQ' .
ra_ebeln- low = lt_ebeln-ebeln.
APPEND ra_ebeln.
ENDLOOP .
ENDIF.
2. 自定义下拉菜单
PARAMETER: p_lfart (2) TYPE C AS LISTBOX VISIBLE LENGTH 25 OBLIGATORY DEFAULT 'Q3' .
PARAMETER: p_conf (2) TYPE C AS LISTBOX VISIBLE LENGTH 15 OBLIGATORY DEFAULT 'P1' .
AT SELECTION-SCREEN OUTPUT .
CLEAR: list1 ,value.
REFRESH list1[].
value-key = 'P1'.
value-text = '已经审核'.
APPEND value TO list1 .
value-key = 'P2'.
value-text = '未审核'.
APPEND value TO list1 .
value-key = 'P3'.
value-text = '全部'.
APPEND value TO list1 .
* &设置
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'P_CONF'
values = list1.
* &设置单据的类型
CLEAR: list2 ,value.
REFRESH list2[].
value-key = 'Q1'.
value-text = '调价换吊牌入库(成本改变)' .
APPEND value TO list2 .
value-key = 'Q2'.
value-text = '调价换吊牌出库(成本改变)' .
APPEND value TO list2 .
value-key = 'Q3'.
value-text = '全部'.
APPEND value TO list2 .
* &设置 填充下拉菜单
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'P_LFART'
values = list2.
CLEAR: list1 ,value.
REFRESH list1[].
value-key = 'P1'.
value-text = '已经审核'.
APPEND value TO list1 .
value-key = 'P2'.
value-text = '未审核'.
APPEND value TO list1 .
value-key = 'P3'.
value-text = '全部'.
APPEND value TO list1 .
* &设置
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'P_CONF'
values = list1.
* &设置单据的类型
CLEAR: list2 ,value.
REFRESH list2[].
value-key = 'Q1'.
value-text = '调价换吊牌入库(成本改变)' .
APPEND value TO list2 .
value-key = 'Q2'.
value-text = '调价换吊牌出库(成本改变)' .
APPEND value TO list2 .
value-key = 'Q3'.
value-text = '全部'.
APPEND value TO list2 .
* &设置 填充下拉菜单
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'P_LFART'
values = list2.
3.定义选择屏幕行数据
SELECTION-SCREEN BEGIN OF LINE .
SELECTION-SCREEN COMMENT 1(10 ) comm3 .
SELECTION-SCREEN POSITION 33 .
"PARAMETERS: p_werks LIKE marc-werks OBLIGATORY.
PARAMETERS: p_werks LIKE mseg- werks OBLIGATORY.
SELECTION-SCREEN COMMENT 52(10 ) comm4 .
"PARAMETERS: p_lgort LIKE mard-lgort OBLIGATORY.
PARAMETERS: p_lgort LIKE mseg- lgort OBLIGATORY.
SELECTION-SCREEN END OF LINE .
SELECTION-SCREEN COMMENT 1(10 ) comm3 .
SELECTION-SCREEN POSITION 33 .
"PARAMETERS: p_werks LIKE marc-werks OBLIGATORY.
PARAMETERS: p_werks LIKE mseg- werks OBLIGATORY.
SELECTION-SCREEN COMMENT 52(10 ) comm4 .
"PARAMETERS: p_lgort LIKE mard-lgort OBLIGATORY.
PARAMETERS: p_lgort LIKE mseg- lgort OBLIGATORY.
SELECTION-SCREEN END OF LINE .
AT SELECTION-SCREEN OUTPUT .
comm3 = '地点:'.
comm4 = '库存地点:'.
comm3 = '地点:'.
comm4 = '库存地点:'.
4.屏幕选择动作下的检查动作
AT SELECTION-SCREEN .
*在执行或者回车的时候,检查必输字段
IF SY- UCOMM = 'ONLI' OR SY- UCOMM = '' .
IF s_class[] IS INITIAL .
MESSAGE E000 (ZRT01 ) WITH '类别不能为空' .
ENDIF .
IF s_zbzcat- low > 'Q3' OR s_zbzcat -high > 'Q3' .
MESSAGE E000 (ZRT01 ) WITH '请选择正确的业务类型' .
ENDIF .
ENDIF .
5.初始化屏幕字段为只显示
AT SELECTION-SCREEN OUTPUT .
* &将屏幕字段设置为只显示
LOOP AT SCREEN .
IF screen - name = 'P_KLART' .
screen - input = 0 .
ENDIF .
MODIFY SCREEN .
ENDLOOP .
*在执行或者回车的时候,检查必输字段
IF SY- UCOMM = 'ONLI' OR SY- UCOMM = '' .
IF s_class[] IS INITIAL .
MESSAGE E000 (ZRT01 ) WITH '类别不能为空' .
ENDIF .
IF s_zbzcat- low > 'Q3' OR s_zbzcat -high > 'Q3' .
MESSAGE E000 (ZRT01 ) WITH '请选择正确的业务类型' .
ENDIF .
ENDIF .
5.初始化屏幕字段为只显示
AT SELECTION-SCREEN OUTPUT .
* &将屏幕字段设置为只显示
LOOP AT SCREEN .
IF screen - name = 'P_KLART' .
screen - input = 0 .
ENDIF .
MODIFY SCREEN .
ENDLOOP .
6. 根据屏幕选择不同,动态实现搜索帮助的变化
*----------------------------------------------------------------------*
* 定义选择屏幕
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK bl2 With FRAME TITLE text- 002.
PARAMETERS: r1 RADIOBUTTON GROUP rg1 DEFAULT 'X' USER-COMMAND chg , "大类
r2 RADIOBUTTON GROUP rg1 . "中类
SELECTION-SCREEN END OF BLOCK bl2.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text- 001 .
SELECT-OPTIONS: s_laeda FOR ztfc_mm015b- laeda.
PARAMETERS: p_klart LIKE rmclre- klart AS LISTBOX VISIBLE LENGTH 15 DEFAULT '026' .
SELECT-OPTIONS: s_class FOR klah- class ."rmclre-class ."MATCHCODE OBJECT CLASC.
SELECT-OPTIONS: s_zbzcat FOR ztfc_mm015b- zbzcat,
s_zlifnr FOR ztfc_mm015b -zlifnr.
SELECTION-SCREEN END OF BLOCK b1.
*----------------------------------------------------------------------*
* 选择屏幕设置
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_class-low .
PERFORM FRM_GET_KOSTL.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_class-high .
PERFORM FRM_GET_KOSTL.
*&代码实现搜索帮助
FORM FRM_GET_KOSTL .
* &定义搜索帮助的条目,有助于用户选择
TYPES: BEGIN OF values,
class LIKE klah-class ,
klart LIKE klah-klart ,
artxt LIKE tclat-artxt ,
klagr LIKE klah-klagr ,
ktext LIKE tclgt-ktext ,
END OF values.
DATA: progname TYPE sy- repid, "程序名称
dynnum TYPE sy -dynnr, "屏幕编号
values_tab TYPE TABLE OF values,
l_klagr LIKE klah -klagr.
IF r1 = 'X'.
l_klagr = 'Z040'.
ELSE.
l_klagr = 'Z050'.
ENDIF.
SELECT a~ class a~ klart a~klagr b ~ktext c ~artxt
INTO CORRESPONDING FIELDS OF TABLE values_tab
FROM klah AS a
LEFT JOIN tclgt AS b
ON a ~klagr = b~klagr
AND b ~spras = '1'
LEFT JOIN tclat AS c
ON a ~klart = c~klart
AND c~ spras = '1'
WHERE a~klart = p_klart
AND a~klagr = l_klagr.
* 赋值,获取程序名称和屏幕号
progname = sy- repid.
dynnum = sy- dynnr.
* 生成指定内容的搜索帮助
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'CLASS' "内表字段
dynpprog = progname
dynpnr = dynnum
dynprofield = 'KLAH-CLASS' "屏幕待输出字段,需要有前缀字段
value_org = 'S'
TABLES
value_tab = values_tab "从这个内表中获取
EXCEPTIONS
parameter_error = 1
no_values_found = 2
others = 3.
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_GET_KOSTL
* 定义选择屏幕
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK bl2 With FRAME TITLE text- 002.
PARAMETERS: r1 RADIOBUTTON GROUP rg1 DEFAULT 'X' USER-COMMAND chg , "大类
r2 RADIOBUTTON GROUP rg1 . "中类
SELECTION-SCREEN END OF BLOCK bl2.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text- 001 .
SELECT-OPTIONS: s_laeda FOR ztfc_mm015b- laeda.
PARAMETERS: p_klart LIKE rmclre- klart AS LISTBOX VISIBLE LENGTH 15 DEFAULT '026' .
SELECT-OPTIONS: s_class FOR klah- class ."rmclre-class ."MATCHCODE OBJECT CLASC.
SELECT-OPTIONS: s_zbzcat FOR ztfc_mm015b- zbzcat,
s_zlifnr FOR ztfc_mm015b -zlifnr.
SELECTION-SCREEN END OF BLOCK b1.
*----------------------------------------------------------------------*
* 选择屏幕设置
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_class-low .
PERFORM FRM_GET_KOSTL.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_class-high .
PERFORM FRM_GET_KOSTL.
*&代码实现搜索帮助
FORM FRM_GET_KOSTL .
* &定义搜索帮助的条目,有助于用户选择
TYPES: BEGIN OF values,
class LIKE klah-class ,
klart LIKE klah-klart ,
artxt LIKE tclat-artxt ,
klagr LIKE klah-klagr ,
ktext LIKE tclgt-ktext ,
END OF values.
DATA: progname TYPE sy- repid, "程序名称
dynnum TYPE sy -dynnr, "屏幕编号
values_tab TYPE TABLE OF values,
l_klagr LIKE klah -klagr.
IF r1 = 'X'.
l_klagr = 'Z040'.
ELSE.
l_klagr = 'Z050'.
ENDIF.
SELECT a~ class a~ klart a~klagr b ~ktext c ~artxt
INTO CORRESPONDING FIELDS OF TABLE values_tab
FROM klah AS a
LEFT JOIN tclgt AS b
ON a ~klagr = b~klagr
AND b ~spras = '1'
LEFT JOIN tclat AS c
ON a ~klart = c~klart
AND c~ spras = '1'
WHERE a~klart = p_klart
AND a~klagr = l_klagr.
* 赋值,获取程序名称和屏幕号
progname = sy- repid.
dynnum = sy- dynnr.
* 生成指定内容的搜索帮助
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'CLASS' "内表字段
dynpprog = progname
dynpnr = dynnum
dynprofield = 'KLAH-CLASS' "屏幕待输出字段,需要有前缀字段
value_org = 'S'
TABLES
value_tab = values_tab "从这个内表中获取
EXCEPTIONS
parameter_error = 1
no_values_found = 2
others = 3.
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_GET_KOSTL
*动态实现ALV的字段,控制可编辑状态,长度和字段描述等
7. FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat .
DATA ls_fcat type lvc_s_fcat .
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
ct_fieldcat = pt_fieldcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
*--Exception handling
ENDIF.
LOOP AT pt_fieldcat INTO ls_fcat .
CASE pt_fieldcat-fieldname .
WHEN 'CARRID' .
ls_fcat-outpulen = '10' .
ls_fcat-coltext = 'Airline Carrier ID' . "控制字段描述
MODIFY pt_fieldcat FROM ls_fcat .
WHEN 'PAYMENTSUM' .
ls_fcat-no_out = 'X' .
MODIFY pt_fieldcat FROM ls_fcat .
ENDCASE .
ENDLOOP .
ENDFORM .
DATA ls_fcat type lvc_s_fcat .
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
ct_fieldcat = pt_fieldcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
*--Exception handling
ENDIF.
LOOP AT pt_fieldcat INTO ls_fcat .
CASE pt_fieldcat-fieldname .
WHEN 'CARRID' .
ls_fcat-outpulen = '10' .
ls_fcat-coltext = 'Airline Carrier ID' . "控制字段描述
MODIFY pt_fieldcat FROM ls_fcat .
WHEN 'PAYMENTSUM' .
ls_fcat-no_out = 'X' .
MODIFY pt_fieldcat FROM ls_fcat .
ENDCASE .
ENDLOOP .
ENDFORM .
8. 有时候我们需要使用到数据的排序.这个可以通过填充参考结构LVC_T_SORT创建的内表来实现,
这个内表中包含了排序的标准.可以传递给set_table_for_first_display这个方法的IT_SORT参数来初始化一个排序.
PS:FORM prepare_sort_table CHANGING pt_sort TYPE lvc_t_sort .
DATA ls_sort TYPE lvc_s_sort .ls_sort-spos = '1' .ls_sort-fieldname = 'CARRID' .ls_sort-up = 'X' . "A to Zls_sort-down = space .APPEND ls_sort TO pt_sort .ls_sort-spos = '2' .ls_sort-fieldname = 'SEATSOCC' .ls_sort-up = space .ls_sort-down = 'X' . "Z to AAPPEND ls_sort TO pt_sort .
9. 调用函数:CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' 后对结构的处理方式ENDFORM. " prepare_sort_table
CHANGE:
READ TABLE it_fields ASSIGNING <wa_fields> WITH KEY fieldname = 'VBELN'.
IF sy- subrc = 0 .
<wa_fields>- col_pos = '4' .
ENDIF.
READ TABLE it_fields ASSIGNING <wa_fields> WITH KEY fieldname = 'ZCKYL' .
IF sy- subrc = 0 .
<wa_fields>- col_pos = '15' .
ENDIF.
READ TABLE it_fields ASSIGNING <wa_fields> WITH KEY fieldname = 'ZZSTA' .
IF sy- subrc = 0 .
<wa_fields>- col_pos = '15' .
ENDIF.
IF sy- subrc = 0 .
<wa_fields>- col_pos = '4' .
ENDIF.
READ TABLE it_fields ASSIGNING <wa_fields> WITH KEY fieldname = 'ZCKYL' .
IF sy- subrc = 0 .
<wa_fields>- col_pos = '15' .
ENDIF.
READ TABLE it_fields ASSIGNING <wa_fields> WITH KEY fieldname = 'ZZSTA' .
IF sy- subrc = 0 .
<wa_fields>- col_pos = '15' .
ENDIF.
DELETE:
DELETE it_fields WHERE fieldname = 'SEL' OR fieldname = 'DEL' OR fieldname = 'GROUP'
OR fieldname = 'TABIX'." or fieldname = 'MEINS'.
OR fieldname = 'TABIX'." or fieldname = 'MEINS'.
CHANGE:
LOOP AT it_fields. l_tabix = sy-tabix .
CASE it_fields-fieldname .
WHEN 'ICON'. "调整ICON属性
it_fields- icon = 'X' .
it_fields- col_pos = 1 .
*调整描述的位置.
WHEN 'NAME1'.
it_fields- col_pos = 6 .
WHEN 'MAKTX'.
it_fields- col_pos = 7 .
WHEN 'QRSL'. "修改确认数量字段属性,可编辑
it_fields- edit = 'X' .
WHEN 'CYSL'.
it_fields- col_pos = 15 .
ENDCASE .
IT_FIELDS- QFIELDNAME = '' .
MODIFY it_fields INDEX sy -tabix .
ENDLOOP.
10. 使用ls_variant来实现区分同一个程序中的不同ALV,这样在设置布局时就不会相互影响了。
DATA: ls_variant TYPE disvariant . "用来定义每个ALV的变式指针
ls_variant-report = sy-repid .
ls_variant-handle = '0001'.
lc_glay-edt_cll_cb = 'X'.
ls_variant-handle = '0001'.
lc_glay-edt_cll_cb = 'X'.
11.设置ALV选择屏幕的下拉菜单,这样就设置了多个值。
DATA: BEGIN OF LT_CLINT,
CLINT LIKE KLAH-CLINT ,
CLASS LIKE KLAH-CLASS ,
KSCHL LIKE SWOR-KSCHL ,
END OF LT_CLINT.
SELECT DISTINCT KLAH~CLINT KLAH ~CLASS SWOR ~KSCHL INTO CORRESPONDING FIELDS OF LT_CLINT
FROM KLAH
INNER JOIN SWOR ON SWOR ~CLINT = KLAH~CLINT
WHERE KLAH~KLART = 'Z04'
AND KLAH~KLAGR = 'TP99'
AND SWOR~SPRAS = SY- LANGU.
VALUE -KEY = LT_CLINT-CLASS .
VALUE -TEXT = LT_CLINT-KSCHL .
APPEND VALUE TO LIST.
CLEAR VALUE .
ENDSELECT.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
ID = 'P_CLINT'
VALUES = LIST.
CLINT LIKE KLAH-CLINT ,
CLASS LIKE KLAH-CLASS ,
KSCHL LIKE SWOR-KSCHL ,
END OF LT_CLINT.
SELECT DISTINCT KLAH~CLINT KLAH ~CLASS SWOR ~KSCHL INTO CORRESPONDING FIELDS OF LT_CLINT
FROM KLAH
INNER JOIN SWOR ON SWOR ~CLINT = KLAH~CLINT
WHERE KLAH~KLART = 'Z04'
AND KLAH~KLAGR = 'TP99'
AND SWOR~SPRAS = SY- LANGU.
VALUE -KEY = LT_CLINT-CLASS .
VALUE -TEXT = LT_CLINT-KSCHL .
APPEND VALUE TO LIST.
CLEAR VALUE .
ENDSELECT.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
ID = 'P_CLINT'
VALUES = LIST.
12.隐藏掉ALV尾部的0的方法:
方法一:给数值加上单位。方法二:设置小数位数为0.it_fields-decimals_out = '0'.方法三:如果没有结构,则使用参考字段的属性。* &20130905_zfr 给数量字段加上关联单位,避免显示小数位后的0READ TABLE t_fieldcat ASSIGNING <w_fieldcat> WITH KEY fieldname = 'FKLMG'.IF sy- subrc = 0 .<w_fieldcat>- qfieldname = 'MEINS' .ENDIF.* &实现将单位的字母转为中文READ TABLE t_fieldcat ASSIGNING <w_fieldcat> WITH KEY fieldname = 'MEINS'.IF sy- subrc = 0 .<w_fieldcat>- qfieldname = 'UNIT' .ENDIF.如果是金额,按单位保存小数位数:fieldcatalog-cfieldname = 内表中的单位字段
数量求和按单位分开:fieldcat-QFIELDNAME = 内表-单位
1. 消息:
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
2. 更新表中对应的字段,通过工作区
modify F_IT_IDATA_CHG from LX_IDATA transporting WERKS LGORT UMWRK UMLGO BWART
where MATNR is not initial.
it_data-sel = ''. “通过工作区更新内表
MODIFY it_data TRANSPORTING sel WHERE fhshbj = 'F'.
posted on 2014-06-22 15:08 color_story 阅读(415) 评论(0) 编辑 收藏 举报