【BDC】BDC录屏实现

1.简单屏幕

 1   REPORT ztest.
 2 
 3   DATA: lt_bdcdata TYPE tab_bdcdata.
 4 
 5 *建BDC数据
 6   PERFORM frm_build_bdc.
 7 *执行BDC
 8   PERFORM frm_proc_bdc.
 9 
10   FORM frm_build_bdc.
11 *  init
12     PERFORM bdc_dynpro TABLES lt_bdcdata USING 'SAPMV45A' '0101'.
13     PERFORM bdc_field TABLES lt_bdcdata USING 'BDC_OKCODE' '/00'.
14     PERFORM bdc_field TABLES lt_bdcdata USING 'VBAK-AUART' 'S001'.
15 
16 *  header
17     PERFORM bdc_dynpro TABLES lt_bdcdata USING 'SAPMV45A' '4001'.
18     PERFORM bdc_field TABLES lt_bdcdata USING 'BDC_OKCODE' '/00'.
19     PERFORM bdc_field TABLES lt_bdcdata USING 'KUAGV-KUNNR' 'H001'.
20 
21 *  header
22     PERFORM bdc_dynpro TABLES lt_bdcdata USING 'SAPMSSY0' '0120'.
23     PERFORM bdc_field TABLES lt_bdcdata USING 'BDC_CURSOR' '05/07'. "弹出屏幕,双击选择,需要CURSOR光标点
24     PERFORM bdc_field TABLES lt_bdcdata USING 'BDC_OKCODE' '=CHOO'.
25 
26 *  items
27 *    lv_posnr = lv_posnr + 10.
28     PERFORM bdc_dynpro TABLES lt_bdcdata USING 'SAPMV45A' '4001'.
29     PERFORM bdc_field TABLES lt_bdcdata USING 'RV45A-KETDAT' '2016.03.10'.
30     PERFORM bdc_field TABLES lt_bdcdata USING 'RV45A-KPRGBZ' 'D'.
31     PERFORM bdc_field TABLES lt_bdcdata USING 'VBKD-PRSDT' '2016.03.10'.
32     PERFORM bdc_field TABLES lt_bdcdata USING 'RV45A-MABNR(01)' 'A21005'.
33     PERFORM bdc_field TABLES lt_bdcdata USING 'RV45A-KWMENG(01)' '2'.
34     PERFORM bdc_field TABLES lt_bdcdata USING 'RV45A-KPRGBZ' 'D'.
35 
36 *  保存逻辑
37     PERFORM bdc_dynpro TABLES lt_bdcdata USING 'SAPMV45A' '4001'.
38     PERFORM bdc_field TABLES lt_bdcdata USING 'BDC_OKCODE' '=SICH'.
39     PERFORM bdc_field TABLES lt_bdcdata USING 'KUAGV-KUNNR' 'H001'.
40     PERFORM bdc_field TABLES lt_bdcdata USING 'KUWEV-KUNNR' 'H001'.
41     PERFORM bdc_field TABLES lt_bdcdata USING 'RV45A-KETDAT' '2016.03.10'.
42     PERFORM bdc_field TABLES lt_bdcdata USING 'RV45A-KPRGBZ' 'D'.
43     PERFORM bdc_field TABLES lt_bdcdata USING 'VBKD-PRSDT' '2016.03.10'.
44   ENDFORM.
45 
46   FORM frm_proc_bdc .
47   
48     DATA: l_mode(1) VALUE 'P'.
49     DATA: l_opt LIKE ctu_params.
50     DATA: l_message TYPE bapiret1-message.
51     DATA: lt_messtab TYPE TABLE OF bdcmsgcoll WITH HEADER LINE.
52   
53     CLEAR: l_opt.
54     l_opt-dismode = l_mode.
55     l_opt-updmode = 'S'.
56 
57     CALL TRANSACTION 'VA01' USING lt_bdcdata
58          OPTIONS FROM l_opt MESSAGES INTO lt_messtab.
59   ENDFORM.                    " FRM_PROC_BDC
60 *&---------------------------------------------------------------------*
61 *&      Form  bdc_dynpro
62 *&---------------------------------------------------------------------*
63   FORM bdc_dynpro  TABLES   pt_bdcdata STRUCTURE bdcdata
64                               "插入正确名称 <...>
65                       USING p_program TYPE bdc_prog
66                             p_dynpro  TYPE bdc_dynr.
67     CLEAR: pt_bdcdata.
68     pt_bdcdata-program  = p_program. "BDC程序名
69     pt_bdcdata-dynpro   = p_dynpro. "BDC屏幕编号
70     pt_bdcdata-dynbegin = 'X'.  "BDC 屏幕启动
71     APPEND pt_bdcdata.
72   ENDFORM.                    " BDC_DYNPRO
73 *&---------------------------------------------------------------------*
74 *&      Form  bdc_field
75 *&---------------------------------------------------------------------*
76 *       text
77 *----------------------------------------------------------------------*
78 *      -->PT_BDCDATA text
79 *      -->P_FNAM     text
80 *      -->P_FVAL     text
81 *----------------------------------------------------------------------*
82   FORM bdc_field  TABLES   pt_bdcdata STRUCTURE bdcdata
83                               "插入正确名称 <...>
84                       USING p_fnam TYPE fnam_____4
85                             p_fval  TYPE bdc_fval.
86 
87     CLEAR: pt_bdcdata.
88     pt_bdcdata-fnam = p_fnam. "BDC屏幕编号
89     pt_bdcdata-fval = p_fval.  "BDC 屏幕启动
90     APPEND pt_bdcdata.
91   ENDFORM.                    " BDC_DYNPRO
BDC sample

2.涉及行

 

  1 *&---------------------------------------------------------------------*
  2 *& Report  ZBDC
  3 *&
  4 *&---------------------------------------------------------------------*
  5 *&
  6 *&
  7 *&---------------------------------------------------------------------*
  8 
  9   REPORT zbdc.
 10 
 11   DATA: lt_bdcdata TYPE tab_bdcdata.
 12 
 13 *  建BDC数据
 14   PERFORM frm_build_bdcdata.
 15 *  执行BDC
 16   PERFORM frm_proc_bdc.
 17 
 18   FORM frm_build_bdcdata.
 19     DATA: lv_posnr TYPE vbap-posnr.
 20     DATA: lv_kwmeng TYPE vbap-kwmeng.
 21     DATA: lv_matnr TYPE vbap-matnr.
 22 *  init:初始化屏幕
 23     PERFORM bdc_dynpro TABLES lt_bdcdata USING 'SAPMV45A' '0101' .
 24     PERFORM bdc_field TABLES lt_bdcdata USING 'BDC_OKCODE' '/00'.
 25     PERFORM bdc_field TABLES lt_bdcdata USING 'VBAK-AUART' 'S001'.
 26 
 27 *  header
 28     PERFORM bdc_dynpro TABLES lt_bdcdata USING 'SAPMV45A' '4001'.
 29     PERFORM bdc_field TABLES lt_bdcdata USING 'BDC_OKCODE' '/00'.
 30     PERFORM bdc_field TABLES lt_bdcdata USING 'KUAGV-KUNNR' 'H001'.
 31 
 32 *选择销售组织屏幕,必须光标
 33     PERFORM bdc_dynpro TABLES lt_bdcdata USING 'SAPMSSY0' '0120'.
 34     PERFORM bdc_field TABLES lt_bdcdata USING 'BDC_CURSOR' '05/07'. "弹出屏幕,双击选择,需要CURSOR光标点
 35     PERFORM bdc_field TABLES lt_bdcdata USING 'BDC_OKCODE' '=CHOO'.
 36 
 37 *  items
 38 DO 3 TIMES.
 39     lv_posnr = lv_posnr + 10.
 40     lv_kwmeng = lv_kwmeng + 1.
 41 
 42     IF lv_posnr = '000010'.
 43       lv_matnr = 'A21005'.
 44     ELSEIF lv_posnr = '000020'.
 45       lv_matnr = 'A21011'.
 46     ELSEIF lv_posnr = '000030'.
 47       lv_matnr = 'A21014'.
 48     ENDIF.
 49 *处理数值字段在右侧问题
 50 *    WRITE lv_kwmeng TO l_fval NO-GROUPING LEFT-JUSTIFIED.
 51 *  主要问题集中在处理新增行的问题,从第二行开始循环,每次填入值在RV45A-MABNR(02)中
 52 *  通过定位按钮来处理
 53   IF sy-tabix = 1.
 54       PERFORM bdc_dynpro TABLES lt_bdcdata USING 'SAPMV45A' '4001'.
 55       PERFORM bdc_field TABLES lt_bdcdata USING 'BDC_OKCODE' '/00'.
 56 
 57       PERFORM bdc_field TABLES lt_bdcdata USING 'RV45A-MABNR(01)' lv_matnr.
 58       PERFORM bdc_field TABLES lt_bdcdata USING 'RV45A-KWMENG(01)' '1'.
 59 
 60       PERFORM bdc_dynpro TABLES lt_bdcdata USING 'SAPMV45A' '4001'.
 61       PERFORM bdc_field TABLES lt_bdcdata USING 'BDC_OKCODE' '=POPO'.
 62 
 63 *  屏幕编号
 64       PERFORM bdc_dynpro TABLES lt_bdcdata USING 'SAPMV45A' '0251'.
 65       PERFORM bdc_field TABLES lt_bdcdata USING 'BDC_OKCODE' '=POSI'.
 66       PERFORM bdc_field TABLES lt_bdcdata USING 'RV45A-POSNR' lv_posnr.
 67   ELSE.
 68       PERFORM bdc_dynpro TABLES lt_bdcdata USING 'SAPMV45A' '4001'.
 69       PERFORM bdc_field TABLES lt_bdcdata USING 'BDC_OKCODE' '/00'.
 70 
 71 
 72       PERFORM bdc_field TABLES lt_bdcdata USING 'RV45A-MABNR(02)' lv_matnr.
 73       PERFORM bdc_field TABLES lt_bdcdata USING 'RV45A-KWMENG(02)' '1'.
 74 
 75       PERFORM bdc_dynpro TABLES lt_bdcdata USING 'SAPMV45A' '4001'.
 76       PERFORM bdc_field TABLES lt_bdcdata USING 'BDC_OKCODE' '=POPO'.
 77 
 78 *  屏幕编号
 79       PERFORM bdc_dynpro TABLES lt_bdcdata USING 'SAPMV45A' '0251'.
 80       PERFORM bdc_field TABLES lt_bdcdata USING 'BDC_OKCODE' '=POSI'.
 81       PERFORM bdc_field TABLES lt_bdcdata USING 'RV45A-POSNR' lv_posnr.
 82   ENDIF.
 83 
 84 ENDDO.
 85 
 86 *保存逻辑
 87     PERFORM bdc_dynpro TABLES lt_bdcdata USING 'SAPMV45A' '4001'.
 88     PERFORM bdc_field TABLES lt_bdcdata USING 'BDC_OKCODE' '=SICH'.
 89 
 90   ENDFORM.
 91   FORM frm_proc_bdc .
 92 
 93     DATA: l_mode(1) VALUE 'A'.
 94     DATA: l_opt LIKE ctu_params.
 95     DATA: l_message TYPE bapiret1-message.
 96     DATA: lt_messtab TYPE TABLE OF bdcmsgcoll WITH HEADER LINE.
 97 
 98     CLEAR: l_opt.
 99     l_opt-dismode = l_mode.
100     l_opt-updmode = 'S'.
101 
102     CALL TRANSACTION 'VA01' USING lt_bdcdata
103          OPTIONS FROM l_opt MESSAGES INTO lt_messtab.
104   ENDFORM.                    " FRM_PROC_BDC
105 
106 
107 *  &---------------------------------------------------------------------*
108 *  &      Form  bdc_dynpro
109 *  &---------------------------------------------------------------------*
110   FORM bdc_dynpro  TABLES   pt_bdcdata STRUCTURE bdcdata
111                               "插入正确名称 <...>
112                       USING p_program TYPE bdc_prog
113                             p_dynpro  TYPE bdc_dynr.
114     CLEAR: pt_bdcdata.
115     pt_bdcdata-program  = p_program. "BDC程序名
116     pt_bdcdata-dynpro   = p_dynpro. "BDC屏幕编号
117     pt_bdcdata-dynbegin = 'X'.  "BDC 屏幕启动
118     APPEND pt_bdcdata.
119   ENDFORM.                    " BDC_DYNPRO
120 *  &---------------------------------------------------------------------*
121 *  &      Form  bdc_field
122 *  &---------------------------------------------------------------------*
123 *       text
124 *  ----------------------------------------------------------------------*
125 *      -->PT_BDCDATA text
126 *      -->P_FNAM     text
127 *      -->P_FVAL     text
128 *  ----------------------------------------------------------------------*
129   FORM bdc_field  TABLES   pt_bdcdata STRUCTURE bdcdata
130                               "插入正确名称 <...>
131                       USING p_fnam
132                             p_fval .
133     CLEAR: pt_bdcdata.
134     pt_bdcdata-fnam = p_fnam. "BDC屏幕编号
135     pt_bdcdata-fval = p_fval.  "BDC 屏幕启动
136     APPEND pt_bdcdata.
137   ENDFORM.                    " BDC_DYNPRO
BDC

 

问题:

遇到的问题:
1.源字段是一个数值类型,目标字段是一个字符类型,赋值后,从调试中看到字符类型字段里始终为空,百思不得其解。后来我想到,由于字符类型字段长度过长(255),而数值类型赋值到字符类型时默认使用了右对齐,造成实际内容在字符串的右端,从调试器中看不到,赋值到屏幕上也被截断了。
这个问题跟上面一样可以用两种方法解决:
1)target = source.
CONDENSE target. "去出多余空格,保留一个
2)WRITE source TO target LEFT-JUSTIFIED. "左移
DATA: source TYPE p DECIMALS 5 VALUE '20.10392'.
DATA: target TYPE char50.
target = source.
WRITE source TO target LEFT-JUSTIFIED.

2.录屏后会出现同一个字段对应不同的东西,比如 NEWKO 这里我既表示资产号,又表示供应商号。
前面FUNCTION里的输入参数你就要定义2个了,然后再付给NEWKO。

3.转换数据
有的客户系统屏幕用的是欧洲的金额的显示,像10.000,00
录屏时,给的金额显示10000.00,这里就需要转换数据才能完成录屏。
DATA LV_WRBTR(10) TYPE C.
** 转换数据\
DATA:
STRING1(1) TYPE C VALUE '.',
STRING2(1) TYPE C VALUE ','.
LV_WRBTR = I_WRBTR.
CONDENSE LV_WRBTR.
REPLACE STRING1 WITH STRING2 INTO LV_WRBTR.

posted on 2020-06-03 09:13  color_story  阅读(415)  评论(0编辑  收藏  举报

导航