2013 Oct 08 3:05 PM
Hello all,
I am trying to develop a program which receives necessary data for material document and then recording it into a ZTABLE.
But before designing the layout and other parameters I wanted to use BAPI_GOODSMVT_CREATE with constants, which I failed.
I am trying to transfer a material from a WBS stock to another.(after that I want to try multiple materials)
My constants are:
Plant :2000
WBS1 : PR00000611
WBS2 : PR00000638
Storage location : E001
Material number :1000077
Movement type :415
Special stock indicator: Q
Document date :30.09.2013
Recording date :30.09.2013
What am I doing wrong? I am new to ABAP and using BAPI's so I collected pieces of codes to work out.
Your help will be greatly appreciated.
Thanks,
Arda
REPORT z_test.
DATA: gm_header TYPE bapi2017_gm_head_01.
DATA: gm_code TYPE bapi2017_gm_code.
DATA: gm_headret TYPE bapi2017_gm_head_ret.
DATA: gm_item TYPE TABLE OF
bapi2017_gm_item_create WITH HEADER LINE.
DATA: gm_return TYPE bapiret2 OCCURS 0 WITH HEADER LINE.
DATA: gm_retmtd TYPE bapi2017_gm_head_ret-mat_doc.
CLEAR: gm_return, gm_retmtd. REFRESH gm_return.
gm_header-pstng_date = '20130930'.
gm_header-doc_date = '20130930'.
gm_code-gm_code = '04'.
CLEAR gm_item.
MOVE '415' TO gm_item-move_type .
MOVE 'Q' TO gm_item-spec_stock.
MOVE '1000077' TO gm_item-material.
MOVE '1' TO gm_item-entry_qnt.
MOVE '2000' TO gm_item-plant.
MOVE 'E001' TO gm_item-stge_loc.
MOVE 'PR00000611' TO gm_item-wbs_elem.
MOVE 'PR00000638' TO gm_item-val_wbs_elem.
APPEND gm_item.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = gm_header
goodsmvt_code = gm_code
IMPORTING
goodsmvt_headret = gm_headret
materialdocument = gm_retmtd
TABLES
goodsmvt_item = gm_item
return = gm_return.
IF gm_return[] IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
return = gm_return.
ELSE.
READ TABLE gm_return INDEX 1.
WRITE: '~ERROR~'.
ENDIF.
2013 Oct 08 3:56 PM
Can you replace the (awful)
IF gm_return[] IS INITIAL.
with a
LOOP AT gm_return TRANSPORTING NO FIELDS WHERE type = 'E' OR type = 'A'.
EXIT. " or MESSAGE statement (and use a work area)
ENDIF.
IF sy-subrc NE 0. " No error was raisedRemember that RETURN may contain S-success messages too (An I-information or a W-warning too)
Regards,
Raymond
Can you replace the (awful)
IF gm_return[] IS INITIAL.
with a
LOOP AT gm_return TRANSPORTING NO FIELDS WHERE type = 'E' OR type = 'A'.
EXIT. " or MESSAGE statement (and use a work area)
ENDIF.
IF sy-subrc NE 0. " No error was raisedRemember that RETURN may contain S-success messages too (An I-information or a W-warning too)
Regards,
Raymond
2013 Oct 08 3:20 PM
Hi Arda,
What exactly is the error that you are getting?
I tried to replicate your same code, and it is working fine...as in it is going to the else part of the code and displaying "~ERROR~".
The error message is : "No internal key found for the PSP element PR00000611 in field WBS_ELEM"
2013 Oct 08 3:41 PM
I used the object key of WBS on PRPS table?
Was that wrong?
I recieve no error except for the "~ERROR~" text I added and no document is being created.
2013 Oct 09 3:55 AM
George,
You are getting this error because that WBS won't be available in your system.
2013 Oct 08 3:56 PM
Can you replace the (awful)
IF gm_return[] IS INITIAL.
with a
LOOP AT gm_return TRANSPORTING NO FIELDS WHERE type = 'E' OR type = 'A'.
EXIT. " or MESSAGE statement (and use a work area)
ENDIF.
IF sy-subrc NE 0. " No error was raisedRemember that RETURN may contain S-success messages too (An I-information or a W-warning too)
Regards,
Raymond
2013 Oct 08 4:57 PM
Hello Raymond,
I did what you asked but should I change ENDIF with ENDLOOP? because it is missing
2013 Oct 09 3:59 AM
Raymond,
RETURN[] will be initial in this BAPI on successful completion of material document creation.
Only on erroneous cases, the return internal table will be filled with messages.
2013 Oct 09 4:15 AM
Hello Arda Takan.
Your code seems to be right after the BAPI.
1) gm_return[] will be initial on successful creation of material document.
Kindly check what message you are getting in gm_return.
Instead of just showing ERROR, display the exact error message.
READ TABLE gm_return WITH KEY type = 'E'.
IF sy-subrc = 0.
MESSAGE gm_return-message TYPE 'S' DISPLAY LIKE 'E'.
leave to screen sy-dynnr.
ENDIF.
2) Make use of function module CONVERSION_EXIT_ALPHA_INPUT (Pad preceding zeroes) for material and then pass to goodsmvt_item-material.
3) Are you passing CHAR24 format of WBS to goodsmvt_item-wbs_elem and goodsmvt_item-val_wbs_elem?
Regards.
2013 Oct 08 4:06 PM
Hi Arda,
After calling the BAPI, you are checking for an initial return table. That way, even if the BAPI returns a success message, you would still get an error message that you have hard coded.
For further usages too, avoid checking for an initial return table from a BAPI or a BDC. Instead check for MSGTY = 'E' in the return tables.
In this case, it would be helpful if you could share the return table after the BAPI call through the debugger. It would be clearer what the error actually is.
Thanks,
Anupam
2013 Oct 09 3:15 PM
Also check whether the WBS element that you are trying to pass exists in your system. If it exists, use a conversion routine to convert to convert it to SAP internal format.
2013 Oct 10 4:15 AM
Anupam,
While passing to BAPI, WBS has to be converted to SAP EXTERNAL format (CHAR 24) and passed into goodsmvt_item.
2013 Oct 09 3:29 PM
What about I need to transfer multiple materials?
Do I need something like " gm_item_number"?
2013 Oct 09 4:06 PM
Hi Arda,
In case you need to pass multiple materials, you need to append the records to the table gm_item for the respective materials along with the respective other values.
Once all the item entries are populated in the table GM_ITEM, you can now call the BAPI.
Thanks,
Anupam
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |