Wednesday, July 23, 2008

Change program in QA client ?

Sometimes when DEV client don’t have the proper data and sometimes when SAP do their some weird action (you know what I mean did u ? heheh) then it will takes thousands changes (hehehe is it??) when you do trial n error to repair some programs/tables/something in QA client. And when you found it error you need to go back to DEV client to repair it, and create a Change Request Number, and then transport it again to QA client, and again and again.
Have you ever think how many wasted CRs created just because of it ?

Well, my colleague gave me a tips for this. You can directly change programs/tables in QA client and see the result of it. You can do trial and error right away in your QA client (yes, right away in your QA client, means you don’t need to code in DEV and create CRs and transport). And after you satisfied with the result in QA, you can go back to DEV client, do the same thing with your programs/tables, create CRs and transport it to QA (replaced) and PROD.

This is the tips :

In QA client,

  1. Open 2 session se38, one session for program LSTRDU34 and another is LSTRDU44
  2. Find this FM : TR_EDIT_CHECK_OBJECTS_KEYS
  3. After that FM lines block, find the sy-subrc result, and put a breakpoint on that.
  4. Ok, open new session se38 again, entry your program, or se11 for your tables, or etc.
  5. Click Change program, when the debugger stopped at sy-subrc you’ve set, change the sy-subrc result from 12 or 4, to sy-subrc = 0.
  6. See the result.
  7. You can activate the programs also with this tips.

Enjoy! But be careful, because sometimes (possibly) :

  1. you enjoy changing in QA so much until when you go back to DEV you forgot what things you’ve done in QA hehehe.
  2. This can be done in PROD also, but this is depending on your authorization to change field contents in debugger.

Monday, July 14, 2008

Create MIRO with GL reference and Profitability segment using BAPI

Purpose : Create MIRO with GL reference and Profitability segment using BAPI.
Function Module : BAPI_INCOMINGINVOICE_CREATE

Field used :
*** HEADERDATA – 1 row
MIRO_HEADER-INVOICE_IND = 'X'.
MIRO_HEADER-DOC_TYPE = 'RE'.
MIRO_HEADER-DOC_DATE =
MIRO_HEADER-PSTNG_DATE = SY-DATUM.
MIRO_HEADER-REF_DOC_NO = [ reference PO number from that GR ]
MIRO_HEADER-PO_REF_NO = [ dummy PO – all item deleted ]
MIRO_HEADER-COMP_CODE = [ company code ]
MIRO_HEADER-DIFF_INV = [ vendor code ]
MIRO_HEADER-BUS_AREA = [ business area ]
MIRO_HEADER-CURRENCY = [ currency used on MIRO doc ]
MIRO_HEADER-EXCH_RATE = 1.
MIRO_HEADER-ALLOC_NMBR = [ allocation number, on my case I use same number with ref_doc_no ]
MIRO_HEADER-HEADER_TXT = [header text]


*** TAXDATA – 1 row
MIRO_HEADER-ITEM_TEXT = [header text]
MIRO_TAX-TAX_CODE = [tax code]

*** MATERIALDATA – 1 row [in my case I use only 1 material]
MIRO_MAT-INVOICE_DOC_ITEM = [sequence number]
MIRO_MAT-MATERIAL = [material number]
MIRO_MAT-VAL_AREA = [plant]
MIRO_MAT-DB_CR_IND = 'S'.
MIRO_MAT-ITEM_AMOUNT = [value amount]
MIRO_MAT-QUANTITY = [value quantity]
MIRO_MAT-BASE_UOM = [unit]
MIRO_MAT-BASE_UOM_ISO = [unit]
MIRO_MAT-TAX_CODE = [tax code]

*** GLACCOUNTDATA – multiple row, according to GL account related to journal
MIRO_GL-INVOICE_DOC_ITEM = [line number - sequence]
MIRO_GL-GL_ACCOUNT = [GL account]
MIRO_GL-ITEM_AMOUNT = [GL value amount]
MIRO_GL-DB_CR_IND = 'H'.
MIRO_GL-COMP_CODE = [company code]
MIRO_GL-TAX_CODE = [tax code]
MIRO_GL-BUS_area = [business area]

*** RUN THE BAPI
CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
EXPORTING
HEADERDATA = miro_header
IMPORTING
INVOICEDOCNUMBER = result_invoice
FISCALYEAR = result_invoice_year
TABLES
ITEMDATA = miro_item
TAXDATA = miro_tax
GLACCOUNTDATA = miro_gl
MATERIALDATA = miro_mat
RETURN = return.

*** INVOICE NUMBER
RESULT_INVOICE
RESULT_INVOICE_YEAR

*** YOU NEED TO COMMIT THE TRANSACTION, OTHERWISE THE INVOICE NUMBER WONT BE SAVED COMPLETELY

IF RESULT_INVOICE NE SPACE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
ENDIF.

Thursday, July 3, 2008

Checking is there any UserExit attached ?

This program is for checking UserExit attached in a tcode.
-----------------------------------------------------------------------------------
REPORT ZARSTEST .
TABLES : tstc, tadir, modsapt, modact, trdir, tfdir, enlfdir.
TABLES : tstct.


DATA : jtab LIKE tadir OCCURS 0 WITH HEADER LINE.
DATA : field1(30).
DATA : v_devclass LIKE tadir-devclass.

PARAMETERS : p_tcode LIKE tstc-tcode OBLIGATORY.

SELECT SINGLE * FROM tstc WHERE tcode EQ p_tcode.
IF sy-subrc EQ 0.
SELECT SINGLE * FROM tadir WHERE pgmid = 'R3TR'
AND object = 'PROG'
AND obj_name = tstc-pgmna. "'SAPLITO0'.
MOVE : tadir-devclass TO v_devclass.
IF sy-subrc NE 0.
SELECT SINGLE * FROM trdir WHERE name = tstc-pgmna.
IF trdir-subc EQ 'F'.
SELECT SINGLE * FROM tfdir WHERE pname = tstc-pgmna.
SELECT SINGLE * FROM enlfdir WHERE funcname = tfdir-funcname.
SELECT SINGLE * FROM tadir WHERE pgmid = 'R3TR'
AND object = 'FUGR'
AND obj_name EQ enlfdir-area.
MOVE : tadir-devclass TO v_devclass.
ENDIF.
ENDIF.
SELECT * FROM tadir INTO TABLE jtab
WHERE pgmid = 'R3TR'
AND object IN ('SMOD', 'SXSD')
AND devclass = v_devclass.
SELECT SINGLE * FROM tstct WHERE sprsl EQ sy-langu AND
tcode EQ p_tcode.

FORMAT COLOR COL_POSITIVE INTENSIFIED OFF.
WRITE:/(19) 'Transaction Code - ',
20(20) p_tcode,
45(50) tstct-ttext.
SKIP.
IF NOT jtab[] IS INITIAL.
WRITE:/(95) sy-uline.
FORMAT COLOR COL_HEADING INTENSIFIED ON.
WRITE:/1 sy-vline,
2 'Exit Name',
21 sy-vline ,
22 'Description',
95 sy-vline.
WRITE:/(95) sy-uline.

LOOP AT jtab.
SELECT SINGLE * FROM modsapt
WHERE sprsl = sy-langu AND
name = jtab-obj_name.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
WRITE:/1 sy-vline,
2 jtab-obj_name HOTSPOT ON,
21 sy-vline ,
22 modsapt-modtext,
95 sy-vline.
ENDLOOP.

WRITE:/(95) sy-uline.
DESCRIBE TABLE jtab.
SKIP.
FORMAT COLOR COL_TOTAL INTENSIFIED ON.
WRITE:/ 'No of Exits:' , sy-tfill.
ELSE.
FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
WRITE:/(95) 'No User Exit exists'.
ENDIF.
ELSE.
FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
WRITE:/(95) 'Transaction Code Does Not Exist'.
ENDIF.

AT LINE-SELECTION.
GET CURSOR FIELD field1.
CHECK field1(4) EQ 'JTAB'.
READ TABLE jtab with key obj_name = sy-lisel+1(19).
IF jtab-object = 'SMOD'.
SET PARAMETER ID 'MON' FIELD sy-lisel+1(10).
CALL TRANSACTION 'SMOD' AND SKIP FIRST SCREEN.
ELSE.
SET PARAMETER ID 'EXN' FIELD sy-lisel+1(19).
CALL TRANSACTION 'SE18' AND SKIP FIRST SCREEN.
ENDIF.


---------------------------------------------------
[Copy from one of my senior colleague, many Thanks ! ]

[Sample] Very Simple ALV and join with conversion MEINS

*&---------------------------------------------------------------------*
*& Report ZMM_OUTPAC
*&
*&---------------------------------------------------------------------*
*& This report is for view outstanding PO qty

*& with material PO type = ZPAC using a Very Simple ALV method
*& (MONITORING OUTSTANDING ORDER PACKAGING REPORT)
*& and a sample how to get converted MEINS (unit of measure) from a select statement

*&---------------------------------------------------------------------*

REPORT zmm_outpac LINE-SIZE 273 LINE-COUNT 35 NO STANDARD PAGE HEADING.

*&---------------------------------------------------------------------*
*& Table description
TABLES : ekko, ekpo, eket, eban, mara, makt, lfa1, mseg, t006a.

*&---------------------------------------------------------------------*
*& Data description
DATA : BEGIN OF itab OCCURS 0,
no(3),
matnr LIKE mara-matnr,
txz01 LIKE ekpo-txz01,
MSEH3 LIKE T006A-MSEH3,
badat LIKE eban-badat,
banfn LIKE ekpo-banfn,
bnfpo LIKE ekpo-bnfpo,
bedat LIKE ekko-bedat,
ebeln LIKE ekpo-ebeln,
ebelp LIKE ekpo-ebeln,
menge LIKE ekpo-menge,
eindt LIKE eket-eindt,
lifnr LIKE ekko-lifnr,
name1 LIKE lfa1-NAME1,
ketpo LIKE tline-tdline,
leado(5),
leadr(5),
kethead LIKE tline-tdline,
END OF itab.

DATA : BEGIN OF vendor_data OCCURS 0,
lifnr LIKE lfa1-lifnr,
name1 LIKE lfa1-name1,
END OF vendor_data.
DATA : BEGIN OF history OCCURS 0,
ebeln LIKE mseg-ebeln,
ebelp LIKE mseg-ebelp,
bwart LIKE mseg-bwart,
menge LIKE mseg-menge,
END OF history.

DATA : v_index LIKE sy-tabix,
v_value1 LIKE mseg-menge,
v_nettof LIKE ekpo-menge.
DATA : BEGIN OF tbl_hdr OCCURS 0,
judul(80),
field(80),
panjang(3).
DATA END OF tbl_hdr.

* for ALV
TYPE-POOLS: slis.

CONSTANTS: c_formname_top_of_page TYPE slis_formname
VALUE 'TOP_OF_PAGE'.

DATA: t_fieldcat TYPE slis_t_fieldcat_alv,
t_layout TYPE slis_layout_alv,
t_print TYPE slis_print_alv,
t_sort TYPE slis_t_sortinfo_alv,
t_sp_group TYPE slis_t_sp_group_alv,
t_grid_title TYPE lvc_title,
t_events TYPE slis_t_event,
t_list_top_of_page TYPE slis_t_listheader,
v_progid LIKE sy-repid,
v_save VALUE 'A',
t_variant LIKE disvariant,
v_variant LIKE disvariant.

*&---------------------------------------------------------------------*
*& Selection Screen
PARAMETERS: p_mtart LIKE mara-mtart DEFAULT 'ZPAC' .
PARAMETERS: p_werks LIKE t001w-werks obligatory.
select-options : s_bedat for ekko-bedat.


AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF screen-name = 'P_MTART'.
screen-input = '0'.
ENDIF.
MODIFY SCREEN.
ENDLOOP.

INITIALIZATION.
s_bedat-low = sy-datlo - 30.
s_bedat-high = sy-datlo.
append s_bedat.



START-OF-SELECTION.
* PERFORM cek_otorisasi.
PERFORM getdata.
IF itab[] IS INITIAL.
MESSAGE i208(00) WITH 'Data not found'.
ELSE.
PERFORM display.
ENDIF.
*&---------------------------------------------------------------------*
*& Form GETDATA
*&---------------------------------------------------------------------*
FORM getdata .
DATA : v_name LIKE thead-tdname.
DATA: lt_tline LIKE tline OCCURS 0 WITH HEADER LINE.
SELECT
a~bedat a~lifnr
b~matnr C~MSEH3 b~menge b~banfn b~bnfpo b~ebeln b~ebelp b~txz01
INTO CORRESPONDING FIELDS OF TABLE itab
FROM ekko AS a
INNER JOIN ekpo AS b ON b~mandt = a~mandt
AND a~ebeln = b~ebeln
INNER JOIN t006a AS C ON C~MSEHI = B~MEINS
and c~spras = sy-langu

WHERE b~mtart = p_mtart AND
b~werks = p_werks and
a~bedat in s_bedat.

CALL FUNCTION 'FI_PROGRESS_INDICATOR'
EXPORTING
percentage = 0
text = 'Collecting data... '.

* GET QTY
SELECT ebeln ebelp bwart menge
INTO CORRESPONDING FIELDS OF TABLE history
FROM mseg
FOR ALL ENTRIES IN itab
WHERE ebeln = itab-ebeln
AND bwart IN ('101', '102').

* vendor name
SELECT lifnr name1
FROM lfa1
INTO CORRESPONDING FIELDS OF TABLE vendor_data
FOR ALL ENTRIES IN itab
WHERE lifnr = itab-lifnr.

* NETTING OFF
LOOP AT itab.
v_index = sy-tabix.
CLEAR : v_value1, v_nettof.
LOOP AT history WHERE ebeln = itab-ebeln AND ebelp = itab-ebelp.
IF history-bwart = '101'.
v_value1 = v_value1 + history-menge.
ELSEIF history-bwart = '102'.
v_value1 = v_value1 - history-menge.
ENDIF.

ENDLOOP.
v_nettof = itab-menge - v_value1.
IF v_nettof <= 0.
DELETE itab.
ELSE.
itab-menge = v_nettof.
MODIFY itab INDEX v_index.
ENDIF.

ENDLOOP.

SORT itab BY ebeln ebelp.
LOOP AT itab.
v_index = sy-tabix.
itab-no = v_index.
SELECT SINGLE badat
FROM eban
INTO itab-badat
WHERE banfn = itab-banfn.

SELECT SINGLE eindt
FROM eket
INTO itab-eindt
WHERE ebeln = itab-ebeln
AND ebelp = itab-ebelp.

READ TABLE vendor_data WITH KEY lifnr = itab-lifnr.
itab-name1 = vendor_data-name1.
* get keterangan PO
"Item PO text
CONCATENATE itab-ebeln itab-ebelp INTO v_name.
PERFORM read_text TABLES lt_tline
USING sy-mandt 'F01' 'EKPO' v_name 132.
READ TABLE lt_tline INDEX 1.
IF sy-subrc = 0.
itab-ketpo = lt_tline-tdline.
ELSE.
itab-ketpo = ''.
ENDIF.

* LEAD PO
itab-leado = sy-datlo - itab-bedat.
* LEAD PR
if itab-badat = '00000000'.
itab-leadr = '-'.
else.
itab-leadr = sy-datlo - itab-badat.
endif.

CLEAR : lt_tline.
REFRESH : lt_tline.
* get keterangan PO HEADER
v_name = itab-ebeln.
PERFORM read_text TABLES lt_tline
USING sy-mandt 'F01' 'EKKO' v_name 132.
READ TABLE lt_tline INDEX 1.
IF sy-subrc = 0.
itab-kethead = lt_tline-tdline.
ELSE.
itab-kethead = ''.
ENDIF.

CLEAR : v_name, lt_tline.
REFRESH : lt_tline.
MODIFY itab INDEX v_index.

* add to ALV

ENDLOOP.
ENDFORM. " GETDATA
*&---------------------------------------------------------------------*
*& Form read_text
*&---------------------------------------------------------------------*
FORM read_text TABLES ft_lines STRUCTURE tline
USING fu_mandt
fu_tdid
fu_tdobject
fu_tdname
fu_length.
DATA: lv_mandt LIKE sy-mandt,
lv_tdid LIKE thead-tdid,
lv_tdobject LIKE thead-tdobject,
lv_tdname LIKE thead-tdname,
lv_length LIKE sy-index.

REFRESH ft_lines.
lv_mandt = fu_mandt.
lv_tdid = fu_tdid.
lv_tdobject = fu_tdobject.
lv_tdname = fu_tdname.
lv_length = fu_length.

CALL FUNCTION 'READ_TEXT'
EXPORTING
client = lv_mandt
id = lv_tdid
language = sy-langu
name = lv_tdname
object = lv_tdobject
TABLES
lines = ft_lines
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
IF sy-subrc = 0.
CALL FUNCTION 'FORMAT_TEXTLINES'
EXPORTING
formatwidth = lv_length
TABLES
lines = ft_lines
EXCEPTIONS
bound_error = 1
OTHERS = 2.

ENDIF.

ENDFORM. " READ_TEXT
*&---------------------------------------------------------------------*
*& Form DISPLAY
*&---------------------------------------------------------------------*
FORM display .
PERFORM header.
PERFORM createalv.
ENDFORM. " DISPLAY
*&---------------------------------------------------------------------*
*& Form HEADER
*&---------------------------------------------------------------------*
FORM header.
DATA : hdr(1000),
pjg TYPE i,
pstr TYPE i,
tp TYPE i,
k1(50),
k2(50),
k3(50),
k4(50).


PERFORM getjudul CHANGING hdr.
SPLIT hdr AT ',' INTO TABLE tbl_hdr.

LOOP AT tbl_hdr.
CONDENSE tbl_hdr-judul.
pstr = STRLEN( tbl_hdr-judul ).
SPLIT tbl_hdr-judul AT '(' INTO k1 k2.
SPLIT k2 AT ')' INTO k3 k4.
pstr = pstr - STRLEN( k4 ).
pjg = STRLEN( k1 ) + 1.
tp = pjg + 2.

IF tp < pstr.
tbl_hdr-panjang = tbl_hdr-judul+pjg(2).
ELSE.
tbl_hdr-panjang = tbl_hdr-judul+pjg(1).
ENDIF.

tbl_hdr-judul = k1.
tbl_hdr-field = k4.
MODIFY tbl_hdr INDEX sy-tabix.
ENDLOOP.
ENDFORM. " Header

*&---------------------------------------------------------------------*
*& Form CREATEALV
*&---------------------------------------------------------------------*
FORM createalv .
CLEAR v_variant.
v_save = 'A'.
v_variant-report = sy-repid.
t_variant = v_variant.

CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
i_save = v_save
CHANGING
cs_variant = t_variant
EXCEPTIONS
not_found = 2.

PERFORM f_create_field USING t_fieldcat[].

PERFORM setting_attr.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
is_layout = t_layout
i_callback_top_of_page = 'TOP-OF-PAGE'
it_fieldcat = t_fieldcat[]
it_special_groups = t_sp_group[]
i_save = v_save
is_variant = v_variant
it_events = t_events[]
TABLES
t_outtab = itab.

ENDFORM. " CREATEALV
*&---------------------------------------------------------------------*
*& Form f_create_field
*&---------------------------------------------------------------------*
FORM f_create_field USING fu_t_fieldcat TYPE slis_t_fieldcat_alv.
DATA: lv_fieldcat TYPE slis_fieldcat_alv.

REFRESH fu_t_fieldcat.

LOOP AT tbl_hdr.
CLEAR lv_fieldcat.
lv_fieldcat-col_pos = sy-tabix.
lv_fieldcat-fieldname = tbl_hdr-field.
lv_fieldcat-outputlen = tbl_hdr-panjang.
lv_fieldcat-reptext_ddic = tbl_hdr-judul.
APPEND lv_fieldcat TO fu_t_fieldcat.
ENDLOOP.
ENDFORM. " f_create_field
*&----------------------------------------------------------
*& Form top-of-page
*&----------------------------------------------------------
FORM top-of-page.
*ALV Header declarations
DATA: t_header TYPE slis_t_listheader,
wa_header TYPE slis_listheader,
tpmatnr LIKE marc-matnr,
temp(20).


* Title
wa_header-typ = 'H'.
wa_header-info = 'MONITORING OUTSTANDING ORDER PACKAGING REPORT'.
APPEND wa_header TO t_header.

wa_header-typ = 'A'.
IF tpmatnr IS INITIAL.
tpmatnr = 'ALL'.
ENDIF.
CONCATENATE 'Plant : ' p_werks INTO wa_header-info SEPARATED BY space.
append wa_header to t_header.

wa_header-typ = 'A'.
CONCATENATE 'Printed By : ' sy-uname INTO wa_header-info SEPARATED BY space.
APPEND wa_header TO t_header.

wa_header-typ = 'A'.
CONCATENATE sy-datlo+6(2) '.' sy-datlo+4(2) '.' sy-datlo(4) INTO temp.
CONCATENATE 'Printed Date : ' temp INTO wa_header-info SEPARATED BY space.
APPEND wa_header TO t_header.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = t_header.
* i_logo = ''.

ENDFORM. " top-of-page
*&---------------------------------------------------------------------*
*& Form SETTING_ATTR
*&---------------------------------------------------------------------*
FORM setting_attr.
* setting variant
* V_VARIANT-VARIANT = P_VAR.
* V_VARIANT-REPORT = SY-REPID.
* V_VARIANT-USERNAME = SY-UNAME.
ENDFORM. "SETTING_ATTR
*&---------------------------------------------------------------------*
*& Form GETJUDUL
*&---------------------------------------------------------------------*
FORM getjudul CHANGING p_hdr.
CONCATENATE 'NO(3)NO,'
'MATERIAL(11)MATNR,'
'MATERIAL DESCRIPTION(40)TXZ01,'
'SATUAN(6)MSEH3,'
'TGL PR(10)BADAT,'
'NO PR(10)BANFN,'
'ITEM PR(8)BNFPO,'
'TGL PO(10)BEDAT,'
'NO PO(10)EBELN,'
'ITEM PO(8)EBELP,'
'SISA(7)MENGE,'
'TGL PERMINTAAN(14)EINDT,'
'SUPPLIER(40)NAME1,'
'KETERANGAN PO(132)KETPO,'
'LEAD PO(7)LEADO,'
'LEAD PR(7)LEADR,'
'KETERANGAN(132)KETHEAD'
INTO p_hdr.
ENDFORM. " GETJUDUL