‎2007 Oct 03 3:29 PM
REPORT YBP_3.
TABLES: MARD.
TYPES : BEGIN OF TAB,
TTYPE(3) TYPE C,
ORDNO(20) TYPE C,
SEQNO(6) TYPE N,
MATNR(50) TYPE C,
EXPQT(9) TYPE N,
END OF TAB.
DATA : LT_TAB TYPE STANDARD TABLE OF TAB WITH HEADER LINE,
LS_TAB TYPE TAB.
TYPES : BEGIN OF T_MARD,
MATNR TYPE MARD-MATNR,
MATNR2 TYPE MARD-MATNR,
END OF T_MARD.
DATA : LT_MARD TYPE STANDARD TABLE OF T_MARD WITH HEADER LINE,
LS_MARD TYPE T_MARD.
PARAMETER : P_PLANT TYPE MARD-WERKS DEFAULT '1204',
P_STLOC TYPE MARD-LGORT DEFAULT '6000',
P_FLPTH(90) TYPE C DEFAULT '/interfaces/unity_WMS/cdc/outbound/reqorder11.txt'.
SELECT MATNR FROM MARD INTO TABLE LT_MARD WHERE WERKS = P_PLANT AND LGORT = P_STLOC.
SORT LT_MARD BY MATNR.
LOOP AT LT_MARD INTO LS_MARD.
AT NEW MATNR.
LS_TAB-TTYPE = 'AUD'.
LS_TAB-ORDNO = 'ORDER1'.
LS_TAB-SEQNO = SY-TABIX.
LS_TAB-EXPQT = '999999999'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = LS_MARD-MATNR
IMPORTING
OUTPUT = LS_MARD-MATNR2.
LS_TAB-MATNR = LS_MARD-MATNR2.
ENDAT.
APPEND LS_TAB TO LT_TAB.
ENDLOOP.
OPEN DATASET P_FLPTH FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC eq 0.
LOOP AT LT_TAB INTO LS_TAB.
TRANSFER LS_TAB TO P_FLPTH.
ENDLOOP.
CLOSE DATASET P_FLPTH.
Else.
LEAVE PROGRAM.
ENDIF.
Hello Gurus,
The above code is syntactically correct. But the sy-subrc is not equal to zero.
There is a problem in the line open dataset. Can anyone help me out what is wrong in my code.
Regards,
Balu
‎2007 Oct 03 3:30 PM
Go to AL11 transaction and check the path specified foe Application server file is correct. That can be a problem.
‎2007 Oct 03 3:34 PM
The path is correct Ashish.
When I debug the code, the sy-subrc is not equal to zero.
Regards,
Balu
‎2007 Oct 03 3:37 PM
If file path is correct, check if your user id has permission to write on Application server. You need to confirm this from your basis team.
‎2007 Oct 03 3:55 PM
open dataset returns sy-subrc in the following way
The addition FOR INPUT opens the file for reading. By default, the file pointer is set at the start of the file. If the file specified does not exist, sy-subrc is set to 8.
The addition FOR OUPUT opens the file for writing. If the specified file already exists, its content is deleted. If the file specified does not exist, it is created. Read access is also permitted.
The addition FOR APPENDING opens the file for appending. If the file specified already exists, it is opened and the file pointer is set at the end of the file. If the file specified does not exist, it is created. Attempted read access to a file opened with FOR APPENDING with the statement READ DATASET fails, and returns the value 4 for sy-subrc.
The addition FOR APPENDING opens the file for appending. If the file specified already exists, it is opened and the file pointer is set at the end of the file. If the file specified does not exist, it is created. Attempted read access to a file opened with FOR APPENDING with the statement READ DATASET fails, and returns the value 4 for sy-subrc.
Now since you have used output, that means even if ur file does not exist it will be created, What u need to do is check the mapping of the path in AL11 that you have mentioned in P_FLPTH.
‎2007 Oct 03 3:59 PM
Hi everyone.
Thanks for all the replies.
I declared the filepath as data element instead of selection parameter and it is working fine.
I dont know if that was the issue but it is working now.
Regards,
Balu
‎2007 Oct 03 4:20 PM
As I said, it is to do with the parameter declaration which in your case always translates the values to upper case. Please see my previous response. You can define the parameter as RLGRAP-FILENAME then also it will work.
‎2007 Oct 03 9:17 PM
Thanks Srinivas.
Points assigned to you.
Hello Gurus,
I have one more question.
I want get a message once the file has been uploaded to the application server.
I mean if I schedule this as a batch job, is there any way I get write a message in the spool list that it has been uploaded or not uploaded.
Also can you tell me how I can display the messages using message keyword.
I want to try both these options.
Regards,
Balaji
‎2007 Oct 03 9:34 PM
Here is a pseudo code for what you are looking for-
OPEN DATASET P_FLPTH FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC eq 0.
LOOP AT LT_TAB INTO LS_TAB.
TRANSFER LS_TAB TO P_FLPTH.
ENDLOOP.
CLOSE DATASET P_FLPTH.
<b>if sy-batch = 'X'.
write:/ 'File uploaded successfully'.
else.
message sXXX with 'File uploaded successfully'.
endif.</b>
Else.
if sy-batch = 'X'.
write:/ 'Error in File upload'.
else.
message sxxx with 'Error in File upload'.
endif.
LEAVE PROGRAM.
ENDIF.
‎2007 Oct 03 9:34 PM
Here is a pseudo code for what you are looking for-
OPEN DATASET P_FLPTH FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC eq 0.
LOOP AT LT_TAB INTO LS_TAB.
TRANSFER LS_TAB TO P_FLPTH.
ENDLOOP.
CLOSE DATASET P_FLPTH.
<b>if sy-batch = 'X'.
write:/ 'File uploaded successfully'.
else.
message sXXX with 'File uploaded successfully'.
endif.</b>
Else.
<b>if sy-batch = 'X'.
write:/ 'Error in File upload'.
else.
message sxxx with 'Error in File upload'.
endif.</b>
LEAVE PROGRAM.
ENDIF.
‎2007 Oct 04 3:31 PM
Thanks Ashish.
Points assigned.
I have one more question, it works fine if I create a background job. It creates the message in the spool list.
Is there any way I get the message if I run in foreground. Do I need to use message key word?
Regards,
Balu
‎2007 Oct 04 3:34 PM
Yes - if you see code mentioned here -
if sy-batch = 'X'.
write:/ 'File uploaded successfully'.
else.
<b>message sXXX with 'File uploaded successfully'.</b>
endif.
Else.
if sy-batch = 'X'.
write:/ 'Error in File upload'.
else.
<b>message sxxx with 'Error in File upload'.</b>
endif.
Either you can display a message in foreground (as i have shown above) or you can write a message using WRITE statement, which will be shown after program executes as report output.
‎2007 Oct 04 4:09 PM
Ashish,
Does the code you gave work for foreground also?
Because I dont see any message if I execute the program. It just goes to selection screen and then if I execute it just returns back to the code. And I see the file got generated in AL11.
Do I need to change anything in order to display the message in foreground.
Regards,
Balu
‎2007 Oct 04 4:11 PM
I just gave an example of message with XXX. You need to assign proper message class and message id in order to work.
Please check once in debug mode if this part gets executed.
‎2007 Oct 04 4:15 PM
‎2007 Oct 03 3:37 PM
Hi,
Please check with BASIS folk perhaps you don't have authorization to access and write a file into the corresponding directory of application server (your file path).
Regards,
Ferry Lianto
‎2007 Oct 03 3:39 PM
HI,
Take P_FLPTH as rlgrap-filename,
P_FLPTH LIKE rlgrap-filename.
And also look at the path you have mentioned here, the path should be case sensitive, so please make sure that you have given the correct path
Regards
Sudheer
‎2007 Oct 03 3:41 PM
Add LOWER CASE statement to your P_FLPATH definition. What it does is it will retain the uppercase and lowercase letters as it is. Otherwise it will be all in uppercase and that is not a valid path in some operating systems. If the path is case sensitive, you can preserve the case using that option.
If that doesn't solve the problem, then you don't have the necessary authorization to create files in that directory.