This is an upload program to create Characteristics in SAP PM module. This program uploads the data file in excel format from the presentation server. BDC session is created for uploading the data. Session log can be checked using tcode SM35. Entire program is given as below.
*Selection Screen
*Output
*Structure Declaration
report ZPMCIPR0001
no standard page heading line-size 255.
TYPE-POOLS: TRUXS.
************************************************************************
* Struture Declaration *
************************************************************************
TYPES: BEGIN OF TY_DATA,
atnam TYPE RCTAV-ATNAM, "Characteristics Name
DATUV TYPE RCTAV-DATUV, "Valid from date
ATBEZ TYPE CABNT-ATBEZ, "Description
ATMST TYPE CABN-ATMST, "Status
FORMAT TYPE CABN-ATFOR, "Data type
ANZST TYPE CABN-ANZST, "No of characters
ANZDZ TYPE CABN-ANZDZ, "Decimal Places
EINHE TYPE RCTMV-EINHE, "Unit of Measurement
single TYPE c, "Single Value/Multiple Value
intervals TYPE c, "Interwals allowed
negative TYPE c, "Negative value allowed
Entry TYPE c, "Entry Required
END OF TY_DATA.
************************************************************************
* Intrnal Table Declaration *
************************************************************************
DATA: IT_DATA TYPE STANDARD TABLE OF TY_DATA,
IT_DATAh TYPE STANDARD TABLE OF TY_DATA,
BDCDATA TYPE STANDARD TABLE OF BDCDATA WITH HEADER LINE,
IT_RAW TYPE TRUXS_T_TEXT_DATA,
CTUMODE LIKE CTU_PARAMS-DISMODE,
WA_DATA TYPE TY_DATA,
WA_DATAh TYPE TY_DATA,
L_ASCII_LIST(200) TYPE C OCCURS 0 WITH HEADER LINE,
L_ABAP_LIST TYPE ABAPLIST OCCURS 0 WITH HEADER LINE.
************************************************************************
* Constants Declaration *
************************************************************************
CONSTANTS: C_BDCNAME LIKE APQI-GROUPID VALUE 'CT01_UPLOAD',
C_TCODE LIKE TSTC-TCODE VALUE 'CT01'.
************************************************************************
* Selection Screen *
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
PARAMETERS : P_FILE LIKE RLGRAP-FILENAME OBLIGATORY .
SELECTION-SCREEN END OF BLOCK B1.
************************************************************************
* At Selection Screen *
************************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = P_FILE.
************************************************************************
* Start of Selection *
************************************************************************
start-of-selection.
*Read the data from the file to internl table.
PERFORM READ_DATA.
*Create Class
PERFORM CREATE_charac.
*&---------------------------------------------------------------------*
*& Form READ_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM READ_DATA .
DATA: l_date(8) TYPE c,
l_tabix LIKE sy-tabix.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
I_LINE_HEADER = 'X'
I_TAB_RAW_DATA = IT_RAW
I_FILENAME = P_FILE
TABLES
I_TAB_CONVERTED_DATA = IT_DATA[]
* EXCEPTIONS
* CONVERSION_FAILED = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
RAISE UPLOAD_PROBLEM.
ENDIF.
*Begin of insert 25.03.2011
*Convert date format from YYYYMMDD to MMDDYYYY
IF it_data IS NOT INITIAL.
LOOP AT it_data INTO wa_data.
l_tabix = sy-tabix.
l_date+0(2) = wa_data-DATUV+6(2).
l_date+2(2) = wa_data-DATUV+4(2).
l_date+4(4) = wa_data-DATUV+0(4).
wa_data-DATUV = l_date.
MODIFY it_data FROM wa_data INDEX l_tabix TRANSPORTING DATUV.
CLEAR: l_tabix,l_date,wa_data.
ENDLOOP.
ENDIF.
*End of insert 25.03.2011
ENDFORM. " READ_DATA
*include bdcrecx1.
*start-of-selection.
*&---------------------------------------------------------------------*
*& Form CREATE_CHARAC
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CREATE_CHARAC .
*perform open_group.
*Create Session
PERFORM OPEN_SESSION USING C_BDCNAME.
LOOP AT it_data INTO wa_data.
perform bdc_dynpro using 'SAPMCTAV' '0100'.
perform bdc_field using 'BDC_CURSOR'
'RCTAV-DATUV'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'CABN-ATNAM'
WA_DATA-ATNAM.
perform bdc_field using 'RCTAV-DATUV'
WA_DATA-DATUV. "'24082010'.
perform bdc_field using 'RCTAV-ATRDA'
WA_DATA-DATUV."SY-DATUM. "'16.09.2010'.
perform bdc_dynpro using 'SAPLCTMV' '0110'.
perform bdc_field using 'BDC_OKCODE'
'=FORMAT'.
perform bdc_field using 'CABNT-ATBEZ'
WA_DATA-ATBEZ. "'test ct01'.
perform bdc_field using 'CABN-ATMST'
WA_DATA-ATMST. "'1'.
perform bdc_field using 'BDC_CURSOR'
'RCTMV-FORMAT'.
perform bdc_field using 'RCTMV-FORMAT'
WA_DATA-FORMAT. "'CHAR'.
perform bdc_field using 'RCTMV-ATEIN'
'X'.
IF wa_data-format = 'CHAR'.
perform bdc_dynpro using 'SAPLCTMV' '0155'.
perform bdc_field using 'BDC_CURSOR'
'RCTMV-ATCST'.
perform bdc_field using 'BDC_OKCODE'
'=RETU'.
perform bdc_field using 'RCTMV-ATCST'
WA_DATA-ANZST. "'7'.
perform bdc_field using 'RCTMV-ATEIN'
'X'.
perform bdc_dynpro using 'SAPLCTMV' '0110'.
perform bdc_field using 'BDC_OKCODE'
'=SICH'.
perform bdc_field using 'CABNT-ATBEZ'
WA_DATA-ATBEZ."'test ct01'.
perform bdc_field using 'CABN-ATMST'
'1'.
perform bdc_field using 'BDC_CURSOR'
'CABN-ANZST'.
perform bdc_field using 'RCTMV-FORMAT'
'CHAR'.
IF WA_DATA-SINGLE = 'Y'.
perform bdc_field using 'RCTMV-ATEIN' "Single Value
'X'.
ELSEIF WA_DATA-SINGLE = 'N'.
perform bdc_field using 'RCTMV-ATLIS' "Multiple Value
'X'.
ENDIF.
IF WA_DATA-entry = 'Y'.
perform bdc_field using 'RCTMV-ATERF' "Entry required
'X'.
ENDIF.
* perform bdc_field using 'CABN-ANZST'
* perform bdc_field using 'RCTMV-ATCST'
* wa_data-anzst. "'7'.
ELSEIF wa_data-format = 'CURR'.
perform bdc_dynpro using 'SAPLCTMV' '0152'.
perform bdc_field using 'BDC_CURSOR'
'RCTMV-WAERS'.
perform bdc_field using 'BDC_OKCODE'
'=RETU'.
perform bdc_field using 'RCTMV-ATAST'
WA_DATA-ANZST. "'7'.
perform bdc_field using 'RCTMV-WAERS'
'INR'.
IF wa_data-single = 'Y'.
perform bdc_field using 'RCTMV-ATEIN' "Single Value
'X'.
ELSEIF wa_data-single = 'N'.
perform bdc_field using 'RCTMV-ATLIS' "Multiple Value
'X'.
ENDIF.
* perform bdc_field using 'RCTMV-ATEIN'
* 'X'.
perform bdc_dynpro using 'SAPLCTMV' '0110'.
perform bdc_field using 'BDC_OKCODE'
'=SICH'.
perform bdc_field using 'CABNT-ATBEZ'
wa_data-atbez. "'test ct01'.
perform bdc_field using 'CABN-ATMST'
'1'.
perform bdc_field using 'BDC_CURSOR'
'CABN-ANZST'.
perform bdc_field using 'RCTMV-FORMAT'
'CURR'.
IF wa_data-single = 'Y'.
perform bdc_field using 'RCTMV-ATEIN' "Single Value
'X'.
ELSEIF wa_data-single = 'N'.
perform bdc_field using 'RCTMV-ATLIS' "Multiple Value
'X'.
ENDIF.
perform bdc_field using 'CABN-ANZST'
wa_data-anzst. "'7'.
perform bdc_field using 'RCTMV-WAERS'
'INR'.
perform bdc_field using 'CABN-ATSCH'
'_,___,___'.
ELSEIF WA_DATA-format = 'DATE'.
perform bdc_dynpro using 'SAPLCTMV' '0110'.
perform bdc_field using 'BDC_CURSOR'
'CABNT-ATBEZ'.
perform bdc_field using 'BDC_OKCODE'
'=SICH'.
perform bdc_field using 'CABNT-ATBEZ'
wa_data-atbez."'test ct01'.
perform bdc_field using 'CABN-ATMST'
'1'. "Always '1'.
perform bdc_field using 'RCTMV-FORMAT'
'DATE'.
IF wa_data-single = 'Y'.
perform bdc_field using 'RCTMV-ATEIN' "Single Value
'X'.
ELSEIF wa_data-single = 'N'.
perform bdc_field using 'RCTMV-ATLIS' "Multiple Value
'X'.
ENDIF.
IF WA_DATA-entry = 'Y'.
perform bdc_field using 'RCTMV-ATERF' "Entry required
'X'.
ENDIF.
IF WA_DATA-intervals = 'Y'.
perform bdc_field using 'RCTMV-ATINT' "intervals allowed
'X'.
ENDIF.
ELSEIF WA_DATA-format = 'NUM'.
perform bdc_dynpro using 'SAPLCTMV' '0150'.
perform bdc_field using 'BDC_CURSOR'
'RCTMV-ATLIS'.
perform bdc_field using 'BDC_OKCODE'
'=RETU'.
perform bdc_field using 'RCTMV-ATAST'
wa_data-anzst. "'7'.
perform bdc_field using 'RCTMV-ATADZ'
wa_data-anzdz. "'2'.
perform bdc_field using 'RCTMV-EINH2'
wa_data-einhe. "'kPa'.
IF wa_data-negative = 'Y'.
perform bdc_field using 'RCTMV-ATVOR' "Negative value allowed
'X'.
ELSEIF wa_data-negative = 'N'.
perform bdc_field using 'RCTMV-ATVOR'
''.
ENDIF.
IF wa_data-single = 'Y'.
perform bdc_field using 'RCTMV-ATEIN' "Single Value
'X'.
ELSEIF wa_data-single = 'N'.
perform bdc_field using 'RCTMV-ATLIS' "
'X'.
ENDIF.
perform bdc_dynpro using 'SAPLCTMV' '0110'.
perform bdc_field using 'BDC_CURSOR'
'RCTMV-ATINT'.
perform bdc_field using 'BDC_OKCODE'
'=SICH'.
perform bdc_field using 'CABNT-ATBEZ'
wa_data-atbez. "'test ct01'.
perform bdc_field using 'CABN-ATMST'
'1'. "Status always '1'.
IF wa_data-entry = 'Y'.
perform bdc_field using 'RCTMV-ATERF' "Entry restricted
'X'.
ELSEIF wa_data-entry = 'N'.
perform bdc_field using 'RCTMV-ATERF'
''.
ENDIF.
IF wa_data-intervals = 'Y'.
perform bdc_field using 'RCTMV-ATINT' "Intervals allowed
'X'.
ELSEIF wa_data-intervals = 'N'.
perform bdc_field using 'RCTMV-ATINT'
''.
ENDIF.
perform bdc_field using 'RCTMV-FORMAT'
'NUM'.
IF wa_data-single = 'Y'.
perform bdc_field using 'RCTMV-ATEIN' "Single Value
'X'.
ELSEIF wa_data-single = 'N'.
perform bdc_field using 'RCTMV-ATLIS' "Multiple value
'X'.
ENDIF.
perform bdc_field using 'CABN-ANZST'
wa_data-anzst. "'7'.
perform bdc_field using 'CABN-ANZDZ'
wa_data-anzdz. "'2'.
IF wa_data-intervals = 'Y'.
perform bdc_field using 'RCTMV-ATINT' "Intervals allowed
'X'.
ELSEIF wa_data-intervals = 'N'.
perform bdc_field using 'RCTMV-ATINT'
''.
ENDIF.
perform bdc_field using 'RCTMV-EINHE'
wa_data-einhe."'kPa'.
IF wa_data-negative = 'Y'.
perform bdc_field using 'CABN-ATVOR' "Negative value allowed
'X'.
ELSEIF wa_data-negative = 'N'.
perform bdc_field using 'CABN-ATVOR'
''.
ENDIF.
perform bdc_field using 'CABN-ATSCH'
'-__,___.__'.
ELSEIF WA_DATA-format = 'TIME'.
perform bdc_dynpro using 'SAPLCTMV' '0110'.
perform bdc_field using 'BDC_CURSOR'
'RCTMV-ATINT'.
perform bdc_field using 'BDC_OKCODE'
'=SICH'.
perform bdc_field using 'CABNT-ATBEZ'
WA_DATA-ATBEZ."'test ct01'.
perform bdc_field using 'CABN-ATMST'
'1'. "Status always '1'.
IF wa_data-entry = 'Y'.
perform bdc_field using 'RCTMV-ATERF' "Entry required.
'X'.
ELSEIF wa_data-entry = 'N'.
perform bdc_field using 'RCTMV-ATERF'
''.
ENDIF.
IF wa_data-intervals = 'Y'.
perform bdc_field using 'RCTMV-ATINT' "Intervals allowed
'X'.
ELSEIF wa_data-intervals = 'N'.
perform bdc_field using 'RCTMV-ATINT'
''.
ENDIF.
perform bdc_field using 'RCTMV-FORMAT'
'TIME'.
IF wa_data-single = 'Y'.
perform bdc_field using 'RCTMV-ATEIN' "Single Value
'X'.
ELSEIF wa_data-single ='N'.
perform bdc_field using 'RCTMV-ATLIS' "Multiple Value
'X'.
ENDIF.
IF wa_data-intervals = 'Y' .
perform bdc_field using 'RCTMV-ATINT' "Intervals allowed
'X'.
ELSEIF wa_data-intervals = 'N'.
perform bdc_field using 'RCTMV-ATINT'
''.
ENDIF.
perform bdc_field using 'CABN-ATGLA' "Restrictable
''.
IF wa_data-entry = 'Y'.
perform bdc_field using 'RCTMV-ATERF' "Entry required
'X'.
ELSEIF wa_data-entry = 'N'.
perform bdc_field using 'RCTMV-ATERF'
''.
ENDIF.
ELSEIF WA_DATA-format = 'SSI'.
perform bdc_dynpro using 'SAPLCTMV' '0110'.
perform bdc_field using 'BDC_CURSOR'
'CABNT-ATBEZ'.
perform bdc_field using 'BDC_OKCODE'
'=SICH'.
perform bdc_field using 'CABNT-ATBEZ'
wa_data-atbez. "'test ct01'.
perform bdc_field using 'CABN-ATMST'
'1'. "Status always '1'.
perform bdc_field using 'RCTMV-FORMAT'
'SSI'.
ENDIF.
* CALL TRANSACTION 'CT01' USING BDCDATA MODE 'A'.
PERFORM BDC_INSERT TABLES BDCDATA
USING C_TCODE.
REFRESH: BDCDATA.
CLEAR : wa_data.
ENDLOOP.
* Close the session
PERFORM CLOSE_SESSION.
* Process the session
PERFORM BDC_SUBMIT.
* perform bdc_transaction using 'CT01'.
*
* perform close_group.
ENDFORM. " CREATE_CHARAC
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM. "bdc_dynpro
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
IF ( FNAM CS 'ATCST' or
FNAM CS 'ATAST' or
FNAM CS 'ATADZ' or
FNAM CS 'ANZST' or
FNAM CS 'ANZDZ').
BDCDATA-FVAL = FVAL.
CONDENSE BDCDATA-FVAL.
ELSE.
BDCDATA-FVAL = FVAL.
ENDIF.
APPEND BDCDATA.
ENDFORM. "bdc_field
*&---------------------------------------------------------------------*
*& Form open_session *
*&---------------------------------------------------------------------*
FORM OPEN_SESSION USING P_SESS.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
GROUP = P_SESS
KEEP = 'X'
USER = SY-UNAME
* importing
* qid =
EXCEPTIONS
CLIENT_INVALID = 1
DESTINATION_INVALID = 2
GROUP_INVALID = 3
GROUP_IS_LOCKED = 4
HOLDDATE_INVALID = 5
INTERNAL_ERROR = 6
QUEUE_ERROR = 7
RUNNING = 8
SYSTEM_LOCK_ERROR = 9
USER_INVALID = 10
OTHERS = 11.
ENDFORM. "open_session
*&---------------------------------------------------------------------*
*& Form bdc_insert *
*&---------------------------------------------------------------------*
FORM BDC_INSERT TABLES BDCDATA
STRUCTURE BDCDATA
USING V_TCODE.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = V_TCODE
TABLES
DYNPROTAB = BDCDATA
EXCEPTIONS
INTERNAL_ERROR = 1
NOT_OPEN = 2
QUEUE_ERROR = 3
TCODE_INVALID = 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS = 7.
ENDFORM. "bdc_insert
*&---------------------------------------------------------------------*
*& Form close_session
*&---------------------------------------------------------------------*
FORM CLOSE_SESSION .
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3.
ENDFORM. " close_session
*&---------------------------------------------------------------------*
*& Form bdc_submit
*&---------------------------------------------------------------------*
* Process the sessions created
*----------------------------------------------------------------------*
FORM BDC_SUBMIT .
SUBMIT RSBDCSUB AND RETURN EXPORTING LIST TO MEMORY
WITH MAPPE = C_BDCNAME
WITH Z_VERARB = 'X'
WITH FEHLER = ' '.
COMMIT WORK AND WAIT.
* Retrieve the output from memory and place into l_abap_list
CLEAR L_ABAP_LIST.
FREE L_ABAP_LIST.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
LISTOBJECT = L_ABAP_LIST
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC EQ 0.
CLEAR L_ASCII_LIST.
FREE L_ASCII_LIST.
CALL FUNCTION 'LIST_TO_ASCI'
EXPORTING
LIST_INDEX = -1
TABLES
LISTASCI = L_ASCII_LIST
LISTOBJECT = L_ABAP_LIST
EXCEPTIONS
EMPTY_LIST = 1
LIST_L_INDEXEX_INVALID = 2
OTHERS = 3.
IF SY-SUBRC NE 0.
* MESSAGE W368 WITH TEXT-006.
ELSE.
LOOP AT L_ASCII_LIST.
WRITE: / L_ASCII_LIST.
ENDLOOP.
SKIP.
WRITE: / TEXT-002 , '"',C_BDCNAME,'"', TEXT-003.
ENDIF.
ENDIF.
ENDFORM. " bdc_submit
*&---------------------------------------------------------------------*
*& Form write.
*&---------------------------------------------------------------------*
FORM WRITE.
LOOP AT L_ASCII_LIST.
WRITE: / L_ASCII_LIST.
ENDLOOP.
SKIP.
WRITE: / TEXT-004 , '"',C_BDCNAME,'"', TEXT-005.
ENDFORM. "WRITE
No comments:
Post a Comment