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: 

not giving a Consistent Output from SM37

Former Member
0 Kudos

Hi freinds,

I have schedule the following program as a batch job, but it's not giving me a consistent output. That means it's not giving me the expected spool request everytime it runs. I have schedule this to run hourly basis.

Here is the program.

Pls help me to solve this out.

Regards

Thanura

REPORT ZTM_DOWNLOAD_INVDATA.

TYPES : BEGIN OF wa,

bukrs LIKE vbrk-bukrs, "Company Code

vbeln LIKE vbrk-vbeln, " Invoice No

posnr LIKE vbrp-posnr, " item no

fkdat LIKE vbrk-fkdat, " Date

kunag LIKE vbrk-kunag, " Sold to party Customer

matnr LIKE vbrp-matnr, " Material

fkimg LIKE vbrp-fkimg, " Billed qty

charg LIKE vbrp-charg, " expiry

knumv LIKE vbrk-knumv, "Number of the document condition

KWERT LIKE konv-KWERT, " invoice price

KWERT1 LIKE konv-KWERT, " invoice discount

END OF wa.

----


  • INTERNAL TABLE Begin with IT *

----


TABLES: vbrk.

DATA : it_sales TYPE STANDARD TABLE OF wa,

wa_sales TYPE wa.

RANGES : r_bwart FOR konv-kschl.

sy-batch = 'X'.

PERFORM f001_getdata.

*&----


*

*& Form F001_GETDATA

*&----


*

FORM f001_getdata .

DATA: w_time(2) TYPE n,

w_timestr(6) TYPE c.

Data: p_bukrs LIKE vbrk-bukrs,

p_fkdat LIKE vbrk-fkdat.

w_time = sy-uzeit(2).

w_time = w_time - 1.

CONCATENATE '%' w_time '%' INTO w_timestr.

  • Discount condition list - 3100

r_bwart-sign = 'I'. r_bwart-option = 'EQ'. r_bwart-low = 'ZKMC'.

APPEND r_bwart TO r_bwart.

r_bwart-sign = 'I'. r_bwart-option = 'EQ'. r_bwart-low = 'ZKMG'.

APPEND r_bwart TO r_bwart.

r_bwart-sign = 'I'. r_bwart-option = 'EQ'. r_bwart-low = 'ZMGN'.

APPEND r_bwart TO r_bwart.

r_bwart-sign = 'I'. r_bwart-option = 'EQ'. r_bwart-low = 'ZCMG'.

APPEND r_bwart TO r_bwart.

r_bwart-sign = 'I'. r_bwart-option = 'EQ'. r_bwart-low = 'ZCDP'.

APPEND r_bwart TO r_bwart.

p_fkdat = sy-datum.

  • p_fkdat = '20050907'.

p_bukrs = '3100'.

SELECT abukrs avbeln bposnr afkdat akunag bmatnr bfkimg bcharg

a~knumv

FROM vbrk AS a

INNER JOIN vbrp AS b ON bvbeln = avbeln

INTO CORRESPONDING FIELDS OF TABLE it_sales

WHERE

a~bukrs = p_bukrs AND

fkdat = p_fkdat

  • fkdat between p_fkdat-low and p_fkdat-high .

AND a~erzet LIKE w_timestr.

DATA :w_KWERT LIKE konv-KWERT,

w_KWERT1 LIKE konv-KWERT.

LOOP AT it_sales INTO wa_sales.

  • Invoice price

SELECT SINGLE KWERT INTO w_KWERT

FROM konv

WHERE knumv = wa_sales-knumv

AND kschl = 'PR00'

AND kposn = wa_sales-posnr.

wa_sales-KWERT = w_KWERT.

MODIFY TABLE it_sales FROM wa_sales

TRANSPORTING KWERT.

  • invoice discount

SELECT SINGLE KWERT INTO w_KWERT1

FROM konv

WHERE knumv = wa_sales-knumv

AND kschl IN r_bwart

AND kposn = wa_sales-posnr.

wa_sales-KWERT1 = w_KWERT1.

MODIFY TABLE it_sales FROM wa_sales

TRANSPORTING KWERT1.

CLEAR wa_sales.

w_KWERT = 0.

w_KWERT1 = 0.

ENDLOOP.

DATA f_filename TYPE string.

DATA: rec(950) TYPE c,

v_line LIKE LINE OF it_sales,

w_fkimg TYPE string,

w1_kbetr TYPE string,

w2_kbetr TYPE string.

.

  • For Spool request to be Generated

NEW-PAGE.

f_filename = '/usr/sap/DBI/INVD.txt'.

OPEN DATASET f_filename FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc = 0.

  • LOOP AT it_sales INTO v_line.

LOOP AT it_sales INTO wa_sales.

Clear rec.

rec(950) = v_line(56).

w_fkimg = wa_sales-fkimg.

w1_kbetr = wa_sales-KWERT.

w2_kbetr = wa_sales-KWERT1.

*

Concatenate wa_sales-bukrs ',' wa_sales-VBELN ',' wa_sales-kunag ','

wa_sales-fkdat ',' wa_sales-matnr ',' w_fkimg ',' w1_KBETR ','

wa_sales-charg ',' w2_kbetr

into rec.

Write rec.

COMMIT WORK.

TRANSFER rec TO f_filename.

ENDLOOP.

ENDIF.

NEW-PAGE PRINT OFF.

CLOSE DATASET f_filename.

ENDFORM. " F001_GETDATA

18 REPLIES 18

Former Member
0 Kudos

Hi,

Two things you need to note is that,

1. In your program there is nothing being written to the SPOOL, instead to a file

hence nothing will show in the spool.

2. Every time the file is written the MODE is OUTPUT only,

which would over write the existing file every time.

use APPENDING along with it.

Regards,

Samson Rodrigues.

0 Kudos

Hi,

How to use APPENDING in the open dataset.

Could u pls show me how to use it.?

Regards

Thanura

0 Kudos

Hi,

OPEN DATASET f_filename FOR APPENDING IN TEXT MODE ENCODING DEFAULT.

evrytime it will append new data to existing file and it wont overwrite the file.

Regards,

Naveen

0 Kudos

Hi,

My requirement is to overwrite the text file every time it runs with the new data.

Hope u understand the program. It downloads every hour invoice data. so the text fiel should contain new data every hour it runs.

Pls help me to solve this out.

REgards

Thanura

0 Kudos

Hi,

Then whatever have mentioned earlier was correct.

Can u tell me what exact problem u r facing.? (be specific)

Spool will be craeted only if ur program is going to display output(like reports/scripts/..) . In ur case u r writing the data to Application server. and hence no spool will be cretaed . But u can check the data in Appl server in the respective file.

Rvert back ..

Regards,

Naveen

0 Kudos

Hi,

Whtever the commands which u r using like:

  • For Spool request to be Generated

NEW-PAGE., NEW_PAGE print OFF...

will come into effect only if ur using the WRITE statements i.e when u r displaying the output like reports, but in ur case as ur craeting the data in application server , there will be no Page breaks....

Revrt back.

Regards,

Naveen

0 Kudos

Hi ,

Write rec statement allows me to display the output. that means when it is running in bg it should create the spool.

My issue is sometims it giving the spool sometimes not, when i run it on bg. that's my problem

Regards

Thanura

0 Kudos

Hi,

Yes u r correct . It shud cretae spool.

Can u tell me, is it for the same test case, spool is sometimes cretaed and sometimes not?

Have u checked, when spool is not cretaed, app server file is blank.

i mean might be no data is being selected and hence no spool.

Rvert back ,

Regards,

Naveen

0 Kudos

Hi,

You can use both statements parallely like,

WRITE ........

TRANSFER ......... TO FILE.

but if there is no data in the internal table then

there will be no data in the SPOOL or FILE.

please check your internal table before writing

to spool like this,

data int_itab type i.

describe table itab lines int_itab.

IF int_itab lt 1.

write:/ 'NO DATA'.

ELSE.

<write data .........>

ENDIF.

0 Kudos

Hi

if no data been select for the internal table, the text file contain the previous hour data. it is not blank.

Regards

Thanura

0 Kudos

Hi,

But it should not...let it be , i wonder y this is happening...

try this way,

In ur coding....

IF sy-subrc = 0.

  • LOOP AT it_sales INTO v_line.

LOOP AT it_sales INTO wa_sales.

Clear rec.

rec(950) = v_line(56).

w_fkimg = wa_sales-fkimg.

w1_kbetr = wa_sales-KWERT.

w2_kbetr = wa_sales-KWERT1.

*

Concatenate wa_sales-bukrs ',' wa_sales-VBELN ',' wa_sales-kunag ','

wa_sales-fkdat ',' wa_sales-matnr ',' w_fkimg ',' w1_KBETR ','

wa_sales-charg ',' w2_kbetr

into rec.

Write rec.

COMMIT WORK.

ENDIF <----


insert here

TRANSFER rec TO f_filename.

ENDLOOP.

ENDIF. <----


comment it

Rvert back ,

Regards,

Naveen

0 Kudos

Hi,

Can't do this. This giving me a compilation error.

Regards

Thanura

Former Member
0 Kudos

Hi,

1 more thing ,

As o/p will start from new page, its not necessary to mention this, unless based on some condition (after some 10 lines) if u want to have new page then u can mention, but for time being commen this,,,, and lets check it out

  • For Spool request to be Generated

NEW-PAGE. <----


comment this

f_filename = '/usr/sap/DBI/INVD.txt'.

OPEN DATASET f_filename FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc = 0.

  • LOOP AT it_sales INTO v_line.

LOOP AT it_sales INTO wa_sales.

Clear rec.

rec(950) = v_line(56).

w_fkimg = wa_sales-fkimg.

w1_kbetr = wa_sales-KWERT.

w2_kbetr = wa_sales-KWERT1.

*

Concatenate wa_sales-bukrs ',' wa_sales-VBELN ',' wa_sales-kunag ','

wa_sales-fkdat ',' wa_sales-matnr ',' w_fkimg ',' w1_KBETR ','

wa_sales-charg ',' w2_kbetr

into rec.

Write rec.

COMMIT WORK.

TRANSFER rec TO f_filename.

ENDLOOP.

ENDIF.

NEW-PAGE PRINT OFF.

CLOSE DATASET f_filename.

ENDFORM. " F001_GETDATA

Regards,

Naveen

0 Kudos

Hi Guys,

I have done every thing u said. But still the problem remain same. What can I do??

Regards

Thanura

0 Kudos

Hi,

Could you paste the entire program here, it would be much easier,

and also what is the ERROR displayed.

Regards,

Samson Rodrigues.

0 Kudos

Hi Tanura,

Did u debug the code when it being executed in b/g?

(tcode : JDBG)

i guess u already did this ...

Revert back

Rgerads,

Naveen

0 Kudos

Hi,

I have paste the entire code when I posting the problem. U can find it from the first message.

And also, yes I did the debuging and when I doing it it always scuess. That means it creates the text file always when I am debuging.

Regards

Thanura

Former Member
0 Kudos

m.,