hi ABAP4 experts,
We are trying to know how many records in BSEG(Accounting Document Segment) based on the parameter values of BKPF(Accounting Document Header). The parameter values of BKPF we know are:
1. Company Code (BUKRS) range from Z100 to Z500
2. Document type (BLART) need to input so many ranges:
ZA
ZE
ZT
ZG
Y2
Y4
U4
U8
3. Doc.status (BSTAT) is not equal to 'S'
Based on the three conditions in BKPF, we would like to know record count in BSEG. We will be very appreciated if some experts here give us the sample code and we sure will give you reward points.
Thanks in advance!
Hi Kevin,
You code like this.
DATA: BEGIN OF ITAB2 OCCURS 0, BELNR LIKE BSEG-BELNR, BURKS LIKE BSEG-BURKS, GJAHR LIKE BSEG-GJAHR, BUZEI LIKE BSEG-BUZEI, WRBTR LIKE BSEG-WRBTR, <b>SHKZG like bseg-SHKZG.</b> DATA: END OF ITAB2. DATA: WA_WRBTR TYPE BSEG-WRBTR, WA_COUNT TYPE I. SELECT BELNR BURKS GJAHR BUZEI WRBTR SHKZG INTO TABLE ITAB2 FROM BSEG FOR ALL ENTRIES IN ITAB1 WHERE BELNR = ITAB1-BELNR AND BURKS = ITAB1-BURKS AND GJAHR = ITAB1-GJAHR. LOOP AT ITAB2. WA_COUNT = WA_COUNT + 1. <b>IF ITAB2-SHKZG = 'S'. WA_WRBTR = WA_WRBTR + ITAB2-WRBTR * -1. ELSE. WA_WRBTR = WA_WRBTR + ITAB2-WRBTR. ENDIF.</b> ENDLOOP. WRITE: / 'TOTAL BSEG-WRBTR:', WA_WRBTR, 'TOTAL COUNT:', WA_COUNT.
Hope this will help.
Regards,
Ferry Lianto
hi
first use the select on the BKPF table based on your condition and populate an internal table ..
populate the ranges..
RANGES R_BUKRS FOR BKPF-BUKRS. RANGES R_BLART FOR BKPF_BLART. R_bukrs-SIGN = 'I'. R_bukrs-OPTION = 'BT'. R_bukrs-LOW = 'Z100'. R_bukrs-HIGH = 'Z500'. APPEND R_bukrs. R_blart-SIGN = 'I'. R_blart-OPTION = 'EQ'. R_blart-LOW = 'ZA'. APPEND R_blart. R_blart-SIGN = 'I'. R_blart-OPTION = 'EQ'. R_blart-LOW = 'ZE'. APPEND R_blart. R_blart-SIGN = 'I'. R_blart-OPTION = 'EQ'. R_blart-LOW = 'ZT'. APPEND R_blart. R_blart-SIGN = 'I'. R_blart-OPTION = 'EQ'. R_blart-LOW = 'ZG'. APPEND R_blart. R_blart-SIGN = 'I'. R_blart-OPTION = 'EQ'. R_blart-LOW = 'Y2'. APPEND R_blart. R_blart-SIGN = 'I'. R_blart-OPTION = 'EQ'. R_blart-LOW = 'Y4'. APPEND R_blart. R_blart-SIGN = 'I'. R_blart-OPTION = 'EQ'. R_blart-LOW = 'U4'. APPEND R_blart. R_blart-SIGN = 'I'. R_blart-OPTION = 'EQ'. R_blart-LOW = 'U8'. APPEND R_blart. select bukrs blart bstat into table itab1 from BKPF where BUKRS in R_bukrs and BLART in R_blart and BSTAT NE 's'. SELECT count(*) into count from BSEG FOR ALL ENTRIES in itab1.
regards
satesh
Message was edited by: Satesh R
Message was edited by: Satesh R
Hi Kevin,
You can code like this.
data: WRBTR type BSEG-WRBTR. SELECT count(*) sum ( WRBTR ) into (count, WRBTR) from BSEG FOR ALL ENTRIES in itab1 where belnr = itab1-belnr and bukrs = itab1-bukrs and gjahr = itab1-gjahr.
Hope this will help.
Regards,
Ferry Lianto
Hi Kevin,
Apologies ... I do not have SAP system now therefore I can not do syntac check.
I believe you can code like this.
DATA: BEGIN OF ITAB2 OCCURS 0, BELNR LIKE BSEG-BELNR, BURKS LIKE BSEG-BURKS, GJAHR LIKE BSEG-GJAHR, WRBTR LIKE BSEG-WRBTR. DATA: END OF ITAB2. DATA: WA_WRBTR TYPE BSEG-WRBTR, WA_COUNT TYPE I. SELECT BELNR BURKS GJAHR WRBTR INTO TABLE ITAB2 FROM BSEG FOR ALL ENTRIES IN ITAB1 WHERE BELNR = ITAB1-BELNR AND BURKS = ITAB1-BURKS AND GJAHR = ITAB1-GJAHR. LOOP AT ITAB2. WA_WRBTR = WA_WRBTR + ITAB2-WRBTR. WA_COUNT = WA_COUNT + 1. ENDLOOP. WRITE: / 'TOTAL BSEG-WRBTR:', WA_WRBTR, 'TOTAL COUNT:', WA_COUNT.
Hope this will help.
Regards,
Ferry Lianto
Hi Kevin,
Do you know the key fields of table BSEG? I don't have SAP system now. I believe my code did not pass enough key field to count number of records. Therefore, system passed less records.
Perhaps like this,
DATA: BEGIN OF ITAB2 OCCURS 0, BELNR LIKE BSEG-BELNR, BURKS LIKE BSEG-BURKS, GJAHR LIKE BSEG-GJAHR, <b>BUZEI LIKE BSEG-BUZEI,</b> WRBTR LIKE BSEG-WRBTR. DATA: END OF ITAB2. DATA: WA_WRBTR TYPE BSEG-WRBTR, WA_COUNT TYPE I. SELECT BELNR BURKS GJAHR <b>BUZEI</b> WRBTR INTO TABLE ITAB2 FROM BSEG FOR ALL ENTRIES IN ITAB1 WHERE BELNR = ITAB1-BELNR AND BURKS = ITAB1-BURKS AND GJAHR = ITAB1-GJAHR. LOOP AT ITAB2. WA_COUNT = WA_COUNT + 1. WA_WRBTR = WA_WRBTR + ITAB2-WRBTR. ENDLOOP. WRITE: / 'TOTAL BSEG-WRBTR:', WA_WRBTR, 'TOTAL COUNT:', WA_COUNT
Also when you sum WRBTR, please include field to determine debit/credit sign.
Hope this will help.
Regards,
Ferry Lianto
Glad to help you.
Regards,
Ferry Lianto
Add a comment