익히 알 법한 자재코드 채번시 사용하는 BAPI : BAPI_MATERIAL_SAVEREPLICA
DATA : l_noappllog LIKE bapie1global_data-no_appl_log,
l_nochangedoc LIKE bapie1global_data-no_change_doc,
l_testrun LIKE bapie1global_data-testrun,
l_inpfldcheck LIKE bapie1global_data-inp_fld_check,
l_return LIKE bapiret2.
DATA : lt_headdata LIKE bapie1matheader OCCURS 0 WITH HEADER LINE,
lt_clientdata LIKE bapie1mara OCCURS 0 WITH HEADER LINE,
lt_clientdatax LIKE bapie1marax OCCURS 0 WITH HEADER LINE,
lt_plantdata LIKE bapie1marc OCCURS 0 WITH HEADER LINE,
lt_plantdatax LIKE bapie1marcx OCCURS 0 WITH HEADER LINE,
lt_storagelocationdata LIKE bapie1mard OCCURS 0 WITH HEADER LINE,
lt_storagelocationdatax LIKE bapie1mardx OCCURS 0 WITH HEADER LINE,
lt_valuationdata LIKE bapie1mbew OCCURS 0 WITH HEADER LINE,
lt_valuationdatax LIKE bapie1mbewx OCCURS 0 WITH HEADER LINE,
lt_salesdata LIKE bapie1mvke OCCURS 0 WITH HEADER LINE,
lt_salesdatax LIKE bapie1mvkex OCCURS 0 WITH HEADER LINE,
lt_materialdescription LIKE bapie1makt OCCURS 0 WITH HEADER LINE,
lt_unitsofmeasure LIKE bapie1marm OCCURS 0 WITH HEADER LINE,
lt_unitsofmeasurex LIKE bapie1marmx OCCURS 0 WITH HEADER LINE,
lt_materiallongtext LIKE bapie1mltx OCCURS 0 WITH HEADER LINE,
lt_taxclassifications LIKE bapie1mlan OCCURS 0 WITH HEADER LINE,
lt_extensionin LIKE bapie1parex OCCURS 0 WITH HEADER LINE,
lt_extensioninx LIKE bapie1parexx OCCURS 0 WITH HEADER LINE,
lt_returnmessages LIKE bapie1ret2 OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'BAPI_MATERIAL_SAVEREPLICA'
EXPORTING
noappllog = l_noappllog
nochangedoc = l_nochangedoc
testrun = l_testrun
inpfldcheck = l_inpfldcheck
IMPORTING
return = l_return
TABLES
headdata = lt_headdata
clientdata = lt_clientdata "기본 단위 세팅
clientdatax = lt_clientdatax
plantdata = lt_plantdata
plantdatax = lt_plantdatax
storagelocationdata = lt_storagelocationdata
storagelocationdatax = lt_storagelocationdatax
valuationdata = lt_valuationdata
valuationdatax = lt_valuationdatax
salesdata = lt_salesdata
salesdatax = lt_salesdatax
materialdescription = lt_materialdescription
unitsofmeasure = lt_unitsofmeasure "대체 단위 세팅
unitsofmeasurex = lt_unitsofmeasurex "대체 단위 세팅
materiallongtext = lt_materiallongtext
taxclassifications = lt_taxclassifications
extensionin = lt_extensionin
extensioninx = lt_extensioninx
returnmessages = t_returnmessages.
msg스트럭쳐-ret_code = l_return-type.
msg스트럭쳐-ret_msg = l_return-message.
IF l_return-type = 'E' AND l_return-message IS INITIAL.
READ TABLE t_returnmessages WITH KEY type = 'E'.
msg스트럭쳐-ret_msg = t_returnmessages-message.
ELSE.
CALL FUNCTION 'BAL_DSP_TXT_MSG_READ'
EXPORTING
i_langu = sy-langu
i_msgid = sy-msgid
i_msgno = sy-msgno
i_msgv1 = sy-msgv1
i_msgv2 = sy-msgv2
i_msgv3 = sy-msgv3
i_msgv4 = sy-msgv4
IMPORTING
e_message_text = msg스트럭쳐-ret_msg.
ENDIF.
IF l_return-type NE 'S'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
CHECK msg스트럭쳐-ret_code = 'S'.
자재마스터를 생성할 때 사용하는 BAPI : BAPI_MATERIAL_SAVEREPLICA
의 테이블 변수 중 unitsofmeasure, unitsofmeasurex 해당 파트에서 해당 자재코드의 기본 단위 세팅을 할 수 있다.
lt_unitsofmeasure-function = 'INS'.
lt_unitsofmeasurex-function = 'INS'.
lt_unitsofmeasure-material = i_matnr.
lt_unitsofmeasurex-material = i_matnr.
IF NOT lt_unitsofmeasure-unit_of_wt IS INITIAL. "중량 단위 사용하는 경우
lt_unitsofmeasurex-unit_of_wt = 'X'.
ENDIF.
lt_unitsofmeasure-gross_wt = '1'. "중량
lt_unitsofmeasurex-gross_wt = 'X'.
lt_unitsofmeasure-alt_unit = 'KG'. "대체 단위
lt_unitsofmeasurex-alt_unit = 'KG'.
lt_unitsofmeasure-numerator = 1000. "분자 - UMREZ..
lt_unitsofmeasure-denominatr = 1234. "분모 - UMREN..
>> 예를 들어 기본단위(M라고 가정) 1000M에 1234KG인 자재라면 이렇게 세팅하면 된다.
lt_unitsofmeasurex-numerator = 'X'.
lt_unitsofmeasurex-denominatr = 'X'.
APPEND lt_unitsofmeasure.
CLEAR lt_unitsofmeasure.
APPEND lt_unitsofmeasurex.
CLEAR lt_unitsofmeasurex.
* 참고로 기본 단위는 clientdata 테이블에서 세팅
lt_clientdata-function = 'INS'.
lt_clientdatax-function = 'INS'.
lt_clientdata-material = i_matnr.
lt_clientdatax-material = i_matnr.
lt_clientdata-base_uom = i_meins. " 기본 단위
lt_clientdatax-base_uom = 'X'.
lt_clientdatax-item_cat = 'X'. " 일반품목범주그룹
lt_clientdata-matl_group = i_matl_group. " 자재그룹
lt_clientdatax-matl_group = 'X'.
lt_clientdata-po_unit = i_bstme. "구매 오더 단위
lt_clientdatax-po_unit = 'X'.
lt_clientdata-var_ord_un = i_vabme. "가변 구매 오더 단위 활성
lt_clientdatax-var_ord_un = 'X'.
lt_clientdata-pur_valkey = i_ekwsl. "구매 값 키
lt_clientdatax-pur_valkey = 'X'.
lt_clientdata-division = i_spart. " 제품군
lt_clientdatax-division = 'X'.
lt_clientdata-prod_hier = i_ prodh. "제품계층구조
lt_clientdatax-prod_hier = 'X'.
lt_clientdata-temp_conds = i_tempb. "온도조건 지시자
lt_clientdatax-temp_conds = 'X'.
lt_clientdata-stor_conds = i_raube. "저장조건
lt_clientdatax-stor_conds = 'X'.
lt_clientdata-batch_mgmt = i_batch. "뱃치관리 소요량 지시자
lt_clientdatax-batch_mgmt = 'X'.
lt_clientdata-trans_grp = i_tras_grp. "운송그룹
lt_clientdatax-trans_grp = 'X'.
lt_clientdata-net_weight = i_net. " 순중량
lt_clientdatax-net_weight = 'X'.
lt_clientdata-unit_of_wt = 'KG'. " 중량 단위
lt_clientdatax-unit_of_wt = 'X'.
APPEND lt_clientdata.
CLEAR lt_clientdata.
APPEND lt_clientdatax.
CLEAR lt_clientdatax.
SAP MM - 자재코드 내역 SQL (0) | 2023.02.17 |
---|