16
Move Corresponding • The move-corresponding statement does the same job as move statement, but it also checks for the field names. Like if we have same field name in two different structures, it would pick up same field name and move the data accordingly. • To perform a move from one field string to another where the data types and/or lengths do not match, use the move-corresponding statement. • Components in the receiving field string that do not have a matching name in the sending field string are not changed.

ERP Slide

Embed Size (px)

Citation preview

Page 1: ERP Slide

Move Corresponding

• The move-corresponding statement does the same job as move statement, but it also checks for the field names. Like if we have same field name in two different structures, it would pick up same field name and move the data accordingly.

• To perform a move from one field string to another where the data types and/or lengths do not match, use the move-corresponding statement.

• Components in the receiving field string that do not have a matching name in the sending field string are not changed.

Page 2: ERP Slide

Example:Data: begin of s1,

c1 type p decimals 2 value '1234.56',c2(3) value 'abc',c3(4) value '1234',

end of s1,begin of s2,

c1(8) ,x2(3) value 'xyz',c3 type i,

end of s2.Move-corresponding s1 to s2.write: s2-c1, s1-c2, s2-c3.

Page 3: ERP Slide

REPORT ZABdata : begin of emp, empno type i, ename(20) type c, end of emp.emp-empno = 1.emp-ename = ‘saint'.write :/ 'EMP structure'.write :/ emp-empno, emp-ename.data : begin of emp1, deptno type i, empno type i, ename(20) type c, end of emp1.move-corresponding emp to emp1.write :/ 'EMP1 structure'.write :/ emp1-deptno, emp1-empno, emp1-ename.

Page 4: ERP Slide
Page 5: ERP Slide

data : t001 like table of t001 with header line.select * from t001 into table t001.describe table t001.write :/ ' Number of records ' , sy-tfill.`

Describe Option in Internal Table

Page 6: ERP Slide

Cont… DATA: BEGIN OF ITAB OCCURS 0,F1,F2 TYPE I,F3(3),END OF ITAB.DATA: LIN type i, oc type i.******Append OperationITAB-F1 = 'A'.ITAB-F2 = 10.ITAB-F3 = 'BC'.APPEND ITAB.ITAB-F1 = 'B'.ITAB-F2 = 15.ITAB-F3 = 'BD'.APPEND ITAB.WRITE:/ ITAB-F1,ITAB-F2,ITAB-F3.

******Describe OperationDESCRIBE TABLE ITAB LINES LIN Occurs oc.write: LIN, oc.write : 'result of ITAB'.

Output:B 15 BD 2 0result of ITAB

Page 7: ERP Slide

Exceptions in a function module-Exceptions are used to handle errors that occur in function modules. The calling program checks whether any errors have occurred and then takes action accordingly. In function Modules there are basically two raise statements are used: raise<exception> andMessage……….Raising<exception>

Page 8: ERP Slide

Pass the exception in Function Modules

Page 9: ERP Slide
Page 10: ERP Slide
Page 11: ERP Slide

FUNCTION ZZEXCEPT*"------------------------------------------------------------*"*"Local interface:*" IMPORTING*" VALUE(ID) LIKE SPFLI-CARRID DEFAULT 'LH '*" EXPORTING*" VALUE(ITAB) TYPE SPFLI_TAB*" EXCEPTIONS*" NOT_FOUND*"------------------------------------------------------------ SELECT * FROM SPFLI INTO TABLE ITAB WHERE CARRID = ID. IF SY-SUBRC NE 0. MESSAGE E007(AT) RAISING NOT_FOUND. ENDIF.ENDFUNCTION.

Page 12: ERP Slide

REPORT MYFUNCTIONMODULE.PARAMETERS CARRIER TYPE S_CARR_ID.DATA: JTAB TYPE SPFLI_TAB, WA LIKE LINE OF JTAB.CALL FUNCTION ' ZZEXCEPT ' EXPORTING ID = CARRIER IMPORTING ITAB = JTAB EXCEPTIONS NOT_FOUND = 1 OTHERS = 2.

Page 13: ERP Slide

CASE SY-SUBRC. WHEN 1. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO. WHEN 2. MESSAGE E702(AT).ENDCASE.

LOOP AT JTAB INTO WA. WRITE: / WA-CARRID, WA-CONNID, WA-CITYFROM, WA-CITYTO.ENDLOOP.

Page 14: ERP Slide

14

Passing Table to Function modules:import parameter:parameter name TYPE associated type P_MATNR type mara-matnrexport parameter: parameter name type spec associated typeMARA_TABLE TYPE MARA MESSAGE TYPE BAPIRET2-MESSAGEthen go for sorce code and write these codeSELECT SINGLE * FROM MARA INTO MARA_TABLE WHERE MATNR = P_MATNR.IF SY-SUBRC = 0.MESSAGE = 'record is found '.WRITE : MESSAGE.ELSE.MESSAGE = 'not found, enter valid values'.WRITE : MESSAGE.ENDIF.

Page 15: ERP Slide

SELECT … ORDER BY ...

Tables: spfli.Select * from spfli

Order by cityfrom. Write: / spfli-carrid, spfli-connid,

spfli-cityfrom.Endselect.

Page 16: ERP Slide

SELECT … GROUP BY ...

Data: carrid like sflight-carrid, mindat Type P Decimals 2, maxdat Type P Decimals 2.Select carrid Min( price ) Max( price ) Into (carrid, mindat, maxdat) From sflight Group by carrid. Write: / carrid, mindat, maxdat.Endselect.

carrid connid fldate Price

LH 0400 20010101 150

LH 0400 20010110 145

LH 0400 20010228 130

SQ 0110 20010226 75

sflight