2019 Jan 04 5:40 PM
Hi Experts,
I'm ABAP beginner and I need your help in report creation.
Report requirements: show vendor items, where a document was posted between two vendors with different or blank VAT registration code.
The thing that stops me: I have created ALV report that displays data from bsik and bsak but II do not know how to get only the rows that meet the above criteria. Please find the code and the report output and the rows I want to display only.
So the condition for the rows selection should be: if there are more than two rows with the same company code, fiscal year and document number then select these rows.
SPAN {
font-family: "Courier New";
font-size: 10pt;
color: #000000;
background: #FFFFFF;
}
.L0S31 {
font-style: italic;
color: #808080;
}
.L0S52 {
color: #0000FF;
}
.L0S55 {
color: #800080;
}
.L0S70 {
color: #808080;
}
*&---------------------------------------------------------------------*
*& Report ZREBOOKING
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZREBOOKING.
* global type definition for bsak
TYPES: BEGIN OF gty_bsak,
* counter TYPE i,
bukrs TYPE bkpf-bukrs,
lifnr TYPE lfa1-lifnr,
gjahr TYPE bkpf-gjahr,
belnr TYPE bkpf-belnr,
buzei TYPE bsak-buzei,
* buzei1 TYPE bsak-buzei,
cpudt TYPE bkpf-cpudt,
budat TYPE bkpf-budat,
blart TYPE bkpf-blart,
xblnr TYPE bkpf-xblnr,
shkzg TYPE bsak-shkzg,
stceg TYPE lfa1-stceg,
* stceg1 TYPE lfa1-stceg,
END OF gty_bsak.
** global type definition for bsik
TYPES: BEGIN OF gty_bsik,
* counter TYPE i,
bukrs TYPE bkpf-bukrs,
lifnr TYPE lfa1-lifnr,
gjahr TYPE bkpf-gjahr,
belnr TYPE bkpf-belnr,
buzei TYPE bsak-buzei,
* buzei1 TYPE bsak-buzei,
cpudt TYPE bkpf-cpudt,
budat TYPE bkpf-budat,
blart TYPE bkpf-blart,
xblnr TYPE bkpf-xblnr,
shkzg TYPE bsak-shkzg,
stceg TYPE lfa1-stceg,
* stceg1 TYPE lfa1-stceg,
END OF gty_bsik.
* global table definition for bsak and bsik
DATA: gt_bsak TYPE TABLE OF gty_bsak,
gt_bsik TYPE TABLE OF gty_bsik.
* global structure definition for bsak and bsik
DATA: gs_bsak TYPE gty_bsak,
gs_bsik TYPE gty_bsik.
* alv definition
DATA: go_alv_grid TYPE REF TO cl_salv_table.
* selection screen options
SELECT-OPTIONS: so_cocp FOR gs_bsak-bukrs,
so_vend FOR gs_bsak-lifnr,
so_doc FOR gs_bsak-belnr,
so_entdt FOR gs_bsak-cpudt,
so_pstdt FOR gs_bsak-budat,
so_dctp FOR gs_bsak-blart.
* query to get data from bsak, lfa1, lfas
SELECT bukrs bsak~lifnr gjahr belnr buzei cpudt budat blart xblnr shkzg lfa1~stceg
INTO TABLE gt_bsak
FROM bsak
INNER JOIN lfa1 on bsak~lifnr = lfa1~lifnr
LEFT OUTER JOIN lfas on lfa1~lifnr = lfas~lifnr
WHERE bukrs in so_cocp
AND bsak~lifnr in so_vend
AND belnr in so_doc
AND cpudt in so_entdt
AND budat in so_pstdt
AND blart in so_dctp
* GROUP BY bukrs bsak~lifnr gjahr belnr cpudt budat blart xblnr " bukrs bsak~lifnr gjahr belnr buzei cpudt budat blart xblnr shkzg lfa1~stceg lfas~stceg
** HAVING min( buzei ) = 1 AND max( buzei ) > 1
ORDER BY bukrs gjahr belnr.
* query to get data from bsik, lfa1, lfas
SELECT bukrs bsik~lifnr gjahr belnr buzei cpudt budat blart xblnr shkzg lfa1~stceg
INTO TABLE gt_bsik
FROM bsik
INNER JOIN lfa1 on bsik~lifnr = lfa1~lifnr
LEFT OUTER JOIN lfas on lfa1~lifnr = lfas~lifnr
WHERE bukrs in so_cocp
AND bsik~lifnr in so_vend
AND belnr in so_doc
AND cpudt in so_entdt
AND budat in so_pstdt
AND blart in so_dctp
* GROUP BY bukrs bsik~lifnr gjahr belnr cpudt budat blart xblnr " bukrs bsik~lifnr gjahr belnr buzei cpudt budat blart xblnr shkzg lfa1~stceg lfas~stceg
* HAVING min( buzei ) = 1 AND max( buzei ) > 1
Order by bukrs gjahr belnr.
* add internal table lines from gt_bsik to internal table gt_bsak
APPEND LINES OF gt_bsik to gt_bsak.
*---------------------------------------------------------
* ALV call for internal table gt_bsak
*TRY.
call method cl_salv_table=>factory
* EXPORTING
* list_display = IF_SALV_C_BOOL_SAP=>FALSE
* r_container =
* container_name =
IMPORTING
r_salv_table = go_alv_grid
CHANGING
t_table = gt_bsak
.
* CATCH cx_salv_msg .
*ENDTRY.
* display data
go_alv_grid->display( ).
2019 Jan 07 12:24 AM
So after select all data, loop at group by document number then you can check in group if they satisfy your condition
2019 Jan 06 8:04 AM
The easiest way is to add a custom button "select document" which will select all the lines with the same company code, fiscal year and document number. But I wonder why you need that feature? I mean, if you select only one line and start any custom function, you may easily know which lines have the same company code, fiscal year and document number and you can process all of them.
2019 Jan 06 8:06 AM
Please, next time, verify the format of your question quickly after posting, so that to correct it (remove CSS code and blank lines)
2019 Jan 06 12:08 PM
Thank you for your answer. The business request is to schedule the report in background and to send the output to recipients. So I need to extract by this report only required data, without user intervention.
2019 Jan 07 12:24 AM
So after select all data, loop at group by document number then you can check in group if they satisfy your condition
2019 Jan 07 7:45 AM
2019 Jan 08 12:31 AM
I have a brief for you:
LOOP AT gt_vbak INTO DATA(gs_vbak) GROUP BY ( belnr = gs_vbak size = GROUP SIZE ) REFERENCE INTO DATA(grp_ref). "you may need more key to group here
CHECK grp_ref-size > 1. "document should be posted between 2 vendors which mean have more than 1 line in 1 group
LOOP AT GROUP gs_vbak INTO DATA(mem).
IF mem-stceg IS INITIAL. " blank VAT code
APPEND mem TO gt_final.
ELSE.
IF line_exists( gt_final[ belnr = mem-belnr stceg = mem-stceg ] ). "same VAT code
ELSE.
APPEND mem TO gt_final.
ENDIF.
ENDIF.
ENDLOOP.
ENDLOOP.
you need more work on it.