Friday, May 3, 2013
Thursday, April 25, 2013
ABAP ALV Programming Logic
This is a standard report type programming.
All you need to do is create a report program, Use OOPs style of programming if that is what is practiced in your office,
Create a ALV list.
Create a type that contains all your output field.( call it final table )
You need to use select queries to fetch the data from various tables.
Then using a loop statement you need to collate the data by reading your internal tables into the final data
.
The call the ALV method 'REUSE_ALV_LIST_DISPLAY' and pass your final internal table for display.
You use select queries on your required table.
There will be always one primary table that will serve as your base table.
Create a ALV list.
Create a type that contains all your output field.( call it final table )
You need to use select queries to fetch the data from various tables.
Then using a loop statement you need to collate the data by reading your internal tables into the final data
.
The call the ALV method 'REUSE_ALV_LIST_DISPLAY' and pass your final internal table for display.
You use select queries on your required table.
There will be always one primary table that will serve as your base table.
Simple ALV to display VBRP tables
REPORT ZBSD_ZAR_52022.
DATA: GT_SFLIGHT TYPE TABLE OF VBRP.
DATA: G_REPID TYPE SY-REPID.
SELECT * FROM VBRP INTO TABLE GT_SFLIGHT.
G_REPID = SY-REPID.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = G_REPID
I_STRUCTURE_NAME = 'VBRP'
I_SAVE = 'A' "Standard and user specific
TABLES
T_OUTTAB = GT_SFLIGHT.
output
DATA: GT_SFLIGHT TYPE TABLE OF VBRP.
DATA: G_REPID TYPE SY-REPID.
SELECT * FROM VBRP INTO TABLE GT_SFLIGHT.
G_REPID = SY-REPID.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = G_REPID
I_STRUCTURE_NAME = 'VBRP'
I_SAVE = 'A' "Standard and user specific
TABLES
T_OUTTAB = GT_SFLIGHT.
output
ALV Demo Programs in SAP
Go To
SE80
PACKAGE
SELECT - SLIS
Example -
DATA: GT_SFLIGHT TYPE TABLE OF SFLIGHT.
DATA: G_REPID TYPE SY-REPID.
SELECT * FROM SFLIGHT INTO TABLE GT_SFLIGHT.
G_REPID = SY-REPID.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = G_REPID
I_STRUCTURE_NAME = 'SFLIGHT'
I_SAVE = 'A' "Standard and user specific
TABLES
T_OUTTAB = GT_SFLIGHT.
SE80
PACKAGE
SELECT - SLIS
Example -
DATA: GT_SFLIGHT TYPE TABLE OF SFLIGHT.
DATA: G_REPID TYPE SY-REPID.
SELECT * FROM SFLIGHT INTO TABLE GT_SFLIGHT.
G_REPID = SY-REPID.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = G_REPID
I_STRUCTURE_NAME = 'SFLIGHT'
I_SAVE = 'A' "Standard and user specific
TABLES
T_OUTTAB = GT_SFLIGHT.
VBRP, KONV, VBRK tables selection UP TO 5 ROWS program
REPORT ZBSD_ZAR_52023.
TABLES: VBRP, KONV, VBRK.
DATA: it TYPE VBRP.
DATA: it1 TYPE KONV.
DATA: it2 TYPE VBRK.
SELECT MATNR VRKME NETWR FKIMG
FROM VBRP
INTO (IT-MATNR, IT-VRKME, IT-NETWR, IT-FKIMG) UP TO 5 ROWS.
WRITE: / it-matnr, it-vrkme, it-netwr.
ENDSELECT.
SELECT KBETR
FROM KONV
INTO (IT1-KBETR) UP TO 5 ROWS.
WRITE: / it1-KBETR.
ENDSELECT.
SELECT VBELN FKDAT
FROM VBRK
INTO (IT2-VBELN, IT2-FKDAT) UP TO 5 ROWS.
WRITE: / IT2-VBELN, IT2-FKDAT.
ENDSELECT.
output-
TABLES: VBRP, KONV, VBRK.
DATA: it TYPE VBRP.
DATA: it1 TYPE KONV.
DATA: it2 TYPE VBRK.
SELECT MATNR VRKME NETWR FKIMG
FROM VBRP
INTO (IT-MATNR, IT-VRKME, IT-NETWR, IT-FKIMG) UP TO 5 ROWS.
WRITE: / it-matnr, it-vrkme, it-netwr.
ENDSELECT.
SELECT KBETR
FROM KONV
INTO (IT1-KBETR) UP TO 5 ROWS.
WRITE: / it1-KBETR.
ENDSELECT.
SELECT VBELN FKDAT
FROM VBRK
INTO (IT2-VBELN, IT2-FKDAT) UP TO 5 ROWS.
WRITE: / IT2-VBELN, IT2-FKDAT.
ENDSELECT.
output-
Three Fields Selection REUSE_ALV_EVENTS_GET example
*&---------------------------------------------------------------------*
*& Report ZBSD_ZAR_5202222
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZBSD_ZAR_5202222.
************************************************************************
* Program Name : ZR_00188B3F78331ED2ABB29778F269541E
* Description :
* Created On : 25.04.13
* Developer :
* Modification Log
************************************************************************
* Transport# Date Developer Description
************************************************************************
* 25.04.13
************************************************************************
************************************************************************
************************************************************************
***************DATA DECLARATION*****************************************
************************************************************************
************************************************************************
************************************************************************
***************ALV TYPE POOLS*******************************************
************************************************************************
TYPE-POOLS:
SLIS,KKBLO.
************************************************************************
***************SAP TABLES***********************************************
************************************************************************
TABLES:
VBRP. "Billing Document: Item Data
************************************************************************
***************CONSTANTS************************************************
************************************************************************
Constants:
C_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE',
X VALUE 'X',
YES VALUE 'Y',
NO VALUE 'N'.
************************************************************************
***************TYPES****************************************************
************************************************************************
TYPES: BEGIN OF TP_VBRP,
VRKME TYPE VRKME, "VRKME
NETWR TYPE NETWR_FP, "NETWR_FP
MATNR TYPE MATNR, "MATNR
END OF TP_VBRP.
TYPES: BEGIN OF TP_COLLECT,
VRKME TYPE VRKME, "Sales unit
NETWR TYPE NETWR_FP, "Net value
MATNR TYPE MATNR, "Material
END OF TP_COLLECT.
************************************************************************
***************VARIABLES************************************************
************************************************************************
DATA:
GV_FIELDNAME TYPE FIELDNAME,
GV_FIELDVALUE TYPE CHAR100.
************************************************************************
***************DATA STRUCTURE*******************************************
************************************************************************
DATA:
GS_VBRP TYPE TP_VBRP,
GS_COLLECT TYPE TP_COLLECT.
************************************************************************
***************FIELD SYMBOLS********************************************
************************************************************************
FIELD-SYMBOLS:
<xicon1> TYPE icon_l2,
<xicon2> TYPE icon_l2,
<xicon1h> TYPE icon_l2,
<xicon2h> TYPE icon_l2,
<collect> TYPE tp_collect.
************************************************************************
***************INTERNAL TABLES******************************************
************************************************************************
DATA:
GT_VBRP TYPE TABLE OF TP_VBRP,
GT_COLLECT TYPE TABLE OF TP_COLLECT.
***ALV Tables*****
DATA:
gt_field_cat TYPE SLIS_T_FIELDCAT_ALV,
GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
************************************************************************
************************************************************************
************************************************************************
***************PARAMETERS***********************************************
************************************************************************
************************************************************************
selection-screen begin of block b1 with frame.
selection-screen end of block b1.
************************************************************************
************************************************************************
************************************************************************
***************INIT SEL*************************************************
************************************************************************
************************************************************************
INITIALIZATION.
perform 010init_sel.
************************************************************************
************************************************************************
************************************************************************
***************MAIN PROGRAM*********************************************
************************************************************************
************************************************************************
START-OF-SELECTION.
perform 020select_data.
perform 030collect_data.
perform 040display_data.
END-OF-SELECTION.
************************************************************************
***************END OF MAIN PROGRAM**************************************
************************************************************************
form 010init_sel.
endform.
form 020select_data.
SELECT VBRP~VRKME VBRP~NETWR VBRP~MATNR
INTO CORRESPONDING FIELDS OF TABLE GT_COLLECT
FROM VBRP.
endform.
form 030collect_data.
loop at GT_COLLECT ASSIGNING <COLLECT>.
endloop.
endform.
form 040display_data.
data: lt_events TYPE slis_t_event,
ls_layout TYPE SLIS_LAYOUT_ALV.
ls_layout-colwidth_optimize = x.
perform ALV_catalog using:
'VRKME' space 'VRKME' 'Sales unit',
'NETWR' space 'NETWR_FP' 'Net value',
'MATNR' space 'MATNR' 'Material'.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = lt_events.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = sy-repid
I_callback_user_command = 'USER_COMMAND'
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
IT_FIELDCAT = gt_field_cat
IS_LAYOUT = ls_layout
I_SAVE = 'U'
it_events = lt_events[]
TABLES
T_OUTTAB = GT_COLLECT
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
endform.
form ALV_catalog using: fieldname key rollname seltext_s.
data: ls_field_cat type slis_fieldcat_alv,
lv_col type i.
DESCRIBE TABLE gt_field_cat lines lv_col.
ls_field_cat-col_pos = lv_col + 1.
ls_field_cat-fieldname = fieldname.
ls_field_cat-key = key.
ls_field_cat-seltext_s = seltext_s.
ls_field_cat-seltext_l = seltext_s.
ls_field_cat-seltext_m = seltext_s.
ls_field_cat-reptext_ddic = seltext_s.
ls_field_cat-no_zero = x.
ls_field_cat-rollname = rollname.
append ls_field_cat to gt_field_cat.
endform.
form TOP_OF_PAGE .
perform HEADER_BUILD CHANGING GT_LIST_TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = GT_LIST_TOP_OF_PAGE.
endform.
form HEADER_BUILD CHANGING GT_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
DATA: LS_LINE TYPE SLIS_LISTHEADER.
refresh: GT_TOP_OF_PAGE.
endform.
Output
*& Report ZBSD_ZAR_5202222
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZBSD_ZAR_5202222.
************************************************************************
* Program Name : ZR_00188B3F78331ED2ABB29778F269541E
* Description :
* Created On : 25.04.13
* Developer :
* Modification Log
************************************************************************
* Transport# Date Developer Description
************************************************************************
* 25.04.13
************************************************************************
************************************************************************
************************************************************************
***************DATA DECLARATION*****************************************
************************************************************************
************************************************************************
************************************************************************
***************ALV TYPE POOLS*******************************************
************************************************************************
TYPE-POOLS:
SLIS,KKBLO.
************************************************************************
***************SAP TABLES***********************************************
************************************************************************
TABLES:
VBRP. "Billing Document: Item Data
************************************************************************
***************CONSTANTS************************************************
************************************************************************
Constants:
C_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE',
X VALUE 'X',
YES VALUE 'Y',
NO VALUE 'N'.
************************************************************************
***************TYPES****************************************************
************************************************************************
TYPES: BEGIN OF TP_VBRP,
VRKME TYPE VRKME, "VRKME
NETWR TYPE NETWR_FP, "NETWR_FP
MATNR TYPE MATNR, "MATNR
END OF TP_VBRP.
TYPES: BEGIN OF TP_COLLECT,
VRKME TYPE VRKME, "Sales unit
NETWR TYPE NETWR_FP, "Net value
MATNR TYPE MATNR, "Material
END OF TP_COLLECT.
************************************************************************
***************VARIABLES************************************************
************************************************************************
DATA:
GV_FIELDNAME TYPE FIELDNAME,
GV_FIELDVALUE TYPE CHAR100.
************************************************************************
***************DATA STRUCTURE*******************************************
************************************************************************
DATA:
GS_VBRP TYPE TP_VBRP,
GS_COLLECT TYPE TP_COLLECT.
************************************************************************
***************FIELD SYMBOLS********************************************
************************************************************************
FIELD-SYMBOLS:
<xicon1> TYPE icon_l2,
<xicon2> TYPE icon_l2,
<xicon1h> TYPE icon_l2,
<xicon2h> TYPE icon_l2,
<collect> TYPE tp_collect.
************************************************************************
***************INTERNAL TABLES******************************************
************************************************************************
DATA:
GT_VBRP TYPE TABLE OF TP_VBRP,
GT_COLLECT TYPE TABLE OF TP_COLLECT.
***ALV Tables*****
DATA:
gt_field_cat TYPE SLIS_T_FIELDCAT_ALV,
GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
************************************************************************
************************************************************************
************************************************************************
***************PARAMETERS***********************************************
************************************************************************
************************************************************************
selection-screen begin of block b1 with frame.
selection-screen end of block b1.
************************************************************************
************************************************************************
************************************************************************
***************INIT SEL*************************************************
************************************************************************
************************************************************************
INITIALIZATION.
perform 010init_sel.
************************************************************************
************************************************************************
************************************************************************
***************MAIN PROGRAM*********************************************
************************************************************************
************************************************************************
START-OF-SELECTION.
perform 020select_data.
perform 030collect_data.
perform 040display_data.
END-OF-SELECTION.
************************************************************************
***************END OF MAIN PROGRAM**************************************
************************************************************************
form 010init_sel.
endform.
form 020select_data.
SELECT VBRP~VRKME VBRP~NETWR VBRP~MATNR
INTO CORRESPONDING FIELDS OF TABLE GT_COLLECT
FROM VBRP.
endform.
form 030collect_data.
loop at GT_COLLECT ASSIGNING <COLLECT>.
endloop.
endform.
form 040display_data.
data: lt_events TYPE slis_t_event,
ls_layout TYPE SLIS_LAYOUT_ALV.
ls_layout-colwidth_optimize = x.
perform ALV_catalog using:
'VRKME' space 'VRKME' 'Sales unit',
'NETWR' space 'NETWR_FP' 'Net value',
'MATNR' space 'MATNR' 'Material'.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = lt_events.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = sy-repid
I_callback_user_command = 'USER_COMMAND'
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
IT_FIELDCAT = gt_field_cat
IS_LAYOUT = ls_layout
I_SAVE = 'U'
it_events = lt_events[]
TABLES
T_OUTTAB = GT_COLLECT
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
endform.
form ALV_catalog using: fieldname key rollname seltext_s.
data: ls_field_cat type slis_fieldcat_alv,
lv_col type i.
DESCRIBE TABLE gt_field_cat lines lv_col.
ls_field_cat-col_pos = lv_col + 1.
ls_field_cat-fieldname = fieldname.
ls_field_cat-key = key.
ls_field_cat-seltext_s = seltext_s.
ls_field_cat-seltext_l = seltext_s.
ls_field_cat-seltext_m = seltext_s.
ls_field_cat-reptext_ddic = seltext_s.
ls_field_cat-no_zero = x.
ls_field_cat-rollname = rollname.
append ls_field_cat to gt_field_cat.
endform.
form TOP_OF_PAGE .
perform HEADER_BUILD CHANGING GT_LIST_TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = GT_LIST_TOP_OF_PAGE.
endform.
form HEADER_BUILD CHANGING GT_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
DATA: LS_LINE TYPE SLIS_LISTHEADER.
refresh: GT_TOP_OF_PAGE.
endform.
Output
Tuesday, April 23, 2013
ABAP Sample Program using Internal tables
ABAP Sample Program using Internal tables
REPORT ZBSD_ZAR_52022.
DATA: it1 TYPE KONV.
DATA: it2 TYPE VBRK.
DATA: it TYPE VBRP.
SELECT * FROM VBRP INTO it UP TO 5 ROWS.
WRITE: / it-matnr, it-vrkme, it-netwr.
ENDSELECT.
ULINE.
SELECT * FROM VBRK INTO it2 UP TO 5 ROWS.
WRITE: / it2-VBELN.
ENDSELECT.
ULINE.
SELECT * FROM KONV INTO it1 UP TO 5 ROWS.
WRITE / it1-KBETR.
ENDSELECT.
ABAP Events And Processing Blocks
Events/Processing blocks in ABAP
Start of an event is marked by event keyword.
End of an event is indicated by start of another event.
INITIALIZATION
Before the standard selection screen is displayed
AT SELECTION-SCREEN
After user input on a selection screen has been processed, but while the selection screen is still active
START-OF-SELECTION
After the standard selection screen has been processed, before data is read from the logical database
GET node
After the logical database has read a data record from the node node
GET node LATE
After all of the nodes of the logical database have been processed that are hierarchically subordinate to the node in the structure of the logical database
END-OF-SELECTION
This event is generally used to mark the end of GET node event in reports where LDB’s are used
List processor events:
TOP-OF-PAGEIn list processing when a new page starts. Frequently used in Simple Reports to display header data.
This event is executed whenever the first WRITE statement is encountered. System first executes the TOP OF PAGE event and then processes the WRITE statement.
END-OF-PAGE
In list processing when a page ends. Generally used in Simple Reports to print footer data.
AT LINE-SELECTION
Triggers when a specific line in the output is selected. Generally used in Simple Drill down reports for navigation. sy-lisel holds the content of the line that was clicked
AT PFnn
When the user triggers the predefined function code
PFnnAT USER-COMMAND
When the user triggers a function code defined in the program
Start of an event is marked by event keyword.
End of an event is indicated by start of another event.
INITIALIZATION
Before the standard selection screen is displayed
AT SELECTION-SCREEN
After user input on a selection screen has been processed, but while the selection screen is still active
START-OF-SELECTION
After the standard selection screen has been processed, before data is read from the logical database
GET node
After the logical database has read a data record from the node node
GET node LATE
After all of the nodes of the logical database have been processed that are hierarchically subordinate to the node in the structure of the logical database
END-OF-SELECTION
This event is generally used to mark the end of GET node event in reports where LDB’s are used
List processor events:
TOP-OF-PAGEIn list processing when a new page starts. Frequently used in Simple Reports to display header data.
This event is executed whenever the first WRITE statement is encountered. System first executes the TOP OF PAGE event and then processes the WRITE statement.
END-OF-PAGE
In list processing when a page ends. Generally used in Simple Reports to print footer data.
AT LINE-SELECTION
Triggers when a specific line in the output is selected. Generally used in Simple Drill down reports for navigation. sy-lisel holds the content of the line that was clicked
AT PFnn
When the user triggers the predefined function code
PFnnAT USER-COMMAND
When the user triggers a function code defined in the program
Monday, April 22, 2013
Use of ALV Program
*&---------------------------------------------------------------------*
*& Report ZBSD_ZAR_520222
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZBSD_ZAR_520222.
DATA:
gs_saplane TYPE saplane,
gt_saplane TYPE TABLE OF saplane.
SELECT * FROM saplane INTO TABLE gt_saplane.
TYPE-POOLS slis.
DATA:
gt_fieldcat TYPE slis_t_fieldcat_alv,
gv_title TYPE lvc_title.
gv_title = 'SAP Table SAPLANE contents'.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = SY-REPID
i_structure_name = 'saplane'
CHANGING
ct_fieldcat = gt_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = gt_fieldcat
i_grid_title = gv_title
TABLES
t_outtab = gt_saplane.
*& Report ZBSD_ZAR_520222
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZBSD_ZAR_520222.
DATA:
gs_saplane TYPE saplane,
gt_saplane TYPE TABLE OF saplane.
SELECT * FROM saplane INTO TABLE gt_saplane.
TYPE-POOLS slis.
DATA:
gt_fieldcat TYPE slis_t_fieldcat_alv,
gv_title TYPE lvc_title.
gv_title = 'SAP Table SAPLANE contents'.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = SY-REPID
i_structure_name = 'saplane'
CHANGING
ct_fieldcat = gt_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = gt_fieldcat
i_grid_title = gv_title
TABLES
t_outtab = gt_saplane.
Tuesday, April 16, 2013
Formatting ABAP Table Display
*&---------------------------------------------------------------------*
*& Report ZTWO
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZTWO.
*NESTED LOOP
DATA:
gs_saplane TYPE CATSDB,
gt_saplane TYPE TABLE OF CATSDB.
WRITE:/20 'NORMAL CATSDB TABLE'. "(10) makes field take up 10 chars
WRITE:/20 sy-uline(19).
skip 1.
SELECT * FROM CATSDB INTO TABLE gt_saplane.
WRITE:/1 sy-vline,
'CREATED ON' COLOR COL_HEADING, sy-vline,(20)
'PROCESSING TIME' COLOR COL_HEADING, sy-vline,(30)
'DATE' COLOR COL_HEADING, sy-vline.
LOOP AT gt_saplane INTO gs_saplane.
WRITE: /1 sy-vline,
gs_saplane-ERSDA COLOR COL_HEADING, sy-vline,
(20) gs_saplane-STATUS COLOR COL_HEADING, sy-vline,
(30) gs_saplane-WORKDATE COLOR COL_HEADING, sy-vline.
ENDLOOP.
ULINE.
skip 2.
SELECT * FROM CATSDB INTO TABLE gt_saplane.
WRITE:/30 'LOOP ON CATS DB TABLE'.
WRITE:/1 'Created On ' color 5,
(30) 'Processing Time' color 5.
*LOOP SHOW PROCESS UNDER 20
LOOP AT gt_saplane INTO gs_saplane WHERE STATUS = 20.
WRITE: /1 gs_saplane-ERSDA,(20)
gs_saplane-STATUS.
ENDLOOP.
EXIT.
OUTPUT
*& Report ZTWO
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZTWO.
*NESTED LOOP
DATA:
gs_saplane TYPE CATSDB,
gt_saplane TYPE TABLE OF CATSDB.
WRITE:/20 'NORMAL CATSDB TABLE'. "(10) makes field take up 10 chars
WRITE:/20 sy-uline(19).
skip 1.
SELECT * FROM CATSDB INTO TABLE gt_saplane.
WRITE:/1 sy-vline,
'CREATED ON' COLOR COL_HEADING, sy-vline,(20)
'PROCESSING TIME' COLOR COL_HEADING, sy-vline,(30)
'DATE' COLOR COL_HEADING, sy-vline.
LOOP AT gt_saplane INTO gs_saplane.
WRITE: /1 sy-vline,
gs_saplane-ERSDA COLOR COL_HEADING, sy-vline,
(20) gs_saplane-STATUS COLOR COL_HEADING, sy-vline,
(30) gs_saplane-WORKDATE COLOR COL_HEADING, sy-vline.
ENDLOOP.
ULINE.
skip 2.
SELECT * FROM CATSDB INTO TABLE gt_saplane.
WRITE:/30 'LOOP ON CATS DB TABLE'.
WRITE:/1 'Created On ' color 5,
(30) 'Processing Time' color 5.
*LOOP SHOW PROCESS UNDER 20
LOOP AT gt_saplane INTO gs_saplane WHERE STATUS = 20.
WRITE: /1 gs_saplane-ERSDA,(20)
gs_saplane-STATUS.
ENDLOOP.
EXIT.
OUTPUT
Monday, April 15, 2013
ABAP Function Module Example
ABAP Function Module Example | How to create a function module in abap | call function in abap
Steps2 - Go to - SE37
Step 2 - GoTo menu - Function Group - Create Group
Step 3- Give the desired function group name and a short text. - Create - Save
Step 4 - Enter the import and export parameters.
Step 5 - Write the code in the source code area.
Step 6 - Then open the transaction se80 and select the ‘Function group’ from the drop down list. Enter the function group name. Press Enter.
Step 7 - Right click on "Your Module Name" and press activate.
Step 8 - Write code in your program
CALL FUNCTION 'Your Module Name'
EXPORT
IMPORT
Steps2 - Go to - SE37
Step 2 - GoTo menu - Function Group - Create Group
Step 3- Give the desired function group name and a short text. - Create - Save
Step 4 - Enter the import and export parameters.
Step 5 - Write the code in the source code area.
Step 6 - Then open the transaction se80 and select the ‘Function group’ from the drop down list. Enter the function group name. Press Enter.
Step 7 - Right click on "Your Module Name" and press activate.
Step 8 - Write code in your program
CALL FUNCTION 'Your Module Name'
EXPORT
IMPORT
Wednesday, April 10, 2013
SAP ABAP TABLES
Internal Tables - These are used to store the temp data inside the program.
- Standerd Table
- Sorted Table
- Hashed Table
Standerd Table - We can reuse them as many time, KEY of the standerd table always non unique and duplication are allowed and possible.
Syntax- DATA <ITAB> THE STANDARD TABLE OF <TY>.
Sorted Table - Recored are always sorted
We can add data using INSERT command to these tables.
Records can be accessed through in two ways INDEX and with KEY(Condition).
Once sorted Internal tables cannot be sorted again.
Syntax - DATA <ITAB> TYPE SORTED TABLE OF <TY> WITH UNIQUE/NON-UNIQUE KEY <Function 1 ><Function 2>
Hashed Table - We can access any data directly using KEY
Hash tables always must have a uniq KEY
Syntax - DATA <ITAB> TYPE HASHED TABLE OF <TY> UNIQUE/NON-UNIQUE KEY <F1><F2>…
We not able to cannot access a hashed table using its INDEX.
Tuesday, April 9, 2013
Simple Calculator Program In ABAP
*---Simple Calculator Program In ABAP using parameter passing.--*
REPORT ZTFIVE.
PARAMETERS:
pa_int1 TYPE i,
pa_op TYPE c Length 1,
pa_int2 TYPE i.
DATA gv_result TYPE p LENGTH 16 DECIMALS 2.
IF ( pa_op = '+' OR
pa_op = '-' OR
pa_op = '*').
CASE pa_op.
WHEN '+'.
gv_result = pa_int1 + pa_int2.
WHEN '-'.
gv_result = pa_int1 - pa_int2.
WHEN '*'.
gv_result = pa_int1 * pa_int2.
ENDCASE.
WRITE: 'Result'(res), gv_result.
ENDIF.
OUTPUT
REPORT ZTFIVE.
PARAMETERS:
pa_int1 TYPE i,
pa_op TYPE c Length 1,
pa_int2 TYPE i.
DATA gv_result TYPE p LENGTH 16 DECIMALS 2.
IF ( pa_op = '+' OR
pa_op = '-' OR
pa_op = '*').
CASE pa_op.
WHEN '+'.
gv_result = pa_int1 + pa_int2.
WHEN '-'.
gv_result = pa_int1 - pa_int2.
WHEN '*'.
gv_result = pa_int1 * pa_int2.
ENDCASE.
WRITE: 'Result'(res), gv_result.
ENDIF.
OUTPUT
ABAP Date Types and Objects
ABAP allready have the following Pre-defined Data Types in it.
Non-Numeric Data Types :
- Character String (C)
- Numeric Character String (N)
- Date (D)
- Time (T)
Numeric Types :
- Integer (I)
- Floating-point number (F)
- Packed Number (P)
ABAP Keywords
Keywords :
Remember Each ABAP statement Should begin with a keyword and ends with a period.
Diffrent Types Of Keywords :
Declarative Key words : To Declare Variables.
TYPES, DATA, TABLES
Syntax for the Variables : DATA < Var. Name> TYPE <Data Types>.
Diffrent Database Keywords : To Working With The Database Operations Such as
- SELECT - To Select Data From The Table
- INSERT - To Insert Data From The Table
- UPDATE - To Change Data From The Table
- DELETE - To Delete Data From The Table..etc
Control Keywords :
IF, ELSEIF, ENDIF.
DO-ENDDO, WHILE – ENDWHILE.
Definition Keywords - Re-usable Modules
Ex :
- FORM - ENDFORM
- FUINCTION - ENDFUNCTION
- MODULE - ENDMODULE
Calling Keywords :
Are used to call Re-usable Modules (Blocks) that are already defined.
PERFORM to Call FORM
CALL FUNCTION to Call FUNCTION
MODULE to Call MODULE
Operational Key Words :
Ex : WRITE, MOVE, ADD
Event Keywords :
Ex : TOP-OF-PAGE To Print the Same Heading On the TOP Of Every Page.
How To Remember Table In SAP
When you are new in SAP its really hard to remember all existed tables inside SAP. You can use below given logic.
Finance module Tables
- The all vendor tables start with L such as lfa1, etc..
- The all customer tables start with K ... Kna1, konv...
- The all sales tables start with V... vbak vbap
- The all master data tables start with T... T001, t001w
- The all bank tables start with B.. Bknf, bkpf....
- The all purchasing tables start with E.. ekko, ekpo etc..
- The all material tables start with M... mara, makt, marc...
- In sales, delivery, billing, purchasing... if the tables name contains K init it is Header data such as vbak, likp, vbrk, ekko...
- If the tables name contains P init it is Item data .... such as vbap, lips, vbrp, ekpo ....
Finance module Tables
- If the table name contains I, that is open item
- If the table name contains A, that is closed item
- If the table name ends with S, that is GL account
- exp BSIS- GL master open items
- BSAS- GL master closed items
- like wise...
- If the table name ends with D, that is customer
- If the table name ends with K, that is vendor
SAP Selection Screen Programs
Program for the all types of SAP selection screen events.
Example
REPORT ZTHREE.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
"----Parameters---"
PARAMETERS: P_STATUS(10).
"-----selection options-"
data: lv_number type int4.
select-options: s_number for lv_number.
"---check box--"
PARAMETERS: P_CH_BOX AS CHECKBOX.
"---RADIO BUTTONS--"
PARAMETERS: p_radio1 radiobutton group grp1,
p_radio2 radiobutton group grp1.
"----push button---"
SELECTION-SCREEN: BEGIN OF LINE,
"------DIMENSION FROM THE 2 SPOT OF THE LINE TWO THE 10-----"
PUSHBUTTON 2(10) text-003 USER-COMMAND cl1,
PUSHBUTTON 12(10) text-004 USER-COMMAND cl2,
END OF LINE.
"---dropbox-- write always - VISIABLE LENGTH----"
PARAMETERS: p_list as LISTBOX VISIBLE LENGTH 10.
SELECTION-SCREEN END OF BLOCK B1.
Example
REPORT ZTHREE.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
"----Parameters---"
PARAMETERS: P_STATUS(10).
"-----selection options-"
data: lv_number type int4.
select-options: s_number for lv_number.
"---check box--"
PARAMETERS: P_CH_BOX AS CHECKBOX.
"---RADIO BUTTONS--"
PARAMETERS: p_radio1 radiobutton group grp1,
p_radio2 radiobutton group grp1.
"----push button---"
SELECTION-SCREEN: BEGIN OF LINE,
"------DIMENSION FROM THE 2 SPOT OF THE LINE TWO THE 10-----"
PUSHBUTTON 2(10) text-003 USER-COMMAND cl1,
PUSHBUTTON 12(10) text-004 USER-COMMAND cl2,
END OF LINE.
"---dropbox-- write always - VISIABLE LENGTH----"
PARAMETERS: p_list as LISTBOX VISIBLE LENGTH 10.
SELECTION-SCREEN END OF BLOCK B1.
SAP WHERE Statement
Program to use WHERE Statement in SAP
Example
REPORT ZG15.
"Internal table declaration
DATA: it TYPE EKPO.
WRITE:/1 'Item' color 5,9 'Short Text' color 5,27 'Order Quantity' color 5,
37 'Price Unit' color 5,49 'Price Date' color 5.
"Data retrieval
SELECT * FROM EKPO INTO it UP TO 100 ROWS WHERE peinh = 10.
WRITE:/1 it-ebelp, 9 it-txz01,
27 it-menge,37 it-peinh,
49 it-prdat.
ENDSELECT.
SYNTAX
SELECT *|<FLD_LIST>
FROM <DB_TABLE>
INTO TABLE <ITAB>
WHERE <CONDITION>.
Example
REPORT ZG15.
"Internal table declaration
DATA: it TYPE EKPO.
WRITE:/1 'Item' color 5,9 'Short Text' color 5,27 'Order Quantity' color 5,
37 'Price Unit' color 5,49 'Price Date' color 5.
"Data retrieval
SELECT * FROM EKPO INTO it UP TO 100 ROWS WHERE peinh = 10.
WRITE:/1 it-ebelp, 9 it-txz01,
27 it-menge,37 it-peinh,
49 it-prdat.
ENDSELECT.
SYNTAX
SELECT *|<FLD_LIST>
FROM <DB_TABLE>
INTO TABLE <ITAB>
WHERE <CONDITION>.
SAP INNER JOIN WITH 4 Tables
SAP Program to Inner Join Between 4 Tables
Example
REPORT zgo7.
TABLES: mara , mkpf, mseg.
DATA: BEGIN OF it OCCURS 0,
matnr LIKE mara-matnr, "Material
meins LIKE mara-meins, "Base Unit of Measure
menge LIKE mseg-menge, "Quantity / Price per base unit of measure
lifnr LIKE mseg-lifnr, "VENDOR
bldat LIKE mkpf-bldat, "Document Date
mjahr LIKE mkpf-mjahr, "Material Doc. Year
makt LIKE makt-maktx, "Material Description
END OF it.
SELECT a~matnr a~meins b~menge b~lifnr c~bldat c~mjahr d~maktx
INTO TABLE it
FROM mara AS a
INNER JOIN mseg AS b ON a~matnr EQ b~matnr
INNER JOIN mkpf AS c ON c~mblnr EQ b~mblnr
INNER JOIN makt AS d ON d~matnr EQ a~matnr.
WRITE: / 'Material', 25 'Quantity', 35 'Base Unit of Measure', 45 'VENDOR', 55 'Document Date', 65 'Material Doc Year', 75 'Material Description'.
LOOP AT it.
WRITE: / it-matnr, it-menge, it-meins, it-lifnr, it-bldat, it-mjahr, it-makt.
ENDLOOP.
Example
REPORT zgo7.
TABLES: mara , mkpf, mseg.
DATA: BEGIN OF it OCCURS 0,
matnr LIKE mara-matnr, "Material
meins LIKE mara-meins, "Base Unit of Measure
menge LIKE mseg-menge, "Quantity / Price per base unit of measure
lifnr LIKE mseg-lifnr, "VENDOR
bldat LIKE mkpf-bldat, "Document Date
mjahr LIKE mkpf-mjahr, "Material Doc. Year
makt LIKE makt-maktx, "Material Description
END OF it.
SELECT a~matnr a~meins b~menge b~lifnr c~bldat c~mjahr d~maktx
INTO TABLE it
FROM mara AS a
INNER JOIN mseg AS b ON a~matnr EQ b~matnr
INNER JOIN mkpf AS c ON c~mblnr EQ b~mblnr
INNER JOIN makt AS d ON d~matnr EQ a~matnr.
WRITE: / 'Material', 25 'Quantity', 35 'Base Unit of Measure', 45 'VENDOR', 55 'Document Date', 65 'Material Doc Year', 75 'Material Description'.
LOOP AT it.
WRITE: / it-matnr, it-menge, it-meins, it-lifnr, it-bldat, it-mjahr, it-makt.
ENDLOOP.
SELECT AND DISPLAY SAP TABLE CONTENTS
Program to SELECT AND DISPLAY SAP TABLE CONTENTS
Example 1
REPORT ZG15.
"Internal table declaration
DATA: it TYPE EKPO.
WRITE:/1 'Item' color 5,9 'Short Text' color 5,17 'Order Quantity' color 5,
27 'Price Unit' color 5,39 'Price Date' color 5.
"Data retrieval
SELECT * FROM EKPO INTO it UP TO 10 ROWS.
WRITE:/1 it-ebelp, 9 it-txz01,
17 it-menge,27 it-peinh,
39 it-prdat.
ENDSELECT.
Example 2
REPORT ZGO1.
DATA:
gs_saplane TYPE MSEG,
gt_saplane TYPE TABLE OF MSEG.
SELECT * FROM MSEG INTO TABLE gt_saplane.
LOOP AT gt_saplane INTO gs_saplane.
WRITE: /
gs_saplane-MATNR,
gs_saplane-DMBTR,
gs_saplane-WAERS.
ENDLOOP.
EXIT.
Example 1
REPORT ZG15.
"Internal table declaration
DATA: it TYPE EKPO.
WRITE:/1 'Item' color 5,9 'Short Text' color 5,17 'Order Quantity' color 5,
27 'Price Unit' color 5,39 'Price Date' color 5.
"Data retrieval
SELECT * FROM EKPO INTO it UP TO 10 ROWS.
WRITE:/1 it-ebelp, 9 it-txz01,
17 it-menge,27 it-peinh,
39 it-prdat.
ENDSELECT.
Example 2
REPORT ZGO1.
DATA:
gs_saplane TYPE MSEG,
gt_saplane TYPE TABLE OF MSEG.
SELECT * FROM MSEG INTO TABLE gt_saplane.
LOOP AT gt_saplane INTO gs_saplane.
WRITE: /
gs_saplane-MATNR,
gs_saplane-DMBTR,
gs_saplane-WAERS.
ENDLOOP.
EXIT.
SAP Hello World Program And Basic Fundamentals
SAP Typical Architecture
How to write a programm in sap?
Use the SE38 transaction code.
SE38 - Tools -> ABAP Workbench -> Development -> ABAP Editor
Create a program name with Z or Y - Example - ZTFOUR
Subobject - Sourcecode
Titile - Hello World
Attribute
Types - Executable Program
SAVE
Create Object Directory Entry
Local Object
"------Program Code----"
REPORT ZTFOUR.
DATA: VAR(50).
VAR = ‘Hello World’.
write: var.
How to write a programm in sap?
Use the SE38 transaction code.
SE38 - Tools -> ABAP Workbench -> Development -> ABAP Editor
Create a program name with Z or Y - Example - ZTFOUR
Subobject - Sourcecode
Titile - Hello World
Attribute
Types - Executable Program
SAVE
Create Object Directory Entry
Local Object
"------Program Code----"
REPORT ZTFOUR.
DATA: VAR(50).
VAR = ‘Hello World’.
write: var.
Subscribe to:
Posts (Atom)