批次更新BAPI_OBJCL_CHANGE

时间:2023-12-27 18:45:25

FORM frm_edit_batch  TABLES pt_field STRUCTURE dfies
USING ps_batch TYPE ty_batch
CHANGING ps_rturn TYPE bapiret2.  DATA : lv_key TYPE bapi1003_key-object,
lv_table TYPE bapi1003_key-objecttable VALUE 'MCH1',
lv_class TYPE bapi1003_key-classnum VALUE 'Z_CLASS_BATCH',
lv_class_type TYPE bapi1003_key-classtype VALUE '',
lv_status TYPE bapi1003_key-status,
*--------------------TUS-CHARG-BEGIN---------------------------------*
lt_alloc_curr TYPE TABLE OF zbapi1003_alloc_values_curr,
lt_alloc_num TYPE TABLE OF zbapi1003_alloc_values_num,
lt_alloc_char TYPE TABLE OF zbapi1003_alloc_values_char,
*--------------------TUS-CHARG-END-----------------------------------*
lt_return TYPE TABLE OF bapiret2,
ls_return TYPE bapiret2.
DATA:ls_field TYPE dfies,
lv_field() TYPE c. *--------------------TUS-CHARG-BEGIN---------------------------------*
FIELD-SYMBOLS:
<fs_s_alloc_curr> TYPE zbapi1003_alloc_values_curr,
<fs_s_alloc_char> TYPE zbapi1003_alloc_values_char,
<fs_s_alloc_num> TYPE zbapi1003_alloc_values_num,
<fs_value>.
*--------------------TUS-CHARG-END-----------------------------------*
REFRESH:lt_alloc_curr,lt_return,lt_alloc_num,lt_alloc_char.
CLEAR:lv_key,lv_status,ls_return. lv_key+() = ps_batch-matnr.
lv_key+() = ps_batch-charg.
*--------------------TUS-CHARG-BEGIN---------------------------------*
CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'
EXPORTING
objectkey = lv_key
objecttable = lv_table
classnum = lv_class
classtype = lv_class_type
keydate = sy-datum
language = sy-langu
IMPORTING
status = lv_status
TABLES
allocvaluesnum = lt_alloc_num
allocvalueschar = lt_alloc_char
allocvaluescurr = lt_alloc_curr
return = lt_return.
*--------------------TUS-CHARG-END-----------------------------------*
LOOP AT pt_field INTO ls_field.
CLEAR lv_field.
CONCATENATE 'Z_' ls_field-fieldname INTO lv_field. ASSIGN COMPONENT ls_field-fieldname OF STRUCTURE ps_batch TO <fs_value>.
IF sy-subrc EQ .
CASE ls_field-datatype.
WHEN 'CHAR'.
READ TABLE lt_alloc_char ASSIGNING <fs_s_alloc_char> WITH KEY charact = lv_field.
IF sy-subrc = .
IF <fs_value> IS NOT INITIAL.
<fs_s_alloc_char>-charact = lv_field.
<fs_s_alloc_char>-value_char = <fs_value>.
<fs_s_alloc_char>-value_neutral = <fs_value>.
ENDIF.
ELSE.
APPEND INITIAL LINE TO lt_alloc_char ASSIGNING <fs_s_alloc_char>.
<fs_s_alloc_char>-charact = lv_field.
<fs_s_alloc_char>-value_char = <fs_value>.
<fs_s_alloc_char>-value_neutral = <fs_value>.
ENDIF.
IF <fs_value> EQ ''.
CLEAR : <fs_s_alloc_char>-value_char,<fs_s_alloc_char>-value_neutral.
ENDIF. WHEN 'DEC' OR 'QUAN'.
READ TABLE lt_alloc_num ASSIGNING <fs_s_alloc_num> WITH KEY charact = lv_field.
IF sy-subrc = .
IF <fs_value> IS NOT INITIAL.
<fs_s_alloc_num>-charact = lv_field.
<fs_s_alloc_num>-value_from = <fs_value>.
<fs_s_alloc_num>-value_to = <fs_value>.
ENDIF.
ELSE.
APPEND INITIAL LINE TO lt_alloc_num ASSIGNING <fs_s_alloc_num>.
<fs_s_alloc_num>-charact = lv_field.
<fs_s_alloc_num>-value_from = <fs_value>.
<fs_s_alloc_num>-value_to = <fs_value>.
ENDIF.
IF <fs_value> EQ .
CLEAR: <fs_s_alloc_num>-value_from,<fs_s_alloc_num>-value_to.
ENDIF. WHEN 'CURR'.
READ TABLE lt_alloc_curr ASSIGNING <fs_s_alloc_curr> WITH KEY charact = lv_field.
IF sy-subrc = .
IF <fs_value> IS NOT INITIAL.
<fs_s_alloc_curr>-charact = lv_field.
<fs_s_alloc_curr>-value_from = <fs_value>.
<fs_s_alloc_curr>-currency_from = 'CNY'.
<fs_s_alloc_curr>-currency_from_iso = 'CNY'.
ENDIF.
ELSE.
APPEND INITIAL LINE TO lt_alloc_curr ASSIGNING <fs_s_alloc_curr>.
<fs_s_alloc_curr>-charact = lv_field.
<fs_s_alloc_curr>-value_from = <fs_value>.
<fs_s_alloc_curr>-currency_from = 'CNY'.
<fs_s_alloc_curr>-currency_from_iso = 'CNY'.
ENDIF.
IF <fs_value> EQ .
CLEAR <fs_s_alloc_curr>-value_from .
ENDIF.
WHEN OTHERS.
ENDCASE.
ENDIF.
ENDLOOP. *--------------------TUS-CHARG-BEGIN---------------------------------*
CALL FUNCTION 'BAPI_OBJCL_CHANGE'
EXPORTING
objectkey = lv_key
objecttable = lv_table
classnum = lv_class
classtype = lv_class_type
status = ''
keydate = sy-datum
IMPORTING
classif_status = lv_status
TABLES
allocvaluesnumnew = lt_alloc_num
allocvaluescharnew = lt_alloc_char
allocvaluescurrnew = lt_alloc_curr
return = lt_return.
*--------------------TUS-CHARG-END-----------------------------------*
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'. LOOP AT lt_return INTO ls_return WHERE type = 'E' OR type = 'A'.
ps_rturn = ls_return.
EXIT.
ENDLOOP. ENDFORM. " FRM_EDIT_BATCH


这个批次可以在CL01/02/03 处查看,批次修改和创建参数基本一致。