cancel
Showing results for 
Search instead for 
Did you mean: 

Flat file Extraction

Former Member
0 Kudos
114

Hi friends

i have issue where . we need to load 120 sites pos data through flat files to cube every day . pos will send us different files for different stores . which are palced in the application server in a specific folder my problem and question s are.

1.is there a way that we can schedule the job in such a way that once the flat file for one site is done it has to automatically access second file , third file etc untill all files are fininshed.

2. there is condition we need to check before loading each file that the file is not duplicted when itis loaded .

3. is there any way that we can schedule that once the file which is been loaded in bw is delted automatically deleted from application servfer and stored in different folder for backup .so that there will be no duplicates files.

these are my issues . hope u all will help me with this issue . thanks for your time in advance .all answers are appericiated and rewarded. thankyou

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

You can do all fo this by abap program and unix command.

Here a sample:

REPORT ywdl_file_upload_scheduling

NO STANDARD PAGE HEADING

LINE-SIZE 80.

    • DDIC-Objects ********************************************************

TABLES: ywdl_file_sched.

    • VARIABLES ***********************************************************

DATA: v_count TYPE i,

v_fileok LIKE rlgrap-filename, "file FTPOK

v_file LIKE rlgrap-filename. "file

DATA: v_tmp LIKE rlgrap-filename. "file tmp

  • Internal table like mapping table with files' names

DATA: BEGIN OF i_file OCCURS 0,

file_name TYPE ywdl_file_sched-file_name,

icube TYPE ywdl_file_sched-icube,

path TYPE ywdl_file_sched-path,

eventid TYPE ywdl_file_sched-eventid,

eventparm TYPE ywdl_file_sched-eventparm,

END OF i_file.

  • GET PRINT PARAMETERS

DATA: params LIKE pri_params,

v_text LIKE pri_params-prtxt.

    • SELECTION SCREEN ****************************************************

PARAMETERS: p_target LIKE ywdl_file_sched-icube. "Data Target

PARAMETERS: p_ok(10) TYPE c. "File trigger

SELECTION-SCREEN: SKIP.

  • --- start - D_LT-002 --- *

*SELECT-OPTIONS: s_date FOR sy-datum.

*SELECT-OPTIONS: s_time FOR sy-uzeit.

*

*SELECTION-SCREEN: BEGIN OF BLOCK 001 WITH FRAME TITLE text-005.

*PARAMETERS: p_event LIKE ywdl_file_sched-eventid. "Event dependent

*PARAMETERS: p_param LIKE ywdl_file_sched-eventparm.

*PARAMETERS: p_wait TYPE i. "Time for scheduling

*SELECTION-SCREEN: END OF BLOCK 001.

  • --- end - D_LT-002 --- *

*Path and name for temporary file, when an upload process is active

PARAMETER p_tmp LIKE ywdl_file_sched-path

DEFAULT '/usr/sap/transfer/it/mi/'.

************************************************************************

  • S T A R T - O F - S E L E C T I O N *

************************************************************************

START-OF-SELECTION.

CLEAR i_file.

REFRESH i_file.

CLEAR v_count.

v_count = 1.

  • fill internal table

SELECT * FROM ywdl_file_sched

INTO CORRESPONDING FIELDS OF TABLE i_file

WHERE icube EQ p_target.

  • error during select

IF sy-subrc NE 0.

WRITE:/ text-001.

WRITE:/ text-002.

EXIT.

ENDIF.

SORT i_file BY file_name.

  • read file and trigger his event

PERFORM read_file.

END-OF-SELECTION.

************************************************************************

  • T O P - O F - P A G E *

************************************************************************

TOP-OF-PAGE.

WRITE: 'Date: ', sy-datum,

/ 'Time: ', sy-uzeit,

/ 'Program: ', 'YWDL_FILE_UPLOAD_SCHEDULING',

/ 'Data Target: ', p_target.

ULINE.

WRITE: /.

************************************************************************

  • R O U T I N E S *

************************************************************************

    • F O R M T R I G G E R _ E V E N T *****************************

&----


*& Form trigger_event

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM trigger_event USING _eventid

_eventparm.

CALL FUNCTION 'BP_EVENT_RAISE'

EXPORTING

eventid = _eventid

eventparm = _eventparm

  • TARGET_INSTANCE = ' '

EXCEPTIONS

bad_eventid = 1

eventid_does_not_exist = 2

eventid_missing = 3

raise_failed = 4

OTHERS = 5 .

IF sy-subrc <> 0.

WRITE: / text-006.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " trigger_event

    • F O R M R E A D _ F I L E ************************************

&----


*& Form read_file

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM read_file.

  • --- start - I_LT-002 --- *

  • check if tmp file exists

OPEN DATASET p_tmp.

  • if tmp file exists, then an upload process is active --> exit

IF sy-subrc EQ 0. "file tmp exists

EXIT.

ELSE. "file tmp doesn't exists

  • At this time we have full exclusive access

  • to start the upload process.

v_tmp = p_tmp.

  • --- end - I_LT-002 --- *

DO.

READ TABLE i_file INDEX v_count.

    • There are not any files to process untill now

IF sy-tabix EQ 0. "END OF TABLE

  • WRITE: text-003. "D_LT-001

  • --- start - D_LT-002 --- *

  • Check date and time for run

  • IF ( sy-uzeit IN s_time ) AND ( sy-datum IN s_date ).

  • wait a little

  • WAIT UP TO p_wait SECONDS.

*

  • trigger restart

  • PERFORM trigger_event USING p_event

  • p_param.

  • ENDIF.

  • --- end - D_LT-002 --- *

EXIT.

ENDIF.

    • FILE PATH + FTPOK

CONCATENATE i_file-path i_file-file_name p_ok INTO v_fileok.

CONDENSE v_fileok NO-GAPS.

CONCATENATE i_file-path i_file-file_name INTO v_file.

CONDENSE v_file NO-GAPS.

    • CHECK FILE EXIST

OPEN DATASET v_fileok.

    • TRIGGER OR ADD COUNT

IF sy-subrc NE 0. "no file found

v_count = v_count + 1.

CONTINUE.

ELSE. "file exists --> start upload

  • --- start - I_LT-002 --- *

  • create tmp file in order to lock the access to starting upload process

OPEN DATASET v_tmp FOR OUTPUT.

CLOSE DATASET v_tmp.

  • --- end - I_LT-002 *

  • GET PRINT PARAMETERS

PERFORM get_pri_param.

  • delete FTPOK

SUBMIT ywzx_unix_rename

WITH file = vfileok "inputfile

WITH _ddcv = 'X' "radiobutton delete

WITH _rdcv = space "radiobutton rename

TO SAP-SPOOL

SPOOL PARAMETERS params

WITHOUT SPOOL DYNPRO

AND RETURN.

  • trigger infopackage for upload

PERFORM trigger_event USING i_file-eventid

i_file-eventparm.

WRITE: text-004, i_file-file_name.

EXIT.

ENDIF.

    • CLOSE DATASET

CLOSE DATASET v_fileok.

ENDDO.

  • --- start - I_LT-002 --- *

ENDIF.

CLOSE DATASET p_tmp.

  • --- end - I_LT-002 --- *

ENDFORM. " read_file

    • F O R M G E T _ P R I _ P A R A M ****************************

&----


*& Form get_pri_param

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_pri_param.

CONCATENATE text-007 i_file-file_name p_ok INTO v_text.

CALL FUNCTION 'GET_PRINT_PARAMETERS'

EXPORTING

  • ARCHIVE_ID = C_CHAR_UNKNOWN

  • ARCHIVE_INFO = C_CHAR_UNKNOWN

  • ARCHIVE_MODE = C_CHAR_UNKNOWN

  • ARCHIVE_TEXT = C_CHAR_UNKNOWN

  • AR_OBJECT = C_CHAR_UNKNOWN

  • ARCHIVE_REPORT = C_CHAR_UNKNOWN

  • AUTHORITY = C_CHAR_UNKNOWN

  • COPIES = C_NUM3_UNKNOWN

cover_page = ' '

  • DATA_SET = C_CHAR_UNKNOWN

department = 'Leonardo MA'

  • destination = 'local'

expiration = 8

immediately = ' '

  • IN_ARCHIVE_PARAMETERS = ' '

  • IN_PARAMETERS = ' '

layout = 'X_PAPER'

line_count = 65

line_size = 220

list_name = 'YWZX_UNIX_RE'

list_text = v_text

mode = 'BATCH'

new_list_id = 'X'

no_dialog = 'X' "C_FALSE

receiver = 'BATCH1IT'

  • RELEASE = C_CHAR_UNKNOWN

  • REPORT = C_CHAR_UNKNOWN

  • SAP_COVER_PAGE = C_CHAR_UNKNOWN

  • HOST_COVER_PAGE = C_CHAR_UNKNOWN

  • PRIORITY = C_NUM1_UNKNOWN

  • SAP_OBJECT = C_CHAR_UNKNOWN

  • TYPE = C_CHAR_UNKNOWN

user = sy-uname

  • DRAFT = C_CHAR_UNKNOWN

  • ABAP_LIST = ' '

  • USE_ARCHIVENAME_DEF = ' '

IMPORTING

  • OUT_ARCHIVE_PARAMETERS =

out_parameters = params

  • VALID = valid

  • EXCEPTIONS

  • ARCHIVE_INFO_NOT_FOUND = 1

  • INVALID_PRINT_PARAMS = 2

  • INVALID_ARCHIVE_PARAMS = 3

  • OTHERS = 4

.

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. " get_pri_param

Regards

Message was edited by: Paolo Siniscalco