【ABAP】知识点2
1. DUMMY是不是检查所有的类型的权限呢?
PS:不是,dummy的意思是虚拟的意思,就是说权限检查的时候有这个权限检查字段,但是不对该字段做权限检查。
AUTHORITY-CHECK OBJECT 'Z_BRAND'
ID 'ACTVT' DUMMY
ID 'BRAND' FIELD p_brand.
IF sy- subrc <> 0.
MESSAGE e001(00 ) WITH '无品牌' p_brand '的权限'.
ENDIF .
ID 'BRAND' FIELD p_brand.
IF sy- subrc <> 0.
MESSAGE e001(00 ) WITH '无品牌' p_brand '的权限'.
ENDIF .
2. BKK_DOMAIN_TEXTS_READ读取域文本的内容,并存放到内表中,
DATA: lt_text TYPE bkkdc_t_domain_text, "抬头
lw_text TYPE bkkdc_s_domain_text ."工作区
CALL FUNCTION 'BKK_DOMAIN_TEXTS_READ'
EXPORTING
i_langu = sy-langu
i_domname = 'ZD_HZDLX'
IMPORTING
lw_text TYPE bkkdc_s_domain_text ."工作区
CALL FUNCTION 'BKK_DOMAIN_TEXTS_READ'
EXPORTING
i_langu = sy-langu
i_domname = 'ZD_HZDLX'
IMPORTING
et_domain_text = lt_text[] .
方式二:
DATA: lt_domain TYPE STANDARD TABLE OF dd07v WITH HEADER LINE .
CALL FUNCTION 'DD_DOMVALUES_GET'
EXPORTING
domname = 'ZD_ZAPPSEX'
text = 'X'
langu = sy -langu
TABLES
dd07v_tab = lt_domain.
EXPORTING
domname = 'ZD_ZAPPSEX'
text = 'X'
langu = sy -langu
TABLES
dd07v_tab = lt_domain.
方式三:
DATA: lt_values_tab TYPE TABLE OF dd07v.
CALL FUNCTION 'GET_DOMAIN_VALUES'
EXPORTING
domname = 'ZE_ZZSTA'
* TEXT = 'X'
* FILL_DD07L_TAB = ' '
TABLES
values_tab = lt_values_tab
* VALUES_DD07L =
EXCEPTIONS
no_values_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
REFRESH lt_values_tab.
ENDIF.
EXPORTING
domname = 'ZE_ZZSTA'
* TEXT = 'X'
* FILL_DD07L_TAB = ' '
TABLES
values_tab = lt_values_tab
* VALUES_DD07L =
EXCEPTIONS
no_values_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
REFRESH lt_values_tab.
ENDIF.
3.使用消息,便面DUMP掉。
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = w_repid
i_callback_pf_status_set = 'FRM_SET_PF_STATUS'
i_callback_user_command = 'FRM_USER_COMMAND'
is_layout = w_layout
it_fieldcat = it_fieldcat[]
i_save = 'A'
TABLES
t_outtab = gt_fhhzd[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy- subrc <> 0.
MESSAGE e001(00 ) WITH '函数REUSE_ALV_GRID_DISPLAY错误!' .
ENDIF.
EXPORTING
i_callback_program = w_repid
i_callback_pf_status_set = 'FRM_SET_PF_STATUS'
i_callback_user_command = 'FRM_USER_COMMAND'
is_layout = w_layout
it_fieldcat = it_fieldcat[]
i_save = 'A'
TABLES
t_outtab = gt_fhhzd[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy- subrc <> 0.
MESSAGE e001(00 ) WITH '函数REUSE_ALV_GRID_DISPLAY错误!' .
ENDIF.
4. 调用SUBMIT获取数据
SUBMIT zhzd_process
WITH p_hzd EQ l_hzd
WITH p_lx EQ 'M'
AND RETURN .
IMPORT msg = gt_fhhzd-msg subrc = sy- subrc FROM MEMORY ID 'ZHZD_PROCESS'.
WITH p_hzd EQ l_hzd
WITH p_lx EQ 'M'
AND RETURN .
IMPORT msg = gt_fhhzd-msg subrc = sy- subrc FROM MEMORY ID 'ZHZD_PROCESS'.
REPORT zhzd_process.
DATA: msg TYPE char255.
PARAMETERS p_hzd TYPE ze_hzd.
PARAMETERS p_lx TYPE c .
CASE p_lx.
WHEN 'F'.
CALL FUNCTION 'Z_JSLHZD_PROCESS'
EXPORTING
hzd = p_hzd
IMPORTING
msg = msg
EXCEPTIONS
process_error = 1
OTHERS = 2.
WHEN 'T'.
CALL FUNCTION 'Z_JSLTHZD_PROCESS'
EXPORTING
hzd = p_hzd
IMPORTING
msg = msg
EXCEPTIONS
process_error = 1
OTHERS = 2.
WHEN 'M'.
CALL FUNCTION 'Z_MDHZD_PROCESS'
EXPORTING
hzd = p_hzd
IMPORTING
msg = msg
EXCEPTIONS
process_error = 1
OTHERS = 2.
ENDCASE.
EXPORT msg = msg subrc = sy -subrc TO MEMORY ID 'ZHZD_PROCESS'.
DATA: msg TYPE char255.
PARAMETERS p_hzd TYPE ze_hzd.
PARAMETERS p_lx TYPE c .
CASE p_lx.
WHEN 'F'.
CALL FUNCTION 'Z_JSLHZD_PROCESS'
EXPORTING
hzd = p_hzd
IMPORTING
msg = msg
EXCEPTIONS
process_error = 1
OTHERS = 2.
WHEN 'T'.
CALL FUNCTION 'Z_JSLTHZD_PROCESS'
EXPORTING
hzd = p_hzd
IMPORTING
msg = msg
EXCEPTIONS
process_error = 1
OTHERS = 2.
WHEN 'M'.
CALL FUNCTION 'Z_MDHZD_PROCESS'
EXPORTING
hzd = p_hzd
IMPORTING
msg = msg
EXCEPTIONS
process_error = 1
OTHERS = 2.
ENDCASE.
EXPORT msg = msg subrc = sy -subrc TO MEMORY ID 'ZHZD_PROCESS'.
5. 默认值,但是不显示
PARAMETERS:p_jsdlx LIKE ztjsd -jsdlx DEFAULT 'W' NO-DISPLAY .
6. 用来匹配模式与逻辑表达式 "p_num CO '0123456789.' p_num NA 'A....'"
1. CO / CN contains only or not : 只包含 不包含
CA / NA contains any or not any :包含任何一个 不包含任何一个CS / NS contain string or not :包含string 不包含stringCP / NP contains pattern or not : 包含模式 不包含模式
IF g_fiuser = space. "非财务用户
r_werks- sign = 'I' .
r_werks- option = 'NP' .
r_werks- low = '*' . "全部门店
APPEND r_werks.
CLEAR r_werks.
ELSE .
r_werks- sign = 'I' .
r_werks- option = 'CP' .
r_werks- low = '*' . "全部门店
APPEND r_werks.
CLEAR r_werks.
ENDIF .
r_werks- sign = 'I' .
r_werks- option = 'NP' .
r_werks- low = '*' . "全部门店
APPEND r_werks.
CLEAR r_werks.
ELSE .
r_werks- sign = 'I' .
r_werks- option = 'CP' .
r_werks- low = '*' . "全部门店
APPEND r_werks.
CLEAR r_werks.
ENDIF .
2.逻辑表达式
EQ或= 等于
NE或<>或>< 不等于
LT或< 小于
LE或<= 小于等于
GT或> 大于GE或>= 大于等于
7. 将特定的值查询后直接赋值到指定的变量中。
SELECT SINGLE name1 jyfs mdxz INTO (g_name1, g_jyfs,g_mdxz ) FROM t001w WHERE werks = p_werks.
8. DIV除之后,取的是整数部分,舍弃了小数部分的内容。如果想保留小数部分,需要使用‘/’
9. ON_CHANGE_OF 用来分组排序,在不同的组内进行排序。
LOOP AT gt_data ASSIGNING <fs_a>.
ON CHANGE OF <fs_a>-clas1 .
CLEAR : l_pm.
ENDON .
l_pm = l_pm + 1.
<fs_a>- pm = l_pm .
ON CHANGE OF <fs_a>-clas1 .
CLEAR : l_pm.
ENDON .
l_pm = l_pm + 1.
<fs_a>- pm = l_pm .
ENDLOOP .
10.*删除F8按钮.
APPEND 'CRET' TO gt_exclude.
CALL FUNCTION 'RS_SET_SELSCREEN_STATUS'
EXPORTING
p_status = sy-pfkey
TABLES
p_exclude = gt_exclude.
CALL FUNCTION 'RS_SET_SELSCREEN_STATUS'
EXPORTING
p_status = sy-pfkey
TABLES
p_exclude = gt_exclude.
11.BCALV_EDIT_04:使用INFORM来展示数据
* first check airline and connection
select single * from spfli into gs_spfli where carrid = g_carrid and connid = g_connid.
if sy- subrc ne 0 .
call function 'POPUP_TO_INFORM'
exporting
titel = text -i01
txt1 = text -i02
txt2 = text -i03
txt3 = text -i04
txt4 = text -i05.
else.
* §0.Lock your database table according to CARRID and CONNID
perform lock_sflight changing g_success .
if g_success eq 'X'.
call screen 100.
else .
message i000(0k ) with text- i10.
endif .
endif.
if sy- subrc ne 0 .
call function 'POPUP_TO_INFORM'
exporting
titel = text -i01
txt1 = text -i02
txt2 = text -i03
txt3 = text -i04
txt4 = text -i05.
else.
* §0.Lock your database table according to CARRID and CONNID
perform lock_sflight changing g_success .
if g_success eq 'X'.
call screen 100.
else .
message i000(0k ) with text- i10.
endif .
endif.
12.* 数量四舍五入 向上取值与向下取值 1.
1.CALL FUNCTION 'HR_NZ_ROUNDING_DECIMALS'
EXPORTING
value_in = gv_max " Input field with decimals
conv_dec = 0 " i Number of desired decimals for conversion
IMPORTING
value_out = gv_max. " Output field with rounded decimals
value_in = gv_max " Input field with decimals
conv_dec = 0 " i Number of desired decimals for conversion
IMPORTING
value_out = gv_max. " Output field with rounded decimals
2. a = 1.36 b = 1.34
CEIL( a/b ). "2
FLOOR( a/b ). "1
ABS( dobj ) 返回参数绝对值SIGN( dobj )返回参数符号:正数返回1,0返回0,负数返回-1.TRUNC( dobj )返回参数的整数部分FRAC( dobj )返回参数的小数部分CEIL( dobj )返回不小于输入参数的最小整数值FLOOR( dobj )返回不大于输入参数的最大整数值SQRT 平方根注意:函数名与左括号间不能有空格,括号与参数间必须有空格.
13.检查必须为数字
"折扣检查
l_str_len = strlen( gt_tab -netpr ).
CLEAR l_do_index.
DO l_str_len TIMES .
IF NOT '0123456789.' CA gt_tab-netpr+l_do_index( 1).
CONCATENATE gt_tab-msg '折扣必须为数字!' INTO gt_tab-msg.
ENDIF .
l_do_index = l_do_index + 1.
ENDDO .
l_str_len = strlen( gt_tab -netpr ).
CLEAR l_do_index.
DO l_str_len TIMES .
IF NOT '0123456789.' CA gt_tab-netpr+l_do_index( 1).
CONCATENATE gt_tab-msg '折扣必须为数字!' INTO gt_tab-msg.
ENDIF .
l_do_index = l_do_index + 1.
ENDDO .
"最好的方法定义一个P类型的,用Catch来把字符串(去掉空格后)赋值给这个P类型,如果返回值为0,就说明是数字~
14.ZFC_RT024:如果BAPI调用出错,直接跳出本次的调用PERFORM 则使用RETURN。程序块:FORM,MODULE,EVENT等。
1. CHECK: 后面跟一个表达式,当表达式的值为假(false),CHECK发生作用,退出循环LOOP或者处理程序 Processing Block.如果CEHCK在循环中,则退出当前的一次循环,从下一次循环继续执行,类似于CONTINUE.如果CHECK出现在循环外,则发生作用时,退出的是当前执行的程序块 Processing Block,如:FORM METHOD or EVENT.2. EXIT: EXIT出现在循环中,退出整个循环,程序从循环结束处开始继续执行。EXIT出现在循环外,退出的是当前的程序块:processing Block,如:FORM METHOD or EVENT。与RETURN类似。3. RETURN:使用RETURN来退出当前执行的程序块,不管是在LOOP中还是在Processing Block中,PS: 建议只在循环中使用EXIT,而不使用RETURN,在外部退出Processing Block中,使用RETURN。4. LEAVE PROGRAM: 直接退出当前程序。5. CONTINUE: 与CHECK类似,CHECK是有条件终止,CONTINUE是无条件终止。在循环中,结束此轮循环,继续下一轮循环。
6. STOP:结束当前块,从下一个块开始执行。这里的块指的是语句快。直接到END-OF-SELECTION.
15. 初始化field-symbols :
UNASSIGN <fs_gw_eban> .
16. 在界面显示正在执行的动作.
if SY -BATCH is initial . "SY-BATCH 正在后台执行程序
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
TEXT = '正在迁移中间数据...'.
endif.
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
TEXT = '正在迁移中间数据...'.
endif.
17. 解决筛选时出现筛选输入字段没有实际表中的字段那么长的问题。 定义参照的表和字段,对于自定义的字段使用intlen属性来设置
CLEAR: ls_fieldcat.
LOOP AT gt_fieldcat INTO ls_fieldcat.
CASE ls_fieldcat-fieldname .
WHEN 'MATNR'.
ls_fieldcat- ref_table = 'MARA' .
ls_fieldcat- ref_field = 'MATNR' .
* ls_fieldcat-intlen = 18.
ENDCASE .
MODIFY gt_fieldcat FROM ls_fieldcat .
ENDLOOP.
LOOP AT gt_fieldcat INTO ls_fieldcat.
CASE ls_fieldcat-fieldname .
WHEN 'MATNR'.
ls_fieldcat- ref_table = 'MARA' .
ls_fieldcat- ref_field = 'MATNR' .
* ls_fieldcat-intlen = 18.
ENDCASE .
MODIFY gt_fieldcat FROM ls_fieldcat .
ENDLOOP.
18.单位转换函数:
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = lv_in"输入的英文单位 IMPORTING output = lv_out."输出的中文单位 CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT' EXPORTING input = lv_in"输入的中文单位 IMPORTING output = lv_out."输出的英文单位
19.RENAMING WITH SUFFIX suffix
TYPES: BEGIN OF t_day,work TYPE c LENGTH 8,free TYPE c LENGTH 16,END OF t_day.DATA BEGIN OF week.INCLUDE TYPE t_day AS monday RENAMING WITH SUFFIX _mon.INCLUDE TYPE t_day AS tuesday RENAMING WITH SUFFIX _tue.INCLUDE TYPE t_day AS wednesday RENAMING WITH SUFFIX _wed....DATA END OF week.
20.ABAP的Parameter ID ,用来get/set值
Parameter ID 通常用于 Data element中,通过set/get方法存取它的值, 那么到底Parameter ID 在哪儿进行维护的呢? 要注意的是这个Parameter ID 是跨Client的,所以维护的时候要注意。
记住可维护表:TPARA 是有必要的
21.查询用户的权限列表: SUIM OR S_BCE_68001400
22. 四舍五入函数:
CALL FUNCTION 'HR_NZ_ROUNDING_DECIMALS'
EXPORTINGvalue_in = l_p " Input field with decimals
conv_dec = 0 " i Number of desired decimals for conversion
IMPORTING
value_out = l_p " Output field with rounded decimals
* EXCEPTIONS
* NO_ROUNDING_REQUIRED = 1 " No rounding required. (CONV_DEC > VALUE_IN dec)
* DECIMALS_GREATER_THAN_10 = 2 " Conversion only possible with decimals <= 10
* ROUNDING_ERROR = 3 " An error occurred during the decimal conversion
* OTHERS = 4.
posted on 2014-06-22 15:25 color_story 阅读(779) 评论(0) 编辑 收藏 举报