BAPI操作手册
- 格式:doc
- 大小:3.60 MB
- 文档页数:17
物料主数据批导bapi 创建物料主数据,根据模板不同批导原材料,半成品,成品。
可根据实际需求对字段进⾏增删。
1 report zmmr_bapi_mm01 no standard page HEADING.2 type-POOLS:slis,truxs,icon.3 tables: sscrfields,lips,resb,marc,ckmlab02.4 data num type stprs_bapi.5 data flag type i. "标识符,如果不为1则不创建物料67 types:begin of ty_tab,8 head_material type matnr, "物料号9 head_ind_sector type mbrsh, "⾏业领域10 head_matl_type type mtart, "物料类型11 marc_plant type werks_d, "⼯⼚12 mvke_sales_org type vkorg, "销售组织13 mvke_distr_chan type vtweg, "分销渠道14 t_makt_matl_desc type maktx, "物料描述15 mara_base_uom type meins, "基本计量单位16 mara_matl_group type matkl, "物料组17 mara_extwg type extwg, "客户18 mara_item_cat type mtpos_mara, "普通项⽬组类别19 t_marm_unit_of_wt type gewei, "重量单位20 mara_wrkst type wrkst, "基本物料21 mara_ihivi type adge_ihivi, "是否客供22 mara_zeinr type dzeinr, "客户物料编码23 mvke_dwerk type maktx, "交货⼯⼚24 mvke_sktof type sktof, "现⾦折扣25 t_mlan_taxclass1 type taxkm, "税分类26 mvke_matl_stats type stgma, "物料统计组27 mvke_acct_assgt type ktgrm, "科⽬设置组28 mvke_item_cat type mtpos, "项⽬类别组29 marc_availcheck type mtvfp, "可⽤性检查30 mara_trans_grp type tragr, "运输组31 marc_loadinggrp type ladgr, "装载组32 marc_pur_group type ekgrp, "采购组33 marc_batch_mgmt type xchpf, "批次管理标⽰34 marc_auto_p_ord type kautb, "⾃动采购订单标识35 marc_webaz type webaz, "收货处理时间36 marc_insmk type insmk_mat, "过账到检验库存37 marc_mrp_group type disgr, "MRP组38 marc_maabc type maabc, "ABC标识39 marc_mrp_type type dismm, "MRP类型40 marc_mrp_ctrler type dispo, "MRP控制者41 marc_lotsizekey type disls, "批量42 marc_minlotsize type bstmi, "最⼩批量43 marc_round_val type bstrf, "舍⼊值44 marc_proc_type type beskz, "采购类型45 marc_lgpro type lgpro, "⽣产仓储地点46 marc_rgekz type rgekz, "反冲47 marc_lgfsb type lgfsb, "外部采购仓储地点48 marc_sm_key type fhori, "计划边际码49 marc_plnd_delry type plifz, "计划交货时间50 marc_sbdkz type sbdkz, "集中/独⽴51* mpop_prmod TYPE mpop-prmod, "预测模型52 mbew_val_class type bklas, "评估级别53 mbew_ml_settle type ck_ml_abst, "价格确定54 mbew_std_price type ck_pvprs_1, "标准价格55 mbew_moving_pr type ck_pvprs_1, "移动平均价56 mbew_price_ctrl type vprsv, "价格控制57 mbew_price_unit type peinh, "价格单位58 mbew_hrkft type hrkft, "原始组59 mbew_orig_mat type hkmat, "物料来源60 marc_losgr type ck_losgr, "成品核算批量61 end of ty_tab.6263 types:begin of ty_tab2,64 head_material type matnr, "物料号65 head_ind_sector type mbrsh, "⾏业领域66 head_matl_type type mtart, "物料类型67 marc_plant type werks_d, "⼯⼚68 mvke_sales_org type vkorg, "销售组织69 mvke_distr_chan type vtweg, "分销渠道70 t_makt_matl_desc type maktx, "物料描述71 mara_base_uom type meins, "基本计量单位72 mara_matl_group type matkl, "物料组73 mara_extwg type extwg, "客户74 mara_spart type spart, "产品组75 mara_item_cat type mtpos_mara, "普通项⽬组类别76 t_marm_unit_of_wt type gewei, "重量单位77 mara_formt type formt, "替代料标识78 mara_wrkst type wrkst, "基本物料79 mara_zeinr type dzeinr, "客户物料编码80 mvke_dwerk type maktx, "交货⼯⼚81 mvke_sktof type sktof, "现⾦折扣82 t_mlan_taxclass1 type taxkm, "税分类83 mvke_matl_stats type stgma, "物料统计组84 mvke_acct_assgt type ktgrm, "科⽬设置组85 mvke_item_cat type mtpos, "项⽬类别组86 marc_availcheck type mtvfp, "可⽤性检查87 mara_trans_grp type tragr, "运输组88 marc_loadinggrp type ladgr, "装载组89 marc_ekgrp type ekgrp, "采购组90 marc_kautb type kautb, "⾃动采购单91 marc_xchpf type xchpf, "批次管理92 marc_webaz type webaz, "收货处理时间93 marc_mrp_group type disgr, "MRP组94 marc_mrp_type type dismm, "MRP类型95 marc_mrp_ctrler type dispo, "MRP控制者96 marc_lotsizekey type disls, "批量⼤⼩97 marc_bstmi type bstmi, "最⼩批量⼤⼩98 marc_bstrf type bstrf, "舍⼊值99 marc_proc_type type beskz, "采购类型100 marc_sobsl type sobsl, "特殊采购类型101 marc_lgpro type lgpro, "⽣产仓储地点102 marc_lgfsb type lgfsb, "外部采购仓储地点103 marc_dzeit type dzeit, "⽣产时间104 marc_plifz type plifz, "计划交货时间105 marc_eisbe type eisbe, "安全库存106 marc_sm_key type fhori, "计划边际码107 marc_strgr type strgr, "策略组108 marc_vrmod type vrmod, "消耗模式109 marc_vint1 type vint1, "逆向消耗期间110 marc_vint2 type vint2, "向前消耗期间111 marc_altsl type altsl, "选择⽅法112 marc_sbdkz type sbdkz, "集中/独⽴113 mpop_prmod type mpop-prmod, "预测模型114 mbew_val_class type bklas, "评估级别115 mbew_ml_settle type ck_ml_abst, "价格确定116 mbew_std_price type ck_pvprs_1, "标准价格117 mbew_price_ctrl type vprsv, "价格控制118 mbew_orig_mat type hkmat, "物料来源119 marc_awsls type awsls, "差异码120 marc_losgr type ck_losgr, "成本核算批量121 end of ty_tab2.122123 data:it_tab type table of ty_tab , "原材料124 wa_tab type ty_tab.125 data:it_tab2 type table of ty_tab2, "成品126 wa_tab2 type ty_tab2.127128*输⼊参数129 data: headdata type bapimathead, "表头数据130 clientdata type bapi_mara, "基本数据131 clientdatax type bapi_marax,132 plantdata like bapi_marc, "⼯⼚数据133 plantdatax like bapi_marcx,134 forecastparameters type bapi_mpop, "预测135 forecastparametersx type bapi_mpopx,136 planningdata type bapi_mpgd, "计划137 planningdatax type bapi_mpgdx,138 valuationdata type bapi_mbew, "评估数据139 valuationdatax type bapi_mbewx,140 warehousenumberdata type bapi_mlgn, "仓库数据141 warehousenumberdatax type bapi_mlgnx,142 salesdata type bapi_mvke, "销售数据143 salesdatax type bapi_mvkex,144 storagetypedata type bapi_mlgt, "存储类型数据145 storagetypedatax type bapi_mlgtx.146147*表参数148 data: materialdescription type table of bapi_makt with header line, "描述 149 unitsofmeasure type table of bapi_marm with header line, "单位 150 unitsofmeasurex type table of bapi_marmx with header line,151 taxclassifications type table of bapi_mlan with header line, "税分类 152 return like table of bapiret2 with header line. "错误信息153154 data pr_unit type meins. "基本单位155 data pr_unit2 type meins. "重量单位156157 data: begin of gt_out occurs 0, "保存return信息158 text(255),159 end of gt_out.160161*TYPES:BEGIN OF ty_fieldnames ,162* name TYPE CHAR255,163*END OF ty_fieldnames.164*DATA it_fname TYPE TABLE OF ty_fieldnames WITH HEADER LINE.165 data:begin of it_fname occurs 0,166 name type char255,167 end of it_fname.168169170 SELECTION-screen begin of block blk_001 with frame title text-001 . "选择⽂件路径171 parameters:p_file like rlgrap-filename.172 SELECTION-screen end of block blk_001.173 SELECTION-screen: uline /1(82).174 SELECTION-screen: uline 83(83).175 SELECTION-screen begin of block blk_002 with frame title text-002. "确定创建物料类型176 parameters:radio_1 radiobutton group radi, "原材料177 radio_2 radiobutton group radi. "半成品/成品178 SELECTION-screen end of block blk_002.179180181 SELECTION-screen function key 1. "应⽤⼯具栏增加按钮182183 initialization.184 write icon_change_text as icon to sscrfields-functxt_01+0(4).185 sscrfields-functxt_01+4(*) = '下载模板'."分配字符位置186187 at SELECTION-screen.188 perform selection_screeen. "模板下载189190191 at SELECTION-screen on value-REQUEST for p_file .192 perform open.193194 START-of-SELECTION.195 if radio_1 = 'X'.196 perform upload_file. "上传数据197 perform mm01_1. "执⾏批导(原材料).198 else.199 perform upload_file2. "上传数据200 perform mm01_2. "执⾏批导(成品/半成品)201 endif.202203204 end-of-SELECTION.205 perform result_message. "显⽰执⾏结果206207*&---------------------------------------------------------------------*208*& Form MM01209*&---------------------------------------------------------------------*210* text211*----------------------------------------------------------------------*212* --> p1 text213* <-- p2 text214*----------------------------------------------------------------------*215 form mm01_1.216 loop at it_tab into wa_tab.217*前导0218 call function'CONVERSION_EXIT_ALPHA_INPUT'219 exporting220 input = wa_tab-head_material221 importing222 output = wa_tab-head_material.223224*判断物料是否以存在225 select single * from marc where matnr = wa_tab-head_material and werks = wa_tab-marc_plant. 226 if sy-subrc = 0.227 concatenate wa_tab-head_material '物料在' wa_tab-marc_plant '⼯⼚已存在!' into gt_out-text. 228 append gt_out.229 clear gt_out.230 continue.231 endif.232233 if wa_tab-mbew_moving_pr = ''.234 concatenate wa_tab-head_material '->原材料的移动平均价格为空' into gt_out-text.235 append gt_out.236 clear gt_out.237 continue.238 endif.239240 call function'CONVERSION_EXIT_ALPHA_INPUT'"科⽬设置组241 exporting242 input = wa_tab-mvke_acct_assgt243 importing244 output = wa_tab-mvke_acct_assgt.245 call function'CONVERSION_EXIT_ALPHA_INPUT'"可⽤性检查246 exporting247 input = wa_tab-marc_availcheck248 importing249 output = wa_tab-marc_availcheck.250 call function'CONVERSION_EXIT_ALPHA_INPUT'"运输组251 exporting252 input = wa_tab-mara_trans_grp253 importing254 output = wa_tab-mara_trans_grp.255 call function'CONVERSION_EXIT_ALPHA_INPUT'"装载组256 exporting257 input = wa_tab-marc_loadinggrp258 importing259 output = wa_tab-marc_loadinggrp.260 call function'CONVERSION_EXIT_ALPHA_INPUT'"MRP组261 exporting262 input = wa_tab-marc_mrp_group263 importing264 output = wa_tab-marc_mrp_group.265 call function'CONVERSION_EXIT_ALPHA_INPUT'"MRP控制者266 exporting267 input = wa_tab-marc_mrp_ctrler268 importing269 output = wa_tab-marc_mrp_ctrler.270 call function'CONVERSION_EXIT_ALPHA_INPUT'"计划边际值271 exporting272 input = wa_tab-marc_sm_key273 importing274 output = wa_tab-marc_sm_key.275276*判断是否客供,提⽰价格信息277 if wa_tab-mara_ihivi <> 'X'.278 clear num.279 num = wa_tab-mbew_std_price / wa_tab-mbew_price_unit.280 case wa_tab-marc_maabc. "ABC标识281 when 'A'.282 if num > 100.283 perform pop_confirm using wa_tab-marc_maabc wa_tab-head_material. 284 if flag = 1. "为否时执⾏下⼀物料285 clear flag.286 continue.287 endif.288 endif.289 when 'B'.290 if num > 5.291 perform pop_confirm using wa_tab-marc_maabc wa_tab-head_material. 292 if flag = 1.293 clear flag.294 continue.295 endif.296 endif.297 when others.298 perform pop_confirm using wa_tab-marc_maabc wa_tab-head_material. 299 if flag = 1.300 clear flag.301 continue.302 endif.303 endcase.304 endif.305306 clear headdata.307 headdata-material = wa_tab-head_material.308 headdata-matl_type = wa_tab-head_matl_type.309 headdata-ind_sector = wa_tab-head_ind_sector.310 headdata-basic_view = 'X'. "基本数据视图311 headdata-sales_view = 'X'. "销售视图312 headdata-purchase_view = 'X'. "采购视图313 headdata-mrp_view = 'X'. "物料需求计划(MRP)视图314* headdata-forecast_view = 'X'. "预测视图315 headdata-warehouse_view = 'X'. "⼯作计划视图316 headdata-account_view = 'X'. "会计视图317 headdata-cost_view = 'X'. "成本视图318319*基本数据320 clear pr_unit.321 perform frm_unit using wa_tab-mara_base_uom changing pr_unit."基本单位 322 clear: clientdata.323 clientdata-base_uom = pr_unit. "基本计量单位324 clientdata-matl_group = wa_tab-mara_matl_group. "物料组325 clientdata-item_cat = wa_tab-mara_item_cat. "普通项⽬类别组326 clientdata-trans_grp = wa_tab-mara_trans_grp. "运输组327 clientdata-extmatlgrp = wa_tab-mara_extwg. "客户328 clientdata-basic_matl = wa_tab-mara_wrkst. "基本物料329 clientdata-high_visc = wa_tab-mara_ihivi. "是否客供330 clientdata-document = wa_tab-mara_zeinr. "客户物料编码331 clear clientdatax.332 clientdatax-base_uom = 'X'. "基本计量单位333 clientdatax-matl_group = 'X'.334 clientdatax-item_cat = 'X'.335 clientdatax-net_weight = 'X'.336 clientdatax-trans_grp = 'X'.337 clientdatax-extmatlgrp = 'X'.338 clientdatax-basic_matl = 'X'.339 clientdatax-high_visc = 'X'.340 clientdatax-document = 'X'.341342*⼯⼚级别数据343 clear:plantdata.344 plantdata-plant = wa_tab-marc_plant. "⼯⼚345 plantdata-availcheck = wa_tab-marc_availcheck. "可⽤性检查346 plantdata-loadinggrp = wa_tab-marc_loadinggrp. "装载组347 plantdata-pur_group = wa_tab-marc_pur_group. "采购组348 plantdata-batch_mgmt = wa_tab-marc_batch_mgmt. "批次管理标⽰349 plantdata-auto_p_ord = wa_tab-marc_auto_p_ord. "⾃动采购订单标识350 plantdata-gr_pr_time = wa_tab-marc_webaz. "⾃动采购订单标识351 plantdata-ind_post_to_insp_stock = wa_tab-marc_insmk. "过账到检验库存 352 plantdata-mrp_group = wa_tab-marc_mrp_group. "MRP组353 plantdata-abc_id = wa_tab-marc_maabc. "ABC标识354 plantdata-mrp_type = wa_tab-marc_mrp_type. "MRP类型355 plantdata-mrp_ctrler = wa_tab-marc_mrp_ctrler. "MRP控制者356 plantdata-lotsizekey = wa_tab-marc_lotsizekey. "批量357 plantdata-minlotsize = wa_tab-marc_minlotsize. "最⼩批量358 plantdata-round_val = wa_tab-marc_round_val. "舍⼊值359 plantdata-proc_type = wa_tab-marc_proc_type. "采购类型360 plantdata-iss_st_loc = wa_tab-marc_lgpro. "⽣产仓储地点361 plantdata-backflush = wa_tab-marc_rgekz. "反冲362 plantdata-sloc_exprc = wa_tab-marc_lgfsb. "外部采购仓储地点363 plantdata-sm_key = wa_tab-marc_sm_key. "计划边际码364 plantdata-plnd_delry = wa_tab-marc_plnd_delry. "计划交货时间365 plantdata-dep_req_id = wa_tab-marc_sbdkz. "集中/独⽴366 plantdata-lot_size = wa_tab-marc_losgr. "批量产品核算367 clear plantdatax.368 plantdatax-plant = wa_tab-marc_plant.369 plantdatax-availcheck = 'X'.370 plantdatax-loadinggrp = 'X'.371 plantdatax-pur_group = 'X'.372 plantdatax-batch_mgmt = 'X'.373 plantdatax-auto_p_ord = 'X'.374 plantdatax-gr_pr_time = 'X'.375 plantdatax-ind_post_to_insp_stock = 'X'.376 plantdatax-mrp_group = 'X'.377 plantdatax-abc_id = 'X'.378 plantdatax-mrp_type = 'X'.379 plantdatax-mrp_ctrler = 'X'.380 plantdatax-lotsizekey = 'X'.381 plantdatax-minlotsize = 'X'.382 plantdatax-round_val = 'X'.383 plantdatax-proc_type = 'X'.384 plantdatax-iss_st_loc = 'X'.385 plantdatax-backflush = 'X'.386 plantdatax-sloc_exprc = 'X'.387 plantdatax-sm_key = 'X'.388 plantdatax-plnd_delry = 'X'.389 plantdatax-dep_req_id = 'X'.390 plantdatax-lot_size = 'X'.391392*销售数据393 clear salesdata.394 salesdata-sales_org = wa_tab-mvke_sales_org. "销售组织395 salesdata-distr_chan = wa_tab-mvke_distr_chan. "分销渠道396 salesdata-delyg_plnt = wa_tab-mvke_dwerk. "交货⼯⼚397 salesdata-cash_disc = wa_tab-mvke_sktof. "现⾦折扣标志398 salesdata-matl_stats = wa_tab-mvke_matl_stats. "物料统计组399 salesdata-acct_assgt = wa_tab-mvke_acct_assgt. "科⽬设置组400 salesdata-item_cat = wa_tab-mvke_item_cat. "项⽬类别组401 clear salesdatax.402 salesdatax-sales_org = wa_tab-mvke_sales_org.403 salesdatax-distr_chan = wa_tab-mvke_distr_chan.404 salesdatax-delyg_plnt = 'X'.405 salesdatax-cash_disc = 'X'.406 salesdatax-matl_stats = 'X'.407 salesdatax-acct_assgt = 'X'.408 salesdatax-item_cat = 'X'.409410**预测411* CLEAR:forecastparameters,forecastparametersx.412* forecastparameters-plant = wa_tab-marc_plant. "⼯⼚413* forecastparameters-fore_model = wa_tab-mpop_prmod. "预测模型414* forecastparametersx-plant = wa_tab-marc_plant.415* forecastparametersx-fore_model = 'X'.416417*会计、成本418 clear valuationdata.419 valuationdata-val_area = wa_tab-marc_plant.420 valuationdata-val_class = wa_tab-mbew_val_class. "评估级别421 valuationdata-ml_settle = wa_tab-mbew_ml_settle. "价格确定422 valuationdata-std_price = wa_tab-mbew_std_price. "标准价格423 valuationdata-moving_pr = wa_tab-mbew_moving_pr. "移动平均价424 valuationdata-price_unit = wa_tab-mbew_price_unit. "价格单位425 valuationdata-price_ctrl = wa_tab-mbew_price_ctrl. "价格控制426 valuationdata-orig_group = wa_tab-mbew_hrkft. "原始组427 valuationdata-orig_mat = wa_tab-mbew_orig_mat. "物料来源428 clear valuationdatax.429 valuationdatax-val_area = wa_tab-marc_plant.430 valuationdatax-val_class = 'X'.431 valuationdatax-ml_settle = 'X'.432 valuationdatax-price_ctrl = 'X'.433 valuationdatax-price_unit = 'X'.434 valuationdatax-moving_pr = 'X'.435 valuationdatax-std_price = 'X'.436 valuationdatax-orig_group = 'X'.437 valuationdatax-orig_mat = 'X'.438439*物料描述440 clear materialdescription[].441 materialdescription-langu_iso = 'ZH'.442 materialdescription-matl_desc = wa_tab-t_makt_matl_desc.443 append materialdescription.444445*单位446 clear unitsofmeasure[].447 unitsofmeasure-alt_unit = pr_unit.448 unitsofmeasure-unit_of_wt = wa_tab-t_marm_unit_of_wt.449 append unitsofmeasure.450 clear unitsofmeasurex[].451 unitsofmeasurex-alt_unit = pr_unit.452 unitsofmeasurex-unit_of_wt = 'X'.453 append unitsofmeasurex.454455*税分类456 clear taxclassifications[].457 taxclassifications-depcountry = 'CN'.458 taxclassifications-tax_type_1 = 'MWST'.459 taxclassifications-taxclass_1 = wa_tab-t_mlan_taxclass1. "税分类460 append taxclassifications.461462 call function'BAPI_MATERIAL_SAVEDATA'463 exporting464 headdata = headdata465 clientdata = clientdata466 clientdatax = clientdatax467 plantdata = plantdata468 plantdatax = plantdatax469 forecastparameters = forecastparameters470 forecastparametersx = forecastparametersx471 valuationdata = valuationdata472 valuationdatax = valuationdatax473 salesdata = salesdata474 salesdatax = salesdatax475 importing476 return = return477 tables478 materialdescription = materialdescription[]479 unitsofmeasure = unitsofmeasure[]480 unitsofmeasurex = unitsofmeasurex481 taxclassifications = taxclassifications[].482 if return-type = 'E'or return-type = 'A'.483 call function'BAPI_TRANSACTION_ROLLBACK'.484 concatenate wa_tab-head_material '原材料—>' return-message into gt_out-text. 485 append gt_out.486 clear gt_out.487 else.488 call function'BAPI_TRANSACTION_COMMIT'489 exporting490 wait = 'X'.491 concatenate wa_tab-head_material '物料创建成功。
BAPI使用经验总结总结人:曾德军QQ : 25117827011.挑选需要的bapi:可以根据前台对应的事务代码到scn里查找对应的bapi,也可以到bapi浏览器里继续根据业务和参数再确认一下哪个bapi是对的,然后根据功能描述到网页上搜索一下,和业务顾问沟通一下,看对应的可能的bapi是不是自己需要的用法。
2.使用bapi:对于一个全新的没有用过的bapi,它的用法一是要找准需要输入的参数并且正确输入进去,二是要能及时解决bapi的报错。
找参数的话,每个bapi里一般都有get detail的方法,这个方法带出来的参数基本跟使用bapi时的参数是一样的,也可以参考bapi最终在标准表里应该生成的正确的结果,比对一下对应的字段的值,看看有没有对应的参数需要输入的,还可以参考bapi文档里的例子,以及网上使用的例子,或者参考系统里bapi的调用,查查别人是怎么用这个bapi的,这样基本参数都可以找到,剩下的偶尔的一些比较特殊的参数可能要多研究,多试试了。
一般bapi报错可以按顺序排查5种原因:1.输入的参数对应数据在前台也做不过去,数据有问题,需要业务顾问重新提供可用数据(这种还包含一种特殊的情况,就是BAPI对应的事务代码使用相同的数据可以实现,但是bapi执行的话就会少执行一两个步骤,导致虽然bapi 执行成功但是有些数据不对,这种一般是业务配置问题,因为不同的配置会影响其执行结果) 2.数据前台可以做过去,但是在往bapi里传参数的时候一些参数的值没有传对,需要调整下代码或者传值逻辑;3.参数的值传对了,但是bapi的传入参数多了或者少了,这时候需要根据业务顾问和报错信息来推断,尝试增加或者删除某些参数,不过如果系统里有很多已经做好了的例子的话,可以参考调用,查看别的例子里都用的哪些参数,如果例子比较多的话,也挺好找出来的。
例子不多,就要多推断,多尝试,多搜索和沟通了;4.前三种问题都排除了,那就可能是增强导致的报错,不是标准报错,这时候就需要跟踪查找增强来解决了。
BAPI操作手册作者:丑儿MSN: njchouer@网上看到一篇关于这样的文章,但是自己手动操作的时候还是出现了一些问题,现在把它整理成文档的形式,以供参考。
这里我非常感谢我的好朋友杜善晶,谢谢她给了我很大的帮助。
---题记(丑儿2007-10-31)1)给BAPI创建数据结构(1)事务代码:SE11- 输入结构的名称:ZBAPI_ORDER_STATUS_IMPORT输入如下的3个字段激活保存2)给BAPI创建数据结构(2)事务代码:SE11- 输入结构的名称:ZBAPISTAT输入如下字段激活保存2)创建函数事务代码:SE37创建函数组:转到—〉函数组—〉创建组输入函数组和函数组短文本保存输入Function module:Z_BAPI_GET_ORDER_STA TUSWW 点创建输入函数模块和函数组() 短文本SA VE属性选择状态如下Import输入如下的参数Export输入如下参数Tables选择参数选择goto –〉Global data 定义全局变量激活保存输入代码如下Types:begin of Type_tj02t,istat like tj02t-istat,txt04 like tj02t-txt04,txt30 like tj02t-txt30,end of type_tj02t.DATA:* Declarations for TABLE parameterT_BAPISTAT like ZBAPISTAT occurs 0, G_BAPISTAT like ZBAPISTAT,* Table for object textst_tj02t type type_tj02t occurs 0,g_tj02t type type_tj02t.* Structure for return messages DATA:BEGIN OF MESSAGE,MSGTY LIKE SY-MSGTY,MSGID LIKE SY-MSGID,MSGNO LIKE SY-MSGNO,MSGV1 LIKE SY-MSGV1,MSGV2 LIKE SY-MSGV2,MSGV3 LIKE SY-MSGV3,MSGV4 LIKE SY-MSGV4,END OF MESSAGE.Source code中增加对应代码激活保存增加的代码如下:FUNCTION Z_BAPI_GET_ORDER_STATUSWW.*"---------------------------------------------------------------------- *"*"Local interface:*" IMPORTING*" VALUE(BAPI_ORDER_STATUS_IMPORT) TYPE ZBAPI_ORDER_STATUS_IMPORT*" EXPORTING*" VALUE(RETURN) TYPE BAPIRETURN*" TABLES*" T_BAPISTAT STRUCTURE ZBAPISTAT *"---------------------------------------------------------------------- DATA:l_aufnr LIKE afko-aufnr,l_objnr LIKE jest-objnr.********************************************* Check if order exists******************************************** SELECT SINGLE aufnrFROM afkoINTO l_aufnrWHERE aufnr = BAPI_ORDER_STATUS_IMPORT-orderid.IF sy-subrc NE 0.CLEAR message.message-msgty = 'E'.message-msgid = 'Z3'.message-msgno = '000'.message-msgv1 = BAPI_ORDER_STATUS_IMPORT-orderid.PERFORM set_return_message USING messageCHANGING return.IF 1 = 2.* The only reason to include this statement, that will obviously* never execute, is that it will create a referecence so that you* can find out where a particular message is being used. This* functionality is used by the BAPIs programmed by SAPMESSAGE e000(z3).ENDIF.ENDIF.CHECK return IS INITIAL.********************************************* Read order status********************************************CONCATENATE 'OR' BAPI_ORDER_STATUS_IMPORT-orderid INTO l_objnr. IF BAPI_ORDER_STATUS_IMPORT-i_excludeinactive = 'X'.SELECT objnr stat inactFROM jestINTO TABLE t_bapistatWHERE objnr = l_objnr ANDinact <> 'X'.ELSE.SELECT objnr stat inactFROM jestINTO TABLE t_bapistatWHERE objnr = l_objnr.ENDIF.IF sy-subrc <> 0.* No object status foundCLEAR message.message-msgty = 'E'.message-msgid = 'Z3'.message-msgno = '001'.message-msgv1 = BAPI_ORDER_STATUS_IMPORT-orderid.PERFORM set_return_message USING messageCHANGING return.IF 1 = 2.MESSAGE e001(z3).ENDIF.ENDIF.CHECK return IS INITIAL.********************************************* Read order status texts********************************************SELECT istat txt04 txt30FROM tj02tINTO TABLE t_tj02tFOR ALL ENTRIES IN t_bapistatWHERE istat = t_bapistat-stat ANDspras = BAPI_ORDER_STATUS_IMPORT-i_spras.SORT t_tj02t BY istat.LOOP AT t_bapistat INTO g_bapistat.READ TABLE t_tj02tWITH KEY istat = g_bapistat-stat BINARY SEARCHINTO g_tj02t.IF sy-subrc = 0.MOVE:g_tj02t-txt04 TO g_bapistat-txt04,g_tj02t-txt30 TO g_bapistat-txt30.MODIFY t_bapistat FROM g_bapistat TRANSPORTING txt04 txt30.ENDIF.ENDLOOP.ENDFUNCTION.***INCLUDE LZBAPISTATUSF01 .*----------------------------------------------------------------------**&---------------------------------------------------------------------**& Form SET_RETURN_MESSAGE*&---------------------------------------------------------------------** This routine is used for setting the BAPI return message.* The routine is a standard routine for BAPIs that handles the message* structure for the BAPIRETURN structure. It has been copied from the* BAPI Company Code Getlist*----------------------------------------------------------------------** -->P_MESSAGE text* <--P_RETURN text*----------------------------------------------------------------------*form SET_RETURN_MESSAGE USING VALUE(P_MESSAGE) LIKE MESSAGECHANGING P_RETURN LIKE BAPIRETURN.CHECK NOT MESSAGE IS INITIAL.CALL FUNCTION 'BALW_BAPIRETURN_GET'EXPORTINGTYPE = P_MESSAGE-MSGTYCL = P_MESSAGE-MSGIDNUMBER = P_MESSAGE-MSGNOPAR1 = P_MESSAGE-MSGV1PAR2 = P_MESSAGE-MSGV2PAR3 = P_MESSAGE-MSGV3PAR4 = P_MESSAGE-MSGV4* LOG_NO = ' '* LOG_MSG_NO = ' 'IMPORTINGBAPIRETURN = P_RETURNEXCEPTIONSOTHERS = 1.endform. " SET_RETURN_MESSAG3)创建API Method事务代码:SWO1输入对象/接口类型:ZORDERSTAW 点创建输入如下的参数确定保存选择实用程序—>API方法 Add方法输入Function module:Z_BAPI_GET_ORDER_STATUSWW确定选择选择确定选择编辑—>更改版本状态—>对象类型—>To Implemented确定Note that the BAPI wizard has added a wrapper class for the function module so it can be sued as method in the business object.选择Choose menu Goto->Program to display the program4)最后一步释放事务代码:SE37释放模组事务代码:SWO1释放业务对象类型选择对象类型—>修改版本状态到—>已实现释放对象类型(把光标放在对象类型上)选择编辑—更改版本状态—对象类型—已释放Release the BAPI as a method in the BOR把光标放在zproder…ZgetOrderSt…选择编辑—更改版本状态—对象类型组件—已释放保存后退生成选择对象类型—生成成功的信息5)查看BAPI事务代码:BAPI结束附件:/abap/bapi/example.htm。
Enhancement to the BAPI based on existing SAP database tables以下是SAP建议的步骤Actions for an Enhancement Based on ExistingSAP Database Tables对现有的sap数据库表的增强动作Purpose :目的We assume that the customer wants to append his own fields to SAP tables involved in a BAPI and/or include additional existing fields from these tables in the BAPI after the fact.我们假设客户想把自己的数据附加到sap表中,这些sap表使用了BAPI并且/或者Process FlowIn this case, the following steps are required at most:1. Extending the database tableThe customer must perform the following actions for each SAP table to append that is involved in the BAPI:a. Create a data structure that contains the customer fields that will be added tothe table.b. Then add an APPEND to the database table that includes the data structurecreated in a) above.An example is available under Appending Customer Fields.2. Identifying and/or creating the BAPI table extensionsThe customer has to make sure that each SAP table that is used for this type ofenhancement has its corresponding BAPI table extension. This is done by reading the documentation on the BAPI extension parameters. If a required table extension has not been supplied by SAP, then the customer is responsible for creating it. Make sure to observe the following guidelines:The naming convention for BAPI table extensions is<namespace>BAPI_TE_<table_name>.If you cannot follow this naming convention due to thelength restriction for structure names, reduce thename accordingly, but try to keep its context clear.Each table should only have one table extension.Therefore, if several BAPIs use the same table, theywill have to share the table extension.Excepti on:If a BAPI has two or more parameters that refer to the same database table, then a separate BAPI table extension is created for each of these BAPI parameters. Thenaming convention in this case is<namespace>BAPI_TE<table_name><consecutive_number>. In our example, ourtable extensions would be namedYBAPI_TE_STRAVELAG1,YBAPI_TE_STRAVELAG2, and so on.The structure of the BAPI table extension mustcontain all the identified key fields of the table towhich the BAPI table extension relates. The tableextension does not initially contain any other fieldsexcept the key fields.3. Enhancing the BAPI table extensionsThe APPEND technique is now used to enhance the BAPI table extensions that you identified and/or created above. As mentioned above, we can differentiate between the following cases:a. If the customer wants to add additional fields from the SAP table for the BAPItable extension, he adds these fields directly to the APPEND structure.b. If the customer has appended his own fields to the corresponding SAP table,then he should include the same data structure – with the customer fields – inthe APPEND as the one used to extend the database table.c. If you want to both add existing fields from the SAP table to the BAPI andappend customer fields, proceed as follows:First add all existing fields from the corresponding table to the APPENDstructure.Then add the INCLUDE that contains the new customer fields to the sameAPPEND structure. Please note that you have to use the same INCLUDE inboth the database table and in the corresponding BAPI table extension.4. Programming the customer exitsThe first customer exit gives customers the option of performing data checks, whilethe second exit allows the further processing of the data passed on to the BAPI (alsosee Actions by the BAPI Developer). The standard rules for customer exits apply andtransactions SMOD( SAP internal) and CMOD(customers) are used for maintainingthem.5. Filling ExtensionIn before a BAPI callBefore a BAPI that involves extended tables can be called, you have to make sure thatthe enhancements are written to parameter ExtensionIn. ExtensionIn is filled asfollows for each data record that is written to the container:o Field VALUEPART1 is first filled with the keys that identify the table lines.o Fields VALUEPART1 through VALUEPART4 are then filled with the values ofthe customer fields in the proper sequence. By structuring the container in thisway, its contents can be converted with a single MOVE command in thestructure of the BAPI table extension.The part for implementation can be described in pseudo-coding as follows:FOR every extendable table XREPEATFill ExtensionIn-VALUEPART1 with key values.Fill VALUEPART1 through VALUEPART4 with data in sequence.APPEND ExtensionIn.UNTIL table X is processedEND FORException:It is not possible to give the container a key value in Create() BAPIs withinternal number assignment, as these values are generated in the BAPI itself.In this case, you should give the container an initial key value. The BAPIdeveloper has already anticipated the assignment of the key generated in theBAPI to the BAPI table extension.A detailed programming example on filling the ExtensionIn parameter and calling theenhanced BAPI is available in the Examples.5. Evaluating ExtensionOut after a BAPI callThe conversion of the ExtensionOut container to a structure may have to beimplemented, depending on your specific situation.以下是SAP说明的实施这种方式的前提(LIB 4312)实施a(Appending customer fields to SAP tables,将数据传入标准表的自建字段中) 1 建了一个结构(ZBAPITEXT)2 将结构APPEND到MARAAPPEND 的方法参考:“E:\禹明的文档\SAP\个人总结\ABAP4\表\透明表\SE11维护DDIC\为SAP 标准表APPEND, INCLUDE 自定义结构”3 建立BAPI Table Extension作用:BAPI table extensions are help structures that allow the customer enhancement of BAPIs. They must exist for every SAP database table that is to be used in the customer enhancement concept. These BAPI table extensions are used during the data import to copy the customer enhancements from the container (ExtensionIn ) to the BAPI interface, and to fill the additional fields of the database table. During data export, the BAPI table extensions are used to copy data from a customer table extension and to place it in the ExtensionOut parameter. Places where BAPI table extensions are used and how their use must be implemented in detail are described in Actions by the BAPI Developer.• 注意事项:A separate BAPI table extension must be created for every database tablethat the BAPI developer thinks could be enhanced. Please note, however, that each table can only have one table extension. Therefore, if several BAPIs use the same table, they will have to share the table extension. BAPI Table Extension 只能用C 类型或者similar data types 的字段Exception: If a BAPI has two or more parameters that refer to the same database table,then a separate BAPI table extension is created for each of these BAPIparameters. The naming convention in this case isBAPI_TE<table_name><consecutive_number>. In our example, the BAPI table extensions would be called BAPI_TE_STRAVELAG1,BAPI_TE_STRAVELAG2, and so onSE11:BAPI_TE_MARA (这个结构SAP 已经建好了,如果没有,要自己建)表的KEY ,一定要有的要添数据的SAP 表名,如果有多个BAPI_TE 结构,以MARA1,MARA2类推4 SE11:BAPI_TE_MARAX(这个结构SAP已经建好了,如果没有,要自己建)步骤同3 (这个结构用来标识BAPI_TE_MARA的哪个字段是需要的,典型的BAPI逻辑)字段名必须是ZZTEXT,和BAPI_TE_MARA的相同,类型必须是BAPIUPDATE5 函数参数EXTENSIONIN REF的结构BAPIPAREX分析•STRUCTUREThe STRUCTURE field contains the name of the BAPI table extension to which therespective data record refers. In turn, because a table extension is allocated to exactlyone database table, the program can determine the extended table in which to savethe data record.•VALUEPART1 through VALUEPART4Each data record of the extension container contains – in addition to the name of thetable extension – the key values and the values that will be inserted in the additionaltable fields. The key values have to be passed on in order to determine the line in thedatabase table where the data in the data record will be written.Exception:It is not possible to pass on the key value(s) in Create()BAPIs with internalnumber assignment, as these values are generated in the BAPI itself. Forinformation on how to proceed in the case of Create() BAPIs, refer to Actionsfor Enhancements Based on Existing Database Tables.6 Filling ExtensionIn before a BAPI call参照程序效果实施b(Using existing database fields,读取标准表的自建字段值,与a刚好相反) 1 继续利用实施a的结构:BAPI_TE_MARA2 SE11:MARA的自建字段中存在以下数据3 通过BAPI_MATERIAL_GET_ALL会自动读取MARA-ZZTEXT字段。
SAP项目中开发用到的BAPI:MM模块1、BAPI_MATERIAL_SAVEDATA 创建物料主数据注意参数EXTENSIONIN的使用,可以创建自定义字段例如WA_BAPI_TE_MARA-MATERIAL = ITAB_UP-MATNR.T_EXTENSIONIN-STRUCTURE = 'BAPI_TE_MARA'.T_EXTENSIONIN-VALUEPART1 = WA_BAPI_TE_MARA.APPEND T_EXTENSIONIN.WA_BAPI_TE_MARAX-MATERIAL = ITAB_UP-MATNR.T_EXTENSIONINX-STRUCTURE = 'BAPI_TE_MARAX'.T_EXTENSIONINX-VALUEPART1 = WA_BAPI_TE_MARAX.APPEND T_EXTENSIONINX.2、BAPI_OBJCL_CREATE 分类视图的创建3、BAPI_OBJCL_GETCLASSES 分类视图得到详细信息4、BAPI_MATERIAL_SAVEREPLICA 物料视图的扩充5、BAPI_GOODSMVT_CREATE 创建物料凭证注意表T158G可以决定goodsmvt_code6、BAPI_GOODSMVT_CANCEL 冲销物料凭证7、BAPI_PR_CREATE 创建PR8、BAPI_PO_CREATE1 创建PO9、BAPI_PO_CHANGE 修改PO和删除PO10、WS_REVERSE_GOODS_ISSUE 冲销交货单的过账发货11、BAPI_RESERVATION_CREATE1 创建预留12、BAPI_RESERVATION_CHANGE 修改和删除预留SD模块1、BAPI_SALESORDER_CREATEFROMDAT2 创建销售订单2、SD_SALESDOCUMENT_CREATE 创建销售订单3、BAPI_OUTB_DELIVERY_CREATE_SLS 根据销售订单创建交货单4、BAPI_BILLINGDOC_CREATEMULTIPLE 创建发票,注意参数ref_doc_ca5、BAPI_SALESORDER_CHANGE 修改或者删除销售订单6、MB_CANCEL_GOODS_MOVEMENT 冲销交货单的过账发货7、BAPI_BILLINGDOC_CANCEL 发票的冲销PM模块1、BAPI_OBJCL_CREATE 、BAPI_OBJCL_CHANGE、BAPI_OBJCL_GETDETAIL计量点通用属性导入2、MEASUREM_DOCUM_RFC_SINGLE_001 计量凭证创建FI模块1、K_HIERARCHY_TABLES_READ 成本要素组明细2、BAPI_ACC_DOCUMENT_POST 创建会计凭证3、BAPI_ACC_DOCUMENT_REV_POST 反冲会计凭证PS模块1、BAPI_PS_INITIALIZATION、BAPI_BUS2001_CREATE、BAPI_PS_PRECOMMIT 创建项目定义2、BAPI_PS_INITIALIZATION、BAPI_BUS2054_CREATE_MULTI、BAPI_PS_PRECOMMIT 创建WBS 创建WBS的时候,注意参数wbs_left和wbs_up,这个是创建有层级的WBS必须要填写的3、KBPP_EXTERN_UPDATE_CO 修改项目和WBS的预算BAPI_MATERIAL_SAVEDATA 建立/更改物料主档BAPI_OBJCL_CREATE 建立/更改物料主档分类BAPI_OBJCL_CHANGE 建立/更改物料主档分类CLMM_MAINTAIN_CLASSIFICATIONS 批量建立/更改物料主档分类CLAF_CLASSIFICATION_OF_OBJECTS 显示物料主档分类特性值BAPI_MATERIAL_EXISTENCECHECK 检查物料主档是否存在BAPI_MATERIAL_GETLIST 显示物料主档明细BAPI_PO_CREATE1 建立采购单BAPI_PO_CHANGE 更改采购单BAPI_PO_GETDETAIL 显示采购单明细BAPI_PO_RELEASE 核发采购单BAPI_REQUISITION_CREATE 建立请购单BAPI_REQUISITION_CHANGE 更改请购单BAPI_REQUISITION_GETDETAIL 显示请购单明细BAPI_REQUISITION_RELEASE_GEN 核发请购单BAPI_CHARACT_CREATE 建立特性BAPI_CHARACT_CHANGE 更改特性BAPI_CHARACT_DELETE 删除特性BAPI_CHARACT_RENAME 重新命名特性BAPI_CHARACT_GETDETAIL 读取特性属性BAPI_CHARACT_ADDLONGTEXT 设定特性或数值的长文BAPI_CHARACT_REMOVELONGTEXT 删除特性或数值的长文BAPI_CHARACT_GETLONGTEXT 读取数值的特性长文CARD_CHARACTERISTIC_READ 显示特性值的值列表BAPI_CLASS_CREATE 建立类别BAPI_CLASS_CHANGE 变更类别BAPI_CLASS_DELETE 删除类别BAPI_CLASS_GETDETAIL 读取类别资讯(取分类下特性及特性值) BAPI_CLASS_EXISTENCECHECK 检查物件存在性BAPI_VENDOR_GETDETAIL 显示供应商明细BAPI_VENDOR_EXISTENCECHECK 检查存在性BAPI_MATERIALGROUP_GET_LIST 读取物料群组/物料群组说明BAPI_GOODSMVT_CREATE 过帐物料异动BAPI_GOODSMVT_CANCEL 冲帐(取消)物料异动BAPI_GOODSMVT_GETDETAIL 显示物料异动明细BAPI_GOODSMVT_GETITEMS 显示物料文件的明细清单。
abap函數bapi_requisition_release用法-回复abap函数bapi_requisition_release用法引言:ABAP是一种高级商务应用编程语言,被广泛应用于SAP系统中。
BAPI (Business Application Programming Interface)是SAP提供的一组可重复使用的函数模块,用于与SAP系统进行交互。
在ABAP中,有一个非常有用的BAPI函数叫做bapi_requisition_release,用于释放采购申请。
本文将一步一步介绍bapi_requisition_release函数的用法,包括它的功能、参数、输入和输出等方面的内容。
第一步:功能介绍bapi_requisition_release函数的主要功能是释放(approval release)采购申请。
在SAP系统中,采购申请需要经过审批流程才能被批准,而该函数可以自动化地完成这一过程,提高工作效率。
第二步:参数介绍bapi_requisition_release函数有以下几个重要的参数:- OBJECT_TYPE:指定对象类型,对于采购申请来说,应该是REQ (Requisition)。
- OBJECT_KEY:指定对象键,即采购申请的编号。
通过该参数,系统可以定位并处理特定的采购申请。
- RELEASE_CODE:指定释放码,用于标识释放的类型。
通常有多个释放码可以选择,例如,01表示技术批准,02表示财务批准等。
- REL_CODETO:指定待释放的编码。
该编码指示了释放码的属性,比如是否必须释放。
第三步:输入参数设置在使用bapi_requisition_release函数之前,我们需要准备好相应的输入参数。
以将采购申请编号为"123456"的申请进行技术批准为例,下面是设置输入参数的示例代码:DATA: ls_input TYPE bapireqrel,lt_input TYPE TABLE OF bapireqrel,lt_return TYPE TABLE OF bapiret2.ls_input-object_type = 'REQ'.ls_input-object_key = '123456'.ls_input-release_code = '01'.ls_input-rel_codeto = 'B'.APPEND ls_input TO lt_input.在以上示例代码中,我们创建了一个结构体ls_input和一个表格lt_input 用于存储输入参数。
BAPI Step by Step ExampleAbout the exampleThis BAPI reads system status for a production order from table JEST and system status text from table TJ02T此BAPI是从JEST读取生产订单系统状态和从表TJ02T中读取文本状态Step1:定义BAPI用到的结构体在此步骤里,BAPI中用到功能模块的表和参数均已在这里定义使用数据类型-结构定义以下结构:结构1:ZBAPI_ORDER_STATUS_IMPORT包含以下字段∙ORDERID Order number (Keyfield) 订单号∙SPRAS Language 语言∙ExcludeInactive - Checkbox - Exclude inactive status结构2:ZBAPISTAT:OBJNR like JEST-OBJNR∙STAT like J_STAT∙INACT like J_INACT∙TXT04 like J_TXT04∙TXT30 like J_TXT30∙OBJNR like J_OBJNRImportant note:You will have to define a structure for every parameter in the BAPI. You cannot use the same structures used in existing applications because BAPI structures are frozen when BAPIs are released and then there are restrictions on changing them.你必须为每个BAPI中的参数定义结构,当BAPI被释放后是限制更改他们的,因为bapi会被冻结,所以你不能在存在的应用中使用同一个结构ZBAPI_ORDER_STATUS_IMPORT –结构1ZBAPISTAT ---结构2第二步:写入功能模块Important notes:∙每个BAPI必须有他们自己的函数组(功能组)∙在属性tab里记住选择存取类型是Remote Enabled module,否则功能模块不能通过RFC来invoke它做为一个BAPI来使用∙输入/输出参数仅仅能被BY VALUE 对于RFC enabled的功能模块∙我们在此仅创建了一个BAPI,但你能创建相关的BAPI在同一模块池中,使得他们能共享全局信息功能模块的属性设定输入参数这里定义功能模块的输入参数为订单输入参数的结构,即是引入结构ZBAPI_ORDER_STATUS_IMPORT做为bapi_order_status_import的参照Export ParametersTablesCodeNotes:∙The subroutine SET_RETURN_MESSAGE is a standard routine used for BAPIs that use the BAPIRETURN structure∙SET_RETURN_MESSAGE子程序是在BAPI中标准的子程序用来使用BAPIRETURN 结构∙在FORM Z_BAPI_GET_ORDER_SYSTEM_STATUS里有个测试是IF 1=2,如果这测试结果为真,则信息就显示,但是这个条件永远不会为真,所以我们就不可能在BAPI里显示出这个信息,为什么要包含这个的原因是,为信息创建一个参照,因此…这时SAP标准控制方法,拷贝公司代码层面的代码GetList BAPI.∙In form Z_BAPI_GET_ORDER_SYSTEM_STATUS there is a test IF 1 = 2. If the test is true a message is displayed. The condition will obviously never be true, and we will never want to display a message in a BAPI. The reason why it is includedis, that it create a reference for the message, so that the WHERE USEDfunctionality can be used for the message. This is the SAP standard way to handle it, copied from the Company Code GetList BAPI.INCLUDE LZBAPISTATUSUXX****************************************************************** THIS FILE IS GENERATED BY THE FUNCTION LIBRARY.** NEVER CHANGE IT MANUALLY, PLEASE!*****************************************************************INCLUDE LZBAPISTATUSU02."Z_BAPI_GET_ORDER_SYSTEM_STATUSINCLUDE LZBAPISTATUSTOP - Global dataFUNCTION-POOL ZBAPISTATUS. "MESSAGE-ID Z3 Types:begin of Type_tj02t,istat like tj02t-istat,txt04 like tj02t-txt04,txt30 like tj02t-txt30,end of type_tj02t.DATA:* Declarations for TABLE parameterT_BAPISTAT like ZBAPISTAT occurs 0,G_BAPISTAT like ZBAPISTAT,* Table for object textst_tj02t type type_tj02t occurs 0,g_tj02t type type_tj02t.* Structure for return messagesDATA:BEGIN OF MESSAGE,MSGTY LIKE SY-MSGTY,MSGID LIKE SY-MSGID,MSGNO LIKE SY-MSGNO,MSGV1 LIKE SY-MSGV1,MSGV2 LIKE SY-MSGV2,MSGV3 LIKE SY-MSGV3,MSGV4 LIKE SY-MSGV4,END OF MESSAGE.INCLUDE LZBAPISTATUSF01 - Subroutines***INCLUDE LZBAPISTATUSF01 .*----------------------------------------------------------------------**&---------------------------------------------------------------------**& Form SET_RETURN_MESSAGE*&---------------------------------------------------------------------** This routine is used for setting the BAPI return message.* The routine is a standard routine for BAPIs that handles the message * structure for the BAPIRETURN structure. It has been copied from the * BAPI Company Code Getlist*----------------------------------------------------------------------** -->P_MESSAGE text* <--P_RETURN text*----------------------------------------------------------------------*form SET_RETURN_MESSAGE USING VALUE(P_MESSAGE) LIKE MESSAGECHANGING P_RETURN LIKE BAPIRETURN. CHECK NOT MESSAGE IS INITIAL.CALL FUNCTION 'BALW_BAPIRETURN_GET'EXPORTINGTYPE = P_MESSAGE-MSGTYCL = P_MESSAGE-MSGIDNUMBER = P_MESSAGE-MSGNOPAR1 = P_MESSAGE-MSGV1PAR2 = P_MESSAGE-MSGV2PAR3 = P_MESSAGE-MSGV3PAR4 = P_MESSAGE-MSGV4* LOG_NO = ' '* LOG_MSG_NO = ' 'IMPORTINGBAPIRETURN = P_RETURNEXCEPTIONSOTHERS = 1.endform. " SET_RETURN_MESSAGEFUNCTION Z_BAPI_GET_ORDER_STATUSFUNCTION z_bapi_get_order_system_status.*"----------------------------------------------------------------------*"*"Local interface:*" IMPORTING*" VALUE(I_AUFNR) TYPE AUFNR*" VALUE(I_SPRAS) TYPE SPRAS DEFAULT SY-LANGU*" VALUE(I_EXCLUDEINACTIVE) TYPE CHAR1 OPTIONAL *" EXPORTING*" VALUE(RETURN) TYPE BAPIRETURN*" TABLES*" T_BAPISTAT STRUCTURE ZBAPISTAT*"------------------------------------------------------***"Local interface:*" IMPORTING*" VALUE(I_AUFNR) TYPE AUFNR*" VALUE(I_SPRAS) TYPE SPRAS DEFAULT SY-LANGU *" VALUE(I_EXCLUDEINACTIVE) TYPE CHAR1 OPTIONAL *" EXPORTING*" VALUE(RETURN) TYPE BAPIRET2*" TABLES*" T_BAPISTAT STRUCTURE ZBAPISTATDATA:l_aufnr LIKE afko-aufnr,l_objnr LIKE jest-objnr.********************************************* Check if order exists********************************************SELECT SINGLE aufnrFROM afkoINTO l_aufnrWHERE aufnr = BAPI_ORDER_STATUS_IMPORT-orderid.IF sy-subrc NE 0.CLEAR message.message-msgty = 'E'.message-msgid = 'Z3'.message-msgno = '000'.message-msgv1 = BAPI_ORDER_STATUS_IMPORT-orderid.PERFORM set_return_message USING messageCHANGING return.IF 1 = 2.* The only reason to include this statement, that will obviously * never execute, is that it will create a referecence so that you * can find out where a particular message is being used. This * functionality is used by the BAPIs programmed by SAP MESSAGE e000(z3).ENDIF.ENDIF.CHECK return IS INITIAL.********************************************* Read order status********************************************CONCATENATE 'OR' BAPI_ORDER_STATUS_IMPORT-orderid INTO l_objnr.IF BAPI_ORDER_STATUS_IMPORT-i_excludeinactive = 'X'.SELECT objnr stat inactFROM jestINTO TABLE t_bapistatWHERE objnr = l_objnr ANDinact <> 'X'.ELSE.SELECT objnr stat inactFROM jestINTO TABLE t_bapistatWHERE objnr = l_objnr.ENDIF.IF sy-subrc <> 0.* No object status foundCLEAR message.message-msgty = 'E'.message-msgid = 'Z3'.message-msgno = '001'.message-msgv1 = BAPI_ORDER_STATUS_IMPORT-orderid.PERFORM set_return_message USING messageCHANGING return.IF 1 = 2.MESSAGE e001(z3).ENDIF.ENDIF.CHECK return IS INITIAL.********************************************* Read order status texts********************************************SELECT istat txt04 txt30FROM tj02tINTO TABLE t_tj02tFOR ALL ENTRIES IN t_bapistatWHERE istat = t_bapistat-stat ANDspras = BAPI_ORDER_STATUS_IMPORT-i_spras.SORT t_tj02t BY istat.LOOP AT t_bapistat INTO g_bapistat.READ TABLE t_tj02tWITH KEY istat = g_bapistat-stat BINARY SEARCHINTO g_tj02t.IF sy-subrc = 0.MOVE:g_tj02t-txt04 TO g_bapistat-txt04,g_tj02t-txt30 TO g_bapistat-txt30.MODIFY t_bapistat FROM g_bapistat TRANSPORTING txt04 txt30.ENDIF.ENDLOOP.ENDFUNCTION.STEP 3 - Create the API Method Using the BAPI WIZARDThe BAPI wizard is used toTo expose the remote function module as a BAPI. The wizard will generate some additional code, so the function module is a valid method of the BOR. This allows the BAPi to be called as a workflow method in addition to be called by an outside program.Note: Each functionmodule corresponds to a method in the BORGo to the Busines Object Builder SWO1.You can either create the new Object type as a subtype of an existing business object or create a new business object from scratch. In this example it would be obvious to create the Object type as a subtype of BUS2005 Production order. However, to illustrate how to create a new Object type from scratch, we will do this.In the Object/Interface type field write the name of the new Business Object: ZORDERSTAT. Press enter and fill in the additional fields necessary to create the object type.Supertype: Not relevant because we are creating our object from scratch Program. This is the name of the program where the wizard generates code for the Object type, NOT the function module we craeted earlier. The program name must not be the name of an existinbg program.Press enter and create the new business object. Note that when you create the business object a standard interface, an attribute ObjectType and the methods ExistenceCheck and Display are automatically generated. These cannot be changed !The next step is to add the Z_BAPI_GET_ORDER_STATUS method to the business object. Select Utillities -> API methods -> Add method and write the name of the functionmodule in the dialogbox. Next the dialogbox show below will be shown. This is the start screen of the BAPI wizard. Proceed with wizardby pressing the button.After you have finished the wizard, tyou will notice that the ZGetOrderStatus has been added to the business object:You can doubleclick on the method to see its properties. To use the business object you must change the Object type status to Implemented. Use menu Edit->Change releases status->Object type->To implemented. No you can test thge object (Press F8).Note that the BAPI wizard has added a wrapper class for the function module so it can be sued as method in the business object. Choose menuGoto->Program to display the program:***** Implementation of object type ZORDERSTAT*****INCLUDE <OBJECT>.BEGIN_DATA OBJECT. " Do not change.. DATA is generated* only private members may be inserted into structure privateDATA:" begin of private," to declare private attributes remove comments and" insert private attributes here ..." end of private,KEY LIKE SWOTOBJID-OBJKEY.END_DATA OBJECT. " Do not change.. DATA is generatedBEGIN_METHOD ZGETORDERSTATUS CHANGING CONTAINER. DATA:BAPIORDERSTATUSIMPORT LIKEZBAPI_ORDER_STATUS_IMPORT,RETURN LIKE BAPIRETURN,TBAPISTAT LIKE ZBAPISTAT OCCURS 0.SWC_GET_ELEMENT CONTAINER 'BapiOrderStatusImport'BAPIORDERSTATUSIMPORT.SWC_GET_TABLE CONTAINER 'TBapistat' TBAPISTAT.CALL FUNCTION 'Z_BAPI_GET_ORDER_STATUS'EXPORTINGBAPI_ORDER_STATUS_IMPORT = BAPIORDERSTATUSIMPORT IMPORTINGRETURN = RETURNTABLEST_BAPISTAT = TBAPISTATEXCEPTIONSOTHERS = 01.CASE SY-SUBRC.WHEN 0. " OKWHEN OTHERS. " to be implementedENDCASE.SWC_SET_ELEMENT CONTAINER 'Return' RETURN.SWC_SET_TABLE CONTAINER 'TBapistat' TBAPISTAT.END_METHOD.STEP 4 - Final stepsWhen the Business object has been checked and the documentation created, the following steps must be carried out:∙Release the BAPI function module (in the Function Builder).∙Release the business object type (in the BOR ObjectType -> Change release status to -> Implemented ).∙Release the BAPI as a method in the BOR (Release the methods you has created - Set the cursor on the method thenEdit -> Change release status -> Object type component -> To released )∙For potential write BAPIs: Release the IDoc and its segmentsYou can now display the BAPI in the BAPI Explorer:。