SlideShare una empresa de Scribd logo
1 de 31
Descargar para leer sin conexión
Updating Single Record (ABAP)
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.




                                                                                1 of 31
Updating Single Record (ABAP)




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




                                                                2 of 31
Updating Single Record (ABAP)




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.




                                                                         3 of 31
Updating Single Record (ABAP)




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.



                                                                           4 of 31
Updating Single Record (ABAP)

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.




                                                                                5 of 31
Updating Single Record (ABAP)




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.




                                                                          6 of 31
Updating Single Record (ABAP)




Accept the warning that may show as follows:




                                                  7 of 31
Updating Single Record (ABAP)

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.


                                                                               8 of 31
Updating Single Record (ABAP)
 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.




                                                                             9 of 31
Updating Single Record (ABAP)

Create GUI Status (Menu) as shown below.




                                                  10 of 31
Updating Single Record (ABAP)




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)




                                                                                11 of 31
Updating Single Record (ABAP)




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




Save the changes.


                                                                          12 of 31
Updating Single Record (ABAP)

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.




                                                                           13 of 31
Updating Single Record (ABAP)




                                14 of 31
Updating Single Record (ABAP)




Save the GUI Status.

Now create GUI title




                                                   15 of 31
Updating Single Record (ABAP)




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.




                                                                             16 of 31
Updating Single Record (ABAP)




Enter Screen number as shown




Click Continue button or hit enter.




                                                    17 of 31
Updating Single Record (ABAP)




Click on the Layout button (or Control + F7)




                                                   18 of 31
Updating Single Record (ABAP)




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.



                                                                                 19 of 31
Updating Single Record (ABAP)




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.




                                                                            20 of 31
Updating Single Record (ABAP)




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




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




                                                                   21 of 31
Updating Single Record (ABAP)




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.




                                                                             22 of 31
Updating Single Record (ABAP)




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.




                                                                             23 of 31
Updating Single Record (ABAP)
 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.




                                                                            24 of 31
Updating Single Record (ABAP)




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.


                                                                            25 of 31
Updating Single Record (ABAP)


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.



                                                                           26 of 31
Updating Single Record (ABAP)
     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
*&---------------------------------------------------------------------*


                                                                           27 of 31
Updating Single Record (ABAP)
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.




                                                                           28 of 31
Updating Single Record (ABAP)




Enter the program name and description.




Click on Continue button or hit Enter.




                                                    29 of 31
Updating Single Record (ABAP)




Save - choose the appropriate package and workbench request.




                                                               30 of 31
Updating Single Record (ABAP)




Run the transaction.




                                                   31 of 31

Más contenido relacionado

Destacado

Abap slide lock Enqueue data clusters auth checks
Abap slide lock Enqueue data clusters auth checksAbap slide lock Enqueue data clusters auth checks
Abap slide lock Enqueue data clusters auth checks
Milind Patil
 
Abap slide exceptionshandling
Abap slide exceptionshandlingAbap slide exceptionshandling
Abap slide exceptionshandling
Milind Patil
 
Abap slides user defined data types and data
Abap slides user defined data types and dataAbap slides user defined data types and data
Abap slides user defined data types and data
Milind Patil
 
Abap slide class4 unicode-plusfiles
Abap slide class4 unicode-plusfilesAbap slide class4 unicode-plusfiles
Abap slide class4 unicode-plusfiles
Milind Patil
 

Destacado (7)

Abap slides set1
Abap slides set1Abap slides set1
Abap slides set1
 
Abap slide lock Enqueue data clusters auth checks
Abap slide lock Enqueue data clusters auth checksAbap slide lock Enqueue data clusters auth checks
Abap slide lock Enqueue data clusters auth checks
 
Abap slide exceptionshandling
Abap slide exceptionshandlingAbap slide exceptionshandling
Abap slide exceptionshandling
 
Abap slides user defined data types and data
Abap slides user defined data types and dataAbap slides user defined data types and data
Abap slides user defined data types and data
 
SAP PM: Test Equipment Management/Calibration process
SAP PM: Test Equipment Management/Calibration processSAP PM: Test Equipment Management/Calibration process
SAP PM: Test Equipment Management/Calibration process
 
Abap slide class4 unicode-plusfiles
Abap slide class4 unicode-plusfilesAbap slide class4 unicode-plusfiles
Abap slide class4 unicode-plusfiles
 
Abap reports
Abap reportsAbap reports
Abap reports
 

Similar a Step bystep abap_changinga_singlerecord

Complete reference to_abap_basics
Complete reference to_abap_basicsComplete reference to_abap_basics
Complete reference to_abap_basics
Abhishek Dixit
 
Page 8 of 8Delete this text and type your name here This fil.docx
Page 8 of 8Delete this text and type your name here This fil.docxPage 8 of 8Delete this text and type your name here This fil.docx
Page 8 of 8Delete this text and type your name here This fil.docx
alfred4lewis58146
 
Page 3 of 11Delete this text and type your name here This .docx
Page 3 of 11Delete this text and type your name here This .docxPage 3 of 11Delete this text and type your name here This .docx
Page 3 of 11Delete this text and type your name here This .docx
alfred4lewis58146
 
Report exchange designer
Report exchange designerReport exchange designer
Report exchange designer
rlsotto
 
CASE STUDY InternetExcel Exercises, page 434, textRecord your.docx
CASE STUDY InternetExcel Exercises, page 434, textRecord your.docxCASE STUDY InternetExcel Exercises, page 434, textRecord your.docx
CASE STUDY InternetExcel Exercises, page 434, textRecord your.docx
keturahhazelhurst
 
SAP BPC 10.1 NW Master Data loading
SAP BPC 10.1 NW Master Data loading SAP BPC 10.1 NW Master Data loading
SAP BPC 10.1 NW Master Data loading
Manoj Kumar
 
User exit training
User exit trainingUser exit training
User exit training
Jen Ringel
 

Similar a Step bystep abap_changinga_singlerecord (20)

Lsmw for master data upload simple explanation
Lsmw for master data upload simple explanationLsmw for master data upload simple explanation
Lsmw for master data upload simple explanation
 
Change transport system in SAP
Change transport system in SAP Change transport system in SAP
Change transport system in SAP
 
Complete reference to_abap_basics
Complete reference to_abap_basicsComplete reference to_abap_basics
Complete reference to_abap_basics
 
Db2
Db2Db2
Db2
 
Calibration process
Calibration processCalibration process
Calibration process
 
Calibration process
Calibration processCalibration process
Calibration process
 
Page 8 of 8Delete this text and type your name here This fil.docx
Page 8 of 8Delete this text and type your name here This fil.docxPage 8 of 8Delete this text and type your name here This fil.docx
Page 8 of 8Delete this text and type your name here This fil.docx
 
Page 3 of 11Delete this text and type your name here This .docx
Page 3 of 11Delete this text and type your name here This .docxPage 3 of 11Delete this text and type your name here This .docx
Page 3 of 11Delete this text and type your name here This .docx
 
Sap application log
Sap application logSap application log
Sap application log
 
Report exchange designer
Report exchange designerReport exchange designer
Report exchange designer
 
CASE STUDY InternetExcel Exercises, page 434, textRecord your.docx
CASE STUDY InternetExcel Exercises, page 434, textRecord your.docxCASE STUDY InternetExcel Exercises, page 434, textRecord your.docx
CASE STUDY InternetExcel Exercises, page 434, textRecord your.docx
 
SAP BPC 10.1 NW Master Data loading
SAP BPC 10.1 NW Master Data loading SAP BPC 10.1 NW Master Data loading
SAP BPC 10.1 NW Master Data loading
 
Sap basis administration handbook
Sap basis administration handbookSap basis administration handbook
Sap basis administration handbook
 
Sap ecatt - mass data uploading
Sap ecatt -  mass data uploadingSap ecatt -  mass data uploading
Sap ecatt - mass data uploading
 
Ch03 supplement 1
Ch03 supplement 1Ch03 supplement 1
Ch03 supplement 1
 
05 conexão logo! 0 ba7 com ihm (wincc flexible)
05 conexão logo! 0 ba7 com ihm (wincc flexible)05 conexão logo! 0 ba7 com ihm (wincc flexible)
05 conexão logo! 0 ba7 com ihm (wincc flexible)
 
05 conexão logo! 0 ba7 com ihm (wincc flexible)
05 conexão logo! 0 ba7 com ihm (wincc flexible)05 conexão logo! 0 ba7 com ihm (wincc flexible)
05 conexão logo! 0 ba7 com ihm (wincc flexible)
 
Visual Logic User Guide
Visual Logic User GuideVisual Logic User Guide
Visual Logic User Guide
 
User exit training
User exit trainingUser exit training
User exit training
 
Change and Transport System (CTS) in SAP
Change and Transport System (CTS) in SAPChange and Transport System (CTS) in SAP
Change and Transport System (CTS) in SAP
 

Más de Milind Patil

Lecture16 abap on line
Lecture16 abap on lineLecture16 abap on line
Lecture16 abap on line
Milind Patil
 
Lecture14 abap on line
Lecture14 abap on lineLecture14 abap on line
Lecture14 abap on line
Milind Patil
 
Lecture13 abap on line
Lecture13 abap on lineLecture13 abap on line
Lecture13 abap on line
Milind Patil
 
Lecture12 abap on line
Lecture12 abap on lineLecture12 abap on line
Lecture12 abap on line
Milind Patil
 
Lecture11 abap on line
Lecture11 abap on lineLecture11 abap on line
Lecture11 abap on line
Milind Patil
 
Lecture10 abap on line
Lecture10 abap on lineLecture10 abap on line
Lecture10 abap on line
Milind Patil
 
Lecture09 abap on line
Lecture09 abap on lineLecture09 abap on line
Lecture09 abap on line
Milind Patil
 
Lecture08 abap on line
Lecture08 abap on lineLecture08 abap on line
Lecture08 abap on line
Milind Patil
 
Lecture07 abap on line
Lecture07 abap on lineLecture07 abap on line
Lecture07 abap on line
Milind Patil
 
Lecture06 abap on line
Lecture06 abap on lineLecture06 abap on line
Lecture06 abap on line
Milind Patil
 
Lecture05 abap on line
Lecture05 abap on lineLecture05 abap on line
Lecture05 abap on line
Milind Patil
 
Lecture04 abap on line
Lecture04 abap on lineLecture04 abap on line
Lecture04 abap on line
Milind Patil
 
Lecture03 abap on line
Lecture03 abap on lineLecture03 abap on line
Lecture03 abap on line
Milind Patil
 
Lecture02 abap on line
Lecture02 abap on lineLecture02 abap on line
Lecture02 abap on line
Milind Patil
 
Lecture01 abap on line
Lecture01 abap on lineLecture01 abap on line
Lecture01 abap on line
Milind Patil
 
Lecture15 abap on line
Lecture15 abap on lineLecture15 abap on line
Lecture15 abap on line
Milind Patil
 
Abap course chapter 6 specialities for erp software
Abap course   chapter 6 specialities for erp softwareAbap course   chapter 6 specialities for erp software
Abap course chapter 6 specialities for erp software
Milind Patil
 
Abap course chapter 5 dynamic programs
Abap course   chapter 5 dynamic programsAbap course   chapter 5 dynamic programs
Abap course chapter 5 dynamic programs
Milind Patil
 

Más de Milind Patil (18)

Lecture16 abap on line
Lecture16 abap on lineLecture16 abap on line
Lecture16 abap on line
 
Lecture14 abap on line
Lecture14 abap on lineLecture14 abap on line
Lecture14 abap on line
 
Lecture13 abap on line
Lecture13 abap on lineLecture13 abap on line
Lecture13 abap on line
 
Lecture12 abap on line
Lecture12 abap on lineLecture12 abap on line
Lecture12 abap on line
 
Lecture11 abap on line
Lecture11 abap on lineLecture11 abap on line
Lecture11 abap on line
 
Lecture10 abap on line
Lecture10 abap on lineLecture10 abap on line
Lecture10 abap on line
 
Lecture09 abap on line
Lecture09 abap on lineLecture09 abap on line
Lecture09 abap on line
 
Lecture08 abap on line
Lecture08 abap on lineLecture08 abap on line
Lecture08 abap on line
 
Lecture07 abap on line
Lecture07 abap on lineLecture07 abap on line
Lecture07 abap on line
 
Lecture06 abap on line
Lecture06 abap on lineLecture06 abap on line
Lecture06 abap on line
 
Lecture05 abap on line
Lecture05 abap on lineLecture05 abap on line
Lecture05 abap on line
 
Lecture04 abap on line
Lecture04 abap on lineLecture04 abap on line
Lecture04 abap on line
 
Lecture03 abap on line
Lecture03 abap on lineLecture03 abap on line
Lecture03 abap on line
 
Lecture02 abap on line
Lecture02 abap on lineLecture02 abap on line
Lecture02 abap on line
 
Lecture01 abap on line
Lecture01 abap on lineLecture01 abap on line
Lecture01 abap on line
 
Lecture15 abap on line
Lecture15 abap on lineLecture15 abap on line
Lecture15 abap on line
 
Abap course chapter 6 specialities for erp software
Abap course   chapter 6 specialities for erp softwareAbap course   chapter 6 specialities for erp software
Abap course chapter 6 specialities for erp software
 
Abap course chapter 5 dynamic programs
Abap course   chapter 5 dynamic programsAbap course   chapter 5 dynamic programs
Abap course chapter 5 dynamic programs
 

Último

Último (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 

Step bystep abap_changinga_singlerecord

  • 1. Updating Single Record (ABAP) 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. 1 of 31
  • 2. Updating Single Record (ABAP) Enter the Function Group (name) and Short Text (description.) 2 of 31
  • 3. Updating Single Record (ABAP) 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. 3 of 31
  • 4. Updating Single Record (ABAP) 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. 4 of 31
  • 5. Updating Single Record (ABAP) 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. 5 of 31
  • 6. Updating Single Record (ABAP) 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. 6 of 31
  • 7. Updating Single Record (ABAP) Accept the warning that may show as follows: 7 of 31
  • 8. Updating Single Record (ABAP) 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. 8 of 31
  • 9. Updating Single Record (ABAP) 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. 9 of 31
  • 10. Updating Single Record (ABAP) Create GUI Status (Menu) as shown below. 10 of 31
  • 11. Updating Single Record (ABAP) 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) 11 of 31
  • 12. Updating Single Record (ABAP) Delete all the following entries using button on the top menu, except the Cancel line and add the Code as shown Save the changes. 12 of 31
  • 13. Updating Single Record (ABAP) 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. 13 of 31
  • 14. Updating Single Record (ABAP) 14 of 31
  • 15. Updating Single Record (ABAP) Save the GUI Status. Now create GUI title 15 of 31
  • 16. Updating Single Record (ABAP) 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. 16 of 31
  • 17. Updating Single Record (ABAP) Enter Screen number as shown Click Continue button or hit enter. 17 of 31
  • 18. Updating Single Record (ABAP) Click on the Layout button (or Control + F7) 18 of 31
  • 19. Updating Single Record (ABAP) 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. 19 of 31
  • 20. Updating Single Record (ABAP) 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. 20 of 31
  • 21. Updating Single Record (ABAP) Do not convert any fields if requested (in this simple example.) Rearrange the fields as shown. Add 4 boxes around the groupings. 21 of 31
  • 22. Updating Single Record (ABAP) 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. 22 of 31
  • 23. Updating Single Record (ABAP) 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. 23 of 31
  • 24. Updating Single Record (ABAP) 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. 24 of 31
  • 25. Updating Single Record (ABAP) 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. 25 of 31
  • 26. Updating Single Record (ABAP) 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. 26 of 31
  • 27. Updating Single Record (ABAP) 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 *&---------------------------------------------------------------------* 27 of 31
  • 28. Updating Single Record (ABAP) 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. 28 of 31
  • 29. Updating Single Record (ABAP) Enter the program name and description. Click on Continue button or hit Enter. 29 of 31
  • 30. Updating Single Record (ABAP) Save - choose the appropriate package and workbench request. 30 of 31
  • 31. Updating Single Record (ABAP) Run the transaction. 31 of 31