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: 

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

aris_hidalgo
Contributor
0 Kudos

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!

1 ACCEPTED SOLUTION

Former Member
0 Kudos

1. Always prefer to use field symbols if the internal table is being updated. If you use a header line you will have to explicitly update the internal table. The field symbols will give a better performance.

2. Declare a structure using a TYPE and create a table out of it. That is the best practice that we have used.

Regards,

Ravi

3 REPLIES 3

Former Member
0 Kudos

1. Always prefer to use field symbols if the internal table is being updated. If you use a header line you will have to explicitly update the internal table. The field symbols will give a better performance.

2. Declare a structure using a TYPE and create a table out of it. That is the best practice that we have used.

Regards,

Ravi

0 Kudos

Hi Ravikumar,

Thanks for the helpful tip. Anyway, as you can see from my select statement

above, will it automatically update the fields <fs_final>-budat, <fs_final>-bldat,

<fs_final>-xblnr and <fs_final>-bktxt?

Thanks again!

0 Kudos

Yes, your select statement should update the internal table as you are dealing with field symbols.

Regards,

Ravi