Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

BAPI_COSTCENTER_CREATEMULTIPLE

Hello Guru's,

I am facing a problem in BAPI_COSTCENTER_CREATEMULTIPLE while processing... that BAPI is executing fine, but data was not getting updated in D/B table, the program i have enclosed below, please have a look and kindly suggest me what is wrong in that...

Helpful Answeres will be Rewarded,

&----


*& Report ZKCZ005R *

*& *

&----


*& *

*& *

&----


REPORT ZKCZ005R NO STANDARD PAGE HEADING LINE-SIZE 255 LINE-COUNT 64

MESSAGE-ID ZFA.

*&----


*& Tables Declaration

*&----


TABLES:T001.

*&----


*& Global Types Declaration

*&----


TYPES: BEGIN OF TY_DATA,

KOSTL TYPE KOSTL, " Cost center

VALID_FROM TYPE DATAB, " From date

VALID_TO TYPE DATBI, " To date

PERSON_IN_CHARGE TYPE VERAK, " Person

DEPARTMENT TYPE ABTEI, " Dept

COSTCENTER_TYPE TYPE KOSAR, " cost center type

COSTCTR_HIER_GRP TYPE KHINR, " cost center hier

COMP_CODE TYPE BUKRS, " company code

BUS_AREA TYPE GSBER, " Business area

PROFIT_CTR TYPE PRCTR, " Profit center

LOCK_UPDATE TYPE BKZOB, " Lock Commit

CSTG_SHEET TYPE AUFKALSM, " Costing Sheet

TITLE TYPE ANRED, " Addr.title

TELCO_LANGU TYPE SPRAS, " Language

NAME TYPE KTEXT, " Name

DESC TYPE KLTXT, " Description

MSG(55) TYPE C, " Message

END OF TY_DATA.

*&----


*& Work area Declaration

*&----


DATA:

WA_DATA TYPE TY_DATA.

*&----


*& Internal tables Declaration

*&----


DATA: T_DATA TYPE STANDARD TABLE OF TY_DATA INITIAL SIZE 0,

t_write_list TYPE TABLE OF abaplist.

************************************************************************

*Global Variables

************************************************************************

CONSTANTS: c_yes TYPE xfeld VALUE 'X'.

data: v_subrc TYPE sy-subrc,

v_error_exist TYPE xfeld.

*&----


*& Selection Screen Declaration

*&----


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS: p_test TYPE checkbox DEFAULT 'X'.

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.

SELECTION-SCREEN BEGIN OF LINE.

PARAMETERS: rb_file RADIOBUTTON GROUP r1.

SELECTION-SCREEN COMMENT 3(29) FOR FIELD p_file.

PARAMETERS: p_file LIKE rlgrap-filename.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN POSITION 3.

SELECTION-SCREEN COMMENT 3(29) FOR FIELD p_header.

PARAMETERS: p_header(3) TYPE n DEFAULT 1.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.

PARAMETERS: rb_clbd RADIOBUTTON GROUP r1.

SELECTION-SCREEN COMMENT (28) text-003.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK b2.

PARAMETERS: p_intca TYPE c NO-DISPLAY. " Internal call

*----


  • Screen Validations

*----


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

PERFORM get_filename USING p_file.

AT SELECTION-SCREEN ON p_file.

PERFORM validate_filename.

*----


  • Start Of Selection

*----


START-OF-SELECTION.

IF p_intca IS INITIAL.

  • Do this because we do not want to lock the material items

  • when using BAPI_GOODSMVT_CREATE. With SUBMIT, the locks

  • on materials will be released

SUBMIT ZKCZ005R

WITH p_test = p_test

WITH rb_file = rb_file

WITH p_file = p_file

WITH p_header = p_header

WITH rb_clbd = rb_clbd

WITH p_intca = 'X'

EXPORTING LIST TO MEMORY AND RETURN.

CALL FUNCTION 'LIST_FROM_MEMORY'

TABLES

listobject = t_write_list

EXCEPTIONS

not_found = 1

OTHERS = 2.

IF sy-subrc <> 0.

ENDIF.

IF NOT t_write_list[] IS INITIAL.

CALL FUNCTION 'WRITE_LIST'

TABLES

listobject = t_write_list.

ENDIF.

ELSE.

CHECK v_subrc IS INITIAL.

PERFORM upload_data CHANGING v_subrc.

IF v_subrc IS INITIAL.

PERFORM CREATE_DATA.

ENDIF.

  • PERFORM display_data.

ENDIF.

*----


  • End Of Selection

*----


END-OF-SELECTION.

  • ----------------------------------------------------------------------

  • SUBROUTINES

&----


&----


*& Form get_filename

&----


FORM get_filename USING pi_file TYPE rlgrap-filename.

DATA: lv_file TYPE string,

li_files TYPE filetable,

lv_subrc TYPE i,

lv_title TYPE string VALUE 'File System for Pres. Server'.

lv_file = pi_file.

CALL METHOD cl_gui_frontend_services=>file_open_dialog

EXPORTING

window_title = lv_title

default_filename = lv_file

CHANGING

file_table = li_files

rc = lv_subrc

EXCEPTIONS

file_open_dialog_failed = 1

cntl_error = 2

error_no_gui = 3

OTHERS = 4.

READ TABLE li_files INDEX 1 INTO pi_file.

ENDFORM. " get_filename

&----


*& Form validate_filename

&----


FORM validate_filename .

CHECK rb_file = c_yes.

IF p_file IS INITIAL.

MESSAGE e318 WITH 'Enter file path name'.

ENDIF.

ENDFORM. " validate_filename

&----


*& Form upload_data

&----


FORM upload_data CHANGING pc_v_subrc TYPE sy-subrc.

DATA: lv_file TYPE string,

lv_subrc LIKE sy-subrc,

lv_tabix TYPE sy-tabix,

lwa_data TYPE TY_data,

lt_clip(1024) OCCURS 0 WITH HEADER LINE.

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

EXPORTING

text = 'Uploading data'(t01).

CLEAR pc_v_subrc.

REFRESH T_data.

IF rb_clbd = 'X'.

CALL FUNCTION 'CLPB_IMPORT'

TABLES

data_tab = lt_clip.

LOOP AT lt_clip.

CHECK lt_clip NE space.

CLEAR lwa_data.

PERFORM asc2dat_konvert

IN PROGRAM saplgrap USING lt_clip lwa_data lv_subrc.

APPEND lwa_data TO T_data.

CLEAR:Lwa_DATA.

ENDLOOP.

ELSEIF rb_file = 'X'.

lv_file = p_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = lv_file

filetype = 'ASC'

has_field_separator = 'X'

dat_mode = 'X'

TABLES

data_tab = t_data

EXCEPTIONS

OTHERS = 4.

IF sy-subrc NE 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

endif.

IF t_data[] IS INITIAL.

pc_v_subrc = 4.

ENDIF.

ENDFORM. " upload_data

&----


*& Form CREATE_data

&----


FORM CREATE_DATA .

DATA: lv_tabix TYPE sy-tabix,

lv_tot_records TYPE i.

    • For BAPI

DATA : lt_data TYPE TABLE OF BAPI0012_CCINPUTLIST,

lT_return TYPE TABLE OF bapiret2,

lv_test TYPE bapi2017_gm_gen-testrun,

LWA_DATA TYPE BAPI0012_CCINPUTLIST,

LV_HEADER TYPE BAPI0012_GEN-CO_AREA.

IF p_test IS INITIAL.

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

EXPORTING

text = 'Posting data'(t02).

ELSE.

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

EXPORTING

text = 'Simulate posting'(t03).

ENDIF.

lv_test = p_test.

LOOP AT T_DATA INTO WA_DATA.

LWA_DATA-COSTCENTER = WA_DATA-KOSTL.

LWA_DATA-VALID_FROM = WA_DATA-VALID_FROM.

LWA_DATA-COMP_CODE = WA_DATA-COMP_CODE.

LWA_DATA-VALID_TO = WA_DATA-VALID_TO.

LWA_DATA-PERSON_IN_CHARGE = WA_DATA-PERSON_IN_CHARGE.

LWA_DATA-DEPARTMENT = WA_DATA-DEPARTMENT.

LWA_DATA-COSTCENTER_TYPE = WA_DATA-COSTCENTER_TYPE.

LWA_DATA-COSTCTR_HIER_GRP = WA_DATA-COSTCTR_HIER_GRP.

LWA_DATA-BUS_AREA = WA_DATA-BUS_AREA.

LWA_DATA-PROFIT_CTR = WA_DATA-PROFIT_CTR.

LWA_DATA-LOCK_IND_COMMITMENT_UPDATE = WA_DATA-LOCK_UPDATE.

LWA_DATA-CSTG_SHEET = WA_DATA-CSTG_SHEET.

LWA_DATA-ADDR_TITLE = WA_DATA-TITLE.

LWA_DATA-TELCO_LANGU = WA_DATA-TELCO_LANGU.

LWA_DATA-NAME = WA_DATA-NAME.

LWA_DATA-DESCRIPT = WA_DATA-DESC.

APPEND: LWA_DATA TO LT_DATA.

CLEAR: LWA_DATA,WA_DATA.

ENDLOOP.

LV_HEADER = 'SG01'.

CALL FUNCTION 'BAPI_COSTCENTER_CREATEMULTIPLE'

EXPORTING

CONTROLLINGAREA = LV_HEADER

TESTRUN = ' '

MASTER_DATA_INACTIVE = ' '

TABLES

COSTCENTERLIST = LT_DATA

RETURN = LT_RETURN

IF SY-SUBRC EQ 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = 'X'.

ELSE.

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

ENDIF.

ENDFORM. " CREATE_data

.Thanks,

Murali

Former Member
Not what you were looking for? View more on this topic or Ask a question