Sams Teach Yourself ABAP/4® in 21 Days


Appendix B

Answers to Quiz Questions and Exercises


Day 1

Quiz Answers

  1. SM04 (use the menu path: System->Status)
  2. S000
  3. S001
  4. Three. There is one database per R/3 system.
  5. Three: two for the application servers, plus one for the database server.
  6. Open SQL is SAP's dialect of ANSI SQL. It is a subset and variation of ANSI SQL.
  7. Open SQL has three advantages:
  8. The database interface portion of the work process implements Open SQL.
  9. A new roll area is allocated whenever a program is executed, and it is deallocated when the program terminates. The roll area contains the values of the variables for that program and the current program pointer.
  10. A user context is allocated each time a user logs on, and deallocated when he or she logs off. It contains information about the user, such as authorizations, profile settings, and TCP/IP address.
  11. The roll-out occurs at the end of a dialog step. It frees the work process to ready it for other requests, so that the program will not use CPU while waiting for user input.

Exercise 1 Answer

In Figures 1.28 and 1.31, the first field does not have type CLNT; therefore, the table is client-independent. Open SQL statements will operate on the all rows within these tables. In Figures 1.29 and 1.30, the first field in the table is type CLNT; therefore, the table is client-dependent. Open SQL statements will only operate on those rows having the same client number as your current logon client number.

Day 2

Quiz Answers

  1. It allocates a default work area for the table and gives the program access to the database table of the same name.
  2. The default table work area is the memory area allocated by a tables statement. This memory area has the same name and structure as the table named on the tables statement. The select statement uses it by default if there is no into clause.
  3. Into the default table work area.
  4. To the same line as the output from previous write statement.
  5. sy-subrc
  6. sy-dbcnt
  7. Line 4 will be executed 30 times, once for each row retrieved.
  8. Zero times. Line 4 will not be executed at all if the table is empty.

Programming Exercise Answers

  1. This report displays all vendor numbers and company codes from table ztxlfb1 where the company code is greater than or equal to 3000. Note that bukrs is a character field. If you don't enclose the value 5000 in single quotation marks, the system automatically converts it to character for the comparison. There is no difference in the output for this program, whether you specify quotation marks or not. However, avoiding conversions is good programming practice and it makes the program more efficient.
1  report ztz0201.

2  tables ztxlfb1.

3  select * from ztxlfb1 where bukrs >= '3000'

4      order by bukrs lifnr descending.

5      write: / ztxlfb1-bukrs, ztxlfb1-lifnr.

6      endselect.

7  if sy-subrc <> 0.

8      write / 'no records found'.

9      endif.

  1. Move the test for sy-subrc after the endselect, as shown here:
1  report ztz0202.

2  tables ztxlfa1.

3  select * from ztxlfa1 where lifnr like 'W%'.

4      write / ztxlfa1-lifnr.

5      endselect.

6  if sy-subrc <> 0.

7      write / 'no records found'.

8      endif.

  1. There is a period missing at the end of the tables statement, and the vendor number must be padded on the left with zeros because it is a character field in the database. (This behavior is more fully explained in the chapter on conversions.)
1  report ztz0203.

2  tables ztxlfa1.

3  select * from ztxlfa1 where lifnr > '0000001050'.

4      write / ztxlfa1-lifnr.

5      endselect.

  1. The last line of the output says no records found, even though records were found. The problem is on line 6. The test should be for equality, not inequality.
1  report ztz0204.

2  tables ztxlfa1.

3  select * from ztxlfa1 where lifnr > '0000001050'.

4      write / ztxlfa1-lifnr.

5      endselect.

6  if sy-dbcnt = 0.

7      write / 'no records found'.

8      endif.

  1. The write statement should be inside the select loop.
1  report ztz0205.

2  tables ztxlfa1.

3  select * from ztxlfa1 where lifnr > '0000001050'.

4      write / ztxlfa1-lifnr.

5      endselect.

6  if sy-subrc <> 0.

7      write / 'no records found'.

8      endif.

  1. Referring to the original program, table ztxlfc3 is not used; the definition for it can be removed from line 2. The into ztxlfa1 on line 4 is not needed, since ztxlfa1 is the default work area. Lines 5 and 6 can be chained together. The second expression using sy-dbcnt on line 8 is redundant and can be removed. Line 12 doesn't need an explicit work area, so it can be removed. Consequently, lines 13 and 14 must be changed to write from ztxlfb1, and line 3 is no longer needed. Lines 13 and 14 can be chained together. The simplified program follows:
1  report ztz0206.

2  tables: ztxlfa1, ztxlfb1.

3

4  select * from ztxlfa1.

5      write: / ztxlfa1-lifnr,

6               ztxlfa1-name1.

7      endselect.

8  if sy-subrc <> 0.

9      write / 'no records found in ztxlfa1'.

10     endif.

11 uline.

12 select * from ztxlfb1.

13     write: / ztxlfb1-lifnr,

14              ztxlfb1-bukrs.

15     endselect.

16 if sy-subrc <> 0.

17     write / 'no records found'.

18     endif.

  1. The syntax error is caused by the endselect on line 5. It should be removed. You could also correct the syntax error by removing the word single from the select statement on line 3. However, this is a less efficient solution since only one row is to be read. The comparison operator on line 3 is also incorrect. It should be =.
1  report ztz0207.

2  tables ztxlfa1.

3  select single * from ztxlfa1 where lifnr = '0000001000'.

4  write / ztxlfa1-lifnr.

5  if sy-subrc <> 0.

6      write / 'no records found'.

7      endif.

Day 3

Quiz Answers

  1. The domain gives a field its technical characteristics, such as data type and length.
  2. The data element contains a domain name, field labels for screens and lists, and documentation for F1 help.
  3. Application data refers to data used by R/3 applications like SD (Sales and Distribution) or MM (Materials Management). There are two types: transaction data and master data. Examples of application data are purchase orders (an example of transaction data) or vendor information (an example of master data). There is also system data, such as configuration data or DDIC metadata, in addition to application data.
  4. No, the location of the decimal point is part of the description of the field. It is contained in the domain, not stored with the value.
  5. SE16, SE17, SM30 and SM31. SE16 is the most commonly used, and SE17 cannot be used to update data.
  6. A transparent table has a one-to-one relationship with a table in the database. Pooled and cluster tables have many-to-one relationships with database tables.

Exercise 1 Answer

For this solution, refer to table ztzlfa1 in the R/3 system.

Exercise 2 Answer

To see the solution for the table kna1, refer to table ztzkna1 in the R/3 system. The solution for the report follows:

1    report ztz0302.

2    tables ztzkna1.

3    select * from ztzkna1.

4        write: / ztzkna1-kunnr, ztzkna1-name1,

5                 ztzkna1-cityc, ztzkna1-regio,

6                 ztzkna1-land1.

7        endselect.

8    if sy-subrc <> 0.

9        write / 'No rows found'.

10       endif.

Day 4

Quiz Answers

  1. They must both use the same domain.
  2. Within table zt1, type .INCLUDE in the field name field and zs1 in the data element name field at the point in the table where the structure should be included.
  3. A text table provides descriptions for codes contained in a check table in multiple languages.
  4. mandt, spras, f1 and f2.
  5. Each field of type CURR must reference a currency key field (type CUKY).

Exercise 1 Answer

For the solution to this exercise, view the table ztzt005 online in the R/3 system.

Exercise 2 Answer

For the solution to this exercise, view the table ztzt005s online in the R/3 system. Don't forget to compare the cardinality and foreign key field type of the foreign key relationship with those specified online.

Exercise 3 Answer

For the solution to this exercise, view the table ztzlfa1 online in the R/3 system. Don't forget to compare the cardinality and foreign key field type of the foreign key relationships with those specified online.

Exercise 4 Answer

For the solution to this exercise, view the table ztzkna1 online in the R/3 system. Don't forget to compare the cardinality and foreign key field type of each relationship with the ones online.

Exercise 5 Answer

For the solution to this exercise, view the tables ztzt005h and ztzt005g online in the R/3 system. Don't forget to compare the cardinality and foreign key field type of your foreign keys with those online.

Exercise 6 Answer

For the solution to this exercise, view the structure tel and the tables ztzlfa1 and ztzkna1 online in the R/3 system.

Exercise 7 Answer

For the solution to this exercise, view the table ztzkna1 online in the R/3 system.

Day 5

Quiz Answers

  1. No. You cannot "bind" an index to a select statement. The optimizer always chooses an index at runtime.
  2. Yes, but you must apply for a modification key from SAP to do so. This can be done through OSS, the Online Service System.
  3. Yes, you can use the runtime analysis tool to measure the difference.

Exercise 1 Answer

Go to the Data Dictionary transaction (transaction code SE12) and display the tables. Look at the technical settings.

The data class for the following:

MARA: APPL0 Master data, transparent tables (see Figure 5.21)
LFA1: APPL0 Master data, transparent tables (see Figure 5.22)
KNA1: APPL0 Master data, transparent tables (see Figure 5.23)

The size category for the following:

MARA: 4 Data records expected: 57,000 to 4,600,000 (see Figure 05.21)
LFA1: 3 Data records expected: 11,000 to 44,000 (see Figure 05.22)
KNA1: 3 Data records expected: 9,600 to 38,000 (see Figure 05.23)

The following figures help explain:

Figure B.1:

Figure B.2:

Figure B.3:

The size category determines the probable space requirement for a table in the database. Press F4 on the field size category to see the number of data records that can be maintained for your table's individual categories without complications. These complications could be, for example, a reorganization becoming necessary because the maximum space to be reserved for the table was exceeded due to the maintained size category.

Day 6

Quiz Answers

  1. Yes. Any changes to the domain require that it be reactivated. The table should also be reactivated and a consistency check should be performed.

Exercise 1 Answer

  1. In the database utility, click the Delete Database Table button. This "drops" the table and the table and content will be deleted. You can recreate the table by pressing the Create Database Table button. The table will be recreated using the active version of the table. You can use the database utility. Be cautious as you do this to a table in SAP.

Day 7

Quiz Answers

The solutions are as follows:

  1. The correct definition is 'Don''t bite.' It should have been enclosed in single quotation marks and it requires two consecutive quotation marks within.
  2. The correct definition is '+2.2E03'. The exponent character is E, not F, and decimals are not allowed in an exponent.
  3. The definition is correct.
  4. The correct definition is '00000F'. There should not be a leading x. An even number of characters must exist, and they must be uppercase.
  5. The correct definition is '-9.9'. Numeric literals containing decimals must be enclosed in single quotation marks, and the sign must lead.
  6. Floating-point values cannot exceed 1E+308.
  7. H is not a valid hexadecimal character. The valid characters are A-F and 0-9.
  8. The definition is correct. A single quotation mark is represented. If written out, the output would be '.
  9. The definition is correct. A double quotation mark within single quotation marks is represented. If written out, the output would be '"'.

The solutions are as follows:

  1. The correct definition is data st_f1(5) type c. A dash should not appear in the definition of a variable name. The underscore character should be used instead.
  2. The correct definition is data f1 type c. The data type for character is C.
  3. The correct definition is data f1(20) type c. There should not be a space between the field name and length specification.
  4. Variable names should not start with a numeric, and a length is not allowed with type i. The correct definition is data a1 type i.
  5. The correct definition is data per_cent type p decimals 1 value '55.5'. A dash should not be used in a variable name. A decimal is specified in the value, but the decimals addition is missing. The value contains a decimal, but it is not enclosed in quotation marks.
  6. The definition is correct. f1 can hold three digits because (L*2)-1 = (2*2)-1 = 3.

Exercise 1 Answer

report ztz0707.

parameters: p_date like sy-datum default sy-datum,   

            p_field1 type c,                         

            chckbox1 as checkbox,                    

            chckbox2 as checkbox,                    

            radbut1 radiobutton group g1 default 'X',

            radbut2 radiobutton group g1.            

Day 8

Quiz Answer

  1. The one predefined constant is SPACE and the equivalent literal format is ' '.
  2. The types of statements that can be used are data and structure type. User-defined are defined in the Data Dictionary to help with maintenance and reduce redundancy.

Exercise 1 Answer

types: dollar(16)   type p decimals 2,

       point(16)    type p decimals 0.     "credit card points



data: begin of usd_amount,

           hotel      type dollar,

           rent_car   type dollar,

           plane      type dollar,

           food       type dollar,

           end of usd_amount,

      begin of amex_pt,

           hotel      type p decimals 2,

           rent_car   type point,

           plane      type point,

           food       type point,

           end of amex_pt.

Exercise 2 Answer

Output:



1 3 4 5

9 8 7 6

Day 9

Quiz Answer

  1. You can use eq or =. For example, move vara to varb. is the same as varb = vara. or varb eq vara.
  2. Operators and operands must be separated by spaces in order for the variables to be computed.

Exercise 1 Answer

  1. sperz
  2. konzs
  3. fdpos
  4. msgid
  5. matkl

The two things wrong in the program are the table declaration of ztxt005t and the single quotation mark before the variable, land1. Declare the table ztxt005t and remove the single quotation mark before the land1 variable.

Day 10

Quiz Answers

  1. The answer is as follows:
case v1.

    when 5.       write 'The number is five.'.

    when 10.      write 'The number is ten.'.

    when others.  write 'The number is not five or ten.'.

    endcase.

  1. The string operators are CP (contains pattern) and NP (does not contain pattern).
  2. The three program control statements are exit, continue, and check:

Exercise 1 Answer

report ztz1001.  

data: l1(2) type c.  

do 20 times.      

    write / sy-index. 

    do 10 times.    

        l1 = sy-index.

        write l1.   

        enddo.          

    enddo.

Conversion occurs in the program as follows:

I --> C  ZTX1001 000060      L1 = SY-INDEX.

Day 11

Quiz Answers

  1. In actuality, your Basis consultant sets a limit on the maximum amount of extended memory an internal table can allocate. If you exceed that amount, your program will allocate private memory from the work process and will no longer be able to roll your program out.
  2. If you do, the system will allocate 8KB from the paging area. Memory will be wasted and paging could increase, resulting in poorer performance.
  3. The read table statement can only be used to read internal tables. It doesn't work with database tables. Use select single instead.

Exercise 1 Answer

In systems prior, conversions were performed by converting from the value on the right to the data type and length of the component on the left.

Figure B.4:

On lines 9 and 10, there was a conversion from c to n (character to numeric) and then a conversion from p to I (parameter to integer).

On line 16, there was a conversion from p to I (parameter to integer).

Day 12

Quiz Answers

  1. Your change to sy-tabix is ignored and the statements would operate on the row in the work area. sy-tabix is like sy-index-modifying either does not affect loop operations. Also, the value of sy-tabix is reset at the endloop, and the next loop pass proceeds as if the value were never changed.
  2. The only thing sy-toccu can tell you that other variables can't is whether your internal table is entirely in the paging area. If it is zero, it is entirely in the paging area. This has no use in a production system, but you might find it useful during development to confirm your expectation of how memory is allocated for an internal table. If, for example, you expect the internal table to be in the roll area, but sy-toccu contains zero (indicating that it's in the paging area), you might have another look at your occurs clause to determine whether it is correct.

Exercise 1 Answer

report ztz1201.

tables ztxlfa1.

data it like ztxlfa1 occurs 23 with header line.



select * from ztxlfa1 into table it.   "don't code an endselect

loop at it.

    write: / sy-tabix, it-land1, it-regio.

    endloop.

uline.

it-land1 = 'US'. modify it index 3 transporting land1.

it-regio = 'TX'. modify it transporting regio where regio = 'MA'.

loop at it.

    write: / sy-tabix, it-land1, it-regio.

    endloop.

free it.

Day 13

Quiz Answer

  1. Numeric fields (types i p and f) are filled with zeros. The rest of the fields to the right of the control level are filled with asterisks.

Exercise 1 Answer

report ztz1301.

data: begin of it occurs 3,

          f1(2) type n,

          f2    type i,

          f3(2) type c,

          f4    type p,

          end of it.



it-f1 = '40'. it-f3 = 'DD'. it-f2 = it-f4 = 4. append it.

it-f1 = '20'. it-f3 = 'BB'. it-f2 = it-f4 = 2. append it.



sort it by f1.

do 5 times.

    it-f1 = sy-index * 10.

    it-f3 = 'XX'.

    it-f2 = it-f4 = sy-index.

    read table it

        with key f1 = it-f1

        binary search

        comparing f2 f3 f4

        transporting no fields.

    if sy-subrc = 2.

        modify it index sy-tabix.

    elseif sy-subrc <> 0.

        insert it index sy-tabix.

        endif.

    enddo.



loop at it.

    write: / it-f1, it-f2, it-f3, it-f4.

    endloop.

Exercise 2 Answer

Here is an efficient way to fix the problem:

report ztz1302.

tables: ztxlfa1.

data: begin of it occurs 10,

          lifnr like ztxlfa1-lifnr,

          land1 like ztxlfa1-land1,

          end of it.                

select lifnr land1 from ztxlfa1 into table it.

loop at it.

    write: / it-lifnr,

             it-land1.

    endloop.

Day 14

Quiz Answers

  1. You must sign off and sign back on again to the R/3 system before changes to user defaults take effect.
  2. An edit mask beginning with a V, when applied to a numeric field (types i, p, and f), causes the sign field to be displayed at the beginning. If applied to a character field, a V is actually output.
  3. The no-sign addition, when used with variables of type i, p, or f, suppresses the sign character's output. In other words, negative numbers will not have a sign and appear as if they were positive.

Exercise 1 Answer

1  report ztz1401.

2  write: /     '....+....1....+....2....+....3....+....4',

3         /     'First',

4          40   'December',

5         /16   'January',

6         /30   'First'.

Day 15

Quiz Answers

  1. The three graphical additions are symbols, icon, and line. The program should have an include statement, include <�>, for each of the graphical additions in order to utilize it. For example:
include <symbol> for symbols,

include <icon> for icons,

include <line> for lines.

  1. The two additions used with the report statement are line size and line count. The variables used for the additions must be numeric because they control the size of the page.

Exercise 1 Answer

report ztz1501.

include <symbol>.

write: /4 sym_filled_square as symbol, 'square',

       /4 sym_filled_diamond as symbol, 'diamond',

       /4 sym_filled_circle as symbol, 'circle',

       /4 sym_glasses as symbol, 'glasses',

       /4 sym_pencil as symbol, 'pencil',

       /4 sym_phone as symbol, 'phone',

       /4 sym_note as symbol, 'note',

       /4 sym_folder as symbol, 'folder'.

Figure B.5:

Day 16

Quiz Answers

  1. The statement back can be used to return to the current output position.
  2. Use the skip sy-linct instead of new-page when you want to set a new page and you want a footer at the bottom of that current page.

Exercise 1 Answer

Day 17

Quiz Answers

  1. No.
  2. Don't use stop in the following events: initialization, at selection-screen output, top-of-page, and end-of-page. Technically, it can work with top-of-page and end-of-page if you refrain from issuing write statements within end-of-selection afterward.
  3. To be precise, a variable is only known within a program after the point at which it is defined. For example, if you define a variable on line 10, you would be able to access it on lines 11 and later, but not on lines 1-9. In the case of a local definition, you can access the global version of the variable at any point before the local definition.

Exercise 1 Answer

REPORT ZTZ1701 NO STANDARD PAGE HEADING.

TABLES ZTXLFA1.

PARAMETERS P_LAND1 LIKE ZTXLFA1-LAND1.



INITIALIZATION.

  P_LAND1 = 'US'.



START-OF-SELECTION.

  PERFORM CREATE_REPORT.



FORM CREATE_REPORT.

  SELECT * FROM ZTXLFA1 WHERE LAND1 = P_LAND1.

      PERFORM WRITE_REC.

      ENDSELECT.

  ENDFORM.



FORM WRITE_REC.

  WRITE: / ZTXLFA1-LIFNR, ZTXLFA1-NAME1, ZTXLFA1-LAND1.

  ENDFORM.



TOP-OF-PAGE.

  FORMAT COLOR COL_HEADING.

  WRITE: / 'Vendors with Country Code', P_LAND1.

  ULINE.

Day 18

Quiz Answers

  1. Parameter names that appear on the form statement are called formal parameters. This term is easy to remember because formal starts with form. For example, in the statement form s1 using p1 changing p2 p3, the parameters p1, p2, and p3 are called formal parameters.
  2. Passing a variable of the wrong data type or length to a typed parameter causes a syntax error.
  3. New memory is not allocated for the value. A pointer to the original memory location is passed instead. All references to the parameter are references to the original memory location. Changes to the variable within the subroutine update the original memory location immediately.
  4. The additions using f1 and changing f1 both pass f1 by reference-they are identical in function. The reason they both exist is that, used properly, they can document whether the subroutine will change a parameter or not.

Exercise 1 Answer

The following output is generated:

          Top of page, flag = S  ctr = 1

          --------------------------------

in Start-Of-Selection

          p1 =

The initialization section is not executed because no selection criteria is present in the program. The Start-Of-Selection event is executed. When the program gets to the first write statement, control in the program is passed along to the Top-of-page event. When the Top-of-page event is complete, control is passed back to the Start-Of-Selection event.

Day 19

Quiz Answer

  1. True. You never need to specify a value for an import parameter that has a proposal.
  2. True. You never need to code parameters that are exported from the function module.

Exercise 1 Answer

When the program executes the internal table is filled and the function module is called. A pop-up window with the contents of the internal table will appear. Depending on what entry was chosen by the user, it will then print out using the write statement.

Day 20

Quiz Answers

  1. The data definitions of both of the parameters must be identical.
  2. Use the menu path Function Module->Release->Cancel Release.
  3. The program will be aborted and a short dump that has the runtime error RAISE_EXCEPTION will result.
  4. They should not be used within function modules. Instead, the raise statement should be used because it enables the caller to set the value of sy-subrc on return.

Exercise 1 Answer

1  function z_tz_div.

2  *"------------------------------------------------------------

3  *"*"Local interface:

4  *"       IMPORTING

5  *"             VALUE(P1) TYPE  I DEFAULT 1

6  *"             VALUE(P2) TYPE  I

7  *"       EXPORTING

8  *"             VALUE(P3) TYPE  P

9  *"       EXCEPTIONS

10 *"             ZERO_DIVIDE

11 *"------------------------------------------------------------

12 if p2 = 0.

13     raise zero_divide.

14     endif.

15 p3 = p1 / p2.

16 endfunction.

Day 21

Quiz Answers

  1. The two flavors of the matchcode assembled are physically and logically. Physically, the data is stored in a separate table. Logically, the data is managed by database view, which is the same as the transparent storage.
  2. Yes, changes to the characteristics of a domain linked to data elements will also change, because data elements in a domain inherit all properties of a domain that are referenced.
  3. The primary rule for establishing a foreign key relationship is to define and link a relationship between multiple tables.

Exercise 1 Answer

report ztz2101.

tables: mara, t001w.

* Selection parameters for BOMs

selection-screen begin of line.

selection-screen comment (33) text-bom.

parameters: bom like mara-matnr,

            spras like t002-spras.

selection-screen end of line.

selection-screen skip 1.

Select-options: matnr for mara-matnr,

                werks for t001w-werks.

Figure B.6:


© Copyright, Sams Publishing. All rights reserved.