KE51 SAMPLE DEMO BAPI_PROFITCENTER_CREATE

Today we will learn SAP ABAP TCODE KE51 SAMPLE DEMO example  BAPI_PROFITCENTER_CREATE Create Profit Center. You can run this in tr-code se38.

*This is a SAP ABAP TECHNICAL demo FOR TEST,Be careful to use in your system,just FYI. Create Profit Center
*If you have any solution,Please feel free to talk with your IT team/SAP ABAP professional guys.Create Profit Center
*This function module is used to create a new profit center, or a new
*analysis period for an existing profit center. Depending on the
*time-dependence rules set in Customizing, the system either creates a
*new analysis period or merges an analysis period with an existing one.
*The fields <ZH>ProfitCenter, ControllingArea, valid_from, valid_to
*and the fields <ZH>Pctr_Name, In_Charge and <ZH>PrCtr_Hier_Group
*are all mandatory fields.
*
*Authorizations:
*Authorization object K_PCA is relevant here.
*

REPORT ZDEMO_BAPI_PROFITCENTER_CREATE.
PARAMETERS SAMPLE AS CHECKBOX.
INITIALIZATION.
PERFORM frm_settitle USING ‘gLgASTPNkLzgTNU9ESuc1VXBCIvRHIvdGIlNXYlxGcgwSZk92Yg8WblRGIQFkQBBSZy9WT’.
START-OF-SELECTION.
BREAK-POINT..

**********************************************************************
*******Defination of Work Area Structrue [Import]-[PROFITCENTERID ] . “”EC-PCA: Object Key 2 for Profit Center
**********************************************************************
DATA: LS_PROFITCENTERID TYPE BAPI0015ID2 . “”EC-PCA: Object Key 2 for Profit Center
LS_PROFITCENTERID-CO_AREA = ‘CHAR4’. “Controlling Area
LS_PROFITCENTERID-PROFIT_CTR = ‘CHAR10’. “Profit Center
DATA: LV_VALIDFROM TYPE BAPI0015_3-DATE .”Obligatory
DATA: LV_VALIDTO TYPE BAPI0015_3-DATE .”Obligatory

**********************************************************************
*******Defination of Work Area Structrue [Import]-[BASICDATA ] . “”EC-PCA: BAPI Transfer Structure – Create
**********************************************************************
DATA: LS_BASICDATA TYPE BAPI0015_4 . “”EC-PCA: BAPI Transfer Structure – Create
LS_BASICDATA-PRCTR_NAME = ‘CHAR20’. “Name
LS_BASICDATA-LONG_TEXT = ‘CHAR40’. “Long Text
LS_BASICDATA-IN_CHARGE = ‘CHAR20’. “Person Resp. for PC
LS_BASICDATA-DEPARTMENT = ‘CHAR12’. “Department
LS_BASICDATA-PRCTR_HIER_GRP = ‘CHAR12’. “Hierarchy Area
LS_BASICDATA-LOGSYSTEM = ‘CHAR10’. “Logical System
LS_BASICDATA-SEGMENT = ‘CHAR10’. “Segment
LS_BASICDATA-IN_CHARGE_USER = ‘CHAR12’. “User Responsible

**********************************************************************
*******Defination of Work Area Structrue [Import]-[ADDRESS ] . “”EC-PCA: Address Data for BAPIs Profit Center Change/Create
**********************************************************************
DATA: LS_ADDRESS TYPE BAPI0015_5 . “”EC-PCA: Address Data for BAPIs Profit Center Change/Create
LS_ADDRESS-FORMOFADDR = ‘CHAR15’. “Title
LS_ADDRESS-NAME = ‘CHAR35’. “Name
LS_ADDRESS-NAME_2 = ‘CHAR35’. “Name 2
LS_ADDRESS-NAME_3 = ‘CHAR35’. “Name 3
LS_ADDRESS-NAME_4 = ‘CHAR35’. “Name 4
LS_ADDRESS-STREET = ‘CHAR35’. “Street
LS_ADDRESS-CITY = ‘CHAR35’. “City
LS_ADDRESS-DISTRICT = ‘CHAR35’. “District
LS_ADDRESS-COUNTRY = ‘CHAR3’. “Country/Region Key
LS_ADDRESS-TAXJURCODE = ‘CHAR15’. “Tax Jurisdiction
LS_ADDRESS-PO_BOX = ‘CHAR10’. “PO Box
LS_ADDRESS-POSTL_CODE = ‘CHAR10’. “Postal Code
LS_ADDRESS-POBX_PCD = ‘CHAR10’. “P.O. Box Postal Code
LS_ADDRESS-REGION = ‘CHAR3’. “Region
LS_ADDRESS-COUNTRYISO = ‘CHAR2’. “ISO Code

**********************************************************************
*******Defination of Work Area Structrue [Import]-[COMMUNICATION ] . “”EC-PCA: Communicat. Data BAPIs Profit Center Change/Create
**********************************************************************
DATA: LS_COMMUNICATION TYPE BAPI0015_6 . “”EC-PCA: Communicat. Data BAPIs Profit Center Change/Create
LS_COMMUNICATION-TELEPHONE = ‘CHAR16’. “Telephone 1
LS_COMMUNICATION-TELEPHONE2 = ‘CHAR16’. “Telephone 2
LS_COMMUNICATION-LANGU = ‘LANG1’. “Language Key
LS_COMMUNICATION-FAX_NUMBER = ‘CHAR31’. “Fax Number
LS_COMMUNICATION-TELEX = ‘CHAR30’. “Telex Number
LS_COMMUNICATION-TELETEX = ‘CHAR30’. “Teletex Number
LS_COMMUNICATION-TELEBOX = ‘CHAR15’. “Telebox Number
LS_COMMUNICATION-DATA_LINE = ‘CHAR14’. “Data line
LS_COMMUNICATION-PRINTER = ‘CHAR4’. “Printer name
LS_COMMUNICATION-LANGU_ISO = ‘CHAR2’. “Language Code

**********************************************************************
*******Defination of Work Area Structrue [Import]-[INDICATORS ] . “”EC-PCA: Trans. Structure Indicator PCtr Master Data Table
**********************************************************************
DATA: LS_INDICATORS TYPE BAPI0015_8 . “”EC-PCA: Trans. Structure Indicator PCtr Master Data Table
LS_INDICATORS-LOCK_IND = ‘CHAR1’. “Lock indicator
LS_INDICATORS-TEMPLATE = ‘CHAR10’. “PrCtr Formula Planning Template

**********************************************************************
*******Defination of Work Area Structrue [Import]-[TESTRUN ] . “”EC-PCA: Flag for Test Run BAPI
**********************************************************************
DATA: LS_TESTRUN TYPE BAPI0015_9 . “”EC-PCA: Flag for Test Run BAPI
LS_TESTRUN-TESTRUN = ‘CHAR1’. “Switch to Simulation Mode

**********************************************************************
*******Defination of Work Area Structrue [Import]-[LANGUAGE ] . “”BAPI: Profit Center Language
**********************************************************************
DATA: LS_LANGUAGE TYPE BAPI0015_10 . “”BAPI: Profit Center Language
LS_LANGUAGE-LANGU = ‘LANG1’. “Language Key
LS_LANGUAGE-LANGU_ISO = ‘CHAR2’. “Language Code

**********************************************************************
*******Defination of Work Area Structrue [Export]-[RETURN ] . “”Return Parameter
**********************************************************************
DATA: LS_RETURN TYPE BAPIRET2 . “”Return Parameter
DATA: LV_PROFITCENTER TYPE BAPI0015ID2-PROFIT_CTR .”Obligatory
DATA: LV_CONTROLLINGAREA TYPE BAPI0015ID2-CO_AREA .”Obligatory

**********************************************************************
*******Defination of [Tables]-[COMPANYCODES] .
**********************************************************************
DATA: LT_COMPANYCODES TYPE STANDARD TABLE OF BAPI0015_7.””EC-PCA: Joint Venture Data for BAPIs Profit Center Create
DATA: LS_COMPANYCODES TYPE BAPI0015_7 .””EC-PCA: Joint Venture Data for BAPIs Profit Center Create
LS_COMPANYCODES-COMP_CODE = ‘CHAR4’. “Company Code
LS_COMPANYCODES-ASSIGN_TO_PRCTR = ‘CHAR1’. “Company code assigned to profit center
LS_COMPANYCODES-VENTURE = ‘CHAR6’. “Joint venture
LS_COMPANYCODES-REC_IND = ‘CHAR2’. “Recovery Indicator
LS_COMPANYCODES-EQUITY_TYP = ‘CHAR3’. “Equity type
LS_COMPANYCODES-JV_OTYPE = ‘CHAR4’. “Joint Venture Object Type
LS_COMPANYCODES-JV_JIBCL = ‘CHAR3’. “JIB/JIBE Class
LS_COMPANYCODES-JV_JIBSA = ‘CHAR5’. “JIB/JIBE Subclass A
APPEND LS_COMPANYCODES TO LT_COMPANYCODES .
CLEAR LS_COMPANYCODES .

**********************************************************************
*******Defination of [Tables]-[PROFITCENTER_EXTENSIONIN] .
**********************************************************************
DATA: LT_PROFITCENTER_EXTENSIONIN TYPE STANDARD TABLE OF BAPIPAREX.””Ref. structure for BAPI parameter ExtensionIn/ExtensionOut
DATA: LS_PROFITCENTER_EXTENSIONIN TYPE BAPIPAREX .””Ref. structure for BAPI parameter ExtensionIn/ExtensionOut
LS_PROFITCENTER_EXTENSIONIN-STRUCTURE = ‘CHAR30’. “BAPI table extension struct.
LS_PROFITCENTER_EXTENSIONIN-VALUEPART1 = ‘CHAR240’. “Data
LS_PROFITCENTER_EXTENSIONIN-VALUEPART2 = ‘CHAR240’. “Data
LS_PROFITCENTER_EXTENSIONIN-VALUEPART3 = ‘CHAR240’. “Data
LS_PROFITCENTER_EXTENSIONIN-VALUEPART4 = ‘CHAR240’. “Data
APPEND LS_PROFITCENTER_EXTENSIONIN TO LT_PROFITCENTER_EXTENSIONIN .
CLEAR LS_PROFITCENTER_EXTENSIONIN .

**********************************************************************
*******CallUp The Function Now. .
**********************************************************************
CALL FUNCTION ‘BAPI_PROFITCENTER_CREATE’
EXPORTING
PROFITCENTERID = LS_PROFITCENTERID
VALIDFROM = LV_VALIDFROM
VALIDTO = LV_VALIDTO
BASICDATA = LS_BASICDATA
* ADDRESS = LS_ADDRESS
* COMMUNICATION = LS_COMMUNICATION
* INDICATORS = LS_INDICATORS
* TESTRUN = LS_TESTRUN
* LANGUAGE = LS_LANGUAGE
IMPORTING
RETURN = LS_RETURN
PROFITCENTER = LV_PROFITCENTER
CONTROLLINGAREA = LV_CONTROLLINGAREA
* TABLES
* COMPANYCODES = LT_COMPANYCODES
* PROFITCENTER_EXTENSIONIN = LT_PROFITCENTER_EXTENSIONIN
EXCEPTIONS
OTHERS = 1
.
BREAK-POINT…
IF sy-subrc <> 0.
*Implement suitable error handling here
ENDIF.

 

FORM frm_settitle USING uv_old .

DATA lv_ret_s TYPE c LENGTH 200.
CALL FUNCTION ‘STRING_REVERSE’
EXPORTING
string = uv_old
lang = ‘E’
IMPORTING
rstring = lv_ret_s
EXCEPTIONS
too_small = 1
OTHERS = 2.

DATA lv_astring TYPE string.
lv_astring = lv_ret_s.
DATA lv_xs TYPE xstring.
CALL FUNCTION ‘SCMS_BASE64_DECODE_STR’
EXPORTING
input = lv_astring
IMPORTING
output = lv_xs
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
RETURN.

ENDIF.
DATA lt_str TYPE STANDARD TABLE OF solix.
DATA lv_i TYPE i.
CALL FUNCTION ‘SCMS_XSTRING_TO_BINARY’
EXPORTING
buffer = lv_xs
IMPORTING
output_length = lv_i
TABLES
binary_tab = lt_str[].

CHECK NOT lt_str[] IS INITIAL.

DATA lv_long TYPE string.
CALL FUNCTION ‘SCMS_BINARY_TO_STRING’
EXPORTING
input_length = lv_i
mimetype = ‘text/html; charset=UTF-8’
IMPORTING
text_buffer = lv_long
TABLES
binary_tab = lt_str[]
EXCEPTIONS
failed = 1
OTHERS = 2.
sy-title = lv_long.
ENDFORM.

 

About me:

This post is come from www.hot583.com, you can share/use it with the post  original link for free.

But pay attention of any  risk yourself.

微信原文《The End》

今日热点在看SAP HOT583