Showing posts with label ABAP. Show all posts
Showing posts with label ABAP. Show all posts

July 03, 2010

Embed SAP View in an ABAP Program

Please read this link : http://naveenvishal.wordpress.com/2009/07/27/embed-view-in-program/#more-472

Customize for maintenance view

Please follow the below steps :

- You create a VIEW MAINTENANCE TABLE for your table;
- Generate a Table Maintenance for this view (not for the table);
- After generating the Table Maintenance go to Enviroment->Modification->Events

Please refer this link for the detail events :
http://help.sap.com/saphelp_47x200/helpdata/en/91/ca9f0ea9d111d1a5690000e82deaaa/frameset.htm

help link : http://forums.sdn.sap.com/message.jspa?messageID=1755550

Hide and Unhide source code in ABAP

read this link : http://naveenvishal.wordpress.com/2009/08/08/hide-source-code/

Save Text for PO Notes

IF ls_theadtab-neu EQ 'X'.
CALL FUNCTION 'INIT_TEXT'
EXPORTING
id = l_thead-tdid
language = my_langu
name = l_thead-tdname
object = l_thead-tdobject
IMPORTING
header = l_thead
TABLES
lines = lt_tline
EXCEPTIONS
OTHERS = 1.
CHECK sy-subrc IS INITIAL.
MOVE-CORRESPONDING l_thead TO ls_theadtab.
ENDIF.

LOOP AT im_textlines INTO l_textline.
l_tline-tdformat = l_textline-tdformat.
l_tline-tdline = l_textline-tdline .
APPEND l_tline TO lt_tline.
ENDLOOP.


CALL FUNCTION 'SAVE_TEXT'
EXPORTING
header = l_thead
IMPORTING
function = l_txfunction
TABLES
lines = lt_tline
EXCEPTIONS
OTHERS = 1.
CHECK sy-subrc IS INITIAL.
ls_theadtab-neu = space.
IF NOT l_txfunction IS INITIAL.
CALL METHOD update_change_doc


EXPORTING
im_tdid = ls_theadtab-tdid
im_tdspras = ls_theadtab-tdspras
im_function = l_txfunction.
ls_theadtab-fixie = space.
ENDIF.
MODIFY my_theadtab FROM ls_theadtab INDEX l_tabix.


ELSE.

READ TABLE my_theadtab INTO ls_theadtab WITH KEY
tdobject = my_text_manager_type->tdobject
tdid = l_textid.
CHECK sy-subrc IS INITIAL.
CALL METHOD delete_text
EXPORTING
im_tdid = ls_theadtab-tdid
im_tdspras = ls_theadtab-tdspras
im_tdobject = ls_theadtab-tdobject
im_tdname = ls_theadtab-tdname.

ls_theadtab-neu = 'X'.
MODIFY TABLE my_theadtab FROM ls_theadtab.

ENDIF.

LMEREQF12

id = 'B01'.
language = E
name = 0010012535
object = EBANH

related link : http://iorboaz.blogspot.com/2007/05/sap-abap-putsave-text-in-sap.html

May 19, 2010

Split text to be words

DATA: str1 TYPE string,
str2 TYPE string,
str3 TYPE string,
itab TYPE TABLE OF string with header Line,
text TYPE string.

text = 'What a drag it is getting old'.

*SPLIT text AT space INTO: str1 str2 str3,
* TABLE itab.

SPLIT text AT space INTO TABLE itab.
break hcl_kamal1.

LOOP AT itab.
case SY-TABIX.
WHEN 1.
str1 = itab.
WHEN 2.
ENDCASE.

ENDLOOP.

April 29, 2010

Task List table

Access for Task List table, as following :

1. Using t-code CA03 (material) and will save to table :
MAPL (PLNTY,PLNNR,PLNAL)
2. Using t-code IA03/IH03 (Equipment) and will save to table :
EAPL (PLNTY,PLNNR,PLNAL)
3. Using t-code IA07 (General Maintenance Task List)


Related to other tables, as following :

1. PLKO (PLNTY,PLNNR,PLNAL)
2. PLWP(PLNTY,PLNNR,PLNAL,PLNKN)
2. PLAS (PLNTY,PLNNR,PLNAL,PLNKN, LOKEZ # Not equal to 'X' )
3. PLPO (PLNTY,PLNNR,PLNKN)
4. PLMZ (PLNTY,PLNNR,PLNKN, LOKEZ # Not equal to 'X', STLTY,STLNR, STLKN, STLAL(alternatif BOM))
5. STAS (STLTY,STLNR, STLAL,STLKN,LKENZ # "X") => Alternatif BOM
5. STPO( STLTY,STLNR, STLKN) --> STPO-IDNRK

October 28, 2009

Dynamic Code

Try this..We create the coding in the notepad then this program will compile the coding and running the coding. I call this program as ABAP Query Analyzer.

*Dynamic manipulation of report programs
*......................................................................
*: Report ZDYNAMICCODE :
*:.....................................................................
*: Execute ABAP from a PC file(.txt) :
*: Therefor allowing any abap code to be executed on any client :
*: which contains this program :
*: :
*.....................................................................:
REPORT zdynamiccode .

TABLES rlgrap.

*selection screen creation
PARAMETER: p_file(200) TYPE c,
p_temp(30) TYPE c DEFAULT 'Z123TEMP_REPORT_FOR_CODE'.

*data declaration
DATA: it_tab TYPE filetable,
gd_subrc TYPE i,
answer TYPE c.

TYPES: BEGIN OF t_abapcode,
row(72) TYPE c,
END OF t_abapcode.
DATA: it_abapcode TYPE STANDARD TABLE OF t_abapcode INITIAL SIZE 0,
it_store TYPE STANDARD TABLE OF t_abapcode INITIAL SIZE 0.

DATA: filename TYPE string.


************************************************************************
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*Selecting a File, plus inserting default file extension
REFRESH: it_tab.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Select File'
default_filename = '*.txt'
multiselection = ' '
CHANGING
file_table = it_tab
rc = gd_subrc.

LOOP AT it_tab INTO p_file.
ENDLOOP.


************************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.

*move file name into a field with type compatable with FM
filename = p_file.

*upload file from PC
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = filename
TABLES
data_tab = it_abapcode
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
IF sy-subrc EQ 0.
* Check if report name being used fro temorary code already exists as
* any code will be over written and lost
READ REPORT p_temp INTO it_store.
IF sy-subrc NE 0.
* Please note any existing code in the program will be lost!!!!
INSERT REPORT p_temp FROM it_abapcode.
SUBMIT (p_temp) AND RETURN.
DELETE REPORT p_temp.
ELSE.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
text_question = 'Report used to store temporary code already
exists!!! Do you want to overwrite it?'
IMPORTING
answer = answer.
IF sy-subrc EQ 0.
IF answer EQ '1'. "yes
* Please note any existing code in the program will be lost!!!!
INSERT REPORT p_temp FROM it_abapcode.
SUBMIT (p_temp) AND RETURN.
DELETE REPORT p_temp.
ENDIF.
ENDIF.
ENDIF.
ENDIF.

Source : http://www.sapdev.co.uk/tips/dynamic/dyn_prog.htm

October 03, 2009

Edit program in Production Server

Step to change program in Production server as following this :

1. Open SE38 and search program LSTRDU34 then click Display button.
2. Set breakpoint for line "IF sy-subrc NE 0".
3. Open SE38 and search program LSTRDU44 then click display button.
4. Set breakpoint for line "IF sy-subrc NE 0".
5. Open SE38 and search program which you want to edit.
6. Then click Change Button.
7. It will run program LSTRDU34 and stop to the breakpoint..Then you must change the value sy-subrc = 0.
8. After that click F8 button.
9. CHANGE YOUR CODING.
10. Then click Activate button.
11. It will run program LSTRDU44 and stop to the breakpoint..Then you must change the value sy-subrc = 0.
12. Click F8 button.
13. You already change your coding.

Note : Need authorization to change value in Debug mode.

September 14, 2009

Tips for READ TABLE using BINARY SEARCH

When using BINARY SEARCH...DON'T FORGET TO SORT fields which are keys.
Example :

SORT tab_knvv_kunag BY kunnr vkorg vtweg spart.
READ TABLE tab_knvv_kunag INTO rec_knvv_kunag WITH KEY kunnr = rec_header-kunag
vkorg = rec_header-vkorg
vtweg = rec_header-vtweg
spart = rec_header-spart BINARY SEARCH.

July 30, 2009

unlock user's session

using t-code SM04 to lock or unlock user's session.

July 29, 2009

ABAP Code For a Progress BAR

Please find below code for displaying a progress bar in ABAP. Once you execute this code a progress bar will be displayed in the status bar. You need to manipulate the code in such a way so that it can be displayed in your program.

REPORT ZEX_PROGRESSIND .



DATA: A LIKE SY-UCOMM.

DO 100 TIMES.
DO 300 TIMES.
GET TIME.
ENDDO.
A(3) = SY-INDEX.A+3 = '%'.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
PERCENTAGE = SY-INDEX
TEXT = A.
ENDDO.

WRITE: / 'Complete'.

source : http://abaplovers.blogspot.com/2008/05/abap-code-for-progress-bar.html

July 05, 2009

Moving Cursor to Next row by pressing Enter in Classical ALV

This event will run when the user edits the column field then press the enter button.
It is used for The edited ALV Grid.

*&---------------------------------------------------------------------*
*& This code snippet shows how to use the classical ALV grid to
*& perform the excel like feature: Move cursor to next row by
*& pressing enter
*&---------------------------------------------------------------------*


REPORT ZTEST_NP_GRID_EDIT.

*
* Data Declration

TYPE-POOLS: SLIS.
*
TYPES: BEGIN OF TY_SFLIGHT.
INCLUDE TYPE SFLIGHT.
TYPES: BOX TYPE CHAR1,
END OF TY_SFLIGHT.
*
*
DATA: GT_SFLIGHT TYPE TABLE OF TY_SFLIGHT.
DATA: GS_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA: LT_EVTS TYPE SLIS_T_EVENT,
LA_EVTS LIKE LINE OF LT_EVTS.
*
DATA: GS_REPORT TYPE SY-CPROG,
GS_TITLE TYPE LVC_TITLE.

*
* Start of Selection
START-OF-SELECTION.
*
* Report
GS_REPORT = SY-CPROG.
GS_TITLE = 'Move Cursor to next row by pressing Enter'.


*
* Selection.
SELECT * FROM SFLIGHT
INTO CORRESPONDING FIELDS OF TABLE GT_SFLIGHT.

*
* Layout
GS_LAYOUT-EDIT = 'X'.

*
* Event for Data Changed
LA_EVTS-NAME = 'DATA_CHANGED'.
LA_EVTS-FORM = 'GET_DATA_CHANGED'.
APPEND LA_EVTS TO LT_EVTS.

*
* Call ABAP List Viewer (ALV)
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_GRID_TITLE = GS_TITLE
I_CALLBACK_PROGRAM = GS_REPORT
I_STRUCTURE_NAME = 'SFLIGHT'
IS_LAYOUT = GS_LAYOUT
IT_EVENTS = LT_EVTS
TABLES
T_OUTTAB = GT_SFLIGHT.

*
*&---------------------------------------------------------------------*
*& Form get_data_changed
*&---------------------------------------------------------------------*
* Here we will get the current cell and than add 1 to it to move
* to next row. Than we will call the method to set the new row
*----------------------------------------------------------------------*
FORM GET_DATA_CHANGED USING RR_DATA_CHANGED
TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
*
DATA: LO_GRID TYPE REF TO CL_GUI_ALV_GRID.
*
DATA: LE_ROW TYPE I,
LE_VALUE TYPE C,
LE_COL TYPE I,
LES_ROW_ID TYPE LVC_S_ROW,
LES_COL_ID TYPE LVC_S_COL,
LES_ROW_NO TYPE LVC_S_ROID.

*
* Get the ALV Object reference
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = LO_GRID.

*
* Get the Current Cell
CALL METHOD LO_GRID->GET_CURRENT_CELL
IMPORTING
E_ROW = LE_ROW
E_VALUE = LE_VALUE
E_COL = LE_COL
ES_ROW_ID = LES_ROW_ID
ES_COL_ID = LES_COL_ID
ES_ROW_NO = LES_ROW_NO.

*
* Set to the next cell
DESCRIBE TABLE GT_SFLIGHT LINES SY-INDEX.
LES_ROW_ID-INDEX = LES_ROW_ID-INDEX + 1.
LES_ROW_NO-ROW_ID = LES_ROW_NO-ROW_ID + 1.
IF LES_ROW_ID-INDEX LE SY-INDEX.
CALL METHOD LO_GRID->SET_CURRENT_CELL_VIA_ID
EXPORTING
IS_ROW_ID = LES_ROW_ID
IS_COLUMN_ID = LES_COL_ID
IS_ROW_NO = LES_ROW_NO.
ENDIF.

ENDFORM. "get_data_changed

source : http://help-abap.blogspot.com/2008/09/moving-cursor-to-next-row-by-pressing.html

June 28, 2009

CONVERT_DATE_TO_EXTERNAL sap function module

The below code shows how function module CONVERT_DATE_TO_EXTERNAL is used to convert a date field from is internal storage format to the users specific display format i.e. from YYYYMMDD to DD/MM/YYYY.
Convert date to users prefered output 

data: ld_date_int type datum,
ld_date_ext type datum.

CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
EXPORTING
date_internal = ld_date_int
IMPORTING
date_external = ld_date_ext
EXCEPTIONS
date_internal_is_invalid = 1
OTHERS = 2.

One of a function module is 'CONVERT_DATE_TO_INTERNAL'

June 24, 2009

June 17, 2009

SAP ABAP Decimal Places in Currency

If you wish to find the decimal places in the currency you can use the following function module.
G_DECIMAL_PLACES_GET The table that stores the Currencies in SAP system (Currency Codes) is TCURC. The code below shows the decimal places for a particular currency.
REPORT ZEX_CURRENCY .

Parameters: p_curr(10).
Data: d_decpl like TCURX-CURRDEC.
CALL FUNCTION 'G_DECIMAL_PLACES_GET'
EXPORTING
CURRENCY = p_curr
IMPORTING
DECIMAL_PLACES = d_decpl .

Write: 'Decimal Places ', d_decpl.

Source : http://abaplovers.blogspot.com/2008/06/sap-abap-decimal-places-in-currency.html

June 08, 2009

Hide Parameter/Select Option in Selection Screen

We can Hide parameter / select option in selection screen dynamically by manipulating screen object.

SCREEN is like an internal table with a header line. However, you do not have to declare it in your program. Go to debugging mode and then view structure of screen.

You can modify SCREEN in your ABAP program during the PBO event of a screen. Its contents override the static attributes of the screen fields for a single screen call. The only statements that you can use with SCREEN are:

LOOP AT SCREEN....
MODIFY SCREEN....
ENDLOOP.

We can hide parameter by set screen-active to 0.Here is example of how to hide parameter in selection screen. Write it, and change click on radiobutton to hide parameter.
REPORT ZAALGAL0006.
DATA: d_ucomm LIKE sy-ucomm.
PARAMETERS: p_grpa1(10) MODIF ID A,p_grpa2(5) MODIF ID A,p_grpb1(2) MODIF ID B.
PARAMETERS: p_actA RADIOBUTTON GROUP rad1 USER-COMMAND ACT DEFAULT 'X',
p_actB RADIOBUTTON GROUP rad1.AT SELECTION-SCREEN.
d_ucomm = sy-ucomm.
AT SELECTION-SCREEN OUTPUT.
LOOP AT screen.
IF p_actA = 'X'.
IF screen-group1 = 'B'.
screen-active = 0.
ENDIF.
ELSEIF p_actB = 'X'.
IF screen-group1 = 'A'.
screen-active = 0.
ENDIF.
ENDIF.
MODIFY screen.
ENDLOOP.

START-OF-SELECTION.

source : http://abap-gallery.blogspot.com/2007/07/hide-parameter-select-option-in.html

June 07, 2009

Searh BADI for each transaction

1. Go to tcode se93, enter the transection name eg va01 click display button. get the package name.
2. Go to tcode se84->enhancement->Bussiness-addins->definition,enter the package name and execute.

here you get the list of all the enhancement badi's for the given package.

source :https://www.sdn.sap.com/irj/scn/thread?threadID=1360407

other link : https://www.sdn.sap.com/irj/scn/advancedsearch?query=how+to+implement+badi&cat=sdn_all

June 06, 2009

Function for Convert minus sign to the left

data prnamt(18).

CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
CHANGING
VALUE = prnamt(18).

May 31, 2009

Print Form PO (Purchase Order)

When you create add on program for Print Out Form PO ( Purchase Order), you will use t-code (SE38). To get parameter PO number from ME23N, you need to add coding like this in below :

*&---------------------------------------------------------------------*
*& Form entry_neu
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->ENT_RETCO text
* -->ENT_SCREEN text
*----------------------------------------------------------------------*
FORM entry_neu USING ent_retco ent_screen.
CLEAR ent_retco.
MOVE nast-objky TO p_ebeln.
* Collect data from several tables
PERFORM f_collect_data.
** Display form
PERFORM f_display_form.
ENDFORM. "entry_neu



After you already finish to develop. You need to assign the program Id in Output Type using t-code spro.


May 28, 2009

Declare Work Area

There are two options or more to define workarea, but we must define internal table firstly.

DATA : it_mara TYPE STANDARD TABLE OF mara.

DATA : wa_mara LIKE LINE OF it_mara.
OR
DATA : wa_mara TYPE mara.