Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

using sFTP without XI to transfer a file to UNIX system

Former Member
0 Kudos

Hi,

I have a requirement in which we need to create a file and send it to 3rd party UNIX system.

We need to use sFTP(Secured File Transfer Protocol) for the same and XI is not involved in the scenario.

Pls help me with the steps involved to build the same.

regards,

teja.

1 ACCEPTED SOLUTION
4 REPLIES 4

0 Kudos

Hi pavan,

thanks for the inputs.

But in our scenario, we are not using I-Docs. we are just creating a flat file and placing it in the application server.

Now we need to move the file created by us to the 3rd party UNIX system and here XI is not involved.

So we need to move the file by some ABAP code without XI.

I think we can use FTP for this which is unsecured.

If anyone had a similar requirement earlier, please help me in solving this.

thanks,

teja.

Former Member
0 Kudos

&----


*& Report ZAXXPR_TO_APO

*&

&----


*&

*&

&----


&----


*& Report ZAXXPR_TO_APO

*&

&----


*& Author: Aveek Ghose

*&

&----


REPORT ZAXXPR_TO_APO.

*Data declarations

include zaxxpr_to_apo_sign_top.

*Subroutines

include zaxxpr_to_apo_sign_forms.

----


  • SELECTION SCREEN *

----


SELECTION-SCREEN: BEGIN OF BLOCK blk1

WITH FRAME TITLE text-001. "Selection Options

SELECTION-SCREEN SKIP 1.

PARAMETERS : p_file TYPE char200.

SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN: END OF BLOCK blk1.

----


  • 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 file

  • PERFORM 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 tabe

PERFORM 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 file

IF 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 log

PERFORM 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.

*Selection texts

*----


  • P_FILE Filepath

-


Code listing for: ZAXXPR_TO_APO_SIGN_TOP

Description: Include ZAXXPR_TO_APO_SIGN_TOP

-


&----


*& Include ZAXXPR_TO_APO_SIGN_TOP

&----


*Types declarations

TYPES : 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 table

TYPES : BEGIN OF ty_direct,

direct TYPE char50,

END OF ty_direct.

*types for the ftp command result internal table

TYPES : BEGIN OF ty_result,

text TYPE char512,

END OF ty_result.

*types for the reterieved files

TYPES : BEGIN OF ty_files,

file TYPE char200,

END OF ty_files.

*types for the data

TYPES : BEGIN OF ty_data,

data TYPE char2000,

END OF ty_data.

*types for the log data

TYPES : BEGIN OF ty_log,

text TYPE char2000,

END OF ty_log.

**types for the lock object table

TYPES : BEGIN OF ty_locobj.

include structure zap_lockobj.

TYPES : END OF ty_locobj.

*types for the archive and log filepath

types : begin of ty_path,

funcproc type rs38l_fnam,

filepath type ZFILEPATH,

arcpath type char512,

logpath type char512,

location type char40,

file type char200,

end of ty_path.

*Internal table declarations

DATA : 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 declarations

DATA : 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 declaration

TYPES : 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 decleration

DATA : v_cmd(512) TYPE c,

l_cmd1(150) TYPE c,

v_handle TYPE i,

v_filepath TYPE ZFILEPATH,

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 declarations

CONSTANTS : 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'.

-


Code listing for: ZAXXPR_TO_APO_SIGN_FORMS

Description: Include ZAXXPR_TO_APO_SIGN_FORMS

-


&----


*& Include ZAXXPR_TO_APO_SIGN_FORMS

&----


FORM f_ftp_connection .

*Local variable declarations

DATA : 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 char200

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 char200

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 ZFILEPATH

CHANGING fp_v_fiseq TYPE char1

fp_v_funproc TYPE rs38l_fnam

fp_it_log TYPE ty_t_log.

  • Local variable

DATA : l_v_fityp TYPE char4,

l_v_date TYPE sy-datum,

l_v_date1 TYPE char4.

  • Add the log

PERFORM f_log_data USING space

space

space

CHANGING fp_it_log.

  • Append the file name to the log table

CLEAR 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 char200

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 variable

DATA : l_v_log TYPE char512,

l_v_datum TYPE char10,

l_v_uzeit TYPE char8.

  • Build the date format

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

INTO l_v_datum SEPARATED BY c_slash.

  • Build the time format

CONCATENATE sy-uzeit0(2) sy-uzeit2(2) sy-uzeit+4(2)

INTO l_v_uzeit SEPARATED BY ':'.

  • Build the log table

CONCATENATE 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 char200

fp_wa_direct TYPE ty_direct

fp_wa_files TYPE ty_files

CHANGING fp_v_filepath TYPE ZFILEPATH.

*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 char200

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 char200

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-datum0(4) sy-datum4(2) sy-datum+6(2)

INTO l_v_datum SEPARATED BY c_slash.

*Build the time format

CONCATENATE sy-uzeit0(2) sy-uzeit2(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-datum4(2) sy-datum6(2) sy-datum+2(2)

INTO l_v_datum SEPARATED BY c_slash.

  • Build the time format

CONCATENATE sy-uzeit0(2) sy-uzeit2(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 ZFILEPATH

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 ZFILEPATH

CHANGING fp_v_lock TYPE char1.

*Local variable

DATA : l_v_filepath TYPE ZFILEPATH.

*Local work area

DATA : l_wa_fileproc TYPE zap_fileproc.

*Check the file is in the processing table

SELECT 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

-


Former Member
0 Kudos

Hi Teja,

though your question is answered , i want to make it very simple manner

I have the same requirement. please the standard program RSFTP002. when you execute this program on the selection screen

give the following

User : userid

Password: ************

Host:

Command 1 : ascii (keep it as it is)

Command 2 : get testdata4.txt ; /usr/interface/data/zz/testdat4.txt

Command 3

RFC Destination : SAPFTPA (default)

Compress:N (default)

userid id , PW and host are the FTP site/folder to log into that.

command 1 : ascii mode of transfer a file from FTP to Unix

you just need basic FTP commands for that see this http://www.cs.colostate.edu/helpdocs/ftp.html

regards,

Sambasiva

you can delete file in FTP, place a file in FTP site...

Hope this will help you ....