• No results found

SAP ABAP MATERIAL

N/A
N/A
Protected

Academic year: 2021

Share "SAP ABAP MATERIAL"

Copied!
196
0
0

Loading.... (view fulltext now)

Full text

(1)

SAP-SQL

SQL: - Structure query language.

o It is used to perform read/write operations on the database table.

o It is a negative language. It can be adopted directly into ABAP but it is not recommended.

o SAP ABAP as introduced “OPEN SQL” instead of using negative SQL to make a computable with ABAP language.

STATEMENT 1 :- ( SELECT *)

SYNTAX: - SELECT * FROM <DBTABLE> INTO TABLE <ITAB>.

EX: - select * from Mara into table lt_mara. * represents all the fields of tables.

PROGRAM:-

Types : t_mara type mara.

Types : tt_mara type standard table of t_mara. Data : lw_mata type t_mara,

lt_mara type tt_mara. Select * from mara into table lt_mara. Loop at lt_mara into lw_mara.

Write : / lw_mara-matnr, lw_mara-mbrsh, lw_mara-mtart……lw_mara-fashgrd. Endloop.

(2)

STATEMENT 2:- (SELECT FILDS)

SYNTAX: - SELECT FLD1 FLD2 FLD3 FROM <DATABASE> INTO TABLE <ITAB>.

EX: - select matnr mbrsh mtart from mara into table lt_mara. PROGRAM:-

Types : t_mara type mara.

Types : tt_mara type standard table of t_mara. Data : lw_mata type t_mara,

lt_mara type tt_mara.

Select matnr mbrsh mtart from mara into table lt_mara. Loop at lt_mara into lw_mara.

Write : / lw_mara-matnr, lw_mara-mbrsh, Lw_mara-mtart.

Clear lw_mara. Endloop.

(3)

STATEMENT 3:- (WHERE CLASS).

SYNTAX: - SELECT FLD1 FLD2 FLD3 FROM <DBTABLE> INTO TABE <ITAB> WHERE <FLD NAME>=?.

EX: - Select matnr mbrsh mtart from mara into table lt_mara Where matnr = ‘123’. PROGRAM:-

Types : begin of t_mara, Matnr type matnr,

Mbrsh type mbrsh, mtart type mtart, End of t_mara.

Types : tt_mara type standard table of t_mara. Data : lw_mata type t_mara,

t_mara type tt_mara. Parameter : p_matnr type mara-matnr.

Select matnr mbrsh mtart from mara into table lt_mara Where matnr = p_matnr. Loop at lt_mara into lw_mara.

Write : / lw_mara-matnr, lw_mara-mbrsh, Lw_mara-mtart.

Clear lw_mara. Endloop.

(4)

SELECT SINGLE:

SYNTAX:SELECT SINGLE FLD1 FROM <DBTABLE> INTO <WA> WHERE FLD1 = ?.

EX: - Select single lifnr name1 land1 from lfa1 into lw_lfa1 Where lifnr = ?.

PROGRAM:-

Types: begin of t_marc, Matnr type matnr, Werks type werks_d, Pstat type pstat_d, End of t_marc.

Data : lw_marc type t_marc.

parameters : p_matnr type matnr obligatory. Select single matnr werks pstat from marc Into lw_marc

Where matnr = p_matnr. Write : / lw_marc-matnr, lw_marc-werks,

Lw_marc-pstat.

(OR)

data : V_matnr type matnr, V_werks type werks_d, V_pstat type pstat_d.

Parameters : p_matnr type matnr obligatory. Select single matnr werks pstat from marc

Into (v_matnr, v_werks, v_pstat) Where matnr = p_matnr.

(5)

SELECT UP TO <N> ROWS: -

SYNTAX: -SELECT FLD1 FLD2 FLD3 FROM <DBTABLE> INTO TABLE <ITAB> UP TO <N> ROWS.

EX: - select fld1 fld2 from <dbtable> into table <itab> Up to <n> rows.

PROGRAM:-

Types : begin of t_vbak, Vbeln type vbeln_va, Vkorg type vkorg, Vtweg type vtweg, Spart type spart, End of t_vbak.

Types : tt_vbak type standard table of t_vbak. Data : lw_vbak type t_vbak,

lt_vbak type tt_vbak.

Parameters : p_count type i obligatory. Select vblen vkorg vtweg spart from vbak

Into table lt_vbak Up to p_count rows. Loop at lt_vbak into lw_vbak.

Write : / lw_vbak-vblen, w_vbak-vkorg, Lw_vbak-vtweg, lw_vbak-spart. Clear lw_vbak.

(6)

SELECT…..INTO CORRESPONDING FIELDS OF TABLE:-

SYNTAX:- SELECT FLD3 FLD1 FLD2 FROM <DBTABLE>

INTO CORRESPONDING FILDS OF TABLE <ITAB> WHERE FLD1 = ?.

EX: - Select mtart matnr mbrsh from mara Into corresponding fields of table lt_mara Where matnr = ?.

PROGRAM:-

Types : begin of t_mara, Matnr type matnr,

Mbrsh type mbrsh, Mtart type mtart, End of t_mara.

Types : tt_mara type standard table of t_mara. Data : lw_mata type t_mara,

t_mara type tt_mara. Parameter : p_matnr type mara-matnr.

Select mbrsh mtart matnr from mara into table lt_mara Into corresponding fields of table lt_mara Where matnr = p_matnr.

Loop at lt_mara into lw_mara.

Write : / lw_mara-matnr, lw_mara-mbrsh, Lw_mara-mtart.

Clear lw_mara. Endloop.

(7)

SELECT……ENDSELECT: -

SYNTAX: - SELECT FLD1 FLD2 FROM <DBTABLE> INTO TABLE <WA> WHERE FLD1 = ?.

ENDSELECT PROGRAM: -

Types : begin of t_likp,

Vbeln type vbeln_vl Lfdat type lfdat_v, Vstel type vstel, End of likp.

Types : tt_likp type standard table of t_likp. Data : lw_likp type t_likp,

lt_likp type tt_likp.

Parameters : p_vbeln type vbeln obligatory. Select vbeln lfdat vstel from likp

into lw_likp up to 3 rows. endselect.

(8)

SELECT-OPTIONS: -

These are used for complex selections on a selection screen and it has been built by using “SELOPT STRUTCURE”. The fields are

• SING • OPTION • LOW • HIGH

SYNTAX: - SELECT-OPTIONS : <S_NAME>FOR <DBTABLE_FLD>.

• A run time selection option is treated as an internal table have four fields in it having SING

OPTION LOW HIGH

NOTE: - Select option need to be passed to the where clause using “IN” parameter.

Q HOW TO MAKE SELECT-OPTION AS A PARAMETER? ANS: - Declare a select option with “NO INTERVALS NO-EXTENSION”

v If u does not pass any values to the select options it will get the whole data of the table. PROGRAM: -

TYPES : begin of t_knal, Kunnr type kunnr, Name1 type name1,

Ort01 type ort01_gp,

Land1 type land1_gp End of t_kna1.

Types : tt_kna1 type standard type of t_kna1. Data : lw_knal type t_kna1,

T_kna1 type tt_kna1.

Seect-options : s_kunnr for kna1-kunnr. Select kunnr name1 ort01 land1 from kna1

Into table lt_kna1

Where kunnr in s_kunnr. Loop at lt_kna1 into lw_kna1.

Write : / lw_kna1-kunnr, lw_kna1-name1, lw_kna1-ort01, lw_kna1-land1. Clear lw_kna1.

(9)

SY-SUBRC: - It is a system variable which keeps a return code of select statement. If it is

successful it will be “ZERO” if it is fail it will be “NOT EQUAL TO ZERO”.

SYNTAX: - SY-SUBRC = 0.

NOTE: - It is mandatory Patrice to check a sy-subrc after any select-option

PROGRAM: -

TYPES : begin of t_vbrk, Vbeln type vbeln, Fkdat type fkdat, Kunrg type kunrg, Netwr type netwr, End of t_vbrk.

Types : tt_vbrk type standard table of t_vbrk. Data : lw_vbrk type t_vbrk,

Lt_vbrk type tt_vbrk.

Parameters : p_vbeln type vbrk-vbeln. Select vbeln fkdat kunrg netwr from vbrk

Into table lt_vbrk Where vbeln = p_vbeln. If sy-subrc = 0.

Loop at lt_vbrk type lw_vbrk.

Write : / lw_vbrk-vbeln, lw_vbrk-fkdat, lw_vbrk-kunrg, lw_vbrk-netwr. Endloop.

Else.

Write : / ‘NO DATA FOUND’. Endif.

(10)

VARIENT CRECATION: - STEP1: - Run the ABAP program

Enter the values in the selection screen Click on save button

Enter the variant name and meaning Click on save

Back.

STEP: - Whenever you want to use the same data

Run the ABAP program Click on get variant button And select the variant.

CREATING A TRANCATION CODE FOR THE REPORT: - STEP: - Go to SE93

Enter the T-code (EX: -ZBILL01)

Enter the transaction code which you want to create Click on enter

Write short text

Select program and selection screen (Report transaction) Press enter

Enter the program name for which you want create a T-code Enter program-program name

Check all the checks boxes Click on save.

(11)

JOINS

JOINS: - In order to extract the data from more than one table we need to make use of

Joins. They are two types of joins: - 1. Inner join

2. Outer join

We cannot join a cluster tables, only transparent tables can be join. JOINS: -

EXAMPLES OF INNER-JOIN: -

FIELD1 FIELD2 FIELD1 FIELD2

A T1

B T2

C T3

FEILD1 FEILD2 FEILD3 FEILD1 FEILD2 FEILD3

A T1 T4

B T2 T5

INNER-JOIN OUTER-JOIN SYNTAX: - SELECT TAB1~FLD1

TAB1~FLD2 TAB1~FLD3 TAB2~FLD1 TAB2~FLD2

INTO TABLE <ITAB>

FROM <TAB1> INNER JOIN <TAB2> ON TAB1~FLD1 = TAB2~FLD1 WHERE TAB1~FLD1 =? . A T1 B T2 C T3 A T1 T4 B T2 T5 C T3

(12)

STEP1: - Select fields from TAB1 and TAB2.

STEP2: - Put into internal table (ITAB). STEP3: - Write an inner join on two tables. STEP4: - Specify common Colum in two tables. STEP5: - Where condition.

PROGRAM: - Tables: Mara, marc. Types: begin of t_mat, matnr type matnr, mbrsh type mbrsh, mtart type mtart, werks type werks_d, pstat type pstat_d, end of t_mat.

Types: tt_mat type standard table of t_mat. Data: lw_mat type t_mat,

lt_mat type tt_mat.

Select-options: s_matnr for mara-matnr. *-- inner join on material info mara marc Select mara~matnr

mara~mbrsh mara~mtart marc~werks marc~pstat into table lt_mat

from mara inner join marc on mara~matnr = marc~matnr where mara~matnr in s_matnr. if sy-subrc eq 0.

loop at lt_mat into lw_mat.

write : / lw_mat-matnr , lw_mat-mbrsh, lw_mat-mtart, lw_mat-werks, lw_mat-pstat.

clear lw_mat. endloop. else.

write : / 'no data found'. endif.

(13)

FOR ALL ENTERIES IN: -

• It is used to retrieve the data based on an already populated ITAB. • It reduces the database access time.

• Before we use for all entries it is mandatory to check the header ITAB is filled or not. • We need to pass all keys in the where clause.

PROGRAM: - Tables : bkpf, bseg. Types : begin of t_bkpf, bukrs type bukrs, belnr type belnr_d, gjahr type gjahr, blart type blart, budat type budat, end of t_bkpf. Types : begin of t_bseg, bukrs type bukrs, belnr type belnr_d, gjahr type gjahr, buzei type buzei, wrbtr type wrbtr, end of t_bseg.

Types : tt_bkpf type standard table of t_bkpf, tt_bseg type standard table of t_bseg. Data : lw_bkpf type t_bkpf,

lw_bseg type t_bseg, lt_bseg type tt_bseg, lt_bkpf type tt_bkpf.

Select-options : s_bukrs for bkpf-bukrs. Select-options : s_belnr for bkpf-belnr. Select-options : s_gjahr for bkpf-gjahr. *-- fetch the header data bkpf

Select bukrs belnr gjahr blart budat from bkpf into table lt_bkpf

(14)

where bukrs in s_bukrs and belnr in s_belnr and gjahr in s_gjahr. if not lt_bkpf is initial. *--- select ietm data select bukrs belnr gjahr buzei wrbtr from bseg

into table lt_bseg for all entries in lt_bkpf where bukrs = lt_bkpf-bukrs and belnr = lt_bkpf-belnr and gjahr = lt_bkpf-gjahr. endif.

if not lt_bkpf is initial. format color 1.

loop at lt_bkpf into lw_bkpf.

write : / lw_bkpf-bukrs, lw_bkpf-blart. clear lw_bkpf.

endloop. endif.

if not lt_bseg is initial. format color 2.

loop at lt_bseg into lw_bseg.

write : / lw_bseg-bukrs, lw_bseg-buzei. clear lw_bseg.

endloop. endif.

(15)

REPORTS

REPORTS: -

• Reports are used for viewing the data in an appropriate format as per the client’s requirement.

• Reports basically consists of business information data

• The reports frequency will be daily, weekly, monthly, quarterly, half early, and annually. There are two types of reports.

1. Classical reports 2. Interactive reports

CLASSICAL REPORTS: - It has only one output list with appropriate events used. INTERACTIVE REPORTS: - It will have one basic list and 20 secondary lists. EVENTS IN CLASSICAL REPORTS: -

1. INTIALIZATION 2. AT SELECTION-SCREEN 3. START-OF-SELECTION 4. TOP-OF-PAGE 5. END-OF-SELECTION 6. END-OF-PAGE

INITIALIZATION: - This event will trigger at first and it is used for initialization screen field’s values.

CODE: - SELECT-OPTION : S_ebeln for ekko-ebeln EX: - INITIALIZATION.

S_EBELN-SING = ‘I’. S_EBELN-OPTION = ‘BT’.

S_BEBLN-LOW = ‘4500004824’. S_EBELN-HIGH = ‘4500004824’.

AT SELECTION-SCREEN: - This event is used to validate the user input if the user input is correct, allow HIM/HER for future processing if not raise an appropriate message.

MESSAGES: - (SE91)

They are 3 types of messages. I- Information – gray color W – Warning – yellow color E – Error – red color

SYNTAX: - MESSAGE <MSG TYPE> <MSG NUM> (MSG CLASS). EX: - Message E001 (ZVK).

(16)

MESSAGE CLASS: - STEP1: - Go to SE91

Enter the message class name (that name should be short name) Click on create

Give a short text (a program related message) Save.

STEP2: - Click on message tab, it has two sections MSG NUM & MSG TEXT EX: - MESSAGE MESSAGE SHORT TEXT

001 Please enter po number . 002 Input valid po number . Save

Back.

START-OF-SELECTION: -

These events are used to get data from database and man plicate the ITAB has per the requirement.

In technical standard point normally will write core logic or processing logic like select statements, and getting the data into ITAB’S and man placating the ITAB likes appending, modifying, and deleting the data.

It is a mandatory event for ABAP code. TOP-OF-PAGE: -

It is used to display list headings (or) reports headings with appropriate field’s description.

TOP-OF-PAGE is the first line which will trigger on the list. Provided you have a write statement in it.

END-OF-SELECTION: - This event is used to display the data on the list and normally it triggers after the start-of-selection

END-OF-PAGE: - This event is used to trigger footer for the given page technically reversing the lines for the footer

These can be achieved by an attribute “LINE-COUNT 65(5)” Where 65 – No. of lines in a page

(5) – reserved for footer.

CLEAR: - It clears the header contents or work area contents. REFERSH: - It removes the contents of a BODY/ITAB. FREE: - It will de-allocate the memory from the ITAB.

(17)

READ TABLE: - Read table will fetch you only record.

SYNTAX: - READ TABLE <ITAB> INTO <WA> WITH KEY <FLD1> = ? .

DESCRIBE TABLE: - Describe table is a key word which will let you know the No. of records available in an ITAB.

SYNTAX: - DESCRIBE TABLE <ITAB> LINES <VAR>. PROGRAMS FOR EVENTS IN CLASSICAL REPORTS: - PROGRAM1: -

tables: vbrk,vbrp.

Types: begin of t_billheader,

vbeln type vbeln_vf, " billing document number fkdat type fkdat, " billing date

kunrg type kunrg, " payer

vkorg type vkorg, " sales organization vtweg type vtweg, " distribution channel spart type spart, " division

fkart type fkart, " billing type end of t_billheader.

Types: begin of t_billitem,

vbeln type vbeln_vf, " billing document number posnr type posnr_vf, " billing item

matnr type matnr, " material number arktx type arktx, " description fkimg type fkimg, " quantity netwr type netwr_fp, " net value end of t_billitem.

Types: tt_billheader type standard table of t_billheader, tt_billitem type standard table of t_billitem.

Data: lw_billheader type t_billheader, lt_billheader type tt_billheader, lw_billitem type t_billitem, lt_billitem type tt_billitem.

selection-screen begin of block b with frame title text-001. select-options: s_vbeln for vbrk-vbeln.

selection-screen end of block b. data: v_subttl type p decimals 2,

(18)

v_gndttl type p decimals 2. *---* Initialization. *---* s_vbeln-sign = 'i'. s_vbeln-option = 'bt'. s_vbeln-low = 0090005385. s_vbeln-high = 0090005386. append s_vbeln. *---* At selection-screen. *---* select single * from vbrk into vbrk where vbeln in s_vbeln. if sy-subrc ne 0. message e001(zcd). endif. *---* Start-of-selection. *---* select vbeln fkdat kunrg vkorg vtweg spart fkart

from vbrk into table lt_billheader where vbeln in s_vbeln.

if not lt_billheader is initial.

loop at lt_billheader into lw_billheader. uline.

format color 1.

write:/ sy-vline,(16) 'billing number', sy-vline,(16) 'billing date', sy-vline,(16) 'payer', sy-vline,(16) 'sales org.', sy-vline,(16) 'dist. channel', sy-vline,(16) 'division', sy-vline,(16) 'billing type', sy-vline.

(19)

uline.

format color 2.

write:/ sy-vline,(16) lw_billheader-vbeln, sy-vline,(16) lw_billheader-fkdat, sy-vline,(16) lw_billheader-kunrg, sy-vline,(16) lw_billheader-vkorg, sy-vline,(16) lw_billheader-vtweg, sy-vline,(16) lw_billheader-spart,

sy-vline,(16) lw_billheader-fkart, sy-vline. clear lw_billitem.

refresh lt_billitem.

select vbeln posnr matnr arktx fkimg netwr from vbrp into table lt_billitem where vbeln = lw_billheader-vbeln. if not lt_billitem is initial.

uline.

format color 4.

write:/ sy-vline,(16) 'billing item', sy-vline,(16) 'material number', sy-vline,(16) 'description', sy-vline,(16) 'quantity.', sy-vline,(16) 'net value', sy-vline.

uline at 0(96).

loop at lt_billitem into lw_billitem. format color 2.

write:/ sy-vline,(16) lw_billitem-posnr, sy-vline,(16) lw_billitem-matnr, sy-vline,(16) lw_billitem-arktx, sy-vline,(16) lw_billitem-fkimg,

sy-vline,(16) lw_billitem-netwr, sy-vline. v_subttl = v_subttl + lw_billitem-netwr. endloop.

uline at 0(96).

write:/65 'sub total rs: ', v_subttl color 3. v_gndttl = v_gndttl + v_subttl.

v_subttl = 0. skip 1.

(20)

else. message: e000(zcd). endif. endloop. skip 2. uline.

write:/63 'grand total rs: ', v_gndttl color 3. else.

message: e000(zcd). endif.

PROGRAM2: -

report znsr_sales_report no standard page heading line-size 255

line-count 65(5). tables : vbak,vbap,mara.

types : begin of t_sales, vbeln type vbeln, vkorg type vkorg, vtweg type vtweg, spart type spart, kunnr type kunnr, posnr type posnr_va, matnr type matnr, arktx type arktx, kwmeng type kwmeng, mbrsh type mbrsh, mtart type mtart, end of t_sales.

types : tt_sales type standard table of t_sales. data : lw_sales type t_sales.

data : lt_sales type tt_sales. types : begin of t_mara, matnr type matnr, mbrsh type mbrsh, mtart type mtart, end of t_mara.

(21)

types : tt_mara type standard table of t_mara. data : lw_mara type t_mara,

lt_mara type tt_mara.

selection-screen begin of block b1 with frame title text-001. select-options : s_vbeln for vbak-vbeln.

selection-screen end of block b1 . start-of-selection.

clear lw_sales. refresh lt_sales.

*-- fetch sales order header and item select vbak~vbeln vbak~vkorg vbak~vtweg vbak~spart vbak~kunnr vbap~posnr vbap~matnr vbap~arktx vbap~kwmeng into table lt_sales

from vbak inner join vbap on vbak~vbeln = vbap~vbeln where vbak~vbeln in s_vbeln. if not lt_sales is initial.

clear lw_mara. refresh lt_mara.

*-- get material attributes

select matnr mbrsh mtart from mara into table lt_mara for all entries in lt_sales where matnr = lt_sales-matnr. endif.

*-- populating the data for mbrsh mtart loop at lt_sales into lw_sales.

read table lt_mara into lw_mara

(22)

if sy-subrc eq 0.

lw_sales-mbrsh = lw_mara-mbrsh. move lw_mara-mtart to lw_sales-mtart. modify lt_sales from lw_sales.

clear lw_sales. endif.

endloop.

"---displaying the final itab---- loop at lt_sales into lw_sales.

write: / lw_sales-vbeln,lw_sales-vkorg,lw_sales-vtweg,lw_sales-spart, lw_sales-kunnr,lw_sales-posnr,lw_sales-matnr,lw_sales-arktx, lw_sales-kwmeng,lw_sales-mbrsh,lw_sales-mtart. clear lw_sales. endloop. end-of-page.

write: 'thank you...visit again'.

EVENTS IN INTERACTIVE REPORTS: -

In interactive reports we can have one basic list and 20 secondary lists and list index will be captured by an index variable “SY-INDEX”.

1. AT LINE-SELECTION 2. AT USER-COMMAND

3. TOP-OF-PAGE DURING LINE-SELECTION.

AT LINE-SELECTION: - When the user double click on the basic list at line selection event will trigger.

AT USER-COMMAND: - These event will trigger when the user perform the action on the tool bar along with exit buttons. The button click value will be stored in a system variable know as “SY-UCOMM”. Technically it captures the functions code of a button.

TOP-OF-PAGE DURING LINE-SELECTION: -

This event is used to write the list headings on the secondary lists.

HIDE AREA: - If you define a field using hide statement that field value will be written into temporary memory area know as hide area.

(23)

EX: - hide : lw_ekko-ebeln.

WORKING WITH AT USER COMMAND: -

• SY-UCOMM will have a function code for each button in the tool bar. • A tool bar can be created using PF-STATUS.

SYNTAX: - SET PF-STATUS <STATUS NAME>. EX: - SET PF-STATUS ‘ZSALES’.

It is also known as GUI STATUS. STEP1: - Go to start-of-selection

Set PF-STATUS ‘ZDEL’. Double click on ZDEL Create object

Click on yes

Enter the short text (ex: -DELIVERY STATUS) Press enter.

STEP2: - Click on application tool bar Click on pulse button to expand Place the cursor on the first box Write display their

Double click on display Press enter

Enter function text (ex: - DISPLAY) Icon name (ex: - ICON-DISPLAY) Enter info text (ex: - DISPLAY) Press enter

Press enter

Select shortcut key for button (ex: - SHIFT+F7) Enter icon text (ex: - DISPLAY)

Enter info text (ex: - DISPLAY) Press enter

Save and activate Back.

STEP3: - Function keys

Expand the function keys

Put BACK, EXIT, CANCLE….. Save and activate

Back. GET CURSOR: -

SYNTAX: - CURSOR FIELD <WA-FLD> VALUE <VARIABLE>. EX: - cursor field lw_likp-vbeln value v_vbeln.

(24)

PROGRAM FOR AT SELECTION AND TOP-OF-PAGE DURING LINE-SELECTION: -

Tables : ekko,ekpo. Types : begin of t_ekko,

ebeln type ebeln, "purchasing document number ekorg type ekorg, "purchasing organization ekgrp type bkgrp, "purchasing group lifnr type elifn, "vendor number end of t_ekko.

Types : begin of t_ekpo,

ebeln type ebeln, "purchasing document number ebelp type ebelp, "item number

matnr type matnr, "material number menge type bstmg, "quantity

netpr type bprei, "netprice end of t_ekpo.

************ declare table

Types : tt_ekko type standard table of t_ekko, tt_ekpo type standard table of t_ekpo. Data : lw_ekko type t_ekko,

lw_ekpo type t_ekpo, lt_ekko type tt_ekko, lt_ekpo type tt_ekpo.

Select-options : s_ebeln for ekko-ebeln. Start-of-selection.

*-- po header data

Select ebeln ekorg ekgrp lifnr from ekko into table lt_ekko

where ebeln in s_ebeln. if not lt_ekko is initial.

loop at lt_ekko into lw_ekko. write : / lw_ekko-ebeln hotspot,

lw_ekko-ekorg , lw_ekko-ekgrp , lw_ekko-lifnr. hide : lw_ekko-ebeln. endloop. endif. At line-selection. clear lw_ekpo.

(25)

refresh lt_ekpo.

Select ebeln ebelp matnr menge netpr from ekpo into table lt_ekpo

where ebeln = lw_ekko-ebeln. if not lt_ekpo is initial.

loop at lt_ekpo into lw_ekpo.

write : /2 lw_ekpo-ebeln , 10 lw_ekpo-ebelp , 17 lw_ekpo-matnr ,

40 lw_ekpo-menge , 62 lw_ekpo-netpr. clear lw_ekpo.

endloop. endif.

top-of-page during line-selection.

write : /2'po num' , 10 'item no', 17 'material', 40 'quantity' , 62 'netval'.

PROGRAM FOR AT USER-COMMAND: - Tables : likp, lips.

Types : begin of t_likp,

vbeln type vbeln_vl, " delivery number vstel type vstel, " shipping point lfdat type lfdat_v, " delivery date kunnr type kunwe,

end of t_likp.

Types : begin of t_lips,

vbeln type vbeln_vl, " delivery number posnr type posnr_vl, " item number erdat type erdat, " date created matnr type matnr, " material number, lfimg type lfimg, " quantity

end of t_lips.

**-- declaring table types

Types : tt_likp type standard table of t_likp, tt_lips type standard table of t_lips. **-- declaring wa and itab

Data : lw_likp type t_likp, lw_lips type t_lips, lt_likp type tt_likp,

(26)

lt_lips type tt_lips. Data : v_vbeln type vbeln_vl. **-- declaring select-option

selection-screen begin of block a1 with frame title text-001. select-options : s_vbeln for likp-vbeln .

selection-screen end of block a1. start-of-selection.

*-- gui status set pf-status 'zdel'. clear lw_likp. refresh lt_likp.

**-- populate the header data

select vbeln vstel lfdat kunnr from likp into table lt_likp

where vbeln in s_vbeln. if not lt_likp is initial.

format color 3.

loop at lt_likp into lw_likp.

write : / lw_likp-vbeln, lw_likp-vstel, lw_likp-lfdat, lw_likp-kunnr. endloop. endif. At user-command. case sy-ucomm. when 'display'.

if not lt_likp is initial. **-- populate the item data clear lw_lips.

refresh lt_lips.

get cursor field lw_likp-vbeln value v_vbeln. select vbeln posnr erdat matnr lfimg from lips into table lt_lips

where vbeln = v_vbeln. endif.

if not lt_lips is initial. format color 4.

(27)

write : / lw_lips-vbeln, lw_lips-posnr, lw_lips-erdat, lw_lips-matnr, lw_lips-lfimg. clear lw_lips. endloop. else.

write : / 'no data found'. endif.

when 'quit'. * leave.

leave to screen 0. * leave program.

when 'back' or 'cancel' or 'exit'. leave.

(28)

CONTROL BREAK STATEMENTS

CONTROL BREAK STATEMENTS: -

Control break statements (CBS) are used for complex calculations like substitutes & grand totals. 1. AT FIRST. --- --- ENDAT. 2. AT NEW. --- --- ENDAT. 3. AT LAST. --- --- ENDAT. 4. AT END OF. --- --- ENDAT.

AT FIRST: - The first line of an ITAB.

AT LAST: - It is a last line (Record) of an ITAB. AT NEW: - At new will fire beginning of group of lines. AT END OF: - This will fire at end of group of lines.

At end is technically used for sub totals & grand totals. The IPF (Inter pack float) fields can be totaled automatically using “SUM” key word.

PRE- REQUISITES FOR CONTROL BREAK STATEMENTS: - 1. Table need to be sorted.

SYNTAX: - SORT <ITAB> BY <FLD> <ASC/DESC>. EX: - Sort lt_ekpo by ebeln.

2. All the control break statements need to be used with in LOOP and ENDLOOP. NOTE: - In order to handle asterisks’ and zeros in the control break statements, we need to move the data another work area or variables and used it along with write statements.

PO NUM ITEM MATERAIL QUANTITY

101 10 PEN 2 101 20 PENCIL 4 102 10 M-01 2 102 20 M-02 3 102 30 M-03 1 104 10 PENCIL 2 105 10 M-01 2 105 20 M-02 4

(29)

PROGRAM1: - (WITH HEADER) tables : ekpo.

data : BEGIN OF lt_ekpo OCCURS 0, ebeln type ebeln,

ebelp type ebelp, matnr type matnr, menge type bstmg, END OF lt_ekpo.

select-options : s_ebeln for ekpo-ebeln. data : v_ebeln type ebeln,

v_ebelp type ebelp, v_matnr type matnr, v_menge type bstmg. START-OF-SELECTION.

SELECT ebeln ebelp matnr menge from ekpo into TABLE lt_ekpo

where ebeln in s_ebeln. if sy-subrc eq 0.

sort lt_ekpo by ebeln. loop at lt_ekpo. v_ebeln = lt_ekpo-ebeln. v_ebelp = lt_ekpo-ebelp. v_matnr = lt_ekpo-matnr. v_menge = lt_ekpo-menge. at FIRST . * WRITE : / LT_EKPO-EBELN,lt_ekpo-ebelp, * lt_ekpo-matnr,lt_ekpo-menge.

write : / v_ebeln , v_ebelp, v_matnr, v_menge.

endat.

************************************************* *at last.

* write : / v_ebeln , v_ebelp, v_matnr, * v_menge.

*endat.

********************************************** * at new ebeln .

* write : / lt_ekpo-ebeln , v_ebelp, v_matnr, * v_menge.

(30)

********************************************** *at end of ebeln.

* sum. * WRITE : / LT_EKPO-EBELN,v_ebelp, * v_matnr,lt_ekpo-menge. *endat. endloop. endif.

PROGRAM2: - (WITHOUT HEADER) TABLES : EKPO.

TYPES : BEGIN OF T_EKPO, ebeln type ebeln,

ebelp type ebelp, matnr type matnr, menge type bstmg, END OF T_ekpo.

TYPES : TT_EKPO TYPE STANDARD TABLE OF T_EKPO. DATA : LW_EKPO TYPE T_EKPO,

LT_EKPO TYPE TT_EKPO. data : v_ebeln type ebeln,

v_ebelp type ebelp, v_matnr type matnr, v_menge type bstmg.

SELECTION-SCREEN BEGIN OF BLOCK B WITH FRAME TITLE TEXT-001. SELECT-OPTIONS: S_EBELN FOR EKPO-EBELN.

SELECTION-SCREEN END OF BLOCK B.

*---* INITIALIZATION. *---* S_EBELN-SIGN = 'I'. S_EBELN-OPTION = 'BT'. S_EBELN-LOW ='4500004823'. S_EBELN-HIGH ='4500004826'. APPEND S_EBELN. *---* AT SELECTION-SCREEN. *---* SELECT SINGLE * FROM EKPO

(31)

WHERE EBELN IN S_EBELN. IF SY-SUBRC NE 0.

MESSAGE E002(ZBSR). ENDIF.

START-OF-SELECTION.

SELECT ebeln ebelp matnr menge from ekpo into TABLE lt_ekpo

where ebeln in s_ebeln. if sy-subrc eq 0.

sort lt_ekpo by ebeln.

loop at lt_ekpo INTO LW_EKPO. v_ebeln = lW_ekpo-ebeln. v_ebelp = lW_ekpo-ebelp. v_matnr = lW_ekpo-matnr. v_menge = lW_ekpo-menge. * at FIRST . * WRITE : / LW_EKPO-EBELN,lW_ekpo-ebelp, * lW_ekpo-matnr,lW_ekpo-menge.

* write : / v_ebeln , v_ebelp, v_matnr, * v_menge.

* endat.

************************************************* at last.

write : / v_ebeln , v_ebelp, v_matnr, v_menge.

endat.

********************************************** * at new ebeln .

* write : / lW_ekpo-ebeln , v_ebelp, v_matnr, * v_menge.

* endat.

********************************************** *at end of ebeln.

* sum. * WRITE : / LW_EKPO-EBELN, * V_EBELP,V_MATNR,lW_ekpo-menge. *endat. endloop. endif.

(32)

MODULARIZATION TECHNIQUES

MODULARIZATION TECHNIQUES: -

These will improve the performance of a program or report it is recommended to implement modularization techniques.

They are 3 types of modularization techniques 1. Function modules

2. Subroutines 3. Includes

WORKING WITH FUNCTION MODULES (FM) : - (TCODE-SE37)

• FM are predefined and complied in status. Every FM is associated with a function group as a parent object and we can keep ‘N’ No. of function modules inside a group.

• They are predefined SAP function modules as well as we can create custom function modules.

• Function modules are stored in a table called as “TFDIR”. They are 3 types of function modules in SAP.

1. Normal function modules 2. Remote-enable function module 3. Update function module

PREDEFINED SAP FUNCTION MODULES: - v SD_DATETIME_DIFFERENCE v RP_LAST_DAY_OF_MONTHS v SPELL_AMOUNT v FIMA_DAYS_AND_MONTHS_AND_YEARS v FIMA_DAYS_BETWEEN_TWO_DATS v CONVERSION_EXIT_ALPHA_INPUT v CONVERSION_EXIT_ALPHA_OUTPUT TESTING FM: - STEP1: - Go to SE37

Enter the function module name (ex: - ISH_GET_WEEKDAY_NAME) Press F8

Enter the import parameters values Date

Language Press F8

(33)

CALLING FUNCTION MODULES: -

SYNTAX: - CALL FUNCTION <FUN NAME>.

ATTRIBUTES: - It describes about function group processing type of an FM and person created etc.

IMPORT: - By using import option we can declare importing variable, structure, ITAB function module is importing and ABAP program is exporting the values.

EXPORT: - By using export option we can export a variable, structure, ITAB and ABAP program is importing those values.

CHANGING: - By using changing option, we can declare variable, structure, ITAB and we can rewrite the existing values of a variable, structure & ITAB.

TABLES: - It is an obsolete option, it is not recommended to user from ECC 5.0 version onwards. The reason is ITAB declared in this become with header line.

EXCEPTIONS: - It is need to be raised to handle invalid inputs and bad data. CREATING CUSTOM FUNCTION: -

STEP1: - Create a function group in SE80 Go to SE80 (object navigator)

Select function group from the drop down Enter the function group name (ex: - ZNSR_FG) Press enter

Click on yes

Enter the short text (ex: - customer fun group) Press enter

Press F7 (local object)

SPET2: - Select the function group root folder Mouse right button

Activate

STEP3: - Go to function builder SE37

Enter the function module (ex: - Z_READ_CUSTOMER_DETAILS) Click on create

Enter function group (ex: - ZVK_FG)

Enter Short text (ex: - CUSTOMER DETAILS)

STEP4: - Go to import tab (ex: - IM_KUNNR TYPE KUNNER)

STEP5: - Go to export tab declare a structure (ex: - KNA1 TYPE KNA1)

(34)

STEP7: - Click on source code tab.

Write the ABAP code using import & export parameters. Save and activate.

STEP8: - Test the function module Run the FM (F8)

Enter the customer No. (IM_KUNNR 1390) Press F8.

STEP9: - Develop a calling program.

Ø Build an ITAB with duplicated data manually.

Ø Delete adjacent duplicates from LT_MARA comparing MATNR. CREATING A TABLE TYPE: -

STEP1: - Create a structure Go to SE11

Select radio button data type (ex: - ZVKS_EKPO) Click on create

Select structure Press enter

Enter short description (ex: - T_EKPO) In component tab

Enter EBELN EBELN POSNR POSNR MATNR MATNR MENGE BSTMG Select the menge field

Click on currency/quantity fields

REFERNCE TABLE REG FIELDS

EKPO MEINS

Save and activate. STEP2: - Creating a table type

Go to SE11

Radio button data type (ex: - ZTT_EKPO) In the line type tab enter the structure Enter line type (ex: - ZVKS_EKPO) Save and activate.

(35)

CREATING A FUNCTION MODULE TO BRING BACK ITAB DATA: - OBJECTIVE: - Find out the purchase order details for a given PO number. STEP1: - Go to SE37

Enter the function name (ex: - Z_READ_PO_DETAILS) Enter Function group (ex: - ZVK_FG)

Enter Short text (ex: - PO DETAILS) Press enter.

STEP2: - In Import tab enter (ex: - IM_EBELN TYPE ZTT_EKPO) STEP3: - In export tab enter (ex: - ET_EKPO TYPE ZTT_EKPO)

Save and activate

STEP4: - In exceptions tab enter (ex: - NO_DATA_FOUND NO DATA FOUND) STEP5: - click on Source code

IF NOT IM_EBELN IS INITIAL.

SELECT EBELN EBELP MATNR MENGE FROM EKPO INTO TABLE ET_EKPO

WHERE EBELN = IM_EBELN IF SY_SUBRC = 0.

RAISE NO_DATA_FOUND. ENDIF.

ENDIF.

Save and activate. Test the FM (F8).

STEP6: - Create a calling program.

Q. How do we pass select-options to the function modules? (OR)

How do we pass range values to the function modules? Ans: - Using select-options with SELOPT structure.

WORKING WITH SUB-ROUTINES: -

Sub-routines are used for Re-usability and improve the performance of the report. They are 3 types of Sub-Routines.

1. PERFORM <PERFORM NAME>

2. PERFORM <PERFORM NAME> USING <VAR/WA/ITAB> 3. PERFORM <PERFORM NAME> TABLES <ITAB>

Ø The parameters associated with PERFORM are known as actual parameters.

Ø The parameters associated with the FORM…………ENDFORM are known as formal parameters.

STEP1: - Go to the start-of-selection Write perform <perform name> And double click on the perform name

(36)

Click on yes

Select the main program

You will be awarded with FORM and ENDFORM And write the ABAP logic on between them.

NOTE: - It is recommended that every PERFORM should have inline comment on top of it. PROGRAM1: -

REPORT ZNSR_SUBROUTINES. data : v_a type i,

v_b TYPE i, v_c TYPE i.

START-OF-SELECTION. PERFORM default_values.

PERFORM get_total USING v_a v_b CHANGING v_c.

BREAK user4.

*&---* *& Form get_total

*&---* * text *---* * -->P_V_A text * -->P_V_B text * <--P_V_C text *---* FORM get_total USING P_V_A

P_V_B CHANGING P_V_C. p_v_c = p_v_a + p_v_b. WRITE : / p_v_c. ENDFORM. " get_total *&---* *& Form default_values

*&---* * text *---* * --> p1 text * <-- p2 text *---*

(37)

FORM default_values . v_a = 20. v_b = 30. ENDFORM. " default_values PROGRAM2: - REPORT ZNSR_SUBROUTINES2. TABLES : LIKP.

TYPES : BEGIN OF T_LIKP,

VBELN TYPE VBELN_VL, " Delivery Number VSTEL TYPE VSTEL, " Shipping Point LFDAT TYPE LFDAT_V, " Delivery Date KUNNR TYPE KUNWE,

END OF T_LIKP.

**-- Declaring Table Types

TYPES : TT_LIKP TYPE STANDARD TABLE OF T_LIKP. DATA : LW_LIKP TYPE T_LIKP,

LT_LIKP TYPE TT_LIKP.

SELECTION-SCREEN BEGIN OF BLOCK A1 WITH FRAME TITLE TEXT-001. SELECT-OPTIONS : S_VBELN FOR LIKP-VBELN .

SELECTION-SCREEN END OF BLOCK A1. START-OF-SELECTION.

PERFORM GET_DATA TABLES LT_LIKP. PERFORM display_data.

*&---* *& Form GET_DATA

*&---* * text

*---* * -->P_LT_LIKP text

*---*

FORM GET_DATA TABLES PT_LIKP STRUCTURE lW_LIKP. SELECT VBELN VSTEL LFDAT KUNNR FROM LIKP

(38)

WHERE VBELN IN S_VBELN. ENDFORM. " GET_DATA

*&---* *& Form display_data

*&---* * text *---* * --> p1 text * <-- p2 text *---* FORM display_data .

loop at lt_likp INTO lw_likp.

WRITE : / lw_likp-vbeln , lw_likp-vstel. clear lw_likp. ENDLOOP. ENDFORM. " PROGRAM3: - REPORT ZVK_SUBROUTINES1. TABLES : EKPO.

TYPES : BEGIN OF T_EKPO, EBELN TYPE EKPO-EBELN, EBELP TYPE EKPO-EBELP, MATNR TYPE EKPO-MATNR, MENGE TYPE EKPO-MENGE, END OF T_EKPO.

TYPES: TT_EKPO TYPE STANDARD TABLE OF T_EKPO. DATA : LW_EKPO TYPE T_EKPO,

LT_EKPO TYPE TT_EKPO.

SELECT-OPTIONS : S_EBELN FOR EKPO-EBELN. START-OF-SELECTION.

PERFORM GET_DATA.

PERFORM display_data using lt_ekpo.

*&---* *& Form get_Data

*&---* * text

*---* * --> p1 text

(39)

* <-- p2 text *---* FORM GET_DATA . SELECT EBELN EBELP MATNR

MENGE FROM EKPO

INTO TABLE LT_EKPO WHERE EBELN IN S_EBELN. *

SORT LT_EKPO BY EBELN. ENDFORM. " get_Data

*&---* *& Form display_data

*&---* * text

*---* * -->P_LT_EKPO text

*---* FORM display_data USING PT_EKPO TYPE TT_EKPO. DATA : PW_EKPO TYPE T_EKPO.

LOOP AT PT_EKPO INTO PW_EKPO.

WRITE : / PW_EKPO-EBELN , PW_EKPO-EBELP, PW_EKPO-MATNR , PW_EKPO-MENGE. ENDLOOP.

ENDFORM. " display_data DEBUGGING TIPS: -

F5 – Line by line execution

F6 – Execute (It goes to available perform or next available statement)

F7 – Return (You have been inside FROM and ENDFORM and where ever you want get out from FORM and ENDFORM press F7)

F8 – Run.

NOTE: - If subroutine is declared with using or changing options the formal parameters need to be declared same as actual parameters.

(40)

ALV REPORTS

ALV REPORTS: - (ABAP LIST VIEWER)

ALV reports are used for complex reporting with the following futures. 1. Sort ascending / Descending

2. ∑ (Sum) 3. Select / Deselect 4. Filter 5. Local file 6. Send email 7. Change layout

ALV reports are user friendly in nature it enable the end user to design the layout as per His/her choice.

They are 2 types of reports in ALV 1. ALV GRID DISPLAY 2. ALV LIST DISPLAY

They are 2 function modules associated with it. 1. RESUSE_ALV_GRID_DISPLAY 2. RESUSE_ALV_LIST_DIAPLAY

To search ALV related function modules enter like this (ex: - RESUSE*ALV*) IN SLIS ROW NO: 73

TO GROUP (SE11)

WE HAVE FIELDCAT AT 73 ROW

IN THAT THERE IS A STRUCTURE (SLIS_FIELDCAT_MAIN0) • COL_POS

• FEILDNAME • TABNAME • SELTEXT_M IN 144 LINE (SLIS_FIELDCAT_ALV)

IMPORTANT PARAMETERS OF RESUSE_ALV_GRID_DISPLAY: - I_CALLBACK_PROGRAM = ‘ABAP program name’

I_GRID_TITLE = ‘Report name’

IT_FIELDCAT = FIELDCAT INTERNAL TABLE

T_OUTTAB = DATA INTERNAL TABLE

(41)

NOTE: - In order to build the field catalog automatically “RESUSE_ALV_FIELD CATALOG_MERGE” INTERACTIVE ALV: -

Interactive ALV can be generated using a function module “RESUSE_ALV_POPUP_TO_SELECT”.

PARAMETERS TO BE PASS: - I_TABNAME

IT_FIELDCAT TABLES

T_OUTTAB = DATA INTERNAL TABLE Ø To capture information of cursor poison in ALV

Ø SLIS_SELFIELD structure is used VALUE field will have run time value of ALV grid selfield value.

3 STEPS: -

1. Build catalog for items 2. Get the item data

3. Call the popup to select FM

TOP-OF-PAGE: - In order to trigger top-of-page for ALV, SLIS_LISTHEADER structure is used. It has two attributes.

a. Typ b. Info

Table type name: - SLIS_T_LISTHEADER

Ø In order to trigger a top-of-page RESUSE_ALV_COMMENTARY_WRITE is used for this FM pass the list header ITAB.

(42)

PRIGRAM: - REPORT ZVK_ALV_REPORTS. INCLUDE ZVK_ALV. START-OF-SELECTION. PERFORM BUILD_CATALOG. TYPE-POOLS SLIS . TABLES : EKKO,EKPO. -

TYPES : BEGIN OF T_EKKO, EBELN TYPE EBELN, EKORG TYPE EKORG, EKGRP TYPE BKGRP, LIFNR TYPE ELIFN, END OF T_EKKO.

TYPES : TT_EKKO TYPE STANDARD TABLE OF T_EKKO. DATA : LW_EKKO TYPE T_EKKO,

LT_EKKO TYPE TT_EKKO. TYPES : BEGIN OF T_EKPO, EBELN TYPE EBELN, EBELP TYPE EBELP, MATNR TYPE MATNR, MENGE TYPE BSTMG, END OF T_EKPO.

TYPES : TT_EKPO TYPE STANDARD TABLE OF T_EKPO. DATA : LW_EKPO TYPE T_EKPO,

LT_EKPO TYPE TT_EKPO. *--ALV DECLERATION

*-- FIELD CATALOG FOR HEADER "MARA DATA : LW_FCAT TYPE SLIS_FIELDCAT_ALV, LT_FCAT TYPE SLIS_T_FIELDCAT_ALV. *-- FIELD CATALOG FOR ITEM "MARC

DATA : LW_ICAT TYPE SLIS_FIELDCAT_ALV, LT_ICAT TYPE SLIS_T_FIELDCAT_ALV. *-- TOP OF PAGE

DATA : LW_HEADER TYPE SLIS_LISTHEADER, LT_HEADER TYPE SLIS_T_LISTHEADER. SELECT-OPTIONS : S_EBELN FOR EKKO-EBELN.

(43)

PERFORM BUILD_TOP_PAGE. PERFORM TOP. PERFORM GET_DATA. PERFORM GRID_DISPLAY. PERFORM list_display. *&---* *& Form build_catalog

*&---* * text *---* * --> p1 text * <-- p2 text *---* FORM BUILD_CATALOG . LW_FCAT-COL_POS = 1. LW_FCAT-FIELDNAME = 'EBELN'. LW_FCAT-TABNAME = 'LT_EKKO'. LW_FCAT-SELTEXT_M = 'PO NUM'. LW_FCAT-REF_FIELDNAME = 'EBELN'. LW_FCAT-REF_TABNAME = 'EKKO'. APPEND LW_FCAT TO LT_FCAT. CLEAR LW_FCAT.

LW_FCAT-COL_POS = 2.

LW_FCAT-FIELDNAME = 'EKORG'. LW_FCAT-TABNAME = 'LT_EKKO'. LW_FCAT-SELTEXT_M = 'PUR ORG'. LW_FCAT-REF_FIELDNAME = 'EKORG'. LW_FCAT-REF_TABNAME = 'EKKO'. APPEND LW_FCAT TO LT_FCAT. CLEAR LW_FCAT.

LW_FCAT-COL_POS = 3.

LW_FCAT-FIELDNAME = 'EKGRP'. LW_FCAT-TABNAME = 'LT_EKKO'. LW_FCAT-SELTEXT_M = 'PO GROUP'. LW_FCAT-REF_FIELDNAME = 'EKGRP'. LW_FCAT-REF_TABNAME = 'EKKO'. APPEND LW_FCAT TO LT_FCAT.

(44)

CLEAR LW_FCAT. LW_FCAT-COL_POS = 4. LW_FCAT-FIELDNAME = 'LIFNR'. LW_FCAT-TABNAME = 'LT_EKKO'. LW_FCAT-SELTEXT_M = 'VENDOR'. LW_FCAT-REF_FIELDNAME = 'LIFNR'. LW_FCAT-REF_TABNAME = 'EKKO'. APPEND LW_FCAT TO LT_FCAT. CLEAR LW_FCAT.

*-- Build catalog for Item EKPO LW_ICAT-COL_POS = 1.

LW_ICAT-FIELDNAME = 'EBELP'. LW_ICAT-TABNAME = 'LT_EKPO'. LW_ICAT-SELTEXT_M = 'ITEM NUM'. LW_ICAT-REF_FIELDNAME = 'EBELP'. LW_ICAT-REF_TABNAME = 'EKPO'. APPEND LW_ICAT TO LT_ICAT. CLEAR LW_ICAT. LW_ICAT-COL_POS = 2. LW_ICAT-FIELDNAME = 'MATNR'. LW_ICAT-TABNAME = 'LT_EKPO'. LW_ICAT-SELTEXT_M = 'MATERIAL'. LW_ICAT-REF_FIELDNAME = 'MATNR'. LW_ICAT-REF_TABNAME = 'EKPO'. APPEND LW_ICAT TO LT_ICAT. CLEAR LW_ICAT. LW_ICAT-COL_POS = 3. LW_ICAT-FIELDNAME = 'MENGE'. LW_ICAT-TABNAME = 'LT_EKPO'. LW_ICAT-SELTEXT_M = 'QUANTITY'. LW_ICAT-REF_FIELDNAME = 'MENGE'. LW_ICAT-REF_TABNAME = 'EKPO'. APPEND LW_ICAT TO LT_ICAT. CLEAR LW_ICAT.

ENDFORM. " build_catalog

*&---* *& Form get_data

(45)

*&---* * text *---* * --> p1 text * <-- p2 text *---* FORM GET_DATA .

SELECT EBELN EKORG EKGRP LIFNR FROM EKKO INTO TABLE LT_EKKO

WHERE EBELN IN S_EBELN. ENDFORM. " get_data

*&---* *& Form grid_display

*&---* * text *---* * --> p1 text * <-- p2 text *---* FORM GRID_DISPLAY .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING * I_INTERFACE_CHECK = ' ' * I_BYPASSING_BUFFER = ' ' * I_BUFFER_ACTIVE = ' ' I_CALLBACK_PROGRAM = SY-REPID * I_CALLBACK_PF_STATUS_SET = ' ' I_CALLBACK_USER_COMMAND = 'USER_COMMAND' I_CALLBACK_TOP_OF_PAGE = 'TOP' * I_CALLBACK_HTML_TOP_OF_PAGE = ' ' * I_CALLBACK_HTML_END_OF_LIST = ' ' * I_STRUCTURE_NAME = * I_BACKGROUND_ID = ' '

* I_GRID_TITLE = 'THOS IS GRID TITLE' * I_GRID_SETTINGS = * IS_LAYOUT = IT_FIELDCAT = LT_FCAT * IT_EXCLUDING = * IT_SPECIAL_GROUPS = * IT_SORT =

(46)

* 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 = LT_EKKO 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 list_display

*&---* * text

(47)

* --> p1 text * <-- p2 text

*---* FORM LIST_DISPLAY .

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY' EXPORTING * I_INTERFACE_CHECK = ' ' * I_BYPASSING_BUFFER = * I_BUFFER_ACTIVE = ' ' I_CALLBACK_PROGRAM = SY-REPID * I_CALLBACK_PF_STATUS_SET = ' ' * I_CALLBACK_USER_COMMAND = ' ' * I_STRUCTURE_NAME = * IS_LAYOUT = IT_FIELDCAT = LT_FCAT * 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 * IR_SALV_LIST_ADAPTER = * IT_EXCEPT_QINFO = * I_SUPPRESS_EMPTY_DATA = ABAP_FALSE * IMPORTING * E_EXIT_CAUSED_BY_CALLER = * ES_EXIT_CAUSED_BY_USER = TABLES T_OUTTAB = LT_EKKO EXCEPTIONS

(48)

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. " list_display

*&---* *& Form USER_COMMAND

*&---* * text

*---*

FORM USER_COMMAND USING V_UCOMM TYPE SY-UCOMM LW_SELFIELD TYPE SLIS_SELFIELD .

CASE V_UCOMM. WHEN '&IC1'.

SELECT EBELN EBELP MATNR MENGE FROM EKPO INTO TABLE LT_EKPO

WHERE EBELN = LW_SELFIELD-VALUE. CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT' EXPORTING * I_TITLE = * I_SELECTION = 'X' * I_ALLOW_NO_SELECTION = * I_ZEBRA = ' ' * I_SCREEN_START_COLUMN = 0 * I_SCREEN_START_LINE = 0 * I_SCREEN_END_COLUMN = 0 * I_SCREEN_END_LINE = 0 * I_CHECKBOX_FIELDNAME = * I_LINEMARK_FIELDNAME = * I_SCROLL_TO_SEL_LINE = 'X' I_TABNAME = 'LT_EKPO' * I_STRUCTURE_NAME = IT_FIELDCAT = LT_ICAT * IT_EXCLUDING = * I_CALLBACK_PROGRAM =

(49)

* I_CALLBACK_USER_COMMAND = * IS_PRIVATE = * IMPORTING * ES_SELFIELD = * E_EXIT = TABLES T_OUTTAB = LT_EKPO 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. ENDCASE.

ENDFORM. "USER_COMMAND

*&---* *& Form BUILD_TOP_PAGE

*&---* * text *---* * --> p1 text * <-- p2 text *---* FORM BUILD_TOP_PAGE .

DATA : V_STR TYPE STRING. LW_HEADER-TYP = 'H'.

LW_HEADER-INFO = TEXT-001.

APPEND LW_HEADER TO LT_HEADER. CLEAR LW_HEADER.

CONCATENATE 'FROM' S_EBELN-LOW ' TO ' S_EBELN-HIGH INTO V_STR SEPARATED BY SPACE.

LW_HEADER-TYP = 'S'. LW_HEADER-INFO = V_STR.

APPEND LW_HEADER TO LT_HEADER. CLEAR LW_HEADER.

(50)

*&---* *& Form TOP

*&---* * text

*---* FORM TOP.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE' EXPORTING IT_LIST_COMMENTARY = LT_HEADER I_LOGO = 'ENJOYSAP_LOGO' * I_END_OF_LIST_GRID = * I_ALV_FORM = . ENDFORM. "TOP

(51)

BDC

BDC (BATCH DATA COMMUNICATION): -

BDC methodology will be used to upload the data from LEGACY systems to SAP. BDC upload can be in 2 ways.

1. Conversion

2. Interfaces (NON-SAP)

WORKING WITH FILES: - Core team will supply files in .XLS format, .EXE format, .CVS format.

CONVERTING XLS SHEET TO TAB-DELMITED FILE: - STEP1: - Open excel sheet

Click on Conner

With mouse right click button Format cells

Select text option Press ok and save STEP2: - Save file as

File name : (ex: - mat.txt)

Save as type : text (tab delimited) Press save

Yes-ok

FILES CAN BE READ FROM 2 PLACES: - 1. PRESENTATION SERVER

2. APPLICATION SERVER FILE FORMAT (In excel sheet): -

MANTR(18) MTART(4) MBRSH(1) MEINS(3)

PEN ROH M EA

PENCIL FERT M PC

BB ROH M EA

STEP1: - Declare an ITAB which is similar to 5 fields sequence and data type should be ‘c’. In order to upload the data from file to ITAB we use “GUI_UPLOAD” function module.

LEGECY SYSTEM

SAP SYATEM

(52)

In order to upload the data from ITAB to file we use “GUI_DOWNLOAD” function module. WORKING WITH APPLICATION SERVER: - (TCODE – ALL1)

Application server is the secure location in SAP technically it will be UNIX server or LINUX server.

UNIX FILE PATH: - Go to AL11

Double click on DIR_HOME And place your file

/usr/sap/LID/DVEBMGSOO/work

In application server we can write a file or we can read a file from it. OPEN A FILE ON APPLICATION SERVER: -

By using open data set statement we can open a file on the application server. If file opens successfully the SY-SUBRC = 0 and if it fails to open the SY-SUBRC = 8.

SYNTAX: - OPEN DATASET <DSN>.

--- --- ---

CLOSE DATASET <DSN>. (Where DSN – file name) WRITE ACCESS: -

In order to write a file on application server, we have to “use output statement” along with open dataset.

SYNTAX: - OPEN DATASET <DSN> FOR OUTPUT. ---

--- ---

CLOSE DATASET <DSN>. READ ACCESS: -

In order to read a file from application server we have to “use input statement” along with open dataset.

SYNTAX: - OPEN DATASET <DSN> FOR INPUT. ---

--- ---

(53)

TEXT MODE: -

In order to open a file in text mode we have to “use in text mode” keyword. SYNTAX: - OPEN DATASET <DSN> FOR <OUTPUT/INPUT> IN TEXT

MODE ENCODING DEFAULT. ---

--- --- CLOSE DATASET <DSN>.

TRANSFER: - Transfer statement does move the ITAB data to file. SYNTAX: - TRANSFER <WA/ITAB> TO <DSN>.

READ DATASET: - Read dataset statement is used to move the data from file to ITAB. SYNTAX: - READ DATASET <DSN> INTO <WA/ITAB>.

1. Read/write the file in application server. 2. Read/write the file in presentation server.

PROGRAM1: - (READ FILE FROM APPL SERVER) REPORT ZVK_READ_FILE_APPL_SVR.

TYPES : BEGIN OF T_MAT, MATNR(18) TYPE C, MTART(4) TYPE C, MBRSH(1) TYPE C, MEINS(3) TYPE C, END OF T_MAT.

TYPES : TT_MAT TYPE STANDARD TABLE OF T_MAT. DATA : LW_MAT TYPE T_MAT,

LT_MAT TYPE TT_MAT. DATA : V_DSN(100) TYPE C. START-OF-SELECTION. *-- read file form Appl server

PERFORM READ_FILE_FRM_APPL_SVR. PERFORM DISPLAY_DATA.

*&---* *& Form read_file_frm_appl_svr

*&---* * text

(54)

*---* * --> p1 text * <-- p2 text *---* FORM READ_FILE_FRM_APPL_SVR . V_DSN = '/usr/sap/LID/DVEBMGS00/work/material.txt'.

OPEN DATASET V_DSN FOR INPUT IN TEXT MODE ENCODING DEFAULT. IF SY-SUBRC EQ 0.

DO.

READ DATASET V_DSN INTO LW_MAT. IF SY-SUBRC EQ 0.

APPEND LW_MAT TO LT_MAT. ELSE.

EXIT. ENDIF. ENDDO. ELSE.

WRITE : / 'No data found'. ENDIF.

CLOSE DATASET V_DSN.

ENDFORM. " read_file_frm_appl_svr

*&---* *& Form display_data

*&---* * text *---* * --> p1 text * <-- p2 text *---* FORM DISPLAY_DATA .

LOOP AT LT_MAT INTO LW_MAT.

WRITE : / LW_MAT-MATNR, LW_MAT-MBRSH. ENDLOOP.

ENDFORM. " display_data

PROGRAM2: - (WRITE FILE TO APLL SERVER) REPORT ZVK_WRITE_FILE_APPL_SVR.

TYPES : BEGIN OF T_MAT, MATNR(18) TYPE C, MTART(4) TYPE C, MBRSH(1) TYPE C,

(55)

MEINS(3) TYPE C, END OF T_MAT.

TYPES : TT_MAT TYPE STANDARD TABLE OF T_MAT. DATA : LW_MAT TYPE T_MAT,

LT_MAT TYPE TT_MAT. DATA : V_DSN(100) TYPE C. START-OF-SELECTION. PERFORM GET_DATA.

PERFORM WRITE_FILE_ON_APPL_SVR.

*&---* *& Form get_data

*&---* * text *---* * --> p1 text * <-- p2 text *---* FORM GET_DATA .

SELECT MATNR MTART MBRSH MEINS FROM MARA INTO TABLE LT_MAT

UP TO 3 ROWS. ENDFORM. " get_data

*&---* *& Form write_file_on_appl_svr

*&---* * text *---* * --> p1 text * <-- p2 text *---* FORM WRITE_FILE_ON_APPL_SVR . V_DSN = '/usr/sap/LID/DVEBMGS00/work/material.txt'. OPEN DATASET V_DSN FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF SY-SUBRC EQ 0.

LOOP AT LT_MAT INTO LW_MAT. TRANSFER LW_MAT TO V_DSN. CLEAR LW_MAT.

(56)

WRITE : / 'File created ' , v_dsn. ELSE.

WRITE : / 'File could not open'. ENDIF.

CLOSE DATASET V_DSN.

ENDFORM. " write_file_on_appl_svr

PROGRAM3: - (READ FILE FROM PRESENTATION SERVER) REPORT ZVK_READ_FILE_PRESENT_SERVER.

TYPES : BEGIN OF T_MAT, MATNR(18) TYPE C, MTART(4) TYPE C, MBRSH(1) TYPE C, MEINS(3) TYPE C, END OF T_MAT.

TYPES : TT_MAT TYPE STANDARD TABLE OF T_MAT. DATA : LW_MAT TYPE T_MAT,

LT_MAT TYPE TT_MAT.

PARAMETERS : p_file type localfile OBLIGATORY.

AT SELECTION-SCREEN on VALUE-REQUEST FOR p_file. CALL FUNCTION 'F4_FILENAME'

EXPORTING PROGRAM_NAME = SYST-CPROG DYNPRO_NUMBER = SYST-DYNNR FIELD_NAME = ' ' IMPORTING FILE_NAME = p_file. START-OF-SELECTION. PERFORM read_file_data. PERFORM display_data. *&---* *& Form read_file_data

*&---* * text *---* * --> p1 text * <-- p2 text *---* FORM read_file_data .

data : l_fnm TYPE string. l_fnm = p_file.

(57)

CALL FUNCTION 'GUI_UPLOAD' EXPORTING FILENAME = l_fnm FILETYPE = 'ASC' HAS_FIELD_SEPARATOR = '#' * HEADER_LENGTH = 0 * READ_BY_LINE = 'X' * DAT_MODE = ' ' * CODEPAGE = ' ' * IGNORE_CERR = ABAP_TRUE * REPLACEMENT = '#' * CHECK_BOM = ' ' * VIRUS_SCAN_PROFILE = * NO_AUTH_CHECK = ' ' * IMPORTING * FILELENGTH = * HEADER = TABLES DATA_TAB = lt_mat * 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 <> 0.

(58)

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.

DELETE lt_mat where matnr eq space. ENDFORM. " read_file_data

*&---* *& Form display_data

*&---* * text *---* * --> p1 text * <-- p2 text *---* FORM display_data .

loop at lt_mat into lw_mat. WRITE : / lw_mat-matnr. clear lw_mat.

ENDLOOP.

ENDFORM. " display_data

CREATING MATERAIL MASTER (MM01): - 01 – CREATE

02 – CHANGE 03 – DISPLAY

STEP1: - Creating basic material Go to MM01

Enter material (ex: - MAT - 01)

Industry sector (ex: - M MECHINICAL ENGINEER) Material type (ex: - ROH RAW MATERAIL)

Click on select views button Select basic data1 & basic data2 Click on default values button Press enter.

STEP2: - Enter the material description (ex: - GLASS MATERAIL) Enter the base unit of measure (ex: - EA)

(59)

CREATING A MATERAIL WITH MULTIPLE VIEWS: - STEP1: - Go to MM01

Enter the 3 field’s material, industry sector, material type Click on select views.

Select BASIC1, BASIC2, PURCHASING, MRP, ACCOUNTING1 Click on default values button

Press enter. Plant (ex: - 1000)

Stor. Location (ex: - 0001) Click on default values Press enter

Enter the description (ex: - I DON’T KNOW) Basic unit measure (ex: - PS)

Material group (ex: - 0001) Click on purchasing tab

Purchasing group (ex: - 001) Click on MRP1 tab

MRP type (ex: - ND) Click on accounting1 tab

Standard price (ex: - 1234) Valuation class (ex: - 3000) Select MRP2 tab

Plant deliv. Time (ex: - 10) days. Click on save.

CREATING CUSTOMER: - (VD01) STEP1: - Go to VD01

Accounting group (ex: - 0001) Customer (ex: - 90600)

Sales organization (ex: - 1000) Distribution channel (ex: - 10) Division (ex; - 00)

Press enter

Title (ex; - COMPANY) Name (ex: - INFOSYS

TCS)

Search term ½ (ex: - KG) City (ex; - HYD)

Country (ex: - IN)

(60)

STEP2: - Click on sales area data button Click on shipping tab

Shipping conditions (ex: - 01) Click on billing documents tab Click on tax classification (ex: - 1) Click on save.

CREATING VENDOR: - (MK01) STEPS: - Go to MK01

Vendor (ex: - 89346)

Purchasing organization (ex: - 0001) Accounting group (ex: - 0001) Press enter

Title (ex: - company) Name (ex: - j & j) Search term ½ (ex: - J) Country (ex: - IN) City (ex: - HYD)

Click on F8 (or) next screen arrow button Click on next screen

Order currency (ex: - INR) Terms of payment (ex: - 002) Click on save.

CREATING PURCHAGE ORDER: - (ME21N) STEP1: - Go to ME21N

Vendor (ex: - 1000) Select org data tab Purch. Org (ex: - 1000) Purch. Group (ex: - 001) Company code (ex: - 1000)

MATERAIL PQ QUANTITY PLANT

100-100 1 1000

Click on save.

CREATING SALES ORDER: - (VA01) STEP1: - Go to VA01

Order type (ex: - OR) Sales. Org (ex: - 1000)

Distribution channel (ex: - 10) Division (ex: - 00)

(61)

Press enter

Sold to party (ex: - 1000) Ship to party (ex: - 1000)

MATERIAL QUANTITY 100-100 1 Press enter & save.

NOTE: - Data will be stored in VBRK, VBAP. RECORDING AT TRANSACTION: - (SHDB)

NOTE: - While recording the transaction sees to those errors are not raised. STEPS: - Go to SHDB

Click on new recoding

Enter the recording name (ex: - ZNSR_MM01_DEMO) Enter the transaction code (ex: - MM01)

Press enter

Carefully enter the data for relative data and save it. Save the recording as well

Change the material No. (ex: - RMMG1_MATNR_DDEE) Click on process

Press enter

Answer ok-code box only

Go and verify in the database table.

BDC METHODS: - We can upload the data using BDC methods in 2 ways. 1. Session

2. Call transaction

SESSION: - It is a 2 step process. First we need to create a session and session need to be processed.

They are 3 functions modules involved in session method • BDC_OPEN_GROUP

• BDC_INSERT

• BDC_CLOSE_GROUP

BDC_OPEN_GROUP: - This FM is used to create a session and the following parameters need to be passing.

GROUP = SESSION NAME KEEP = X

(62)

BDC_INSERT: - This FM enables to pass the data on the given transactions using

“BDCDATA” structure and the following parameters need to be passing to the function module.

TCODE = MM01

DYNPRO TAB = LT_BDCDATA

BDC_CLOSE_GROUP: - It closes the currency open session if you do not pass any parameters to it.

BDCDATA STRUCTURE: - It has 5 fields. • PROGRAM

• DYNPRO • DYNBEGIN • FNAM • FVAL

PROGRAM: - We need to pass transaction code program name to this attribute. DYNPRO: - This attribute represents the screen number.

DYNBEGIN: - It is the new screen indicator.

FNAM: - This attribute represents the screen field name FVAL: - This attribute represents the screen field value.

CALL TRANSACTION: - It is an online update and you can update the data synchronously or asynchronously.

SYNRAX: - CALL TRANSACTION <TCODE> USING <BDCDATA> MODE<A/N/E>

UPDATE <S/A>

MESSAGE INTO <BDCMSGCOLL>. EX: - Call transaction ‘MM01’ using LT_BDCDATA

Mode ‘A’ Update ‘S’

Message into LT_BDCMSGCOLL. Even call transaction user BDCDATA structure to move the data onto the transaction. MODE: - ‘A’ Stands for all screen mode

‘N’ Stands for no screen mode ‘E’ Stands for error mode. UPDATE: - ‘S’ – Synchronous update

References

Related documents

secara signifikan jumlah total NUM dan DENUM node B mampu melakukan panggilan akan tetapi ada beberapa cell yang mengalami penurunan traffik sehingga akan menyebabkan

This study was conducted to determine whether there was Streptococcus pneumoniae colonization among Medical Students of the Faculty of Medicine Universitas Padjadjaran Batch 2011

This paper presents TuneGraph, an online visual tool for exploring melodic similarity. The underlying data comes from a large index of online music, all transcribed in

(Note: If you click the Custom radio button, click the Add link to select the message file.). Result: A Select Announcements dialog

To view a plan that has been created, click on the Planner tab, select the plan from the drop-down menu, then click the view radio button and click Load, as shown below.. For

The perception of risk factor showed to affect consumers behavior in reading animal-based food product’s label, while their health condition and time availability

(B) Yearly loss in CLR ⬎20% and ⬍20% in 65 patients treated with 90 Y-DOTATOC or 177 Lu-DOTATATE who had 0 –5 risk factors from hypertension, diabetes, age ⬎60 y, cumulative

Select the data source created, and click on the New button at the tree view, a popup will open where you can select the type of the Table Query you want to create.. The user