*&---------------------------------------------------------------------*
*& Report ZSERVICE_NOTIFI_UPLOAD
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZSERVICE_NOTIFI_UPLOAD.
TABLES:SSCRFIELDS.
TYPE-POOLS: SLIS.
TYPES: BEGIN OF TY_DATA,
FIELD1(25),
FIELD2(25),
FIELD3(25),
FIELD4(25),
FIELD5(25),
FIELD6(25),
FIELD7(25),
FIELD8(25),
FIELD9(25),
FIELD10(25),
FIELD11(25),
FIELD12(25),
FIELD13(25),
FIELD14(25),
FIELD15(25),
END OF TY_DATA.
TYPES : BEGIN OF TY_SNOT,
PARTNER TYPE I_PARNR,
MATERIAL TYPE MATNR,
SERIALNO TYPE GERNR,
ZMDATE TYPE SYDATUM,"Commission date
ZCOM_TIM TYPE SYUZEIT,"Commission Time
ZCTYP TYPE ZSECTYP,"Under Warranty
SHORT_TEXT TYPE QMTXT,"Problem reported
ZCOMPD TYPE SYDATUM,"Complaint Date
ZCOMPT TYPE SYUZEIT,"Complaint Time
STRMLFNDATE TYPE AUSVN,
STRMLFNTIME TYPE AUZTV,
ENDMLFNDATE TYPE AUSBS,
ENDMLFNTIME TYPE AUZTB,
RTIME TYPE SYUZEIT,"Redressal time (dd:hh:mm)
REPORTEDBY TYPE QMNAM,"User name
OBS_TEXT TYPE CHAR2000,
CAUSE_CODE TYPE URCOD,"Cause Code
ZSTAT TYPE ZSESTAT,"Complaint Status
ZSERNU TYPE CHAR10,"Service Report Number
END OF TY_SNOT.
TYPES : BEGIN OF TY_OBSER,
LNO TYPE I,
TXT TYPE CHAR2000,
END OF TY_OBSER.
TYPES : BEGIN OF TY_ETAB,
LNO TYPE MSSLINENUM,
MTYPE TYPE BAPI_MTYPE,
NOTIF_NO TYPE QMNUM,
ID TYPE SYMSGID,
NUMBER TYPE SYMSGNO,
MESSAGE TYPE BAPI_MSG,
END OF TY_ETAB.
DATA : IT_TAB TYPE STANDARD TABLE OF ZALSMEX_TABLINE,
WA_TAB LIKE LINE OF IT_TAB,
IT_SNOT TYPE STANDARD TABLE OF TY_SNOT,
WA_SNOT LIKE LINE OF IT_SNOT,
IT_OBSER TYPE STANDARD TABLE OF TY_OBSER,
WA_OBSER LIKE LINE OF IT_OBSER,
IT_ETAB TYPE STANDARD TABLE OF TY_ETAB,
WA_ETAB LIKE LINE OF IT_ETAB.
SELECTION-SCREEN: BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
PARAMETER: P_FILE TYPE RLGRAP-FILENAME.
SELECTION-SCREEN END OF BLOCK B2.
SELECTION-SCREEN: FUNCTION KEY 1.
INITIALIZATION.
DATA:FUNCTXT TYPE SMP_DYNTXT.
CLEAR FUNCTXT.
FUNCTXT-TEXT = TEXT-001.
SSCRFIELDS-FUNCTXT_01 = FUNCTXT.
AT SELECTION-SCREEN.
CASE SSCRFIELDS-UCOMM.
WHEN 'FC01'.
PERFORM DOWNLOAD_EXCEL_FORMAT.
WHEN '' OR 'ONLI'.
PERFORM SSCR_VALIDATION.
WHEN OTHERS.
ENDCASE.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
PERFORM GET_F4_FILE.
START-OF-SELECTION.
PERFORM GET_EXCEL.
PERFORM GET_DATA.
PERFORM BUILT_DATA_AND_UPLOAD.
END-OF-SELECTION.
PERFORM SHOW_LOG.
*&---------------------------------------------------------------------*
*& Form DOWNLOAD_EXCEL_FORMAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DOWNLOAD_EXCEL_FORMAT .
DATA: LD_FILENAME TYPE STRING,
LD_PATH TYPE STRING,
LD_FULLPATH TYPE STRING,
LD_RESULT TYPE I,
LV_DEXT TYPE STRING , " 'XLS',
LV_FNAME TYPE STRING, " '
LV_FDIREC TYPE STRING. " 'c:\temp\'.
DATA : IT_DATA TYPE STANDARD TABLE OF TY_DATA,
WA_DATA LIKE LINE OF IT_DATA.
LV_DEXT = TEXT-026.
LV_FNAME = TEXT-027.
LV_FDIREC = TEXT-028.
IF IT_DATA[] IS INITIAL.
WA_DATA-FIELD1 = TEXT-030."
WA_DATA-FIELD2 = TEXT-031."
WA_DATA-FIELD3 = TEXT-032."
WA_DATA-FIELD4 = TEXT-033.
WA_DATA-FIELD5 = TEXT-034.
WA_DATA-FIELD6 = TEXT-035.
WA_DATA-FIELD7 = TEXT-036.
WA_DATA-FIELD8 = TEXT-037.
WA_DATA-FIELD9 = TEXT-038.
WA_DATA-FIELD10 = TEXT-039.
WA_DATA-FIELD11 = TEXT-040.
WA_DATA-FIELD12 = TEXT-041.
WA_DATA-FIELD13 = TEXT-042.
WA_DATA-FIELD14 = TEXT-043.
WA_DATA-FIELD15 = TEXT-044.
APPEND WA_DATA TO IT_DATA.
ENDIF.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
EXPORTING
DEFAULT_EXTENSION = LV_DEXT
DEFAULT_FILE_NAME = LV_FNAME
INITIAL_DIRECTORY = LV_FDIREC
CHANGING
FILENAME = LD_FILENAME
PATH = LD_PATH
FULLPATH = LD_FULLPATH
USER_ACTION = LD_RESULT
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
ENDIF.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = LD_FULLPATH
FILETYPE = 'ASC'
* APPEND = 'X'
WRITE_FIELD_SEPARATOR = 'X'
* CONFIRM_OVERWRITE = 'X'
TABLES
DATA_TAB = IT_DATA[]. "need to declare and populate
ENDFORM. " DOWNLOAD_EXCEL_FORMAT
*&---------------------------------------------------------------------*
*& Form SSCR_VALIDATION
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SSCR_VALIDATION .
IF P_FILE IS INITIAL.
MESSAGE 'Please Select File Path' TYPE 'E'.
ENDIF.
ENDFORM. " SSCR_VALIDATION
*&---------------------------------------------------------------------*
*& Form GET_F4_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_F4_FILE .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = 'P_FILE'
IMPORTING
FILE_NAME = P_FILE.
ENDFORM. " GET_F4_FILE
*&---------------------------------------------------------------------*
*& Form GET_EXCEL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_EXCEL .
REFRESH : IT_TAB[].
CALL FUNCTION 'ZALSM_EXCEL_TO_ITAB_LONG_TXT'
EXPORTING
FILENAME = P_FILE
I_BEGIN_COL = '1'
I_BEGIN_ROW = '2'
I_END_COL = '30'
I_END_ROW = '9999'
TABLES
INTERN = IT_TAB
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
ENDIF.
ENDFORM. " GET_EXCEL
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA .
DATA : LV_DATET TYPE CHAR25.
LOOP AT IT_TAB INTO WA_TAB.
CASE WA_TAB-COL.
WHEN '0001'.
WA_SNOT-PARTNER = WA_TAB-VALUE.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = WA_SNOT-PARTNER
IMPORTING
OUTPUT = WA_SNOT-PARTNER.
WHEN '0002'.
WA_SNOT-MATERIAL = WA_TAB-VALUE.
WHEN '0003'.
WA_SNOT-SERIALNO = WA_TAB-VALUE.
WHEN '0004'.
PERFORM SPLIT_DATE_TIME2 USING WA_TAB-VALUE CHANGING WA_SNOT-ZMDATE WA_SNOT-ZCOM_TIM.
WHEN '0005'.
WA_SNOT-ZCTYP = WA_TAB-VALUE.
WHEN '0006'.
WA_SNOT-SHORT_TEXT = WA_TAB-VALUE.
WHEN '0007'.
PERFORM SPLIT_DATE_TIME2 USING WA_TAB-VALUE CHANGING WA_SNOT-ZCOMPD WA_SNOT-ZCOMPT.
WHEN '0008'.
PERFORM SPLIT_DATE_TIME2 USING WA_TAB-VALUE CHANGING WA_SNOT-STRMLFNDATE WA_SNOT-STRMLFNTIME.
WHEN '0009'.
PERFORM SPLIT_DATE_TIME2 USING WA_TAB-VALUE CHANGING WA_SNOT-ENDMLFNDATE WA_SNOT-ENDMLFNTIME.
WHEN '0010'.
WA_SNOT-RTIME = WA_TAB-VALUE.
WHEN '0011'.
WA_SNOT-REPORTEDBY = WA_TAB-VALUE.
WHEN '0012'.
WA_SNOT-OBS_TEXT = WA_TAB-VALUE.
WHEN '0013'.
WA_SNOT-CAUSE_CODE = WA_TAB-VALUE.
WHEN '0014'.
WA_SNOT-ZSTAT = WA_TAB-VALUE.
WHEN '0015'.
WA_SNOT-ZSERNU = WA_TAB-VALUE.
WHEN OTHERS.
ENDCASE.
AT END OF ROW.
APPEND WA_SNOT TO IT_SNOT.
CLEAR WA_SNOT.
ENDAT.
ENDLOOP.
ENDFORM. " GET_DATA
*&---------------------------------------------------------------------*
*& Form SPLIT_DATE_TIME2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_WA_TAB_VALUE text
* <--P_WA_SNOT_ZMDATE text
* <--P_WA_SNOT_ZCOM_TIM text
*----------------------------------------------------------------------*
FORM SPLIT_DATE_TIME2 USING P_WA_TAB_VALUE
CHANGING P_DATE
P_TIME.
DATA : LV_DATE_TXT TYPE CHAR12,
LV_TIME_TXT TYPE CHAR12.
DATA : LV_HR(2) TYPE C,
LV_MIN(2) TYPE C.
SPLIT P_WA_TAB_VALUE AT '' INTO LV_DATE_TXT LV_TIME_TXT .
*Covert DATE
CALL FUNCTION 'KCD_EXCEL_DATE_CONVERT'
EXPORTING
EXCEL_DATE = LV_DATE_TXT
DATE_FORMAT = 'TMJ'
IMPORTING
SAP_DATE = P_DATE.
*Convert Time
SPLIT LV_TIME_TXT AT ':' INTO LV_HR LV_MIN.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = LV_HR
IMPORTING
OUTPUT = LV_HR.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = LV_MIN
IMPORTING
OUTPUT = LV_MIN.
CONCATENATE LV_HR LV_MIN '00' INTO P_TIME .
ENDFORM. " SPLIT_DATE_TIME2
*&---------------------------------------------------------------------*
*& Form BUILT_DATA_AND_UPLOAD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BUILT_DATA_AND_UPLOAD .
DATA : LS_NOTIFHEADER TYPE BAPI2080_NOTHDRI,
LT_NOTITEM TYPE STANDARD TABLE OF BAPI2080_NOTITEMI,
LS_NOTITEM LIKE LINE OF LT_NOTITEM ,
LT_NOTIFCAUS TYPE STANDARD TABLE OF BAPI2080_NOTCAUSI,
LS_NOTIFCAUS LIKE LINE OF LT_NOTIFCAUS,
LT_NOTIFPARTNR TYPE STANDARD TABLE OF BAPI2080_NOTPARTNRI,
LS_NOTIFPARTNR LIKE LINE OF LT_NOTIFPARTNR,
LT_RETURN TYPE STANDARD TABLE OF BAPIRET2,
LS_RETURN LIKE LINE OF LT_RETURN,
LS_NOTIFHEADER_EXPORT TYPE BAPI2080_NOTHDRE,
LS_NOTIFHEADER_FINAL TYPE BAPI2080_NOTHDRE,
LT_LONGTEXTS TYPE STANDARD TABLE OF BAPI2080_NOTFULLTXTI,
LS_LONGTEXTS LIKE LINE OF LT_LONGTEXTS.
DATA : LV_LNO TYPE I,
LV_POSTED TYPE C.
* LV_NOTI_NO TYPE BAPI2080_NOTHDRE-NOTIF_NO.
DATA : LS_HEADER TYPE THEAD,
LT_LINES TYPE STANDARD TABLE OF TLINE,
LS_LINES LIKE LINE OF LT_LINES,
LT_OUT_LINES TYPE STANDARD TABLE OF CHAR128,
LS_OUT_LINES LIKE LINE OF LT_OUT_LINES .
LOOP AT IT_SNOT INTO WA_SNOT.
LV_LNO = SY-TABIX.
LS_NOTIFHEADER-SERIALNO = WA_SNOT-SERIALNO.
LS_NOTIFHEADER-MATERIAL = WA_SNOT-MATERIAL.
LS_NOTIFHEADER-SHORT_TEXT = WA_SNOT-SHORT_TEXT.
LS_NOTIFHEADER-STRMLFNDATE = WA_SNOT-STRMLFNDATE.
LS_NOTIFHEADER-STRMLFNTIME = WA_SNOT-STRMLFNTIME.
LS_NOTIFHEADER-REPORTEDBY = WA_SNOT-REPORTEDBY.
LS_NOTIFHEADER-ENDMLFNDATE = WA_SNOT-ENDMLFNDATE.
LS_NOTIFHEADER-ENDMLFNTIME = WA_SNOT-ENDMLFNTIME.
LS_NOTIFHEADER-BREAKDOWN = 'X'.
LS_NOTITEM-ITEM_KEY = '0001'.
LS_NOTITEM-ITEM_SORT_NO = '0001'.
APPEND LS_NOTITEM TO LT_NOTITEM.
LS_NOTIFCAUS-CAUSE_KEY = '0001'.
LS_NOTIFCAUS-CAUSE_SORT_NO = '0001'.
LS_NOTIFCAUS-ITEM_KEY = '0001'.
LS_NOTIFCAUS-CAUSE_CODEGRP = 'CS'.
LS_NOTIFCAUS-CAUSE_CODE = WA_SNOT-CAUSE_CODE.
LS_NOTIFCAUS-ITEM_SORT_NO = '0001'.
IF LS_NOTIFCAUS-CAUSE_CODE = ''.
LS_NOTIFCAUS-CAUSE_CODE = '33'.
ENDIF.
APPEND LS_NOTIFCAUS TO LT_NOTIFCAUS.
LS_NOTIFPARTNR-PARTN_ROLE = 'AG'.
LS_NOTIFPARTNR-PARTNER = WA_SNOT-PARTNER.
APPEND LS_NOTIFPARTNR TO LT_NOTIFPARTNR.
LS_LONGTEXTS-OBJTYPE = 'QMEL'.
APPEND LS_LONGTEXTS TO LT_LONGTEXTS.
CALL FUNCTION 'BAPI_SERVNOT_CREATE'
EXPORTING
* EXTERNAL_NUMBER =
NOTIF_TYPE = 'K1'
NOTIFHEADER = LS_NOTIFHEADER* TASK_DETERMINATION = ' '
* SENDER =
* ORDERID =
IMPORTING
NOTIFHEADER_EXPORT = LS_NOTIFHEADER_EXPORT
TABLES
NOTITEM = LT_NOTITEM
NOTIFCAUS = LT_NOTIFCAUS* NOTIFACTV =
* NOTIFTASK =
NOTIFPARTNR = LT_NOTIFPARTNR
LONGTEXTS = LT_LONGTEXTS* KEY_RELATIONSHIPS =
RETURN = LT_RETURN
.
READ TABLE LT_RETURN WITH KEY TYPE = 'E' TRANSPORTING NO FIELDS.
IF SY-SUBRC <> 0.
REFRESH LT_RETURN.
LS_NOTIFHEADER_EXPORT-LONG_TEXT = 'X'.
CALL FUNCTION 'BAPI_SERVNOT_SAVE'
EXPORTING
NUMBER = LS_NOTIFHEADER_EXPORT-NOTIF_NO
IMPORTING
NOTIFHEADER = LS_NOTIFHEADER_FINAL
TABLES
RETURN = LT_RETURN.
READ TABLE LT_RETURN WITH KEY TYPE = 'E' TRANSPORTING NO FIELDS.
IF SY-SUBRC <> 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
* IMPORTING
* RETURN =
.
LV_POSTED = 'X'.
WA_ETAB-LNO = LV_LNO.
WA_ETAB-MTYPE = 'S'.
WA_ETAB-NOTIF_NO = LS_NOTIFHEADER_FINAL-NOTIF_NO.
WA_ETAB-MESSAGE = 'Documnet Updated Successfully..!'.
APPEND WA_ETAB TO IT_ETAB.
CLEAR WA_ETAB.
ELSE.
LOOP AT LT_RETURN INTO LS_RETURN WHERE TYPE = 'E'.
WA_ETAB-LNO = LV_LNO.
WA_ETAB-MTYPE = LS_RETURN-TYPE.
WA_ETAB-ID = LS_RETURN-ID.
WA_ETAB-MESSAGE = LS_RETURN-MESSAGE.
APPEND WA_ETAB TO IT_ETAB.
CLEAR WA_ETAB.
ENDLOOP.
ENDIF.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN =
.
LOOP AT LT_RETURN INTO LS_RETURN WHERE TYPE = 'E'.
WA_ETAB-LNO = LV_LNO.
WA_ETAB-MTYPE = LS_RETURN-TYPE.
WA_ETAB-ID = LS_RETURN-ID.
WA_ETAB-MESSAGE = LS_RETURN-MESSAGE.
APPEND WA_ETAB TO IT_ETAB.
CLEAR WA_ETAB.
ENDLOOP.
ENDIF.
IF LV_POSTED = 'X'.
WAIT UP TO 2 SECONDS.
*Update Custom Fields in QMEL Table
IF LS_NOTIFHEADER_EXPORT-NOTIF_NO IS NOT INITIAL.
UPDATE QMEL SET ZMDATE = WA_SNOT-ZMDATE
ZCTYP = WA_SNOT-ZCTYP
ZCOMPD = WA_SNOT-ZCOMPD
ZCOMPT = WA_SNOT-ZCOMPT
ZSTAT = WA_SNOT-ZSTAT
ZSERNU = WA_SNOT-ZSERNU
WHERE QMNUM = LS_NOTIFHEADER_FINAL-NOTIF_NO.
* Update Observation & Analysis Long Text
LS_HEADER-TDNAME = LS_NOTIFHEADER_FINAL-NOTIF_NO.
LS_HEADER-TDOBJECT = 'QMEL'.
LS_HEADER-TDID = 'LTXT'.
LS_HEADER-TDSPRAS = SY-LANGU.
* LS_HEADER-TDLINESIZE = 132.
CALL FUNCTION 'RKD_WORD_WRAP'
EXPORTING
TEXTLINE = WA_SNOT-OBS_TEXT* DELIMITER = ' '
OUTPUTLEN = '72'
* IMPORTING
* OUT_LINE1 =
* OUT_LINE2 =
* OUT_LINE3 =
TABLES
OUT_LINES = LT_OUT_LINES
EXCEPTIONS
OUTPUTLEN_TOO_LARGE = 1
OTHERS = 2
.
APPEND INITIAL LINE TO LT_LINES.
LOOP AT LT_OUT_LINES INTO LS_OUT_LINES.
LS_LINES-TDFORMAT = '*'.
LS_LINES-TDLINE = LS_OUT_LINES.
APPEND LS_LINES TO LT_LINES.
ENDLOOP.
CALL FUNCTION 'SAVE_TEXT'
EXPORTING
* CLIENT = SY-MANDT
HEADER = LS_HEADER* INSERT = 'X'
SAVEMODE_DIRECT = 'X'
* OWNER_SPECIFIED = 'X'
* LOCAL_CAT = ' '
* IMPORTING
* FUNCTION =
* NEWHEADER =
TABLES
LINES = LT_LINES
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
OBJECT = 4
OTHERS = 5
.
ENDIF.
ENDIF.
CLEAR : LS_NOTIFHEADER,LS_NOTITEM,LS_NOTIFCAUS,LS_NOTIFPARTNR,LV_POSTED,LS_HEADER,LV_LNO.
REFRESH : LT_NOTITEM,LT_NOTIFCAUS,LT_NOTIFPARTNR,LT_RETURN,LT_LINES,LT_OUT_LINES.
ENDLOOP.
ENDFORM. " BUILT_DATA_AND_UPLOAD
*&---------------------------------------------------------------------*
*& Form SHOW_LOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SHOW_LOG .
SORT IT_ETAB BY MTYPE ASCENDING.
CALL FUNCTION 'ZSTANDARD_ALV'
EXPORTING
* I_START_COLUMN = 25
* I_START_LINE = 6
* I_END_COLUMN = 100
* I_END_LINE = 10
I_TITLE = 'Log for Service Notification Upload'
I_POPUP = ''
TABLES
IT_ALV = IT_ETAB
.
ENDFORM. " SHOW_LOGSelection screen