Skip to Content
0
Jul 05, 2006 at 05:44 AM

Please comment on my code(shall I use field-symbol or header line)

23 Views

Hello experts,

In my select statement below, the one that I am getting single records from BKPF and putting it in an internal table with a field-symbol assigned. Is there any loopheloes/mistakes that I am doing here?Below is my code guys:

DATA: lv_age_of_rec TYPE p.

LOOP AT it_final ASSIGNING <fs_final>.

  • get records from BKPF

SELECT SINGLE bukrs belnr gjahr budat bldat xblnr bktxt FROM bkpf

INTO (bkpf-bukrs, bkpf-belnr, bkpf-gjahr, <fs_final>-budat,

<fs_final>-bldat, <fs_final>-xblnr, <fs_final>-bktxt)

WHERE bukrs = <fs_final>-bukrs

AND belnr = <fs_final>-belnr

AND gjahr = <fs_final>-gjahr.

  • if <fs_final>-shkzg = 'H', multiply dmbtr(amount in local currency)

  • by negative 1

IF <fs_final>-shkzg = 'H'.

<fs_final>-dmbtr = <fs_final>-dmbtr * -1.

ENDIF.

  • combine needed data to get long text

CONCATENATE: <fs_final>-bukrs <fs_final>-belnr

<fs_final>-gjahr <fs_final>-buzei

INTO it_thead-tdname.

CALL FUNCTION 'READ_TEXT'

EXPORTING

client = sy-mandt

id = '0001'

language = sy-langu

name = it_thead-tdname

object = 'DOC_ITEM'

  • ARCHIVE_HANDLE = 0

  • LOCAL_CAT = ' '

  • IMPORTING

  • HEADER =

TABLES

lines = it_lines

EXCEPTIONS

id = 1

language = 2

name = 3

not_found = 4

object = 5

reference_check = 6

wrong_access_to_archive = 7

OTHERS = 8.

  • IF sy-subrc <> 0.

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

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

  • ENDIF.

  • if successful, split long text into start and end date

IF sy-subrc = 0.

READ TABLE it_lines TRANSPORTING tdline.

IF sy-subrc = 0.

SPLIT it_lines-tdline AT '-' INTO

<fs_final>-s_dat <fs_final>-e_dat.

ENDIF.

ENDIF.

  • get vendor name

SELECT SINGLE name1 FROM lfa1

INTO <fs_final>-name1

WHERE lifnr = <fs_final>-lifnr.

lv_age_of_rec = p_budat - <fs_final>-budat.

  • condition for age of deposits

IF lv_age_of_rec < 30.

<fs_final>-amount1 = <fs_final>-dmbtr.

ELSEIF lv_age_of_rec > 30 AND lv_age_of_rec < 60.

<fs_final>-amount2 = <fs_final>-dmbtr.

ELSEIF lv_age_of_rec > 60 AND lv_age_of_rec < 90.

<fs_final>-amount3 = <fs_final>-dmbtr.

ELSEIF lv_age_of_rec > 90 AND lv_age_of_rec < 120.

<fs_final>-amount4 = <fs_final>-dmbtr.

ELSEIF lv_age_of_rec > 180.

<fs_final>-amount5 = <fs_final>-dmbtr.

ENDIF.

CLEAR: bkpf, it_lines-tdline.

ENDLOOP.

**Also, when doing reports, which is a better practice, declare first a structure(types: begin of...end of..) or data: begin of itabn occurs 0...end of itab.

Again, thanks a lot guys and have a nice day!