Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

*&---------------------------------------------------------------------*

*& Report ZAXXPR_TO_APO

*&

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*REPORT ZAXXPR_TO_APO.* Data declarations

* include zaxxpr_to_apo_top.*&---------------------------------------------------------------------*

*& Include ZAXXPR_TO_APO_TOP

*&---------------------------------------------------------------------**Types declarationsTYPES : BEGIN OF ty_flatfile,

record TYPE char120,

END OF ty_flatfile.

TYPES : BEGIN OF ty_text,

line TYPE char128,

END OF ty_text.*types for the directory tableTYPES : BEGIN OF ty_direct,

direct TYPE char50,

END OF ty_direct.*types for the ftp command result internal tableTYPES : BEGIN OF ty_result,

text TYPE char512,

END OF ty_result.*types for the reterieved filesTYPES : BEGIN OF ty_files,

file TYPE char200,

END OF ty_files.*types for the dataTYPES : BEGIN OF ty_data,

data TYPE char2000,

END OF ty_data.*types for the log dataTYPES : BEGIN OF ty_log,

text TYPE char2000,

END OF ty_log.**types for the lock object tableTYPES : BEGIN OF ty_locobj.

include structure zap_lockobj.

TYPES : END OF ty_locobj.*types for the archive and log filepathtypes : begin of ty_path,

funcproc type rs38l_fnam,

filepath type ZFILEPATH01,

arcpath type char512,

logpath type char512,

location type char40,

file type char200,

end of ty_path.*Internal table declarationsDATA : it_flatfile TYPE STANDARD TABLE OF ty_flatfile,

it_result TYPE STANDARD TABLE OF ty_result,

it_direct TYPE STANDARD TABLE OF ty_direct,

it_files TYPE STANDARD TABLE OF ty_files,

it_data TYPE STANDARD TABLE OF ty_data,

it_log TYPE STANDARD TABLE OF ty_log,

it_log1 TYPE standard table of ty_log,

it_locobj TYPE STANDARD TABLE OF ZAP_LOCKOBJ2,

it_funcproc TYPE STANDARD TABLE OF zap_funcproc,

it_seqno1 TYPE STANDARD TABLE OF zap_flatfile,

it_seqno2 TYPE STANDARD TABLE OF zap_flatfile,

it_seqno3 TYPE STANDARD TABLE OF zap_flatfile,

it_seqno4 TYPE STANDARD TABLE OF zap_flatfile,

it_seqno5 TYPE STANDARD TABLE OF zap_flatfile,

it_lockobj TYPE STANDARD TABLE OF ZAP_LOCKOBJ2,

it_path type standard table of ty_path.*Work area declarationsDATA : l_wa_flatfile TYPE ty_flatfile,

wa_result TYPE ty_result,

wa_direct TYPE ty_direct,

wa_files TYPE ty_files,

wa_data TYPE ty_data,

wa_log TYPE ty_log,

wa_path type ty_path.*Table type declarationTYPES : ty_t_direct TYPE TABLE OF ty_direct,

ty_t_result TYPE TABLE OF ty_result,

ty_t_files TYPE TABLE OF ty_files,

ty_t_data TYPE TABLE OF ty_data,

ty_t_log TYPE TABLE OF ty_log,

ty_t_locobj TYPE TABLE OF ZAP_LOCKOBJ2,

ty_t_funcproc TYPE TABLE OF zap_funcproc,

ty_t_seqno TYPE TABLE OF zap_flatfile,

ty_t_lockobj TYPE TABLE OF ZAP_LOCKOBJ2,

ty_t_path type table of ty_path.*Global variable declerationDATA : v_cmd(512) TYPE c,

l_cmd1(150) TYPE c,

v_handle TYPE i,

v_filepath TYPE ZFILEPATH01,

v_fiseq TYPE char1,

v_process TYPE char1,

v_lock TYPE char1,

v_funproc TYPE rs38l_fnam,

v_seqno TYPE char1,

v_locobj TYPE char1,

v_logpath TYPE char512,

v_arcpath TYPE char512,

v_filepath1 type char512,

v_error type char1,

v_location type char40.*Constant declarationsCONSTANTS : c_path TYPE char128 VALUE

'\\pmipmftpaisdev.eu.pm.com\pmipmftpaisdev\',

c_host TYPE char100 VALUE

'\\pmipmftpaisdev.eu.pm.com\PMIPMFTPAISDEV',

c_e TYPE char1 VALUE 'E',

c_w TYPE char1 VALUE 'W',

c_slash TYPE char1 VALUE '/',

c_20 TYPE char2 VALUE '20',

c_y TYPE char1 VALUE 'Y',

c_x TYPE char1 VALUE 'X',

c_1 TYPE char1 VALUE '1',

c_2 TYPE char1 VALUE '2'.*Subroutines

* include zaxxpr_to_apo_forms.*----------------------------------------------------------------------*

* SELECTION SCREEN *

*----------------------------------------------------------------------*SELECTION-SCREEN: BEGIN OF BLOCK blk1

WITH FRAME TITLE text-001. "Selection Options

SELECTION-SCREEN SKIP 1.

PARAMETERS : p_file TYPE RLGRAP-FILENAME.

SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN: END OF BLOCK blk1.*----------------------------------------------------------------------*

* SELECTION SCREEN *

*----------------------------------------------------------------------*AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

STATIC = 'X'

CHANGING

FILE_NAME = P_FILE

EXCEPTIONS

MASK_TOO_LONG = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

MESSAGE 'no file' type 'e'.

ENDIF.

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

* START OF SELECTION

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

START-OF-SELECTION.

*Check whether the time is open for processing from

*the timeslot table

PERFORM f_check_open_time CHANGING v_process.

*Dont process the file if the time is not open for processing

IF v_process <> c_y.

LEAVE LIST-PROCESSING.

ENDIF.

*Perform FTP connection with the windows NT server

PERFORM f_ftp_connection.

*Get the directory from the FTP path

PERFORM f_get_directory USING p_file

CHANGING it_direct.

LOOP AT it_direct INTO wa_direct.

*Get the files inside the directory

PERFORM f_get_files USING p_file

wa_direct

CHANGING it_files.

LOOP AT it_files INTO wa_files.

*Lock the file before processing

PERFORM f_lock_file USING p_file

wa_direct

wa_files

CHANGING v_filepath.

*Validate the files and issue the appropiate log

PERFORM f_validate_file USING wa_files

v_filepath

CHANGING v_fiseq

v_funproc

it_log.

*Read the files from the path

PERFORM f_read_files USING p_file

wa_direct

wa_files

CHANGING v_arcpath

v_filepath1

v_location

it_data

it_log.

*Delete the file from the current directory and archive the

*file in the archive directory

PERFORM f_archive_file USING it_data

v_arcpath

v_filepath1.

*Create the log table in the respective filepath

PERFORM f_create_log USING p_file

wa_direct

wa_files

it_log

CHANGING v_logpath.

*Update the archive path in the custom table for processing

PERFORM f_update_archive_file USING v_funproc

v_filepath

v_arcpath

v_logpath

v_location

wa_files

CHANGING it_path.

REFRESH : it_data,

it_log.

CLEAR : v_lock,

v_locobj,

v_seqno,

v_funproc,

v_filepath.

ENDLOOP.

REFRESH it_files.

ENDLOOP.

LOOP AT it_path INTO wa_path.

*Lock the file before processing

PERFORM f_lock_filepath USING wa_path-filepath

CHANGING v_lock.

*If the file is already in processing skip the file

IF v_lock = c_x.

PERFORM f_log_data USING space

text-020

space

CHANGING it_log1.

CONTINUE.

ENDIF.

*Read the data from the archive directory

PERFORM f_read_archive_data USING wa_path-arcpath

CHANGING it_data.***Sequence the filePERFORM f_sequence_file USING wa_path-funcproc

it_data

CHANGING v_seqno

it_locobj

it_funcproc

it_seqno1

it_seqno2

it_seqno3

it_seqno4

it_seqno5.*Lock the locations and the lock objects in the custom lock tabePERFORM f_lock_objects USING it_locobj

CHANGING v_locobj

it_lockobj.*If any of the location and its lock object are locked

*dont process the fileIF v_locobj = c_x.

PERFORM f_log_data USING space

text-019

space

CHANGING it_log1.

DELETE FROM zap_fileproc WHERE filepath = wa_path-filepath.

COMMIT WORK.

CONTINUE.

ENDIF.*Perform start processing logPERFORM f_start_process_log CHANGING it_log1.*MOD-010

* IF it_seqno1[] IS NOT INITIAL.*

**Process the first sequence and get the log table

* PERFORM f_process_seqno USING it_seqno1

* it_funcproc

* c_1* CHANGING v_error

* it_log1.

*

* ENDIF.

*

* IF it_seqno2[] IS NOT INITIAL.*

**Process the second sequence and get the log table

* PERFORM f_process_seqno USING it_seqno2

* it_funcproc

* c_2

* CHANGING v_error

* it_log1.*

* ENDIF.

*MOD-010

*Perform end of processing log

PERFORM f_end_process_log CHANGING it_log1.

*append the log table in the respective filepath

PERFORM f_append_log USING it_log1

wa_path-logpath.

** Delete the filepath from the custom table after processing

* PERFORM f_delete_lock_file USING wa_path-filepath

* it_lockobj.

*

* IF there is an error occured during loading or in the file

* send the email notification to the customer

IF v_error = c_x.

PERFORM f_send_email USING p_file

wa_direct

wa_path-file

wa_path-logpath

wa_path-arcpath

wa_path-location.

ENDIF.*CLEAR : v_lock,

v_locobj,

v_seqno,

v_funproc,

v_filepath,

v_error.

REFRESH : it_locobj,

it_funcproc,

it_seqno1,

it_seqno2,

it_seqno3,

it_seqno4,

it_seqno5,

it_log1,

it_data,

it_lockobj.

ENDLOOP.*&---------------------------------------------------------------------*

*& Include ZAXXPR_TO_APO_FORMS

*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*

*& Include ZAXXPR_TO_APO_SIGN_TOP

*&---------------------------------------------------------------------**&---------------------------------------------------------------------*

*& Include ZAXXPR_TO_APO_SIGN_FORMS

*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*

*& Form f_ftp_connection

*&---------------------------------------------------------------------*

* FTP connectivity to Windows NT server

*----------------------------------------------------------------------*FORM f_ftp_connection .*Local variable declarationsDATA : l_v_pwd TYPE char20 VALUE 'Tezomin4',

l_v_key TYPE i VALUE 26101957,

l_v_pwd_len TYPE i.

DESCRIBE FIELD l_v_pwd LENGTH l_v_pwd_len IN CHARACTER MODE.

* Scramble the password before connecting to the FTP server

CALL 'AB_RFC_X_SCRAMBLE_STRING'

ID 'SOURCE' FIELD l_v_pwd ID 'KEY' FIELD l_v_key

ID 'SCR' FIELD 'X' ID 'DESTINATION' FIELD l_v_pwd

ID 'DSTLEN' FIELD l_v_pwd_len.

* Connect to the FTP server

CALL FUNCTION 'FTP_CONNECT'

EXPORTING

user = 'ap\s-ftpsgacd'

password = l_v_pwd

host = 'pmipmftpaisdev.eu.pm.com'

rfc_destination = 'SAPFTPA'

IMPORTING

handle = v_handle

EXCEPTIONS

not_connected = 1

OTHERS = 2.

IF sy-subrc <> 0.

ENDIF.

ENDFORM. " f_ftp_connection

*&---------------------------------------------------------------------*

*& Form f_get_directory

*&---------------------------------------------------------------------*

* Get the directorys for the paths specified in the selection

* screen

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

* <--FP_IT_DIRECT Directorys internal table

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

FORM f_get_directory USING fp_p_file TYPE LOCALFILE

CHANGING fp_it_direct TYPE ty_t_direct.

* Local variables

DATA : l_v_cmd TYPE char512,

l_v_fdpos TYPE syfdpos.

* Changing directory

CONCATENATE 'cd' fp_p_file INTO l_v_cmd SEPARATED BY space.

* Change the directory

PERFORM f_ftp_command USING l_v_cmd

CHANGING it_result.

IF sy-subrc = 0.

REFRESH it_result.

CLEAR l_v_cmd.

* Ascii mode

l_v_cmd = 'ascii'.

PERFORM f_ftp_command USING l_v_cmd

CHANGING it_result.

IF sy-subrc = 0.

REFRESH it_result.

CLEAR l_v_cmd.

* Get the folders inside the directory

l_v_cmd = 'dir'.

PERFORM f_ftp_command USING l_v_cmd

CHANGING it_result.

IF sy-subrc = 0.

LOOP AT it_result INTO wa_result.

SEARCH wa_result FOR '<DIR>'.

IF sy-subrc = 0.

l_v_fdpos = sy-fdpos.

l_v_fdpos = l_v_fdpos + 5.

DO.

l_v_fdpos = l_v_fdpos + 1.

IF wa_result+l_v_fdpos(1) <> ' '.

wa_direct-direct = wa_result+l_v_fdpos(20).

APPEND wa_direct TO fp_it_direct.

EXIT.

ENDIF.

ENDDO.

ENDIF.

ENDLOOP.

ENDIF.

ENDIF.

ENDIF.

REFRESH it_result.

ENDFORM. " f_get_directory

*&---------------------------------------------------------------------*

*& Form f_ftp_command

*&---------------------------------------------------------------------*

* Execute the unix command

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

* -->FP_L_CMD text

* <--FP_IT_RESULT text

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

FORM f_ftp_command USING fp_l_cmd TYPE char512

CHANGING fp_it_result TYPE ty_t_result.

*Execute the FTP Command

CALL FUNCTION 'FTP_COMMAND'

EXPORTING

handle = v_handle

command = fp_l_cmd

TABLES

data = fp_it_result

EXCEPTIONS

tcpip_error = 1

command_error = 2

data_error = 3

OTHERS = 4.

IF sy-subrc <> 0.

ENDIF.

ENDFORM. " f_ftp_command

*&---------------------------------------------------------------------*

*& Form f_get_files

*&---------------------------------------------------------------------*

* Get the files from the directory

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

* -->FP_P_FILE File path

* -->FP_WA_DIRECT Directory name

* <--FP_IT_FILES Files

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

FORM f_get_files USING fp_p_file TYPE LOCALFILE

fp_wa_direct TYPE ty_direct

CHANGING fp_it_files TYPE ty_t_files.

* Local variable

DATA : l_v_cmd TYPE char512,

l_v_fdpos TYPE syfdpos.

CONCATENATE 'cd' fp_wa_direct INTO l_v_cmd SEPARATED BY space.

* Change the directory

PERFORM f_ftp_command USING l_v_cmd

CHANGING it_result.

IF sy-subrc = 0.

REFRESH it_result.

CLEAR v_cmd.

CONCATENATE 'dir' '*.csv' v_cmd INTO v_cmd SEPARATED BY space.

* Get the files from the directory

PERFORM f_ftp_command USING v_cmd

CHANGING it_result.

IF sy-subrc = 0.

LOOP AT it_result INTO wa_result.

IF sy-tabix = 1.

CONTINUE.

ENDIF.

SEARCH wa_result FOR '.csv'.

IF sy-subrc = 0.

wa_files-file = wa_result+39(200).

APPEND wa_files TO fp_it_files.

l_v_fdpos = sy-fdpos.

DO.

l_v_fdpos = l_v_fdpos - 1.

IF wa_result+l_v_fdpos(1) = ' '.

l_v_fdpos = l_v_fdpos + 1.

wa_files-file = wa_result+l_v_fdpos(100).

APPEND wa_files TO fp_it_files.

EXIT.

ENDIF.

ENDDO.

ENDIF.

ENDLOOP.

ENDIF.

ENDIF.

l_v_cmd = 'cdup'.

* Change the directory by one

PERFORM f_ftp_command USING l_v_cmd

CHANGING it_result.

IF sy-subrc = 0.

REFRESH it_result.

CLEAR l_v_cmd.

ENDIF.

ENDFORM. " f_get_files*&---------------------------------------------------------------------*

*& Form f_validate_file

*&---------------------------------------------------------------------*

* Validate the file name and issue appropiate log

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

* -->FP_WA_FILES File name

* -->FP_V_FILEPATH File Path

* <--FP_V_FISEQ File sequence

* <--FP_V_FUNPROC Function Module

* <--FP_IT_LOG Log internal table

*----------------------------------------------------------------------*FORM f_validate_file USING fp_wa_files TYPE ty_files

fp_v_filepath TYPE ZFILEPATH01

CHANGING fp_v_fiseq TYPE char1

fp_v_funproc TYPE rs38l_fnam

fp_it_log TYPE ty_t_log.* Local variableDATA : l_v_fityp TYPE char4,

l_v_date TYPE sy-datum,

l_v_date1 TYPE char4.* Add the logPERFORM f_log_data USING space

space

space

CHANGING fp_it_log.* Append the file name to the log tableCLEAR wa_log.

CONCATENATE c_host fp_v_filepath INTO wa_log-text

SEPARATED BY '/'.

CONCATENATE text-005 wa_log-text INTO wa_log-text

SEPARATED BY space.

APPEND wa_log TO fp_it_log.

*Validate the file type

SELECT SINGLE

fityp

fiseq

funproc

FROM zap_file

INTO (l_v_fityp,

fp_v_fiseq,

fp_v_funproc)

WHERE fityp = fp_wa_files+0(4).

IF sy-subrc <> 0.

*Not valid file type

PERFORM f_log_data USING c_e

text-003

space

CHANGING fp_it_log.

ELSE.

l_v_date = fp_wa_files+4(8).

*Validate the date in the file

l_v_date1 = sy-datum - l_v_date.

IF l_v_date1 > c_20.

*Date is not within 20 days

PERFORM f_log_data USING c_e

text-004

space

CHANGING fp_it_log.

ENDIF.

ENDIF.

ENDFORM. " f_validate_file

*&---------------------------------------------------------------------*

*& Form f_read_files

*&---------------------------------------------------------------------*

* Read the file from the directory

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

* -->FP_P_FILE File path

* -->FP_WA_DIRECT Directory

* -->FP_WA_FILES File name

* <--FP_IT_DATA Raw Data

* <--FP_IT_LOG Log internal table

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

FORM f_read_files USING fp_p_file TYPE LOCALFILE

fp_wa_direct TYPE ty_direct

fp_wa_files TYPE ty_files

CHANGING fp_v_arcpath TYPE char512

fp_v_filepath TYPE char512

fp_v_location TYPE char40

fp_it_data TYPE ty_t_data

fp_it_log TYPE ty_t_log.

*Local variables

DATA : l_v_filepath TYPE char512.

* local constants

CONSTANTS : c_host TYPE char100 VALUE

'\\pmipmftpaisdev.eu.pm.com\PMIPMFTPAISDEV',

l_c_archive TYPE char20 VALUE 'archive'.

CONCATENATE c_host fp_p_file fp_wa_direct fp_wa_files

INTO fp_v_filepath SEPARATED BY '\'.

CONCATENATE fp_p_file fp_wa_direct INTO fp_v_location

SEPARATED BY '\'.

* Open the file and transfer the data into the internal table

OPEN DATASET fp_v_filepath

FOR

INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc = 0.

DO.

READ DATASET

fp_v_filepath

INTO wa_data .

IF sy-subrc = 0.

APPEND wa_data TO fp_it_data.

CLEAR wa_data.

ELSE.

EXIT.

ENDIF.

ENDDO.

CONCATENATE c_host fp_p_file fp_wa_direct l_c_archive

fp_wa_files INTO fp_v_arcpath SEPARATED BY '\'.

*Open the archive directory

OPEN DATASET fp_v_arcpath

FOR

OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc = 0.

*Put the file in the archive directory

LOOP AT fp_it_data INTO wa_data.

TRANSFER wa_data TO fp_v_arcpath.

ENDLOOP.

*Delete the file in the current location

DELETE DATASET fp_v_filepath.

ENDIF.

ENDIF.

ENDFORM. " f_read_files*&---------------------------------------------------------------------*

*& Form f_log_data

*&---------------------------------------------------------------------*

* Read all the log information in the internal table

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

* -->FP_MSGTY Message type

* -->FP_MSGTX Message text

* -->FP_MSGV1 Message number

* <--FP_IT_LOG Log table

*----------------------------------------------------------------------*FORM f_log_data USING fp_msgty TYPE any

fp_msgtx TYPE char512

fp_msgv1 TYPE any

CHANGING fp_it_log TYPE ty_t_log.* Local variableDATA : l_v_log TYPE char512,

l_v_datum TYPE char10,

l_v_uzeit TYPE char8.* Build the date formatCONCATENATE sy-datum+0(4) sy-datum+4(2) sy-datum+6(2)

INTO l_v_datum SEPARATED BY c_slash.* Build the time formatCONCATENATE sy-uzeit+0(2) sy-uzeit+2(2) sy-uzeit+4(2)

INTO l_v_uzeit SEPARATED BY ':'.* Build the log tableCONCATENATE text-002 l_v_datum l_v_uzeit INTO l_v_log

SEPARATED BY space.

CONCATENATE l_v_log ':' fp_msgtx INTO l_v_log

SEPARATED BY space.

CLEAR wa_log.

* Append the log into the internal table

wa_log-text = l_v_log.

APPEND wa_log TO fp_it_log.

ENDFORM. " f_log_data

*&---------------------------------------------------------------------*

*& Form f_check_open_time

*&---------------------------------------------------------------------*

* Check whether the time is open for processing

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

* --> p1 text

* <-- p2 text

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

FORM f_check_open_time CHANGING fp_v_process.

*Local variable

DATA : l_v_process TYPE char1,

l_v_date TYPE char2,

l_v_hour TYPE char2.

*Local constants

CONSTANTS : l_c_star TYPE char1 VALUE '*'.

l_v_date = sy-datum+6(2).

l_v_hour = sy-uzeit+0(2).

SELECT SINGLE

process

FROM zap_timeslot

INTO l_v_process

WHERE zdate = l_v_date AND

zhour = l_v_hour.

IF sy-subrc <> 0.

SELECT SINGLE

process

FROM zap_timeslot

INTO l_v_process

WHERE zdate = l_c_star AND

zhour = l_v_hour.

IF sy-subrc = 0.

fp_v_process = l_v_process.

ENDIF.

ELSE.

fp_v_process = l_v_process.

ENDIF.

ENDFORM. " f_check_open_time

*&---------------------------------------------------------------------*

*& Form f_lock_file

*&---------------------------------------------------------------------*

* Lock the file in the table

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

* -->FP_P_FILE File Path

* -->FP_WA_DIRECT Directory

* -->FP_WA_FILES File name

* <--FP_V_FILEPATH FIle Path

* <--FP_V_LOCK Lock Key

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

FORM f_lock_file USING fp_p_file TYPE LOCALFILE

fp_wa_direct TYPE ty_direct

fp_wa_files TYPE ty_files

CHANGING fp_v_filepath TYPE ZFILEPATH01.

*Concatenate the files and get the file path

CONCATENATE fp_p_file fp_wa_direct fp_wa_files

INTO fp_v_filepath SEPARATED BY '\'.

ENDFORM. " f_lock_file

*&---------------------------------------------------------------------*

*& Form f_delete_lock_file

*&---------------------------------------------------------------------** Delete the filepath after processing

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

* -->FP_V_FILEPATH File Path

* -->FP_IT_LOCKOBJ Lock Object Internal Table

*----------------------------------------------------------------------*FORM f_delete_lock_file USING fp_v_filepath TYPE ZFILEPATH01

fp_it_lockobj TYPE ty_t_locobj.

DELETE FROM zap_fileproc WHERE filepath = fp_v_filepath.* DELETE zap_lockobj FROM TABLE fp_it_lockobj.COMMIT WORK.

ENDFORM. " f_delete_lock_file*&---------------------------------------------------------------------*

*& Form f_sequence_file

*&---------------------------------------------------------------------*

* Sequecnce the file using the file type function module

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

** -->FP_V_FUNPROC Function Module for sequencing

* -->FP_IT_DATA Flatfile internal table

* <--FP_V_SEQNO Sequence Number

* <--FP_IT_LOCOBJ Lock Object internal table

* <--FP_IT_FUNCPROC Function modules for processing the sequence

* <--FP_IT_SEQNO1 Sequcence No 1 internal table

* <--FP_IT_SEQNO2 Sequcence No 2 internal table

* <--FP_IT_SEQNO3 Sequcence No 3 internal table

* <--FP_IT_SEQNO4 Sequcence No 4 internal table

* <--FP_IT_SEQNO5 Sequcence No 5 internal table

*--------------------------------#-----------------------------------*FORM f_sequence_file USING fp_v_funproc TYPE rs38l_fnam

fp_it_data TYPE ty_t_data

CHANGING fp_v_seqno TYPE char1

fp_it_locobj TYPE ty_t_locobj

fp_it_funcproc TYPE ty_t_funcproc

fp_it_seqno1 TYPE ty_t_seqno

fp_it_seqno2 TYPE ty_t_seqno

fp_it_seqno3 TYPE ty_t_seqno

fp_it_seqno4 TYPE ty_t_seqno

fp_it_seqno5 TYPE ty_t_seqno.

CALL FUNCTION fp_v_funproc

IMPORTING

seq_no = fp_v_seqno

TABLES

input_data = fp_it_data

lockobject = fp_it_locobj

funcproc = fp_it_funcproc

seqno1 = fp_it_seqno1

seqno2 = fp_it_seqno2

seqno3 = fp_it_seqno3

seqno4 = fp_it_seqno4

seqno5 = fp_it_seqno5

EXCEPTIONS

no_sequence_number_found = 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.

ENDIF.

ENDFORM. " f_sequence_file

*&---------------------------------------------------------------------*

*& Form f_lock_objects

*&---------------------------------------------------------------------*

* Lock the location wise lock objects

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

* -->FP_IT_LOCOBJ Location Lock object

* <--FP_V_LOCOBJ Lock Object

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

FORM f_lock_objects USING fp_it_locobj TYPE ty_t_locobj

CHANGING fp_v_locobj TYPE char1

fp_it_lockobj TYPE ty_t_lockobj.

*Local internal table

DATA : l_it_lockobj TYPE STANDARD TABLE OF zap_lockobj2.

*Local work area

DATA : l_wa_lockobj TYPE ZAP_LOCKOBJ2,

l_wa_lockobj1 TYPE ZAP_LOCKOBJ2.

*Check whether the lock entries are in the custom lock table

*or not

SELECT location

funproc

FROM zap_lockobj2

INTO TABLE l_it_lockobj

FOR ALL ENTRIES IN fp_it_locobj

WHERE location = fp_it_locobj-location AND

funproc = fp_it_locobj-funproc.

IF sy-subrc = 0.

fp_v_locobj = c_x.

ELSE.

LOOP AT fp_it_locobj INTO l_wa_lockobj.

l_wa_lockobj1-mandt = sy-mandt.

l_wa_lockobj1-location = l_wa_lockobj-location.

l_wa_lockobj1-funproc = l_wa_lockobj-funproc.

APPEND l_wa_lockobj1 TO fp_it_lockobj.

ENDLOOP.

MODIFY zap_lockobj2 FROM TABLE fp_it_lockobj.

COMMIT WORK.

ENDIF.

ENDFORM. " f_lock_objects

*&---------------------------------------------------------------------*

*& Form f_create_log

*&---------------------------------------------------------------------*

* Transfer the log information

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

* -->FP_P_FILE File Path

* -->FP_WA_DIRECT Directories Name

* -->FP_WA_FILES File Name

* -->FP_IT_LOG Log internal table

* <--FP_V_LOGPATH File path for Log

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

FORM f_create_log USING fp_p_file TYPE LOCALFILE

fp_wa_direct TYPE ty_direct

fp_wa_files TYPE ty_files

fp_it_log TYPE ty_t_log

CHANGING fp_v_logpath TYPE char512.

*Local variables

DATA : l_v_files TYPE char200.

CONCATENATE 'log_' fp_wa_files INTO l_v_files.

REPLACE '.csv' IN l_v_files WITH '.txt'.

CONCATENATE c_host fp_p_file fp_wa_direct 'log' l_v_files

INTO v_logpath SEPARATED BY '\'.

*Open the log directory

OPEN DATASET fp_v_logpath

FOR APPENDING

IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc = 0.

*Put the file in the log directory

LOOP AT fp_it_log INTO wa_log.

TRANSFER wa_log TO fp_v_logpath.

ENDLOOP.

CLOSE DATASET fp_v_logpath.

ENDIF.

ENDFORM. " f_create_log

*&---------------------------------------------------------------------*

*& Form f_send_email

*&---------------------------------------------------------------------*

* Send the Email Notification to the customer

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

* -->FP_P_FILE File path

* -->FP_WA_FILES File Name

* -->FP_V_LOGPATH Log File path

* -->FP_V_ARCPATH Archive file path

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

FORM f_send_email USING fp_p_file TYPE LOCALFILE

fp_wa_direct TYPE ty_direct

fp_wa_files TYPE char200

fp_v_logpath TYPE char512

fp_v_arcpath TYPE char512

fp_v_location TYPE char40.

* Local variables

DATA : l_v_lines TYPE char2,

l_v_text TYPE char200,

l_v_datum TYPE char10,

l_v_uzeit TYPE char8,

l_v_smtpadr TYPE ad_smtpadr,

l_v_location TYPE char40.

* Local work area

DATA : l_wa_content TYPE solisti1,

l_wa_document TYPE sodocchgi1,

l_wa_recieve TYPE somlreci1.

* Local internal table

DATA : l_it_content TYPE STANDARD TABLE OF solisti1,

l_it_recieve TYPE STANDARD TABLE OF somlreci1.

CONCATENATE fp_p_file fp_wa_direct INTO l_v_location

SEPARATED BY '\'.

*Select the email address based on the file path

SELECT SINGLE

smtpadr

FROM zap_email

INTO l_v_smtpadr

WHERE location = fp_v_location.

IF sy-subrc = 0.

*Mail contents

CLEAR l_wa_content.

l_wa_content-line = 'Dear Customer,'.

APPEND l_wa_content TO l_it_content.

CLEAR l_wa_content.

APPEND l_wa_content TO l_it_content.

CONCATENATE text-007 text-008 INTO l_v_text

SEPARATED BY space.

l_wa_content-line = l_v_text.

APPEND l_wa_content TO l_it_content.

CLEAR l_wa_content.

l_wa_content-line = text-009.

APPEND l_wa_content TO l_it_content.

CLEAR l_wa_content.

l_wa_content-line = fp_v_logpath.

APPEND l_wa_content TO l_it_content.

CLEAR l_wa_content.

APPEND l_wa_content TO l_it_content.

CLEAR l_wa_content.

l_wa_content-line = text-010.

APPEND l_wa_content TO l_it_content.

CLEAR l_wa_content.

l_wa_content-line = fp_v_arcpath.

APPEND l_wa_content TO l_it_content.

CLEAR l_wa_content.

APPEND l_wa_content TO l_it_content.

CLEAR l_wa_content.

CONCATENATE text-011 text-012 INTO l_v_text

SEPARATED BY space.

l_wa_content-line = l_v_text.

APPEND l_wa_content TO l_it_content.

CLEAR l_wa_content.

APPEND l_wa_content TO l_it_content.

CLEAR l_wa_content.

l_wa_content-line = text-013.

APPEND l_wa_content TO l_it_content.

CLEAR l_wa_content.

APPEND l_wa_content TO l_it_content.

CONCATENATE text-006 fp_wa_files INTO l_wa_content-line

SEPARATED BY space.

APPEND l_wa_content TO l_it_content.

CLEAR l_wa_content.

APPEND l_wa_content TO l_it_content.

*Build the date format

CONCATENATE sy-datum+0(4) sy-datum+4(2) sy-datum+6(2)

INTO l_v_datum SEPARATED BY c_slash.

*Build the time format

CONCATENATE sy-uzeit+0(2) sy-uzeit+2(2) sy-uzeit+4(2)

INTO l_v_uzeit SEPARATED BY ':'.

CONCATENATE text-014 l_v_datum l_v_uzeit INTO l_wa_content-line

SEPARATED BY space.

APPEND l_wa_content TO l_it_content.

CLEAR l_wa_content.

APPEND l_wa_content TO l_it_content.

l_wa_content-line = text-015.

APPEND l_wa_content TO l_it_content.

*Heading of the mail

l_wa_document-obj_name = 'ERROR'.

CONCATENATE text-006 fp_wa_files INTO l_wa_document-obj_descr

SEPARATED BY '-'.

l_wa_document-obj_langu = sy-langu.

l_wa_document-sensitivty = 'O'.

l_wa_document-priority = '1'.

*Reciptents Mail Id

l_wa_recieve-receiver = l_v_smtpadr.

l_wa_recieve-rec_type = 'U'.

l_wa_recieve-com_type = 'SOTR'.

APPEND l_wa_recieve TO l_it_recieve.

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

document_data = l_wa_document

document_type = 'RAW'

put_in_outbox = c_x

commit_work = c_x

TABLES

object_content = l_it_content

receivers = l_it_recieve

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.

ENDIF.

ENDIF.

ENDFORM. " f_send_email

*&---------------------------------------------------------------------*

*& Form f_process_seqno1

*&---------------------------------------------------------------------*

* Process the first sequence and get the log table

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

* -->FP_IT_SEQNO1 Sequence Internal table

* -->FP_IT_FUNCPROC Function module for processing

* -->FP_V_SEQNO Sequence number

* <--FP_IT_LOG Log table

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

FORM f_process_seqno USING fp_it_seqno TYPE ty_t_seqno

fp_it_funcproc TYPE ty_t_funcproc

fp_v_seqno TYPE char1

CHANGING fp_v_error TYPE char1

fp_it_log TYPE ty_t_log.

*Local variable

DATA : l_v_error TYPE char1,

l_v_reprocess TYPE char1,

l_v_cnt TYPE int1.

*Local work area

DATA : l_wa_funcproc TYPE zap_funcproc.

*Local internal table

DATA : l_it_log TYPE STANDARD TABLE OF ty_log.

* READ TABLE fp_it_funcproc INTO l_wa_funcproc

* WITH KEY fiseq = fp_v_seqno.

* IF sy-subrc = 0.

* REFRESH l_it_log.

* CALL FUNCTION l_wa_funcproc-funproc

* IMPORTING

* flg_error = l_v_error

* flg_reprocess = l_v_reprocess

* TABLES

* it_seq = fp_it_seqno

* it_log = l_it_log.

*

* IF sy-subrc = 0.

*

* IF l_v_reprocess = c_x.

* l_v_cnt = l_v_cnt + 1.

*

* IF l_v_cnt LE 3.

*

* CLEAR fp_v_error.

** REFRESH fp_it_log.

* PERFORM f_process_seqno USING fp_it_seqno

* fp_it_funcproc

* fp_v_seqno

* CHANGING fp_v_error

* fp_it_log.

* ENDIF.

*

* ENDIF.

*

* LOOP AT l_it_log INTO wa_log.

* APPEND wa_log TO fp_it_log.

* ENDLOOP.

*

* IF l_v_error = c_x.

* fp_v_error = l_v_error.

* ENDIF.

* ENDIF.

* ENDIF.

CLEAR l_v_error.

CLEAR wa_log.

APPEND wa_log TO fp_it_log.

REFRESH l_it_log.

ENDFORM. " f_process_seqno1

*&---------------------------------------------------------------------*

*& Form f_start_process_log

*&---------------------------------------------------------------------*

* Start processing Log

*----------------------------------------------------------------------*#

* <--FP_IT_LOG Log table

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

FORM f_start_process_log CHANGING fp_it_log TYPE ty_t_log.

* Local variable

DATA : l_v_log TYPE char512,

l_v_datum TYPE char8,

l_v_uzeit TYPE char6.

* Build the date format

CONCATENATE sy-datum+4(2) sy-datum+6(2) sy-datum+2(2)

INTO l_v_datum SEPARATED BY c_slash.

* Build the time format

CONCATENATE sy-uzeit+0(2) sy-uzeit+2(2)

INTO l_v_uzeit SEPARATED BY ':'.

CONCATENATE text-016 l_v_uzeit l_v_datum text-017

INTO l_v_log SEPARATED BY space.

PERFORM f_log_data USING space

l_v_log

space

CHANGING fp_it_log.

CLEAR wa_log.

APPEND wa_log TO fp_it_log.

ENDFORM. " f_start_process_log

*&---------------------------------------------------------------------*

*& Form f_end_process_log

*&---------------------------------------------------------------------*

* Process log end

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

* <--FP_IT_LOG Log internal table

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

FORM f_end_process_log CHANGING fp_it_log TYPE ty_t_log.

CLEAR wa_log.

APPEND wa_log TO fp_it_log.

PERFORM f_log_data USING space

text-018

space

CHANGING fp_it_log.

ENDFORM. " f_end_process_log

*&---------------------------------------------------------------------*

*& Form f_archive_file

*&---------------------------------------------------------------------*

* Archive the file in the archive directory

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

* -->FP_IT_DATA Raw file data

* -->FP_V_ARCPATH Archive Path

* -->FP_V_FILEPATH1 original File path

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

FORM f_archive_file USING fp_it_data TYPE ty_t_data

fp_v_arcpath TYPE char512

fp_v_filepath TYPE char512.

* Open the archive directory

OPEN DATASET fp_v_arcpath

FOR

OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc = 0.

* Put the file in the archive directory

LOOP AT fp_it_data INTO wa_data.

TRANSFER wa_data TO fp_v_arcpath.

ENDLOOP.

CLOSE DATASET fp_v_arcpath.

* Delete the file in the current location

DELETE DATASET fp_v_filepath.

ENDIF.

ENDFORM. " f_archive_file

*&---------------------------------------------------------------------*

*& Form f_update_archive_file

*&---------------------------------------------------------------------*

* Update the archive path in the internal table

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

* -->FP_V_ARCPATH text

* -->FP_V_LOGPATH text

* <--FP_IT_PATH text

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

FORM f_update_archive_file USING fp_v_funcproc TYPE rs38l_fnam

fp_v_filepath TYPE ZFILEPATH01

fp_v_arcpath TYPE char512

fp_v_logpath TYPE char512

fp_v_location TYPE char40

fp_wa_files TYPE ty_files

CHANGING fp_it_path TYPE ty_t_path.

* Update the path table

wa_path-funcproc = fp_v_funcproc.

wa_path-filepath = fp_v_filepath.

wa_path-arcpath = fp_v_arcpath.

wa_path-logpath = fp_v_logpath.

wa_path-location = fp_v_location.

wa_path-file = fp_wa_files.

APPEND wa_path TO fp_it_path.

ENDFORM. " f_update_archive_file

*&---------------------------------------------------------------------*

*& Form f_read_archive_data

*&--------#----------------------------------------------------------*

* Read the archive data

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

* -->FP_WA_PATH_ARCPATH Archive path

* <--FP_IT_DATA Raw data

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

FORM f_read_archive_data USING fp_wa_path_arcpath TYPE char512

CHANGING fp_it_data TYPE ty_t_data.

* Open the file and transfer the data into the internal table

OPEN DATASET fp_wa_path_arcpath

FOR

INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc = 0.

DO.

READ DATASET

fp_wa_path_arcpath

INTO wa_data .

IF sy-subrc = 0.

APPEND wa_data TO fp_it_data.

CLEAR wa_data.

ELSE.

EXIT.

ENDIF.

ENDDO.

ENDIF.

ENDFORM. " f_read_archive_data

*&---------------------------------------------------------------------*

*& Form f_append_log

*&---------------------------------------------------------------------*

* Append the log in the respective log path

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

* -->FP_IT_LOG Log internal table

* -->FP_WA_LOGPATH Log path

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

FORM f_append_log USING fp_it_log TYPE ty_t_log

fp_wa_path-logpath TYPE char512.

* Open the log directory

OPEN DATASET fp_wa_path-logpath

FOR APPENDING

IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc = 0.

* Put the file in the log directory

LOOP AT fp_it_log INTO wa_log.

TRANSFER wa_log TO fp_wa_path-logpath.

ENDLOOP.

ENDIF.

ENDFORM. " f_append_log*&---------------------------------------------------------------------*

*& Form f_lock_filepath

*&---------------------------------------------------------------------*

* Lock the file path in the custom table

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

* -->FP_WA_PATH_FILE Filepath

* <--FP_V_LOCK Lock key

*----------------------------------------------------------------------*FORM f_lock_filepath USING fp_wa_path_file TYPE ZFILEPATH01

CHANGING fp_v_lock TYPE char1.*Local variableDATA : l_v_filepath TYPE ZFILEPATH01.*Local work areaDATA : l_wa_fileproc TYPE zap_fileproc.*Check the file is in the processing tableSELECT filepath

FROM zap_fileproc

INTO l_v_filepath

UP TO 1 ROWS

WHERE filepath = fp_wa_path_file.

ENDSELECT.

IF sy-subrc <> 0.

l_wa_fileproc-mandt = sy-mandt.

l_wa_fileproc-filepath = fp_wa_path_file.

MODIFY zap_fileproc FROM l_wa_fileproc.

COMMIT WORK.

ELSE.

fp_v_lock = c_x.

ENDIF.

ENDFORM. " f_lock_filepath

  • No labels