Professional Documents
Culture Documents
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.
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.
REPORT ZAB data : 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.
DATA: BEGIN OF ITAB OCCURS 0, F1, F2 TYPE I, F3(3), END OF ITAB. DATA: LIN type i, oc type i. ******Append Operation ITAB-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 Operation DESCRIBE TABLE ITAB LINES LIN Occurs oc. write: LIN, oc. write : 'result of ITAB'.
Cont
BD
Exceptions in a function moduleExceptions 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> and Message.Raising<exception>
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.
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.
CASE SY-SUBRC. WHEN 1. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SYMSGNO. WHEN 2. MESSAGE E702(AT). ENDCASE. LOOP AT JTAB INTO WA. WRITE: / WA-CARRID, WA-CONNID, WA-CITYFROM, WACITYTO. ENDLOOP.
Passing Table to Function modules: import parameter: parameter name TYPE associated type P_MATNR type mara-matnr export parameter: parameter name type spec associated type MARA_TABLE TYPE MARA MESSAGE TYPE BAPIRET2-MESSAGE then go for sorce code and write these code
SELECT 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.
14
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.
sflight
carrid connid fldate Price
LH LH LH SQ