Here's a report using simple ALV to display and transfer to Excel.
And it run macro also, to create column lines.
Place your excel template using tcode OAOR
for include program, please refer to this link:
ZGEN_EXCELZAB_ALVFile Excel (contain macro)This program also contains :
- how to get Material initial stock balance (MB5B) (include backposting - stock in transfer)
- how to get Material end stock balance
- how to get Quantity received or quantity required for MRP (MD04)
- outstanding PO Qty
- display the report using ALV and Excel
REPORT zmm_realisasi NO STANDARD PAGE HEADING LINE-SIZE 237.
TABLES : mara, t001w, makt, mbewh, mardh.
DATA : BEGIN OF t_mara OCCURS 0,
matnr LIKE mara-matnr,
meins LIKE mara-meins,
mtart LIKE mara-mtart,
maktx LIKE makt-maktx,
END OF t_mara,
BEGIN OF t_mbewh OCCURS 0,
matnr LIKE mbewh-matnr,
bwkey LIKE mbewh-bwkey,
lbkum LIKE mbewh-lbkum,
END OF t_mbewh,
BEGIN OF t_t_mbewh OCCURS 0,
matnr LIKE ekpo-matnr,
werks LIKE ekpo-werks,
END OF t_t_mbewh,
BEGIN OF t_mbew OCCURS 0,
matnr LIKE mbew-matnr,
bwkey LIKE mbew-bwkey,
lbkum LIKE mbew-lbkum,
lfgja LIKE mbew-lfgja,
lfmon LIKE mbew-lfmon,
END OF t_mbew,
BEGIN OF t_mardh OCCURS 0,
matnr LIKE mardh-matnr,
werks LIKE mardh-werks,
lgort LIKE mardh-lgort,
umlme LIKE mardh-umlme,
END OF t_mardh,
BEGIN OF t_qtypo OCCURS 0,
bedat LIKE ekko-bedat,
ebeln LIKE ekpo-ebeln,
ebelp LIKE ekpo-ebelp,
matnr LIKE ekpo-matnr,
werks LIKE ekpo-werks,
menge LIKE ekpo-menge,
elikz LIKE ekpo-elikz,
END OF t_qtypo,
BEGIN OF t_qtypo2 OCCURS 0,
matnr LIKE ekpo-matnr,
werks LIKE ekpo-werks,
menge LIKE ekpo-menge,
END OF t_qtypo2,
t_qtypooutst LIKE t_qtypo2 OCCURS 0 WITH HEADER LINE,
BEGIN OF t_io OCCURS 0,
budat LIKE mkpf-budat,
mblnr LIKE mseg-mblnr,
zeile LIKE mseg-zeile,
werks LIKE mseg-werks,
matnr LIKE mseg-matnr,
bwart LIKE mseg-bwart,
shkzg LIKE mseg-shkzg,
menge LIKE mseg-menge,
END OF t_io,
BEGIN OF t_outpo OCCURS 0,
bedat LIKE ekko-bedat,
matnr LIKE ekpo-matnr,
werks LIKE ekpo-werks,
ebeln LIKE ekpo-ebeln,
ebelp LIKE ekpo-ebelp,
belnr LIKE ekbe-belnr,
buzei LIKE ekbe-buzei,
bwart LIKE ekbe-bwart,
menge LIKE ekbe-menge,
END OF t_outpo,
* begin of t_outpo occurs 0,
* bedat like ekko-bedat,
* matnr like ekpo-matnr,
* werks like ekpo-werks,
* ebeln like ekpo-ebeln,
* ebelp like ekpo-ebelp,
* bwart like ekbe-bwart,
* menge like ekbe-menge,
* end of t_outpo,
* ekko~bedat
* ekpo~matnr ekpo~werks
* ekbe~ebeln ekbe~ebelp
* ekbe~bwart ekbe~menge
BEGIN OF t_input2 OCCURS 0,
matnr LIKE mseg-matnr,
werks LIKE mseg-werks,
menge LIKE mseg-menge,
END OF t_input2,
BEGIN OF t_rata2 OCCURS 0,
matnr LIKE mseg-matnr,
werks LIKE mseg-werks,
menge LIKE mseg-menge,
rbagi(1) TYPE p DECIMALS 0,
END OF t_rata2,
t_outpt2 LIKE t_input2 OCCURS 0 WITH HEADER LINE,
t_kumi2 LIKE t_input2 OCCURS 0 WITH HEADER LINE,
t_kumo2 LIKE t_input2 OCCURS 0 WITH HEADER LINE,
t_other LIKE t_input2 OCCURS 0 WITH HEADER LINE,
t_kumot LIKE t_input2 OCCURS 0 WITH HEADER LINE,
t_outstx LIKE t_input2 OCCURS 0 WITH HEADER LINE,
t_stockcur LIKE t_input2 OCCURS 0 WITH HEADER LINE,
t_io2 LIKE t_io OCCURS 0 WITH HEADER LINE,
t_iobck LIKE t_io OCCURS 0 WITH HEADER LINE.
DATA : BEGIN OF t_data OCCURS 0,
matnr LIKE mara-matnr,
maktx LIKE makt-maktx,
meins LIKE mara-meins,
werks LIKE t001w-werks,
awal LIKE mbewh-lbkum,
qtypo LIKE ekpo-menge,
input LIKE mseg-menge,
kumi LIKE mseg-menge,
outst LIKE ekpo-menge,
estpk LIKE ekpo-menge,
outpt LIKE mseg-menge,
kumo LIKE mseg-menge,
pctus LIKE ekpo-zwert,
other LIKE mseg-menge,
kumot LIKE mseg-menge,
akhir LIKE mbew-lbkum,
rata2 LIKE mseg-menge,
tod(8) TYPE p DECIMALS 0, " LIKE ekpo-zwert,
END OF t_data.
DATA : v_year LIKE mbewh-lfgja,
v_lastmo LIKE mbewh-lfmon,
v_tglawal LIKE sy-datum,
v_trata_b LIKE sy-datum,
v_trata_e LIKE sy-datum,
x TYPE i,
v_var(30),
v_bln(2).
DATA: w_msg(50).
INCLUDE zab_alv.
INCLUDE zgen_excel.
**************************************
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME.
SELECT-OPTIONS : s_matnr FOR mara-matnr .
SELECT-OPTIONS : s_werks FOR t001w-werks OBLIGATORY.
PARAMETERS: p_mtart LIKE mara-mtart OBLIGATORY.
PARAMETERS: p_date LIKE sy-datum OBLIGATORY.
SELECTION-SCREEN END OF BLOCK blk1.
SELECTION-SCREEN BEGIN OF BLOCK blc2 WITH FRAME TITLE text-s20.
PARAMETERS : rb_chk1 RADIOBUTTON GROUP a DEFAULT 'X',
rb_chk2 RADIOBUTTON GROUP a.
SELECTION-SCREEN END OF BLOCK blc2.
***************************************
INITIALIZATION.
* ALV init
PERFORM f_alv_init.
AT SELECTION-SCREEN.
PERFORM authority_check CHANGING w_msg.
IF NOT w_msg IS INITIAL.
MESSAGE e398(00) WITH w_msg.
EXIT.
ENDIF.
*--
START-OF-SELECTION.
PERFORM f_getdata.
IF rb_chk1 = 'X'.
PERFORM f_displayalv.
ELSE.
WRITE:/ 'Transfer to excel complete !.'.
WRITE:/ 'Please save excel file before closing this page'.
PERFORM f_to_excel.
ENDIF.
*-----------------------------------------------------------------------
FORM authority_check CHANGING msg.
DATA: BEGIN OF lit_t001w OCCURS 0,
werks LIKE t001w-werks,
END OF lit_t001w.
CLEAR msg.
SELECT werks
FROM t001w
INTO TABLE lit_t001w
WHERE werks IN s_werks.
IF lit_t001w[] IS INITIAL.
w_msg = 'Plant Not Found'.
ELSE.
LOOP AT lit_t001w.
AUTHORITY-CHECK OBJECT 'M_BEST_WRK'
ID 'ACTVT' FIELD '03'
ID 'WERKS' FIELD lit_t001w-werks.
IF sy-subrc <> 0.
CONCATENATE 'Not Authorized to Plant' lit_t001w-werks
INTO w_msg
SEPARATED BY space.
EXIT.
ENDIF.
ENDLOOP. "lit_t001w
ENDIF.
ENDFORM. "authority_check
*&---------------------------------------------------------------------*
*& Form F_GETDATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_getdata.
DATA : v_estimasi_a LIKE mdps-mng01.
SELECT a~matnr a~meins a~mtart b~maktx
INTO CORRESPONDING FIELDS OF TABLE t_mara
FROM mara AS a INNER JOIN makt AS b
ON a~matnr = b~matnr
WHERE a~matnr IN s_matnr
AND a~mtart = p_mtart.
* TGL UTK RATA2 OUTPUT, AMBIL 4 BULAN KEBELAKANG, CURRENT TDK TRMSK.
CALL FUNCTION 'HR_PT_ADD_MONTH_TO_DATE'
EXPORTING
dmm_datin = p_date
dmm_count = '4'
dmm_oper = '-'
dmm_pos = space
IMPORTING
dmm_daout = v_trata_b.
v_trata_b+6(2) = '01'.
CALL FUNCTION 'HR_PT_ADD_MONTH_TO_DATE'
EXPORTING
dmm_datin = p_date
dmm_count = '1'
dmm_oper = '-'
dmm_pos = space
IMPORTING
dmm_daout = v_trata_e.
CALL FUNCTION 'LAST_DAY_OF_MONTHS'
EXPORTING
day_in = v_trata_e
IMPORTING
last_day_of_month = v_trata_e.
v_year = v_trata_e(4).
v_lastmo = v_trata_e+4(2).
v_tglawal = p_date.
v_tglawal+6(2) = '01'.
IF NOT t_mara[] IS INITIAL.
* STOCK AWAL
SELECT * FROM mbewh
INTO CORRESPONDING FIELDS OF TABLE t_mbewh
FOR ALL ENTRIES IN t_mara
WHERE matnr = t_mara-matnr
AND bwkey IN s_werks
AND lfgja = v_year
AND lfmon = v_lastmo.
* stock awal - stock in transfer
SELECT * FROM mardh
INTO CORRESPONDING FIELDS OF TABLE t_mardh
FOR ALL ENTRIES IN t_mara
WHERE matnr = t_mara-matnr
AND werks IN s_werks
AND lfgja = v_year
AND lfmon = v_lastmo
AND umlme > 0.
* STOCK AKHIR
SELECT * FROM mbew
INTO CORRESPONDING FIELDS OF TABLE t_mbew
FOR ALL ENTRIES IN t_mara
WHERE matnr = t_mara-matnr
AND bwkey IN s_werks.
* AND lfgja = p_date(4)
* AND lfmon = p_date+4(2).
* QTY PO
SELECT ekko~bedat
ekpo~ebeln ekpo~ebelp ekpo~werks ekpo~matnr ekpo~menge ekpo~elikz
FROM ekko AS ekko
INNER JOIN ekpo AS ekpo ON ekko~ebeln = ekpo~ebeln
INTO CORRESPONDING FIELDS OF TABLE t_qtypo
FOR ALL ENTRIES IN t_mara
* WHERE ekko~bedat >= v_tglawal AND ekko~bedat <= p_date
WHERE ekko~bedat <= p_date
AND ekpo~werks IN s_werks
AND ekpo~matnr = t_mara-matnr
AND ekpo~loekz NE 'L'.
* COLLECT QTY PO
LOOP AT t_qtypo.
IF t_qtypo-bedat >= v_tglawal.
* qty po kolom F
* COLLECT t_qtypo INTO t_qtypo2.
READ TABLE t_qtypo2 WITH KEY matnr = t_qtypo-matnr.
IF sy-subrc = 0.
t_qtypo2-menge = t_qtypo2-menge + t_qtypo-menge.
MODIFY t_qtypo2 INDEX sy-tabix.
ELSE.
t_qtypo2-matnr = t_qtypo-matnr.
t_qtypo2-menge = t_qtypo-menge.
t_qtypo2-werks = t_qtypo-werks.
APPEND t_qtypo2.
ENDIF.
ENDIF.
* qty all outstanding po per material
IF t_qtypo-elikz NE 'X'.
READ TABLE t_qtypooutst WITH KEY matnr = t_qtypo-matnr.
IF sy-subrc = 0.
t_qtypooutst-menge = t_qtypooutst-menge + t_qtypo-menge.
MODIFY t_qtypooutst INDEX sy-tabix.
ELSE.
t_qtypooutst-matnr = t_qtypo-matnr.
t_qtypooutst-menge = t_qtypo-menge.
t_qtypooutst-werks = t_qtypo-werks.
APPEND t_qtypooutst.
ENDIF.
ENDIF.
ENDLOOP.
* INPUT HARI INI (P_DATE) DAN KUMULATIF (AWAL S/D P_DATE)
* SELECT mkpf~budat mseg~matnr mseg~bwart mseg~menge
* FROM mkpf AS mkpf
* INNER JOIN mseg AS mseg
* ON mkpf~mblnr = mseg~mblnr AND mkpf~mjahr = mseg~mjahr
* INTO CORRESPONDING FIELDS OF TABLE t_io
* FOR ALL ENTRIES IN t_mara
* WHERE mkpf~budat >= v_tglawal AND mkpf~budat <= p_date
* AND mseg~matnr = t_mara-matnr
* AND mseg~werks IN s_werks
* AND mseg~bwart IN ('101', '102', '261', '262' ).
SELECT mkpf~budat mseg~mblnr mseg~zeile mseg~werks mseg~matnr
mseg~bwart mseg~shkzg mseg~menge
FROM mkpf AS mkpf
INNER JOIN mseg AS mseg
ON mkpf~mblnr = mseg~mblnr AND mkpf~mjahr = mseg~mjahr
INTO CORRESPONDING FIELDS OF TABLE t_io
FOR ALL ENTRIES IN t_mara
WHERE mkpf~budat >= v_trata_b AND mkpf~budat <= p_date
AND mseg~matnr = t_mara-matnr
AND mseg~werks IN s_werks
AND mseg~xauto EQ space.
* AND mseg~bwart IN ('101', '102', '261', '262' ).
* all outstanding po, utk material2 selected di mbewh
IF NOT t_mbewh[] IS INITIAL.
LOOP AT t_mbewh.
t_t_mbewh-matnr = t_mbewh-matnr.
t_t_mbewh-werks = t_mbewh-bwkey.
APPEND t_t_mbewh.
ENDLOOP.
SELECT ekko~bedat
ekpo~ebeln ekpo~ebelp
ekpo~matnr ekpo~werks
ekbe~belnr ekbe~buzei ekbe~bwart ekbe~menge
FROM ekko AS ekko
INNER JOIN ekpo AS ekpo ON ekko~ebeln = ekpo~ebeln
INNER JOIN ekbe AS ekbe ON ekpo~ebeln = ekbe~ebeln
AND ekpo~ebelp = ekbe~ebelp
INTO CORRESPONDING FIELDS OF TABLE t_outpo
FOR ALL ENTRIES IN t_t_mbewh
WHERE ( ekpo~elikz EQ space AND ekpo~loekz EQ space )
AND ekko~bedat <= p_date
AND ekpo~matnr = t_t_mbewh-matnr
AND ekpo~werks = t_t_mbewh-werks
AND ekbe~budat <= p_date.
* calculate var pengurang total qty all po outst per mat
LOOP AT t_outpo.
IF t_outpo-bwart = '101' OR t_outpo-bwart = '123'.
READ TABLE t_outstx WITH KEY matnr = t_outpo-matnr
werks = t_outpo-werks.
IF sy-subrc = 0.
t_outstx-menge = t_outstx-menge + t_outpo-menge.
MODIFY t_outstx INDEX sy-tabix.
ELSE.
t_outstx-matnr = t_outpo-matnr.
t_outstx-menge = t_outpo-menge.
t_outstx-werks = t_outpo-werks.
APPEND t_outstx.
ENDIF.
ELSEIF t_outpo-bwart = '102' OR t_outpo-bwart = '122'.
READ TABLE t_outstx WITH KEY matnr = t_outpo-matnr
werks = t_outpo-werks.
IF sy-subrc = 0.
t_outstx-menge = t_outstx-menge - t_outpo-menge.
MODIFY t_outstx INDEX sy-tabix.
ELSE.
t_outstx-matnr = t_outpo-matnr.
t_outstx-menge = t_outpo-menge * - 1.
t_outstx-werks = t_outpo-werks.
APPEND t_outstx.
ENDIF.
ENDIF.
ENDLOOP.
ENDIF.
DATA : v_tglx LIKE sy-datum,
var_menge LIKE mseg-menge.
SORT t_io BY budat werks mblnr matnr.
LOOP AT t_io.
*---
IF t_io-budat = p_date.
* I/O HARI INI
IF t_io-bwart = '101'.
READ TABLE t_input2 WITH KEY matnr = t_io-matnr
werks = t_io-werks.
IF sy-subrc = 0.
t_input2-menge = t_input2-menge + t_io-menge.
MODIFY t_input2 INDEX sy-tabix.
ELSE.
t_input2-matnr = t_io-matnr.
t_input2-menge = t_io-menge.
t_input2-werks = t_io-werks.
APPEND t_input2.
ENDIF.
ELSEIF t_io-bwart = '102'.
READ TABLE t_input2 WITH KEY matnr = t_io-matnr
werks = t_io-werks.
IF sy-subrc = 0.
t_input2-menge = t_input2-menge - t_io-menge.
MODIFY t_input2 INDEX sy-tabix.
ELSE.
t_input2-matnr = t_io-matnr.
t_input2-menge = t_io-menge * -1.
t_input2-werks = t_io-werks.
APPEND t_input2.
ENDIF.
ELSEIF t_io-bwart = '261'.
READ TABLE t_outpt2 WITH KEY matnr = t_io-matnr
werks = t_io-werks.
IF sy-subrc = 0.
t_outpt2-menge = t_outpt2-menge + t_io-menge.
MODIFY t_outpt2 INDEX sy-tabix.
ELSE.
t_outpt2-matnr = t_io-matnr.
t_outpt2-menge = t_io-menge.
t_outpt2-werks = t_io-werks.
APPEND t_outpt2.
ENDIF.
ELSEIF t_io-bwart = '262'.
READ TABLE t_outpt2 WITH KEY matnr = t_io-matnr
werks = t_io-werks.
IF sy-subrc = 0.
t_outpt2-menge = t_outpt2-menge - t_io-menge.
MODIFY t_outpt2 INDEX sy-tabix.
ELSE.
t_outpt2-matnr = t_io-matnr.
t_outpt2-menge = t_io-menge * -1.
t_outpt2-werks = t_io-werks.
APPEND t_outpt2.
ENDIF.
ELSE.
*---
* OTHERS - H = MINUS
IF t_io-shkzg = 'H'. t_io-menge = t_io-menge * -1. ENDIF.
READ TABLE t_other WITH KEY matnr = t_io-matnr
werks = t_io-werks.
IF sy-subrc = 0.
t_other-menge = t_other-menge + t_io-menge.
MODIFY t_other INDEX sy-tabix.
ELSE.
t_other-matnr = t_io-matnr.
t_other-menge = t_io-menge.
t_other-werks = t_io-werks.
APPEND t_other.
ENDIF.
* balikin lagi qty nya
IF t_io-shkzg = 'H'.
t_io-menge = t_io-menge * -1.
ENDIF.
ENDIF.
ENDIF.
*---
* I/O KUM DAN OTHER KUM
IF t_io-budat >= v_tglawal AND t_io-budat <= p_date.
IF t_io-bwart = '101'.
READ TABLE t_kumi2 WITH KEY matnr = t_io-matnr
werks = t_io-werks.
IF sy-subrc = 0.
t_kumi2-menge = t_kumi2-menge + t_io-menge.
MODIFY t_kumi2 INDEX sy-tabix.
ELSE.
t_kumi2-matnr = t_io-matnr.
t_kumi2-menge = t_io-menge.
t_kumi2-werks = t_io-werks.
APPEND t_kumi2.
ENDIF.
ELSEIF t_io-bwart = '102'.
READ TABLE t_kumi2 WITH KEY matnr = t_io-matnr
werks = t_io-werks.
IF sy-subrc = 0.
t_kumi2-menge = t_kumi2-menge - t_io-menge.
MODIFY t_kumi2 INDEX sy-tabix.
ELSE.
t_kumi2-matnr = t_io-matnr.
t_kumi2-menge = t_io-menge * -1.
t_kumi2-werks = t_io-werks.
APPEND t_kumi2.
ENDIF.
ELSEIF t_io-bwart = '261'.
READ TABLE t_kumo2 WITH KEY matnr = t_io-matnr
werks = t_io-werks.
IF sy-subrc = 0.
t_kumo2-menge = t_kumo2-menge + t_io-menge.
MODIFY t_kumo2 INDEX sy-tabix.
ELSE.
t_kumo2-matnr = t_io-matnr.
t_kumo2-menge = t_io-menge.
t_kumo2-werks = t_io-werks.
APPEND t_kumo2.
ENDIF.
ELSEIF t_io-bwart = '262'.
READ TABLE t_kumo2 WITH KEY matnr = t_io-matnr
werks = t_io-werks.
IF sy-subrc = 0.
t_kumo2-menge = t_kumo2-menge - t_io-menge.
MODIFY t_kumo2 INDEX sy-tabix.
ELSE.
t_kumo2-matnr = t_io-matnr.
t_kumo2-menge = t_io-menge * -1.
t_kumo2-werks = t_io-werks.
APPEND t_kumo2.
ENDIF.
ELSE.
*---
* KUMULATIF OTHERS - H = MINUS
IF t_io-shkzg = 'H'. t_io-menge = t_io-menge * -1. ENDIF.
READ TABLE t_kumot WITH KEY matnr = t_io-matnr
werks = t_io-werks.
IF sy-subrc = 0.
t_kumot-menge = t_kumot-menge + t_io-menge.
MODIFY t_kumot INDEX sy-tabix.
ELSE.
t_kumot-matnr = t_io-matnr.
t_kumot-menge = t_io-menge.
t_kumot-werks = t_io-werks.
APPEND t_kumot.
ENDIF.
* balikin lagi qty nya
IF t_io-shkzg = 'H'. t_io-menge = t_io-menge * -1. ENDIF.
ENDIF.
*---
* hitung stock current di mseg, S = MINUS
IF t_io-shkzg = 'S'. t_io-menge = t_io-menge * -1. ENDIF.
READ TABLE t_stockcur WITH KEY matnr = t_io-matnr
werks = t_io-werks.
IF sy-subrc = 0.
t_stockcur-menge = t_stockcur-menge - t_io-menge.
MODIFY t_stockcur INDEX sy-tabix.
ELSE.
t_stockcur-matnr = t_io-matnr.
t_stockcur-menge = t_io-menge * -1.
t_stockcur-werks = t_io-werks.
APPEND t_stockcur.
ENDIF.
* balikin lagi qty nya
IF t_io-shkzg = 'S'. t_io-menge = t_io-menge * -1. ENDIF.
ENDIF.
*---
* RATA2 OUTPUT
IF t_io-budat >= v_trata_b
AND t_io-budat <= v_trata_e
AND ( t_io-bwart = '261' OR t_io-bwart = '262' ) .
IF t_io-bwart = '261'.
READ TABLE t_rata2 WITH KEY matnr = t_io-matnr
werks = t_io-werks.
IF sy-subrc = 0.
IF v_bln = t_io-budat+4(2).
ELSE.
t_rata2-rbagi = t_rata2-rbagi + 1.
v_bln = t_io-budat+4(2).
ENDIF.
t_rata2-menge = t_rata2-menge + t_io-menge.
MODIFY t_rata2 INDEX sy-tabix.
ELSE.
t_rata2-matnr = t_io-matnr.
t_rata2-menge = t_io-menge.
t_rata2-werks = t_io-werks.
t_rata2-rbagi = 1.
v_bln = t_io-budat+4(2).
APPEND t_rata2.
ENDIF.
ELSEIF t_io-bwart = '262'.
READ TABLE t_rata2 WITH KEY matnr = t_io-matnr
werks = t_io-werks.
IF sy-subrc = 0.
IF v_bln = t_io-budat+4(2).
ELSE.
t_rata2-rbagi = t_rata2-rbagi + 1.
v_bln = t_io-budat+4(2).
ENDIF.
t_rata2-menge = t_rata2-menge - t_io-menge.
MODIFY t_rata2 INDEX sy-tabix.
ELSE.
t_rata2-matnr = t_io-matnr.
t_rata2-menge = t_io-menge * -1.
t_rata2-werks = t_io-werks.
t_rata2-rbagi = 1.
v_bln = t_io-budat+4(2).
APPEND t_rata2.
ENDIF.
ENDIF.
* count jumlah bulan utk variable pembagi rata2
* if v_bln = t_io-budat+4(2).
*
* else.
* v_monthr = v_monthr + 1.
* v_bln = t_io-budat+4(2).
* endif.
ENDIF.
ENDLOOP.
ENDIF.
* COMBINE ALL DATA INTO 1 TABLE.
SORT t_mara BY matnr.
SORT t_mbewh BY matnr bwkey.
SORT t_mbew BY matnr bwkey.
SORT t_qtypo BY matnr werks.
SORT t_input2 BY matnr werks.
SORT t_outpt2 BY matnr werks.
SORT t_kumi2 BY matnr werks.
SORT t_kumo2 BY matnr werks.
SORT t_rata2 BY matnr werks.
SORT t_other BY matnr werks.
SORT t_kumot BY matnr werks.
* HEADER EXCEL
CONCATENATE 'Tgl. ' p_date+6(2) '-' p_date+4(2) '-' p_date(4)
INTO v_var SEPARATED BY space.
PERFORM modify_to_cell USING 9 2 v_var.
x = 7.
LOOP AT t_mbewh.
CLEAR t_data.
v_estimasi_a = 0.
* MATERIAL DATA
t_data-matnr = t_mbewh-matnr.
READ TABLE t_mara WITH KEY matnr = t_mbewh-matnr.
t_data-maktx = t_mara-maktx.
t_data-meins = t_mara-meins.
t_data-werks = t_mbewh-bwkey.
* STOCK AWAL
t_data-awal = t_mbewh-lbkum.
var_menge = 0.
* stock awal v.4 - ditambahkan dengan transaksi back-posting.
SELECT mkpf~budat mseg~mblnr mseg~zeile mseg~werks mseg~matnr
mseg~bwart mseg~shkzg mseg~menge
FROM mkpf AS mkpf
INNER JOIN mseg AS mseg
ON mkpf~mblnr = mseg~mblnr AND mkpf~mjahr = mseg~mjahr
INTO CORRESPONDING FIELDS OF TABLE t_iobck
WHERE mkpf~budat <= v_trata_e AND mkpf~bldat > v_trata_e
AND mseg~matnr = t_data-matnr
AND mseg~werks = t_data-werks.
IF NOT t_iobck[] IS INITIAL.
LOOP AT t_iobck.
IF t_iobck-bwart EQ '321' OR t_iobck-bwart EQ '322' OR
t_iobck-bwart EQ '343' OR t_iobck-bwart EQ '344' OR
t_iobck-bwart EQ '349' OR t_iobck-bwart EQ '350' .
ELSE.
IF t_iobck-shkzg = 'H'.
t_iobck-menge = t_iobck-menge * -1.
ENDIF.
var_menge = var_menge + t_iobck-menge.
ENDIF.
ENDLOOP.
t_data-awal = t_data-awal + var_menge.
ENDIF.
* stock awal v.4 - dikurangi dengan stock in transfer
LOOP AT t_mardh WHERE matnr = t_data-matnr AND werks = t_data-werks.
t_data-awal = t_data-awal - t_mardh-umlme.
ENDLOOP.
* QTY PO
READ TABLE t_qtypo2 WITH KEY matnr = t_mbewh-matnr
werks = t_mbewh-bwkey.
IF sy-subrc = 0.
t_data-qtypo = t_qtypo2-menge.
ENDIF.
* INPUT HARI INI
READ TABLE t_input2 WITH KEY matnr = t_mbewh-matnr
werks = t_mbewh-bwkey.
IF sy-subrc = 0.
t_data-input = t_input2-menge.
ENDIF.
* KUM INPUT
READ TABLE t_kumi2 WITH KEY matnr = t_mbewh-matnr
werks = t_mbewh-bwkey.
IF sy-subrc = 0.
t_data-kumi = t_kumi2-menge.
ENDIF.
* OUTSTANDING PO QTY, ALL PO QTY DARI SEJAK LIVE - EKBE(BWART 101,102,
*123,122)
t_data-outst = 0.
READ TABLE t_qtypooutst WITH KEY matnr = t_mbewh-matnr
werks = t_mbewh-bwkey.
IF sy-subrc = 0.
READ TABLE t_outstx WITH KEY matnr = t_mbewh-matnr
werks = t_mbewh-bwkey.
IF sy-subrc = 0.
t_data-outst = t_qtypooutst-menge - t_outstx-menge.
ELSE.
t_data-outst = t_qtypooutst-menge.
ENDIF.
ENDIF.
* OUTPUT HARI INI
READ TABLE t_outpt2 WITH KEY matnr = t_mbewh-matnr
werks = t_mbewh-bwkey.
IF sy-subrc = 0.
t_data-outpt = t_outpt2-menge.
ENDIF.
* KUM OUTPUT
READ TABLE t_kumo2 WITH KEY matnr = t_mbewh-matnr
werks = t_mbewh-bwkey.
IF sy-subrc = 0.
t_data-kumo = t_kumo2-menge.
ENDIF.
* ESTIMASI PAKAI
PERFORM f_get_md01 USING v_tglawal t_mbewh-matnr t_mbewh-bwkey
CHANGING v_estimasi_a.
t_data-estpk = v_estimasi_a + t_data-kumo.
* PERSEN USAGE
IF t_data-estpk = 0.
t_data-pctus = 0.
ELSE.
t_data-pctus = ( t_data-kumo / t_data-estpk ) * 100.
ENDIF.
* OTHERS
READ TABLE t_other WITH KEY matnr = t_mbewh-matnr
werks = t_mbewh-bwkey.
IF sy-subrc = 0.
t_data-other = t_other-menge.
ENDIF.
* KUM OTHER
READ TABLE t_kumot WITH KEY matnr = t_mbewh-matnr
werks = t_mbewh-bwkey.
IF sy-subrc = 0.
t_data-kumot = t_kumot-menge.
ENDIF.
** STOCK AKHIR, v.2
t_data-akhir = 0.
IF p_date = sy-datum.
* kalau hari ini, brati ambil dari mbew lfgja dan lfmon = now.
READ TABLE t_mbew WITH KEY matnr = t_mbewh-matnr
bwkey = t_mbewh-bwkey
lfgja = sy-datum(4)
lfmon = sy-datum+4(2).
IF sy-subrc = 0 AND t_mbew-lbkum > 0.
t_data-akhir = t_mbew-lbkum.
ENDIF.
ENDIF.
IF t_data-akhir = 0.
* stock awal + transaksi (stock cur)
READ TABLE t_stockcur WITH KEY matnr = t_data-matnr
werks = t_data-werks.
IF sy-subrc = 0.
t_data-akhir = t_data-awal + t_stockcur-menge.
ELSE.
t_data-akhir = t_data-awal .
ENDIF.
ENDIF.
* kalau masih 0 juga, pake cara trakhir.
IF t_data-akhir = 0.
DATA : temp_mbewh LIKE mbewh OCCURS 0 WITH HEADER LINE,
v_mbewh(6), var_ok(1).
* CARI DATA DARI T_MBEWH TRAKHIR YG LBKUM > 0.
SELECT * FROM mbewh
INTO CORRESPONDING FIELDS OF TABLE temp_mbewh
* FOR ALL ENTRIES IN t_mara
WHERE matnr = t_mbewh-matnr
AND bwkey = t_mbewh-bwkey
AND lbkum > 0 ORDER BY lfgja DESCENDING lfmon DESCENDING.
* ditambah dgn transaksi dari awal bulan selanjutnya - tgl yg diinput
CLEAR : var_ok.
LOOP AT temp_mbewh.
CONCATENATE temp_mbewh-lfgja temp_mbewh-lfmon INTO v_mbewh.
var_ok = 'N'.
IF v_mbewh < p_date(6).
var_ok = 'Y'.
EXIT.
ENDIF.
ENDLOOP.
IF var_ok NE 'Y'.
CLEAR temp_mbewh.
t_data-akhir = 0.
ELSE.
v_tglx = '00000000'.
* ambil transaksi dari awal bulan temp_mbewh-lfmon + 1 smp p_date
CONCATENATE temp_mbewh-lfgja temp_mbewh-lfmon '01' INTO v_tglx.
var_menge = 0.
CLEAR t_io2.
REFRESH t_io2.
CALL FUNCTION 'HR_PT_ADD_MONTH_TO_DATE'
EXPORTING
dmm_datin = v_tglx
dmm_count = '1'
dmm_oper = '+'
dmm_pos = space
IMPORTING
dmm_daout = v_tglx.
SELECT mkpf~budat mseg~mblnr mseg~zeile mseg~werks mseg~matnr
mseg~bwart mseg~shkzg mseg~menge
FROM mkpf AS mkpf
INNER JOIN mseg AS mseg
ON mkpf~mblnr = mseg~mblnr AND mkpf~mjahr = mseg~mjahr
INTO CORRESPONDING FIELDS OF TABLE t_io2
WHERE mkpf~budat >= v_tglx AND mkpf~budat <= p_date
AND mseg~matnr = t_data-matnr
AND mseg~werks = t_data-werks.
LOOP AT t_io2.
IF t_io2-bwart EQ '321' OR t_io2-bwart EQ '322' OR
t_io2-bwart EQ '343' OR t_io2-bwart EQ '344' OR
t_io2-bwart EQ '349' OR t_io2-bwart EQ '350' .
ELSE.
IF t_io2-shkzg = 'H'. t_io2-menge = t_io2-menge * -1. ENDIF.
var_menge = var_menge + t_io2-menge.
ENDIF.
ENDLOOP.
t_data-akhir = temp_mbewh-lbkum + var_menge.
ENDIF.
ENDIF.
* RATA2 OUTPUT
READ TABLE t_rata2 WITH KEY matnr = t_mbewh-matnr
werks = t_mbewh-bwkey.
IF sy-subrc = 0.
t_data-rata2 = t_rata2-menge / t_rata2-rbagi.
ENDIF.
* T O D
IF t_data-akhir = 0 OR t_data-rata2 = 0.
t_data-tod = 0.
ELSE.
t_data-tod = t_data-akhir / ( t_data-rata2 / 25 ) .
ENDIF.
* filter yg 0 ga usah di add.
IF t_data-awal = 0
AND t_data-qtypo = 0
AND t_data-input = 0
AND t_data-kumi = 0
AND t_data-outst = 0
AND t_data-estpk = 0
AND t_data-kumo = 0
AND t_data-pctus = 0
AND t_data-other = 0
AND t_data-kumot = 0
AND t_data-akhir = 0
AND t_data-rata2 = 0
AND t_data-tod = 0.
ELSE.
APPEND t_data.
* PREPARE EXCEL
PERFORM modify_to_cell USING 1 x t_data-matnr.
PERFORM modify_to_cell USING 2 x t_data-maktx.
PERFORM modify_to_cell USING 3 x t_data-meins.
PERFORM modify_to_cell USING 4 x t_data-werks.
PERFORM append_to_cell USING 'C' 5 x t_data-awal.
PERFORM append_to_cell USING 'C' 6 x t_data-qtypo.
PERFORM append_to_cell USING 'C' 7 x t_data-input.
PERFORM append_to_cell USING 'C' 8 x t_data-kumi.
PERFORM append_to_cell USING 'C' 9 x t_data-outst.
PERFORM append_to_cell USING 'C' 10 x t_data-estpk.
PERFORM append_to_cell USING 'C' 11 x t_data-outpt.
PERFORM append_to_cell USING 'C' 12 x t_data-kumo.
PERFORM append_to_cell USING 'C' 13 x t_data-pctus.
PERFORM append_to_cell USING 'C' 14 x t_data-other.
PERFORM append_to_cell USING 'C' 15 x t_data-kumot.
PERFORM append_to_cell USING 'C' 16 x t_data-akhir.
PERFORM append_to_cell USING 'C' 17 x t_data-rata2.
PERFORM append_to_cell USING 'C' 18 x t_data-tod.
x = x + 1.
ENDIF.
ENDLOOP.
x = x - 7.
PERFORM modify_to_cell USING 1 1 x.
ENDFORM. " F_GETDATA
*&---------------------------------------------------------------------*
*& Form f_get_md01
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_V_TGLAWAL text
* -->P_V_MATNR text
* -->P_V_WERKS text
* <--P_V_ESTIMASI_A text
*----------------------------------------------------------------------*
FORM f_get_md01 USING p_v_tglawal
p_v_matnr
p_v_werks
CHANGING p_v_estimasi_a.
TYPES:
BEGIN OF m61x_mdlg_r,
sign(1),
option(2),
low LIKE mdlg-lgort,
high LIKE mdlg-lgort,
END OF m61x_mdlg_r.
TYPES:
BEGIN OF m61x_mdll_r,
sign(1),
option(2),
low LIKE mdll-lbear,
high LIKE mdll-lbear,
END OF m61x_mdll_r.
TYPES:
m61x_mdlg_range TYPE m61x_mdlg_r OCCURS 0,
m61x_mdll_range TYPE m61x_mdll_r OCCURS 0.
DATA: BEGIN OF v_cm61b,
disfg LIKE t000md-disfg,
dbxxx TYPE c,
berid LIKE mdlv-berid,
berty LIKE mdlv-berty,
bertx LIKE mdlv-bertx,
werzg LIKE mdlv-werzg,
ortzg LIKE mdlv-ortzg,
lbear LIKE mdll-lbear,
mdlgx_range TYPE m61x_mdlg_range, " OCCURS 0,
mdlgy_range TYPE m61x_mdlg_range, " OCCURS 0,
mdlly_range TYPE m61x_mdll_range,
sobsl LIKE mdma-sobsl,
disgr LIKE mdma-disgr,
END OF v_cm61b.
DATA v_mt61d LIKE mt61d.
DATA v_cm61x LIKE cm61x.
DATA v_cm61w LIKE cm61w.
DATA v_t399d LIKE t399d.
DATA v_mdkp LIKE mdkp .
DATA v_cm61m LIKE cm61m .
*MRP table used in MD04
DATA i_mdpsx LIKE mdps OCCURS 0 WITH HEADER LINE.
DATA :
p_v_tglakhir LIKE sy-datum.
*get akhir bulan
CALL FUNCTION 'LAST_DAY_OF_MONTHS'
EXPORTING
day_in = p_v_tglawal
IMPORTING
last_day_of_month = p_v_tglakhir.
CALL FUNCTION 'MD_READ_MATERIAL'
EXPORTING
ewerks = p_v_werks
ematnr = p_v_matnr
IMPORTING
imt61d = v_mt61d
icm61b = v_cm61b
EXCEPTIONS
error = 1
OTHERS = 2.
*if no record found, write out error
IF sy-subrc <> 0.
* MESSAGE e000(vz) WITH 'MD_READ_MATERIAL failed on' v_matnr v_werks.
ENDIF.
CALL FUNCTION 'MD_READ_PLANT'
EXPORTING
ewerks = p_v_werks
IMPORTING
icm61w = v_cm61w
it399d = v_t399d
EXCEPTIONS
error = 01.
*CONSTRUCT MDPSX ANNOUNCEMENTS
CALL FUNCTION 'AUFBAUEN_MDPSX_ANZEIGEN'
EXPORTING
ecm61w = v_cm61w
ecm61x = v_cm61x
emt61d = v_mt61d
et399d = v_t399d
ecm61b = v_cm61b
IMPORTING
icm61m = v_cm61m
imdkp = v_mdkp
TABLES
mdpsx = i_mdpsx.
*if no record, write out error
IF sy-subrc <> 0.
* MESSAGE e000(vz) WITH 'MD04 read failed' v_matnr v_werks.
ELSE .
CALL FUNCTION 'PRUEFEN_UMTERMINIERUNG'
EXPORTING
ecm61m = v_cm61m
ecm61w = v_cm61w
emdkp = v_mdkp
et399d = v_t399d
TABLES
mdpsx = i_mdpsx.
LOOP AT i_mdpsx.
IF i_mdpsx-dat00 >= p_v_tglawal AND i_mdpsx-dat00 <= p_v_tglakhir
AND i_mdpsx-plumi = '-'.
* IF i_mdpsx-plumi = '+'.
* i_mdpsx-mng01 = i_mdpsx-mng01 * -1.
* ENDIF.
p_v_estimasi_a = p_v_estimasi_a + i_mdpsx-mng01.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM. " f_get_md01
*&---------------------------------------------------------------------*
*& Form f_displayalv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_displayalv.
* ALV Layout
PERFORM f_alv_build_layout USING :
'ZEBRA' 'X',
'NO_COLHEAD' '',
'GROUP_CHANGE_EDIT' 'X',
'F2CODE' 'F2'.
* Sort Field
* perform f_alv_sort using:
* 'T_DATA' 'ERDAT' 'X' '' ''.
* print setup
PERFORM f_build_print USING d_alv_print.
PERFORM f_create_header.
PERFORM f_alv_build_event USING:
slis_ev_top_of_page 'F_TOP_OF_PAGE', "c_top_of_page_alv,
slis_ev_user_command c_user_command.
* ALV Fieldcat
PERFORM f_build_fieldcat.
* Execute ALV Function
d_alv_varnt-variant = p_vari.
* PERFORM f_alv_grid_display TABLES t_data.
* clear t_header.
* PERFORM f_top_of_page_alv.
PERFORM f_alv_grid_display TABLES t_data.
** using '' d_alv_save.
* perform f_alv_list_display tables t_data
* using '' d_alv_save.
ENDFORM. " f_displayalv
*&---------------------------------------------------------------------*
*& Form f_build_fieldcat
*&---------------------------------------------------------------------*
* Build Fieldcat ALV
*----------------------------------------------------------------------*
FORM f_build_fieldcat .
PERFORM f_alv_build_catalog USING :
t_alv_fctlg 'T_DATA' 'MATNR' 'Material' '' ''
'' '10' '' 'X' '' '1' '1' '' '' '',
t_alv_fctlg 'T_DATA' 'MAKTX' 'Material Desc' '' ''
'' '30' '' 'X' '' '1' '2' '' '' '',
t_alv_fctlg 'T_DATA' 'MEINS' 'BaseUnit' '' ''
'' '8' '' 'X' '' '1' '3' '' '' '',
t_alv_fctlg 'T_DATA' 'WERKS' 'Plant' '' ''
'' '6' '' 'X' '' '1' '4' '' '' ''.
PERFORM f_alv_build_catalog_qty USING:
t_alv_fctlg 'T_DATA' 'AWAL' 'Stock Awal'
'MBEWH' 'LBKUM' '' '16' '' '' '' 'MEINS' '' '1' '5',
t_alv_fctlg 'T_DATA' 'QTYPO' 'QTY Po'
'EKPO' 'MENGE' '' '16' '' '' '' 'MEINS' '' '1' '6',
t_alv_fctlg 'T_DATA' 'INPUT' 'Input - HariIni'
'MSEG' 'MENGE' '' '16' '' '' '' 'MEINS' '' '1' '7',
t_alv_fctlg 'T_DATA' 'KUMI' 'Input - Kumulatif'
'MSEG' 'MENGE' '' '16' '' '' '' 'MEINS' '' '1' '8',
t_alv_fctlg 'T_DATA' 'OUTST' 'Outstanding PO'
'EKPO' 'MENGE' '' '16' '' '' '' 'MEINS' '' '1' '9',
t_alv_fctlg 'T_DATA' 'ESTPK' 'Estimasi Pakai'
'EKPO' 'MENGE' '' '16' '' '' '' 'MEINS' '' '1' '10',
t_alv_fctlg 'T_DATA' 'OUTPT' 'Output - HariIni'
'MSEG' 'MENGE' '' '16' '' '' '' 'MEINS' '' '1' '11',
t_alv_fctlg 'T_DATA' 'KUMO' 'Output - Kumulatif'
'MSEG' 'MENGE' '' '16' '' '' '' 'MEINS' '' '1' '12'.
PERFORM f_alv_build_catalog_crncy USING:
t_alv_fctlg 'T_DATA' 'PCTUS' '% Usage'
'EKPO' 'ZWERT' '16' '' '' 'WAERS' '' '' '1' '13' ''.
PERFORM f_alv_build_catalog_qty USING:
t_alv_fctlg 'T_DATA' 'OTHER' 'Other - Hari ini'
'EKPO' 'MENGE' '' '16' '' '' '' 'MEINS' '' '1' '14',
t_alv_fctlg 'T_DATA' 'KUMOT' 'Other - Kumulatif'
'MSEG' 'MENGE' '' '16' '' '' '' 'MEINS' '' '1' '15',
t_alv_fctlg 'T_DATA' 'AKHIR' 'Stock Akhir'
'MBEW' 'LBKUM' '' '16' '' '' '' 'MEINS' '' '1' '16',
t_alv_fctlg 'T_DATA' 'RATA2' 'Rata-rata Output'
'MSEG' 'MENGE' '' '16' '' '' '' 'MEINS' '' '1' '17'.
PERFORM f_alv_build_catalog_qty USING:
t_alv_fctlg 'T_DATA' 'TOD' 'T O D'
'EKPO' 'UMREZ' '' '16' '' '' '' 'MEINS' '' '1' '18'.
* perform f_alv_build_catalog_crncy using:
* t_alv_fctlg 'T_DATA' 'TOD' 'T O D'
* 'EKPO' 'UMREZ' '16' '' '' 'WAERS' '' '' '1' '17' ''.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form f_to_excel
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_to_excel.
CALL SCREEN 8999.
ENDFORM. " f_to_excel
*&---------------------------------------------------------------------*
*& Module STATUS_8999 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_8999 OUTPUT.
SET PF-STATUS '8999'.
SET TITLEBAR '8999'.
ENDMODULE. " STATUS_8999 OUTPUT
*&---------------------------------------------------------------------*
*& Module m_init OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE m_init OUTPUT.
DATA : w_para TYPE i.
PERFORM connect_to_excel USING '' "Excel in SAP
'ZMM' "Object Name
'ZMM' "Object ID
'TEMP_ZMM_REALISASI' "Descr
'' "Status Logo
''. "Logo
PERFORM select_new_sheet USING 'Sheet1'.
PERFORM formatting_rangesdef_tab.
PERFORM set_data.
*--
PERFORM run_macro_param USING 'kotak_ok'
w_para 'Sheet1'
'' '' '' '' '' '' '' '' '' '' ''.
PERFORM close_excel_link.
LEAVE TO SCREEN 0.
ENDMODULE. " m_init OUTPUT
*&---------------------------------------------------------------------*
*& Form f_create_header
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_create_header.
DATA: l_wa_listheader TYPE slis_listheader,
lv_date1(10),
lv_date2(10).
l_wa_listheader-typ = 'H'.
l_wa_listheader-key = 'LAPORAN REALISASI HARIAN'.
l_wa_listheader-info = 'LAPORAN REALISASI HARIAN'.
APPEND l_wa_listheader TO t_header.
l_wa_listheader-typ = 'A'.
l_wa_listheader-key = 'LAPORAN REALISASI HARIAN'.
CONCATENATE p_date+6(2) p_date+4(2) p_date(4) INTO
l_wa_listheader-info
SEPARATED BY '/'.
CONCATENATE 'Tgl. :' l_wa_listheader-info INTO
l_wa_listheader-info SEPARATED BY space.
APPEND l_wa_listheader TO t_header.
ENDFORM. " f_create_header
*---------------------------------------------------------------------*
* FORM F_TOP_OF_PAGE *
*---------------------------------------------------------------------*
* TOP-OF-PAGE *
*---------------------------------------------------------------------*
FORM f_top_of_page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = t_header.
ENDFORM. "F_TOP_OF_PAGE
*---------------------------------------------------------------------*
* FORM append_to_cell *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> P_CT *
* --> P_COLS *
* --> P_ROWS *
* --> P_VALUE *
*---------------------------------------------------------------------*
FORM append_to_cell USING p_ct p_cols p_rows
CHANGING p_value.
DATA : lv_value(18).
lv_value = p_value.
IF p_ct = 'C'.
PERFORM f_format_xx USING p_value CHANGING lv_value.
ENDIF.
struc_generic-column = p_cols.
struc_generic-row = p_rows.
struc_generic-value = lv_value.
APPEND struc_generic TO tcontents.
ENDFORM. " append_to_cell
*---------------------------------------------------------------------*
* FORM f_format_xx *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> FV_AMO *
* --> FV_AMOUNT *
*---------------------------------------------------------------------*
FORM f_format_xx USING fv_amo CHANGING fv_amount TYPE format_amount.
DATA : p_val TYPE p DECIMALS 2,
y TYPE i, x TYPE i.
p_val = fv_amo.
IF p_val < 0.
p_val = p_val * -1.
WRITE p_val TO fv_amount CURRENCY 'USD'.
CONCATENATE '-' fv_amount INTO fv_amount.
ELSE.
WRITE p_val TO fv_amount CURRENCY 'USD'.
ENDIF.
CONDENSE fv_amount NO-GAPS.
ENDFORM. " f_format_xx