SAP ABAP - Custom Report AR Sales Revenue
REPORT zsdr003.
INCLUDE zsdr003_01.
INCLUDE zsdr003_02.
INCLUDE zsdr003_03.
INITIALIZATION.
PERFORM get_parameter.
START-OF-SELECTION.
"Check Company Code Authorization
AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
ID 'BUKRS' FIELD p_bukrs
ID 'ACTVT' FIELD '03'.
IF sy-subrc = 0.
PERFORM get_data.
ELSE.
str_msg = |No Authorization for company code { p_bukrs }|.
MESSAGE str_msg TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
END-OF-SELECTION.
CLEAR i_layout.
PERFORM f_layout_init USING i_layout.
PERFORM f_eventtab_build USING i_events[].
i_variant-report = sy-repid.
PERFORM f_print_control.
PERFORM f_build_header_list.
PERFORM f_build_fieldcat.
PERFORM f_print_alv.
Include ZSDR003_01.
*&---------------------------------------------------------------------*
*& Include ZSDR003_01
*&---------------------------------------------------------------------*
TABLES : acdoca, vbrp, ekko, vbak, likp, vbrk, vbkd.
TYPES :
BEGIN OF ty_blart,
blart TYPE blart,
END OF ty_blart,
BEGIN OF ty_kschl,
kschl TYPE kschl,
END OF ty_kschl,
BEGIN OF ty_f4inv,
bstkd TYPE bstkd,
rbukrs TYPE bukrs,
donum TYPE vbeln_vl,
kunnr TYPE kunnr,
kname TYPE zkname,
END OF ty_f4inv,
BEGIN OF ty_f4cont,
cntrt TYPE zcntrt,
rbukrs TYPE bukrs,
donum TYPE vbeln_vl,
kunnr TYPE kunnr,
kname TYPE zkname,
END OF ty_f4cont,
BEGIN OF ty_kna1,
kunnr TYPE kna1-kunnr,
name1 TYPE adrc-name1,
name2 TYPE adrc-name2,
END OF ty_kna1.
DATA :
lt_blart TYPE TABLE OF ty_blart,
lt_kschl TYPE TABLE OF ty_kschl,
ls_blart TYPE ty_blart,
ls_kschl TYPE ty_kschl,
lt_kna1 TYPE TABLE OF ty_kna1,
ls_kna1 TYPE ty_kna1,
lt_f4inv TYPE TABLE OF ty_f4inv,
lt_f4cont TYPE TABLE OF ty_f4cont,
ls_f4inv TYPE ty_f4inv,
ls_f4cont TYPE ty_f4cont.
DATA :
lt_data TYPE TABLE OF zsrsd003,
ls_data TYPE zsrsd003,
lt_pgidoc TYPE TABLE OF zcds_sales_revenue02,
ls_pgidoc TYPE zcds_sales_revenue02,
lt_vbfa TYPE TABLE OF vbfa,
ls_vbfa TYPE vbfa,
ls_tax TYPE zcds_tax_calculation,
lt_rtab LIKE ddshretval OCCURS 0 WITH HEADER LINE,
ls_rtab TYPE ddshretval.
DATA :
v_contr TYPE char30,
xkschl TYPE kschl,
str_msg TYPE string,
indf4 TYPE char1.
DATA :
l_id TYPE thead-tdid,
l_language TYPE thead-tdspras,
l_name TYPE thead-tdname,
l_object TYPE thead-tdobject,
lt_lines TYPE TABLE OF tline,
ls_lines TYPE tline.
*Common Mandatory and Non Mandatory ALV Variables
DATA:
i_layout TYPE slis_layout_alv,
i_events TYPE slis_t_event,
i_fieldcat TYPE slis_t_fieldcat_alv,
i_print TYPE slis_print_alv,
i_list_top TYPE slis_t_listheader,
i_list_end TYPE slis_t_listheader,
i_sort TYPE slis_t_sortinfo_alv,
i_color TYPE lvc_t_scol WITH HEADER LINE,
wa_fieldcat LIKE LINE OF i_fieldcat,
i_variant LIKE disvariant,
i_selfield TYPE slis_selfield,
fcode TYPE TABLE OF sy-ucomm,
ok_code TYPE sy-ucomm,
data_count TYPE i,
header_count TYPE i,
v_total TYPE sy-pagno.
RANGES :
s_kschl FOR xkschl.
*&---------------------------------------------------------------------*
*& Constants
*&---------------------------------------------------------------------*
CONSTANTS:
yes TYPE flag VALUE 'X',
no TYPE flag VALUE space.
CONSTANTS :
c_form_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE',
c_form_before_line TYPE slis_formname VALUE 'BEFORE_LINE_OUTPUT'.
CONSTANTS:
c_vrsio(3) VALUE '000'.
CONSTANTS: c_x VALUE 'X'.
CONSTANTS: n_s VALUE ' '.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERS :
p_bukrs TYPE bukrs OBLIGATORY.
SELECT-OPTIONS:
s_budat FOR acdoca-budat,
s_kunnr FOR acdoca-kunnr,
s_vbeln FOR likp-vbeln,
s_bilnm FOR vbrk-vbeln,
s_awref FOR vbkd-bstkd,
s_contr FOR v_contr NO INTERVALS.
SELECTION-SCREEN SKIP.
PARAMETERS p_check AS CHECKBOX USER-COMMAND uc1.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-002.
PARAMETERS :
p_gjahr TYPE gjahr DEFAULT sy-datum(4) MODIF ID sc1.
SELECT-OPTIONS:
s_belnr FOR acdoca-belnr MODIF ID sc1.
SELECTION-SCREEN END OF BLOCK b2.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF screen-group1 = 'SC1' AND p_check EQ 'X'.
screen-active = 1.
MODIFY SCREEN.
ELSEIF screen-group1 = 'SC1' AND p_check NE 'X'.
screen-active = 0.
MODIFY SCREEN.
ENDIF.
IF p_bukrs IS INITIAL AND screen-name CS 'P_CHECK'.
screen-active = 0.
MODIFY SCREEN.
ELSEIF p_bukrs IS NOT INITIAL AND screen-name CS 'P_CHECK'.
screen-active = 1.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_awref-low .
CLEAR indf4.
PERFORM f4_for_inv. "
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_awref-high .
indf4 = 'X'.
PERFORM f4_for_inv.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_contr-low .
CLEAR indf4.
PERFORM f4_for_contract.
FORM f4_for_inv.
IF p_bukrs IS INITIAL.
MESSAGE 'Select company code' TYPE 'S' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
REFRESH : lt_rtab, lt_f4inv.
CLEAR lt_rtab.
SELECT * FROM zcds_sales_revenue
INTO CORRESPONDING FIELDS OF TABLE @lt_f4inv
FOR ALL ENTRIES IN @lt_blart
WHERE rbukrs = @p_bukrs AND bstkd <> ''
AND blart = @lt_blart-blart AND budat IN @s_budat.
SORT lt_f4inv BY rbukrs kunnr donum bstkd.
DELETE ADJACENT DUPLICATES FROM lt_f4inv COMPARING rbukrs kunnr donum bstkd.
CLEAR ls_f4inv.
LOOP AT lt_f4inv INTO ls_f4inv.
SELECT SINGLE adrc~name1 FROM adrc INNER JOIN kna1
ON adrc~addrnumber = kna1~adrnr
INTO ls_f4inv-kname WHERE kna1~kunnr = ls_f4inv-kunnr.
MODIFY lt_f4inv FROM ls_f4inv TRANSPORTING kname
WHERE kunnr = ls_f4inv-kunnr.
CLEAR ls_f4inv.
ENDLOOP.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'BSTKD'
value_org = 'S'
* multiple_choice = 'X'
TABLES
value_tab = lt_f4inv
return_tab = lt_rtab
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF indf4 <> 'X'.
s_awref-low = lt_rtab-fieldval.
ELSE.
s_awref-high = lt_rtab-fieldval.
ENDIF.
CLEAR indf4.
ENDFORM.
FORM f4_for_contract.
IF p_bukrs IS INITIAL.
MESSAGE 'Select company code' TYPE 'S' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
REFRESH : lt_rtab, lt_f4cont.
CLEAR lt_rtab.
SELECT * FROM zcds_sales_revenue
INTO CORRESPONDING FIELDS OF TABLE @lt_f4cont
FOR ALL ENTRIES IN @lt_blart
WHERE rbukrs = @p_bukrs AND blart = @lt_blart-blart
AND donum <> '' AND budat IN @s_budat.
SORT lt_f4cont BY rbukrs kunnr donum.
DELETE ADJACENT DUPLICATES FROM lt_f4cont COMPARING rbukrs kunnr donum.
CLEAR ls_f4cont.
LOOP AT lt_f4cont INTO ls_f4cont.
SELECT SINGLE adrc~name1 FROM adrc INNER JOIN kna1
ON adrc~addrnumber = kna1~adrnr
INTO ls_f4cont-kname WHERE kna1~kunnr = ls_f4cont-kunnr.
MODIFY lt_f4cont FROM ls_f4cont TRANSPORTING kname
WHERE kunnr = ls_f4cont-kunnr.
CLEAR : l_id, l_name.
l_id = 'ZD01'.
l_object = 'VBBK'.
l_name = ls_f4cont-donum.
l_language = sy-langu.
REFRESH lt_lines.
CALL FUNCTION 'READ_TEXT'
EXPORTING
id = l_id
language = l_language
name = l_name
object = l_object
TABLES
lines = lt_lines
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
CLEAR : ls_lines, ls_f4cont-cntrt.
READ TABLE lt_lines INTO ls_lines INDEX 1.
ls_f4cont-cntrt = ls_lines-tdline.
MODIFY lt_f4cont FROM ls_f4cont TRANSPORTING cntrt
WHERE donum = ls_f4cont-donum.
CLEAR ls_f4cont.
ENDLOOP.
DELETE lt_f4cont WHERE cntrt IS INITIAL.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'CNTRT'
value_org = 'S'
* multiple_choice = 'X'
TABLES
value_tab = lt_f4cont
return_tab = lt_rtab
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF indf4 <> 'X'.
s_contr-low = lt_rtab-fieldval.
ELSE.
s_contr-high = lt_rtab-fieldval.
ENDIF.
CLEAR indf4.
ENDFORM.
Include ZSDR003_02.
*&---------------------------------------------------------------------*
*& Include ZSDR003_02
*&---------------------------------------------------------------------*
FORM get_parameter.
SELECT * FROM zcadt_parameters INTO TABLE @DATA(lt_params)
WHERE program_name = 'R_SALES_REVENUE'.
REFRESH : lt_blart, lt_kschl, s_kschl.
LOOP AT lt_params INTO DATA(ls_params).
IF ls_params-variable_name = 'BLART'.
CLEAR ls_blart.
ls_blart-blart = ls_params-zlow.
APPEND ls_blart TO lt_blart.
ELSEIF ls_params-variable_name = 'KSCHL'.
CLEAR s_kschl.
s_kschl-sign = 'I'.
s_kschl-option = 'EQ'.
s_kschl-low = ls_params-zlow.
APPEND s_kschl TO s_kschl[].
ENDIF.
CLEAR ls_params.
ENDLOOP.
ENDFORM.
FORM get_data.
DATA ls_condt TYPE prcd_elements.
REFRESH lt_data.
SELECT * FROM zcadt_parameters INTO TABLE @DATA(lt_params)
WHERE program_name = 'R_SALES_REVENUE'.
REFRESH : lt_blart, lt_kschl, s_kschl.
LOOP AT lt_params INTO DATA(ls_params).
IF ls_params-variable_name = 'BLART'.
CLEAR ls_blart.
ls_blart-blart = ls_params-zlow.
APPEND ls_blart TO lt_blart.
ELSEIF ls_params-variable_name = 'KSCHL'.
CLEAR s_kschl.
s_kschl-sign = 'I'.
s_kschl-option = 'EQ'.
s_kschl-low = ls_params-zlow.
APPEND s_kschl TO s_kschl[].
ENDIF.
CLEAR ls_params.
ENDLOOP.
CHECK lt_blart IS NOT INITIAL.
IF p_check EQ 'X' AND s_belnr[] IS NOT INITIAL.
IF p_gjahr IS INITIAL.
MESSAGE 'Input Fiscal Year' TYPE 'S' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
SELECT * FROM zcds_sales_revenue INTO CORRESPONDING FIELDS OF TABLE @lt_data
FOR ALL ENTRIES IN @lt_blart
WHERE rbukrs = @p_bukrs AND kunnr IN @s_kunnr AND donum IN @s_vbeln
AND bstkd IN @s_awref AND blart = @lt_blart-blart AND bilnm IN @s_bilnm
AND belnr IN @s_belnr AND gjahr = @p_gjahr AND budat IN @s_budat.
ELSE.
SELECT * FROM zcds_sales_revenue INTO CORRESPONDING FIELDS OF TABLE @lt_data
FOR ALL ENTRIES IN @lt_blart
WHERE rbukrs = @p_bukrs AND kunnr IN @s_kunnr AND donum IN @s_vbeln
AND bstnk IN @s_awref AND blart = @lt_blart-blart AND bilnm IN @s_bilnm
AND budat IN @s_budat.
ENDIF.
IF lt_data IS NOT INITIAL.
SELECT * FROM zcds_tax_calculation INTO TABLE @DATA(lt_tax)
FOR ALL ENTRIES IN
@lt_data WHERE mwskz = @lt_data-mwskz AND aland = 'ID'.
REFRESH lt_pgidoc.
SELECT * FROM zcds_sales_revenue02 INTO TABLE @lt_pgidoc
FOR ALL ENTRIES IN @lt_data
WHERE vbeln_im = @lt_data-donum
AND ( vbelp_im = @lt_data-vgpos OR uecha = @lt_data-vgpos ).
"Ambil Condition Type PPN
IF s_kschl[] IS NOT INITIAL.
SELECT * FROM prcd_elements INTO TABLE @DATA(lt_condt)
FOR ALL ENTRIES IN @lt_data
WHERE knumv = @lt_data-knumv AND kschl IN @s_kschl.
ENDIF.
REFRESH lt_kna1.
SELECT kna1~kunnr adrc~name1 adrc~name2 FROM kna1 INNER JOIN adrc
ON kna1~adrnr = adrc~addrnumber
INTO TABLE lt_kna1
FOR ALL ENTRIES IN lt_data
WHERE kna1~kunnr = lt_data-kunnr.
SORT lt_kna1 BY kunnr.
SORT lt_pgidoc BY vbeln_im vbelp_im uecha.
CLEAR ls_data.
LOOP AT lt_data INTO ls_data.
* READ TABLE s_contr[] INTO s_contr with key
CLEAR ls_kna1.
READ TABLE lt_kna1 INTO ls_kna1 WITH KEY kunnr = ls_data-kunnr BINARY SEARCH.
CONCATENATE ls_kna1-name1 ls_kna1-name2 INTO ls_data-kname SEPARATED BY space.
READ TABLE lt_condt
WITH KEY knumv = ls_data-knumv kposn = ls_data-posnr TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
CLEAR ls_condt.
LOOP AT lt_condt INTO ls_condt WHERE knumv = ls_data-knumv AND kposn = ls_data-posnr.
IF ls_condt-krech = 'A'.
ls_data-txhsl = ls_data-txhsl + ( ls_data-hsl * ( ls_condt-kbetr / 100 ) ).
ls_data-txwsl = ls_data-txwsl + ( ls_data-wsl * ( ls_condt-kbetr / 100 ) ).
ls_data-txvsl = ls_data-txvsl + ( ls_data-vsl * ( ls_condt-kbetr / 100 ) ).
ENDIF.
CLEAR ls_condt.
ENDLOOP.
ENDIF.
CLEAR ls_pgidoc.
READ TABLE lt_pgidoc INTO ls_pgidoc WITH KEY vbeln_im = ls_data-donum vbelp_im = ls_data-vgpos BINARY SEARCH.
IF ls_pgidoc IS INITIAL.
READ TABLE lt_pgidoc WITH KEY vbeln_im = ls_data-donum uecha = ls_data-vgpos BINARY SEARCH TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
CLEAR ls_pgidoc.
LOOP AT lt_pgidoc INTO ls_pgidoc WHERE vbeln_im = ls_data-donum AND uecha = ls_data-vgpos.
ls_data-cogsval = ls_data-cogsval + ls_pgidoc-wsl.
ls_data-cogsact = ls_pgidoc-racct.
ls_data-cogsactname = ls_pgidoc-txt50.
CLEAR ls_pgidoc.
ENDLOOP.
ENDIF.
ELSE.
ls_data-cogsact = ls_pgidoc-racct.
ls_data-cogsactname = ls_pgidoc-txt50.
ls_data-cogsval = ls_pgidoc-wsl.
ENDIF.
IF ls_data-donum IS NOT INITIAL.
"Ambil Nomor Contract
CLEAR : l_id, l_name.
l_id = 'ZD01'.
l_object = 'VBBK'.
l_name = ls_data-donum.
l_language = sy-langu.
REFRESH lt_lines.
CALL FUNCTION 'READ_TEXT'
EXPORTING
id = l_id
language = l_language
name = l_name
object = l_object
TABLES
lines = lt_lines
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
CLEAR ls_lines.
READ TABLE lt_lines INTO ls_lines INDEX 1.
ls_data-cntrt = ls_lines-tdline.
ENDIF.
IF ls_data-blart <> 'RV'.
CLEAR : ls_data-bilnm, ls_tax.
READ TABLE lt_tax INTO ls_tax WITH KEY mwskz = ls_data-mwskz.
ls_data-txhsl = ls_data-hsl * ( ( ls_tax-kbetr / 10 ) / 100 ).
ls_data-txwsl = ls_data-wsl * ( ( ls_tax-kbetr / 10 ) / 100 ).
ls_data-txvsl = ls_data-vsl * ( ( ls_tax-kbetr / 10 ) / 100 ).
ENDIF.
MODIFY lt_data FROM ls_data TRANSPORTING kname WHERE kunnr = ls_data-kunnr.
MODIFY lt_data FROM ls_data TRANSPORTING txhsl txwsl txvsl cogsact cogsactname cogsval cntrt bilnm
WHERE rbukrs = ls_data-rbukrs AND belnr = ls_data-belnr
AND gjahr = ls_data-gjahr AND buzei = ls_data-buzei.
CLEAR ls_data.
ENDLOOP.
DELETE lt_data WHERE cntrt NOT IN s_contr.
SORT lt_data BY blart rbukrs belnr gjahr bilnm posnr.
ENDIF.
ENDFORM.
Include ZSDR003_03.
*&---------------------------------------------------------------------*
*& Include ZSDR003_03
*&---------------------------------------------------------------------*
FORM f_layout_init USING p_layout TYPE slis_layout_alv.
*&---------------------------------------------------------------------*
* Global settings for ALV worksheet, Change according to needs
*&---------------------------------------------------------------------*
* p_layout-detail_popup = yes.
* p_layout-numc_sum = yes.
p_layout-colwidth_optimize = yes.
* p_layout-zebra = no.
* p_layout-get_selinfos = yes.
* p_layout-coltab_fieldname = 'COLINFO'.
p_layout-subtotals_text = 'SubTotal'.
p_layout-totals_text = 'Total'.
* p_layout-info_fieldname = 'ROWCOLOR'.
p_layout-box_fieldname = 'RBUKRS'.
ENDFORM. " f_layout_init
FORM f_eventtab_build USING p_events TYPE slis_t_event.
*&---------------------------------------------------------------------*
DATA:
ls_event TYPE slis_alv_event.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = p_events.
** IF rcry EQ ' ' AND rgrd EQ 'X'.
READ TABLE p_events WITH KEY name = slis_ev_top_of_page INTO ls_event.
IF sy-subrc = 0.
MOVE slis_ev_top_of_page TO: ls_event-form, ls_event-name.
APPEND ls_event TO p_events.
ENDIF.
** ENDIF.
READ TABLE p_events WITH KEY name = slis_ev_end_of_page INTO ls_event.
IF sy-subrc = 0.
MOVE slis_ev_end_of_page TO: ls_event-form, ls_event-name.
APPEND ls_event TO p_events.
ENDIF.
*/..........
* READ TABLE p_events WITH KEY name = slis_ev_end_of_list INTO ls_event.
* IF sy-subrc = 0.
* MOVE slis_ev_end_of_list TO: ls_event-form, ls_event-name.
* APPEND ls_event TO p_events.
* ENDIF.
*/.........
READ TABLE p_events WITH KEY name = slis_ev_top_of_list INTO ls_event.
IF sy-subrc = 0.
MOVE slis_ev_top_of_list TO: ls_event-form, ls_event-name.
APPEND ls_event TO p_events.
ENDIF.
*/...................
READ TABLE p_events WITH KEY name = slis_ev_pf_status_set INTO ls_event.
IF sy-subrc = 0.
MOVE slis_ev_pf_status_set TO: ls_event-form, ls_event-name.
APPEND ls_event TO p_events.
ENDIF.
*/..............
READ TABLE p_events WITH KEY name = slis_ev_user_command INTO ls_event.
IF sy-subrc = 0.
MOVE slis_ev_user_command TO: ls_event-form, ls_event-name.
APPEND ls_event TO p_events.
ENDIF.
ENDFORM. " f_eventtab_build
*&---------------------------------------------------------------------*
FORM f_print_control.
*&---------------------------------------------------------------------*
i_print-no_print_selinfos = yes.
i_print-no_print_listinfos = yes.
i_print-reserve_lines = 0.
i_print-no_change_print_params = yes.
ENDFORM. " f_print_control
*&---------------------------------------------------------------------*
FORM f_build_header_list.
*&---------------------------------------------------------------------*
DATA: lwa_list_top LIKE LINE OF i_list_top,
lv_text LIKE sy-title,
gs_line TYPE slis_listheader,
vtime TYPE char12,
vtitle TYPE char50,
vtitle1 TYPE char50,
vtgl1 TYPE char10,
vtgl2 TYPE char10,
zmonth TYPE char30,
zagedas TYPE char50,
zpctr TYPE char50,
zperner TYPE char50,
vbukrs TYPE char70.
SELECT SINGLE adrc~name1 INTO vtitle
FROM adrc
INNER JOIN t001 ON adrc~addrnumber EQ t001~adrnr
WHERE t001~bukrs = p_bukrs.
CONCATENATE p_bukrs '-' vtitle
INTO vbukrs
SEPARATED BY ' '.
CLEAR lwa_list_top.
lwa_list_top-typ = 'H'.
lwa_list_top-key = no. "'Company Code '.
lwa_list_top-info = vtitle.
* lwa_list_top-info = vbukrs.
APPEND lwa_list_top TO i_list_top.
* vtitle = 'Aging Payables '.
vtitle = 'AR Sales Revenue List '.
CLEAR lwa_list_top.
lwa_list_top-typ = 'H'.
lwa_list_top-key = no.
lwa_list_top-info = vtitle. "sy-title.
APPEND lwa_list_top TO i_list_top.
DATA irows TYPE i.
DESCRIBE TABLE lt_data LINES irows.
CLEAR zagedas.
zagedas = irows.
CONDENSE zagedas.
CONCATENATE ':' zagedas 'Rows' INTO zagedas SEPARATED BY ' '.
CLEAR lwa_list_top.
lwa_list_top-typ = 'S'.
lwa_list_top-key = 'Total Data '.
lwa_list_top-info = zagedas.
APPEND lwa_list_top TO i_list_top.
DATA tamp TYPE string.
CLEAR tamp.
ENDFORM. " f_build_header_list
FORM f_build_sort.
*&---------------------------------------------------------------------*
* ini untuk pengurutan record
*----------------------------------------------------------------------*
DATA: l_sort TYPE slis_sortinfo_alv.
DEFINE def_sort.
CLEAR l_sort.
*Sort position
l_sort-spos = &1.
l_sort-fieldname = &2.
l_sort-subtot = &3.
* l_sort-up = &4.
*Sort by ascending
l_sort-up = yes. """"""""""""""""""""""" kalo mau merubah desc digan dengan no
*Separate Line between Group
l_sort-group = 'UL'.
APPEND l_sort TO i_sort.
END-OF-DEFINITION.
* def_sort '01' 'BUKRS' yes.
* def_sort '02' 'LIFNR' yes.
ENDFORM. "f_build_sort
*&--------------------------------------------------------------------*
FORM f_print_alv.
*&--------------------------------------------------------------------*
* data:
* i_save value 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* i_callback_program = gs_extract1-report
i_callback_program = sy-repid
* i_callback_pf_status_set = 'PF_STATUS_SET'
i_callback_user_command = 'USER_COMMAND'
is_layout = i_layout
it_fieldcat = i_fieldcat
i_save = 'A'
is_variant = i_variant
it_events = i_events[]
it_sort = i_sort
is_print = i_print
i_html_height_top = 25
TABLES
t_outtab = lt_data
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. "
FORM f_build_fieldcat.
PERFORM :
append_fieldcat USING 'BLART' 'Trans Type' 'CHAR' '' '' '12' '' 'X' 'LT_DATA',
append_fieldcat USING 'AUART' 'Doc Type' 'CHAR' '' '' '12' '' 'X' 'LT_DATA',
append_fieldcat USING 'BELNR' 'DocNum' 'CHAR' '' '' '10' '' 'X' 'LT_DATA',
append_fieldcat USING 'GJAHR' 'DocYear' 'NUMC' '' '' '10' '' 'X' 'LT_DATA',
append_fieldcat USING 'SONUM' 'Sales Order' 'CHAR' '' '' '10' '' 'X' 'LT_DATA',
append_fieldcat USING 'DONUM' 'Delivery' 'CHAR' '' '' '10' '' 'X' 'LT_DATA',
append_fieldcat USING 'BILNM' 'Billing Number' 'CHAR' '' '' '10' '' 'X' 'LT_DATA',
append_fieldcat USING 'BSTKD' 'Inv No' 'CHAR' '' '' '35' '' '' 'LT_DATA',
append_fieldcat USING 'CNTRT' 'Contract' 'CHAR' '' '' '20' '' '' 'LT_DATA',
* append_fieldcat USING 'LDLNO' 'List DelNo' 'CHAR' '' '' '60' '' '' 'LT_DATA',
append_fieldcat USING 'KUNNR' 'Card Code' 'CHAR' '' '' '10' '' '' 'LT_DATA',
append_fieldcat USING 'KNAME' 'Card Name' 'CHAR' '' '' '80' '' '' 'LT_DATA',
append_fieldcat USING 'BLDAT' 'Doc. Date' 'DATS' '' '' '10' '' '' 'LT_DATA',
append_fieldcat USING 'MATNR' 'Item Code' 'CHAR' '' '' '40' '' '' 'LT_DATA',
append_fieldcat USING 'MAKTX' 'Description' 'CHAR' '' '' '40' '' '' 'LT_DATA',
append_fieldcat USING 'RACCT' 'Account' 'CHAR' '' '' '40' '' '' 'LT_DATA',
append_fieldcat USING 'TXT50' 'Account Name' 'CHAR' '' '' '40' '' '' 'LT_DATA',
append_fieldcat USING 'RWCUR' 'Document Currency' 'CUKY' '' '' '40' '' '' 'LT_DATA',
append_fieldcat USING 'MSL' 'Quantity' 'QUAN' 'RUNIT' '' '20' '' '' 'LT_DATA',
append_fieldcat USING 'RUNIT' 'Unit' 'UNIT' '' '' '20' '' '' 'LT_DATA',
append_fieldcat USING 'HSL' 'AR Value' 'CURR' '' 'RHCUR' '20' '' '' 'LT_DATA',
append_fieldcat USING 'TXHSL' 'Tax Value' 'CURR' '' 'RHCUR' '20' '' '' 'LT_DATA',
append_fieldcat USING 'WSL' 'AR Value FC' 'CURR' '' 'RWCUR' '20' '' '' 'LT_DATA',
append_fieldcat USING 'TXWSL' 'Tax Value FC' 'CURR' '' 'RWCUR' '20' '' '' 'LT_DATA',
append_fieldcat USING 'VSL' 'AR Value SC' 'CURR' '' 'RVCUR' '20' '' '' 'LT_DATA',
append_fieldcat USING 'TXVSL' 'Tax Value SC' 'CURR' '' 'RVCUR' '20' '' '' 'LT_DATA',
* append_fieldcat USING 'DONUM' 'Delivery' 'CHAR' '' '' '10' '' '' 'LT_DATA',
append_fieldcat USING 'COGSACT' 'COGS Account' 'CHAR' '' '' '20' '' '' 'LT_DATA',
append_fieldcat USING 'COGSACTNAME' 'COGS Account Name' 'CHAR' '' '' '20' '' '' 'LT_DATA',
append_fieldcat USING 'COGSVAL' 'COGS Value' 'CURR' '' 'RWCUR' '20' '' '' 'LT_DATA'.
* append_fieldcat USING 'MATNR' 'Item Code' 'CURR' '' 'PSWSL' '30' '' '' 'LT_DATA',
ENDFORM.
FORM append_fieldcat USING p_fname p_fdesc p_dtype p_qfield p_cfield p_olen p_sum p_key p_tabname.
* wa_fieldcat TO i_fieldcat
DATA irows TYPE i.
CLEAR irows.
DESCRIBE TABLE i_fieldcat LINES irows.
irows = irows + 1.
CLEAR wa_fieldcat.
wa_fieldcat-col_pos = irows.
wa_fieldcat-key = p_key.
wa_fieldcat-fieldname = p_fname.
wa_fieldcat-seltext_l = p_fdesc.
wa_fieldcat-seltext_m = p_fdesc.
wa_fieldcat-seltext_s = p_fdesc.
wa_fieldcat-datatype = p_dtype.
wa_fieldcat-qfieldname = p_qfield.
wa_fieldcat-cfieldname = p_cfield.
wa_fieldcat-outputlen = p_olen.
wa_fieldcat-do_sum = p_sum.
wa_fieldcat-tabname = p_tabname.
IF p_fname = 'KUNNR'.
wa_fieldcat-ref_tabname = 'KNA1'.
ENDIF.
IF p_fname = 'RUNIT'.
* wa_fieldcat-ref_tabname = 'T006'.
wa_fieldcat-edit_mask = '==CUNIT'.
ENDIF.
IF p_fname = 'BELNR' OR p_fname = 'BILNM' OR p_fname = 'DONUM' OR p_fname = 'SONUM'.
wa_fieldcat-hotspot = 'X'.
ENDIF.
IF p_fname = 'MSL' OR p_fname CS 'HSL' OR p_fname CS 'WSL'
OR p_fname CS 'OSL' OR p_fname CS 'VSL' OR p_fname = 'COGSVAL'.
wa_fieldcat-do_sum = 'X'.
ENDIF.
IF p_fname = 'BLART'.
wa_fieldcat-ref_tabname = 'BKPF'.
* wa_fieldcat-tabname = 'BSEG'.
ENDIF.
IF p_fname = 'RBUKRS'.
wa_fieldcat-no_out = 'X'.
ENDIF.
APPEND wa_fieldcat TO i_fieldcat.
ENDFORM.
*&---------------------------------------------------------------------*
FORM top_of_page. "#EC CALLED
*&---------------------------------------------------------------------*
DATA: lflg_grid TYPE c,
lv_text LIKE sy-title.
IMPORT lflg_grid FROM MEMORY ID 'ALV_GRID_TOP_OF_PAGE'.
IF lflg_grid = yes.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
i_logo = 'LOGO_IRNC' "'ENJOYSAP_LOGO'
it_list_commentary = i_list_top.
* I_END_OF_LIST_GRID = i_list_end.
ELSE.
PERFORM f_print_header USING TEXT-100 lv_text space.
ENDIF.
ENDFORM. "TOP_OF_PAGE
*&---------------------------------------------------------------------*
FORM pf_status_set USING rt_extab TYPE slis_t_extab.
*&---------------------------------------------------------------------*
DESCRIBE TABLE rt_extab. "Avoid Extended Check Warning
SET PF-STATUS 'ZRV_PF_STAT'.
* SET PF-STATUS 'STANDARD_FULLSCREEN'.
* SET TITLEBAR 'TITLEALV'.
ENDFORM. "PF_STATUS_SET
*&---------------------------------------------------------------------*
FORM user_command USING r_ucomm
i_selfield LIKE i_selfield.
*&---------------------------------------------------------------------*
DATA: t_answer TYPE char1.
CLEAR ok_code.
ok_code = r_ucomm.
CLEAR sy-ucomm.
CASE r_ucomm.
WHEN '&IC1'.
IF i_selfield-fieldname = 'BELNR'.
CLEAR ls_data.
READ TABLE lt_data INTO ls_data INDEX i_selfield-tabindex.
IF ls_data-belnr IS NOT INITIAL.
SET PARAMETER ID 'BLN' FIELD ls_data-belnr.
SET PARAMETER ID 'BUK' FIELD p_bukrs.
* SET PARAMETER ID 'BUK' FIELD ls_data-rbukrs.
SET PARAMETER ID 'GJR' FIELD ls_data-gjahr.
CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
ENDIF.
ELSEIF i_selfield-fieldname = 'BILNM'.
CLEAR ls_data.
READ TABLE lt_data INTO ls_data INDEX i_selfield-tabindex.
IF ls_data-bilnm IS NOT INITIAL.
SET PARAMETER ID 'VF' FIELD ls_data-bilnm.
CALL TRANSACTION 'VF03' AND SKIP FIRST SCREEN.
ENDIF.
ELSEIF i_selfield-fieldname = 'DONUM'.
CLEAR ls_data.
READ TABLE lt_data INTO ls_data INDEX i_selfield-tabindex.
IF ls_data-donum IS NOT INITIAL.
SET PARAMETER ID 'VL' FIELD ls_data-donum.
CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN.
ENDIF.
ELSEIF i_selfield-fieldname = 'SONUM'.
CLEAR ls_data.
READ TABLE lt_data INTO ls_data INDEX i_selfield-tabindex.
IF ls_data-sonum IS NOT INITIAL.
SET PARAMETER ID 'AUN' FIELD ls_data-sonum.
CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
ENDIF.
ENDIF.
ENDCASE.
ENDFORM. "user_command
*&---------------------------------------------------------------------*
FORM end_of_page. "#EC CALLED
*&---------------------------------------------------------------------*
DATA: l_pos(3) TYPE n VALUE 0, l_foot(30) VALUE '*** END OF PAGE ***'.
l_pos = ( sy-linsz / 2 ) - ( strlen( l_foot ) / 2 ).
ULINE.
WRITE: /, AT l_pos l_foot.
ENDFORM. "END_OF_PAGE
*&---------------------------------------------------------------------*
FORM end_of_list. "#EC CALLED
*&---------------------------------------------------------------------*
DATA: lv_page_count(3).
DATA: l_pos(3) TYPE n VALUE 0, l_foot(30) VALUE '*** END OF REPORT ***'.
l_pos = ( sy-linsz / 2 ) - ( strlen( l_foot ) / 2 ).
ULINE.
WRITE: /, AT l_pos l_foot.
CHECK sy-ucomm EQ '&RNT'.
v_total = sy-pagno.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
i_logo = 'ENJOYSAP_LOGO'
i_end_of_list_grid = i_list_end.
ENDFORM. "END_OF_LIST
*&---------------------------------------------------------------------*
FORM f_print_header USING p_title1 LIKE sy-title
p_title2 LIKE sy-title
p_title3 LIKE sy-title.
*&---------------------------------------------------------------------*
DATA : v_temp_str TYPE string,
v_tgl1 TYPE string,
v_tgl2 TYPE string.
DATA: l_post1 TYPE i, l_post2 TYPE i, l_post3 TYPE i, l_post4 TYPE i, l_posin TYPE i.
l_post1 = ( sy-linsz / 2 ) - ( strlen( p_title1 ) / 2 ).
l_posin = sy-linsz - 35.
WRITE : / 'PT XX'.
WRITE AT l_posin 'Date :'.
WRITE sy-datum.
l_post4 = ( sy-linsz / 2 ) - ( strlen( v_temp_str ) / 2 ) - 6.
WRITE /.
WRITE AT: l_posin 'Reporting date :'.
WRITE: / 'UserID :', sy-uname.
WRITE /.
WRITE AT l_posin 'Page :'.
IF v_total IS NOT INITIAL.
WRITE : AT l_posin sy-pagno NO-ZERO, 'of', (3) v_total.
ELSE.
WRITE (3) sy-pagno NO-ZERO.
ENDIF.
ENDFORM. "f_print_header
dd
Custom structure
Mas, apakah pernah ambil data CSK2 dengan ABAP/BADI...?
ReplyDeleteBelum pernah mas
Delete