Sunday, February 19, 2012

DAy 5

Sy-Index is for the no of loops in a do or where command.
Sy-Tabbix is for No.of rows in an internal table.

U CAN ALSO USE HEADER LINE INSTEAD OF WORK AREA
DATA: BEGIN OF STU,
CARRID TYPE SCARR-CARRID,
CARRNAME TYPE SCARR-CARRNAME,
END OF STU.
data: itab like stu OCCURS 0 with HEADER LINE.
SELECT CARRID CARRNAME FROM SCARR INTO TABLE ITAB.
LOOP AT ITAB.
WRITE:/ ITAB-CARRID, ITAB-CARRNAME.
ENDLOOP.

There are few changes when compared
to a normal Internal table report, as it does not use workarea.

U can also write occurs 0 at begin
of stu, but if that is the case u can not use headerline. Then u need to go for
wa. But u can still continue with data instead of changing it to types.

Create a function module Z_ADD
Import
A type i
B type i
C type i
Export
D type i


Source code
D = ( ( ( A + 5 ) * 4 ) / 2 ).
WRITE: d.
CLEAR D.
D = ( ( ( B + 5 ) * 4 ) / 2 ).
WRITE: d.
CLEAR D.
D = ( ( ( C + 5 ) * 4 ) / 2 ).
WRITE: d.

Now g to se38 ABAP Editor
Parameters : X TYPE I,
Y TYPE I,
Z TYPE I.
DATA: R TYPE I.
CALL FUNCTION 'Z_ADD'
EXPORTING
A = X
B = Y
C = Z
IMPORTING
D = R
.

Day 6

BDC- Batch Data Communictions.
This is basically used to transfer data in bulk from notepad/excel into
SAP.
For ex
We need to create say 10 Materials in SAP, instead of going and creating
each and every Material separately we
follow this method.
To create Material u need to go to MM01. Where u will be entering around
6 fields.
So instead u go to SHDB go to the transaction recorder screen.
When u press start recording, u need togo to MM01 screen which u have
already kept it open. Touch and every field that u want to enter and enter
data. Then press Finished recording.
After recording Press Program. It will transfer us from recording to
prog. You can enter the Prog Name.
After that press enter the prog that was recorded will be displayed.
In that u need to comment 4items
1)
Include
2)
Perform open group
3)
Perform bdc_transactiion using MM01
4)
Perform Close_group

We entered values in 6 fields at the
time of recording.
There are 3 modes for running BDC
A-
Show all screens
N- Show No screens
E- Show Error screens.
report ZBDC_CALL_TRANSACTION_NEW
no standard page heading line-size 255.
*include bdcrecx1.
types : BEGIN OF stu,
matnr type mara-matnr,
mbrsh type mara-mbrsh,
mtart type mara-mtart,
maktx type makt-maktx,
meins type mara-meins,
matkl type mara-matkl,
end of stu.
data : wa type stu,
itab TYPE TABLE OF stu.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:\BDC_TEST.TXT'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = ITAB
.
TYPES : BEGIN OF STU1,
PROGRAM TYPE BDCDATA-PROGRAM,
DYNPRO TYPE BDCDATA-DYNPRO,
DYNBEGIN TYPE BDCDATA-DYNBEGIN,
FNAM TYPE BDCDATA-FNAM,
FVAL TYPE BDCDATA-FVAL,
END OF STU1.
DATA : WA_BDCDATA TYPE STU1,
BDCDATA TYPE TABLE OF STU1.
start-of-selection.
*perform open_group.
LOOP AT ITAB INTO WA.
REFRESH BDCDATA.
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MTART'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RMMG1-MATNR'
WA-MATNR.
perform bdc_field using 'RMMG1-MBRSH'
WA-MBRSH.
perform bdc_field using 'RMMG1-MTART'
WA-MTART.
perform bdc_dynpro using 'SAPLMGMM' '0070'.
perform bdc_field using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
'X'.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'MAKT-MAKTX'
WA-MAKTX.
perform bdc_field using 'BDC_CURSOR'
'MARA-MATKL'.
perform bdc_field using 'MARA-MEINS'
WA-MEINS.
perform bdc_field using 'MARA-MATKL'
WA-MATKL.
perform bdc_field using 'MARA-MTPOS_MARA'
'NORM'.
CALL TRANSACTION 'MM01' USING BDCDATA MODE 'A'.
ENDLOOP.
*perform bdc_transaction using 'MM01'.
*perform close_group.
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
WA_BDCDATA-PROGRAM = PROGRAM.
WA_BDCDATA-DYNPRO = DYNPRO.
WA_BDCDATA-DYNBEGIN = 'X'.
APPEND WA_BDCDATA TO BDCDATA.
CLEAR WA_BDCDATA.
ENDFORM.
FORM BDC_FIELD USING FNAM FVAL.
WA_BDCDATA-FNAM = FNAM.
WA_BDCDATA-FVAL = FVAL.
APPEND WA_BDCDATA TO BDCDATA.
CLEAR WA_BDCDATA.
ENDFORM.

Monday, February 13, 2012

Day 4

JOINING OF TABLES

We can join tables in abap in 2 ways . They are Inner joint and left outer joint.
Lets learn inner joint first.

When you want to join 2 tables with inner joint means the system wil giveout the value only for the entry which is common in both tables

for eg
Table 1
a 4 akdshk
b 3 aksdnf
f 8 akjsdhf
g 4 jasdkfhl


Table 2
a 1.00
c 4.21
d 8.01
f 1.21
g 2.10

If you want to join 2 tables by inner joint, then the resulting table is going to be
a 4 akdshk 1.00
f 8 akjsdhf 1.21
g 4 jasdkfhl 2.10


so the prog for this is.

TYPES: BEGIN OF stu,
matnr TYPE mara-matnr,
laeda TYPE mara-laeda,
pstat TYPE mara-pstat,
mtart TYPE mara-mtart,
maktx TYPE makt-maktx,
END OF stu.

DATA: wa type stu,
itab TYPE TABLE OF stu.

SELECT a~matnr
a~laeda
a~pstat
a~mtart
b~maktx INTO TABLE itab from mara as a INNER JOIN makt as b on a~matnr = b~matnr.

LOOP AT itab INTO wa.
WRITE:/ wa-matnr, wa-laeda,wa-pstat,wa-mtart,wa-maktx.

ENDLOOP.

LEFTOUTER JOIN

In the above table eg if we want to use left outer join the result is going to be.

a 4 akdshk 1.00
f 8 akjsdhf 1.21
g 4 jasdkfhl 2.10
b 3 aksdnf 0.00

the code is the same for both inner and left outer join join except for the words inner and left outer in the prog.

TYPES: BEGIN OF stu,
matnr TYPE mara-matnr,
laeda TYPE mara-laeda,
pstat TYPE mara-pstat,
mtart TYPE mara-mtart,
maktx TYPE makt-maktx,
END OF stu.

DATA: wa type stu,
itab TYPE TABLE OF stu.

SELECT a~matnr
a~laeda
a~pstat
a~mtart
b~maktx INTO TABLE itab from mara as a LEFT OUTER JOIN makt as b on a~matnr = b~matnr.

LOOP AT itab INTO wa.
WRITE:/ wa-matnr, wa-laeda,wa-pstat,wa-mtart,wa-maktx.

ENDLOOP.

STANDARD SAP FUNCTION MODULE

Standard function modules are modules inbuilt by SAP like reuse_ALV_grid_display.

CUSTOM FUNCTION MODULE

To create function module you require function group.
To create function group goto se80. Select function group hit enter, it will ask for creation hit ok. Then give a short description.

Right click on the tree at the bottom on the right and activate.

Now got to se37 for function module.

Function Module = fin MOD_test

Import
A type i
B type i
C type i

Export
D type i

Source Code
d = a + b + c
write d.

In se38
Parameters: x type i,
y type i,
z type i.
data r type i.

call function 'z fun_Mod_Test' "Go call this function from the pattern."

Exporting

a=x
b=y
c=z
Importing
d=r.

Lets learn more about function modules in the next post.

Day 3

Let's learn about Reports.

Reports are of 3 types.
  1. Classical
  2. Interactive
  3. ALV - Mostly used reports.

Classical Report events are as follows

  1. Intialization
  2. At selection screen
  3. Start of selection
  4. End of selection
  5. Top of Page
  6. End of Page


Classical Report

TABLES MARA.
TYPES: BEGIN OF stu,
matnr TYPE mara-matnr,
mtart TYPE mara-mtart,
mbrsh TYPE mara-mbrsh,
matkl TYPE mara-matkl,
meins TYPE mara-meins,
END OF stu.

DATA: wa TYPE stu,
itab TYPE TABLE OF stu.

DATA Count TYPE i.
SELECT-OPTIONS: S_matnr for mara-matnr. " for letting you writ at-seslection command for the report"

INITIALIZATION.
Count = 5.

AT SELECTION-SCREEN.
IF S_matnr is initial.
MESSAGE 'Enter Value to Proceed' TYPE 'E'. " this is the error message that is going to display."


ENDIF.

START-OF-SELECTION.
SELECT matnr mtart mbrsh matkl meins FROM MARA INTO TABLE itab WHERE Matnr in S_matnr.

LOOP AT Itab INTO wa.
Count = count + 5.
write:/ count, wa-matnr, wa-mtart, wa-mbrsh, wa-matkl, wa-meins.

ENDLOOP.

END-of-SELECTION.

TOP-OF-Page.

WRITE:/ 'Header'.

end-of-PAGE.
WRITE:/ 'Footer'.


INTERACTIVE REPORT
In an interactive report , we write all the codes just like a classical report, on top of that we write at line selection line to make it interactive.

for that

apart from the above prog u need to include the data u want it to display from the other table . In this case , if we click on matnr we want the info of matkx.
so in the begin of stu line include.

maktx type mara-maktx


at LINE-SELECTION.
SELECT
matnr
maktx from makt INTO TABLE itab1 where matnr = wa-matnr.

LOOP AT itab1 INTO wa1.
WRITE:/ wa1-matnr, wa1-maktx.

ENDLOOP.


II exercise linking vbrk and vbrp

TABLES: VBRK , VBRP.

TYPES: BEGIN OF stu,
vbeln TYPE vbrk-vbeln,
vbtyp TYPE vbrk-vbtyp,
vtweg TYPE vbrk-vtweg,
vsbed TYPE vbrk-vsbed,
posnr TYPE vbrp-posnr,
END OF stu.

DATA: COUNT TYPE I,
WA TYPE STU,
ITAB TYPE TABLE OF STU,
WA1 TYPE STU,
ITAB1 TYPE TABLE OF STU.
SELECT-OPTIONS : S_VBELN FOR vbrk-vbeln.

INITIALIZATION.

COUNT = 1.

AT SELECTION-SCREEN.
IF S_VBELN IS INITIAL.
MESSAGE: 'PLEASE ENTER THE VALUE TO PROCEED' TYPE 'E'.
ENDIF.

START-OF-SELECTION.

SELECT vbeln
vbtyp
vtweg
vsbed FROM VBRK INTO TABLE ITAB WHERE VBELN IN S_VBELN.

LOOP AT ITAB INTO WA.
COUNT = COUNT + 1.
WRITE:/ COUNT, WA-VBELN, WA-VBTYP, WA-VTWEG, WA-VSBED.
ENDLOOP.


END-OF-SELECTION.

TOP-OF-PAGE.
WRITE:/ 'HEADER'.
END-OF-PAGE.
WRITE:/ 'FOOTER'.

at LINE-SELECTION.
SELECT vbeln posnr from vbrp INTO TABLE itab1 WHERE VBELN = wa-VBELN.
LOOP AT itab1 INTO wa1.
WRITE:/ wa1-vbeln, wa1-posnr.

ENDLOOP.

ALV REPORT

HERE YOU NEED TO WRITE A ROUTINE AND A SUB ROUTINE.

PERFORM SELECT.
PERFORM DESIGN.
PERFORM DISPLAY


TYPE-POOLS slis.
TYPES: BEGIN OF stu,
carrid TYPE scarr-carrid,
carrname TYPE scarr-carrname,
currcode TYPE scarr-currcode,
END OF stu.

DATA: wa_scarr TYPE stu,
i_scarr TYPE TABLE OF stu.
DATA: FWA TYPE SLIS_FIELDCAT_ALV,
F_TAB TYPE TABLE OF SLIS_FIELDCAT_ALV.

"noW WRITE ROTUINE"

PERFORM SELECT.
PERFORM DESIGN.
PERFORM DISPLAY.

"NOW WRITE SUB-ROTUINE"

FORM SELECT.
SELECT Carrid
carrname
currcode FROM SCARR INTO TABLE I_SCARR.
ENDFORM.

FORM dESIGN.
FWA-FIELDNAME = 'CARRID'.
FWA-SELTEXT_M = 'AIRCODE'.
FWA-KEY = 'X'. " TO mENTION THAT IT IS A KEY FIELD"
APPEND FWA TO F_TAB.
CLEAR FWA.

FWA-FIELDNAME = 'CURRCODE'.
FWA-SELTEXT_M = 'CURRENCY'.
APPEND FWA TO F_TAB.
CLEAR FWA.

ENDFORM.


FORM DISPLAY.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
* I_CALLBACK_PROGRAM = ' '
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
IT_FIELDCAT = F_TAB[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = I_SCARR[]
* 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.

Saturday, February 11, 2012

Day 1

SAP stands for System Analysis and Program Development.
SAP is an ERP ( Enterprise Resource Planning) software. This software is used by many companies which are in various business platforms.
There are even seperate IS ( Industry specific) SAP available.

SAP has 3 classification under it
  1. Technical- Under this comes ABAP and Basis
  2. Financial - Under this comes HR, Finance and Logistics like PP,MM,OTC,SD,QM
  3. Techno Functional - Under this comes BW

SAP R/3 is a 3 layer software . The layers are presentation, application and database.

ABAP mainly is used for RICEF.

RICEF stands for Reports, Interface, Conversion, Enchancement and Form. Form included SAP Script and SAP Smartform. Interface is Interfacing SAP with non SAP softwares.

Stages of SAP in a Company

  1. Implementation
  2. Support
  3. Upgrade
  4. Rollout- This means implementing the sameorganisation structure in a sister concern.

ASAP method of Implementation is followed for SAP

  1. Requirement gathering - This is where the core team{end users} sits with the IT Team.
  2. Blueprint - Making a list of things that needs to be implemented.
  3. Realisation - Assigning jobs to various people
  4. Final Preparation
  5. Go Live and Support
  6. Run - In case of any major fault or defect the IT Team interferes to solve the problem.

Tables are called data dictionary

Tcode for data dictionary is se11,se16,se16n.

Rows are called records and columns are called fields.

There are 2 kinds of tables

Standard Table (like MARA) and custom Table.

Custom Table are of 2 types, they are predefined and Data element method.

Data element has 2 types they are either Top down approach or Botton up approach.

Pre defined Table

SE11 Database table. In any table mention MANDT .

When starting custom tqable start with z or y.

Delivery class A

If you click intl and dont enter any value it will automatically take as 0 or nill.

Then go adjust Technical settings.

Go Make entries

utilization-Table contents- create entry.

or go directly to sm30.

In data element method

Top down approach- Create in below given order

  1. Field - Column
  2. Data Element - Column description.
  3. Domain - data type.

In the bottum up approach - Create table in the below given order.

  1. Domain
  2. Data Element
  3. Field.

OK Lets meet u all in DAY 2 blog of ABAP.