Archive

Archive for the ‘ABAP’ Category

Simplified PM Service Notification

January 23rd, 2009

I have been searching for BAPI for creating a PM service notification. I found several Function Modules: First I found BAPI_SERVICENOTIFICAT_CREATE and second I found BAPI_SERVNOT_CREATE.

I tried to create notification using BAPI_SERVICENOTIFICAT_CREATE but it keeps giving this error: EIS499E499 Non-specifiable notification in function module. When I try to use BAPI_SERVICENOTIFICAT_GETLIST
to get an example data for existing service notification, I can’t use the function module since all the example data doesn’t contain any customer number while the function module set customer number as an obligatory parameter.

Create PM Notification
Create PM Notification screenshot

Then it leaves me to the second choice, BAPI_SERVNOT_CREATE. When I tried to create service notification using this function, it keeps giving this error: ‘Notification Type M1 is not defined’. Now I need to know how to populate the data in the function module. Maybe I populated them wrong, so I run this function BAPI_SERVNOT_GET_DETAIL filling service notification number that has been created manually. It still giving the same error ‘Notification Type M1 is not defined’. Then I almost gave up.

Read more…

vera ABAP , ,

Problem with BAPI

January 23rd, 2009

Today is the xxxth day I’m looking for this BAPI_SERVNOT_CREATE documentation all over the net. I’m not familiar with PM transaction and we don’t have any functional here so I’ve got no one to ask. I’ve been searching the internet for the documentation but found none.

All the articles I found are only explaining how the function module works, but there’s no example on how to populate the data.

If I got any luck and succeed, I’ll write down a complete example code to get the function module work. Wish me luck!

vera ABAP ,

Making ALV Grid Editable

November 18th, 2008

Actually this subject is included in BCALV_EDIT* in SAP/R3. I just want to make several conclusions, and make some notes on how to implement an ALV Editable Grid with the minimum method required to make it work. In this example I use a dynamic ALV Grid, so here are the steps:

1. You must create a screen (e.g. 9000) and create a CUSTOM_CTRL on that screen.
2. Add these variables to your program:

DATA: GRID TYPE REF TO CL_GUI_ALV_GRID,

CUST_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,

G_LAYOUT TYPE LVC_S_LAYO,

G_FIELDCAT TYPE LVC_S_FCAT OCCURS 0,

GS_FIELDCAT TYPE LVC_S_FCAT.

3. You must define a class derived from CL_GUI_ALV_GRID to make custom methods that you can edit according to your needs.
To see the methods (and parameters needed) available for CL_GUI_ALV_GRID, you can double click on the class.
The code will look like this:

CLASS LCL_9000_GRIDEVENT DEFINITION.
PUBLIC SECTION.
METHODS:
HANDLE_DATACHANGE FOR EVENT DATA_CHANGED OF
CL_GUI_ALV_GRID IMPORTING
ER_DATA_CHANGED
E_ONF4
E_ONF4_BEFORE
E_ONF4_AFTER,

HANDLE_USERCOMMAND FOR EVENT USER_COMMAND OF
CL_GUI_ALV_GRID IMPORTING E_UCOMM.

ENDCLASS.

CLASS LCL_9000_GRIDEVENT IMPLEMENTATION.

METHOD HANDLE_DATACHANGE.
perform f_datachange using er_data_changed.
ENDMETHOD.

METHOD HANDLE_USERCOMMAND.
perform f_usercommand using e_ucomm.
ENDMETHOD.

ENDCLASS.

4. Create a variable that refers to the class created.

DATA: LCL_9000_GRIDEVENT TYPE REF TO LCL_9000_GRIDEVENT.

5. Create PBO for your screen. For example your PBO method name is PBO_9000. The code will look like this:

MODULE PBO_9000 OUTPUT.

IF CUST_CONTAINER IS INITIAL.

CREATE OBJECT CUST_CONTAINER
EXPORTING
CONTAINER_NAME = ‘CS_CTRL’.

CREATE OBJECT GRID
EXPORTING
I_PARENT = CUST_CONTAINER.

GS_REPID = SY-REPID.

*—This part will costumize the display of your grid
G_LAYOUT-GRID_TITLE = ‘Put your title here’.
G_LAYOUT-CWIDTH_OPT = ‘X’.
G_LAYOUT-no_rowins = ‘X’.
*—————————————————-

*—Build your field catalog for your internal table displayed
PERFORM F_9000_BUILD.
*—————————————————-

CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = G_LAYOUT
CHANGING
IT_OUTTAB = T_DATA
IT_FIELDCATALOG = G_FIELDCAT.

*—–These are the key methods called for editable ALV Grid to *—–work properly
CALL METHOD GRID->SET_READY_FOR_INPUT
EXPORTING
I_READY_FOR_INPUT = 1.

call method grid->register_edit_event
exporting
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
*———————————————————————–

*——————attach your grid to the EVENT HANDLER
CREATE OBJECT LCL_9000_GRIDEVENT.
set handler LCL_9000_GRIDEVENT->handle_datachange for grid.
set handler LCL_9000_GRIDEVENT->handle_usercommand for grid.
*———————————————————

ENDIF.

CALL METHOD GRID->SET_FRONTEND_FIELDCATALOG
EXPORTING
IT_FIELDCATALOG = G_FIELDCAT.
CALL METHOD GRID->REFRESH_TABLE_DISPLAY.

CALL METHOD CL_GUI_CONTROL=>SET_FOCUS EXPORTING CONTROL = GRID.

ENDMODULE. ” PBO_9000 OUTPUT

6. You need to fill in G_FIELDCAT variable. For example, you want to make an internal table contains material id and text. Material ID will be editable but not the text because material text will be obtained from MAKT table. This is the implementation looks like:

FORM F_9000_BUILD.
clear GS_FIELDCAT.
GS_FIELDCAT-fieldname = ‘MATNR’.
GS_FIELDCAT-ref_table = ‘MARA’.
GS_FIELDCAT-ref_field = ‘MATNR’.
GS_FIELDCAT-EDIT = ‘X’.
append GS_FIELDCAT TO G_FIELDCAT.

CLEAR GS_FIELDCAT.
GS_FIELDCAT-fieldname = ‘MAKTX’.
GS_FIELDCAT-ref_table = ‘MAKT’.
GS_FIELDCAT-ref_field = ‘MAKTX’.
append GS_FIELDCAT TO G_FIELDCAT.
ENDFORM

Done! You’re Editable ALV Grid is ready to be used. Enjoy!

vera ABAP ,

Edit program in QA/Prod

October 7th, 2008

I got this code 6 years ago from some site. I don’t remember where I got this from, but it’s really handy when you need to make small changes of ABAP Programs in PROD/QA. You won’t need to make unnecessary transports thus you will also save CR numbers.

Just copy paste the next code, let’s name it ZEDIT. Transport it and you will be able to change your programs in PROD/QA as many times as you like.

IMPORTANT NOTES:
1. This program can only change the program that is already exist in PROD/QA, so you will need to transport the program you’d like to change to PROD/QA.

2. To maintain the integrity between DEV and PROD/QA, change the program as you need in DEV. After it’s successfully activated, run the ZEDIT program in PROD/QA, copy paste your whole program there, then try to execute your changed program again.

Enjoy!

REPORT ZEDIT .

* global data test data
DATA: BEGIN OF t_report OCCURS 9,
line(72),
END OF t_report.

* macro
define mac_check_uname.
*this program can only be used by you
check sy-uname = ‘IT-VERA’.
end-of-definition.

* user interface
PARAMETERS: p_cprog LIKE sy-cprog.

* main program
START-OF-SELECTION.
mac_check_uname.
SELECT SINGLE name FROM trdir INTO p_cprog
WHERE name = p_cprog.
IF sy-subrc <> 0.
MESSAGE e000(zz) WITH ‘Program name is not valid!’.
ENDIF.

READ REPORT p_cprog INTO t_report.
EDITOR-CALL FOR t_report. “display-mode title ‘Test’.
* EDITOR-CALL FOR REPORT p_cprog.
* IF sy-ucomm = ‘TTU’.
IF sy-ucomm = ‘WB_SAVE’.
INSERT REPORT p_cprog FROM t_report.
IF sy-subrc = 0.
MESSAGE s000(zz) WITH ‘Program is saved!’.
ENDIF.
ENDIF.
END-OF-SELECTION.

vera ABAP