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: 

Program in background mode failed

Former Member
0 Kudos
180

I have developed an customized report which basically uploads a file from server and perform computation against the data in SAP.

Tested ok when executed normally. But it fails to upload file when its set to background job.

Used 'Open Dataset'

Please advice.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
147

Hi Duxton

Can you post your code? Also can you check if the

file still exists on server by the time you are

executing in background.

Kind Regards

Eswar

9 REPLIES 9

Former Member
0 Kudos
148

Hi Duxton

Can you post your code? Also can you check if the

file still exists on server by the time you are

executing in background.

Kind Regards

Eswar

0 Kudos
147
    OPEN DATASET ZFNAME IN TEXT MODE.
    IF SY-SUBRC = 0.
      DO.
        READ DATASET ZFNAME INTO ZLINE LENGTH LEN.
        IF SY-SUBRC <> 0.
          EXIT.
        ENDIF.
        ITAB-LINE = ZLINE.
        APPEND ITAB. CLEAR ITAB.
      ENDDO.
    ENDIF.
    CLOSE DATASET ZFNAME.

Its a simple code, and i have checked that file existed during the scheduled time.

0 Kudos
147

Hi Duxton,

The only simplest answer to this is that maybe 'ZFNAME' has no value in it. Can you please hardcode the value and then try and let me know if still it fails.

Regards

Nishant

Former Member
0 Kudos
147

Hi

Couldnt find anything wrong with your code, for it to fail in background...can u post your complete code?

Regards,

Raj

0 Kudos
147
CALL FUNCTION 'WS_UPLOAD'
       EXPORTING
            FILENAME        = ZFNAME
            FILETYPE        = 'ASC'
       IMPORTING
            FILELENGTH      = RC
       TABLES
            DATA_TAB        = ITAB
       EXCEPTIONS
            FILE_OPEN_ERROR = 1
            OTHERS          = 2.

  IF SY-SUBRC <> 0 .
    DATA: LEN TYPE I.
    CLEAR ZLINE.
    OPEN DATASET ZFNAME IN TEXT MODE.
    IF SY-SUBRC = 0.
      DO.
        READ DATASET ZFNAME INTO ZLINE LENGTH LEN.
        IF SY-SUBRC <> 0.
          EXIT.
        ENDIF.
        ITAB-LINE = ZLINE.
        APPEND ITAB. CLEAR ITAB.
      ENDDO.
    ENDIF.
    CLOSE DATASET ZFNAME.
  ENDIF.

  IF ITAB[] IS INITIAL .
    ERR-FDATE = SDATE.
    ERR-REMARKS = "unable to find file".
    APPEND ERR.
  ENDIF.

This is the portion for uploading the file.

Anyway to debug when in backgroud?

0 Kudos
147
Hi Duxton

  While opening the file to read the data, use as
  OPEN DATASET ZFNAME <b>FOR INPUT</b> IN TEXT MODE.  
  I guess the default mode will be FOR OUTPUT.

  For debugging a background job, there are two options
  1. When the job is finished, go to SM37. Select the 
job, execute command JDBG in command field. A series of 
F7 need to be done until you reach your program. From 
then you can debug to see how the commands are executed.

  2. Place an infinite loop in the program, execute in 
background. Go to SM50, select the process. Go to menu
Program/Mode -> Program -> Debugging. Which will open 
your program in debugging mode, change the value to exit 
the infinite loop and proceed with other steps.

  Btb, can you check if you are using the same filename
for both foreground and background processing as the 
naming convention will be different for presentation 
server filename and application server filename.
Eg: 
Presentation Server: 'C:Eswar.txt'.
Application Server: '/usr/sap/Eswar.txt'.
     
  Hope your problem gets resolved.

Kind Regards
Eswar

0 Kudos
147

Good Your problem is already resolved. Am slow to respond.

Kind Regards

Eswar

anversha_s
Active Contributor
0 Kudos
147

hi,

Only work in the case of BDC.

please add this condition also.

IF sy-binpt IS NOT INITIAL.

sy-binpt = 1 when its a back ground job,

regards,

anver

0 Kudos
147

there is no BDC involved in the program

It merely compares the amount from the file against the amount in SAP table.