Skip to Content
-1

how to fetch fields (buzei qsskz monat xblnr)from bseg and bkpf?

I am new in ABAP.

I try the following code

SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L0S31 { font-style: italic; color: #808080; } .L0S32 { color: #3399FF; } .L0S33 { color: #4DA619; } .L0S52 { color: #0000FF; } .L0S55 { color: #800080; } .L0S70 { color: #808080; }

***Declaring database tables
TABLES: bseg,bkpf.
*
**************************************************************
**********Declare a Line Type - local structures for internal table *********************************
*****INTERNAL TABLE TO HOLD THE CONTENTS FROM THE BSEG TABLE
TYPES: BEGIN OF ty_bseg,
bukrs TYPE bseg-bukrs,
gjahr TYPE bseg-gjahr, "Οικονομική Χρήση
gsber TYPE bseg-gsber, "Επιχειρησιακή Περιοχή
hkont TYPE bseg-hkont, "Λογαριασμός Γενικής Λογιστικής
MWSKZ type bseg-mwskz,
* QSSKZ type bseg-qsskz,
sgtxt TYPE bseg-sgtxt, "Κείμενο Αναλυτικής Γραμμής
shkzg TYPE bseg-shkzg, "Δείκτης Χρέωσης/Πίστωσης
dmbtr TYPE bseg-dmbtr, "Ποσό σε Τοπικό Νόμισμα

* wrbtr TYPE bseg-wrbtr, "Ποσό σε νόμισμα παραστατικού
belnr TYPE bseg-belnr, "Αριθμός Λογιστικής Εγγραφής
buzei TYPE bseg-buzei, "Αναλυτικες γραμμές

END OF ty_bseg,
*****INTERNAL TABLE TO HOLD THE CONTENTS FROM THE BKPF TABLE
BEGIN OF ty_bkpf,
bukrs TYPE bkpf-bukrs,
gjahr TYPE bkpf-gjahr, ""Οικονομική Χρήση
rldnr TYPE bkpf-rldnr, "Καθολικό σε Γενική Λογιστική
monat TYPE bkpf-monat, "Οικονομική Περίοδος
cpudt TYPE bkpf-cpudt, "Ημ/νία Καταχώρισης Λογιστικής Εγγραφής
belnr TYPE bkpf-belnr, "Αριθμός Λογιστικής Εγγραφής
xblnr type bkpf-xblnr, "Αναφορά
END OF ty_bkpf,
*
**
*******INTERNAL TABLE WHICH ACTUALLY MERGES ALL THE OTHER INTERNAL TABLES.
BEGIN OF ty_out,
sel,
bukrs TYPE bseg-bukrs,
gjahr TYPE bseg-gjahr, "Οικονομική Χρήση
gsber TYPE bseg-gsber, "Επιχειρησιακή Περιοχή
hkont TYPE bseg-hkont, "Λογαριασμός Γενικής Λογιστικής
MWSKZ type bseg-mwskz,
* qsskz type bseg-qsskz,
sgtxt TYPE bseg-sgtxt, "Κείμενο Αναλυτικής Γραμμής
shkzg TYPE bseg-shkzg, "Δείκτης Χρέωσης/Πίστωσης
dmbtr TYPE bseg-dmbtr, "Ποσό σε Τοπικό Νόμισμα
projk TYPE bseg-projk, "Στοιχείο Δομής Διακοπής Εργασίας (Στοιχείο WBS)
* wrbtr TYPE bseg-wrbtr, "Ποσό σε νόμισμα παραστατικού
belnr TYPE bkpf-belnr, "Αριθμός Λογιστικής Εγγραφής
rldnr TYPE bkpf-rldnr, "Καθολικό σε Γενική Λογιστική
monat TYPE bkpf-monat, "Οικονομική Περίοδος
cpudt TYPE bkpf-cpudt, "Ημ/νία Καταχώρισης Λογιστικής Εγγραφής
buzei TYPE bseg-buzei, "Αναλυτικες γραμμές
xblnr type bkpf-xblnr,
END OF ty_out.
*
*********************************************************************
******Declare the 'Table Type' based on the 'Line Type***************
*
******Declare the table based on the 'Table Type*********************
DATA: i_bseg TYPE STANDARD TABLE OF ty_bseg,
i_bkpf TYPE STANDARD TABLE OF ty_bkpf,
i_out TYPE STANDARD TABLE OF ty_out.
**********************************************************************
************Declare the Work Area to use with our Internal Table******
DATA: wa_bseg TYPE ty_bseg,
wa_bkpf TYPE ty_bkpf,
wa_out TYPE ty_out.

*********************************************************************
**********Declaration for Selection Screen***************************
DATA: gjahr TYPE bseg-gjahr.
DATA: belnr TYPE bseg-belnr.
DATA: hkont TYPE bseg-hkont.

*********************************************************************
***********Selection Screens*****************************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-zs1.
SELECT-OPTIONS: s_bukrs FOR bseg-bukrs DEFAULT '1000'.
SELECT-OPTIONS: s_gjahr FOR bseg-gjahr. "Οικονομική Χρήση
SELECT-OPTIONS: s_monat FOR bkpf-monat. "Οικονομική Περίοδος
SELECT-OPTIONS: s_rldnr FOR bkpf-rldnr . "Καθολικό σε Γενική Λογιστική
SELECT-OPTIONS: s_hkont FOR wa_bseg-hkont. "Λογαριασμός Γενικής Λογιστικής
SELECTION-SCREEN END OF BLOCK b1.

DATA: wa_fcat_out TYPE slis_fieldcat_alv,
i_fcat_out TYPE slis_t_fieldcat_alv,
wa_layout TYPE slis_layout_alv, "* To pass the overall structure of the ALV report
wa_top TYPE slis_listheader,
i_top TYPE slis_t_listheader. "* Internal table to hold the data for display top-of-page


DATA: v_prog TYPE sy-repid, "Program name
v_date TYPE sy-datum, "Current date
v_time TYPE sy-uzeit, "Current time
v_name TYPE sy-uname.
** Event Initialization
**This event is executed before the selection screen is displayed .
INITIALIZATION.
v_prog = sy-repid.
v_date = sy-datum.
v_time = sy-uzeit.
v_name = sy-uname.

START-OF-SELECTION.
PERFORM get_data_bseg.
PERFORM get_data_bkpf.
PERFORM prepare_output. "SUBROUTINE TO SELECT DATA FROM VARIOUS TABLES AND POPULATE IT IN THE
** INTERNAL TABLE.
END-OF-SELECTION.

* PERFORM prepare_fieldcat. "SUBROUTINE TO POPULATE THE FIELDS OF THE FIELD CATALOGUE.
* PERFORM prepare_layout. " SUBROUTINE TO POPULATE THE LAYOUT STRUCTURE
* PERFORM alv_list_display. "SUBROUTINE TO DISPLAY THE LIST
*PERFORM get_output.
PERFORM display.
*---Event top of page--------------------------------------------------*
TOP-OF-PAGE.
PERFORM top_of_page.
*&---------------------------------------------------------------------*
*& Form get_data_bseg
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_data_bseg.

* select *
*into corresponding fields of table i_bseg
*from bseg
*for all entries in i_bkpf
*where bukrs = i_bkpf-bukrs and
*belnr = i_bkpf-belnr and
*gjahr = i_bkpf-gjahr and hkont in s_hkont.


SELECT bukrs
gjahr
gsber
hkont
MWSKZ
sgtxt
shkzg
dmbtr
* qsskz
* wrbtr
belnr
buzei FROM bseg INTO TABLE i_bseg
WHERE gjahr IN s_gjahr AND bukrs IN s_bukrs. "and belnr = wa_bkpf-belnr.
IF sy-subrc = 0.
SORT i_bseg BY bukrs.
ELSE.
MESSAGE 'Doesn''t exist' TYPE 'I'.
* ENDIF.
ENDIF.

ENDFORM. "get_data_bseg
*&---------------------------------------------------------------------*
*& Form get_data_bkpf
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_data_bkpf.
IF i_bseg IS NOT INITIAL.

* select *
*into corresponding fields of table i_bkpf
*from bkpf
*where monat IN s_monat
* AND rldnr IN s_rldnr AND gjahr IN s_gjahr AND bukrs IN s_bukrs. "and cpudt <> space.


SELECT bukrs
gjahr
rldnr
monat
cpudt
belnr
xblnr FROM bkpf
INTO TABLE i_bkpf
FOR ALL ENTRIES IN i_bseg
WHERE gjahr = i_bseg-gjahr AND bukrs EQ i_bseg-bukrs AND monat IN s_monat
AND rldnr IN s_rldnr AND belnr = i_bseg-belnr.

IF sy-subrc = 0.
SORT i_bseg BY bukrs.
ELSE.
MESSAGE 'Doesn''t exist' TYPE 'I'.
ENDIF.
ENDIF.

* SELECT bukrs
* gjahr
* gsber
* hkont
* MWSKZ
* sgtxt
* shkzg
* dmbtr
** qsskz
** wrbtr
* belnr
* buzei FROM bseg INTO TABLE i_bseg
* FOR ALL ENTRIES IN i_out
* WHERE belnr = i_out-belnr.
ENDFORM. "get_data_bkfp

*&---------------------------------------------------------------------*
*& Form get_output
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_output .

* IF i_bseg IS NOT INITIAL.
LOOP AT i_bseg INTO wa_bseg.

READ TABLE i_bkpf INTO wa_bkpf WITH KEY belnr = wa_bseg-belnr.

wa_out-bukrs = wa_bseg-bukrs.
wa_out-gjahr = wa_bseg-gjahr. "Οικονομική Χρήση
wa_out-gsber = wa_bseg-gsber. "Επιχειρησιακή Περιοχή
wa_out-hkont = wa_bseg-hkont. "Λογαριασμός Γενικής Λογιστικής
wa_out-mwskz = wa_bseg-MWSKZ.
* wa_out-qsskz = wa_bseg-qsskz.
wa_out-sgtxt = wa_bseg-sgtxt. "Κείμενο Αναλυτικής Γραμμής
wa_out-shkzg = wa_bseg-shkzg. "Δείκτης Χρέωσης/Πίστωσης
wa_out-dmbtr = wa_bseg-dmbtr. "Ποσό σε Τοπικό Νόμισμα
wa_out-belnr = wa_bseg-belnr.
wa_out-xblnr = wa_bkpf-xblnr.
* wa_out-wrbtr = wa_bseg-wrbtr. "Ποσό σε νόμισμα παραστατικού
wa_out-belnr = wa_bkpf-belnr. "Αριθμός Λογιστικής Εγγραφής
wa_out-rldnr = wa_bkpf-rldnr. "Καθολικό σε Γενική Λογιστική
wa_out-monat = wa_bkpf-monat. "Οικονομική Περίοδος
wa_out-cpudt = wa_bkpf-cpudt. "Ημ/νία Καταχώρισης Λογιστικής Εγγραφής
wa_out-bUZEI = wa_bseg-bUZEI.
APPEND wa_out TO i_out.
CLEAR wa_out.
ENDLOOP.
ENDFORM. " GET_OUTPUT

but i receive the following error when i put the button "check" :

"The field DMBTR and component SHKZG of I_bseg are not compatible"

"The field QSSKZ and component DMBTR of I_bseg are not compatible".

Could you please help with this? is the code correct?

thank you in advance.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Nov 14, 2017 at 06:56 AM

    Either use the exact same sequence of fields in the SELECT and in the internal table, or use a INTO CORRESPONDING option. (Read online documentation for work area prerequisites)

    NB: To get the correct document header you need bukrs, gjahr and belnr.

    Add comment
    10|10000 characters needed characters exceeded

    • Thank you for your answer.

      What you mean with "the exact same sequence of fields in the SELECT and in the internal table" ?

      Do you think that this code is suitable for cluster table (bseg)? Thanks again.