Application Development and Automation 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: 
Read only

billing documents

Former Member
0 Likes
684

Can u guys pls suggest me some code dealing with billing documnets like eample code!!!

3 REPLIES 3
Read only

Former Member
0 Likes
529

check the table VBRK+VBRP to get billing documents based on the where clause.

use this tool to generate report.

u have to link VBRK-VBELN = VBRP-VBELN

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b09ac4d5-e3ad-2910-6a81-96d1b861...

Regards

Prabhu

Read only

Former Member
0 Likes
529

Hi,

Please find the sample code for Billing document BAPI.

t_billing-salesorg = vbak-vkorg.

t_billing-DISTR_CHAN = vbak-vtweg.

t_billing-DIVISION = vbak-spart.

t_billing-DOC_TYPE = vbak-auart.

t_billing-ref_doc = vbak-vbeln.

t_billing-ref_item = vbap-posnr.

t_billing-doc_number = vbak-vbeln.

t_billing-ITM_NUMBER = vbap-posnr.

t_billing-ordbilltyp = 'BILLING TYPE'.

t_billing-price_date = sy-datum.

t_billing-ref_doc_ca = vbak-vbtyp.

t_billing-sold_to = vbak-kunnr.

t_billing-material = vbap-matnr.

t_billing-plant = vbap-werks.

APPEND t_billing.

CALL FUNCTION 'BAPI_BILLINGDOC_CREATEMULTIPLE'

TABLES

billingdatain = t_billing

return = t_return

success = t_success.

commit work.

Pls. reward if useful..

Read only

Former Member
0 Likes
529

&----


*& Report ZAVR001_SALES_MATGRP_WISE *

*& *

&----


*& *

*& *

&----


REPORT zavr001_sales_matgrp_wise NO STANDARD PAGE HEADING LINE-SIZE 140 LINE-COUNT 37(3) MESSAGE-ID zavme.

*----


  • MODULE : Sales & Distribution

*----


    • Objective : To Display the Sales Details Material Gruop Wise.

  • And compare the sales in two Years/Months.

    • Program : ZAVR001_SALES_MATGRP_WISE.

**

    • ** Message Classs : ZAVME.

    • Transport Request : SFDK924139

    • Package :

    • Funct.Spec.No : FS-SD-REP-002

    • Spec Prepared by :

    • Approved by :

----


  • Modification History

    • Modified On :

    • New Request :

    • Modified On :

    • New Request :

*----


*----


GLOBAL DECLARATIONS.

TYPE-POOLS: slis.

----


  • TABLES DECLARATON *

----


TABLES: vbrk, "Billing Doc Header

vbrp, "Billing Doc Item

tvko, "Organizational Unit: Sales Organizations

tvtw, "Organizational Unit: Distribution Channels

t023. "Material Groups

----


  • INTERNAL TABLES *

----


DATA : BEGIN OF it_temp OCCURS 0,

matkl LIKE mara-matkl , " MATERIAL GROUP

matnr LIKE vbrp-matnr, " Material Number

netwr LIKE vbrp-netwr, " Net Price

fkimg LIKE vbrp-fkimg, " Quantity

netwr1 LIKE vbrp-netwr, " Net Price

fkimg1 LIKE vbrp-fkimg, " Quantity

END OF it_temp.

DATA : it_outtab LIKE it_temp OCCURS 0 WITH HEADER LINE.

DATA : BEGIN OF it_vbrk OCCURS 0,

vbeln LIKE vbrk-vbeln, " BILLING DOC NUMBER

netwr LIKE vbrk-netwr, " Net price

fkdat LIKE vbrk-fkdat, " Billing date

vtweg LIKE vbrk-vtweg,

END OF it_vbrk.

DATA : it_vbrk1 LIKE it_vbrk OCCURS 0 WITH HEADER LINE.

DATA : BEGIN OF it_vbrp OCCURS 0,

matkl LIKE vbrp-matkl,

matnr LIKE vbrp-matnr,

vbeln LIKE vbrk-vbeln,

posnr LIKE vbrp-posnr, "Item No.

fkimg LIKE vbrp-fkimg,

netwr LIKE vbrp-netwr,

END OF it_vbrp.

DATA : it_vbrp1 LIKE it_vbrp OCCURS 0 WITH HEADER LINE.

*----


Data Declarations

DATA : w_spmon TYPE spmon,

w_spmon2 TYPE spmon.

DATA: w_year1 LIKE vbrk-gjahr,

w_year2 LIKE vbrk-gjahr,

w_yearlow LIKE sy-datum,

w_yearhi LIKE sy-datum,

w_yearlow1 LIKE sy-datum,

w_yearhi1 LIKE sy-datum,

w_rep1(10) TYPE c,

w_rep2(10) TYPE c,

w_temp1 LIKE vbrk-gjahr,

w_temp2 LIKE vbrk-gjahr,

w_temp3 like vbrk-gjahr,

w_temp4 like vbrk-gjahr,

w_months LIKE p0347-scrmm,

w_year LIKE vbrk-gjahr.

*******************************************************

--


ALV DECLARATION--

*******************************************************

DATA : it_fieldcat TYPE slis_t_fieldcat_alv,

it_sort TYPE slis_t_sortinfo_alv,

it_listheader TYPE slis_t_listheader,

it_alvevent TYPE slis_t_event.

DATA : wa_fieldcat TYPE slis_fieldcat_alv,

w_pos TYPE i VALUE 1,

wa_listheader TYPE slis_listheader,

wa_alvevent TYPE slis_alv_event,

wa_sort TYPE slis_sortinfo_alv.

DATA : wa_repid LIKE sy-repid.

****************************************************

**--


CONSTANTS--


****************************************************

CONSTANTS: c_formname_top_of_page TYPE slis_formname

VALUE 'F_TOP_OF_PAGE',

c_formname_end_of_list TYPE slis_formname

VALUE 'F_END_OF_LIST'.

*****SELECTION SCREEN.

SELECTION-SCREEN BEGIN OF BLOCK input WITH FRAME TITLE text-001.

PARAMETERS : pr_vkorg(4) TYPE c DEFAULT '7000'. "sales organization

SELECT-OPTIONS : so_vtweg FOR vbrk-vtweg OBLIGATORY, "Distribution Channel

so_matkl FOR vbrp-matkl. "material group

SELECTION-SCREEN END OF BLOCK input.

SELECTION-SCREEN : BEGIN OF BLOCK display WITH FRAME TITLE text-005.

PARAMETERS : pa_list RADIOBUTTON GROUP rad2 ,

pa_grid RADIOBUTTON GROUP rad2 . "List/Grid Display Indicator

SELECTION-SCREEN END OF BLOCK display.

SELECTION-SCREEN BEGIN OF BLOCK compare WITH FRAME TITLE text-002.

PARAMETERS : pa_year RADIOBUTTON GROUP rad1 USER-COMMAND radio,

pa_month RADIOBUTTON GROUP rad1 . "Comparision indicator

SELECTION-SCREEN END OF BLOCK compare.

  • Compare In Two Years

SELECTION-SCREEN : BEGIN OF BLOCK yearwise WITH FRAME TITLE text-003.

PARAMETERS : pr_year1 LIKE vbrk-gjahr MODIF ID yrs ,

pr_year2 LIKE vbrk-gjahr MODIF ID yrs .

SELECTION-SCREEN : END OF BLOCK yearwise.

  • Compare In Two Months

SELECTION-SCREEN: BEGIN OF BLOCK monthwise WITH FRAME TITLE text-004.

PARAMETERS : pr_mnth1 TYPE spmon MODIF ID mth ,

pr_mnth2 TYPE spmon MODIF ID mth .

SELECTION-SCREEN : END OF BLOCK monthwise.

                    • Screen Change

AT SELECTION-SCREEN OUTPUT.

PERFORM change-screen.

*----


At Selection Screen

AT SELECTION-SCREEN.

*----


Validate Sales Organization.

IF pr_vkorg IS NOT INITIAL.

IF pr_vkorg NE '7000'.

MESSAGE s001(zavme) WITH text-029.

STOP.

ENDIF.

ELSE.

MESSAGE s001(zavme) WITH text-030.

STOP.

ENDIF.

*------Validate Distribution channel.

IF so_vtweg-low IS NOT INITIAL.

SELECT SINGLE * FROM tvtw WHERE vtweg = so_vtweg-low.

IF sy-subrc NE 0.

MESSAGE e001(zavme) WITH text-031.

ENDIF.

ENDIF.

IF so_vtweg-high IS NOT INITIAL.

SELECT SINGLE * FROM tvtw WHERE vtweg = so_vtweg-high.

IF sy-subrc NE 0.

MESSAGE e001(zavme) WITH text-032.

ENDIF.

ENDIF.

*-------Validate Material group

IF so_matkl-low IS NOT INITIAL.

SELECT SINGLE * FROM t023 WHERE matkl = so_matkl-low.

IF sy-subrc NE 0.

MESSAGE e001(zavme) WITH text-033.

ENDIF.

ENDIF.

IF so_matkl-high IS NOT INITIAL.

SELECT SINGLE * FROM t023 WHERE matkl = so_matkl-high.

IF sy-subrc NE 0.

MESSAGE e001(zavme) WITH text-034.

ENDIF.

ENDIF.

                      • Popup To Select A Month

AT SELECTION-SCREEN ON VALUE-REQUEST FOR pr_mnth1.

PERFORM month_f4 USING pr_mnth1.

                      • Popup To Select A Month

AT SELECTION-SCREEN ON VALUE-REQUEST FOR pr_mnth2.

PERFORM month_f4 USING pr_mnth2.

*----


Start-Of-Selection

START-OF-SELECTION.

        • Date Validations.

PERFORM validate_data.

        • Select data from DB tables

PERFORM collect_data.

*****Print data in List/Grid .

PERFORM display.

*-------Top of page

TOP-OF-PAGE.

WRITE: 39 text-022 COLOR COL_HEADING.

WRITE:/39 sy-uline(35).

WRITE:/ sy-uline(112).

WRITE:/ sy-vline,50 '(',w_rep1 COLOR COL_GROUP,')',90 '(',w_rep2 COLOR COL_GROUP,')'.

WRITE:112 sy-vline.

WRITE:/ sy-vline,1 sy-uline(111),112 sy-vline.

WRITE:/ sy-vline, text-023 COLOR COL_KEY,15 text-024 COLOR COL_KEY,40 text-025 COLOR COL_KEY ,60 text-026 COLOR COL_KEY ,82 text-025 COLOR COL_KEY,102 text-026 COLOR COL_KEY,112 sy-vline.

WRITE:/ sy-uline(112).

*------End of page

END-OF-PAGE.

WRITE:/ sy-vline,1 sy-uline(111),112 sy-vline.

WRITE:/ sy-vline,45 text-027 COLOR COL_NORMAL,sy-pagno COLOR COL_NORMAL,112 sy-vline.

WRITE:/ sy-vline,1 sy-uline(111),112 sy-vline.

&----


*& Form change-screen

&----


FORM change-screen .

****Enable the select options when perticular selection is made.

IF pa_month = 'X'.

LOOP AT SCREEN.

CHECK screen-group1 = 'YRS'.

screen-active = '0'.

MODIFY SCREEN.

ENDLOOP.

ELSE.

****Enable the select options when perticular selection is made.

LOOP AT SCREEN.

CHECK screen-group1 = 'MTH'.

screen-active = '0'.

MODIFY SCREEN.

ENDLOOP.

ENDIF.

ENDFORM. " change-screen

&----


*& Form month_f4

&----


  • -->P_PR_MNTH1 text

----


FORM month_f4 USING w_month TYPE spmon.

IF w_month IS INITIAL.

w_month = sy-datum+0(6).

ENDIF.

CALL FUNCTION 'POPUP_TO_SELECT_MONTH'

EXPORTING

actual_month = w_month

IMPORTING

selected_month = w_month

EXCEPTIONS

factory_calendar_not_found = 01

holiday_calendar_not_found = 02

month_not_found = 03.

ENDFORM. " month_f4

&----


*& Form display *

&----


FORM display .

IF pa_list = 'X'.

PERFORM fm_list_disp.

ELSE.

PERFORM fm_alv_disp.

ENDIF.

ENDFORM. " display

&----


*& Form fm_list_disp *

&----


FORM fm_list_disp .

SORT it_outtab BY matkl.

LOOP AT it_outtab.

ON CHANGE OF it_outtab-matnr.

ON CHANGE OF it_outtab-matkl.

WRITE:/1 sy-vline,5 it_outtab-matkl,112 sy-vline.

ENDON.

WRITE:/15 it_outtab-matnr.

ENDON.

WRITE:33 it_outtab-fkimg, it_outtab-netwr,it_outtab-fkimg1,it_outtab-netwr1.

WRITE: 1 sy-vline ,112 sy-vline.

ENDLOOP.

WRITE:/ sy-uline(112).

ENDFORM. " fm_list_disp

&----


*& Form fm_alv_disp

&----


FORM fm_alv_disp.

*------Build Field catalog.

PERFORM build_fcat USING '1' 'MATKL' 'IT_OUTTAB' ' ' ' ' ' ' 'MatType'.

PERFORM build_fcat USING '2' 'MATNR' 'IT_OUTTAB' ' ' ' ' ' ' 'MatNo'.

PERFORM build_fcat USING '3' 'NETWR' 'IT_OUTTAB' ' ' ' ' ' ' 'Netprice'.

PERFORM build_fcat USING '4' 'FKIMG' 'IT_OUTTAB' 'X' 'X' ' ' 'Qty'.

PERFORM build_fcat USING '5' 'NETWR1' 'IT_OUTTAB' ' ' ' ' ' ' 'Netprice'.

PERFORM build_fcat USING '6' 'FKIMG1' 'IT_OUTTAB' 'X' 'X' ' ' 'Qty'.

*---Build Top of page for grid.

PERFORM biuld_top USING it_listheader[].

*------Sort The Catalog

PERFORM sort_cat TABLES it_outtab USING it_sort[].

*------Display Table In GRID

PERFORM disp_grid TABLES it_outtab[].

ENDFORM. " fm_alv_disp

&----


*& Form validate_data

&----


FORM validate_data .

DATA : w_year1 LIKE vbrk-gjahr,

w_year2 LIKE vbrk-gjahr,

w_loc1 LIKE vbrk-gjahr,

w_loc2 LIKE vbrk-gjahr.

w_spmon = sy-datum+0(6).

w_year = sy-datum+0(4).

        • Year Wise Comparision ---- DATE validations.

IF pa_year = 'X'.

IF pr_year1 IS INITIAL AND pr_year2 IS INITIAL.

MESSAGE s001(zavme) WITH text-006.

STOP.

ELSE.

IF pr_year1 IS INITIAL AND pr_year2 IS NOT INITIAL.

MESSAGE s001(zavme) WITH text-007.

STOP.

ELSE.

IF pr_year1 IS NOT INITIAL AND pr_year2 IS INITIAL.

MESSAGE s001(zavme) WITH text-008.

STOP.

ELSE.

IF pr_year1 IS NOT INITIAL AND pr_year2 IS NOT INITIAL.

IF pr_year1 > w_year .

MESSAGE s002(zavme) WITH text-009 pr_year1.

STOP.

ENDIF.

IF pr_year2 > w_year.

MESSAGE s002(zavme) WITH text-010 pr_year2.

STOP.

ENDIF.

IF pr_year1 > pr_year2.

MESSAGE s003(zavme) WITH text-011 pr_year1 pr_year2.

STOP.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

        • Month Wise Comparision ---- DATE validations.

ELSE.

IF pa_month = 'X'.

IF pr_mnth1 IS INITIAL AND pr_mnth2 IS INITIAL.

MESSAGE s001(zavme) WITH text-012.

STOP.

ELSE.

IF pr_mnth1 IS INITIAL AND pr_mnth2 IS NOT INITIAL.

MESSAGE s001(zavme) WITH text-013.

STOP.

ELSE.

IF pr_mnth1 IS NOT INITIAL AND pr_mnth2 IS INITIAL.

MESSAGE s001(zavme) WITH text-014.

STOP.

ELSE.

IF pr_mnth1 IS NOT INITIAL AND pr_mnth2 IS NOT INITIAL.

IF pr_mnth1 EQ pr_mnth2.

MESSAGE s001(zavme) WITH text-036.

STOP.

ENDIF.

IF pr_mnth14(2) NE pr_mnth24(2).

MESSAGE s001(zavme) WITH text-035.

STOP.

ENDIF.

IF pr_mnth1 > w_spmon.

MESSAGE s002(zavme) WITH text-015 pr_mnth1.

STOP.

ENDIF.

IF pr_mnth2 > w_spmon.

MESSAGE s002(zavme) WITH text-016 pr_mnth2.

STOP.

ENDIF.

IF pr_mnth10(4) > pr_mnth20(4).

MESSAGE s003(zavme) WITH text-017 pr_mnth1 pr_mnth2.

STOP.

IF pr_mnth14(2) > pr_mnth24(2).

MESSAGE s003(zavme) WITH text-018 pr_mnth1 pr_mnth2.

STOP.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

*------- Data selection based on year.

IF pr_year1 IS NOT INITIAL AND pr_year2 IS NOT INITIAL.

*------- fiscal year starts with 01/04/yyyy and ends with 31/03/yyyy.

CLEAR: w_yearhi,

w_yearlow,

w_yearhi1,

w_yearlow1.

w_loc1 = pr_year1 + 1.

w_loc2 = pr_year1 + 2.

*----


this case is when we suppose to get the sales in one single year.

IF pr_year2 EQ pr_year1.

w_temp1 = pr_year1.

w_temp2 = pr_year2 + 1.

CONCATENATE w_temp1 '0401' INTO w_yearlow.

CONCATENATE w_temp2 '0331' INTO w_yearlow1.

CONCATENATE w_temp1 '0401' INTO w_yearhi.

CONCATENATE w_temp2 '0331' INTO w_yearhi1.

*----


yearlow, yearlow1 contains the date interval.

*----


yearhi, yearhi1 contains the date interval.

CONCATENATE w_temp1 '-' w_temp2 INTO w_rep1.

ENDIF.

*----


yearwise

if pr_year1 ne pr_year2.

CLEAR : w_temp1,

w_temp2,

w_rep1,

w_rep2,

w_temp3,

w_temp4.

w_temp1 = pr_year1.

w_temp2 = pr_year1 + 1.

w_temp3 = pr_year2.

w_temp4 = pr_year2 + 1.

CONCATENATE w_temp1 '0401' INTO w_yearlow.

CONCATENATE w_temp2 '0331' INTO w_yearlow1.

CONCATENATE w_temp3 '0401' INTO w_yearhi.

CONCATENATE w_temp4 '0331' INTO w_yearhi1.

CONCATENATE w_temp1 '-' w_temp2 INTO w_rep1.

CONCATENATE w_temp3 '-' w_temp4 INTO w_rep2.

*----


year1low and yearhi contains the first date of months.

*----


year1low1 and yearhi1 contains the last date of months.

ENDIF.

PERFORM getdata.

endif.

*------- Data selection based on Month

IF pr_mnth1 IS NOT INITIAL AND pr_mnth2 IS NOT INITIAL.

CLEAR : w_yearlow,

w_yearhi,

w_yearlow1,

w_yearhi1,

w_months,

w_rep1,

w_rep2.

*----


Allow the data selection in the same month.

IF pr_mnth14(2) EQ pr_mnth24(2).

CONCATENATE pr_mnth1 '01' INTO w_yearlow.

CONCATENATE pr_mnth2 '01' INTO w_yearhi.

*----


last date of month might be 30 or 31 or 28 or 29

CALL FUNCTION 'SG_PS_GET_LAST_DAY_OF_MONTH'

EXPORTING

day_in = w_yearlow

IMPORTING

last_day_of_month = w_yearlow1

EXCEPTIONS

day_in_not_valid = 1

OTHERS = 2.

CALL FUNCTION 'SG_PS_GET_LAST_DAY_OF_MONTH'

EXPORTING

day_in = w_yearhi

IMPORTING

last_day_of_month = w_yearhi1

EXCEPTIONS

day_in_not_valid = 1

OTHERS = 2.

*----


year1low and yearhi contains the first date of months.

*----


year1low1 and yearhi1 contains the last date of months.

*----


getd data using w_yearlow w_yearlow1 w_yearhi w_yearhi1.

CONCATENATE w_yearlow4(2) '/' w_yearlow0(4) INTO w_rep1.

CONCATENATE w_yearhi4(2) '/' w_yearhi10(4) INTO w_rep2.

PERFORM getdata.

ENDIF.

ENDIF.

ENDFORM. " validate_data

&----


*& Form build_fcat

&----


FORM build_fcat USING value(col_pos)

value(fieldname)

value(tabname)

value(key)

value(no_zero)

value(do_sum)

value(reptext_ddic).

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = col_pos.

wa_fieldcat-fieldname = fieldname.

wa_fieldcat-tabname = tabname.

wa_fieldcat-key = key.

wa_fieldcat-no_zero = no_zero.

wa_fieldcat-do_sum = do_sum.

wa_fieldcat-reptext_ddic = reptext_ddic.

APPEND wa_fieldcat TO it_fieldcat.

ENDFORM. " build_fcat

&----


*& Form sort_cat

&----


  • -->P_IT_SORT[] text

----


FORM sort_cat TABLES it_outtab STRUCTURE it_outtab USING it_sort TYPE slis_t_sortinfo_alv.

CLEAR wa_sort.

wa_sort-fieldname = 'MATKL'.

wa_sort-tabname = 'IT_OUTTAB'.

wa_sort-spos = 1.

wa_sort-up = 'X'.

wa_sort-subtot = ' '.

APPEND wa_sort TO it_sort.

ENDFORM. " sort_cat

&----


*& Form getdata

&----


FORM getdata .

REFRESH : it_vbrk[],

it_vbrk1[].

CLEAR : it_vbrk,

it_vbrk1.

REFRESH : it_vbrp[],

it_vbrp1[].

CLEAR : it_vbrp,

it_vbrp1.

        • When Data has to get within One Fiscal Year

IF PR_YEAR1 IS NOT INITIAL AND PR_YEAR2 IS NOT INITIAL and pr_year2 EQ pr_year1.

SELECT

vbeln

netwr

fkdat

FROM

vbrk

INTO TABLE

it_vbrk

WHERE

vkorg = pr_vkorg

AND vtweg IN so_vtweg

AND fkdat BETWEEN w_yearlow AND w_yearlow1.

IF it_vbrk[] IS NOT INITIAL.

SELECT

matkl

matnr

vbeln

posnr

fkimg

netwr

FROM

vbrp

INTO TABLE

it_vbrp

FOR ALL ENTRIES IN

it_vbrk

WHERE

vbeln = it_vbrk-vbeln

AND matkl IN so_matkl.

ENDIF.

perform collect_data.

EXIT.

endif.

        • Otherwise The first case

SELECT

vbeln

netwr

fkdat

FROM

vbrk

INTO TABLE

it_vbrk

WHERE

vkorg = pr_vkorg

AND vtweg IN so_vtweg

AND fkdat BETWEEN w_yearlow AND w_yearlow1.

IF it_vbrk[] IS NOT INITIAL.

SELECT

matkl

matnr

vbeln

posnr

fkimg

netwr

FROM

vbrp

INTO TABLE

it_vbrp

FOR ALL ENTRIES IN

it_vbrk

WHERE

vbeln = it_vbrk-vbeln

AND matkl IN so_matkl.

ENDIF.

SELECT

vbeln

netwr

fkdat

FROM

vbrk

INTO TABLE

it_vbrk1

WHERE

vkorg = pr_vkorg

AND vtweg IN so_vtweg

AND fkdat BETWEEN w_yearhi AND w_yearhi1.

IF it_vbrk1[] IS NOT INITIAL.

SELECT

matkl

matnr

vbeln

posnr

fkimg

netwr

FROM

vbrp

INTO TABLE

it_vbrp1

FOR ALL ENTRIES IN

it_vbrk1

WHERE

vbeln = it_vbrk1-vbeln

AND matkl IN so_matkl.

ENDIF.

ENDFORM. " getdata

&----


*& Form DISP_GRID

&----


  • -->P_IT_VBRP[] text

----


FORM disp_grid TABLES it_outtab STRUCTURE it_outtab.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = sy-repid

i_callback_top_of_page = 'TOP_OF_PAGE'

it_fieldcat = it_fieldcat

it_sort = it_sort

TABLES

t_outtab = it_outtab

EXCEPTIONS

program_error = 1

OTHERS = 2.

IF sy-subrc <> 0.

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

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

ENDIF.

ENDFORM. " DISP_GRIP

&----


*& Form collect_data

&----


FORM collect_data .

IF it_vbrp[] IS INITIAL AND it_vbrp1[] IS INITIAL.

MESSAGE s001(zavme) WITH text-028.

STOP.

ENDIF.

IF it_vbrp[] IS NOT INITIAL AND it_vbrp1[] IS INITIAL.

SORT it_vbrp BY matkl matnr.

LOOP AT it_vbrp.

it_temp-matkl = it_vbrp-matkl.

it_temp-matnr = it_vbrp-matnr.

it_temp-fkimg = it_vbrp-fkimg.

it_temp-netwr = it_vbrp-netwr.

APPEND it_temp.

CLEAR it_temp.

ENDLOOP.

perform sort_tab tables it_temp.

ELSE.

IF it_vbrp1[] IS NOT INITIAL AND it_vbrp[] IS INITIAL.

SORT it_vbrp1 BY matkl matnr.

LOOP AT it_vbrp1.

it_temp-matkl = it_vbrp1-matkl.

it_temp-matnr = it_vbrp1-matnr.

it_temp-fkimg1 = it_vbrp1-fkimg.

it_temp-netwr1 = it_vbrp1-netwr.

APPEND it_temp.

CLEAR it_temp.

ENDLOOP.

perform sort_tab tables it_temp.

ELSE.

IF it_vbrp[] IS NOT INITIAL AND it_vbrp1[] IS NOT INITIAL.

SORT it_vbrp BY matkl matnr.

SORT it_vbrp1 BY matkl matnr.

LOOP AT it_vbrp.

it_temp-matkl = it_vbrp-matkl.

it_temp-matnr = it_vbrp-matnr.

it_temp-netwr = it_vbrp-netwr.

it_temp-fkimg = it_vbrp-fkimg.

APPEND it_temp.

CLEAR it_temp.

ENDLOOP.

LOOP AT it_vbrp1.

it_temp-matkl = it_vbrp1-matkl.

it_temp-matnr = it_vbrp1-matnr.

it_temp-netwr1 = it_vbrp1-netwr.

it_temp-fkimg1 = it_vbrp1-fkimg.

APPEND it_temp.

CLEAR it_temp.

ENDLOOP.

perform sort_tab tables it_temp.

ENDIF.

ENDIF.

ENDIF.

ENDFORM. " collect_data

*----


Top of page for Grid.

FORM top_of_page.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = it_listheader.

ENDFORM. "top_of_page

&----


*& Form biuld_top

&----


  • -->P_IT_LISTHEADER[] text

----


FORM biuld_top USING it_listheader TYPE slis_t_listheader.

DATA : text(100) TYPE c.

CLEAR it_listheader.

CLEAR wa_listheader.

wa_listheader-typ = 'H'.

wa_listheader-info = text-037.

APPEND wa_listheader TO it_listheader.

CLEAR wa_listheader.

CONCATENATE text-038 ' , In :' w_rep1 '---' w_rep2 INTO text.

wa_listheader-typ = 'S'.

  • wa_listheader-key = text.

wa_listheader-info = text.

APPEND wa_listheader TO it_listheader.

ENDFORM. " biuld_top

&----


*& Form sort_tab

&----


  • -->P_IT_TEMP text

----


form sort_tab tables it_temp structure it_temp.

DATA : price LIKE vbrp-netwr VALUE 0,

qty LIKE vbrp-fkimg VALUE 0,

price1 LIKE vbrp-netwr VALUE 0,

qty1 LIKE vbrp-fkimg VALUE 0.

refresh it_outtab[].

clear it_outtab.

SORT it_temp BY matkl matnr.

LOOP AT it_temp.

price = price + it_temp-netwr.

qty = qty + it_temp-fkimg.

price1 = price1 + it_temp-netwr1.

qty1 = qty1 + it_temp-fkimg1.

AT END OF matnr.

it_outtab-matkl = it_temp-matkl.

it_outtab-matnr = it_temp-matnr.

it_outtab-netwr = price.

it_outtab-fkimg = qty.

it_outtab-netwr1 = price1.

it_outtab-fkimg1 = qty1.

APPEND it_outtab.

CLEAR : it_outtab,price,qty,price1,qty1.

ENDAT.

ENDLOOP.

endform. " sort_tab