zai 00004
TRANSCRIPT
7/29/2019 Zai 00004
http://slidepdf.com/reader/full/zai-00004 1/18
************************************************************************* Program : ZAI00004 Creation Dt: 07/05/2004* Title : Company Vehicle Interface for Retirements* Transaction (Vehicle Auction)** Author : Beatriz Alvarez* Lead : Kay Ramsey** Type : AA inbound interface Script Id : IL051************************************************************************* Description : This interface is required for retirements (sales) from* CV. This program will transfer Lease and company* vehicles to be retired for the current month from CV* system to SAP AA system using "Call Session Method".* A BDC will be created as error log.************************************************************************* Input : File of data* Output: List/Mail of errors and statistics************************************************************************* Modification History:** YYYY/MM/DD Author* Correction# Description* ----------- --------------------------------------------------------
* 2004/07/05 Beatriz Alvarez* DV5K919163 Initial Version*************************************************************************report ZAI00004 no standard page heading
line-size 150message-id za.
*-----------------------------------------------------------------------*TABLES*-----------------------------------------------------------------------tables: anla.
*-----------------------------------------------------------------------
* INCLUDE PROGRAMS*-----------------------------------------------------------------------* Includes for standard report header & replaces fields with sy fieldsinclude zziheadr.*Include for standard header & trailer recordsinclude ZZIFILE1.INCLUDE zzifile3.INCLUDE <ICON>.
*Mail structuresdata: doc_chng LIKE sodocchgi1,
objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE.
*-----------------------------------------------------------------------*PARAMETERS*-----------------------------------------------------------------------selection-screen skip.
selection-screen begin of block blk1 with frame title text-001.
selection-screen begin of line.selection-screen comment 1(31) text-003.
7/29/2019 Zai 00004
http://slidepdf.com/reader/full/zai-00004 2/18
parameters: p_source as checkbox default 'X'.selection-screen end of line.selection-screen begin of line.selection-screen comment 1(31) text-004.parameters p_test as checkbox default 'X'.selection-screen end of line.parameters: p_file1 like rlgrap-filename obligatory
default '/nmcfs1/<sysid>/in/ccv1130.cvsales'.parameters: p_file2 like rlgrap-filename obligatory
default '/nmcfs1/<sysid>/in/ccv1130.cvsales_error.<datetime>'.PARAMETERS: P_FDATA LIKE RLGRAP-FILETYPE default 'DAT'.
selection-screen skip.parameters: p_group(12) obligatory DEFAULT SY-REPID,
p_user like sy-uname obligatory DEFAULT 'BDC_AA',p_keep as checkbox default 'X',p_hdate like sy-datum.
select-options s_erec for reclist-receiver DEFAULT'[email protected]'obligatory no intervals.
selection-screen end of block blk1.
selection-screen begin of block blk2 with frame title text-002.parameters: p_bukrs like anla-bukrs default '2177'.parameters: p_bldat like anla-ERDAT default sy-datum.parameters: p_budat like anla-ERDAT default sy-datum.selection-screen end of block blk2.
*-----------------------------------------------------------------------*INTERNAL TABLES*-----------------------------------------------------------------------data: begin of t_file occurs 0,
ccode(4), " Company Owner Group IDvin(17), " VIN Numbermodel(5), " Model number
invnr(6), " Serial numbererlbt(12), " Manual ValueDATE(8), " Asset Value Date
* NEXT FIELDS ARE NOT RELEVANT IN THIS PROGRAMASSET(12), " AssetPLANT(4), " plantCCENTER(18), " cost centerPROC_DATE(8), " process date
end of t_file.
data begin of t_error occurs 0.include structure t_file.
data msg(50).
data type.data end of t_error.
data: begin of i_msgs occurs 0. "for emailinclude structure soli.
data: end of i_msgs.* Detail in maildata begin of i_msg_det occurs 0.
include structure soli.data end of i_msg_det.
7/29/2019 Zai 00004
http://slidepdf.com/reader/full/zai-00004 3/18
* BDC structuredata: begin of bdcdata occurs 0.
include structure bdcdata. " BDC Data Structuredata: end of bdcdata.
data: begin of t_data occurs 0,anln1 like raifp2-anln1, " Asset IDbldat(10), " Document Datebudat(10), " Posting Datebzdat(10), " Asset Value Datexmaer like raifp2-xmaer, " Manual Value (Radiobutton)erlbt(13), " Manual valuexblnr like raifp1-xblnr, " Reference document numbervin(17), " VIN#
end of t_data.
* INPUT RECORDDATA: BEGIN OF in_rec,
recbody(460) TYPE c,END OF in_rec.
* Asset infodata: begin of t_anla,
anln1 like anla-anln1, "Asset #
anln2 like anla-anln2, "subasset #invnr like anla-invnr, "Inventory #DEAKT LIKE ANLA-DEAKT, "Deactivation date
end of t_anla.
*DATA DECLARATIONdata: count TYPE I,
msgs_lin type i,TOTAL_RECORDS(6) TYPE N,chk_continue,chk_message,d_date(10),count_good type i,
count_bad type i,count_deactiv type i,count_rej type i,bukrs LIKE ANLA-BUKRS,error_flag value space,header_id(4) type c value 'HDR ', "File Header Record Identifiertrailer_id(4) type c value 'TRLR'. "File Trailer Record Identifier
CONSTANTS: C_zero VALUE '0',c_x value 'X',C_S value 'S',C_D VALUE 'D',c_R VALUE 'R',
C_E VALUE 'E',C_N VALUE 'N',C_A VALUE 'A',c_raw(3) VALUE 'RAW',T_CODE(5) VALUE 'ABAON',c_init(8) VALUE '00000000',C_DOT VALUE '.',C_NUMBERS(11) VALUE '0123456789 '.
*-----------------------------------------------------------------------*INITIALIZATION.
7/29/2019 Zai 00004
http://slidepdf.com/reader/full/zai-00004 4/18
*-----------------------------------------------------------------------INITIALIZATION.refresh t_data.refresh t_error.refresh bdcdata.
*-----------------------------------------------------------------------*AT-SELECTION-SCREEN*-----------------------------------------------------------------------at selection-screen on value-request for p_file1.if p_source = space.perform open_file using p_file1.
endif.
at selection-screen on value-request for p_file2.if p_source = space.
perform open_file using p_file2.endif.
* COMP CODEat selection-screen on p_bukrs.select single bukrs into bukrs from t093c where bukrs = p_bukrs.if sy-subrc <> 0.
message e000 with 'Company Code'(005) p_bukrs 'not valid'(006).
endif.
* FILE TYPE INVISIBLE IF INPUT FILE FROM SERVER (HARD CODE)at selection-screen OUTPUT.LOOP AT SCREEN.
IF SCREEN-NAME = 'P_FDATA'.IF P_SOURCE = 'X'.
screen-INVISIBLE = '1'.SCREEN-ACTIVE = '0'.screen-OUTPUT = '0'.
ELSE.screen-INVISIBLE = '0'.SCREEN-ACTIVE = '1'.
screen-OUTPUT = '1'.ENDIF.MODIFY SCREEN.
ENDIF.IF SCREEN-NAME = '%_P_FDATA_%_APP_%-TEXT'.IF P_SOURCE = 'X'.
screen-INVISIBLE = '1'.SCREEN-ACTIVE = '0'.screen-OUTPUT = '0'.MODIFY SCREEN.
ENDIF.ENDIF.
ENDLOOP.
*-----------------------------------------------------------------------*START-OF-SELECTION.*-----------------------------------------------------------------------start-of-selection.* Performing function module Z_GET_VARIANT_CONTENTS.include ZZIGETVAR.
* LOCK PROGRAMperform lock_program.
7/29/2019 Zai 00004
http://slidepdf.com/reader/full/zai-00004 5/18
if p_source = space.perform get_file.
else.perform read_data.
endif.
if chk_continue = c_X.perform get_data.perform write_summary.perform set_mail. "pendingperform send_mail. "pending
endif.
*-----------------------------------------------------------------------*END-OF-SELECTION.*-----------------------------------------------------------------------end-of-selection.include zzifinproc.*************************BEGIN OF FORM ROUTINES*************************
************************************************************************
* PERFORM OPEN_FILE ************************************************************************** Display the window to choose the path where the PC file will be gotten************************************************************************form open_file using p_file.call function 'WS_FILENAME_GET'
exportingdef_filename = p_filedef_path = 'c:/temp'mask = ',*.*,*.*.'mode = 'O'title = 'File'(002)
importing
filename = p_file.* no sy-subrc checking is necessary here.endform.
************************************************************************* PERFORM GET_FILE ************************************************************************** Get file from PC************************************************************************form get_file.call function 'WS_UPLOAD'
exportingfilename = p_file1
filetype = P_FDATAtables
data_tab = t_fileexceptions
conversion_error = 1file_open_error = 2file_read_error = 3invalid_type = 4no_batch = 5unknown_error = 6
7/29/2019 Zai 00004
http://slidepdf.com/reader/full/zai-00004 6/18
invalid_table_width = 7gui_refuse_filetransfer = 8customer_error = 9others = 10.
case sy-subrc.when 0.perform write_success using 'File'(002)
p_file1(50)'Read Successfully'(007).
chk_continue = c_X.when others.perform write_failure using 'Error Reading the file'(008)
p_file1(50).chk_continue = space.
endcase.endform.
************************************************************************* PERFORM OPEN_GROUP ************************************************************************** Open BDC session for inserting data************************************************************************form open_group.
call function 'BDC_OPEN_GROUP'exportingclient = sy-mandtgroup = p_groupuser = p_userkeep = p_keepholddate = p_hdate
EXCEPTIONSCLIENT_INVALID = 1DESTINATION_INVALID = 2GROUP_INVALID = 3GROUP_IS_LOCKED = 4HOLDDATE_INVALID = 5
INTERNAL_ERROR = 6QUEUE_ERROR = 7RUNNING = 8SYSTEM_LOCK_ERROR = 9USER_INVALID = 10.
case sy-subrc.when 0.chk_continue = c_X.
when others.perform write_failure using 'Error! opening BDC Session'(009)
p_group.chk_continue = space.
endcase.endform.
************************************************************************* FORM GET_DATA ************************************************************************** This form wil be used to loop input file, check for correct informa-* tion. For correct items perform a call funciton (ABAON). The erroneus* ones will go to BDC. The VINs # not existing in SAP will be rejected.************************************************************************
7/29/2019 Zai 00004
http://slidepdf.com/reader/full/zai-00004 7/18
form get_data.loop at t_file.
count = count + 1.clear t_anla.
* Check that the VIN # exists already in the table to get the asset #translate t_file-vin to upper case.
* Select only one recordselect anln1 anln2 invnr DEAKT up to 1 rowsfrom anla into t_anla
where bukrs = p_bukrs andinvnr = t_file-vin.
endselect.case sy-subrc.when 0.
if t_anla-DEAKT <> c_init.perform store_error_record USING 'Asset'(013) t_anla-anln1
'Deactivated'(042) space C_D.continue.
endif.perform format_tdata.if p_test = c_x.perform store_error_record USING 'CORRECT'(010) '' '' '' C_S.count_good = count_good + 1.
else.
perform build_session.endif.when others.move t_file to t_error.perform store_error_record USING
'VIN does not exists in SAP'(011) '' '' '' C_R.endcase.
endloop.
if p_source = C_X and p_test = space.delete dataset: p_file1.
endif.
endform.
************************************************************************* FORM BUILD_SESSION ************************************************************************** Perform call transaction for correct items, if the call transaction* fails, change its status and send it to error log.************************************************************************form build_session.SET PARAMETER ID 'BUK' FIELD P_BUKRS.PERFORM FILL_BDC_STRUCTURE.call transaction t_code USING BDCDATA mode C_N UPDATE C_S.if sy-subrc = 0.
commit work.count_good = count_good + 1.perform store_error_record USING 'CORRECT'(010) '' '' '' C_S.
else.move t_file to t_error.perform store_error_record USING
'Call transaction failed-'(012) 'Asset'(013)t_anla-anln1 t_anla-anln2 C_E.
endif.refresh bdcdata.
7/29/2019 Zai 00004
http://slidepdf.com/reader/full/zai-00004 8/18
endform.
************************************************************************* PERFORM CLOSE_GROUP ************************************************************************** Close BDC session after inserting************************************************************************form close_group.call function 'BDC_CLOSE_GROUP'
EXCEPTIONSNOT_OPEN = 1QUEUE_ERROR = 2.
case sy-subrc.when 0.when others.perform write_failure using 'Error! closing Session:'(014)
p_group.endcase.
endform.
************************************************************************* PERFORM BDC_TRANSACTION *************************************************************************
* Insert record to BDC to perform transaction************************************************************************form bdc_transaction using VALUE(t_code).DATA TCODE LIKE TSTC-TCODE.TCODE = T_CODE.call function 'BDC_INSERT'
exportingtcode = tcode
tablesdynprotab = bdcdata.
* Since no exceptions are evaluated,sy-subrc does not need to be checkedendform.
************************************************************************* PERFORM BDC_DYNPRO *************************************************************************form bdc_dynpro using program dynpro.clear bdcdata.bdcdata-program = program.bdcdata-dynpro = dynpro.bdcdata-dynbegin = C_X.append bdcdata.
endform.
************************************************************************* PERFORM BDC_FIELD *
************************************************************************form bdc_field using fnam fval.clear bdcdata.bdcdata-fnam = fnam.bdcdata-fval = fval.append bdcdata.
endform.
************************************************************************* PERFORM WRITE_SUCCESS *
7/29/2019 Zai 00004
http://slidepdf.com/reader/full/zai-00004 9/18
************************************************************************form write_success using message1 message2 message3.SKIP.write:/ message1, message2, message3.skip.
endform.
************************************************************************* PERFORM WRITE_FAILURE *************************************************************************form write_failure using message1 message2.SKIP.write:/ message1, message2.skip.
endform.
************************************************************************* PERFORM WRITE_SUMMARY ************************************************************************** Control report and download error file.************************************************************************form write_summary.write:/ 'Total records uploaded from file: '(015),
count.skip.write:/ 'Total records Processed (Retirements): '(016),
count_good.skip.write:/ 'Total records in Error submitted to BDC: '(017),
count_bad.skip.write:/ 'Total records Rejected due to VIN not existing in SAP:'(018),
count_rej.skip.
if count_deactiv > 0.
write:/ 'Total records Rejected due to Deactivated asset: '(043),count_deactiv.skip.
endif.
if p_test = space.if count_bad > 0.ULINE AT 20(64).FORMAT color col_heading intensified off.write: /20 SY-VLINE,
'BDC'(019), p_group,'has been created. It contains error records'(020),SY-VLINE,
/ SPACE.FORMAT COLOR OFF INTENSIFIED ON.ULINE AT 20(64).
endif.elseif p_test = C_X.
ULINE AT 20(68).FORMAT color col_heading intensified off.write: /20 SY-VLINE,
'BDC'(019), p_group, 'and Assets'(021),'were NOT retired. This is a test run'(022),
7/29/2019 Zai 00004
http://slidepdf.com/reader/full/zai-00004 10/18
SY-VLINE,/ SPACE.
FORMAT COLOR OFF INTENSIFIED ON.ULINE AT 20(68).
endif.
format color off intensified on.
* DISPLAY REJECTED RECORDS AND SEND ERROR RECORDS TO ERROR BDCperform display_error_records.
* MESSAGES TO BE MAILEDif p_test = space.
IF COUNT_BAD > 0.concatenate 'BDC'(019) p_group
'has been created. It contains error records'(020)into i_msgs-line separated by SPACE.
append i_msgs.clear i_msgs.append i_msgs.
ENDIF.else.
concatenate 'BDC'(019) p_group 'and Assets'(021)'were NOT retired. This is a test run'(022)
into i_msgs-line separated by SPACE.append i_msgs.clear i_msgs.append i_msgs.
endif.
i_msgs-line = count.condense i_msgs-line.concatenate TEXT-015 i_msgs-line into i_msgs-line separated by space.append i_msgs.i_msgs-line = count_good.condense i_msgs-line.concatenate TEXT-016 i_msgs-line into i_msgs-line separated by space.
append i_msgs.i_msgs-line = count_bad.condense i_msgs-line.concatenate TEXT-017 i_msgs-line into i_msgs-line separated by space.append i_msgs.
i_msgs-line = count_rej.condense i_msgs-line.concatenate TEXT-018 i_msgs-line into i_msgs-line separated by space.append i_msgs.
if count_deactiv > 0.i_msgs-line = count_deactiv.condense i_msgs-line.
concatenate TEXT-043 i_msgs-line into i_msgs-line separated by space.append i_msgs.
endif.
if chk_message = C_A.write:/ sy-repid, 'has concluded with errors.'(023).skip.concatenate sy-repid 'has concluded with errors.'(023)
into i_msgs-line separated by space.append i_msgs.
7/29/2019 Zai 00004
http://slidepdf.com/reader/full/zai-00004 11/18
endif.* DOWONLOAD ERROR LOG TO A FILE (EITHER IN PC OR UNIX)if count_bad > 0.if p_source = space.
perform download_error.else.perform write_error_file.
endif.endif.
endform.
************************************************************************* PERFORM DOWNLOAD_ERROR ************************************************************************** Download file to PC************************************************************************form download_error .call function 'WS_DOWNLOAD'
exportingfilename = p_file2filetype = P_FDATA
tablesdata_tab = t_error
exceptions
file_open_error = 1file_write_error = 2invalid_filesize = 3invalid_type = 4no_batch = 5unknown_error = 6invalid_table_width = 7gui_refuse_filetransfer = 8customer_error = 9others = 10.
case sy-subrc.when 0.
perform write_success using 'Error file'(024)p_file2(60)'Written Successfully'(025).
when others.perform write_failure using 'Error Writing the Error file'(026)
p_file2.endcase.
endform.*&---------------------------------------------------------------------**& Form read_data*&---------------------------------------------------------------------** Form which reads the UNIX file into the internal table*----------------------------------------------------------------------*
form read_data.PERFORM add_sysid_to_file_name USING p_file1.PERFORM add_sysid_to_file_name USING p_file2.
call function 'Z_GET_FILES'exporting
file_prefix = p_file1importing
first_file = p_file1exceptions
7/29/2019 Zai 00004
http://slidepdf.com/reader/full/zai-00004 12/18
not_found = 1invalid_length = 2.
* Validation to SY-SUBRC is not necessary here, even if it returns a* value different to 0, the file name won't be changed.
concatenate 'Input file ->'(027) p_file1 into i_msgs-lineseparated by space.
append i_msgs.concatenate 'Error file ->'(028) p_file2 into i_msgs-line
separated by space.append i_msgs.
open dataset p_file1 for input in text mode.if sy-subrc ne 0.
write: / 'Cannot open inbound data file ->'(029), 35 p_file1.concatenate 'Cannot open inbound data file ->'(029) p_file1
into i_msgs-line separated by space.append i_msgs.perform set_mail.perform send_mail.stop.
endif.
do.read dataset p_file1 into IN_REC.if sy-subrc ne 0.exit.
endif.TOTAL_RECORDS = TOTAL_RECORDS + 1.
* check headerIF in_rec(3) = header_id.MOVE in_rec TO std_header.CONTINUE.
ENDIF.
* check trailerIF in_rec(4) = trailer_id.MOVE in_rec TO std_trailer.CONTINUE.
ENDIF.
MOVE in_rec TO t_file.append t_file.
enddo.
close dataset p_file1.IF std_trailer-num_recs NE TOTAL_RECORDS.
CONCATENATE 'File trailer record count'(030) std_trailer-num_recs'does not match total records'(031) TOTAL_RECORDSINTO i_msgs.
APPEND i_msgs.perform set_mail.perform send_mail.MESSAGE e000 WITH 'File trailer record count'(030)
std_trailer-num_recs'does not match total records'(031) TOTAL_RECORDS.
ENDIF.
7/29/2019 Zai 00004
http://slidepdf.com/reader/full/zai-00004 13/18
describe table t_file lines sy-tfill.if sy-tfill eq 0.
write: p_file1,055 'File is empty.'(032).
concatenate p_file1 'File is empty.'(032)into i_msgs-line separated by space.
append i_msgs.perform set_mail.perform send_mail.stop.
endif.
chk_continue = C_X.
endform. " read_data
*&---------------------------------------------------------------------**& Form write_error_file*&---------------------------------------------------------------------** Form which outputs a dump to a desktop file*----------------------------------------------------------------------*form write_error_file.* open outbound error file
open dataset p_file2 for output in text mode.if sy-subrc ne 0.write: / 'Cannot open outbound error file ->'(034),
35 p_file2.concatenate 'Cannot open outbound error file ->'(034) p_file2
into i_msgs-line separated by space.append i_msgs.perform set_mail.perform send_mail.stop.
endif.
loop at t_error.
transfer t_error to p_file2.endloop.
close dataset p_file2.endform. " write_error_file*&---------------------------------------------------------------------**& Form FILL_BDC_STRUCTURE*&---------------------------------------------------------------------** Fill BDC structure (BDCDATA) to be inserted to BCC*----------------------------------------------------------------------*FORM FILL_BDC_STRUCTURE.
perform bdc_dynpro using 'SAPLAMDP' '0100'.perform bdc_field using 'BDC_OKCODE'
'=TAB02'.perform bdc_field using 'BDC_SUBSCR''SAPLAMDP 0300OBJECT'.perform bdc_field using 'BDC_CURSOR'
'RAIFP2-ANLN1'.perform bdc_field using 'RAIFP2-ANLN1'
t_data-anln1.perform bdc_field using 'RAIFP2-ANLN2'
c_zero.perform bdc_field using 'RAIFP1-BLDAT'
7/29/2019 Zai 00004
http://slidepdf.com/reader/full/zai-00004 14/18
t_data-bldat.perform bdc_field using 'RAIFP1-BUDAT'
t_data-budat.perform bdc_field using 'RAIFP1-BZDAT'
t_data-bzdat.perform bdc_field using 'RAIFP2-SGTXT'
T_DATA-vin.perform bdc_field using 'RAIFP2-XMAER'
c_X.perform bdc_field using 'RAIFP2-ERLBT'
t_data-erlbt.
perform bdc_dynpro using 'SAPLAMDP' '0100'.perform bdc_field using 'BDC_OKCODE'
'=SAVE'.
perform bdc_field using 'RAIFP1-XBLNR't_data-xblnr.
perform bdc_field using 'RAIFP2-ZUONR't_data-vin.
ENDFORM. " FILL_BDC_STRUCTURE*&---------------------------------------------------------------------**& Form lock_program*&---------------------------------------------------------------------*
* Standard lock function*----------------------------------------------------------------------*FORM lock_program.call function 'Z_LOCK_PROGRAM'
exceptionsforeign_lock = 1system_failure = 2others = 3.
if sy-subrc <> 0.message e000 with 'Another copy of the program'(035) sy-repid
'is currently running'(036) space.chk_message = 'A'.
perform write_summary.
endif.ENDFORM. " lock_program*&---------------------------------------------------------------------**& Form store_error_record*&---------------------------------------------------------------------** Save record in error log*----------------------------------------------------------------------*FORM store_error_record USING VALUE(MSG) VALUE(MSG1)
VALUE(MSG2) value(msg3) value(type).T_ERROR = T_FILE.concatenate msg msg1 msg2 msg3 into T_ERROR-MSG separated by space.
t_error-type = type.if t_error-type = C_E.
count_bad = count_bad + 1.elseif t_error-type = C_R.
count_rej = count_rej + 1.elseif t_error-type = C_D.
count_deactiv = count_deactiv + 1.endif.append t_error.
7/29/2019 Zai 00004
http://slidepdf.com/reader/full/zai-00004 15/18
clear t_error.ENDFORM. " store_error_record*&---------------------------------------------------------------------**& Form display_error_records*&---------------------------------------------------------------------** Display detail of either what was correctly processed or not.* Build ERROR BDC*----------------------------------------------------------------------*FORM display_error_records.refresh i_msg_Det.skip.WRITE:/ TEXT-999.CLEAR chk_continue.IF P_TEST = SPACE.IF COUNT_BAD > 0.
* OPEN ERROR SESSIONREAD TABLE T_ERROR WITH KEY TYPE = C_E.IF SY-SUBRC = 0.perform open_group.ENDIF.
ENDIF.endif.
write:/ ICON_INCOMPLETE as icon, 'REJECTED RECORDS'(037),
ICON_CHECKED as icon, 'CORRECT RECORDS'(038),ICON_FAILURE as icon, 'RECS SENT TO BDC'(039).WRITE:/ TEXT-999.skip.error_flag = C_X.
* move header columns to filemove text-d01 to i_msg_Det.append i_msg_det.clear i_msg_det.loop at t_error.
IF T_ERROR-TYPE = C_R or "REJECTEDT_ERROR-TYPE = C_D.
write / ICON_INCOMPLETE as icon.
ELSEIF T_ERROR-TYPE = c_E. "ERROR sent to BDCWRITE / ICON_FAILURE as icon.if p_test = space.
* Format Dataperform format_tdata.
* Fill BDC structurePERFORM FILL_BDC_STRUCTURE.
* Insert record to BDCperform bdc_transaction using T_CODE.refresh bdcdata.
endif.ELSE.WRITE / ICON_CHECKED as icon.
ENDIF.* Display Records with message
write: t_error-vin, " VIN Numbert_error-erlbt, " Manual Valuet_error-DATE, " Asset Value Datet_error-model, " Model numbert_error-invnr, " Serial numbert_error-msg. " Message
clear t_error-type. "don't pass the error type to the filemove t_error to i_msg_det.
7/29/2019 Zai 00004
http://slidepdf.com/reader/full/zai-00004 16/18
append i_msg_det.clear i_msg_det.
endloop.FORMAT COLOR OFF.IF chk_continue = C_X.
perform close_group.ENDIF.
ENDFORM. " display_error_records*&---------------------------------------------------------------------**& Form format_tdata*&---------------------------------------------------------------------** Fill structure t_data with data from input file.*----------------------------------------------------------------------*FORM format_tdata.DATA: DATE LIKE SY-DATUM,
int(10),decimal(2).
* if record is flagged as error, take the Asset number, otherwise, look* for it with the VIN #.if error_flag = space.
t_data-anln1 = t_anla-anln1.else.
t_data-anln1 = t_error-msg+31(12).endif.* FORMAT DATA
if p_bldat = space.write sy-datum to d_date dd/mm/yyyy.t_data-bldat = d_date.
else.write p_bldat to d_date dd/mm/yyyy.t_data-bldat = d_date.
endif.if p_budat = space.write sy-datum to d_date dd/mm/yyyy.t_data-budat = d_date.
else.write p_budat to d_date dd/mm/yyyy.t_data-budat = d_date.
endif.
move T_FILE-DATE to date.WRITE date TO D_DATE DD/MM/YYYY.t_data-bzdat = d_date.
* AMOUNTIF t_file-erlbt CO C_NUMBERS.unpack t_file-erlbt to t_file-erlbt.
ENDIF.int = t_file-erlbt(10).
decimal = t_file-erlbt+10(2).concatenate int decimal into t_data-erlbt separated by C_DOT.T_DATA-VIN = T_FILE-VIN.concatenate t_file-model t_file-invnr into t_data-xblnr.
ENDFORM. " format_tdata
*&---------------------------------------------------------------------**& Form send_mail*&---------------------------------------------------------------------** This form Send the e-mail to the users
7/29/2019 Zai 00004
http://slidepdf.com/reader/full/zai-00004 17/18
*----------------------------------------------------------------------*FORM send_mail.data: tmp_date like sy-datum.write SY-DATUM TO tmp_date mmddyy. " Run date
* E-MAIL SUBJECT LINECLEAR doc_chng.CONCATENATE sy-cprog '(' sy-sysid(03) ')' 'Retirements_'(040)
tmp_date INTO doc_chng-obj_descr SEPARATED BY ' '.
* ATTACHMENT attributesCLEAR objpack.concatenate 'Retirements_'(040) tmp_date '.TXT'(041)
INTO objpack-obj_descr.
msgs_lin = msgs_lin + 1.objpack-body_start = msgs_lin.
****append lines of i_msg_Det to i_msgs.describe table i_msgs lines msgs_lin.
***objpack-body_num = msgs_lin. " for ? linesobjpack-doc_type = c_raw. " TXT FILE
READ TABLE i_msgs INDEX msgs_lin. " read the last partial line
objpack-doc_size = ( msgs_lin - 1 ) * 255 + STRLEN( i_msgs ).APPEND objpack.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'EXPORTING
document_data = doc_chngput_in_outbox = c_x
TABLESpacking_list = objpackcontents_txt = i_msgsreceivers = reclist
EXCEPTIONStoo_many_receivers = 1document_not_sent = 2document_type_not_exist = 3operation_no_authorization = 4parameter_error = 5x_error = 6enqueue_error = 7OTHERS = 8.
IF sy-subrc EQ 0. " if successful* The Log should display the SAP ID
MESSAGE i000 WITH 'E-mail attaching Retirements sent to Users'(045).
ELSE. " error* * The Log should display the SAP ID
MESSAGE i000 WITH 'Error in sending e-mail to Users'(044)'RC ='(046) sy-subrc.
ENDIF.
ENDFORM. " send_mail
*&---------------------------------------------------------------------**& Form set_mail
7/29/2019 Zai 00004
http://slidepdf.com/reader/full/zai-00004 18/18
*&---------------------------------------------------------------------** Assign the corresponding e-mail address depending of the SAP user,*----------------------------------------------------------------------*FORM set_mail.* E-MAIL BODY** attributesREFRESH objpack.CLEAR objpack.objpack-body_start = 1.describe table i_msgs lines msgs_lin.objpack-body_num = msgs_lin.objpack-doc_type = c_raw.APPEND objpack.
* RECEIVERREFRESH reclist.CLEAR reclist.
loop at s_erec.reclist-receiver = s_erec-low.
* detail will be sent to the Internet address specified in the input.reclist-rec_type = 'U'.reclist-express = c_x.APPEND reclist.
endloop.ENDFORM. " set_mail