Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

not giving a Consistent Output from SM37

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

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question