Wednesday, April 20, 2011

Updating Material Master long text (BASIC DATA TEXT, INSPECTION TEXT and INTERNAL COMMENT)

This program could be used to upload the material master long text (Basic data text, inspection text, internal comment). Following is the screenshot from the transaction MM02.

We can achieve this functionality by using the Function Module ‘CREATE_TEXT’.

Please note that if the long text already exists, then it is overwritten in this case.

REPORT ZMM_INSERT_LONGTEXT.
*Internal table to hold long text...
DATA:
BEGIN OF T_UPLOAD OCCURS 0,
MATNR LIKE MARA-MATNR, " Material number
ID(2) TYPE C, " Identification
LTEXT LIKE TLINE-TDLINE, " Long text
END OF T_UPLOAD,
*Internal table to hold long text....
T_LINE LIKE TLINE OCCURS 0 WITH HEADER LINE.
DATA:
W_GRUN LIKE THEAD-TDID , " To hold id
W_OBJECT LIKE THEAD-TDOBJECT VALUE 'MATERIAL',
" To hold object id
LV_VALUE(70). " Value to hold material number
START-OF-SELECTION.
* This perform is used to upload the file
PERFORM UPLOAD_FILE.
* This perform is used to place the text in MM02 transaction
PERFORM PLACE_LONGTEXT.
*&---------------------------------------------------------------------*
*& Form create_text
*&---------------------------------------------------------------------*
* This routine used to create text in MM02 transaction
*----------------------------------------------------------------------*
* Passed the parameter w_grun to P_C_GRUN
* and lv_value to P_LV_VALUE
*----------------------------------------------------------------------*
FORM CREATE_TEXT USING P_C_GRUN
P_LV_VALUE.
  DATA:
L_ID LIKE THEAD-TDID,
L_NAME(70).
  MOVE : P_C_GRUN TO L_ID,
P_LV_VALUE TO L_NAME.
  CALL FUNCTION 'CREATE_TEXT'
EXPORTING
FID = L_ID
FLANGUAGE = SY-LANGU
FNAME = L_NAME
FOBJECT = W_OBJECT
* SAVE_DIRECT = 'X'
* FFORMAT = '*'
TABLES
FLINES = T_LINE
EXCEPTIONS
NO_INIT = 1
NO_SAVE = 2
OTHERS = 3
.
IF SY-SUBRC <> 0.
CLEAR LV_VALUE.
ELSE.
DELETE T_LINE INDEX 1.
ENDIF.
ENDFORM.                    " create_text
*&---------------------------------------------------------------------*
*& Form upload_file
*&---------------------------------------------------------------------*
* This routine is used to upload file
*----------------------------------------------------------------------*
* No interface parameters are passed
*----------------------------------------------------------------------*
FORM UPLOAD_FILE .
  CALL FUNCTION 'UPLOAD'
EXPORTING
* CODEPAGE = ' '
* FILENAME = ' '
FILETYPE = 'DAT'
* ITEM = ' '
* FILEMASK_MASK = ' '
* FILEMASK_TEXT = ' '
* FILETYPE_NO_CHANGE = ' '
* FILEMASK_ALL = ' '
* FILETYPE_NO_SHOW = ' '
* LINE_EXIT = ' '
* USER_FORM = ' '
* USER_PROG = ' '
* SILENT = 'S'
* IMPORTING
* FILESIZE =
* CANCEL =
* ACT_FILENAME =
* ACT_FILETYPE =
TABLES
DATA_TAB = T_UPLOAD
EXCEPTIONS
CONVERSION_ERROR = 1
INVALID_TABLE_WIDTH = 2
INVALID_TYPE = 3
NO_BATCH = 4
UNKNOWN_ERROR = 5
GUI_REFUSE_FILETRANSFER = 6
OTHERS = 7
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
  SORT T_UPLOAD BY MATNR ID.
ENDFORM.                    " upload_file
*&---------------------------------------------------------------------*
*& Form place_longtext
*&---------------------------------------------------------------------*
* This routine places the text in MM02 transaction
*----------------------------------------------------------------------*
* No interface parameters are passed
*----------------------------------------------------------------------*
FORM PLACE_LONGTEXT .
  LOOP AT T_UPLOAD.
    T_LINE-TDFORMAT = 'ST'.
T_LINE-TDLINE = T_UPLOAD-LTEXT.
APPEND T_LINE.
    IF T_UPLOAD-ID EQ 'BT'.
MOVE T_UPLOAD-MATNR TO LV_VALUE.
MOVE 'GRUN' TO W_GRUN. "Test ID for Basic data text
PERFORM CREATE_TEXT USING W_GRUN LV_VALUE.
ENDIF.
    IF T_UPLOAD-ID EQ 'IT'.
CLEAR W_GRUN.
MOVE T_UPLOAD-MATNR TO LV_VALUE.
MOVE 'PRUE' TO W_GRUN. "Test ID for Inspection text
PERFORM CREATE_TEXT USING W_GRUN LV_VALUE.
ENDIF.
    IF T_UPLOAD-ID EQ 'IC'.
CLEAR W_GRUN.
MOVE : T_UPLOAD-MATNR TO LV_VALUE,
'IVER' TO W_GRUN.
"Test ID for Internal comment
PERFORM CREATE_TEXT USING W_GRUN LV_VALUE.
ENDIF.
ENDLOOP.
ENDFORM.                    " place_longtext


Calling an RFC function module from one system to another

Following are the participant system for our demo purpose:

D05 – System where RFC function module exists

DS3 – Calling system (an RFC call is made from this system to D05)

Scenario:

We would develop a small RFC function module in D05 system, which would add two variables. We would pass two variables from DS3 to D05 and get back the sum of those two variables back to DS3.

Activities to be performed in the system D05

Go to SE37.

Under Utilities > Create Function Group (say ZGB_FUNC), if doesn’t exists.

Now create a New Function Module ZGB_FUNC01

Under IMPORT Tab, define the following variables

Under EXPORT Tab

In the Source Code

Now set the function module as “Remote-enabled module” in the attributes tab.

Activities to be performed in the System DS3

Create an RFC destination from DS3 to D05.

Go to SM59, Press Create.

Enter the RFC Destination name: D05-205-TEST

Connection Type: 3

In Description: Test Connection to D05

In The Technical Settings Tab, enter the system details

In The Logon/Security Tab, enter the logon details.

Click on Save. A Popup will imply that connection has been created

Now Press the TEST CONNECTION to check the connection.

This means the connection to the remote system was successful.

If the connection fails we get an error like this



However establishing a connection will not ensure logging on to the target system. For that we have to test REMOTE LOGON.

Press the REMOTE LOGON button

If we can see this

And this

Then our connection was successful.

However if we see the screen as shown below then there is an authentication failure (user-id or password is wrong).

The new connection will become visible in the SM59 list like this.

After establishing the connection, let us create a program, which would trigger the RFC in D05 system.

Go to SE38 and create a program ZGB_RFC

Write the following code

Activate (Ctrl+F3) and Execute (F8)

Type any two numbers.

Press (F8) Again. We have the desired output.




Object oriented programming (OOP) explained with an example

Create a class that keeps track of a bank account balance. Then write a program to use this class.

Steps involved:

  • Run the class builder utility (SE24).

  • Create a class called ZACCOUNTxx, where xx is the last two digits of your logon ID.

  • Declare a PRIVATE attribute BALANCE of type DMBTR to store the account balance.

  • Create the following PUBLIC methods:

    • SET_BALANCE (Sets the balance to a new value)

      • IMPORTING NEW_BALANCE TYPE DMBTR

    • DEPOSIT (Adds a deposit amount to the balance and returns the new balance)

      • IMPORTING AMOUNT TYPE DMBTR

      • RETURNING NEW_BALANCE TYPE DMBTR

    • WITHDRAW (Subtracts a deposit amount from the balance and returns the new balance.)

      • IMPORTING AMOUNT TYPE DMBTR

      • RETURNING NEW_BALANCE TYPE DMBTR

      • EXCEPTIONS INSUFFICIENT_FUNDS

  • Activate all elements of your class.

  • Write a program called Z_USE_ACCOUNT_xx, where xx is the last two digits of your logon ID. This program should do the following:

    • Instantiate an instance of the Account class.

    • Set the account balance to some initial value.

    • Make several deposits and withdrawals, printing the new balance each time. Do not allow the balance to become less than zero. (Use the exception to detect this.)

  • Test and debug your program.

"Extra Credit": If you have extra time, try any of the following:

  • Replace the SET_BALANCE method with a constructor. Pass the opening balance when you instantiate the account object.

  • Create a static attribute and methods to set and get the name of the bank that holds the accounts.

Step-by-step approach with screen-shots

Go to SE24 (Class builder)

Type in ZACCOUNTAA as the name of the class and press Create.

Define 3 methods DEPOSIT, SET_BALANCE and WITHDRAW.

Place the mouse cursor in DEPOSIT and hit the Parameters button.

Write the parameters imported / exported for DEPOSIT method.

Similarly for SET_BALANCE

And WITHDRAW

For withdraw we define an exception.

We can see the attributes and methods by pressing “Display object list” button on top.

Now we IMPLEMENT the 3 methods. Double click the method DEPOSIT.



Write the required code. Similarly for SET_BALANCE

Similarly for WITHDRAW.

Now we are almost done creating the object. Press CTRL + F3 to activate or hit the Matchstick.

We will see this in the status

Now we are done building the global class we can test it. Press F8.

Click SET_BALANCE. Write the NEW_BALANCE and press ENTER.

We come back to Initial Screen. Now click DEPOSIT.

We see the return Values now.

Now let’s WITHDRAW 4000

Now the BALANCE is 2000

Lets try withdrawing 3000 now.

We get an exception.

Given below is an example code for using the global class we defined.

REPORT ZGB_OOPS_BANK .

DATA: acct1 type ref to zaccountaa.

DATA: bal type i.

create object: acct1.

selection-screen begin of block a.
parameters: p_amnt type dmbtr,
p_dpst type dmbtr,
p_wdrw type dmbtr.
selection-screen end of block a.

start-of-selection.

call method acct1->set_balance( p_amnt ).
write:/ 'Set balance to ', p_amnt.

bal = acct1->deposit( p_dpst ).
write:/ 'Deposited ', p_dpst ,' bucks making balance to ', bal.

bal = acct1->withdraw( p_wdrw ).
write:/ 'Withdrew ', p_wdrw ,' bucks making balance to ', bal.

This is the output.




Creating F1 helps with ease

Go to SE61 and create a general text TX like the one shown below.

  • Select General Text from Document Class
  • Select Language
  • Type Name and press create

Type in what you want to see in output

U1 is for the Bold Text you see in the heading of the F1 Help. If you don’t want to specify a bold text you can just type it in the DOKTITLE in the function module called.

Save the Text.

Now Displaying the F1 Help. I have modified an existing program for showing F1 help. See below

*&---------------------------------------------------------------------*
*& Report ZGB_TEST_SEARCH_HELP *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*

REPORT  ZGB_TEST_SEARCH_HELP                    .
* INTERNAL TABLE FOR STORING NAMES IN SELECTION LIST
data: begin of t_itab occurs 0,
name(10) type c,
end of t_itab.
*FIELDNAME AND TAB NAME FOR THE SELECTION
DATA :field_tab LIKE dfies OCCURS 0 WITH HEADER LINE.
*THE TABLE FOR RETURNING THE NAME OF THE SELECTED ITEM
DATA : return_tab LIKE ddshretval OCCURS 0 WITH HEADER LINE.
*START THE SELECTION SCREEN BLOCK
selection-screen begin of block ss1 with frame.
parameters: p_name1(10) type c.
selection-screen end of block ss1.
*&---------------------------------------------------------------------*
*& *
*& F4 Help for p_name1 *
*&---------------------------------------------------------------------*
at selection-screen on value-request for p_name1.
*CLEAR ALL EXISTING DATA
*TO BE DONE EVERYTIME F4 HELP IS REQUESTED
REFRESH t_itab.
REFRESH field_tab.
field_tab-fieldname = 'ERNAM'.
field_tab-tabname = 'VBAK'.
APPEND field_tab.
t_itab-name = 'Andrews'.
append t_itab.
t_itab-name = 'Jennie'.
append t_itab.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
* DDIC_STRUCTURE = ' '
retfield = field_tab-fieldname
* PVALKEY = ' '
* DYNPPROG = ' '
* DYNPNR = ' '
* DYNPROFIELD = ' '
* STEPL = 0
WINDOW_TITLE = 'Select name'
* VALUE = ' '
* VALUE_ORG = 'C'
* MULTIPLE_CHOICE = ' '
* DISPLAY = ' '
* CALLBACK_PROGRAM = ' '
* CALLBACK_FORM = ' '
* MARK_TAB =
* IMPORTING
* USER_RESET =
tables
value_tab = t_itab
FIELD_TAB = field_tab
RETURN_TAB = return_tab
* DYNPFLD_MAPPING =
EXCEPTIONS
PARAMETER_ERROR = 1
NO_VALUES_FOUND = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
else.
p_name1 = return_tab-fieldval.
ENDIF.
*&---------------------------------------------------------------------*
*& *
*& F1 Help for p_name1 *
*&---------------------------------------------------------------------*
at selection-screen on help-request for p_name1.
CALL FUNCTION 'DSYS_SHOW_FOR_F1HELP'
EXPORTING
* APPLICATION = 'SO70'
dokclass = 'TX'
DOKLANGU = SY-LANGU
dokname = 'Z_GAURAB_DEMO'
* DOKTITLE = 'This appears as bold title'
* HOMETEXT = ' '
* OUTLINE = ' '
* VIEWNAME = 'STANDARD'
* Z_ORIGINAL_OUTLINE = ' '
* CALLED_FROM_SO70 = ' '
* SHORT_TEXT = ' '
* APPENDIX = ' '
* IMPORTING
* APPL =
* PF03 =
* PF15 =
* PF12 =
EXCEPTIONS
CLASS_UNKNOWN = 1
OBJECT_NOT_FOUND = 2
OTHERS = 3
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

Apart from the FM DSYS_SHOW_FOR_F1HELP,following FM’s can also be used:

  1. HELP_OBJECT_SHOW_FOR_FIELD
  2. HELP_OBJECT_SHOW

Here is the output




Dynamic Variant in a report

Scenario: This blog is to explain the creation of Dynamic Variant for report selection screen.

Let us understand ‘What is Dynamic Variant?’ Dynamic Variant consists of selection variable for a selection screen item where in a formula can be defined. For example: On the selection screen of a report, take a Date field, which needs to be dynamic. From Date should be ‘Current date – 15’ and To Date should be ‘Current Date’. In this way the report when run with this variant, it would be possible to retrieve all those records which are past 15 days entries from now.

Please find below the procedure to define DYNAMIC Variant.

Step 1: Go to transaction SE38 to specify the Program name and select ‘Variant’ radio button and ‘Display’.

Then it will lead you to next screen ‘ABAP:Variants –Initial Screen’ as shown below: Specify the variant which needs to be created or changed.

Step2: Specify all those values which are static on the selection screen in this step. Then click ‘Variant Attributes’ to define selection variable for ‘Date Created’ on the selection screen.

Step 3: In this step, provide suitable meaning for the variant. As we need to define selection variable for ‘Date created’ item on selection screen, check the box under L as shown in the selection screen below:

Step 4: In the previous step, select ‘Selection Variables’ on the menu. It leads to the next screen as shown below. As we have decided to create selection variable for ‘Date created’ item only, in this screen you get to see the variable as ‘Date created’. Here you are provided with three options.

T: Table variable from TVARV

D: Dynamic Date Calculation

B: User defined Variables.

From the provided options as per our requirement select ‘D’ option. This can be done by clicking the Traffic lights under ‘D’as shown below to know that the particular option is selected.

Now click the black arrow as shown in the screenshot below and you will be prompted with search help of different formulas for the selection variable.

Step 5: Find the suitable formula as ‘Current date – xxx, current date + yyy’ and select it. This will lead you to the next screen to enter the values for xxx and yyy. So, provide values as 15 for xxx and 0 for yyy. Save the variant and this will conclude the creation of dynamic variant with the help of selection variable. This variant can also be used in the background jobs.



Working with Menu Painter

For theoretical concepts on Menu Painter, please visit SAP.help.com

Create a program in SE38 T- Code.

Enter the Title of the Program And Select the Type as Executable Program.

And click on save. Save it in a Relevant Package.

Go to T-code SE41

Enter the Program name and Status name.

Click on create

Enter the Short text for Status.

Click on Menu Bar.

Specify a Menu Name file

Double click on File.

Enter the Code and text Values.

Click on save, check and Activate.

Press Execute or F8.

Click on Continue and Enter.

Created Menu is displayed here.



To create a Title, Click on Title List.

Click on create.

Enter the Title Code and Title. Click on continue.

Click on enter and Click on Test.

Enter the created Title Code in Title, Click on execute.

Click on Continue.

Created Title Displayed.

Click on Save.

*&---------------------------------------------------------------------*
*& Report ZMENU_PAINTER
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT  ZMENU_PAINTER.
TABLES: MARA.
DATA:  MATNR TYPE MARA-MATNR,
ERSDA TYPE MARA-ERSDA,
ERNAM TYPE MARA-ERNAM,
DISPLAY TYPE C,
SAVE TYPE C,
DELETE TYPE C,
CLEAR TYPE C,
EXIT TYPE C,
OK_CODE LIKE SY-UCOMM.
CALL SCREEN 101.
*&---------------------------------------------------------------------*
*& Module STATUS_0101 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0101 OUTPUT.
SET PF-STATUS 'ZMENU'.
SET TITLEBAR 'ZMENU_PAINTER'.
CASE SY-UCOMM.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'BACK'.
LEAVE PROGRAM.
WHEN 'DISPLAY'.
SELECT SINGLE ERSDA ERNAM FROM MARA INTO (MARA-ERSDA, MARA-ERNAM) WHERE MATNR = MARA-MATNR.
WHEN 'CLEAR'.
CLEAR MARA.
ENDCASE.
ENDMODULE.                 " STATUS_0101  OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0101 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0101 INPUT.
ENDMODULE.                 " USER_COMMAND_0101  INPUT

Click on middle Icon .

Enter MARA in the Table/Fieldname Text Box Then click on Get From Dictionary.

Select the require fields and click on continue.

Insert these boxes on the screen.

You can view like this after placing the boxes.


Create require Push buttons from toolbox.

Create require check box from toolbox.

Give the required Name , Text and Function Code Name .

Click on Save, Check and Activate.

Output:

Enter the Material number and Press Display.

Click on Display.

Values are displayed as shown below.

Similarly You Can View Clear And Exit.

Clear – It will clear all the displayed contents.

Exit - It will return to code..

We can Use the same operation in Function Keys.

  • F5 Clear
  • F6 Display
  • F7 Exit.

Enter the Material and Press F6 .

The same functionality F5 to Clear and F7 to Exit.


Tutorials on SAP-ABAP

Adobe Interactive Forms Tutorials

Business Server Pages (BSP)

Userexits/BADIs

Web Dynpro for ABAP (Step by step procedure for web dynpro,Tutorials on Web Dynpro,)

ALV Tutorials

Blog Archive

goodsites