Beruflich Dokumente
Kultur Dokumente
Hi everyone.
: VT03N -> Button - Means of transport and Packaging Matl for Currnet Shipment (Shift+F9) ->
Double click 'Handling Unit'.
As you can see above, TRUCKID1 was packed with DO 10, 20, 30.
So I'd like to know how to change 'Contents' with keeping pack status.
Current parameter for the bapi is like below.
HEADERDATA
HDUNHEADER
- HDL_UNIT_EXID : TRUCKID1
- CONTENT : TEST1,2,3
HDUNHEADERACTION
- HDL_UNIT_EXID : C
- CONTENT :C
Version 1
inShare
Scenario
At the time of implementation, we need to upload large amount master data and transactional
data in the MM Module. For Example to Upload the initial stock. Secondly there may be a
situation that we need to upload a large amount of Goods Movement transaction. In order to
achieve that we can use the following BAPI. This document explains the steps to arrange the
data and upload in the system using BAPI.
This document will provide a guideline with respect to your requirement. Use this BAPI
template for all types of Goods movement transaction by Changing appropriate movement
indicator, GMcode of header information of BAPI and execute it.
Pre-requisite
Arrange the Data in the following format. Preferably in the Excel format
Ths is a comprehensive list of data. You can use the relevent fields based on your movement
type. But do not change the sequence.
External Document Number - Any reference document number you need to maintain
There are some header level flags for BAPI we set based on the movement type we execute.
Movement Indicator
BAPI - Details
Name : BAPI_GOODSMVT_CREATE
Header Data : Header, Code
Item Details : Internal table that contain material details that we fetch from Excelsheet
Technical details
Now we see the technical details for writing this BAPI Execution code
Data Defention
plant(4), "Plant
qty(13), "Quantity
end of itemtab.
Read Data
form UPLOAD_DATA .
DATA: loc_filename TYPE rlgrap-filename. "string.
DATA: it_raw TYPE truxs_t_text_data.
loc_filename = p-file.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_line_header = 'X'
i_tab_raw_data = it_raw
i_filename = loc_filename
TABLES
i_tab_converted_data = pcitab
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
gmhead-pstng_date = sy-datum. "you can change it from the data you read from excl
gmhead-doc_date = sy-datum.
gmhead-pr_uname = sy-uname.
gmcode-gm_code = '04'. "04 - MB1B - Transfer Posting
append itab.
endloop.
clear errflag.
loop at errmsg.
if errmsg-type eq 'E'.
write:/'Error in function', errmsg-message.
errflag = 'X'.
else.
write:/ errmsg-message.
endif.
endloop.
You can use this BAPI template for Goods movement by setting appropriate header flags
Give the name in the Data type field and click create.
In the pop-up that comes up, select the radio button “ structure”.
In the components tab of the structure, give the different fields and their corresponding
field types and press enter to check the compatibility and corrective ness.
Do not forget to save it in a package. You can even save it as a local object. For my
example, I save it in a package.
Check the structure (ctrl + F2) and activate (ctrl + F3) the structure.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++
Go to transaction SE37 where you create function modules. Click on create after you
enter the name of the Function module.
A screen as shown above would pop-up where you mention the function group to save
the function module and also provide some short text describing your function module.
In the next pop-up that follows, click on continue as shown above.
The function module screen would look like the one above.
Go to the Attributes tab and select the radio button reading “remote-enabled module”.
Come back to the imports tab and provide the import parameters as shown or as per
your requirement.
Now in the Export tab, provide the export parameters as shown or as per your
requirement.
In the tables tab, provide the information as shown or as per your requirement.
The next screen you visit is the source code. It would look like this.
In the source code tab, write the following code in order to pick the data based on the
input you provide.
Now, save and check the code and activate the function module.
+++++++++++++++++++++++++++++++++++++++++++++++
Go to transaction SWO1 and enter the name of the BAPI you would like to create or as
shown in the screen and click the create button.
Give the name of the BAPI as above and click on create.
Click or select the method as shown above and go to the path “Utilities->API methods-
>Add methods”.
On the screen that follows, provide the function module name and click on the continue
icon.
In the ultimate pop-up, click the next step icon. We observe that the information is
predefined in the fields.
This is the next screen where you would just click on the “next” icon.
Click on Yes. You can see an information message reading “ ZBAPIFMT001” inserted.
Now save after you add the method. Select & Double click on the API method.
The message shows, The object type status set to modeled. (or already modeled)
Now, go to: Edit -> Change Release Status -> Object -> To Released.
There would be two pop ups coming up. Click continue on the Pop Ups.
You can see the message reading “ status for method „zbapifmt001‟ set to modeled”.
Now, go to: Edit -> Change Release Status -> Object type component -> TO
Implemented
You can see the message reading “ status for method „zbapifmt001‟ set to
implemented”.
Now go to: Edit -> Change Releasse Status -> Object type component -> To Released
You can see the message reading “ status for method „zbapifmt001‟ set to Released”.
Click on Generate Button. (the red ball kind of button is the Generate button)
After clicking on the generate button, you can see the message reading “Object type
'ZBAPI_T001' generated successfully”.
Now go to BAPI Tcode (BOR) there we can find the BAPI (our BAPI)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++
Enter the name of your BAPI in the transaction SWO1 and click on „Test‟.
The above screen is displayed. Click on the Execute icon against the BAPI as shown.
The above screen is displayed where you would require entering the data against the
empty input fields.
The following screen is displayed which has some values as is indicated by the
ITEMTAB.
Click on the Edit table icon as shown below.
After executing the BAPI based on the input provided, we get the following screen.
Hit on the execute icon.
Also contains the logic of how to find out what views to update from the reference
material by using the Maintenance status field (PSTAT) from MARC
report ZSA_TEST002.
start-of-selection.
view,
gv_i type i,
gv_msg(200).
field-symbols:
EXPORTING
material = p_matcfg
COMP_CODE = 'L153'
VAL_AREA = '7530'
* VAL_TYPE =
PLANT = p_werks0
* STGE_LOC =
SALESORG = p_vkorg0
DISTR_CHAN = p_disnso
* WHSENUMBER =
* STGE_TYPE =
* LIFO_VALUATION_LEVEL =
IMPORTING
CLIENTDATA = str_clientdata
PLANTDATA = str_plantdata
FORECASTPARAMETERS = str_forecastparameters
PLANNINGDATA = str_planningdata
STORAGELOCATIONDATA = str_storagelocationdata
VALUATIONDATA = str_valuationdata
WAREHOUSENUMBERDATA = str_warehousenumberdata
SALESDATA = str_salesdata
STORAGETYPEDATA = str_storagetypedata
PRTDATA = str_prtdata
LIFOVALUATIONDATA = str_lifovaluationdata
TABLES
* MATERIALDESCRIPTION =
* UNITSOFMEASURE =
* INTERNATIONALARTNOS =
* MATERIALLONGTEXT =
* TAXCLASSIFICATIONS =
* EXTENSIONOUT =
RETURN = tab_get_all_r.
if sy-subrc = 0.
if sy-subrc = 0.
counter = 0. clear view.
do gv_i times.
view = <fs_marc>-pstat+counter(sy-index).
counter = counter + 1.
case view.
when 'K'.
tab_head-basic_view = view.
when 'V'.
tab_head-sales_view = view.
when 'E'.
tab_head-purchase_view = view.
when 'D' .
tab_head-mrp_view = view.
when 'P'.
tab_head-forecast_view = view.
when 'A'.
tab_head-WORK_SCHED_VIEW = view.
when 'F'.
tab_head-PRT_VIEW = view.
when 'L'.
tab_head-storage_view = view.
when 'S'.
tab_head-warehouse_view = view.
when 'Q'.
tab_head-quality_view = view.
when 'B'.
tab_head-account_view = view.
when 'G'.
tab_head-cost_view = view.
when others.
endcase.
enddo.
endif.
endif.
tab_head-material = p_matnr.
tab_head-ind_sector = str_clientdata-ind_sector.
tab_head-matl_type = str_clientdata-matl_type.
do .
case sy-index.
when 1.
when 2.
when 3.
when 4.
when 5.
assign tab_stlocdata to <f1>.
when 6.
when 7.
when 8.
when 9.
when others.
exit.
endcase.
enddo.
tab_salesdata-sales_org = p_vkorg0.
tab_salesdata-distr_chan = p_disnso.
clear: tab_salesdatax-sales_org,
tab_salesdatax-distr_chan.
tab_salesdatax-sales_org = tab_salesdata-sales_org.
tab_salesdatax-distr_chan = tab_salesdata-distr_chan.
clear tab_plantdatax-plant.
tab_plantdatax-plant = tab_plantdata-plant.
CLEAR tab_valdatax-val_area.
tab_valdatax-val_area = tab_valdata-val_area.
EXPORTING
headdata = tab_head
CLIENTDATA = tab_client
CLIENTDATAX = tab_clientx
PLANTDATA = tab_plantdata
PLANTDATAX = tab_plantdatax
FORECASTPARAMETERS = tab_forecast
FORECASTPARAMETERSX = tab_forecastx
PLANNINGDATA = tab_plangdata
PLANNINGDATAX = tab_plangdatax
STORAGELOCATIONDATA = tab_stlocdata
STORAGELOCATIONDATAX = tab_stlocdatax
VALUATIONDATA = tab_valdata
VALUATIONDATAX = tab_valdatax
WAREHOUSENUMBERDATA = tab_warehouse
WAREHOUSENUMBERDATAX = tab_warehousex
SALESDATA = tab_salesdata
SALESDATAX = tab_salesdatax
STORAGETYPEDATA = tab_stortyped
STORAGETYPEDATAX = tab_stortypedx
IMPORTING
RETURN = tab_return
TABLES
MATERIALDESCRIPTION = gt_makt
* UNITSOFMEASURE =
* UNITSOFMEASUREX =
* INTERNATIONALARTNOS =
* MATERIALLONGTEXT =
* TAXCLASSIFICATIONS =
RETURNMESSAGES = tab_return_msgs.
* PRTDATA =
* PRTDATAX =
* EXTENSIONIN =
* EXTENSIONINX =
if tab_return-type = 'S'.
EXPORTING
WAIT = 'X'.
else.
endif.
gv_msg = <fms>.
write:/ gv_msg.
endloop.
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_<F1> text
* -->P_<F2> text
*----------------------------------------------------------------------*
do.
if sy-subrc = 0.
<fstructx> = 'X'.
endif.
endif.
enddo.
Function Module:
BAPI_MATERIAL_AVAILABILITY
Posted by Tuncay Karaca in ABAP Connectivity on Apr 26, 2007 9:45:52 PM
inShare
Using this function module, you can determine the receipt quantity still available for a particular
material in a certain plant according to ATP logic (MRPII).
The availability check is carried out on transferring the material number, the plant and the input
table (WMDVSX). The scope of the check, that is, which stocks, receipts and issues are to be
included in the check is defined by the combination of checking group (material master) and
cheking rule. In the function module, the system uses the checking rule defined in Sales &
Distribution (A). You can overrule this checking rule by using an interface or a user-exit
(exit_saplw61v_001). A similar procedure is also valid for the plant parameters. The customer
number in the user-exit means that the plant selection can be controlled via the customer. If no
plant parameters are given via the interface, the system uses the parameter 'WRK' saved in the
user's fixed values.
The results of the availability check are recorded in the output table (WMDVEX). This table
contains dates and available receipt quantities (ATP quantities). The results of the check depends
on the following entries:
If no date and no quantity is transferred, the system displays the ATP situation
from today's date into the future as the result.
If only a date and no quantity is transferred, the system displays the ATP situation
from the corresponding date as the result.
If both a date and a quantity are transferred, the system calculates the availability
situation for the quantity specified.
In the last two cases, the parameter 'DIALOGFLAG' is supplied. This can result in the
following:
The system also displays the end of the replenishment lead time (ENDLEADTME).
You can run BAPI_MATERIAL_AVAILABILITY for only one material, one plant, one unit at
a time. But we needed to check availability for multiple materials at a time, so I wrote a Z* RFC
which wraps BAPI_MATERIAL_AVAILABILITY. Simply Z* RFC accepts multiple materials
in a table parameter, then call BAPI_MATERIAL_AVAILABILITY in a loop.
Here is how call it:
Import Parameters:
Export Parameters:
RETURN: If something returns with this parameter, it shows something is wrong. After calling
function module, firstly check this parameter. For example you can get a message like that:
"Material MMM not maintained in plant"
If even you don't give (fill out WMDVSX table), any required quantity,
you get a result in table WMDVEX.
But requirement date was accepted today's date, and required quantity was accepted as much as
big number like 9,999,999,999.000.
Its documentation says export parameter DIALOGFLAG can be used to see whether required
quantity is available or not ( ' (blank): Available, 'X': Not available or partially available, 'N':
Material not relevant to the availability check ). But as you see I didn't use DIALOGFLAG. I
used table WMDVEX to do that. If I require 600 EAch material, and if it gives me less than this
number as committed quantity, it means there is no available quantity for my requirement.
If you want to compare the result, you can use transaction CO09 (Availability Overview). It
gives the same result as BAPI_MATERIAL_AVAILABILITY does.
On SDN forums there are several discussions keep going about
BAPI_MATERIAL_AVAILABILITY:
BAPI_MATERIAL_AVAILABILITY
http://www.newtosap.info/2012/06/create-custom-bapi-easily.html
3) Go to SE37 and create a custom BAPI FM(Function Module). ZBAPI_GET_WERKS is the bapi name. All
custom BAPI FM’s should begin with ZBAPI*
Make the FM remote enabled by selecting Remote Enabled Module. All BAPI FM’s are RFC enabled.
Now add the bapi import structure we created in import tab. Always remember to tick Pass by value
since BAPI FM which is a RFC enabled FM cannot use pass by reference.
In the export tab we will put BAPI return parameters. BAPIRETURN is a standard BAPI return structure.
In the source code of the program we need to make use of this parameter to show success or failure
status along with messages.
In the tables we will use our BAPI export table structure we created. We always use LIKE for tables.
4) Source code:
Add the logic of the FM here.
FUNCTION ZBAPI_GET_WERKS.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(MATNR) TYPE ZBAPI_ADIIMPORT-MATNR
*" EXPORTING
*" VALUE(RETURN) TYPE BAPIRETURN
*" TABLES
*" ZTABLE STRUCTURE ZBAPI_ADIEXPORT
*"----------------------------------------------------------------------
Logic of our BAPI is simple; it fetches matnr and werks value from marc table based on input matnr
values and fills the BAPI table. Lets test the FM, click execute and input a test data
ZTABLE will be filled with values from marc table corresponding to input matnr value
5 ) Place this Function Module in to BOR(Business object repository) using the T-code SWO1. Provide
the name of the object and press create button.
Add our Custom BAPI FM using Utilities = > API Method = >Add Method
Now you can use this BAPI like other BAPI.To learn how to use BAPI in reports , refer
BAPI's are basically function modules only. ALL BAPI's are remote enabled function modules which
enables to access via non SAP systems.
A remote function enabled FM(Function Module) will be attached to BOR(Business Object Repository) ,
then only it is termed as BAPI. Using BAPIs you can develop applications without detailed knowledge of
the underlying R/3 System.
Each BAPI is having its own business application and area. The integration between R/3 and third-party
software, legacy systems, and custom-developed software can be achieved via BAPI.
BAPI explorer with TCODE 'BAPI'.
BAPI explorer
All BAPI's are arraigned according to the business area. Details documentation is also available for some
BAPI's to show the usage of the BAPI
BAPI since its RFC enabled FM, has no exceptions. There are BAPI return tables which can be used to
analyze the success/failure of the process.
Since BAPI's are basically FM only , we call BAPI the same way we call a normal FM.
Its very important to select appropriate BAPI and also to pass the data in a way required by BAPI. Go
through all I/O structures for the BAPI selected to understand this better. We can also call BAPI of other
SAP systems. Just mention destination and you are good to go.
Ex:
call function 'BAPI_SALESORDER_GETSTATUS'
destination 'PW2'
exporting
salesdocument = order
importing
return = return
tables
statusinfo = statusinfo.
We need to call BAPI_TRANSACTION_COMMIT after each BAPI call to finalize or commit the change or
if some error occurs and we have identified the errors we need to use BAPI_TRANSACTION_ROLLBACK
to rollback the changes made if any.