Hai, Dalam Inventory Management, transaksi daftar dokumen material digunakan untuk membuat daftar dokumen material. Ini adalah transaksi yang sangat populer yang sering kita gunakan terutama bagi yang berhubungan dengan inventory.
Kali ini kita akan membahas bagaimana menambahkan 3 field di MB51 dengan cara copy ke z program.
- Copy Z Program
- Add fields yang dibutuhkan ke Variable
Itab
- Tambahkan Proses pada subrutin
DATA_SELECTION
FORM DATA_SELECTION . "#EC CALLED
* Data selection routine for standard access
* process SELECT command depending on the
* required material selection
if g_cnt_matnr_total > 0 and
g_cnt_matnr_total = g_cnt_matnr_i_eq.
* work with .. for all entries ...
select (g_t_fields)
into corresponding fields of table itab
from mkpf inner join mseg
on mkpf~mandt = mseg~mandt
and mkpf~mblnr = mseg~mblnr
and mkpf~mjahr = mseg~mjahr
for all entries in matnr
where matnr = matnr-low
and MKPF~BUDAT in BUDAT
and MSEG~BWART in BWART
and MSEG~CHARG in CHARG
and MSEG~KUNNR in KUNNR
and MSEG~LGORT in LGORT
and MSEG~LIFNR in LIFNR
and MSEG~SOBKZ in SOBKZ
and MKPF~USNAM in USNAM
and MKPF~VGART in VGART
and MSEG~WERKS in WERKS
and MKPF~XBLNR in XBLNR
.
else.
* work with the select command as usual
select (g_t_fields)
into corresponding fields of table itab
from mkpf inner join mseg
on mkpf~mandt = mseg~mandt
and mkpf~mblnr = mseg~mblnr
and mkpf~mjahr = mseg~mjahr
WHERE MKPF~BUDAT in BUDAT
and MSEG~BWART in BWART
and MSEG~CHARG in CHARG
and MSEG~KUNNR in KUNNR
and MSEG~LGORT in LGORT
and MSEG~LIFNR in LIFNR
and MSEG~MATNR in MATNR
and MSEG~SOBKZ in SOBKZ
and MKPF~USNAM in USNAM
and MKPF~VGART in VGART
and MSEG~WERKS in WERKS
and MKPF~XBLNR in XBLNR
.
endif.
IF itab[] IS NOT INITIAL.
DATA: LT_AFKO TYPE TABLE OF AFKO WITH HEADER LINE,
LT_AFPO TYPE TABLE OF AFPO WITH HEADER LINE,
LT_MAKT TYPE TABLE OF MAKT WITH HEADER LINE.
SELECT * FROM AFKO
INTO TABLE LT_AFKO
FOR ALL ENTRIES IN ITAB
WHERE AUFNR = ITAB-AUFNR.
IF SY-SUBRC = 0.
SELECT * FROM AFpo
INTO TABLE LT_AFpO
FOR ALL ENTRIES IN LT_AFKO
WHERE aufnr = LT_AFKO-aufnr.
SELECT * FROM MAKT
INTO TABLE LT_MAKT
FOR ALL ENTRIES IN LT_AFKO
WHERE MATNR = LT_AFKO-PLNBEZ
AND SPRAS = SY-LANGU.
ENDIF.
IF LT_AFKO[] IS NOT INITIAL.
LOOP AT ITAB.
READ TABLE LT_AFKO WITH KEY AUFNR = ITAB-AUFNR.
IF SY-SUBRC = 0.
ITAB-PLNBEZ = LT_AFKO-PLNBEZ.
READ TABLE LT_AFPO WITH KEY AUFNR = LT_AFKO-AUFNR.
IF SY-SUBRC = 0.
ITAB-PLNBEZ_C = LT_AFPO-CHARG.
ENDIF.
READ TABLE LT_MAKT WITH KEY MATNR = LT_AFKO-PLNBEZ.
IF SY-SUBRC = 0.
ITAB-PLNBEZ_T = LT_MAKT-MAKTX.
ENDIF.
MODIFY ITAB.
ENDIF.
ENDLOOP.
ENDIF.
ENDIF.
ENDFORM. " DATA_SELECTION
- Tambahkan Field tsb di subrutine
build_fieldcatalog
Secara standard jika ada penambahan field di report, maka report tsb belum bisa menampilkan data tersebut ketika di jalankan, maka kita perlu menambahkan nya di program report kita pada subrutin build_fieldcatalog .
Berikut merupakan contoh sample code program tsb:
FORM build_fieldcatalog.
REFRESH fc_flat.
LOOP AT rtt WHERE FIELDNAME EQ 'MATNR'.
RTT-TABNAME = 'AFKO'.
RTT-FIELDNAME = 'PLNBEZ'.
APPEND RTT.
RTT-FIELDNAME = 'PLNBEZ_T'.
APPEND RTT.
RTT-FIELDNAME = 'PLNBEZ_C'.
APPEND RTT.
ENDLOOP.
LOOP AT rtt.
CLEAR fc_flat.
fc_flat-fieldname = rtt-fieldname.
fc_flat-ref_tabname = rtt-tabname.
fc_flat-ref_fieldname = rtt-fieldname.
CASE rtt-cqindicator.
WHEN 'C'. fc_flat-cfieldname = rtt-cqfieldname.
WHEN 'Q'. fc_flat-qfieldname = rtt-cqfieldname.
ENDCASE.
fc_flat-tabname = 'LIST'.
IF rtt-output_position = '00'.
fc_flat-no_out = 'X'.
ENDIF.
* PS_PSP_PNR need a special conversion and refers to another field
IF rtt-fieldname = 'PS_PSP_PNR'.
fc_flat-fieldname = 'PSPID'.
fc_flat-ref_tabname = 'PRPS'.
fc_flat-ref_fieldname = 'POSID'.
ENDIF.
*ENHANCEMENT-POINT rm07docs_07 SPOTS es_rm07docs.
APPEND fc_flat.
* Some fields have apendixes (e.g. MATNR is followed by MAKTX)
CLEAR fc_flat.
CASE rtt-fieldname.
WHEN 'MATNR'.
fc_flat-fieldname = 'MAKTX'.
fc_flat-tabname = 'LIST'.
fc_flat-ref_tabname = 'MAKT'.
WHEN 'AUFNR'.
fc_flat-tabname = 'LIST'.
WHEN 'PLNBEZ'.
fc_flat-tabname = 'LIST'.
WHEN 'PLNBEZ_T'.
fc_flat-tabname = 'LIST'.
WHEN 'PLNBEZ_C'.
fc_flat-tabname = 'LIST'.
WHEN 'WERKS'.
fc_flat-fieldname = 'NAME1'.
fc_flat-tabname = 'LIST'.
fc_flat-ref_tabname = 'T001W'.
WHEN 'BWART'.
fc_flat-fieldname = 'BTEXT'.
fc_flat-tabname = 'LIST'.
fc_flat-ref_tabname = 'T156T'.
WHEN 'NPLNR'. "215929
fc_flat-fieldname = 'VORNR'. "215929
fc_flat-tabname = 'LIST'. "215929
fc_flat-ref_tabname = 'RESB'. "215929
WHEN 'EBELN'.
fc_flat-fieldname = 'LONGNUM'.
fc_flat-tabname = 'LIST'.
fc_flat-ref_tabname = 'GOITEM'.
WHEN OTHERS.
CONTINUE.
ENDCASE.
fc_flat-no_out = 'X'.
APPEND fc_flat.
ENDLOOP.
* For the hierarchic ALV, the header fields are extracted
* and activated.
REFRESH fc_hier.
LOOP AT fc_flat.
IF fc_flat-fieldname eq 'PLNBEZ'.
fc_flat-seltext_l = 'Material Order'.
fc_flat-seltext_m = 'Material Order'.
fc_flat-seltext_s = 'Mat. Order'.
MODIFY fc_flat.
ENDIF.
IF fc_flat-fieldname eq 'PLNBEZ_T'.
fc_flat-seltext_l = 'Mat. Order Text'.
fc_flat-seltext_m = 'Mat. Order Text'.
fc_flat-seltext_s = 'Mat. Order Text'.
MODIFY fc_flat.
ENDIF.
IF fc_flat-fieldname eq 'PLNBEZ_C'.
fc_flat-seltext_l = 'Order Batch'.
fc_flat-seltext_m = 'Order Batch'.
fc_flat-seltext_s = 'Order Batch'.
MODIFY fc_flat.
ENDIF.
fc_hier = fc_flat.
CASE fc_flat-fieldname.
WHEN 'MATNR' OR 'MAKTX' OR 'WERKS' OR 'NAME1'.
fc_hier-tabname = 'HEADER'.
fc_hier-no_out = ' '.
ENDCASE.
APPEND fc_hier.
ENDLOOP.
ENDFORM.
- Selesai dan Jalankan