Top Banner
Updating Single Record (ABAP) 1 of 31 Task: Changing a Single Record Program: SAPMZ##_CUSTOMER1 Transaction: Z##_CUSTOMER1 Copy template: SAPBC414T_CREATE_CUSTOMER_01 Model Solution: SAPBC414S_CREATE_CUSTOMER_01 Our Program name: Z027393A_CUSTOMER1 The exercise makes you copy the template SAPBC414T_CREATE_CUSTOMER_01 to SAPMZ##_CUSTOMER1 where ## is the student number, but here we will create the complete exercise from scratch. Also, the exercise uses Module Pool to create the program; here we are creating the program using Function Pool. Information: SCUSTOM is the database table that holds the Customer data. The application is written to save the data to this table. Use Transaction Code SE11 for getting the record description and field description. And use Transaction Code SE16 to see the existing data. After the program is completed and executed, a new row will be added to this table and can be viewed using the same transaction code SE16. Table and Fields: SCUSTOM --> Flight Customer Data MANDT - Client ID - Customer Number NAME - Customer name FORM - Form of address STREET - Street POSTBOX - PO Box POSTCODE - Postal Code CITY - City COUNTRY - Country code REGION - Region TELEPHONE - Telephone number of flight customer CUSTTYPE - Customer type DISCOUNT - Discount rate LANGU - Language Key Launch SE80. Ensure that you are on the ‘Repository Browser’. Select Package from the drop down and enter your Package name [ZxxxxxxA] where xxxxxx is your SAP Login ID or Oracle ID, then click on the [Display] button. Create the package if the package does not already exist. Now create a Function Module, by right clicking the ‘Function Group’ item and selecting ‘Create’ as shown.
31

Step bystep abap_changinga_singlerecord

Oct 31, 2014

Download

Technology

mkpatil

 
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

1 of 31

Task: Changing a Single Record Program: SAPMZ##_CUSTOMER1 Transaction: Z##_CUSTOMER1 Copy template: SAPBC414T_CREATE_CUSTOMER_01 Model Solution: SAPBC414S_CREATE_CUSTOMER_01 Our Program name: Z027393A_CUSTOMER1 The exercise makes you copy the template SAPBC414T_CREATE_CUSTOMER_01 to SAPMZ##_CUSTOMER1 where ## is the student number, but here we will create the complete exercise from scratch. Also, the exercise uses Module Pool to create the program; here we are creating the program using Function Pool. Information: SCUSTOM is the database table that holds the Customer data. The application is written to save the data to this table. Use Transaction Code SE11 for getting the record description and field description. And use Transaction Code SE16 to see the existing data. After the program is completed and executed, a new row will be added to this table and can be viewed using the same transaction code SE16. Table and Fields: SCUSTOM --> Flight Customer Data MANDT - Client ID - Customer Number NAME - Customer name FORM - Form of address STREET - Street POSTBOX - PO Box POSTCODE - Postal Code CITY - City COUNTRY - Country code REGION - Region TELEPHONE - Telephone number of flight customer CUSTTYPE - Customer type DISCOUNT - Discount rate LANGU - Language Key Launch SE80. Ensure that you are on the ‘Repository Browser’. Select Package from the drop down and enter your Package name [ZxxxxxxA] where xxxxxx is your SAP Login ID or Oracle ID, then click on the [Display] button. Create the package if the package does not already exist. Now create a Function Module, by right clicking the ‘Function Group’ item and selecting ‘Create’ as shown.

Page 2: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

2 of 31

Enter the Function Group (name) and Short Text (description.)

Page 3: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

3 of 31

Click on Save.

Click on Save Symbol Icon.

Click on Continue Icon or hit Enter. The system automatically creates two include functions as shown below.

Page 4: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

4 of 31

Double click on the LZ027393A_CUSTOMER1TOP include file and enter the following code. FUNCTION-POOL Z027393A_CUSTOMER1 MESSAGE-ID bc414. DATA: answer, flag. DATA: ok_code LIKE sy-ucomm, save_ok LIKE ok_code. TABLES: scustom. “This command is not obsolete for use in this situation

The command TABLES: scustom creates the SCUSTOM structure that retains the newly entered (created) customer data.

Page 5: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

5 of 31

The BC414 message class is declared as a program default in the PROGRAM statement (see syntax MESSAGE-ID bc414 in the above code) and therefore valid throughout the programs. Save the Function Module by clicking on the Save button at the top. Since we need to generate a unique ID for each new customer generated, we need to use SAP functionality that does that. This Number Range Object/Buffer can be created new or existing one used [Use Transaction Code SNRO to create and maintain new Number Range Object.] We are using the existing object 'SBUSPID'. SAP also provides us with a function NUMBER_GET_NEXT to get the IDS using this object. We will first create a Subroutine to access the function in addition to other subroutines been created. Create the following subroutines as shown below, by right clicking on the Function Group name and selecting Create > Subroutine.

Page 6: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

6 of 31

Enter the name of the subroutine ‘ASK_LOSS’, SAP suggest a new Include for this subroutine, select the suggested name ‘LZ027393A_CUSTOMER1F01’ – we will use the same include to save all the subroutines that we will create shortly.

Page 7: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

7 of 31

Accept the warning that may show as follows:

Page 8: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

8 of 31

FORM ask_loss USING p_answer. CALL FUNCTION 'POPUP_TO_CONFIRM_LOSS_OF_DATA' EXPORTING textline1 = 'Continue?'(004) titel = 'Create Customer'(003) IMPORTING answer = p_answer. ENDFORM. " ASK_LOSS Similarly create the following subroutines by right clicking on the Function Group name and selecting Create > Subroutine. ASK_SAVE NUMBER_GET_NEXT SAVE SAVE_SCUSTOM FORM NUMBER_GET_NEXT USING p_scustom LIKE scustom. DATA: return TYPE inri-returncode. * get next free number in the number range '01' * of number object'SBUSPID' CALL FUNCTION 'NUMBER_GET_NEXT' EXPORTING nr_range_nr = '01' object = 'SBUSPID' IMPORTING number = p_scustom-id returncode = return EXCEPTIONS OTHERS = 1. CASE sy-subrc. WHEN 0. CASE return. WHEN 1. * number of remaining numbers critical MESSAGE s070. WHEN 2. * last number MESSAGE s071. WHEN 3. * no free number left over MESSAGE a072. ENDCASE. WHEN 1. * internal error MESSAGE a073 WITH sy-subrc.

Page 9: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

9 of 31

ENDCASE. ENDFORM. " NUMBER_GET_NEXT FORM ASK_SAVE USING p_answer. * POPUP_TO_CONFIRM_STEP is obsolete, so using POPUP_TO_CONFIRM below * CALL FUNCTION 'POPUP_TO_CONFIRM_STEP' * EXPORTING * textline1 = 'Data has been changed.'(001) * textline2 = 'Save before leaving transaction?'(002) * titel = 'Create Customer'(003) * IMPORTING * answer = p_answer. call function 'POPUP_TO_CONFIRM' exporting titlebar = 'Create Customer'(003) text_question = 'Data has been changed. Save before leaving transaction? ' text_button_1 = 'Yes' icon_button_1 = 'ICON_YES' text_button_2 = 'No' icon_button_2 = 'ICON_NO' default_button = '2' display_cancel_button = 'X' importing answer = p_answer. ENDFORM. " ASK_SAVE FORM SAVE. * get SCUSTOM-ID from number range object BC_SCUSTOM PERFORM number_get_next USING scustom. * save new customer PERFORM save_scustom. ENDFORM. FORM SAVE_SCUSTOM. INSERT INTO scustom VALUES scustom. IF sy-subrc <> 0. * insertion of dataset in DB-table not possible MESSAGE a048. ELSE. * insertion successfull MESSAGE s015 WITH scustom-id. ENDIF. ENDFORM.

Page 10: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

10 of 31

Create GUI Status (Menu) as shown below.

Page 11: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

11 of 31

Click on the ‘+’ next to the Menu Bar and add the following text and labels.

Now double click on the ‘Edit’ text (next to the Customer Data label that was entered)

Page 12: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

12 of 31

Delete all the following entries using button on the top menu, except the Cancel line and add the Code as shown

Save the changes.

Page 13: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

13 of 31

Now maximize the Function Keys by clicking on the ‘+’ sign next to it.

Enter SAVE, BACK, EXIT and CANCEL function code next (above) the save, back, exit and Cancel icon as shown below under the Standard Toolbar button.

Enter the fast text as shown below for these buttons. Leave Function Type as blank (Blank defaults to Application Function) for Save and Back button and E (exit) for Exit and Cancel.

Page 14: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

14 of 31

Page 15: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

15 of 31

Save the GUI Status. Now create GUI title

Page 16: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

16 of 31

Enter the Title Code and Title as shown below

Click on enter to save the GUI title. Save and Activate the program, by clicking on the Activate button. Creating the screen. Now create a Screen, by right clicking the ‘Function Group’ item and selecting ‘Create’ and then ‘Screen’ as shown.

Page 17: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

17 of 31

Enter Screen number as shown

Click Continue button or hit enter.

Page 18: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

18 of 31

Click on the Layout button (or Control + F7)

Page 19: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

19 of 31

Click on the Dictionary/Program Field Window button or hit F6. In the Table/Field Name field enter ‘SCUSTOM’ and then click on the ‘Get from Dictionary’ button. Important note – by selecting these fields from the database tables [in repository] all the fields automatically get all the labels/field help/etc defaulted from their respective fields’ definition in the data dictionary.

Select the fields as shown.

Page 20: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

20 of 31

Click on the Continue button. Click on the blank screen somewhere near the top left corner, so that the selected fields get copied over to the screen.

Page 21: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

21 of 31

Do not convert any fields if requested (in this simple example.)

Rearrange the fields as shown. Add 4 boxes around the groupings.

Page 22: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

22 of 31

Save the screen and exit the Screen Painter (Screen > Exit) Go to the ‘Element List’ tab of the Screen (this tab is between the ‘Attributes’ and ‘Flow Logic’ tab. On the ‘General Attributes’ sub tab enter the Frame01, Frame02, Frame03 and Frame04 for the four unnamed boxes created. Also enter the ‘OK_CODE’ name for the field name that has the ‘Type of screen element’ OK (this is automatically created by the screen when the screen is created – we provide a name.) During run time this field OK_CODE will have the name of the function code of the button or key that was clicked by user.

Page 23: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

23 of 31

On the ‘Flow Logic’ tab enter the following code for the Process Before Output (PBO) and Process After Input (PAI) logic.

PROCESS BEFORE OUTPUT. MODULE STATUS_0100. PROCESS AFTER INPUT. MODULE EXIT AT EXIT-COMMAND. MODULE SAVE_OK_CODE.

Page 24: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

24 of 31

FIELD: scustom-name MODULE mark_changed ON REQUEST. MODULE USER_COMMAND_0100. Save the changes. Create the modules STATUS_0100 and USER_COMMAND_0100 by forward navigation (i.e., double click on any module name(s), since these modules do not exist currently, the system will prompt us, to create these.) These modules are created in the appropriate INCLUDE file. Double click on STATUS_0100 in the above ABAP editor. At the following prompt select ‘Yes’.

Select the recommended new include file that the system shows.

Note that the alphabet ‘O’ in the name (3rd character from last) stands for OUTPUT of PROCESS BEFORE OUTPUT (PBO) modules and all the output modules may be created here.

Page 25: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

25 of 31

Select Continue button or hit Enter. Modify the module definition as shown below.

*----------------------------------------------------------------------* ***INCLUDE LZ027393A_CUSTOMER1O01 . *----------------------------------------------------------------------* MODULE STATUS_0100 OUTPUT. SET PF-STATUS 'DYN_0100'. SET TITLEBAR 'DYN_0100'. ENDMODULE. " STATUS_0100 OUTPUT Save and hit the Back button (F3) to go back to the Flow Logic of the screen. Now double click on the USER_COMMAND_0100 name.

Select Yes.

Page 26: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

26 of 31

Accept the new INCLUDE file name for this new INPUT (PAI – Process after Input) module.

Click on Continue button or hit Enter. Enter the following code in this INCLUDE function. *----------------------------------------------------------------------* ***INCLUDE LZ027393A_CUSTOMER1I01 . *----------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Module EXIT INPUT *&---------------------------------------------------------------------* MODULE exit INPUT. CASE ok_code. WHEN 'EXIT'. IF sy-datar IS INITIAL AND flag IS INITIAL. * no changes on screen 100 LEAVE PROGRAM. ELSE.

Page 27: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

27 of 31

PERFORM ask_save USING answer. * CASE answer. * WHEN 'J'. * ok_code = 'SAVE&EXIT'. * WHEN 'N'. * LEAVE PROGRAM. * WHEN 'A'. * CLEAR ok_code. * SET SCREEN 100. * ENDCASE. CASE answer. WHEN '1'. ok_code = 'SAVE&EXIT'. WHEN '2'. LEAVE PROGRAM. WHEN 'A'. CLEAR ok_code. SET SCREEN 100. ENDCASE. ENDIF. WHEN 'CANCEL'. IF sy-datar IS INITIAL AND flag IS INITIAL. * no changes on screen 100 LEAVE TO SCREEN 0. ELSE. PERFORM ask_loss USING answer. CASE answer. WHEN 'J'. LEAVE TO SCREEN 0. WHEN 'N'. CLEAR ok_code. SET SCREEN 100. ENDCASE. ENDIF. ENDCASE. ENDMODULE. " EXIT INPUT *&---------------------------------------------------------------------* *& Module SAVE_OK_CODE INPUT *&---------------------------------------------------------------------* MODULE save_ok_code INPUT. save_ok = ok_code. CLEAR ok_code. ENDMODULE. " SAVE_OK_CODE INPUT *&---------------------------------------------------------------------* *& Module USER_COMMAND_0100 INPUT *&---------------------------------------------------------------------*

Page 28: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

28 of 31

MODULE user_command_0100 INPUT. CASE save_ok. WHEN 'SAVE&EXIT'. PERFORM save. LEAVE PROGRAM. WHEN 'SAVE'. IF flag IS INITIAL. SET SCREEN 100. ELSE. PERFORM save. SET SCREEN 0. ENDIF. WHEN 'BACK'. IF flag IS INITIAL. SET SCREEN 0. ELSE. PERFORM ask_save USING answer. CASE answer. WHEN 'J'. PERFORM save. SET SCREEN 0. WHEN 'N'. SET SCREEN 0. WHEN 'A'. SET SCREEN 100. ENDCASE. ENDIF. ENDCASE. ENDMODULE. " USER_COMMAND_0100 INPUT *&---------------------------------------------------------------------* *& Module MARK_CHANGED INPUT *&---------------------------------------------------------------------* MODULE mark_changed INPUT. * set flag to mark changes were made on screen 100 flag = 'X'. ENDMODULE. " MARK_CHANGED INPUT Save and Activate the program (including the screens, etc) Create a transaction code to execute this program.

Page 29: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

29 of 31

Enter the program name and description.

Click on Continue button or hit Enter.

Page 30: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

30 of 31

Save - choose the appropriate package and workbench request.

Page 31: Step bystep abap_changinga_singlerecord

Updating Single Record (ABAP)

31 of 31

Run the transaction.