1, Session
不直接运行,而是将BDC程序生成session,通过SM35或者SAP标准程序RSBDCSUB或者 RSBDCBTC 触发。
优点:通过T-code SM35可以进行运行管理及日志管理,方便查错。
缺点:数据直到session被处理才能更新。
2, 用到的函数、程序
. 1, BDC_OPEN_GROUP.
2. BDC_INSERT
可在一个Session中插入多个BDC
3. BDC_CLOSE_GROUP.
触发程序:RSBDCSUB或者 RSBDCBTC,在BDC_CLOSE_GROUP.之后submit
3, 例子程序
通过session 批量更新payment block,Tcode:FB09
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
REPORT ztest_bdc_session. * update payment block by BDC DATA:git_bdcdata TYPE STANDARD TABLE OF bdcdata, gwa_bdcdata LIKE LINE OF git_bdcdata.. * open group PERFORM frm_open_group. REFRESH:git_bdcdata, git_messtab. * input document number PERFORM frm_bdc_dynpro USING 'SAPMF05L' '0102'. PERFORM frm_bdc_field USING 'RF05L-BELNR' '016000000'. PERFORM frm_bdc_field USING 'RF05L-BUKRS' '3250'. PERFORM frm_bdc_field USING 'RF05L-GJAHR' '2015'. PERFORM frm_bdc_field USING 'RF05L-BUZEI' '1'. PERFORM frm_bdc_field USING 'BDC_OKCODE' '/00'. * set payment block PERFORM frm_bdc_dynpro USING 'SAPMF05L' '0302'. PERFORM frm_bdc_field USING 'BSEG-ZLSPR' 'A'. * save PERFORM frm_bdc_field USING 'BDC_OKCODE' '=AE'. * 向session中插入BDC数据,处理多张凭证时,可以插入多个,本例子只插入1个 PERFORM frm_bdc_insert. * close group and trigger BDC session PERFORM frm_close_group. *&---------------------------------------------------------------------* *& Form FRM_BDC_INSERT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_bdc_insert . CALL FUNCTION 'BDC_INSERT' EXPORTING tcode = 'FB09' TABLES dynprotab = git_bdcdata EXCEPTIONS internal_error = 1 not_open = 2 queue_error = 3 tcode_invalid = 4 printing_invalid = 5 posting_invalid = 6 OTHERS = 7. IF sy-subrc <> 0. * error ENDIF. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_OPEN_GROUP *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_open_group . CALL FUNCTION 'BDC_OPEN_GROUP' EXPORTING client = sy-mandt group = 'BDC_SESSION' "SM35中的session名字,可以随便命名 keep = 'X' user = sy-uname EXCEPTIONS client_invalid = 1 destination_invalid = 2 group_invalid = 3 group_is_locked = 4 holddate_invalid = 5 internal_error = 6 queue_error = 7 running = 8 system_lock_error = 9 user_invalid = 10 OTHERS = 11. IF sy-subrc <> 0. * error RETURN. ENDIF. "sy-subrc ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_CLOSE_GROUP *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_close_group . CALL FUNCTION 'BDC_CLOSE_GROUP' EXCEPTIONS not_open = 1 queue_error = 2 OTHERS = 3. IF sy-subrc <> 0. ELSE. * Submit program RSBDCSUB to process the BDC session directly SUBMIT rsbdcsub WITH mappe EQ 'BDC_SESSION' "要触发的session名字 WITH z_verarb EQ 'X' WITH fehler EQ ' ' WITH logall EQ 'X' AND RETURN. ENDIF. ENDFORM. *----------------------------------------------------------------------* * Start new screen * *----------------------------------------------------------------------* FORM frm_bdc_dynpro USING i_program i_dynpro. CLEAR gwa_bdcdata. gwa_bdcdata-program = i_program. gwa_bdcdata-dynpro = i_dynpro. gwa_bdcdata-dynbegin = abap_true. APPEND gwa_bdcdata TO git_bdcdata. ENDFORM. "FRM_BDC_DYNPRO *&---------------------------------------------------------------------* *& Form FRM_BDC_FIELD *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_1131 text * -->P_LWA_CO07_BDgco_mATNR text *----------------------------------------------------------------------* FORM frm_bdc_field USING i_fnam i_fval. CLEAR gwa_bdcdata. gwa_bdcdata-fnam = i_fnam. gwa_bdcdata-fval = i_fval. "delete leading zero SHIFT gwa_bdcdata-fval LEFT DELETING LEADING space. APPEND gwa_bdcdata TO git_bdcdata. ENDFORM. " FRM_BDC_FIELD |
程序运行结果:
以下BDC Session 信息界面是RSBDCSUB输出的。
SM35:session ‘BDC_SESSION’已经被触发
FB09,运行后可以看到payment block字段值被赋成A
以上。
发表评论