on 2008 Dec 18 11:27 AM
Dear All,
I want to upload the initial stock with movement type 561.My materials are Batch Managed and the Batch are having certain Characterstic.So i want to upload the Stock with Batch Characterstic.This is not possible with recording in LSMW.Can anybody help me out in making the LSMW.
Thanks
Jagmohan
Jagmohan
I would suggest you to use ABAP program for this.
You should create the batches first with their appropriate characterstics value & then use BAPI in the program to upload stocks with the batches.
Regards
Mahesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this code
REPORT zosmm_carga_caract_lote NO STANDARD PAGE HEADING LINE-SIZE 100.
*----
-
Global Parameters
*----
-
DATA: BEGIN OF t_message OCCURS 0.
INCLUDE STRUCTURE bapiret2.
DATA: END OF t_message.
DATA: BEGIN OF t_archivo OCCURS 0,
lineas(42),
END OF t_archivo.
DATA: BEGIN OF t_carga OCCURS 0,
charg(10),
valor(30),
END OF t_carga.
DATA: BEGIN OF t_caract OCCURS 40,
atnam LIKE cabn-atnam,
atinn LIKE cabn-atinn,
atfor LIKE cabn-atfor,
anzst LIKE cabn-anzst,
END OF t_caract.
BAPI structures
DATA: BEGIN OF wa_allocvaluescharnew OCCURS 0.
INCLUDE STRUCTURE bapi1003_alloc_values_char.
DATA: END OF wa_allocvaluescharnew.
DATA: BEGIN OF wa_allocvaluesnumnew OCCURS 0.
INCLUDE STRUCTURE bapi1003_alloc_values_num.
DATA: END OF wa_allocvaluesnumnew.
DATA: BEGIN OF wa_allocvaluescurrnew OCCURS 0.
INCLUDE STRUCTURE bapi1003_alloc_values_curr.
DATA: END OF wa_allocvaluescurrnew.
Variables
DATA: lineas TYPE i,
w_rc LIKE sy-subrc,
mens LIKE message,
date_err(1) TYPE c,
swc(1).
DATA: c_totreg(6),
c_vanreg(6).
DATA: v_atinn LIKE cabn-atinn,
v_atfor LIKE cabn-atfor,
v_anzst LIKE cabn-anzst.
*----
-
SELECTION-SCREEN
*----
-
SELECTION-SCREEN BEGIN OF BLOCK uno WITH FRAME TITLE text-001.
PARAMETER: p_matnr LIKE mara-matnr OBLIGATORY,
p_atnam LIKE cabn-atnam OBLIGATORY.
PARAMETER: p_file LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF BLOCK uno.
*----
-
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM buscar_archivo USING p_file.
*----
-
START-OF-SELECTION.
*----
-
START-OF-SELECTION.
REFRESH: t_archivo, t_carga, t_caract.
*** Characteristics Values
SELECT SINGLE atinn atfor anzst
INTO (v_atinn, v_atfor, v_anzst)
FROM cabn
WHERE atnam = p_atnam.
IF sy-subrc NE 0.
MESSAGE i899(m3) WITH 'Not Valid Characteritics'.
ELSE.
*** Read input and upload
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = p_file
filetype = 'ASC'
TABLES
data_tab = t_archivo
EXCEPTIONS
conversion_error = 1
invalid_table_width = 2
invalid_type = 3
no_batch = 4
unknown_error = 5
gui_refuse_filetransfer = 6
OTHERS = 7.
IF sy-subrc EQ 0.
LOOP AT t_archivo.
CLEAR t_carga.
SPLIT t_archivo AT ';'
INTO t_carga-charg t_carga-valor.
APPEND t_carga.
ENDLOOP.
DESCRIBE TABLE t_carga LINES lineas.
IF lineas > 0.
PERFORM clasificar_lotes.
ELSE.
MESSAGE i899(m3) WITH 'Doesn't exist batch to process'.
ENDIF.
ELSE.
MESSAGE i899(m3) WITH 'Error on upload'.
ENDIF.
ENDIF.
*----
-
TOP-OF-PAGE
*----
-
TOP-OF-PAGE.
WRITE: /'TITLE', sy-datum, sy-uname NO-GAP.
WRITE: /'Material: ', p_matnr.
WRITE: /'Characteristics: ', p_atnam.
SKIP.
WRITE: 01 'Batch', 11 'Valor', 30 'Log'.
ULINE.
**********************
*&----
*
*& Form clasificar_lotes
*&----
*
FORM clasificar_lotes.
DATA: w_matnr LIKE mara-matnr,
w_cuobjbm LIKE mch1-cuobj_bm,
w_obtab LIKE inob-obtab,
w_objek LIKE inob-objek,
w_class LIKE klah-class,
w_clint LIKE kssk-clint,
w_valor(8),
w_mbapi(80),
logline(100).
CLEAR: t_message.
LOOP AT t_carga WHERE charg IS NOT INITIAL.
REFRESH: wa_allocvaluescharnew,
wa_allocvaluesnumnew,
wa_allocvaluescurrnew.
CLEAR: wa_allocvaluescharnew,
wa_allocvaluesnumnew,
wa_allocvaluescurrnew,
date_err,
w_mbapi,
logline.
CONCATENATE t_carga-charg t_carga-valor
INTO logline SEPARATED BY space.
*** Find object to classified
SELECT SINGLE cuobj_bm matnr
INTO (w_cuobjbm, w_matnr)
FROM mch1
WHERE charg = t_carga-charg
AND matnr = p_matnr.
IF sy-subrc EQ 0.
SELECT SINGLE obtab objek
INTO (w_obtab,w_objek)
FROM inob
WHERE cuobj = w_cuobjbm.
*** Find class from object
SELECT SINGLE clint INTO w_clint
FROM kssk
WHERE objek = w_cuobjbm
AND mafid = 'O'
AND klart = '023'.
IF sy-subrc = 0.
SELECT SINGLE class INTO w_class
FROM klah
WHERE clint = w_clint.
TRANSLATE t_carga-valor USING ',.'.
CONDENSE t_carga-valor.
CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'
EXPORTING
objectkey = w_objek
objecttable = 'MCH1'
classnum = w_class
classtype = '023'
KEYDATE = SY-DATUM
UNVALUATED_CHARS = ' '
language = sy-langu
IMPORTING
STATUS =
STANDARDCLASS =
TABLES
allocvaluesnum = wa_allocvaluesnumnew
allocvalueschar = wa_allocvaluescharnew
allocvaluescurr = wa_allocvaluescurrnew
return = t_message.
*** Define characteristics type
CASE v_atfor.
WHEN 'CHAR' OR 'BOOL'.
wa_allocvaluescharnew-charact = p_atnam.
wa_allocvaluescharnew-value_char = t_carga-valor.
APPEND wa_allocvaluescharnew.
LOOP AT wa_allocvaluescharnew WHERE charact = p_atnam.
wa_allocvaluescharnew-value_char = t_carga-valor.
wa_allocvaluescharnew-value_neutral = t_carga-valor.
MODIFY wa_allocvaluescharnew.
ENDLOOP.
WHEN 'NUM' OR 'TIME'.
wa_allocvaluesnumnew-charact = p_atnam.
wa_allocvaluesnumnew-value_from = t_carga-valor.
APPEND wa_allocvaluesnumnew.
LOOP AT wa_allocvaluesnumnew WHERE charact = p_atnam.
wa_allocvaluesnumnew-value_from = t_carga-valor.
wa_allocvaluesnumnew-value_from = t_carga-valor.
MODIFY wa_allocvaluesnumnew.
ENDLOOP.
WHEN 'DATE'.
CALL FUNCTION 'CONVERT_DATE_TO_INTERN_FORMAT'
EXPORTING
datum = t_carga-valor
dtype = 'DATS'
IMPORTING
error = date_err
idate = w_valor
messg = mens.
IF date_err = 'X'.
CONCATENATE logline '-> Error: Fecha no valida'
INTO logline SEPARATED BY space.
ENDIF.
wa_allocvaluesnumnew-charact = p_atnam.
wa_allocvaluesnumnew-value_from = w_valor.
APPEND wa_allocvaluesnumnew.
LOOP AT wa_allocvaluesnumnew WHERE charact = p_atnam.
wa_allocvaluesnumnew-value_from = w_valor.
MODIFY wa_allocvaluesnumnew.
ENDLOOP.
WHEN 'CURR'.
wa_allocvaluescurrnew-charact = p_atnam.
wa_allocvaluescurrnew-value_from = t_carga-valor.
APPEND wa_allocvaluescurrnew.
LOOP AT wa_allocvaluescurrnew WHERE charact = p_atnam.
wa_allocvaluescurrnew-value_from = t_carga-valor.
MODIFY wa_allocvaluescurrnew.
ENDLOOP.
ENDCASE.
***
IF date_err IS INITIAL.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> by AGARCIA
CALL FUNCTION 'BAPI_OBJCL_CHANGE_KEY'
CALL FUNCTION 'BAPI_OBJCL_CHANGE'
EXPORTING
objectkey = w_objek
objecttable = 'MCH1'
classnum = w_class
classtype = '023'
status = '1'
TABLES
allocvaluesnumnew = wa_allocvaluesnumnew
allocvaluescharnew = wa_allocvaluescharnew
allocvaluescurrnew = wa_allocvaluescurrnew
return = t_message.
IF sy-subrc EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
LOOP AT t_message WHERE type CO 'EA'.
CONCATENATE w_mbapi t_message-message ';'
INTO w_mbapi SEPARATED BY space.
ENDLOOP.
IF w_mbapi IS INITIAL.
CONCATENATE logline '-> Ok!' INTO logline SEPARATED BY space.
ELSE.
CONCATENATE logline '-> Error:' w_mbapi
INTO logline SEPARATED BY space.
ENDIF.
ELSE.
CONCATENATE logline '-> Error: Problem on BAPI Execution
INTO logline SEPARATED BY space.
ENDIF.
ENDIF.
ELSE.
CONCATENATE logline '-> Error: Class object don't found'.
INTO logline SEPARATED BY space.
ENDIF.
ELSE.
CONCATENATE logline '-> Error: Class object don't found'.
INTO logline SEPARATED BY space.
ENDIF.
WRITE: / logline.
ENDLOOP.
WRITE: / '>>>>>>>>>> FIN DEL PROCESO <<<<<<<<<<'.
ENDFORM. " clasificar_lotes
*----
*
Form buscar_archivo
Muestra el diálogo para seleccionar el archivo
*----
+----
*
FORM buscar_archivo CHANGING ie_arch.
DATA: v_file1 LIKE dynpread-fieldname,
v_file2 LIKE ibipparms-path.
v_file1 = ie_arch.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
field_name = v_file1
IMPORTING
file_name = v_file2.
ie_arch = v_file2.
ENDFORM. " BUSCAR_ARCHIVO
User | Count |
---|---|
93 | |
9 | |
8 | |
7 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.