The function bapi_goodsmvt_create calls an instance.

Source: Internet
Author: User

ReportZmb31.
Tables: Mseg, mkpf, rm07m, t158b, t001l, msegk.

Data: Mat_docLikeBapi2017_gm_head_ret-mat_doc.

Data: Save_codeLikeSy-ucomm,
OK _codeLikeSy-ucomm,
Loc_msg (50),
GmngaLikeAfru-gmnga,
MtsnrLikeRm07m-mtsnr,
Errflag ..

Data:Begin OfGt_afpoOccurs 0.
Include StructureAfpo.
Data:End OfGt_afpo.

Data: GmheadLikeBapi1__gm_head_01.

Data:Begin OfGmcode.
Include StructureBapi1__gm_code.
Data:End OfGmcode.

Data:Begin OfMthead.
Include StructureBapi1__gm_head_ret.
Data:End OfMthead.

Data:Begin OfItabOccurs 100.
Include StructureBapi1__gm_item_create.
Data:End OfItab.

Data:Begin OfErrmsgOccurs 10.
Include StructureBapiret2.
Data:End OfErrmsg.

initialization .
t001l-lgort = 'bg01' .
mseg-lgort = 'bg01' .
mseg-werks = '123' .
mkpf-bldat = sy-datum.
mkpf-budat = sy-datum.
t158b-bwart = '20140901' .
* rm07m-sobkz = ''. "special stock
rm07m-werks = '123' .
rm07m-lgort = 'bg01' .
mseg-erfme = 'pc' .
gmcode-gm_code = '02' .

* ********* Gmcode-gm_code Value Meaning *******
* ******* 01 mb01
* ******* 02 mb31
* ******* 03 mb1a
* ******* 04 mb1b
* ******* 05 mb1c
* ******* 06 mb11
* ******* 07 mb04

Gmhead-pstng_date = sy-datum."Mkpf-bldat.
Gmhead-doc_date = sy-datum."Mkpf-budat.
Gmhead-pr_uname = sy-uname.

Itab-material = '123' .
Itab-plant = '123' .
Itab-stge_loc = 'Bg01' .
Itab-move_type = '123' .
Itab-spec_stock = 'Bg01' ..
Itab-entry_qnt = '6' .
Itab-entry_uom = 'Ea' .
Itab-po_number = '123' .
Itab-po_item = '123' .
Itab-mvt_ind = 'B' .
Itab-move_mat = '123' .
Itab-move_plant = '123' .
Itab-move_stloc = 'Bg01' .
Itab-nb_slips = 1 .

AppendItab.

Call Function 'Bapi _ goodsmvt_create'
Exporting
Goodsmvt_header = gmhead
Goodsmvt_code = gmcode
Importing
Goodsmvt_headret = mthead
Materialdocument = mat_doc
Tables
Goodsmvt_item = itab
Return= Errmsg.

Loop At Errmsg.
Clear Loc_msg.
Concatenate 'Posting successful! ' Errmsg- Message Into Loc_msg.
If Errmsg- Type EQ 'E' .
Message Errmsg- Message Type 'E' .
Errflag = 'X' .
Else .
Message Loc_msg Type 'S' .
Endif .
Endloop .

If Errflag Is Initial .
Commit Work And Wait .
Clear Loc_msg.
If Sy-subrc Ne 0 .
Message 'Posting operation error. Please try again later! ' Type 'E' .
Exit .
Else .
Concatenate 'Material credential :' Mat_doc 'Created successfully! ' Into Loc_msg.
Message I000 (znyj13) With Loc_msg.

Gmhead-ref_doc_no = '' .
Gmhead-header_txt = '' .
Mseg-matnr = '' .
Msegk-mat_kdauf = '' .
Msegk-mat_kdpos = '' .
Mseg-erfmg = '' .
Rm07m-mtsnr = '' .
Gmnga = '' .
Mkpf-bktxt = '' .
Endif .
Else .
Message 'This is not the correct sending ticket or the credential has been created! ' Type 'E' .
Endif .

Call Function 'Bapi _ transaction_commit'
Exporting
Wait='X'.

---------------------------- 261/262 return material for production orders ------------------------

 

ReportTest.
* Title data of material creden
Data:

Li_gm_headType Standard Table OfBapi1__gm_head_01,
Rochelle gm_headLikeBapi1__gm_head_01,
* Allocate transactions for bapi goods movementCode
Li_gm_codeType Standard Table OfBapi1__gm_code,
Rochelle gm_codeLikeBapi1__gm_code,

* Return document number
Rochelle mat_docLikeBapi2017_gm_head_ret-mat_doc,

* Credential item
Li_gm_itemType Standard Table OfBapi1__gm_item_create,
Rochelle gm_itemLikeBapi1__gm_item_create,

*-------------------------
Li_returnType Standard Table OfBapiret2,
Rochelle returnTypeBapiret2,
* Error flag
Rochelle rflag (1)Type C.

* & lt;/span>
* & form callbapi
* & lt;/span>
* Text
* Rows *
* fill in the header data

L_gm_head-pstng_date = sy-datum.
L_gm_head-doc_date = sy-datum.
AppendRochelle gm_headToLi_gm_head.
* Allocate transaction code
L_gm_code-gm_code ='03'.
AppendRochelle gm_codeToLi_gm_code.

* Delivery details
L_gm_item-material = '123' . "10 410a
L_gm_item-plant = '123' .
L_gm_item-stge_loc = '123' .
L_gm_item-move_type = '123' . "Mobile type (Inventory Management)
* L_gm_item-mvt_ind = 'F '.
L_gm_item-entry_qnt = '1' .
L_gm_item-entry_uom = 'Ea' .
L_gm_item-orderid = '123' . "Mo No.
L_gm_item-reserv_no ='123' . "Reserved/related requirement No. resb ~ Rsnum
L_gm_item-res_item = '123' . "Reserved/required project No. resb ~ Rspos
* L_gm_item-XSTOB = 'x'. "offset sign, do not modify the mobile type 261, after the completion is also 262; Use 262, But here not set or 261.

Gm_code = 03 and 05 are both correct. I don't know if it's a bugger.
AppendRochelle gm_itemToLi_gm_item.

call function 'bapi _ goodsmvt_create '
exporting
goodsmvt_header = l_gm_head
goodsmvt_code = '03'
* return
importing
* goodsmvt_headret = l_mat_doc
materialdocument = l_mat_doc
tables
goodsmvt_item = li_gm_item
return = li_return
.
clear l_errflag.
message i005 (ymess) with l_mat_doc.

If l_errflag is initial .
call function 'bapi _ transaction_commit '.
else .
message i005 (ymess) with 'error' .
endif .

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.