Skip to Content
0
Former Member
Dec 24, 2007 at 02:54 AM

Need help to sum up total amount in at end of.....endat!!! Please help

328 Views

Hi,

There is one program need to calculat the SUB-TOTAL AMOUNT FOR SAME DOCUMENT NUMBER.

Means: Need to sumup betrg for the same belnr.

QUESTION:

How can I write the sorce cord In AT END OF...ENDAT.

TO SUMUP THE AMOUNT FOR SAME DOCUMENT NUMBER.

Please help!!

Thanks.

Here is the sourc code.

-


DATA: BEGIN OF t OCCURS 0,

bukrs LIKE knb1-bukrs,

*<<<<< CR01

zuonr Like bsid-zuonr, "sort key "CR01

*>>>>> CR01

belnr LIKE bsid-belnr,

kunnr LIKE kna1-kunnr,

bldat LIKE bsid-bldat,

budat LIKE bsid-budat,

netdt LIKE bsega-netdt,

waers LIKE bsid-waers,

wrbtr LIKE bsid-wrbtr,

shkzg LIKE bsid-shkzg,

xblnr LIKE bsid-xblnr, "WD041005a

sgtxt LIKE bsid-sgtxt,

dmbtr LIKE bsid-dmbtr,

END OF t.

  • Description of Interface-record RECON

DATA: BEGIN OF s,

belnr(10), " document number

*<<<< CR01 STRAT ADD ZUONR

zuonr(10), "sort key " CR01

*>>>> CR01 END ADD ZUONR

filler1(1),

  • KUNNR(5), " customer no."WD290705a

kunnr LIKE kna1-kunnr, " customer no."WD290705a

filler2(1),

bldat(10), " date

filler3(1),

budat(10),

filler4(1),

netdt(10), " due date for payment

filler5(1),

betrg(14), " amount

filler6(1),

waers(3), " currency

filler7(1), " document field - blank

compcode(4), " company-code "fw070905

filler8(1), " comment - blank

sgtxt(50), " Text "INS MG020207

filler9(1),

kmmnt(30),

filler10(1),

vbeln(12) ,

filler11(1),

xblnr(16), "WD041005a hier Referenznr rein

filler12(1),

lifn2(11),

filler13(1), " remark - blank

dmbtr(14),

filler14(1),

twaer(3),

END OF s.

DATA: BEGIN OF outtab OCCURS 1000,

s LIKE s,

END OF outtab.

*<<<<< INS MG020207

TYPES: BEGIN OF ty_outalv,

belnr(10), " document number

*<<<< CR01 START ADD ZUONR

zuonr, " sort key " CR01

*>>>>CR01 END ADD AUONR

kunnr LIKE kna1-kunnr, " customer no."WD290705a

bldat(10), " date

budat(10), " posting date

netdt(10), " due date for payment

betrg(14), " amount

waers(3), " currency

compcode(4), " company-code "fw070905

sgtxt(30), " comment

kmmnt(30), " comment

vbeln(12), " delivery number

xblnr(16), "WD041005a hier Referenznr rein

lifn2(11), " customer number

dmbtr(14),

twaer(3), " currency company code

END OF ty_outalv.

DATA: gt_outalv TYPE STANDARD TABLE OF ty_outalv.

DATA: gs_outalv TYPE ty_outalv.

*>>>>> INS MG020207

DATA: l_date TYPE sy-datum.

DATA: g_date TYPE sy-datum.

DATA: g_budat TYPE bsik-budat.

*<<<< CR01 START ADD DATA STATEMENT

DATA: wk_belnr LIKE bsid-zuonr,

wk_x_belnr LIKE bsid-zuonr,

ZUONR LIKE BSID-ZUONR,

WRBTR LIKE BSID-WRBTR,

WK_ZUONR LIKE BSID-ZUONR,

WK_WRBTR LIKE BSID-WRBTR.

*>>>> CR01 END ADD DATA STATEMENT

DATA: l_it_bsik TYPE STANDARD TABLE OF bsik. "INS MG050706

DATA: l_wa_bsik TYPE bsik. "INS MG050706

TYPE-POOLS: slis. "INS MG020207

DATA: "INS MG020207

gt_fieldcat TYPE slis_t_fieldcat_alv, "INS MG020207

gs_layout TYPE slis_layout_alv, "INS MG020207

gs_fieldcat TYPE slis_fieldcat_alv. "INS MG020207

-


END-OF-SELECTION.

SORT t.

LOOP AT t.

AT NEW bukrs.

CLEAR anz_dl.

CLEAR htext-anzahl.

CLEAR htext-datei.

htext-text1 = ' records writen in file '.

CLEAR p_pfad.

CONCATENATE

i_pfad

'CU_CC'

t-bukrs

'_'

sy-datum+6(2)

sy-datum+4(2)

sy-datum(4)

'_'

sy-uzeit

'.txt'

INTO p_pfad.

CLEAR outtab.

REFRESH outtab.

REFRESH: gt_outalv. "INS MG020207

ENDAT.

  • IF t-shkzg = 'H'.

  • h_betrg = t-wrbtr * -1.

  • ELSE.

h_betrg = t-wrbtr.

h_dmbtr = t-dmbtr.

  • ENDIF.

s-filler1 = s-filler2 = s-filler3 = s-filler4 = s-filler5 = ';'.

s-filler6 = s-filler7 = s-filler8 = ';'.

s-filler9 = s-filler10 = s-filler11 = s-filler12 = s-filler13 = ';'.

s-filler14 = ';'.

s-belnr = t-belnr.

IF t-xblnr NE space. "WD041005a

s-xblnr = t-xblnr. "WD041005a

ELSE. "WD041005a

s-xblnr = t-belnr. "WD041005a

ENDIF. "WD041005a

WHILE s-xblnr(1) EQ '0'. "INS MG130606

SHIFT s-xblnr LEFT. "INS MG130606

ENDWHILE. "INS MG130606

WRITE t-kunnr TO s-kunnr NO-ZERO.

s-lifn2 = s-kunnr.

shift s-lifn2 RIGHT.

s-lifn2(1) = 'R'.

  • S-KUNNR = T-KUNNR+5(5).

s-bldat+2(1) = '/'.

s-bldat+5(1) = '/'.

s-bldat0(2) = t-bldat4(2).

s-bldat3(2) = t-bldat6(2).

s-bldat6(4) = t-bldat0(4).

s-budat+2(1) = '/'.

s-budat+5(1) = '/'.

s-budat0(2) = t-budat4(2).

s-budat3(2) = t-budat6(2).

s-budat6(4) = t-budat0(4).

s-netdt+2(1) = '/'.

s-netdt+5(1) = '/'.

s-netdt0(2) = t-netdt4(2).

s-netdt3(2) = t-netdt6(2).

s-netdt6(4) = t-netdt0(4).

s-waers = t-waers.

s-dmbtr = t-dmbtr.

s-sgtxt = t-sgtxt.

CLEAR s-twaer.

SELECT SINGLE waers INTO s-twaer

FROM t001

WHERE bukrs = t-bukrs.

IF h_betrg < 0.

hs_betrg+0(1) = '-'.

ELSE.

hs_betrg+0(1) = ' '.

ENDIF.

WRITE h_betrg CURRENCY t-waers TO hs_betrg+1 NO-GROUPING

NO-SIGN

LEFT-JUSTIFIED.

REPLACE ',' WITH '.' INTO hs_betrg.

WRITE hs_betrg TO s-betrg.

IF h_dmbtr < 0.

hs_betrg+0(1) = '-'.

ELSE.

hs_betrg+0(1) = ' '.

ENDIF.

WRITE h_dmbtr CURRENCY t-waers TO hs_betrg+1 NO-GROUPING

NO-SIGN

LEFT-JUSTIFIED.

REPLACE ',' WITH '.' INTO hs_betrg.

WRITE hs_betrg TO s-dmbtr.

s-compcode = t-bukrs. "fw070905

IF p_downl = 'X'.

MOVE s TO outtab-s.

APPEND outtab.

ADD 1 TO anz_dl.

ENDIF.

gs_outalv-belnr = s-belnr. "INS MG020207

*<<<< CR01 START ADD as_outalv-zuonr

gs_outalv-zuonr = s-zuonr. "CR01

*>>>> CR01 EDD ADD as_outalv-zuonr

gs_outalv-kunnr = s-kunnr. "INS MG020207

gs_outalv-bldat = s-bldat. "INS MG020207

gs_outalv-netdt = s-netdt. "INS MG020207

gs_outalv-betrg = s-betrg. "INS MG020207

gs_outalv-waers = s-waers. "INS MG020207

gs_outalv-compcode = s-compcode. "INS MG020207

gs_outalv-budat = s-budat. "INS MG020207

gs_outalv-sgtxt = s-sgtxt.

gs_outalv-kmmnt = s-kmmnt.

gs_outalv-vbeln = s-vbeln.

gs_outalv-xblnr = s-xblnr.

gs_outalv-lifn2 = s-lifn2.

gs_outalv-dmbtr = s-dmbtr.

gs_outalv-twaer = s-twaer.

APPEND gs_outalv TO gt_outalv. "INS MG020207

AT END OF bukrs.

WRITE anz_dl TO htext-anzahl.

WRITE p_pfad TO htext-datei.

CONDENSE htext.

IF p_downl = 'X'.

SKIP 2.

WRITE: / htext.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = p_pfad

filetype = 'ASC'

TABLES

data_tab = outtab

EXCEPTIONS

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

no_authority = 5

unknown_error = 6

header_not_allowed = 7

separator_not_allowed = 8

filesize_not_allowed = 9

header_too_long = 10

dp_error_create = 11

dp_error_send = 12

dp_error_write = 13

unknown_dp_error = 14

access_denied = 15

dp_out_of_memory = 16

disk_full = 17

dp_timeout = 18

file_not_found = 19

dataprovider_exception = 20

control_flush_error = 21

OTHERS = 22.

IF sy-subrc <> 0.

  • write: / 'Error creating File:', P_Pfad, sy-subrc.

MESSAGE e405 WITH text-002 p_pfad.

ENDIF.

ENDIF.

*<<<<< INS MG020207

IF p_alvd EQ 'X'.

PERFORM build_layout_data.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = sy-repid

i_structure_name = 'GT_OUTALV'

is_layout = gs_layout

it_fieldcat = gt_fieldcat[]

i_callback_top_of_page = 'TOP-OF-PAGE'

TABLES

t_outtab = gt_outalv.

ENDIF.

*>>>>> INS MG020207

ENDAT.

ENDLOOP.