Batch Classification Document

Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 22

FUNCTION Module Code

===========================

FUNCTION zmaterial_classfication.
*"---------------------------------------------------------------------
-
*"*"Local Interface:
*" TABLES
*" T_INPUT STRUCTURE ZMM_CHAR1
*" T1_DISPLAY STRUCTURE ZMM_CHAR
*" T1_UPDATE STRUCTURE ZMM_CHAR2
*" T1_CRE_UPDATE STRUCTURE ZMM_CHAR2
*"---------------------------------------------------------------------
-

IF t_input[] IS NOT INITIAL.


REFRESH:t1_display[], t_display[].
t_mat1[] = t_input[].
DELETE t_mat1[] WHERE charg IS NOT INITIAL OR chactername1 IS NOT
INITIAL.
***********************************Step1 Creating
Batches***************************************
LOOP AT t_mat1[] INTO w_mat1.
* PERFORM create_batch.
* t1_create[] = t_create[].
PERFORM display1.
t1_display[] = t_display[].
ENDLOOP.
************************************End1*******************************
*******

***************************************Step2 Displaying Batch


Characterstics*******************************************
REFRESH: t_mat1[],t_display[].
t_mat1[] = t_input[].
DELETE t_mat1[] WHERE charg IS INITIAL OR chactername1 IS NOT
INITIAL.
LOOP AT t_mat1[] INTO w_mat1.
PERFORM display.
APPEND LINES OF t_display[] TO t1_display[].
* t1_display[] = t_display[].
ENDLOOP.
****************************************End2***************************
****************

****************************************Step3 Updating Batch


Characterstics *******************************************
REFRESH: t_mat1[].
t_mat1[] = t_input[].
REFRESH:t_update[],t1_update[].
DELETE t_mat1[] WHERE charg IS INITIAL OR chactername1 IS INITIAL .
LOOP AT t_mat1[] INTO w_mat1.
PERFORM update.
t1_update[] = t_update[].
ENDLOOP.
***********************************End3********************************
*********
*
*******************************Step4 Creating Bathces and Updating
Characterstics***********************************************
REFRESH: t_mat1[],t1_cre_update[],t_update[]..
t_mat1[] = t_input[].
DELETE t_mat1[] WHERE charg IS NOT INITIAL OR chactername1 IS
INITIAL.
LOOP AT t_mat1[] INTO w_mat1.
PERFORM create_update.
t1_cre_update[] = t_update[].
ENDLOOP.
*******************************End4************************************
*******
ENDIF.
ENDFUNCTION.

TOP INCLUDE DECLARATION

==========================

DATA:t_mat1 TYPE TABLE OF zmm_char1,


w_mat1 TYPE zmm_char1,
t_mat2 TYPE TABLE OF zmm_char1,
w_mat2 TYPE zmm_char1,
t_mat3 TYPE TABLE OF zmm_char1,
w_mat3 TYPE zmm_char1,
t_mat4 TYPE TABLE OF zmm_char1,
w_mat4 TYPE zmm_char1.

*///1st step declaration

DATA: lv_objecttable TYPE bapi1003_key-objecttable,


lv_objectkey_conc TYPE bapi1003_key-object,
t_objectkeytable TYPE TABLE OF bapi1003_object_keys,
w_objectkeytable TYPE bapi1003_object_keys,
t_return TYPE TABLE OF bapiret2,
w_return TYPE bapiret2,
lv_material TYPE bapibatchkey-material,
lv_plant TYPE bapibatchkey-plant,
lv_object type AUSP-OBJEK,
lv_batch TYPE bapibatchkey-batch,
w_create TYPE zmm_char2,
t_class TYPE TABLE OF sclass,
w_class TYPE sclass,
t_objectdata TYPE TABLE OF clobjdat,
w_objectdata TYPE clobjdat.

DATA: t_allocvaluesnum TYPE TABLE OF bapi1003_alloc_values_num,


t_allocvalueschar TYPE TABLE OF bapi1003_alloc_values_char,
t_allocvaluescurr TYPE TABLE OF bapi1003_alloc_values_curr,
w_allocvaluesnum TYPE bapi1003_alloc_values_num,
w_allocvalueschar TYPE bapi1003_alloc_values_char,
w_allocvaluescurr TYPE bapi1003_alloc_values_curr,
w_display TYPE zmm_char.

DATA:t_display TYPE TABLE OF zmm_char,


t_create TYPE TABLE OF zmm_char2,
t_update TYPE TABLE OF zmm_char2,
w_update TYPE zmm_char2.

Table Parameters

================

T_INPUT LIKE ZMM_CHAR1

T1_DISPLAY LIKE ZMM_CHAR

T1_UPDATE LIKE ZMM_CHAR2

T1_CRE_UPDATE LIKE ZMM_CHAR2

Structure ZMM_CHAR1

======================

MATNR 1 Types MATNR CHAR 18 0 material code

WERKS 1 Types WERKS_D CHAR 4 0 Plant

LGORT 1 Types LGORT_D CHAR 4 0 Storage Location

CHARG 1 Types CHARG_D CHAR 10 0 Batch Number


CHACTERNAME1 CHAR 30 0 Characteristic Name 1

CHARVALUE1 CHAR 30 0 Characteristic Value 1

VALUE_FROM1 FLTP 16 16 Numeric Value 1

VALUE_TO1 FLTP 16 16 Numeric value 1

CURRENCY_FROM1 FLTP 16 16 Currency Value 1

CURRENCY_TO1 FLTP 16 16 Currency value 1

CHACTERNAME2 CHAR 30 0 Characteristic Name 2

CHARVALUE2 CHAR 30 0 Characteristic Value 2

VALUE_FROM2 FLTP 16 16 Numeric Value 2

VALUE_TO2 FLTP 16 16 Numeric value 2

CURRENCY_FROM2 FLTP 16 16 Currency Value 2

CURRENCY_TO2 FLTP 16 16 Currency value 2

CHACTERNAME3 CHAR 30 0 Characteristic Name 3

CHARVALUE3 CHAR 30 0 Characteristic Value 3

VALUE_FROM3 FLTP 16 16 Numeric Value 3

VALUE_TO3 FLTP 16 16 Numeric Value 3

CURRENCY_FROM3 FLTP 16 16 Currency Value 3

CURRENCY_TO3 FLTP 16 16 Currency value 3

CHACTERNAME4 CHAR 30 0 Characteristic Name 4

CHARVALUE4 CHAR 30 0 Characteristic Value 4

VALUE_FROM4 FLTP 16 16 Numeric Value 4

VALUE_TO4 FLTP 16 16 Numeric Value 4

CURRENCY_FROM4 FLTP 16 16 Currency Value 4

CURRENCY_TO4 FLTP 16 16 Currency value 4

CHACTERNAME5 CHAR 30 0 Characteristic Name 5

CHARVALUE5 CHAR 30 0 Characteristic Value 5

VALUE_FROM5 FLTP 16 16 Numeric Value 5

VALUE_TO5 FLTP 16 16 Numeric Value 5


CURRENCY_FROM5 FLTP 16 16 Currency Value 5

CURRENCY_TO5 FLTP 16 16 Currency value 5

REMARKS CHAR 30 0 Remarks

ZMM_CHAR

==========

MATNR MATNR CHAR 18 0 material code

WERKS WERKS_D CHAR 4 0 Plant

LGORT LGORT_D CHAR 4 0 Storage Location

CHARG CHARG_D CHAR 10 0 Batch Number

CHARACT ATNAM CHAR 30 0 Characteristic Name

CHARACT_DESCR ATBEZ CHAR 30 0 Characteristic

VALUE_CHAR ATWRT CHAR 30 0 Characteristic Value

VALUE_FROM ATFLV FLTP 16 16 Internal floating point

VALUE_TO ATFLB FLTP 16 16 Internal floating point

UNIT_FROM MEINS UNIT 3 0 Vignesh

UNIT_TO MEINS UNIT 3 0 Vignesh

CURRENCY_FROM WAERS CUKY 5 0 Currency Key

CURRENCY_TO WAERS CUKY 5 0 Currency Key

INHERITED FLINH CHAR 1 0 Indicator:

INSTANCE ATZIS NUMC 3 0 Instance counter

ZMM_CHAR2

==============

MSG 1 Types CHAR 100 0 Remarks


Source Code for PERFORM STATMENTS

===================================

*----------------------------------------------------------------------
*
***INCLUDE LZMATERIAL_CLASSFICATIONF01.
*----------------------------------------------------------------------
*
*&---------------------------------------------------------------------
*
*& Form DISPLAY
*&---------------------------------------------------------------------
*
* text
*----------------------------------------------------------------------
*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
*
FORM display .
CLEAR: lv_objecttable,w_objectkeytable,lv_objectkey_conc.
REFRESH:t_objectkeytable.
* IF w_mat1-matnr IS NOT INITIAL AND w_mat1-werks IS INITIAL.
lv_objecttable = 'MCH1'.
w_objectkeytable-key_field = 'MATNR'.
w_objectkeytable-value_int = w_mat1-matnr.
APPEND w_objectkeytable TO t_objectkeytable.
CLEAR:w_objectkeytable.
w_objectkeytable-key_field = 'CHARG'.
w_objectkeytable-value_int = w_mat1-charg.
APPEND w_objectkeytable TO t_objectkeytable.
CLEAR:w_objectkeytable.
* ELSE.
* lv_objecttable = 'MCHA'.
* w_objectkeytable-key_field = 'MATNR'.
* w_objectkeytable-value_int = w_mat1-matnr.
* APPEND w_objectkeytable TO t_objectkeytable.
* CLEAR:w_objectkeytable.
* w_objectkeytable-key_field = 'WERKS'.
* w_objectkeytable-value_int = w_mat1-werks.
* APPEND w_objectkeytable TO t_objectkeytable.
* CLEAR:w_objectkeytable.
* w_objectkeytable-key_field = 'CHARG'.
* w_objectkeytable-value_int = w_mat1-charg.
* APPEND w_objectkeytable TO t_objectkeytable.
* CLEAR:w_objectkeytable.
* ENDIF.

CALL FUNCTION 'BAPI_OBJCL_CONCATENATEKEY'


EXPORTING
objecttable = lv_objecttable
IMPORTING
objectkey_conc = lv_objectkey_conc
TABLES
objectkeytable = t_objectkeytable
return = t_return.
IF sy-subrc NE 0 AND t_return IS NOT INITIAL.
READ TABLE t_return INTO w_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
EXIT.
ENDIF.
ELSE.
lv_object = w_mat1-matnr.
CALL FUNCTION 'CLAF_CLASSIFICATION_OF_OBJECTS'
EXPORTING
classtype = '023'
features = 'X'
language = sy-langu
object = lv_object
objecttable = 'MARA'
key_date = sy-datum
initial_charact = 'X'
TABLES
t_class = t_class
t_objectdata = t_objectdata
EXCEPTIONS
no_classification = 1
no_classtypes = 2
invalid_class_type = 3
OTHERS = 4.

READ TABLE t_class INTO w_class INDEX 1.


IF sy-subrc EQ 0.
CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'
EXPORTING
objectkey = lv_objectkey_conc
objecttable = lv_objecttable
classnum = w_class-class
classtype = '023'
keydate = sy-datum
language = sy-langu
TABLES
allocvaluesnum = t_allocvaluesnum
allocvalueschar = t_allocvalueschar
allocvaluescurr = t_allocvaluescurr
return = t_return.
IF sy-subrc NE 0 AND t_return[] IS NOT INITIAL.
READ TABLE t_return INTO w_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
EXIT.
ENDIF.
ELSE.
IF t_allocvaluesnum[] IS NOT INITIAL.
LOOP AT t_allocvaluesnum INTO w_allocvaluesnum.
w_display-matnr = w_mat1-matnr.
w_display-werks = w_mat1-werks.
w_display-lgort = w_mat1-lgort.
w_display-charg = w_mat1-charg.
w_display-charact = w_allocvaluesnum-charact.
w_display-value_from = w_allocvaluesnum-value_from .
w_display-value_to = w_allocvaluesnum-value_to .
w_display-unit_from = w_allocvaluesnum-unit_from.
w_display-unit_to = w_allocvaluesnum-unit_to .
w_display-inherited = w_allocvaluesnum-inherited .
w_display-instance = w_allocvaluesnum-instance .
w_display-charact_descr = w_allocvaluesnum-charact_descr.
APPEND w_display TO t_display.
CLEAR:w_display.
ENDLOOP.
ENDIF.
IF t_allocvalueschar[] IS NOT INITIAL.
LOOP AT t_allocvalueschar INTO w_allocvalueschar.
w_display-matnr = w_mat1-matnr.
w_display-werks = w_mat1-werks.
w_display-lgort = w_mat1-lgort.
w_display-charg = w_mat1-charg.
w_display-charact = w_allocvalueschar-charact.
w_display-value_char = w_allocvalueschar-value_char.
w_display-inherited = w_allocvalueschar-inherited .
w_display-instance = w_allocvalueschar-instance .
w_display-charact_descr = w_allocvalueschar-charact_descr.
APPEND w_display TO t_display.
CLEAR:w_display.
ENDLOOP.
ENDIF.
IF t_allocvaluescurr[] IS NOT INITIAL.
LOOP AT t_allocvaluescurr INTO w_allocvaluescurr.
w_display-matnr = w_mat1-matnr.
w_display-werks = w_mat1-werks.
w_display-lgort = w_mat1-lgort.
w_display-charg = w_mat1-charg.
w_display-charact = w_allocvaluescurr-charact.
w_display-value_from = w_allocvaluescurr-value_from .
w_display-value_to = w_allocvaluescurr-value_to .
w_display-currency_from = w_allocvaluescurr-currency_from.
w_display-currency_to = w_allocvaluescurr-currency_to .
w_display-inherited = w_allocvaluescurr-inherited .
w_display-instance = w_allocvaluescurr-instance .
w_display-charact_descr = w_allocvaluescurr-charact_descr.
APPEND w_display TO t_display.
CLEAR:w_display.
ENDLOOP.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
*************************2nd
End*****************************************
ENDFORM. " DISPLAY
*&---------------------------------------------------------------------
*
*& Form CREATE_BATCH
*&---------------------------------------------------------------------
*
* text
*----------------------------------------------------------------------
*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
*
FORM create_batch .
CLEAR : lv_objecttable ,
lv_objectkey_conc,
lv_batch,
w_return,
lv_material,
lv_plant.

REFRESH:t_objectkeytable ,
t_return .
IF w_mat1-matnr IS NOT INITIAL AND w_mat1-werks IS NOT INITIAL.
lv_material = w_mat1-matnr.
lv_plant = w_mat1-werks .
CALL FUNCTION 'BAPI_BATCH_CREATE'
EXPORTING
material = lv_material
plant = lv_plant
IMPORTING
batch = lv_batch
TABLES
return = t_return.
IF t_return IS NOT INITIAL.
READ TABLE t_return INTO w_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
EXIT.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
ENDIF.
IF lv_batch IS NOT INITIAL.
w_create-msg = lv_batch.
CONCATENATE text-101 lv_batch text-102 lv_material text-103
lv_plant INTO w_create-msg SEPARATED BY space.
APPEND w_create TO t_create.
CLEAR:w_create.
ENDIF.
ELSE.
lv_material = w_mat1-matnr.
CALL FUNCTION 'BAPI_BATCH_CREATE'
EXPORTING
material = lv_material
IMPORTING
batch = lv_batch
TABLES
return = t_return.
IF t_return IS NOT INITIAL.
READ TABLE t_return INTO w_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
EXIT.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
ENDIF.
IF lv_batch IS NOT INITIAL.
w_create-msg = lv_batch.
CONCATENATE text-101 lv_batch text-102 lv_material INTO w_create-
msg SEPARATED BY space.
APPEND w_create TO t_create.
CLEAR:w_create.
ENDIF.
ENDIF.

ENDFORM. " CREATE_BATCH


*&---------------------------------------------------------------------
*
*& Form UPDATE
*&---------------------------------------------------------------------
*
* text
*----------------------------------------------------------------------
*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
*
FORM update .
CLEAR: lv_objecttable,w_objectkeytable,lv_objectkey_conc.
REFRESH:t_objectkeytable.
* IF w_mat1-matnr IS NOT INITIAL AND w_mat1-werks IS INITIAL.
lv_objecttable = 'MCH1'.
w_objectkeytable-key_field = 'MATNR'.
w_objectkeytable-value_int = w_mat1-matnr.
APPEND w_objectkeytable TO t_objectkeytable.
CLEAR:w_objectkeytable.
w_objectkeytable-key_field = 'CHARG'.
w_objectkeytable-value_int = w_mat1-charg.
APPEND w_objectkeytable TO t_objectkeytable.
CLEAR:w_objectkeytable.
* ELSE.
* lv_objecttable = 'MCHA'.
* w_objectkeytable-key_field = 'MATNR'.
* w_objectkeytable-value_int = w_mat1-matnr.
* APPEND w_objectkeytable TO t_objectkeytable.
* CLEAR:w_objectkeytable.
* w_objectkeytable-key_field = 'WERKS'.
* w_objectkeytable-value_int = w_mat1-werks.
* APPEND w_objectkeytable TO t_objectkeytable.
* CLEAR:w_objectkeytable.
* w_objectkeytable-key_field = 'CHARG'.
* w_objectkeytable-value_int = w_mat1-charg.
* APPEND w_objectkeytable TO t_objectkeytable.
* CLEAR:w_objectkeytable.
* ENDIF.

CALL FUNCTION 'BAPI_OBJCL_CONCATENATEKEY'


EXPORTING
objecttable = lv_objecttable
IMPORTING
objectkey_conc = lv_objectkey_conc
TABLES
objectkeytable = t_objectkeytable
return = t_return.
IF sy-subrc NE 0 AND t_return IS NOT INITIAL.
READ TABLE t_return INTO w_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
EXIT.
ENDIF.
ELSE.
CLEAR:lv_object.
lv_object = w_mat1-matnr.
CALL FUNCTION 'CLAF_CLASSIFICATION_OF_OBJECTS'
EXPORTING
classtype = '023'
features = 'X'
language = sy-langu
object = lv_object
objecttable = 'MARA'
key_date = sy-datum
initial_charact = 'X'
TABLES
t_class = t_class
t_objectdata = t_objectdata
EXCEPTIONS
no_classification = 1
no_classtypes = 2
invalid_class_type = 3
OTHERS = 4.

READ TABLE t_class INTO w_class INDEX 1.


IF sy-subrc EQ 0.
CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'
EXPORTING
objectkey = lv_objectkey_conc
objecttable = lv_objecttable
classnum = w_class-class
classtype = '023'
keydate = sy-datum
language = sy-langu
TABLES
allocvaluesnum = t_allocvaluesnum
allocvalueschar = t_allocvalueschar
allocvaluescurr = t_allocvaluescurr
return = t_return.
IF sy-subrc NE 0 AND t_return[] IS NOT INITIAL.
READ TABLE t_return INTO w_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
EXIT.
ENDIF.
ELSE.
LOOP AT t_allocvalueschar INTO w_allocvalueschar.
IF w_mat1-chactername1 EQ w_allocvalueschar-charact .
IF w_mat1-charvalue1 NE w_allocvalueschar-value_char.
w_allocvalueschar-value_char = w_mat1-charvalue1.
ENDIF.
ELSEIF w_mat1-chactername2 EQ w_allocvalueschar-charact.
IF w_mat1-charvalue2 NE w_allocvalueschar-value_char.
w_allocvalueschar-value_char = w_mat1-charvalue2.
ENDIF.
ELSEIF w_mat1-chactername3 EQ w_allocvalueschar-charact.
IF w_mat1-charvalue3 NE w_allocvalueschar-value_char.
w_allocvalueschar-value_char = w_mat1-charvalue3.
ENDIF.
ELSEIF w_mat1-chactername4 EQ w_allocvalueschar-charact.
IF w_mat1-charvalue4 NE w_allocvalueschar-value_char.
w_allocvalueschar-value_char = w_mat1-charvalue4.
ENDIF.
ELSEIF w_mat1-chactername5 EQ w_allocvalueschar-charact.
IF w_mat1-charvalue5 NE w_allocvalueschar-value_char.
w_allocvalueschar-value_char = w_mat1-charvalue5.
ENDIF.
ENDIF.
MODIFY t_allocvalueschar INDEX sy-tabix FROM
w_allocvalueschar.
ENDLOOP.

LOOP AT t_allocvaluesnum INTO w_allocvaluesnum.


IF w_mat1-chactername1 EQ w_allocvaluesnum-charact .
IF w_mat1-value_from1 NE w_allocvaluesnum-value_from.
w_allocvaluesnum-value_from = w_mat1-value_from1.
ENDIF.
IF w_mat1-value_to1 NE w_allocvaluesnum-value_to.
w_allocvaluesnum-value_to = w_mat1-value_to1.
ENDIF.
ELSEIF w_mat1-chactername2 EQ w_allocvaluesnum-charact.
IF w_mat1-value_from2 NE w_allocvaluesnum-value_from.
w_allocvaluesnum-value_from = w_mat1-value_from2.
ENDIF.
IF w_mat1-value_to2 NE w_allocvaluesnum-value_to.
w_allocvaluesnum-value_to = w_mat1-value_to2.
ENDIF.
ELSEIF w_mat1-chactername3 EQ w_allocvaluesnum-charact.
IF w_mat1-value_from3 NE w_allocvaluesnum-value_from.
w_allocvaluesnum-value_from = w_mat1-value_from3.
ENDIF.
IF w_mat1-value_to3 NE w_allocvaluesnum-value_to.
w_allocvaluesnum-value_to = w_mat1-value_to3.
ENDIF.
ELSEIF w_mat1-chactername4 EQ w_allocvaluesnum-charact.
IF w_mat1-value_from1 NE w_allocvaluesnum-value_from.
w_allocvaluesnum-value_from = w_mat1-value_from1.
ENDIF.
IF w_mat1-value_to4 NE w_allocvaluesnum-value_to.
w_allocvaluesnum-value_to = w_mat1-value_to4.
ENDIF.
ELSEIF w_mat1-chactername5 EQ w_allocvaluesnum-charact.
IF w_mat1-value_from1 NE w_allocvaluesnum-value_from.
w_allocvaluesnum-value_from = w_mat1-value_from1.
ENDIF.
IF w_mat1-value_to5 NE w_allocvaluesnum-value_to.
w_allocvaluesnum-value_to = w_mat1-value_to5.
ENDIF.
ENDIF.
MODIFY t_allocvaluesnum INDEX sy-tabix FROM w_allocvaluesnum
TRANSPORTING value_from value_to.
ENDLOOP.

LOOP AT t_allocvaluescurr INTO w_allocvaluescurr.


IF w_mat1-chactername1 EQ w_allocvaluescurr-charact .
IF w_mat1-currency_from1 NE w_allocvaluescurr-value_from.
w_allocvaluescurr-value_from = w_mat1-currency_from1.
ENDIF.
IF w_mat1-currency_to1 NE w_allocvaluescurr-value_to.
w_allocvaluescurr-value_to = w_mat1-currency_to1.
ENDIF.
ELSEIF w_mat1-chactername2 EQ w_allocvaluescurr-charact.
IF w_mat1-currency_from2 NE w_allocvaluescurr-value_from.
w_allocvaluescurr-value_from = w_mat1-currency_from2.
ENDIF.
IF w_mat1-currency_to2 NE w_allocvaluescurr-value_to.
w_allocvaluescurr-value_to = w_mat1-currency_to2.
ENDIF.
ELSEIF w_mat1-chactername3 EQ w_allocvaluescurr-charact.
IF w_mat1-currency_from3 NE w_allocvaluescurr-value_from.
w_allocvaluescurr-value_from = w_mat1-currency_from3.
ENDIF.
IF w_mat1-currency_to3 NE w_allocvaluescurr-value_to.
w_allocvaluescurr-value_to = w_mat1-currency_to3.
ENDIF.
ELSEIF w_mat1-chactername4 EQ w_allocvaluescurr-charact.
IF w_mat1-currency_from4 NE w_allocvaluescurr-value_from.
w_allocvaluescurr-value_from = w_mat1-currency_from4.
ENDIF.
IF w_mat1-currency_to4 NE w_allocvaluescurr-value_to.
w_allocvaluescurr-value_to = w_mat1-currency_to4.
ENDIF.
ELSEIF w_mat1-chactername5 EQ w_allocvaluescurr-charact.
IF w_mat1-currency_from5 NE w_allocvaluescurr-value_from.
w_allocvaluescurr-value_from = w_mat1-currency_from5.
ENDIF.
IF w_mat1-currency_to5 NE w_allocvaluescurr-value_to.
w_allocvaluescurr-value_to = w_mat1-currency_to5.
ENDIF.
ENDIF.
MODIFY t_allocvaluescurr INDEX sy-tabix FROM w_allocvaluescurr
TRANSPORTING currency_from currency_to.
ENDLOOP.

CALL FUNCTION 'BAPI_OBJCL_CHANGE'


EXPORTING
objectkey = lv_objectkey_conc
objecttable = lv_objecttable
classnum = w_class-class
classtype = '023'
keydate = sy-datum
TABLES
allocvaluesnumnew = t_allocvaluesnum
allocvaluescharnew = t_allocvalueschar
allocvaluescurrnew = t_allocvaluescurr
return = t_return.

IF sy-subrc NE 0 AND t_return[] IS NOT INITIAL.


READ TABLE t_return INTO w_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
EXIT.
ENDIF.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
CONCATENATE text-105 w_mat1-charg text-106 w_mat1-matnr text-
103 w_mat1-werks
INTO w_update
SEPARATED BY space.
APPEND w_update TO t_update.
CLEAR:w_update.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " UPDATE
*&---------------------------------------------------------------------
*
*& Form CREATE_UPDATE
*&---------------------------------------------------------------------
*
* text
*----------------------------------------------------------------------
*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
*
FORM create_update .
CLEAR : lv_objecttable ,
lv_objectkey_conc,
lv_batch,
w_return,
lv_material,
w_allocvaluesnum,
w_objectkeytable,w_class,
w_objectdata,w_allocvaluesnum,
w_allocvalueschar,w_allocvaluescurr,w_return,
lv_plant.
REFRESH:t_objectkeytable,t_class,
t_objectdata,t_allocvaluesnum,
t_allocvalueschar,t_allocvaluescurr,t_return.

IF w_mat1-matnr IS NOT INITIAL AND w_mat1-werks IS NOT INITIAL.


lv_material = w_mat1-matnr.
lv_plant = w_mat1-werks .
CALL FUNCTION 'BAPI_BATCH_CREATE'
EXPORTING
material = lv_material
plant = lv_plant
IMPORTING
batch = lv_batch
TABLES
return = t_return.
IF sy-subrc IS NOT INITIAL.
READ TABLE t_return INTO w_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
EXIT.
ENDIF.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
ELSE.
lv_material = w_mat1-matnr.
CALL FUNCTION 'BAPI_BATCH_CREATE'
EXPORTING
material = lv_material
IMPORTING
batch = lv_batch
TABLES
return = t_return.
IF sy-subrc IS NOT INITIAL.
READ TABLE t_return INTO w_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
EXIT.
ENDIF.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
ENDIF.
IF lv_batch IS NOT INITIAL.
* IF w_mat1-matnr IS NOT INITIAL AND w_mat1-werks IS INITIAL.
lv_objecttable = 'MCH1'.
w_objectkeytable-key_field = 'MATNR'.
w_objectkeytable-value_int = w_mat1-matnr.
APPEND w_objectkeytable TO t_objectkeytable.
CLEAR:w_objectkeytable.
w_objectkeytable-key_field = 'CHARG'.
w_objectkeytable-value_int = lv_batch.
APPEND w_objectkeytable TO t_objectkeytable.
CLEAR:w_objectkeytable.
* ELSE.
* lv_objecttable = 'MCHA'.
* w_objectkeytable-key_field = 'MATNR'.
* w_objectkeytable-value_int = w_mat1-matnr.
* APPEND w_objectkeytable TO t_objectkeytable.
* CLEAR:w_objectkeytable.
* w_objectkeytable-key_field = 'WERKS'.
* w_objectkeytable-value_int = w_mat1-werks.
* APPEND w_objectkeytable TO t_objectkeytable.
* CLEAR:w_objectkeytable.
* w_objectkeytable-key_field = 'CHARG'.
* w_objectkeytable-value_int = lv_batch.
* APPEND w_objectkeytable TO t_objectkeytable.
* CLEAR:w_objectkeytable.
* ENDIF.
CALL FUNCTION 'BAPI_OBJCL_CONCATENATEKEY'
EXPORTING
objecttable = lv_objecttable
IMPORTING
objectkey_conc = lv_objectkey_conc
TABLES
objectkeytable = t_objectkeytable
return = t_return.
IF sy-subrc NE 0 AND t_return IS NOT INITIAL.
READ TABLE t_return INTO w_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
EXIT.
ENDIF.
ELSE.
CLEAR:lv_object.
lv_object = w_mat1-matnr.
CALL FUNCTION 'CLAF_CLASSIFICATION_OF_OBJECTS'
EXPORTING
classtype = '023'
features = 'X'
language = sy-langu
object = lv_object
objecttable = 'MARA'
key_date = sy-datum
initial_charact = 'X'
TABLES
t_class = t_class
t_objectdata = t_objectdata
EXCEPTIONS
no_classification = 1
no_classtypes = 2
invalid_class_type = 3
OTHERS = 4.
READ TABLE t_class INTO w_class INDEX 1.
IF sy-subrc EQ 0.
IF w_mat1-chactername1 IS NOT INITIAL.
IF w_mat1-value_from1 IS NOT INITIAL OR w_mat1-value_to1 IS
NOT INITIAL.
w_allocvaluesnum-charact = w_mat1-chactername1.
w_allocvaluesnum-value_from = w_mat1-value_from1.
w_allocvaluesnum-value_to = w_mat1-value_to1.
APPEND w_allocvaluesnum TO t_allocvaluesnum.
CLEAR:w_allocvaluesnum.
ENDIF.
IF w_mat1-charvalue1 IS NOT INITIAL.
w_allocvalueschar-charact = w_mat1-chactername1.
w_allocvalueschar-value_char = w_mat1-charvalue1.
APPEND w_allocvalueschar TO t_allocvalueschar.
CLEAR:w_allocvalueschar.
ENDIF.
IF w_mat1-currency_from1 IS NOT INITIAL OR w_mat1-currency_to1
IS NOT INITIAL.
w_allocvaluescurr-charact = w_mat1-chactername1.
w_allocvaluescurr-value_from = w_mat1-currency_from1.
w_allocvaluescurr-value_to = w_mat1-currency_to1.
APPEND w_allocvaluescurr TO t_allocvaluescurr.
CLEAR:w_allocvaluescurr.
ENDIF.
ELSEIF w_mat1-chactername2 IS NOT INITIAL.
IF w_mat1-value_from2 IS NOT INITIAL OR w_mat1-value_to2 IS
NOT INITIAL.
w_allocvaluesnum-charact = w_mat1-chactername2.
w_allocvaluesnum-value_from = w_mat1-value_from2.
w_allocvaluesnum-value_to = w_mat1-value_to2.
APPEND w_allocvaluesnum TO t_allocvaluesnum.
CLEAR:w_allocvaluesnum.
ENDIF.
IF w_mat1-charvalue2 IS NOT INITIAL.
w_allocvalueschar-charact = w_mat1-chactername2.
w_allocvalueschar-value_char = w_mat1-charvalue2.
APPEND w_allocvalueschar TO t_allocvalueschar.
CLEAR:w_allocvalueschar.
ENDIF.
IF w_mat1-currency_from2 IS NOT INITIAL OR w_mat1-currency_to2
IS NOT INITIAL.
w_allocvaluescurr-charact = w_mat1-chactername2.
w_allocvaluescurr-value_from = w_mat1-currency_from2.
w_allocvaluescurr-value_to = w_mat1-currency_to2.
APPEND w_allocvaluescurr TO t_allocvaluescurr.
CLEAR:w_allocvaluescurr.
ENDIF.
ELSEIF w_mat1-chactername3 IS NOT INITIAL.
IF w_mat1-value_from3 IS NOT INITIAL OR w_mat1-value_to3 IS
NOT INITIAL.
w_allocvaluesnum-charact = w_mat1-chactername3.
w_allocvaluesnum-value_from = w_mat1-value_from3.
w_allocvaluesnum-value_to = w_mat1-value_to3.
APPEND w_allocvaluesnum TO t_allocvaluesnum.
CLEAR:w_allocvaluesnum.
ENDIF.
IF w_mat1-charvalue3 IS NOT INITIAL.
w_allocvalueschar-charact = w_mat1-chactername3.
w_allocvalueschar-value_char = w_mat1-charvalue3.
APPEND w_allocvalueschar TO t_allocvalueschar.
CLEAR:w_allocvalueschar.
ENDIF.
IF w_mat1-currency_from3 IS NOT INITIAL OR w_mat1-currency_to3
IS NOT INITIAL.
w_allocvaluescurr-charact = w_mat1-chactername3.
w_allocvaluescurr-value_from = w_mat1-currency_from3.
w_allocvaluescurr-value_to = w_mat1-currency_to3.
APPEND w_allocvaluescurr TO t_allocvaluescurr.
CLEAR:w_allocvaluescurr.
ENDIF.
ELSEIF w_mat1-chactername4 IS NOT INITIAL.
IF w_mat1-value_from4 IS NOT INITIAL OR w_mat1-value_to4 IS
NOT INITIAL.
w_allocvaluesnum-charact = w_mat1-chactername4.
w_allocvaluesnum-value_from = w_mat1-value_from4.
w_allocvaluesnum-value_to = w_mat1-value_to4.
APPEND w_allocvaluesnum TO t_allocvaluesnum.
CLEAR:w_allocvaluesnum.
ENDIF.
IF w_mat1-charvalue4 IS NOT INITIAL.
w_allocvalueschar-charact = w_mat1-chactername4.
w_allocvalueschar-value_char = w_mat1-charvalue4.
APPEND w_allocvalueschar TO t_allocvalueschar.
CLEAR:w_allocvalueschar.
ENDIF.
IF w_mat1-currency_from4 IS NOT INITIAL OR w_mat1-currency_to4
IS NOT INITIAL.
w_allocvaluescurr-charact = w_mat1-chactername4.
w_allocvaluescurr-value_from = w_mat1-currency_from4.
w_allocvaluescurr-value_to = w_mat1-currency_to4.
APPEND w_allocvaluescurr TO t_allocvaluescurr.
CLEAR:w_allocvaluescurr.
ENDIF.
ELSEIF w_mat1-chactername5 IS NOT INITIAL.
IF w_mat1-value_from5 IS NOT INITIAL OR w_mat1-value_to5 IS
NOT INITIAL.
w_allocvaluesnum-charact = w_mat1-chactername5.
w_allocvaluesnum-value_from = w_mat1-value_from5.
w_allocvaluesnum-value_to = w_mat1-value_to5.
APPEND w_allocvaluesnum TO t_allocvaluesnum.
CLEAR:w_allocvaluesnum.
ENDIF.
IF w_mat1-charvalue5 IS NOT INITIAL.
w_allocvalueschar-charact = w_mat1-chactername5.
w_allocvalueschar-value_char = w_mat1-charvalue5.
APPEND w_allocvalueschar TO t_allocvalueschar.
CLEAR:w_allocvalueschar.
ENDIF.
IF w_mat1-currency_from5 IS NOT INITIAL OR w_mat1-currency_to5
IS NOT INITIAL.
w_allocvaluescurr-charact = w_mat1-chactername5.
w_allocvaluescurr-value_from = w_mat1-currency_from5.
w_allocvaluescurr-value_to = w_mat1-currency_to5.
APPEND w_allocvaluescurr TO t_allocvaluescurr.
CLEAR:w_allocvaluescurr.
ENDIF.
ENDIF.

CALL FUNCTION 'BAPI_OBJCL_CREATE'


EXPORTING
objectkeynew = lv_objectkey_conc
objecttablenew = lv_objecttable
classnumnew = w_class-class
classtypenew = '023'
keydate = sy-datum
TABLES
allocvaluesnum = t_allocvaluesnum
allocvalueschar = t_allocvalueschar
allocvaluescurr = t_allocvaluescurr
return = t_return.
IF t_return[] IS NOT INITIAL.
READ TABLE t_return INTO w_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
EXIT.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
CONCATENATE text-101 lv_batch text-102 w_mat1-matnr text-103
w_mat1-werks text-107
INTO w_update
SEPARATED BY space.
APPEND w_update TO t_update.
CLEAR:w_update.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " CREATE_UPDATE
*&---------------------------------------------------------------------
*
*& Form DISPLAY1
*&---------------------------------------------------------------------
*
* text
*----------------------------------------------------------------------
*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------
*
FORM display1 .
lv_object = w_mat1-matnr.
CALL FUNCTION 'CLAF_CLASSIFICATION_OF_OBJECTS'
EXPORTING
classtype = '023'
features = 'X'
language = sy-langu
object = lv_object
objecttable = 'MARA'
key_date = sy-datum
initial_charact = 'X'
TABLES
t_class = t_class
t_objectdata = t_objectdata
EXCEPTIONS
no_classification = 1
no_classtypes = 2
invalid_class_type = 3
OTHERS = 4.
IF sy-subrc EQ 0.
LOOP AT t_objectdata INTO w_objectdata.
w_display-matnr = w_mat1-matnr.
w_display-werks = w_mat1-werks.
w_display-lgort = w_mat1-lgort.
w_display-charact = w_objectdata-atnam.
w_display-charact_descr = w_objectdata-smbez.
APPEND w_display TO t_display.
CLEAR:w_display.
ENDLOOP.
ENDIF.
ENDFORM. " DISPLAY1

You might also like