Skip to Content
0
Former Member
Feb 25, 2007 at 10:10 AM

BDC output problem in amount conversion

40 Views

REPORT zgl_rept_automaticclearing_e_3

LINE-COUNT 64(1)

LINE-SIZE 260

NO STANDARD PAGE HEADING.

TYPES: BEGIN OF t_bsis,

bldat LIKE bsis-bldat,

budat LIKE bsis-budat,

bukrs LIKE bsis-bukrs,

waers LIKE bsis-waers,

monat LIKE bsis-monat,

blart LIKE bsis-blart,

hkont LIKE bsis-hkont,

belnr LIKE bsis-belnr,

bschl LIKE bsis-bschl,

wrbtr LIKE bsis-wrbtr,

  • pswbt LIKE bsis-pswbt,

valut LIKE bsis-valut,

END OF t_bsis.

  • Internal table declaration.

DATA: it_bsis TYPE TABLE OF t_bsis INITIAL SIZE 0 WITH HEADER LINE.

DATA: BEGIN OF it_docno OCCURS 0,

belnr LIKE bsis-belnr,

END OF it_docno.

DATA: BEGIN OF it_bseg OCCURS 0,

belnr LIKE bseg-belnr,

augbl LIKE bseg-augbl,

augdt LIKE bseg-augdt,

  • valut LIKE bseg-valut,

  • pswbt LIKE bseg-pswbt,

wrbtr LIKE bseg-wrbtr,

bschl LIKE bseg-bschl,

END OF it_bseg.

DATA: BEGIN OF it_final OCCURS 0,

blart LIKE bsis-blart,

budat LIKE bsis-budat,

bldat LIKE bsis-bldat,

AMT(20),

belnr LIKE bseg-belnr,

augdt LIKE bseg-augdt,

augbl LIKE bseg-augbl,

valut LIKE bsis-valut,

END OF it_final.

data: begin of it_ermsg occurs 0,

belnr like bsis-belnr,

ertxt(120),

end of it_ermsg.

DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE,

it_bdcmsgcoll LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.

  • varible decalration

data: v_ertxt(120),

V_AMT(20).

  • Selection-screen

PARAMETERS: p_bukrs LIKE bsis-bukrs DEFAULT '3100',

p_hkont LIKE bsis-hkont DEFAULT '101046',

p_cacno LIKE bsis-hkont DEFAULT '101047',

p_bldat LIKE bsis-bldat .

INITIALIZATION.

DATA: v_end_date LIKE sy-datum.

CALL FUNCTION 'LAST_DAY_OF_MONTHS'

EXPORTING

day_in = sy-datum

IMPORTING

last_day_of_month = v_end_date

EXCEPTIONS

day_in_no_date = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

p_bldat = v_end_date.

START-OF-SELECTION.

*DATA: V_AMT LIKE TCURC-waers VALUE 'USD'.

*WRITE itab-curr CURRENCY v_waers.

SELECT bldat

budat

bukrs

waers

monat

blart

hkont

belnr

bschl

  • pswbt

wrbtr

valut

FROM bsis

INTO TABLE it_bsis

WHERE bukrs EQ p_bukrs

AND hkont EQ p_hkont.

  • AND valut GE p_bldat.

  • delete it_bsis where belnr ='4200000072'.

*

IF NOT it_bsis[] IS INITIAL.

LOOP AT it_bsis.

PERFORM fill_screen_data.

CALL TRANSACTION 'F-04' USING bdcdata MODE 'N' UPDATE 'S'

MESSAGES INTO it_bdcmsgcoll.

IF sy-subrc EQ 0.

it_docno-belnr = it_bsis-belnr.

APPEND it_docno.

CLEAR it_docno.

ELSE.

perform error_msg_text.

it_ermsg-belnr = it_bsis-belnr.

it_ermsg-ertxt = v_ertxt.

append it_ermsg.

clear: it_ermsg, it_bdcmsgcoll.

endif.

REFRESH bdcdata.

CLEAR BDCDATA.

CLEAR it_bsis.

ENDLOOP.

ENDIF.

*SORT it_docno BY belnr.

*

IF NOT it_docno[] IS INITIAL.

SELECT belnr

augbl

augdt

  • valut

  • pswbt

wrbtr

bschl

INTO TABLE it_bseg

FROM bseg

FOR ALL ENTRIES IN it_docno

WHERE BELNR EQ it_docno-belnr.

*

ENDIF.

*

  • SORT it_bsis BY belnr.

SORT it_bseg BY BELNR.

*

IF NOT it_bseg[] IS INITIAL.

  • DELETE IT_BSEG WHERE BSCHL <> 40 AND BSCHL <> 50 OR WRBTR = 0.

LOOP AT it_bseg.

READ TABLE it_bsis WITH KEY belnr = it_bseg-BELNR.

IF IT_BSEG-BSCHL = 25.

V_AMT = IT_BSEG-WRBTR.

CONCATENATE V_AMT '-' INTO V_AMT.

ELSEIF IT_BSEG-BSCHL = 50.

V_AMT = IT_BSEG-WRBTR.

ENDIF.

IT_FINAL-BLART = IT_BSIS-BLART.

IT_FINAL-BUDAT = IT_BSIS-BUDAT.

IT_FINAL-BLDAT = IT_BSIS-BLDAT.

IT_FINAL-AMT = V_AMT.

IT_FINAL-BELNR = IT_BSis-BELNR.

IT_FINAL-AUGDT = IT_BSEG-AUGDT.

IT_FINAL-AUGBL = IT_BSEG-AUGBL.

IT_FINAL-VALUT = IT_BSIS-VALUT.

APPEND IT_FINAL.

CLEAR IT_FINAL.

ENDLOOP.

ENDIF.

top-of-page.

write : /1 'G/L Account No.', p_hkont.

write : /1 'Company Code ' , p_bukrs.

skip 2.

write :/3'DocumentType', 18 'posted on', 31'Document Date',

51 'amount', 66'DocumentNo',79 'clearing Date',

97 'clearingDocumentnumber',123 'Value date'.

end-of-selection.

IF NOT IT_FINAL[] IS INITIAL.

LOOP AT IT_FINAL.

WRITE:/7 IT_FINAL-BLART, 18 IT_FINAL-BUDAT, 31 IT_FINAL-BLDAT, 41 IT_FINAL-AMT, 66 IT_FINAL-BELNR, 82 IT_FINAL-AUGDT, 101 IT_FINAL-AUGBL,123 IT_FINAL-VALUT.

ENDLOOP.

ENDIF.

if not it_ermsg[] is initial.

loop at it_ermsg.

write:/ it_ermsg-belnr, IT_ERMSG-ERTXT.

endloop.

endif.

&----


*& Form fill_screen_data

&----


  • text

----


FORM fill_screen_data .

DATA: l_dat1(8),

l_dat2(8),

l_dat3(8),

s1(2),

s2(2),

s3(4).

clear v_amt.

DATA : p_amt TYPE p DECIMALS 2,

v_amt(15).

p_amt = it_bsis-wrbtr.

  • clear v_amt.

v_amt = p_amt.

REPLACE '.' IN v_amt WITH space.

CONDENSE v_amt.

  • DATA : p_amt TYPE p DECIMALS 2,

  • v_amt(15).

*

  • p_amt = it_bsis-wrbtr.

  • v_amt = p_amt.

*

  • SEARCH v_amt FOR '.'.

  • IF sy-subrc EQ 0.

  • CLEAR v_amt+sy-fdpos(1).

  • ENDIF.

  • CONDENSE v_amt.

  • WRITE : v_amt.

s1 = it_bsis-bldat+6(2).

s2 = it_bsis-bldat+4(2).

s3 = it_bsis-bldat+0(4).

CONCATENATE s2 s1 s3 INTO l_dat1.

s1 = it_bsis-budat+6(2).

s2 = it_bsis-budat+4(2).

s3 = it_bsis-budat+0(4).

CONCATENATE s2 s1 s3 INTO l_dat2.

s1 = it_bsis-valut+6(2).

s2 = it_bsis-valut+4(2).

s3 = it_bsis-valut+0(4).

CONCATENATE s2 s1 s3 INTO l_dat3.

PERFORM bdc_dynpro USING 'SAPMF05A' '0122'.

PERFORM bdc_field USING 'BDC_CURSOR'

'BKPF-WAERS'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=SL'.

PERFORM bdc_field USING 'BKPF-BLDAT'

l_dat1.

PERFORM bdc_field USING 'BKPF-BLART'

it_bsis-blart .

PERFORM bdc_field USING 'BKPF-BUKRS'

p_bukrs.

PERFORM bdc_field USING 'BKPF-BUDAT'

l_dat2.

PERFORM bdc_field USING 'BKPF-MONAT'

it_bsis-monat.

PERFORM bdc_field USING 'BKPF-WAERS'

it_bsis-waers.

PERFORM bdc_field USING 'FS006-DOCID'

'*'.

PERFORM bdc_dynpro USING 'SAPMF05A' '0710'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RF05A-XPOS1(03)'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=PA'.

PERFORM bdc_field USING 'RF05A-AGBUK'

p_bukrs.

PERFORM bdc_field USING 'RF05A-AGKON'

p_hkont.

PERFORM bdc_field USING 'RF05A-AGKOA'

'S'.

PERFORM bdc_field USING 'RF05A-XNOPS'

'X'.

PERFORM bdc_field USING 'RF05A-XPOS1(01)'

''.

PERFORM bdc_field USING 'RF05A-XPOS1(03)'

'X'.

PERFORM bdc_dynpro USING 'SAPMF05A' '0731'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RF05A-SEL01(01)'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=PA'.

PERFORM bdc_field USING 'RF05A-SEL01(01)'

it_bsis-belnr.

PERFORM bdc_dynpro USING 'SAPDF05X' '3100'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=AB'.

PERFORM bdc_field USING 'BDC_SUBSCR'

'SAPDF05X'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RF05A-ABPOS'.

PERFORM bdc_field USING 'RF05A-ABPOS'

'1'.

PERFORM bdc_dynpro USING 'SAPMF05A' '0700'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RF05A-NEWKO'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'RF05A-NEWBS'

'50'.

PERFORM bdc_field USING 'RF05A-NEWKO'

'101047'.

PERFORM bdc_dynpro USING 'SAPMF05A' '0300'.

PERFORM bdc_field USING 'BDC_CURSOR'

'BSEG-WRBTR'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BU'.

PERFORM bdc_field USING 'BSEG-WRBTR'

v_amt.

PERFORM bdc_field USING 'BSEG-VALUT'

l_dat3.

PERFORM bdc_field USING 'BDC_SUBSCR'

'SAPLKACB'.

PERFORM bdc_field USING 'DKACB-FMORE'

'X'.

PERFORM bdc_dynpro USING 'SAPLKACB' '0002'.

PERFORM bdc_field USING 'BDC_CURSOR'

'COBL-ANLN1'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTE'.

PERFORM bdc_field USING 'BDC_SUBSCR'

'SAPLKACB'.

  • PERFORM bdc_field USING 'BDC_OKCODE'

  • '=ENTE'.

  • PERFORM bdc_dynpro USING 'SAPMF05A' '0300'.

*

  • PERFORM bdc_field USING 'BDC_OKCODE'

  • '/01'.

  • PERFORM bdc_field USING 'BDC_OKCODE'

  • '=ENTE'.

ENDFORM. " fill_screen_data

&----


*& Form bdc_field

&----


  • text

----


  • -->FNAM text

  • -->FVAL text

----


FORM bdc_field USING fnam fval.

  • IF FVAL <> NODATA.

CLEAR bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

APPEND bdcdata.

  • ENDIF.

ENDFORM. "BDC_FIELD

&----


*& Form bdc_dynpro

&----


  • text

----


  • -->PROGRAM text

  • -->DYNPRO text

----


FORM bdc_dynpro USING program dynpro.

CLEAR bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = 'X'.

APPEND bdcdata.

ENDFORM. "BDC_DYNPRO

&----


*& Form error_msg_text

&----


form error_msg_text .

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = it_bdcmsgcoll-MSGID

LANG = sy-langu

NO = it_bdcmsgcoll-msgnr

V1 = it_bdcmsgcoll-MSGV1

V2 = it_bdcmsgcoll-MSGV2

V3 = it_bdcmsgcoll-MSGV3

V4 = it_bdcmsgcoll-MSGV4

IMPORTING

MSG = v_ertxt

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2

.

IF sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

endform. " error_msg_text

Problem aim facing :

1. amount conversion (output iam expecting 1,245 ) - iam getting 12.34

2. iam not able to display AUGDT AND AUGBL in line item.

Pls any one can help.