Skip to Content
-1
Jun 09, 2022 at 11:58 AM

Populate PR without PO in custom ALV report.

276 Views

Dear Fellows,

I am making an ALV report on the procurement cycle, The issue I am facing is to display PR on which PO doesn't created yet. My report is showing records that have POs. Hence, the PO can display without PR for some items which is okay. Kindly help me out.

blog1.png

Source Code:

TYPE-POOLS: slis.
TABLES: eban, ekpo, ekko, eket, mkpf.

DATA : gt_fcat TYPE slis_t_fieldcat_alv,
gs_fcat TYPE slis_fieldcat_alv,
gs_layout TYPE slis_layout_alv,
gt_sort TYPE slis_t_sortinfo_alv,
gs_sort TYPE slis_sortinfo_alv.

Data: IT_menu TYPE SLIS_T_EXTAB.

append '&ODN' to it_menu. "Ascending sort
append '&OUP' to it_menu. "Decending Sot
*append '&RNT' to it_menu. "Print menu from list menu bar


TYPES: BEGIN OF ty_data,

ebeln TYPE ekko-ebeln, "PO number
bsart TYPE ekko-bsart, "Document Type
aedat TYPE ekko-aedat, "PO date
ebelp TYPE ekpo-ebelp, "Item number PO
* ebeln TYPE ekpo-EBELN,
txz01 TYPE eban-txz01, "Item name
menge TYPE ekpo-menge, "GRN Quantity
banfn TYPE eban-banfn, "PR number
matnr TYPE ekpo-matnr, "Material No
badat TYPE eban-badat, "PR date
mblnr TYPE mseg-mblnr, "GRN number
budat TYPE mseg-mblnr,
bnfpo TYPE ekpo-bnfpo,
zeile TYPE mseg-zeile,
LOEKZ TYPE EKPO-LOEKZ,
ELIKZ TYPE EKPO-ELIKZ,
* gr_num TYPE char200,
* ebeln TYPE eket-ebeln,
wemng TYPE eket-wemng,
END OF ty_data.

TYPES: BEGIN OF ty_mseg2,
ebeln TYPE mseg-ebeln,
ebelp TYPE mseg-ebelp,
bpmng TYPE mseg-bpmng,
bwart TYPE mseg-bwart,
END OF ty_mseg2.


DATA: it_mseg1_sum TYPE TABLE OF ty_mseg2,
it_mseg2_sum TYPE TABLE OF ty_mseg2,
wa_mseg_sum TYPE ty_mseg2.

""FOR 103
DATA: it_mseg3_sum TYPE TABLE OF ty_mseg2,
it_mseg4_sum TYPE TABLE OF ty_mseg2,
wa_mseg1_sum TYPE ty_mseg2.


DATA : it_data TYPE STANDARD TABLE OF ty_data,
ls_data TYPE ty_data.
DATA : it_mkpf TYPE STANDARD TABLE OF mkpf,
ls_mkpf TYPE mkpf.
DATA : it_ekpo TYPE STANDARD TABLE OF ekpo,
ls_ekko TYPE ekpo.
DATA : it_mseg2 TYPE STANDARD TABLE OF ty_mseg2.


START-OF-SELECTION.
PERFORM get_data.

END-OF-SELECTION.


PERFORM display_alv.
PERFORM sort.

TYPES: BEGIN OF ty_output,

ebelp TYPE ekpo-ebelp, "Item number PO
txz01 TYPE eban-txz01, "Item name
banfn TYPE eban-banfn, "PR number
badat TYPE eban-badat, "PR date
ebeln TYPE ekpo-ebeln, "PO number
aedat TYPE ekko-aedat, "PO date
mblnr TYPE mseg-mblnr, "GRN number
budat_mkpf TYPE mseg-budat_mkpf, "GRN date
menge TYPE mseg-bpmng, "GRN Quantity
menge1 TYPE mseg-bpmng, "GRN Quantity for 103
bsart TYPE ekko-bsart, "Document Type
matnr TYPE eban-matnr,
po_quan TYPE ekpo-menge,
t_po_quan TYPE ekpo-menge,
percent TYPE p DECIMALS 2,
grquan TYPE mseg-bpmng,
linepercent TYPE p DECIMALS 2,
prquan TYPE eban-menge,
gr_num TYPE char200,
subtract TYPE p DECIMALS 2,


END OF ty_output.

DATA : it_output TYPE TABLE OF ty_output,
ls_output TYPE ty_output.

DATA: g_variant TYPE disvariant,
gx_variant TYPE disvariant.

CONSTANTS : c_delt_ind(1) TYPE c VALUE 'L'.




SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS: so_ebeln FOR ekpo-ebeln, "PO number
so_matnr FOR ekpo-matnr NO INTERVALS NO-EXTENSION, "material number
so_bsart FOR ekko-bsart, "document Type
so_aedat FOR ekko-aedat, "PO date
so_werks FOR ekpo-werks. "plant
*so_banfn FOR eban-banfn, "PR number
*so_mblnr FOR mkpf-mblnr. "GRN

SELECTION-SCREEN : END OF BLOCK b1.


FORM get_data.

SELECT * INTO CORRESPONDING FIELDS OF TABLE it_data
FROM ekko INNER JOIN ekpo ON ekko~ebeln EQ ekpo~ebeln
WHERE ekpo~ebeln IN so_ebeln
AND ekpo~matnr IN so_matnr
AND ekko~bsart IN so_bsart
AND ekko~aedat IN so_aedat
AND ekpo~werks IN so_werks
AND EKPO~LOEKZ = ' '
AND EKPO~ELIKZ = ' '.
*
* CHECK sy-subrc = 0.

SELECT ebeln, bsart, aedat
FROM ekko
INTO TABLE @DATA(it_ekko)
FOR ALL ENTRIES IN @it_data
WHERE ebeln EQ @it_data-ebeln.



SELECT ebeln, ebelp, LOEKZ, txz01, matnr, menge, ELIKZ
FROM ekpo
INTO TABLE @DATA(it_ekpo)
FOR ALL ENTRIES IN @it_data
WHERE ebeln EQ @it_data-ebeln
AND ebelp EQ @it_data-ebelp
and LOEKZ = ' '
AND aedat EQ @it_data-aedat
And ELIKZ = ' '.

SELECT ebeln, ebelp, LOEKZ, menge FROM ekpo INTO TABLE @DATA(lt_pototal)
FOR ALL ENTRIES IN @it_ekpo
WHERE ebeln = @it_ekpo-ebeln.



SELECT banfn, matnr, menge, badat, ebeln , ebelp
FROM eban
INTO TABLE @DATA(it_eban)
FOR ALL ENTRIES IN @it_data
WHERE banfn EQ @it_data-banfn.
* AND ebeln EQ @it_data-ebeln.


SHIFT eban-matnr LEFT DELETING LEADING '0'.
*
* SELECT mblnr, bwart, menge, budat_mkpf, ebeln, zeile
* FROM mseg
* INTO TABLE @DATA(it_mseg)
* FOR ALL ENTRIES IN @it_data
* WHERE ebeln EQ @it_data-ebeln
* AND bwart IN ('101','102','103','104','105','106').

SELECT mblnr, bwart, bpmng, budat_mkpf, ebeln, zeile, ebelp
FROM mseg
INTO TABLE @DATA(it_mseg1)
FOR ALL ENTRIES IN @it_data
WHERE ebeln EQ @it_data-ebeln
AND ebelp EQ @it_data-ebelp
AND bwart IN ('101','105').

SELECT mblnr, bwart, bpmng, budat_mkpf, ebeln, zeile, ebelp
FROM mseg
INTO TABLE @DATA(it_mseg2)
FOR ALL ENTRIES IN @it_data
WHERE ebeln EQ @it_data-ebeln
AND bwart IN ('102','106','122').

LOOP AT it_mseg1 INTO DATA(wa_mseg1) .
MOVE-CORRESPONDING wa_mseg1 TO wa_mseg_sum.
COLLECT wa_mseg_sum INTO it_mseg1_sum.
ENDLOOP.

LOOP AT it_mseg2 INTO DATA(wa_mseg2).
MOVE-CORRESPONDING wa_mseg2 TO wa_mseg_sum.
COLLECT wa_mseg_sum INTO it_mseg2_sum.
ENDLOOP.

LOOP AT it_mseg1_sum INTO wa_mseg_sum.
DATA(lv_tabix) = sy-tabix.
CASE wa_mseg_sum-bwart.
WHEN '101'.
READ TABLE it_mseg2_sum INTO DATA(wa_mseg2_sum) WITH KEY ebeln = wa_mseg_sum-ebeln
bwart = '102'
ebelp = wa_mseg_sum-ebelp .
IF sy-subrc = 0.
wa_mseg_sum-bpmng = wa_mseg_sum-bpmng - wa_mseg2_sum-bpmng.
ENDIF.

READ TABLE it_mseg2_sum INTO wa_mseg2_sum WITH KEY ebeln = wa_mseg_sum-ebeln
bwart = '122'
ebelp = wa_mseg_sum-ebelp .
IF sy-subrc = 0.
wa_mseg_sum-bpmng = wa_mseg_sum-bpmng - wa_mseg2_sum-bpmng.
ENDIF.

WHEN '105'.
READ TABLE it_mseg2_sum INTO wa_mseg2_sum WITH KEY ebeln = wa_mseg_sum-ebeln
bwart = '106'
ebelp = wa_mseg_sum-ebelp .
IF sy-subrc = 0.
wa_mseg_sum-bpmng = wa_mseg_sum-bpmng - wa_mseg2_sum-bpmng.
ENDIF.

ENDCASE.
MODIFY it_mseg1_sum FROM wa_mseg_sum INDEX lv_tabix.
ENDLOOP.

""Get GRN quantity of movement type 103 subract from 104 or 124.
SELECT mblnr, bwart, bpmng, budat_mkpf, ebeln, zeile, ebelp
FROM mseg
INTO TABLE @DATA(it_mseg3)
FOR ALL ENTRIES IN @it_data
WHERE ebeln EQ @it_data-ebeln
AND ebelp EQ @it_data-ebelp
AND bwart IN ('103').

SELECT mblnr, bwart, bpmng, budat_mkpf, ebeln, zeile, ebelp
FROM mseg
INTO TABLE @DATA(it_mseg4)
FOR ALL ENTRIES IN @it_data
WHERE ebeln EQ @it_data-ebeln
AND bwart IN ('104','105','124').

LOOP AT it_mseg3 INTO DATA(wa_mseg3) .
MOVE-CORRESPONDING wa_mseg3 TO wa_mseg1_sum.
COLLECT wa_mseg1_sum INTO it_mseg3_sum.
ENDLOOP.

LOOP AT it_mseg4 INTO DATA(wa_mseg4).
MOVE-CORRESPONDING wa_mseg4 TO wa_mseg1_sum.
COLLECT wa_mseg1_sum INTO it_mseg4_sum.
ENDLOOP.

LOOP AT it_mseg3_sum INTO wa_mseg1_sum.
DATA(lv_tabix1) = sy-tabix.
CASE wa_mseg1_sum-bwart.
WHEN '103'.
READ TABLE it_mseg4_sum INTO DATA(wa_mseg4_sum) WITH KEY ebeln = wa_mseg1_sum-ebeln
bwart = '104'
ebelp = wa_mseg1_sum-ebelp .
IF sy-subrc = 0.
wa_mseg1_sum-bpmng = wa_mseg1_sum-bpmng - wa_mseg4_sum-bpmng.
ENDIF.

READ TABLE it_mseg4_sum INTO wa_mseg4_sum WITH KEY ebeln = wa_mseg1_sum-ebeln
bwart = '124'
ebelp = wa_mseg1_sum-ebelp .
IF sy-subrc = 0.
wa_mseg1_sum-bpmng = wa_mseg1_sum-bpmng - wa_mseg4_sum-bpmng.
ENDIF.


READ TABLE it_mseg4_sum INTO wa_mseg4_sum WITH KEY ebeln = wa_mseg1_sum-ebeln
bwart = '105'
ebelp = wa_mseg1_sum-ebelp .
IF sy-subrc = 0.
wa_mseg1_sum-bpmng = wa_mseg1_sum-bpmng - wa_mseg4_sum-bpmng.
ENDIF.

* wa_mseg1_sum-menge = wa_mseg1_sum-menge - wa_mseg_sum-menge.
ENDCASE.
MODIFY it_mseg3_sum FROM wa_mseg1_sum INDEX lv_tabix1.
clear wa_mseg1_sum-bpmng.
ENDLOOP.

* loop at it_mseg1_sum into wa_mseg_sum.
* wa_mseg1_sum-menge = wa_mseg1_sum-menge - wa_mseg_sum-menge.
* MODIFY it_mseg1_sum FROM wa_mseg_sum.
* APPEND
* ENDLOOP.




""calculate total gr quantity
TYPES: BEGIN OF grtotal,
ebeln TYPE mseg-ebeln,
* ebelp TYPE mseg-ebelp,
menge TYPE mseg-bpmng,
END OF grtotal.

DATA: it_sum TYPE TABLE OF grtotal,
wa_sum TYPE grtotal.

DATA: total TYPE i.
SELECT ebeln, bpmng FROM mseg INTO TABLE @DATA(lt_total)
FOR ALL ENTRIES IN @it_mseg1
WHERE ebeln = @it_mseg1-ebeln.



LOOP AT lt_total INTO DATA(w_total).
MOVE w_total TO wa_sum.
COLLECT wa_sum INTO it_sum.
ENDLOOP.
* group by ebeln.

""End of GR TOTAL Calculation


LOOP AT it_data INTO ls_data.

SORT it_ekpo BY ebeln ebelp loekz ELIKZ .
READ TABLE it_ekpo REFERENCE INTO DATA(id_ekpo)
WITH KEY ebeln = ls_data-ebeln
ebelp = ls_data-ebelp
LOEKZ = ' '
ELIKZ = ' ' BINARY SEARCH .

IF sy-subrc = 0.
ls_output-ebeln = id_ekpo->ebeln.
ls_output-ebelp = id_ekpo->ebelp.
ls_output-matnr = id_ekpo->matnr.
ls_output-txz01 = id_ekpo->txz01.
ls_output-po_quan = id_ekpo->menge.
ENDIF.

SORT it_ekko BY ebeln.
READ TABLE it_ekko REFERENCE INTO DATA(id_ekko)
WITH KEY ebeln = ls_data-ebeln BINARY SEARCH.
IF sy-subrc = 0.
ls_output-aedat = id_ekko->aedat.
ENDIF.


SORT it_eban BY banfn matnr ebelp.
READ TABLE it_eban REFERENCE INTO DATA(id_eban)
WITH KEY banfn = ls_data-banfn
matnr = ls_data-matnr
ebelp = ls_data-ebelp BINARY SEARCH.

IF sy-subrc = 0.
ls_output-banfn = id_eban->banfn.
ls_output-prquan = id_eban->menge.
ls_output-badat = id_eban->badat.
ENDIF.
SHIFT ls_output-matnr LEFT DELETING LEADING '0'.
CLEAR id_eban.

""calculate total po quantity ...
Data : ptotal type mseg-bpmng.
LOOP AT lt_pototal INTO DATA(w_pototal) where ebeln = ls_data-ebeln and LOEKZ = ' '.
ptotal = ptotal + w_pototal-menge.
ENDLOOP.


READ TABLE it_mseg1_sum REFERENCE INTO DATA(id_mseg)
WITH KEY ebeln = ls_data-ebeln
ebelp = ls_data-ebelp.
IF sy-subrc = 0.
ls_output-menge = id_mseg->bpmng.
ENDIF.

""GR TOTAL QTY
Data : gtotal type mseg-bpmng.
LOOP AT it_mseg1_sum INTO DATA(w_gototal) where ebeln = ls_data-ebeln.
gtotal = gtotal + w_gototal-bpmng.
ENDLOOP.


READ TABLE it_mseg3_sum REFERENCE INTO DATA(id_mseg1)
WITH KEY ebeln = ls_data-ebeln
ebelp = ls_data-ebelp.
IF sy-subrc = 0.

ls_output-menge1 = id_mseg1->bpmng.

ENDIF.


"" Gather GR NUMBER INTO ONE CELL

LOOP AT it_mseg1 INTO wa_mseg1 WHERE ebeln = ls_output-ebeln AND ebelp = ls_output-ebelp.
CONCATENATE wa_mseg1-mblnr ls_output-gr_num INTO ls_output-gr_num SEPARATED BY ','.
ENDLOOP.

""FOR 103 GET GR NUMBER INTO 1 CELL.

LOOP AT it_mseg3 INTO wa_mseg3 WHERE ebeln = ls_output-ebeln AND ebelp = ls_output-ebelp.
CONCATENATE wa_mseg3-mblnr ls_output-gr_num INTO ls_output-gr_num SEPARATED BY ','.
ENDLOOP.


**GR percent per line item

IF ls_output-menge IS NOT INITIAL.
ls_output-linepercent = ( ls_output-menge / ls_output-po_quan ) * 100.
* ls_output-linepercent = |{ ls_output-linepercent }| & | | & |{ '%' }|.
* CONCATENATE ls_output-linepercent'%' INTO ls_output-linepercent.
ENDIF.



READ TABLE it_sum REFERENCE INTO DATA(id_sum)
WITH KEY ebeln = ls_data-ebeln.
IF sy-subrc = 0.
ls_output-grquan = id_sum->menge.
ENDIF.


* IF ls_output-menge IS NOT INITIAL.
ls_output-percent = ( gtotal / ptotal ) * 100.
* ENDIF.

"" Subtract PO from GR Quantity.

IF ls_output-po_quan IS NOT INITIAL.
ls_output-subtract = ls_output-po_quan - ls_output-menge .
ENDIF.


APPEND ls_output TO it_output.
* DELETE ADJACENT DUPLICATES FROM it_output COMPARING ebeln banfn mblnr.
* DELETE it_output WHERE BANFN EQ ''.

CLEAR: ls_output,gtotal,ptotal.

ENDLOOP.
ENDFORM.



FORM display_alv.

IF it_output IS NOT INITIAL.

PERFORM get_fieldcatalog.


* gs_layout-cell_merge = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
i_callback_program = sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
i_callback_top_of_page = 'TOP-OF-PAGE'
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
is_layout = gs_layout
it_fieldcat = gt_fcat
IT_EXCLUDING = IT_MENU
* IT_SPECIAL_GROUPS =
it_sort = gt_sort
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
i_save = 'A'
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* O_PREVIOUS_SRAL_HANDLER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = it_output
EXCEPTIONS
program_error = 1
OTHERS = 2.

ELSE.
MESSAGE 'Purchasing document closed or No values found!' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.

ENDFORM.



FORM get_fieldcatalog.

CLEAR: gs_fcat.
REFRESH: gt_fcat.

gs_fcat-col_pos = 1.
gs_fcat-fieldname = 'MATNR'.
gs_fcat-tabname = 'IT_OUTPUT'.
gs_fcat-seltext_m = 'Item #'.
* gs_fcat-outputlen = 20.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.

gs_fcat-col_pos = 2.
gs_fcat-fieldname = 'TXZ01'.
gs_fcat-tabname = 'IT_OUTPUT'.
gs_fcat-seltext_m = 'Item Name'.
* gs_fcat-outputlen = 20.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.

gs_fcat-col_pos = 3.
gs_fcat-fieldname = 'BANFN'.
gs_fcat-tabname = 'IT_OUTPUT'.
gs_fcat-seltext_m = 'PR #'.
* gs_fcat-outputlen = 20.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.

gs_fcat-col_pos = 4.
gs_fcat-fieldname = 'BADAT'.
gs_fcat-tabname = 'IT_OUTPUT'.
gs_fcat-seltext_m = 'PR Date'.
* gs_fcat-outputlen = 20.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.

gs_fcat-col_pos = 5.
gs_fcat-fieldname = 'PRQUAN'.
gs_fcat-tabname = 'IT_OUTPUT'.
gs_fcat-seltext_m = 'PR Quantity'.
gs_fcat-decimals_out = '2'.
* gs_fcat-outputlen = 20.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.

gs_fcat-col_pos = 6.
gs_fcat-fieldname = 'EBELN'.
gs_fcat-tabname = 'IT_OUTPUT'.
gs_fcat-seltext_m = 'PO #'.
* gs_fcat-outputlen = 20.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.

gs_fcat-col_pos = 7.
gs_fcat-fieldname = 'AEDAT'.
gs_fcat-tabname = 'IT_OUTPUT'.
gs_fcat-seltext_m = 'PO Date'.
* gs_fcat-outputlen = 20.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.

gs_fcat-col_pos = 8.
gs_fcat-fieldname = 'PO_QUAN'.
gs_fcat-tabname = 'IT_OUTPUT'.
gs_fcat-seltext_m = 'PO Quantity'.
gs_fcat-decimals_out = '2'.
* gs_fcat-outputlen = 20.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.

gs_fcat-col_pos = 9.
gs_fcat-fieldname = 'GR_NUM'.
gs_fcat-tabname = 'IT_OUTPUT'.
gs_fcat-seltext_m = 'GRN #'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.

* gs_fcat-col_pos = 10.
* gs_fcat-fieldname = 'BUDAT_MKPF'.
* gs_fcat-tabname = 'IT_OUTPUT'.
* gs_fcat-seltext_m = 'GRN Date'.
* APPEND gs_fcat TO gt_fcat.
* CLEAR gs_fcat.

gs_fcat-col_pos = 10.
gs_fcat-fieldname = 'MENGE'.
gs_fcat-tabname = 'IT_OUTPUT'.
gs_fcat-seltext_m = 'GRN QTY'.
gs_fcat-decimals_out = '2'.
* gs_fcat-do_sum = 'X'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.

gs_fcat-col_pos = 11.
gs_fcat-fieldname = 'SUBTRACT'.
gs_fcat-tabname = 'IT_OUTPUT'.
gs_fcat-seltext_m = 'GRN Balance QTY '.
gs_fcat-decimals_out = '2'.
gs_fcat-emphasize = 'C700'.
* gs_fcat-do_sum = 'X'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.


gs_fcat-col_pos = 12.
gs_fcat-fieldname = 'MENGE1'.
gs_fcat-tabname = 'IT_OUTPUT'.
gs_fcat-seltext_m = 'Blocked Stock 103'.
gs_fcat-decimals_out = '2'.
gs_fcat-emphasize = 'C600'.
* gs_fcat-do_sum = 'X'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.

gs_fcat-col_pos = 13.
gs_fcat-fieldname = 'LINEPERCENT'.
gs_fcat-tabname = 'IT_OUTPUT'.
gs_fcat-seltext_m = 'GRN% Per Item'.
gs_fcat-decimals_out = '0'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.

gs_fcat-col_pos = 14.
gs_fcat-fieldname = 'PERCENT'.
* gs_fcat-tabname = 'IT_DATA'.
gs_fcat-seltext_m = 'Total GRN% vs PO'.
gs_fcat-emphasize = 'C502'.
gs_fcat-decimals_out = '0'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.

gs_sort-spos = 6.
gs_sort-fieldname = 'EBELN'.
gs_sort-up = 'X'.
gs_sort-subtot = 'X'.
APPEND gs_sort TO gt_sort.

ENDFORM.

FORM sort.
CLEAR gs_sort.
REFRESH: gt_sort.
gs_sort-spos = 1.
gs_sort-fieldname = 'EBELN'.
gs_sort-tabname = 'IT_OUTPUT'.
gs_sort-up = 'X'.
gs_sort-subtot = 'X'.
APPEND gs_sort TO gt_sort.
ENDFORM.




FORM top-of-page.

CONSTANTS : lc_s TYPE c VALUE 'S',
lc_h TYPE c VALUE 'H'.

DATA : lt_header TYPE slis_t_listheader,
ls_header TYPE slis_listheader,
lv_to(2) TYPE c,
lv_count TYPE i.


ls_header-typ = 'H'.
ls_header-info = 'POPRS Report'.
APPEND ls_header TO lt_header.
CLEAR ls_header.


ls_header-typ = 'S'.
ls_header-key = 'Date: '.

* CONCATENATE SO_DATE-LOW+6(2) '.' SO_DATE-LOW+4(2) '.' SO_DATE-LOW(4) ' to ' ` ` SO_DATE-HIGH+6(2) '.' SO_DATE-HIGH+4(2) '.' SO_DATE-HIGH(4) INTO LS_HEADER-INFO.
* APPEND LS_HEADER TO LT_HEADER.
* CLEAR: LS_HEADER.
* APPEND LS_HEADER TO LT_HEADER.


DESCRIBE TABLE it_output LINES lv_count.

* lv_count = lines(it_output).

ls_header-typ = lc_s.
ls_header-key = 'No of Records : '.
ls_header-info = lv_count.
APPEND ls_header TO lt_header.
CLEAR ls_header.


CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = lt_header.

CLEAR lt_header.

ENDFORM.

Attachments

blog1.png (38.8 kB)