You are on page 1of 7

**&---------------------------------------------------------------------* **& Report ZPP_UPLOAD_DATA_FROM_UNIX **& **&---------------------------------------------------------------------* **& **& **&---------------------------------------------------------------------* * * REPORT ZPP_UPLOAD_DATA_FROM_UNIX. *& tables : zppt_tran_001,zppt_tran_002.

data: xout type string. data: iout type table of string. field-symbols: <fs>. data: begin of itab occurs 0, rec(1000) type c, end of itab. data: p_file type localfile, p_file1 type localfile. data : v_dummy type string. data: ifile type table of salfldir with header line. data: sout type table of string with header line. data : p_path type salfile-longname value '/touchscreen/download/'. data : p_path1 type salfile-longname value '/touchscreen/archive/'. data : s_file(10) type c value '*.txt'. data : begin of I_FINAL occurs 0, ZDOENTRY like ZPPT_TRAN_001-ZDOENTRY, ZTENTRY like ZPPT_TRAN_001-ZTENTRY, ZPRDDT like ZPPT_TRAN_001-zprddt, ZZMACHINE like ZPPT_TRAN_001-ZZMACHINE, MATNR like ZPPT_TRAN_001-MATNR, WERKS like ZPPT_TRAN_001-WERKS, VERID like ZPPT_TRAN_001-VERID, zzdecision like zppt_tran_001-zzdecision, ZZPOTTER like ZPPT_TRAN_001-ZZPOTTER, ZZINSPECTOR like ZPPT_TRAN_001-ZZINSPECTOR, ZZGLAZER like ZPPT_TRAN_001-ZZGLAZER, ZZSORTER like ZPPT_TRAN_001-ZZSORTER, ZZSTOPPER like ZPPT_TRAN_001-ZZSTOPPER, ZKODE1 like ZPPT_TRAN_001-ZKODE1, ZKODE2 like ZPPT_TRAN_001-ZKODE2, ZKODE3 like ZPPT_TRAN_001-ZKODE3, ZZPOSTED like ZPPT_TRAN_001-ZZPOSTED, MBLNR like ZPPT_TRAN_001-MBLNR, zzreason like zppt_tran_001-zzreason, * count type i, end of I_FINAL. data : wa_final like i_final. data : begin of i_duplicate occurs 0, * ZDOENTRY like ZPPT_TRAN_001-ZDOENTRY, * ZTENTRY like ZPPT_TRAN_001-ZTENTRY, * ZPRDDT like ZPPT_TRAN_001-zprddt, ZZMACHINE like ZPPT_TRAN_001-ZZMACHINE, MATNR like ZPPT_TRAN_001-MATNR, WERKS like ZPPT_TRAN_001-WERKS, VERID like ZPPT_TRAN_001-VERID, zzdecision like zppt_tran_001-zzdecision,

* * *

ZZPOTTER like ZPPT_TRAN_001-ZZPOTTER, ZZINSPECTOR like ZPPT_TRAN_001-ZZINSPECTOR, ZZGLAZER like ZPPT_TRAN_001-ZZGLAZER, ZZSORTER like ZPPT_TRAN_001-ZZSORTER, ZZSTOPPER like ZPPT_TRAN_001-ZZSTOPPER, ZKODE1 like ZPPT_TRAN_001-ZKODE1, ZKODE2 like ZPPT_TRAN_001-ZKODE2, ZKODE3 like ZPPT_TRAN_001-ZKODE3, ZZPOSTED like ZPPT_TRAN_001-ZZPOSTED, MBLNR like ZPPT_TRAN_001-MBLNR, zzreason like zppt_tran_001-zzreason, count type i, end of i_duplicate.

data : wa_duplicate like i_duplicate. data : objdata type SOLISTI1 occurs 0 with header line, doc_data type sodocchgi1, packing_list type SOPCKLSTI1 occurs 0 with header line, contents_text type solisti1 occurs 0 with header line, receivers like somlreci1 occurs 0 with header line. *PARAMETERS : P_FILE2 TYPE RLGRAP-FILENAME. * *AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE2. * *PERFORM F4HELP USING P_FILE2. start-of-selection. call function 'RZL_READ_DIR_LOCAL' EXPORTING name = p_path TABLES file_tbl = ifile EXCEPTIONS argument_error = 1 not_found = 2 others = 3. loop at ifile. SEARCH ifile-name FOR '.txt'. if sy-subrc = 0. concatenate p_path ifile-name into p_file. open dataset p_file for input in text mode encoding default. if sy-subrc = 0. do. read dataset p_file into xout. if sy-subrc <> 0. exit. endif. SPLIT XOUT AT cl_abap_char_utilities=>horizontal_tab INTO: wa_FINAL-ZDOENTRY wa_FINAL-ZTENTRY wa_FINAL-ZPRDDT wa_FINAL-ZZMACHINE wa_FINAL-MATNR wa_FINAL-WERKS wa_FINAL-VERID wa_FINAL-zzdecision wa_FINAL-ZZPOTTER wa_FINAL-ZZINSPECTOR wa_FINAL-ZZGLAZER wa_FINAL-ZZSORTER wa_FINAL-ZZSTOPPER wa_FINAL-ZKODE1 wa_FINAL-ZKODE2 wa_FINAL-ZKODE3 v_dummy. append wa_final to i_final. append xout to sout.

enddo. endif. close dataset p_file. * Copy to temp folder concatenate p_path1 ifile-name into p_file1. open dataset p_file1 for output in text mode encoding default. loop at sout. transfer sout to p_file1. endloop. close dataset p_file1. DELETE DATASET p_file. clear xout. endif. endloop. ****************************** 1. Commented by Shravan on 09-07-2011 *********** ********************************* *---------------------------------------------- ----------------- ------------**************************** *CALL FUNCTION 'WS_UPLOAD' * EXPORTING ** CODEPAGE = ' ' * FILENAME = P_FILE2 * FILETYPE = 'DAT' ** HEADLEN = ' ' ** LINE_EXIT = ' ' ** TRUNCLEN = ' ' ** USER_FORM = ' ' ** USER_PROG = ' ' ** DAT_D_FORMAT = ' ' ** IMPORTING ** FILELENGTH = * TABLES * DATA_TAB = i_final * * EXCEPTIONS * CONVERSION_ERROR = 1 * FILE_OPEN_ERROR = 2 * FILE_READ_ERROR = 3 * INVALID_TYPE = 4 * NO_BATCH = 5 * UNKNOWN_ERROR = 6 * INVALID_TABLE_WIDTH = 7 * GUI_REFUSE_FILETRANSFER = 8 * CUSTOMER_ERROR = 9 * NO_AUTHORITY = 10 * OTHERS = 11. *IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. * *else. * MESSAGE 'file uploaded' TYPE 'I'. * *ENDIF.

*-----------------------

------------------------ ----------------- -------

------****************************

loop at i_final. ZPPT_TRAN_001-ZDOENTRY = I_FINAL-ZDOENTRY. ZPPT_TRAN_001-ZTENTRY = I_FINAL-ZTENTRY. ************* START *modified on 22-12-2007 ********** IF I_FINAL-WERKS = '1102' AND I_FINAL-VERID = '0021'. ZPPT_TRAN_001-VERID = '1021'. CONCATENATE I_FINAL-ZZMACHINE+0(2) 'W' I_FINAL-ZZMACHINE+3(1) INTO ZPPT_TRAN _001-ZZMACHINE. ***************START*modified on 8-1-2008 ************ ZPPT_TRAN_001-ZPRDDT = SY-DATUM. IF I_FINAL-zzdecision = 'REW' OR I_FINAL-zzdecision = 'rew'. ZPPT_TRAN_001-zzdecision = 'REF'. ELSE. ZPPT_TRAN_001-zzdecision = I_FINAL-zzdecision. ENDIF. ***************END*modified on 8-1-2008 ************ ELSE. ZPPT_TRAN_001-VERID = I_FINAL-VERID. ZPPT_TRAN_001-ZZMACHINE = I_FINAL-ZZMACHINE. ZPPT_TRAN_001-zzdecision = I_FINAL-zzdecision. ZPPT_TRAN_001-ZPRDDT = I_FINAL-ZPRDDT. ENDIF. ************* END *modified on 22-12-2007 ********** ZPPT_TRAN_001-MATNR = I_FINAL-MATNR. ZPPT_TRAN_001-WERKS = I_FINAL-WERKS. ZPPT_TRAN_001-ZZPOTTER = I_FINAL-ZZPOTTER. ZPPT_TRAN_001-ZZINSPECTOR = I_FINAL-ZZINSPECTOR. ZPPT_TRAN_001-ZZGLAZER = I_FINAL-ZZGLAZER. ZPPT_TRAN_001-ZZSORTER = I_FINAL-ZZSORTER. ZPPT_TRAN_001-ZZSTOPPER = I_FINAL-ZZSTOPPER. ZPPT_TRAN_001-ZKODE1 = I_FINAL-ZKODE1. ZPPT_TRAN_001-ZKODE2 = I_FINAL-ZKODE2. ZPPT_TRAN_001-ZKODE3 = I_FINAL-ZKODE3. ZPPT_TRAN_001-ZZPOSTED = I_FINAL-ZZPOSTED. ZPPT_TRAN_001-MBLNR = I_FINAL-MBLNR. ZPPT_TRAN_001-zzreason = I_FINAL-zzreason. select single * from zppt_tran_002 WHERE ZDOENTRY = ZPPT_TRAN_001-ZDOENTRY and ZTENTRY = ZPPT_TRAN_001-ZTENTRY and ZPRDDT = ZPPT_TRAN_001-ZPRDDT and ZZMACHINE = ZPPT_TRAN_001-ZZMACHINE and MATNR = ZPPT_TRAN_001-MATNR and VERID = ZPPT_TRAN_001-VERID and ZZDECISION = ZPPT_TRAN_001-zzdecision. * and werks = ZPPT_TRAN_001-WERKS. if sy-subrc = 0.

* * * *

ZPPT_TRAN_001-ZZPOSTED = 'D'. ZPPT_TRAN_001-zzreason = 'Duplicate Record'. insert zppt_tran_001. COMMIT WORK. move-corresponding i_final to i_duplicate. append i_duplicate. else. insert zppt_tran_001. COMMIT WORK. endif. clear: i_final,ZPPT_TRAN_001. endloop. ********************************************************************* if i_duplicate is not initial. loop at i_duplicate into wa_duplicate. concatenate wa_duplicate-ZZMACHINE wa_duplicate-MATNR wa_duplicate-WERKS wa_duplicate-VERID wa_duplicate-zzdecision wa_duplicate-ZZPOTTER wa_duplicate-ZZINSPECTOR wa_duplicate-ZZGLAZER wa_duplicate-ZZSORTER wa_duplicate-ZZSTOPPER wa_duplicate-ZKODE1 wa_duplicate-ZKODE2 wa_duplicate-ZKODE3 wa_duplicate-ZZPOSTED CL_ABAP_CHAR_UTILITIES=>NEWLINE into objdata separated by CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB. append objdata. endloop. break-point. CLEAR doc_data. doc_data-doc_size = 255 + STRLEN( objdata ). doc_data-obj_langu = sy-langu. doc_data-obj_name = 'SAPRPT'. doc_data-obj_descr = 'test mail'. doc_data-sensitivty = 'F'. contents_text = 'have a nice day'. append contents_text. clear packing_list. refresh packing_list. packing_list-TRANSF_BIN = space. packing_list-HEAD_START = 1. packing_list-HEAD_NUM = 0. packing_list-BODY_START = 1. describe table contents_text lines packing_list-BODY_NUM. packing_list-DOC_TYPE = 'RAW'. *packing_list-OBJ_NAME = 1. *packing_list-OBJ_DESCR = 1. *packing_list-OBJ_LANGU = 1. *packing_list-DOC_SIZE = 1. append packing_list. packing_list-TRANSF_BIN = 'X'.

packing_list-HEAD_START = 1. packing_list-HEAD_NUM = 1. packing_list-BODY_START = 1. describe table objdata lines packing_list-BODY_NUM. packing_list-DOC_TYPE = 'XLS'. packing_list-OBJ_NAME = 'attch name'. packing_list-OBJ_DESCR = 'attach desc'. *packing_list-OBJ_LANGU = 1. packing_list-DOC_SIZE = packing_list-BODY_NUM * 255. append packing_list. CLEAR receivers. REFRESH receivers. receivers-receiver = 'shravan@hindware.co.in'. receivers-rec_type = 'U'. receivers-com_type = 'INT'. receivers-notif_del = 'X'. receivers-notif_ndel = 'X'. APPEND receivers. CALL FUNCTION 'SO_DOCUMENT_SEND_API1' EXPORTING DOCUMENT_DATA = doc_data PUT_IN_OUTBOX = ' ' SENDER_ADDRESS = 'narendravasili@hindware.co.in' SENDER_ADDRESS_TYPE = 'INT' COMMIT_WORK = 'X' IMPORTING SENT_TO_ALL = NEW_OBJECT_ID = SENDER_ID = TABLES PACKING_LIST = packing_list OBJECT_HEADER = CONTENTS_BIN = objdata CONTENTS_TXT = contents_text CONTENTS_HEX = OBJECT_PARA = OBJECT_PARB = RECEIVERS = receivers EXCEPTIONS TOO_MANY_RECEIVERS = 1 DOCUMENT_NOT_SENT = 2 DOCUMENT_TYPE_NOT_EXIST = 3 OPERATION_NO_AUTHORIZATION = 4 PARAMETER_ERROR = 5 X_ERROR = 6 ENQUEUE_ERROR = 7 OTHERS = 8 . IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. else. MESSAGE 'Mail Send' TYPE 'I'. ENDIF. endif. *********************************************************************

* * * * * * * *

*&---------------------------------------------------------------------* *& Form F4HELP *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_P_FILE2 text *----------------------------------------------------------------------* *FORM F4HELP USING P_FILE. * *DATA : L_PATH TYPE IBIPPARMS-PATH. * *CALL FUNCTION 'F4_FILENAME' ** EXPORTING ** PROGRAM_NAME = SYST-CPROG ** DYNPRO_NUMBER = SYST-DYNNR ** FIELD_NAME = ' ' * IMPORTING * FILE_NAME = P_file. * * *ENDFORM. " F4HELP