Thursday, October 27, 2011
Goods Movement For Production Order
Sample Code to fulfill Goods Movement For Production Order.
*** PARAMETERS PASSED
i_aufnr , i_aufnr_itno , i_plant , i_lgort , i_quantity
*** PARAMETERS PASSED
*** DATA Decleration
DATA : gs_header TYPE bapi2017_gm_head_01 ,
gs_code TYPE bapi2017_gm_code ,
gt_headret TYPE TABLE OF bapi2017_gm_head_ret WITH HEADER LINE ,
gt_item TYPE TABLE OF bapi2017_gm_item_create WITH HEADER LINE,
gt_return TYPE TABLE OF bapiret2 WITH HEADER LINE.
*** Find Order's UNIT
SELECT SINGLE sbmeh FROM afko INTO lv_sbmeh
WHERE aufnr = i_aufnr.
*GM_CODE TCODE Description
*01 MB01 Goods receipt for purchase order
*02 MB31 Goods receipt for production order
*03 MB1A Goods issue
*04 MB1B Transfer posting
*05 MB1C Other goods receipt
*06 MB11 Reversal of goods movements
*07 MB04 Subsequent adjustment with regard to a subcontract order
*** Set Code
gs_code-gm_code = '02' .
*** Header
gs_header-pstng_date = sy-datum .
gs_header-doc_date = sy-datum .
gs_header-pr_uname = sy-uname .
gs_header-header_txt = 'Text 123'.
gs_header-ref_doc_no = i_aufnr.
*** Item
CLEAR gt_item .
gt_item-move_type = '101' .
gt_item-spec_stock = 'E'.
gt_item-mvt_ind = 'F'.
gt_item-stck_type = 'X'.
*** Order Id
gt_item-orderid = i_aufnr.
gt_item-order_itno = i_aufnr_itno.
gt_item-plant = i_plant .
gt_item-stge_loc = i_lgort.
gt_item-entry_qnt = i_quantity .
gt_item-entry_uom = lv_sbmeh.
gt_item-entry_uom_iso = lv_sbmeh.
gt_item-item_text = i_aufnr .
APPEND gt_item .
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = gs_header
goodsmvt_code = gs_code
IMPORTING
goodsmvt_headret = gt_headret
TABLES
goodsmvt_item = gt_item[]
return = gt_return[].
BREAK-POINT.
LOOP AT gt_return WHERE type = 'S'
AND id = 'L9'
AND number = '514'.
ENDLOOP.
IF sy-subrc EQ 0.
*** Delivery Created - OK
ELSE.
*** Problem Occured - Check gt_return[]
ENDIF.
Thursday, October 6, 2011
Full-screen ALV
ABAP developers face ALV full-screen problem most of the times as a part of designing issue. Displaying ALV in full-screen mode is just easy as below. You don't need to create a custom container.
if go_alv is initial.
create object go_alv
exporting
i_parent = cl_gui_container=>screen0
* i_appl_events = 'X'
exceptions
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
others = 5.
if sy-subrc ne 0.
message id sy-msgid type sy-msgty number
sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3
sy-msgv4.
endif.
endif.
Currency Conversion
Like unit conversion , currency conversion is also one of the most needed operation. And for this kind of common operations we should have code snippets. Here is a sample usage for currency conversion.
*** Currency Conversion
if lv_waers_from ne lv_waers_to.
perform convert_currency using lv_waers_from
lv_waers_to
changing lv_wrbtr.
endif.
*-------------------------------------------
* Form convert_currency
*-------------------------------------------
FORM convert_currency USING p_from_waers
p_to_waers
CHANGING p_wrbtr.
DATA : lv_ukurs TYPE tcurr-ukurs .
CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
EXPORTING
date = gv_keydate
foreign_amount = p_wrbtr
foreign_currency = p_from_waers
local_currency = p_to_waers
IMPORTING
exchange_rate = lv_ukurs
EXCEPTIONS
no_rate_found = 1
overflow = 2
no_factors_found = 3
no_spread_found = 4
derived_2_times = 5
OTHERS = 6.
CHECK sy-subrc EQ 0.
p_wrbtr = p_wrbtr * lv_ukurs.
ENDFORM. " convert_currency
Subscribe to:
Posts (Atom)