Tuesday, June 07, 2005

ZPP_MATERIAL_CREATE

*&---------------------------------------------------------------------*
*& Report ZPP_MATERIAL_CREATE *
*& *
*&---------------------------------------------------------------------*
*& asd
*
*& *
*&---------------------------------------------------------------------*
REPORT zpp_material_create .
TYPE-POOLS: slis.
TABLES : bapimathead, bapi_marc, bapi_mbew, makt.

DATA : headdata LIKE bapimathead.
DATA : plantdata LIKE bapi_marc.
DATA : plantdatax LIKE bapi_marcx.
DATA : valuationdata LIKE bapi_mbew.
DATA : valuationdatax LIKE bapi_mbewx.
DATA : storagelocationdata LIKE bapi_mard.
DATA : storagelocationdatax LIKE bapi_mardx.
DATA : return LIKE bapiret2.
DATA : fname(256).

*----------------------------------------------------------------------
* Deklaration der globalen Variablen
*----------------------------------------------------------------------
DATA:
g_repid LIKE sy-repid.

*** Fuer ALV
DATA:
* Feldkatalog fuer ALV
gt_fieldcat TYPE slis_t_fieldcat_alv,
* Callback routines
g_status_set TYPE slis_formname VALUE 'SET_STATUS',
g_user_command TYPE slis_formname VALUE 'USER_COMMAND',
* List layout description
gs_layout TYPE slis_layout_alv,
* Funktionscodes, die vom Status ausgeschlossen werden sollen
gt_excluding TYPE slis_t_extab.




DATA : BEGIN OF i_tab OCCURS 100,
matl_type LIKE bapimathead-matl_type, "Malzeme türü
material LIKE bapimathead-material, "Malzeme numarası
maktxx LIKE makt-maktx, "Malzeme tanımı
plant LIKE bapi_marc-plant, "Üretim yeri
mrp_type LIKE bapi_marc-mrp_type, "MİP karakteristiği
mrp_ctrler LIKE bapi_marc-mrp_ctrler, "MİP sorumlusu
lotsizekey LIKE bapi_marc-lotsizekey, "MİP parti büyüklüğü
minlotsize LIKE bapi_marc-minlotsize, "Asgari parti büyüklüğü
reorder_pt LIKE bapi_marc-reorder_pt, " Yeniden sipariş seviyesi
round_val LIKE bapi_marc-round_val, "yuvarlama değeri
plnd_delry LIKE bapi_marc-plnd_delry, "Planlanan teslimat süresi
proc_type LIKE bapi_marc-proc_type, "Tedarik türü
iss_st_loc LIKE bapi_marc-iss_st_loc, "Üretim depo yeri
inhseprodt LIKE bapi_marc-inhseprodt, "Dahili üretim süresi
sm_key LIKE bapi_marc-sm_key, "süre anahtarı
plan_strgp LIKE bapi_marc-plan_strgp, "Planlama stratejisi grubu
consummode LIKE bapi_marc-consummode, "Mahsuplaştırma kipi
bwd_cons LIKE bapi_marc-bwd_cons, "Mahs. geriye doğru
fwd_cons LIKE bapi_marc-fwd_cons, "Mahs. ileriye doğru
availcheck LIKE bapi_marc-availcheck, "Kull. kontrolü
ind_post_to_insp_stock LIKE bapi_marc-ind_post_to_insp_stock,
* Kalite kontrol stoku
unlimited LIKE bapi_marc-unlimited, "Sınırsız teslimat
prodprof LIKE bapi_marc-prodprof, "Üretim yöneltim profili
production_scheduler LIKE bapi_marc-production_scheduler,
* Üretim yöneltim sorumlusu
qty_struct LIKE bapi_mbew-qty_struct, "miktar yapısı
orig_mat LIKE bapi_mbew-orig_mat, "malzeme kaynağı
specprocty LIKE bapi_marc-specprocty, "m.h. özel tedarik tipi
variance_key LIKE bapi_marc-variance_key, "Sapma anahtarı
lot_size LIKE bapi_marc-lot_size, "m.h. parti büyüklüğü
webaz LIKE marc-webaz, "MG isleme Suresi
takzt LIKE marc-takzt, "Takt Zamani
bstma LIKE marc-bstma, " Azami Parti Buy
safety_stk LIKE bapi_marc-safety_stk. " Emniyet Stoğu
DATA : END OF i_tab.

DATA : BEGIN OF result OCCURS 100,
matl_type LIKE bapimathead-matl_type, "Malzeme türü
material LIKE bapimathead-material, "Malzeme numarası
plant LIKE bapi_marc-plant, "Üretim yeri
type LIKE bapiret2-type ,
message LIKE bapiret2-message.
DATA : END OF result.

DATA : pc_file TYPE string.


PARAMETERS: p_file(128) DEFAULT 'c:\BOLU_Malzeme.txt' LOWER CASE
OBLIGATORY.




START-OF-SELECTION.

PERFORM upload_itab.
PERFORM run_bapi.
PERFORM write_result.

*&---------------------------------------------------------------------*
*& Form upload_itab
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM upload_itab .

pc_file = p_file.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = pc_file
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = i_tab
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_table_width = 4
invalid_type = 5
no_batch = 6
unknown_error = 7
gui_refuse_filetransfer = 8
OTHERS = 9.


ENDFORM. " upload_itab
*&---------------------------------------------------------------------*
*& Form run_bapi
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM run_bapi .

LOOP AT i_tab.

CLEAR : headdata, plantdata, plantdatax, valuationdata,
valuationdatax.

headdata-matl_type = i_tab-matl_type .
headdata-material = i_tab-material .
headdata-mrp_view = 'X' .
headdata-work_sched_view = 'X' .
headdata-cost_view = 'X' .
headdata-storage_view = 'X'.

plantdata-plant = i_tab-plant .
plantdata-mrp_type = i_tab-mrp_type .
plantdata-mrp_ctrler = i_tab-mrp_ctrler .
plantdata-lotsizekey = i_tab-lotsizekey .
plantdata-minlotsize = i_tab-minlotsize .
plantdata-reorder_pt = i_tab-reorder_pt .
plantdata-round_val = i_tab-round_val .
plantdata-plnd_delry = i_tab-plnd_delry .
plantdata-proc_type = i_tab-proc_type .
plantdata-iss_st_loc = i_tab-iss_st_loc .
plantdata-inhseprodt = i_tab-inhseprodt .
plantdata-sm_key = i_tab-sm_key .
plantdata-plan_strgp = i_tab-plan_strgp .
plantdata-consummode = i_tab-consummode .
plantdata-bwd_cons = i_tab-bwd_cons .
plantdata-fwd_cons = i_tab-fwd_cons .
plantdata-availcheck = i_tab-availcheck .
plantdata-ind_post_to_insp_stock = i_tab-ind_post_to_insp_stock .
plantdata-unlimited = i_tab-unlimited .
plantdata-prodprof = i_tab-prodprof .
plantdata-production_scheduler = i_tab-production_scheduler .
plantdata-gr_pr_time = i_tab-webaz.
plantdata-cycle_time = i_tab-takzt.
plantdata-maxlotsize = i_tab-bstma.
plantdata-specprocty = i_tab-specprocty .
plantdata-variance_key = i_tab-variance_key .
plantdata-lot_size = i_tab-lot_size .
plantdata-safety_stk = i_tab-safety_stk.
plantdata-backflush = '1'.
plantdata-pur_group = 'D01'.

valuationdata-val_area = i_tab-plant .
valuationdata-val_type = ' ' .
valuationdata-orig_mat = i_tab-orig_mat.
valuationdata-qty_struct = i_tab-qty_struct .

valuationdatax-val_area = i_tab-plant .
valuationdatax-val_type = ' ' .
valuationdatax-orig_mat = 'X'.
valuationdatax-qty_struct = 'X'.

storagelocationdata-plant = i_tab-plant.
storagelocationdata-stge_loc = i_tab-iss_st_loc.

storagelocationdatax-plant = i_tab-plant.
storagelocationdatax-stge_loc = i_tab-iss_st_loc.


plantdatax-plant = i_tab-plant .

IF NOT plantdata-mrp_type IS INITIAL.
plantdatax-mrp_type = 'X'.
ENDIF.

IF NOT plantdata-mrp_ctrler IS INITIAL.
plantdatax-mrp_ctrler = 'X'.
ENDIF.

IF NOT plantdata-lotsizekey IS INITIAL.
plantdatax-lotsizekey = 'X'.
ENDIF.

IF NOT plantdata-minlotsize IS INITIAL.
plantdatax-minlotsize = 'X'.
ENDIF.

IF NOT plantdata-reorder_pt IS INITIAL.
plantdatax-reorder_pt = 'X'.
ENDIF.


IF NOT plantdata-round_val IS INITIAL.
plantdatax-round_val = 'X'.
ENDIF.

IF NOT plantdata-plnd_delry IS INITIAL.
plantdatax-plnd_delry = 'X'.
ENDIF.

IF NOT plantdata-proc_type IS INITIAL.
plantdatax-proc_type = 'X'.
ENDIF.

IF NOT plantdata-iss_st_loc IS INITIAL.
plantdatax-iss_st_loc = 'X'.
ENDIF.

IF NOT plantdata-inhseprodt IS INITIAL.
plantdatax-inhseprodt = 'X'.
ENDIF.

IF NOT plantdata-sm_key IS INITIAL.
plantdatax-sm_key = 'X'.
ENDIF.

IF NOT plantdata-plan_strgp IS INITIAL.
plantdatax-plan_strgp = 'X'.
ENDIF.

IF NOT plantdata-consummode IS INITIAL.
plantdatax-consummode = 'X'.
ENDIF.

IF NOT plantdata-bwd_cons IS INITIAL.
plantdatax-bwd_cons = 'X'.
ENDIF.

IF NOT plantdata-fwd_cons IS INITIAL.
plantdatax-fwd_cons = 'X'.
ENDIF.

IF NOT plantdata-availcheck IS INITIAL.
plantdatax-availcheck = 'X'.
ENDIF.

IF NOT plantdata-ind_post_to_insp_stock IS INITIAL.
plantdatax-ind_post_to_insp_stock = 'X'.
ENDIF.

IF NOT plantdata-unlimited IS INITIAL.
plantdatax-unlimited = 'X'.
ENDIF.

IF NOT plantdata-prodprof IS INITIAL.
plantdatax-prodprof = 'X'.
ENDIF.

IF NOT plantdata-production_scheduler IS INITIAL.
plantdatax-production_scheduler = 'X'.
ENDIF.

IF NOT valuationdata-qty_struct IS INITIAL.
valuationdatax-qty_struct = 'X'.
ENDIF.

IF NOT valuationdata-mat_origin IS INITIAL.
valuationdatax-mat_origin = 'X'.
ENDIF.

IF NOT plantdata-specprocty IS INITIAL.
plantdatax-specprocty = 'X'.
ENDIF.

IF NOT plantdata-variance_key IS INITIAL.
plantdatax-variance_key = 'X'.
ENDIF.

IF NOT plantdata-lot_size IS INITIAL.
plantdatax-lot_size = 'X'.
ENDIF.

IF NOT plantdata-gr_pr_time IS INITIAL.
plantdatax-gr_pr_time = 'X'.
ENDIF.

IF NOT plantdata-cycle_time IS INITIAL.
plantdatax-cycle_time = 'X'.
ENDIF.

IF NOT plantdata-maxlotsize IS INITIAL.
plantdatax-maxlotsize = 'X'.
ENDIF.

IF NOT plantdata-safety_stk IS INITIAL.
plantdatax-safety_stk = 'X'.
ENDIF.

IF NOT plantdata-backflush IS INITIAL.
plantdatax-backflush = 'X'.
ENDIF.

IF NOT plantdata-pur_group IS INITIAL.
plantdatax-pur_group = 'X'.
ENDIF.




CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = headdata-material
IMPORTING
output = headdata-material
* EXCEPTIONS
* LENGTH_ERROR = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CLEAR return.
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
headdata = headdata
* CLIENTDATA =
* CLIENTDATAX =
plantdata = plantdata
plantdatax = plantdatax
* FORECASTPARAMETERS =
* FORECASTPARAMETERSX =
* PLANNINGDATA =
* PLANNINGDATAX =
storagelocationdata = storagelocationdata
storagelocationdatax = storagelocationdatax
valuationdata = valuationdata
valuationdatax = valuationdatax
* WAREHOUSENUMBERDATA =
* WAREHOUSENUMBERDATAX =
* SALESDATA =
* SALESDATAX =
* STORAGETYPEDATA =
* STORAGETYPEDATAX =
* FLAG_ONLINE = ' '
* FLAG_CAD_CALL = ' '
* NO_DEQUEUE = ' '
IMPORTING
return = return
* TABLES
* MATERIALDESCRIPTION =
* UNITSOFMEASURE =
* UNITSOFMEASUREX =
* INTERNATIONALARTNOS =
* MATERIALLONGTEXT =
* TAXCLASSIFICATIONS =
* RETURNMESSAGES =
* PRTDATA =
* PRTDATAX =
* EXTENSIONIN =
* EXTENSIONINX =
.

MOVE-CORRESPONDING i_tab TO result.
MOVE-CORRESPONDING return TO result.
APPEND result. CLEAR result.

ENDLOOP.

ENDFORM. " run_bapi
*&---------------------------------------------------------------------*
*& Form write_result
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM write_result .


g_repid = sy-repid.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = g_repid
i_internal_tabname = 'RESULT'
i_inclname = g_repid
CHANGING
ct_fieldcat = gt_fieldcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.



CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = g_repid
* i_callback_pf_status_set = g_status_set
* i_callback_user_command = g_user_command
* is_layout = gs_layout
it_fieldcat = gt_fieldcat
TABLES
t_outtab = result
EXCEPTIONS
program_error = 1
OTHERS = 2.





ENDFORM. " write_result

0 Comments:

Post a Comment

<< Home