2005 Dec 02 12:01 AM
Hi,
I have to upload Vendor Master data from the application server using standard program RFBIKR00. For this I have written the following code:-
REPORT ZREPORT
NO STANDARD PAGE HEADING
MESSAGE-ID ZFI
LINE-COUNT 65
LINE-SIZE 120.
&----
*& TABLES
&----
Internal to store the list of files.
DATA : BEGIN OF T_LISTFILES OCCURS 0.
INCLUDE STRUCTURE SALFLDIR.
DATA: END OF T_LISTFILES.
Internal table to hold the external file data.
DATA: BEGIN OF T_INPUTFILE OCCURS 0,
LINE(1000) TYPE C,
END OF T_INPUTFILE.
&----
*& PROGRAM VARIABLES
&----
DATA: V_DIRFILES TYPE SALFILE-LONGNAME VALUE '/holdarchlogs/outbound',
V_FILENAME(128) TYPE C,
V_FILEPATH(256) TYPE C,
V_MSG(256) TYPE C.
----
*S T A R T - O F - S E L E C T I O N *
----
START-OF-SELECTION.
Perform to get the list of all the files in a specific directory of application server.
PERFORM GET_DIRECTORY_FILES.
Perform to process the logic
PERFORM PROCESS_FILES.
&----
*& Form GET_DIRECTORY_FILES
&----
Perform to get the list of all the files in a specific directory of application server
----
FORM GET_DIRECTORY_FILES .
CALL FUNCTION 'RZL_READ_DIR_LOCAL'
EXPORTING
NAME = V_DIRFILES
TABLES
FILE_TBL = T_LISTFILES
EXCEPTIONS
ARGUMENT_ERROR = 1
NOT_FOUND = 2
OTHERS = 3
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
SORT T_LISTFILES BY NAME.
CLEAR T_LISTFILES.
ENDIF.
ENDFORM. " GET_DIRECTORY_FILES
&----
*& Form PROCESS_FILES
&----
Perform to process the logic
----
FORM PROCESS_FILES .
LOOP AT T_LISTFILES .
DELETE T_LISTFILES WHERE NAME = '.' .
DELETE T_LISTFILES WHERE NAME = '..'.
CLEAR T_LISTFILES.
ENDLOOP.
Open the file
LOOP AT T_LISTFILES.
CONCATENATE V_DIRFILES '/' T_LISTFILES-NAME INTO V_FILEPATH.
OPEN DATASET V_FILEPATH FOR INPUT IN TEXT MODE ENCODING DEFAULT MESSAGE V_MSG.
WRITE: V_FILEPATH.
IF SY-SUBRC <> 0.
WRITE: 'File cannot be opened', V_MSG.
EXIT.
ENDIF.
Reading the file.
DO.
READ DATASET V_FILEPATH INTO T_INPUTFILE.
IF SY-SUBRC <> 0.
EXIT.
ELSE.
SUBMIT RFBIKR00 AND RETURN.
ENDIF.
APPEND T_INPUTFILE.
WRITE:/ T_INPUTFILE.
ENDDO.
Close the file.
CLOSE DATASET V_FILEPATH.
ENDLOOP.
Here when I am testing 3 info message come (breakpoint setup in the submit statement):-
1.) No such file or directory
2.) File could not be opened
3.) ...Editing was terminated.
So to test with a real time scenario... I created a .txt file with the structure of BGR00, BLFA1, BLFB1 this i uploaded in an internal table using GUI_UPLOAD and then transfered it to application server... my problem is that application server is not showing all the content of the .txt file that I created on my c: drive. For this I have written the following code:-
REPORT ZPCFILE_UNIX.
DATA: FILENAME1(100) value '/holdarchlogs/outbound/appsertestfile.txt',
FILENAME(100) value
'C:\Testfiles\AP-INT-001 TEST FILE.txt',
MSGS(256),
g_file type string.
DATA: BEGIN OF T_DATATAB OCCURS 0,
line(1000) type c,
END OF T_DATATAB.
G_FILE = FILENAME.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = G_FILE
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = ' '
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
IMPORTING
FILELENGTH =
HEADER =
TABLES
DATA_TAB = T_DATATAB
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
open file
OPEN DATASET FILENAME1 FOR OUTPUT IN TEXT MODE ENCODING DEFAULT MESSAGE MSGS.
IF SY-SUBRC <> 0.
WRITE: 'File could not be opened', MSGS.
ENDIF.
transfering data.
LOOP AT T_DATATAB.
TRANSFER T_DATATAB TO FILENAME1.
ENDLOOP.
Close file.
CLOSE DATASET FILENAME1.
Please tell me what is going wrong in the "SUBMIT RFBIKR00 AND RETURN" statement.
Thank You,
SB.
2005 Dec 02 1:34 AM
Try this...
SUBMIT rfbikr00 WITH ds_name = g_otfile
WITH fl_check = space
AND RETURN.
Let us know what you get....
2005 Dec 02 12:36 AM
you have to pass some parameters to RFBIKR00. You neeed at least the file name which is parameter RFBIFILE.
eg,
SUBMIT RFBIKR00 with rfbifile = ? AND RETURN.
Sam is correct: the parameter name is 'DS_NAME' not RFBIFILE.
Message was edited by: Neil Woodruff
2005 Dec 02 1:34 AM
Try this...
SUBMIT rfbikr00 WITH ds_name = g_otfile
WITH fl_check = space
AND RETURN.
Let us know what you get....
2005 Dec 02 1:35 AM
2005 Dec 02 4:02 AM
So long as your file is in the correct format, you do not need to submit it from this program. You can submit it directly giving it the filename and for preliminary runs, check off "Check file only".
Rob
2005 Dec 02 4:13 AM
Hi Rob,
Can you please explain this more ellaborately.
Thank You,
SB
2005 Dec 02 7:26 AM
Hi,
split you process in 2 parts:
1) migration of data: from source file to SAP structures (BLFA1, BLFB1,...) and transfer to target file
2) running rfbikr00 per job (sm36) with target file from 1)
regards Andreas
2005 Dec 02 2:12 PM
2005 Dec 02 4:39 PM
Hi,
The file in the application server is in the structure of BGR00, BLF00, BLFA1, BLFB1 (all of them as one source file).
The Specs clearly says the following:-
BGR00, BLF00, BLFA1 and BLFB1
The SAP standard structures for Batch Input will be used in the external file coming from source system:
1. BGR00 1 record per file
2. BLF00 1 record per vendor
3. BLFA1 1 record per vendor
4. BLFB1 1 record per vendor
So I have to read all the files in the current directory. One by one process the files by calling program RFBIKR00. Close the dataset and lastly move the file to archive directory. I am able to achieve the first part of the functionality. I have problem in the second part.
Thank You,
SB.
2005 Dec 02 4:51 PM
It is lot easier to use LSMW for this. Is that an option?
Object 0040, Method 0001 will use the same program RFBIKR00. It will save you the pains of mapping and creating the file and submitting the program RFBIKR00.
Srinivas
2005 Dec 02 4:56 PM
That seems a very awkward way to go about it. Normally all the records would be in one file; however, if you must do it this way, process all of the files in a separate program and use them to create an internal table. Then write that file to a <b>single</b> file on the app server. Finally submit RFBIKR00 with the new file as a parameter.
Rob
Ignore this. I misread your specs.
Message was edited by: Rob Burbank
2005 Dec 02 5:04 PM
Hi Srinivas,
As of now no... I need to find out solution by calling the RFBIKR00 program only.
Thank You,
SB.
2005 Dec 02 5:08 PM
What is the error you are getting now?
Did you change your submit statement?
2005 Dec 02 5:26 PM
Hi Sam,
Yes I did that & that has eliminated my first 2 errors ... In debug mode I see that control is going to Submit statement & I get the following message:-
Session 1: Special character for 'empty field'is /
Session 1 session name RBMST0000001 was opened
Session 1 session name RBMST0000001 was created
How should I cross check that the code has functioned correctly.
2005 Dec 02 6:07 PM
2005 Dec 02 5:22 PM
Here is your original program with modifications. Run this and let me know if you are still having problems.
REPORT zreport NO STANDARD PAGE HEADING MESSAGE-ID zfi
LINE-COUNT 65
LINE-SIZE 120.
*&------------------------------------------------*
*& TABLES
*&------------------------------------------------*
* Internal to store the list of files.
DATA : BEGIN OF t_listfiles OCCURS 0.
INCLUDE STRUCTURE salfldir.
DATA: END OF t_listfiles.
* Internal table to hold the external file data.
DATA: BEGIN OF t_inputfile OCCURS 0,
line(1000) TYPE c.
DATA: END OF t_inputfile.
*&----------------------------------------------*
*& PROGRAM VARIABLES
*&----------------------------------------------*
DATA: v_dirfiles TYPE salfile-longname
VALUE '/holdarchlogs/outbound',
v_filename(128) TYPE c,
v_filepath(256) TYPE c,
v_msg(256) TYPE c.
*-----------------------------------------------*
*S T A R T - O F - S E L E C T I O N *
*-----------------------------------------------*
START-OF-SELECTION.
* Perform to get the list of all the files in a specific directory of
*application server.
PERFORM get_directory_files.
* Perform to process the logic
PERFORM process_files.
*&----------------------------------------------*
*& Form GET_DIRECTORY_FILES
*&----------------------------------------------*
* Perform to get the list of all the files in a specific directory of
*application server
*-----------------------------------------------*
FORM get_directory_files .
CALL FUNCTION 'RZL_READ_DIR_LOCAL'
EXPORTING
name = v_dirfiles
TABLES
file_tbl = t_listfiles
EXCEPTIONS
argument_error = 1
not_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
* SORT T_LISTFILES BY NAME.
CLEAR t_listfiles.
ENDIF.
ENDFORM. " GET_DIRECTORY_FILES
*&--------------------------------------------------*
*& Form PROCESS_FILES
*&-------------------------------------------------*
* Perform to process the logic
*--------------------------------------------------*
FORM process_files .
DELETE t_listfiles WHERE name = space
OR name = '..'.
* open the file
LOOP AT t_listfiles.
CONCATENATE v_dirfiles
'/'
t_listfiles-name
INTO v_filepath.
OPEN DATASET v_filepath FOR INPUT IN TEXT MODE
ENCODING DEFAULT MESSAGE v_msg.
IF sy-subrc <> 0.
WRITE: 'File cannot be opened', v_msg.
*-- read the next file
CONTINUE.
ENDIF.
* Reading the file and appending the internal table to archive.
DO.
READ DATASET v_filepath INTO t_inputfile.
IF sy-subrc <> 0.
EXIT.
ENDIF.
APPEND t_inputfile.
WRITE:/ t_inputfile.
ENDDO.
*-- Close the file.
CLOSE DATASET v_filepath.
*-- if the file is read properly and the internal table is filled with
* the records of the file, then submit the standard program for this
* file
IF NOT t_inputfile[] IS INITIAL.
SUBMIT rfbikr00 AND RETURN.
ENDIF.
*-- download this file contents to the archive directory
*...........
*.......
*-- then delete the contents of this internal table to read the next
* file
REFRESH t_inputfile.
ENDLOOP.
ENDFORM.