SAP Abap programming & SAP Modules SD,MM,HR,PP...
Search this site
Saturday, March 31, 2012
Create index in table sap ?
Get date time in abap sap ?
SY-DATLO
User’s local date, for example 19981129, 19990628, …
SY-DATUM
Current application server date, for example 19981130, 19990627, …
SY-DAYST
X during summertime, otherwise space.
SY-FDAYW
Factory calendar day of the week: Monday = 1 … Friday = 5.
SY-TIMLO
Friday, March 30, 2012
Way to find a badi in abap sap
There are several ways to find BADIs in the program.
1. Set a beark-point in method ‘CL_EXITHANDLER=>GET_INSTANCE’. Because old BAID technology will always call this method to get the BADI instance.
2. Search string ‘CL_EXITHANDLER=>GET_INSTANCE’ in the program. This drawback of this method is that the program may call another program in the runtime. In this case, you will be able to find the BADI in another program.
3. You can also go the t-code SPRO, you can also find plenty of BADIs in the related area.
4. You can also find the BADI call using ST05. Below is the steps:
- Go to ST05, then choose ‘table buffer trace’ and activate the trace.
- Run the t-code from where you want to find the BADI.
- Deactive the trace and then display trace.
- using selection criteria object ‘V_EXT_IMP’ and ‘V_EXT_ACT’ and then you can get called BADI list.
This analyzing technique is based on the fact that all BAdIs are registrated in SAP database tables. So for each BAdI call these database tables will be accessed. The BAdI database tables are SXS_INTER, SXC_EXIT, SXC_CLASS and SXC_ATTR. These tables are always accessed by the views V_EXT_IMP and V_EXT_ACT. So these two ABAP views (T: SE11) will be the basis for the trace.
Example ALV in abap SAP
*& Report Z_SCREEN_DEMO
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_SCREEN_DEMO.
*&---------------------------------------------------------------------*
* Declare global object and selection screen.
*&---------------------------------------------------------------------*
*-----------------------------------------------------------------------
* TYPE POOL
*-----------------------------------------------------------------------
TYPE-POOLS:
SLIS.
*----------------------------------------------------------------------*
* TABLES
*----------------------------------------------------------------------*
TABLES:MARA.
*----------------------------------------------------------------------*
* TYPES
*----------------------------------------------------------------------*
*Struct MARA
TYPES: BEGIN OF GTY_MARA,
MATNR TYPE MARA-MATNR,"MATERIAL NUMBER
MTART TYPE MARA-MTART,
END OF GTY_MARA.
*Struct MAKT
TYPES: BEGIN OF GTY_MAKT,
MATNR TYPE MAKT-MATNR,"MATERIAL NUMBER
MAKTX TYPE MAKT-MAKTX,
END OF GTY_MAKT.
*Struct OUTPUT
TYPES: BEGIN OF GTY_OUTPUT,
MATNR TYPE MARA-MATNR,"MATERIAL NUMBER
MTART TYPE MARA-MTART,"MATERIAL TYPE
MAKTX TYPE MAKT-MAKTX,"MATERIAL DES
END OF GTY_OUTPUT.
*----------------------------------------------------------------------*
* Internal table
*----------------------------------------------------------------------*
DATA: GT_OUTPUT TYPE STANDARD TABLE OF GTY_OUTPUT,
GT_MARA TYPE STANDARD TABLE OF GTY_MARA,
GT_MAKT TYPE STANDARD TABLE OF GTY_MAKT,
*----------------------------------------------------------------------*
* Work area
*----------------------------------------------------------------------*
GS_OUTPUT TYPE GTY_OUTPUT,
GS_MARA TYPE GTY_MARA,
GS_MAKT TYPE GTY_MAKT.
*----------------------------------------------------------------------*
* Selection screen
*----------------------------------------------------------------------*
SELECT-OPTIONS: S_ERDA FOR MARA-ERSDA default '20110916 ' OBLIGATORY.
PARAMETERS:
pa_lim_1 RADIOBUTTON GROUP lim ,"JOIN
pa_lim_2 RADIOBUTTON GROUP lim,"FOR ALL ENTRIES
*----------------------------------------------------------------------*
* INITIALIZATION.
*----------------------------------------------------------------------*
INITIALIZATION.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
*----------------------------------------------------------------------*
* START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
*Select data
IF PA_LIM_1 IS NOT INITIAL.
*Join
SELECT
M~MATNR
M~MTART
M2~MAKTX
INTO TABLE GT_OUTPUT
FROM
MARA AS M
JOIN MAKT AS M2 ON M~MATNR = M2~MATNR
WHERE M~ERSDA IN S_ERDA AND
M2~SPRAS = 'E'.
ELSE.
*For all entries
SELECT
MATNR
MTART
FROM MARA
INTO TABLE GT_MARA
WHERE ERSDA IN S_ERDA.
DELETE ADJACENT DUPLICATES FROM GT_MARA COMPARING MATNR.
IF GT_MARA IS NOT INITIAL.
SELECT
MATNR
MAKTX
FROM MAKT
INTO TABLE GT_MAKT
FOR ALL ENTRIES IN GT_MARA
WHERE MATNR = GT_MARA-MATNR AND SPRAS = 'E'.
ENDIF.
SORT GT_MAKT BY MATNR.
LOOP AT GT_MARA INTO GS_MARA.
CLEAR: GS_MAKT.
READ TABLE GT_MAKT BINARY SEARCH WITH KEY MATNR = GS_MARA-MATNR
INTO GS_MAKT.
GS_OUTPUT-MATNR = GS_MARA-MATNR.
GS_OUTPUT-MTART = GS_MARA-MTART.
GS_OUTPUT-MAKTX = GS_MAKT-MAKTX.
APPEND GS_OUTPUT TO GT_OUTPUT.
ENDLOOP.
ENDIF.
*----------------------------------------------------------------------*
* End-OF-SELECTION
*----------------------------------------------------------------------*
END-OF-SELECTION.
* Output data
* ALV
data: LS_FIELDCAT type slis_fieldcat_alv.
data: GT_FIELDCAT type slis_t_fieldcat_alv.
PERFORM CREATE_FIELD_CAT.
*&---------------------------------------------------------------------*
*& Form CREATE_FIELD_CAT
*&---------------------------------------------------------------------*
* Create field catalogies
*----------------------------------------------------------------------*
FORM CREATE_FIELD_CAT .
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_internal_tabname = 'GT_OUTPUT'
i_structure_name = 'ZOUTPUT'
changing
ct_fieldcat = GT_FIELDCAT.
ENDFORM. " CREATE_FIELD_CAT
*&---------------------------------------------------------------------*
*& Form GRID_DISPLAY
*&---------------------------------------------------------------------*
* Grid Display
*----------------------------------------------------------------------*
FORM GRID_DISPLAY .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = 'ZSCREEN_DEMO1'
* I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
I_CALLBACK_TOP_OF_PAGE = 'FRM_TOP_OF_PAGE'
IT_FIELDCAT = GT_FIELDCAT
I_SAVE = 'X'
* IS_VARIANT = G_VARIANT
TABLES
T_OUTTAB = GT_OUTPUT
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " GRID_DISPLAY
*&---------------------------------------------------------------------*
*& Form Top of page
*&---------------------------------------------------------------------*
* Top of page
*----------------------------------------------------------------------*
FORM FRM_TOP_OF_PAGE.
*ALV Header declarations
DATA: T_HEADER TYPE SLIS_T_LISTHEADER,
WA_HEADER TYPE SLIS_LISTHEADER.
* Title
WA_HEADER-TYP = 'H'.
WA_HEADER-INFO = 'ALV Demo'.
APPEND WA_HEADER TO T_HEADER.
CLEAR WA_HEADER.
* Date
WA_HEADER-TYP = 'S'.
WA_HEADER-KEY = 'Date: '.
CONCATENATE SY-DATUM+6(2) '.'
SY-DATUM+4(2) '.'
SY-DATUM(4) INTO WA_HEADER-INFO. "todays date
APPEND WA_HEADER TO T_HEADER.
CLEAR: WA_HEADER.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = T_HEADER.
ENDFORM.
BDC example in ABAP ?
What is BDC in ABAP SAP ?
The full form of BDC is Batch Data Communication. It’s a technique in SAP used for mass input of data or uploading data into SAP system (If particular BAPI is not available).BDC also known as Batch Input. There are two types of BDC are there
- Call Transaction Using (using CALL TRANSACTION statement)
- Batch Input Session (using BDC_OPEN_GROUP, BDC_INSERT and BDC_CLOSE_GROUP function modules)
ABAP programming is requires for any BDC methods. First we need to record a transaction and then embed this recording in our ABAP program. Then we will run this using Call Transaction using or BI session method.
CALL TRANSACTION USING:
This is the fastest method to transfer data.
Syntax:
CALL TRANSACTION
USING
MODE
UPDATE
Main Display Modes used
A: Display all
E: Display Errors only
N : No Display
Main Updates modes
S: Synchronous
A: Asynchronous
L : Local Update
While we doing CALL TRANSACTION USING method, first we will create a structure BDCDATA for the transaction. This structure is used in the USING addition of the CALL TRANSACTION statement.
Batch Input Session
In this method data is stored in a batch input session and later run this session. Here is the process flow of BI session method.
- Use BDC_OPEN_GROUP function module to create a BI session.
- BDCDATA structure, enter the value for all screens and fields that must be processed in the transaction
- Use BDC INSERT function module to transfer the transaction and the BDCDATA structure to the session
- Use BDC_CLOSE_GROUP function module to close the batch input session.
Now this session will be in a batch input queue and we need to process it. The session processing can be two types
- Manually using the batch input menu options (SM35 transaction).
- Use RSBDCSUB program to run the session in background.
Tuesday, March 27, 2012
List processing example
*& Report Z_LIST_PROCESSING
*&
*&---------------------------------------------------------------------*
REPORT Z_LIST_PROCESSING .
*&---------------------------------------------------------------------*
* Declare global object and selection screen.
*&---------------------------------------------------------------------*
*-----------------------------------------------------------------------
* TYPE POOL
*-----------------------------------------------------------------------
TYPE-POOLS:
SLIS.
*----------------------------------------------------------------------*
* TABLES
*----------------------------------------------------------------------*
TABLES:MARA.
*----------------------------------------------------------------------*
* TYPES
*----------------------------------------------------------------------*
*Struct MARA
TYPES: BEGIN OF GTY_MARA,
MATNR TYPE MARA-MATNR,"MATERIAL NUMBER
MTART TYPE MARA-MTART,
END OF GTY_MARA.
*Struct MAKT
TYPES: BEGIN OF GTY_MAKT,
MATNR TYPE MAKT-MATNR,"MATERIAL NUMBER
MAKTX TYPE MAKT-MAKTX,
END OF GTY_MAKT.
*Struct OUTPUT
TYPES: BEGIN OF GTY_OUTPUT,
MATNR TYPE MARA-MATNR,"MATERIAL NUMBER
MTART TYPE MARA-MTART,"MATERIAL TYPE
MAKTX TYPE MAKT-MAKTX,"MATERIAL DES
END OF GTY_OUTPUT.
*----------------------------------------------------------------------*
* Internal table
*----------------------------------------------------------------------*
DATA: GT_OUTPUT TYPE STANDARD TABLE OF GTY_OUTPUT,
GT_MARA TYPE STANDARD TABLE OF GTY_MARA,
GT_MAKT TYPE STANDARD TABLE OF GTY_MAKT,
*----------------------------------------------------------------------*
* Work area
*----------------------------------------------------------------------*
GS_OUTPUT TYPE GTY_OUTPUT,
GS_MARA TYPE GTY_MARA,
GS_MAKT TYPE GTY_MAKT.
*----------------------------------------------------------------------*
* Selection screen
*----------------------------------------------------------------------*
SELECT-OPTIONS: S_ERDA FOR MARA-ERSDA default '20111017 ' OBLIGATORY.
PARAMETERS:
pa_lim_1 RADIOBUTTON GROUP lim ,"JOIN
pa_lim_2 RADIOBUTTON GROUP lim,"FOR ALL ENTRIES
*----------------------------------------------------------------------*
* INITIALIZATION.
*----------------------------------------------------------------------*
INITIALIZATION.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
*----------------------------------------------------------------------*
* START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
*Select data
IF PA_LIM_1 IS NOT INITIAL.
*Join
SELECT
M~MATNR
M~MTART
M2~MAKTX
INTO TABLE GT_OUTPUT
FROM
MARA AS M
JOIN MAKT AS M2 ON M~MATNR = M2~MATNR
WHERE M~ERSDA IN S_ERDA AND
M2~SPRAS = 'E'.
ELSE.
*For all entries
SELECT
MATNR
MTART
FROM MARA
INTO TABLE GT_MARA
WHERE ERSDA IN S_ERDA.
DELETE ADJACENT DUPLICATES FROM GT_MARA COMPARING MATNR.
IF GT_MARA IS NOT INITIAL.
SELECT
MATNR
MAKTX
FROM MAKT
INTO TABLE GT_MAKT
FOR ALL ENTRIES IN GT_MARA
WHERE MATNR = GT_MARA-MATNR AND SPRAS = 'E'.
ENDIF.
SORT GT_MAKT BY MATNR.
LOOP AT GT_MARA INTO GS_MARA.
CLEAR: GS_MAKT.
READ TABLE GT_MAKT BINARY SEARCH WITH KEY MATNR = GS_MARA-MATNR
INTO GS_MAKT.
GS_OUTPUT-MATNR = GS_MARA-MATNR.
GS_OUTPUT-MTART = GS_MARA-MTART.
GS_OUTPUT-MAKTX = GS_MAKT-MAKTX.
APPEND GS_OUTPUT TO GT_OUTPUT.
ENDLOOP.
ENDIF.
*----------------------------------------------------------------------*
* End-OF-SELECTION
*----------------------------------------------------------------------*
END-OF-SELECTION.
* Output data
LIST PROCESSING
* Struct
TYPES: BEGIN OF GTY_OUTPUT1,
MTART TYPE MARA-MTART,"MATERIAL TYPE
MATNR TYPE MARA-MATNR,"MATERIAL NUMBER
MAKTX TYPE MAKT-MAKTX,"MATERIAL DES
END OF GTY_OUTPUT1.
DATA: GT_OUTPUT1 TYPE STANDARD TABLE OF GTY_OUTPUT1,
GS_OUTPUT1 TYPE GTY_OUTPUT1.
LOOP AT GT_OUTPUT INTO GS_OUTPUT.
GS_OUTPUT1-MTART = GS_OUTPUT-MTART.
GS_OUTPUT1-MATNR = GS_OUTPUT-MATNR.
GS_OUTPUT1-MAKTX = GS_OUTPUT-MAKTX.
APPEND GS_OUTPUT1 TO GT_OUTPUT1.
ENDLOOP.
SORT GT_OUTPUT1 BY MTART MATNR.
LOOP AT GT_OUTPUT1 INTO GS_OUTPUT1.
AT FIRST.
WRITE: / 'AT FIRST'.
ENDAT.
AT NEW MTART.
WRITE: /.
WRITE: /10(15) 'MATERIAL TYPE:'.
WRITE: 26(10) GS_OUTPUT1-MTART.
WRITE: /1(15) 'Material number'.
WRITE: 17(20) 'Material description'.
ENDAT.
WRITE: /1(10) GS_OUTPUT1-MATNR.
WRITE: 17(20) GS_OUTPUT1-MAKTX.
AT END OF MTART.
WRITE: /.
ULINE 10(30).
ENDAT.
AT LAST.
WRITE: / 'AT last'.
ENDAT.
ENDLOOP.
ENDIF.
Sap grid control
Data Formatting and Control Level Processing
Programming Data Retrieval
Selection Screen
Outputting Data in Lists
TOP-OF-PAGE event : generate page headersExample:
Workflow
- What is workflow ?
- Abap workflow tcodes ?
- Abap workflow tutorial ?
- Abap workflow interview questions?
- Abap workflow example ,how to create workflow ?
What is workflow ?
SAP Workflow is a tool to automate complex business processes where there is more than one user involved. SAP workflow maps the position in organization because SAP believes that Positions are more stable than the people.
SAP Workflow is a process tool that is designed to facilitate and automate business processes involving the tasks sequence performed by the users (people in the workplace) and ensure that the right work is assigned in the right sequence at the right time to the right person in the workflow. The SAP workflow can be linked to other software tools such as Microsoft Outlook or Lotus Notes. Using SAP Workflow, each step of a business transaction can be easily monitored throughout the initiation and completion of the business processes. The SAP Workflow enables the process owners to track deadlines, determine the workload as well as provide statistics on the length of time to complete work processes.
The key components of the SAP Workflow include the Workflow Definition, Work Items, Events triggers and the Organizational Structure in the workplace.
Monday, March 26, 2012
Logical database
- What is logical database ?
- Abap logical database example
- Abap logical database selection screen
- Abap logical database PCH
- Abap logical database PNP
- Abap logical database transaction
What is logical database ?
Advantages:
i)check functions which check that user input is complete, correct,and plausible.
ii)Meaningful data selection.
iii)central authorization checks for database accesses.
iv)good read access performance while retaining the hierarchical data view determined by the application logic.
Disadvantages:
i)If you donot specify a logical database in the program attributes,the GET events never occur.
ii)There is no ENDGET command,so the code block associated with an event ends with the next event statement (such as another GET or an END-OF-SELECTION).
Sunday, March 25, 2012
BADI
- What is BADI ?
- Way to find a badi in abap sap?
- Abap BADI tutorial
- Abap BADI example
- Abap badi interview questions
- Abap badi transaction
- Abap badi error handling
What is BADI ?
What is ALV ?
Step to Create SAP Query
Specify the users who should be authorized to run the query.
Indicates from which part of the SAP database the data is going to be retrieved and how the data is to be retrieved by the query.
Components of SAP query
· InfoSets - InfoSets determine to which tables, or field within a table, a query can refer. InfoSets are usually based on table joins or logical databases.These should be created with sharability in mind.
· User Groups -The user group allows you to to specify the users who are authorized to run and/or create/change queries under that user group.
· Queries - Formatting the data identified in the InfoSet to
create the desired report.