Anda di halaman 1dari 69

WorkIng wIth Check box (|odule pool programmIng)

By Vikram Chellappa, Mouri Tech Solutions


Scenario: We would design a screen with an input Iield Ior customer number and three check
boxes Ior Name, City and Address. Upon entering the customer number and selecting any oI the
check boxes, the corresponding data should be displayed
Go to Tcode SE38 .

Click on create and save the program. We would write the code later.
2 Go to Tcode SE5



n the Layout:
Drag and drop the fields as shown below. (The properties of each field can be seen on the right hand side
of the screenshot

Customer Number:

nput field:

Check box: Name

Check box: CTY

Check box: Address

!ush button: Display



!ush button: Cancel

3 Go to SE38.

Enter the following code:
*&---------------------------------------------------------------------*
*& Report ZDBM_MODULE_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPJRT zdbm_module_test.
DATA : kunnr TYPE kunnr,
name TYPE c,
city TYPE c,
address TYPE c,
ok_code LIKE sy-ucomm.

DATA : name1 TYPE name1,
ort01 TYPE ort01,
adrnr TYPE adrnr.

DATA : w_name1 TYPE name1,
w_ort01 TYPE ort01,
w_adrnr TYPE adrnr.

CALL SCREEN 100.

*&---------------------------------------------------------------------*
*& Module CHECK_VALUES INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MJDULE check_values INPUT.
IF ok_code EQ 'DISPLAY'.
LEAVE TJ LIST-PRJCESSING.
SELECT SINGLE name1 ort01 adrnr FRJM kna1 INTJ (w_name1, w_ort01, w_adrn
r) WHERE kunnr = kunnr.
IF NAME EQ 'X'.
WRITE : w_name1.
name1 = w_name1.
ENDIF.
IF CITY EQ 'X'.
WRITE : w_ort01.
ort01 = w_ort01.
ENDIF.
IF ADDRESS EQ 'X'.
adrnr = w_adrnr.
WRITE : w_adrnr.
ENDIF.
ELSEIF ok_code EQ 'CANCEL' JR ok_code EQ 'BACK'.
LEAVE PRJGRAM.
ENDIF.
ENDMJDULE. CHECK_VALUES INPUT
PBO OUTPUT

Execute the program


nsert data Into the database table usIng Classes


By Vikram Chellappa, Mouri Tech Solutions
o to Class Builder and create a new class

Provide the method name.

o to parameters and provide the attributes.

o back to methods. And provide the logic by double click on the method name.

Then save it, check it, activate it and execute it.


Press F8.
The data is stored in database.
To veriIy, go to VBAK table (SE16) and check whether the data is stored or not.

Now we will create a program using the above class Ior inserting the data into the database table.
o to SE38 and create a program.

Select create button.
AIter that provide the Iollowing logic.
---------------------------------------------------------------------
Report ZPG_INSERTINTJDB

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


---------------------------------------------------------------------
REPJRT ZPG_INSERTINTJDB.
provide the object for the class
DATA: JBJ_INSERT TYPE REF TJ ZCL_INSERTDB.
*provide parameters
PARAMETERS: V_VBELN TYPE VBELN,
V_ERDAT TYPE ERDAT,
V_ERZET TYPE ERZET.
*provide work area
DATA: WA TYPE VBAK.
*create the object
START-JF-SELECTIJN.
CREATE JBJECT JBJ_INSERT.
*provide insert method
CALL METHJD JBJ_INSERT-INSERT_DATA
*provide exporting parameters
EXPJRTING
P_VBELN = V_VBELN
P_ERDAT = V_ERDAT
P_ERZET = V_ERZET
*provide import parameters
IMPJRTING
WA_VBAK = WA.
*display the data.
WRITE:/ WA-VBELN,
WA-ERDAT,
WA-ERZET.
Save it , activate it, execute it .
The screen is like this.

Provide values.

Execute it.

Following is the sample output oI the same:

WorkIng wIth nterfaces


By Vikram Chellappa, Mouri Tech Solutions
n ABA! interfaces are implemented in addition to, and independently of classes. An interface only has a
declaration part, and do not have visibility sections. Components (Attributes, methods, constants, types can be
defined the same way as in classes.
O nterfaces are listed in the definition part of the class, and must always be in the !&BLC SECTON.
O Operations defined in the interface are implemented as methods of the class. All methods of the
interface must be present in the implementation part of the class.
O Attributes, events, constants and types defined in the interface are automatically available to the class
carrying out the implementation.
O nterface components are addressed in the class by <interface name>~<component name>
Go to SE24 provide interface name.
nterface name start with ZF_

!ress create button.



!rovide description.
Save it.

Save it.

!rovide the method name.

!rovide the parameters for this method.

The screen is like this.

Then save it, check it, activate it.


We cannot implement the method of this interface.
!rovide the name in the class.

Create it.

Save it.
Go to interface tab.
!rovide the interface name.

Save it.
Then go to the methods tab.
Then we can see the interface method name in the class method.

Then double click on the method then write the logic here.

Then save it, check it, activate it.


Create a program in SE38.

!rovide the code.
*&---------------------------------------------------*
*& Report ZCL_INTERFACE *
*&---------------------------------------------------*
REPJRT ZCL_INTERFACE .
*provide mara table
DATA: MARA TYPE MARA.
*provide data objects
DATA: JBJ TYPE REF TJ ZCL_INTERFACE,
IT_MARA TYPE Z_MARA,
WA_MARA TYPE MARA.
*provide selection screen
SELECT-JPTIJNS: S_MATNR FJR MARA-MATNR.
*provide object
START-JF-SELECTIJN.
CREATE JBJECT JBJ.
*call the method.
CALL METHJD JBJ-ZIF_INTERFACE~SELECT_METHJD
EXPJRTING
P_MATNR_LJW = S_MATNR-LJW
P_MATNR_HIGH = S_MATNR-HIGH
IMPJRTING
IT_MARA = IT_MARA
WA_MARA = WA_MARA.
*display the data
LJJP AT IT_MARA INTJ WA_MARA.
WRITE:/ WA_MARA-MATNR,
WA_MARA-ERSDA,
WA_MARA-ERNAM,
WA_MARA-MATKL,
WA_MARA-MEINS.
ENDLJJP.
Then save it, check it ,activate it then execute it the output is like this.

The output is see in the list.

What is the use of aIiases.
ALASES:
This is the aliases name. it is only for interfaces.
Go to se24.
Then go to aliases tab.
Then provide another name for the interface method.
Then provide public.
Save it, check it, activate it.

Then go to SE38.
Change the method name also.
*&---------------------------------------------------------------------*
*& Report ZCL_INTERFACE *
*& *
*&---------------------------------------------------------------------*
REPJRT ZCL_INTERFACE .
*provide mara table
DATA: MARA TYPE MARA.
*provide data objects
DATA: JBJ TYPE REF TJ ZCL_INTERFACE,
IT_MARA TYPE Z_MARA,
WA_MARA TYPE MARA.
*provide selection screen
SELECT-JPTIJNS: S_MATNR FJR MARA-MATNR.
*provide object
START-JF-SELECTIJN.
CREATE JBJECT JBJ.
*call the method.
* CALL METHOD OBJ->ZIF_INTERFACE~SELECT_METHOD
CALL METHJD JBJ-SEL
EXPJRTING
P_MATNR_LJW = S_MATNR-LJW
P_MATNR_HIGH = S_MATNR-HIGH
IMPJRTING
IT_MARA = IT_MARA
WA_MARA = WA_MARA.
*display the data
LJJP AT IT_MARA INTJ WA_MARA.
WRITE:/ WA_MARA-MATNR,
WA_MARA-ERSDA,
WA_MARA-ERNAM,
WA_MARA-MATKL,
WA_MARA-MEINS.
ENDLJJP.The output would be as shown below:.

Number Range Ub|ect


Suresh Kumar Parvathaneni
Creation of a Number range object:
.Go to transaction SNRO (Simple way to remember is SapNumberRangeObject.

2.Enter the number range object name and press CREATE.


3. Enter the description, Long text and Number Length domain andWarning % as shown
below:

Warning% Assume that an interval is defined from to . f you want to issue a warning at the number
9, enter (% here.
4.!ress SAVE. You would get a prompt as shown below:

5.!ress YES and assign the object to a local class.
6.Now click on "Number Ranges button on the application toolbar.

7.Click on "Change ntervals.


8.Click on "nsert nterval.
9.Enter the values as shown below:

.Click "nsert and then SAVE. The number range object is generated.
%esting the Number Range Object:
We can use the function module, N&MBER_GET_NEXT, to get the next number of any number
range object.
Following is a test program to get the next available number of the object created above:

REPJRT zsnro_test.

DATA: NUMBER TYPE I.

CALL FUNCTIJN 'NUMBER_GET_NEXT'
EXPJRTING
nr_range_nr = '01'
object = 'ZDEMJ'
IMPJRTING
NUMBER = NUMBER
EXCEPTIJNS
INTERVAL_NJT_FJUND = 1
NUMBER_RANGE_NJT_INTERN = 2
JBJECT_NJT_FJUND = 3
QUANTITY_IS_0 = 4
QUANTITY_IS_NJT_1 = 5
INTERVAL_JVERFLJW = 6
BUFFER_JVERFLJW = 7
JTHERS = 8
.
IF sy-subrc < 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNJ
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Write :/ 'Next available number is: ', Number.
-----------------------------------------------------------------------------
-----
$chedulIng background jobs
By Rahul Tyagi
Objective: Scheduling a background job in SA! R/3. These document intents to provide steps which can
be done even by an end user to prepare a Job.
Main Steps:
.Change screen layout of stock report as per the requirement.
2.Create variant to run the stock report (MB52 via Job.
3.Access transaction code SM36 to create the Job.
4.Monitor the Job and check the spool
5.Access SA! Business Work place to check the Spool.
Step: Create Screen layout
Assumption: Go to transaction MB52 and enter the value of the !lant (let's say .

Step : Create Variant along with the layout which we have created in previous step.
!ress F4 on the layout field in initial screen and then press save.

After selecting the layout here please click on save.


Step: !lease mention the variant name as per your choice and also mention the description.
You may also mark the check box protect variant for the field plant and layout though its not mandatory.
Previous

Save
Step: Finding the program name for transaction code MB52

Now please notice the !rogram name RM7MLBS.

Step: Log in transaction code SM36.
Mention the Job name as ZDaliystk_MB52_.

!ress enter to get the below screen

Click on the ABA! program and mention the program and also select the variant name which was
created in initial steps.


Click on check and save
Step : Now click on the start condition button.

n this step we are giving the frequency of running the job. As already mentioned the Job needs to run
daily basis.

click on the period values button and also mark the period check box as the job has to run every day.

Click on the spool recipient button

Just press enter and save to get the message that job is in release status

Monitor and check the output of job. Access transaction code SM37.
Also mention the Job name

execute and check the spool.

click on the type

Step: Here we are with the results which is list of stock in our case

%abstrIps on the $electIon $creen


By Sandipan Ghosh, Capgemini
Report ZTEST.
DATA flag(1) TYPE c.
* SUBSCREEN 1
SELECTIJN-SCREEN BEGIN JF SCREEN 100 AS SUBSCREEN.
SELECTIJN-SCREEN BEGIN JF BLJCK b1 WITH FRAME.
PARAMETERS: Field1(20) TYPE c,
Field2(20) TYPE c,
Field3(20) TYPE c.
SELECTIJN-SCREEN END JF BLJCK b1.
SELECTIJN-SCREEN END JF SCREEN 100.
* SUBSCREEN 2
SELECTIJN-SCREEN BEGIN JF SCREEN 200 AS SUBSCREEN.
SELECTIJN-SCREEN BEGIN JF BLJCK b2 WITH FRAME.
PARAMETERS: q1(20) TYPE c ,
q2(20) TYPE c ,
q3(20) TYPE c .
SELECTIJN-SCREEN END JF BLJCK b2.
SELECTIJN-SCREEN END JF SCREEN 200.
* STANDARD SELECTION SCREEN
SELECTIJN-SCREEN: BEGIN JF TABBED BLJCK mytab FJR 10 LINES,
TAB (20) button1 USER-CJMMAND push1,
TAB (20) button2 USER-CJMMAND push2,
END JF BLJCK mytab.
INITIALIZATIJN.
button1 = 'TAB1'.
button2 = 'TAB2'.
mytab-prog = sy-repid.
mytab-dynnr = 100.
mytab-activetab = 'BUTTJN1'.
AT SELECTIJN-SCREEN.
CASE sy-dynnr.
WHEN 1000.
CASE sy-ucomm.
WHEN 'PUSH1'.
mytab-dynnr = 100.
mytab-activetab = 'BUTTJN1'.
WHEN 'PUSH2'.
mytab-dynnr = 200.
mytab-activetab = 'BUTTJN2'.
ENDCASE.
WHEN 100.
MESSAGE s888(sabapdocu) WITH text-040 sy-dynnr.
WHEN 200.
MESSAGE s888(sabapdocu) WITH text-050 sy-dynnr.
ENDCASE.
MJDULE init_0100 JUTPUT.
LJJP AT SCREEN.
IF screen-group1 = 'MJD'.
CASE flag.
WHEN 'X'.
screen-input = '1'.
WHEN ' '.
screen-input = '0'.
ENDCASE.
MJDIFY SCREEN.
ENDIF.
ENDLJJP.
ENDMJDULE.
MJDULE user_command_0100 INPUT.
MESSAGE s888(sabapdocu) WITH text-050 sy-dynnr.
CASE sy-ucomm.
WHEN 'TJGGLE'.
IF flag = ' '.
flag = 'X'.
ELSEIF flag = 'X'.
flag = ' '.
ENDIF.
ENDCASE.
ENDMJDULE.
START-JF-SELECTIJN.
WRITE: / 'Field1:', Field1,'Q1:', q1,
/ 'Field2:', Field2,'Q2:', q2,
/ 'Field3:', Field3,'Q3:', q3.

@
@

&nderstandIng A8AP &nIt


By Nithya Murugesan, YASH Technologies
ntroduction:
It is a best practice to modularize our programs as much as we can Ior better programming. II we
want to check one particular module like subroutines, Iunction modules or classes Ior bugs then
we can do it using ABAP Unit. ABAP Unit is a tool Ior unit testing oI ABAP programs.
ow to write these tests:
ABAP unit is based on ABAP objects. The global class CLAUNITASSERT contains methods
which can be used Ior testing .Tests are implemented in local classes. Inside the local class the
necessary method Irom the global class can be called Ior testing. These test classes can be
written inside the program Ior which the test is to be done. It will not aIIect our production code
in anyways.
Difference between Ordinary class and Test class:
Both the test class and test method should have FOR TESTIN addition.
Ex:
CLASS mytest DEFINITION OR TEST.
PRIVATE SECTION.
METHODS mytest OR TEST.
ENDCLASS.
ethods in CL_AUT_ASSERT for Testing:
O ASSERTEQUALS
O ASSERTDIFFERS
O ASSERTBOUND
O ASSERTNOTBOUND
O ASSERTINITIAL
O ASSERTNOTINITIAL
O ASSERTCHARCP
O ASSERTCHARNP
O ASSERTEQUALSF
O FAIL
O ABORT
ASSERTEQUALS - Checks the equality oI two data objects.
ASSERTDIFFERS - Checks Ior the diIIerence oI two data objects.
ASSERTBOUND - checks Ior the validity oI the reIerence oI a reIerence variable.
ASSERTINITIAL - checks whether the reIerence oI a reIerence variable is invalid.
ASSERTNOTINITIAL - checks whether the data object is not having its initial value.
ASSERTSUBRC - checks Ior the speciIic value oI SY-SUBRC.
ASSERT_EQUALS:
ASSERTEQUALS is one oI the methods in the class CLAUNITASSERT. This method can
be used Ior checking equality oI two data objects.
The parameters oI the method:
ACT - Actual result
EXP - Expected Result
S - Message to be displayed in the result
LEVEL - Error level (Tolerable/Critical/Iatal)
QUT - II the test Iails, Ilow level is controlled using this
(NO/METHOD/CLASS/PRORAM)
TOL - Tolerance level Ior F
Levels:
O - Tolerable
O 1 - Critical
O - Fatal
Quit:
O No ( ) It will continue the current test Method.
O Method ( 1 ) It will interrupt the current test method
O Class ( ) It will interrupt the current test class.
O Program ( 3 ) abandon execution oI all test classes Ior the tested program.
Tolerance:
II the tolerance limit speciIied is exceeded then error is shown.
Ex:
Actual result .
Expected Result .
Tolerance 0.9999.
Difference = Expected Result - Actual result.
= 1 > tolerance.
Therefore displays an error.
Example Program:
Let us consider an example Ior ABAP unit test using the method ASSERTEQUALS to check
the equality oI two data objects. In this program, we have two methods divide and Iactorial in a
local class MATH. We want to test the Iactorial method. So we have created one class and one
method MYTEST Ior testing. In the test method implementation we have called the Iactorial
method and so the data object RESULT is populated. Now we are going to compare the actual
data object (RESULT) with the expected result. For that we are calling the ASSERTEQUALS
Irom the global class passing the expected result.
*----------------------------------------------------------------------*
* CLASS math DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS math DEFINITIJN.
PUBLIC SECTIJN.
METHJDS divide
IMPJRTING opr1 TYPE i
opr2 TYPE i
EXPJRTING result TYPE f
RAISING cx_sy_arithmetic_error.
METHJDS factorial
IMPJRTING n TYPE i
RETURNING value(fact) TYPE i.
ENDCLASS. math DEFINITION
*----------------------------------------------------------------------*
* CLASS math IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS math IMPLEMENTATIJN.
METHJD divide.
result = opr2 / opr1.
ENDMETHJD. divide
METHJD factorial.
fact = 1.
IF n = 0.
RETURN.
ELSE.
DJ n TIMES.
fact = fact sy-index.
ENDDJ.
ENDIF.
ENDMETHJD. 1actorial
ENDCLASS. math IMPLEMENTATION
START-JF-SELECTIJN.
DATA w_obj TYPE REF TJ math.
DATA exc TYPE REF TJ cx_sy_arithmetic_error.
DATA res TYPE f.
DATA result TYPE i.
DATA text TYPE string.
CREATE JBJECT w_obj.
TRY.
w_obj-divide( EXPJRTING opr1 = 32 opr2 = 4
IMPJRTING result = res ).
WRITE : res.
text = res.
CATCH cx_sy_arithmetic_error INTJ exc.
text = exc-get_text( ).
MESSAGE text TYPE 'I'.
ENDTRY.
CREATE JBJECT w_obj.
CJMPUTE result = w_obj-factorial( 4 ).
WRITE :/ 'The result for factorial is:',result.
*----------------------------------------------------------------------*
* CLASS mytest DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS mytest DEFINITIJN AU Risk_Level Harmless
FJR TESTING. AU Duration Short
PRIVATE SECTIJN.
METHJDS mytest FJR TESTING.
ENDCLASS. mytest DEFINITION
*----------------------------------------------------------------------*
* CLASS mytest IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS mytest IMPLEMENTATIJN.
METHJD mytest.
CREATE JBJECT w_obj.
result = w_obj-factorial( 4 ).
cl_aunit_assert=assert_equals( act = result
exp = '24'
msg = 'Factorial Not calculated Correc
tly'
level = '0'
quit = '2'
tol = '0.999'
).
ENDMETHJD. mytest
ENDCLASS. mytest IMPLEMENTATION
Executing Unit Tests:
or program,
Program -~ Test -~ Unit Test.
or class,
Class -~ Unit Test.
or unction odule,
Function Module -~ Test -~ Unit Test.
Result of Unit Test:
II both the actual and the expected result is same, then Unit test does not Iind any errors. In that
case one message will be displayed on status bar like,

II it Iinds errors then a result will be displayed as Iollows:

The task is displayed in a tree structure with a Program name, Class name and method name.
Both the expected and the actual results can be seen in the Unit test results. Also in the stack it
will be displaying the line number where the error occurred. By double clicking the line number
we can enter into the source code.
ABAP Unit results in Code nspector:
We can see the ABAP unit results in code inspector. While creating the variant, check Ior the
ABAP unit in Dynamic check.

In the Code inspector results we can check Ior the ABAP unit errors, warnings and inIormations.


---------------------------------------------------------------------------------------------------------------
evelopIng sImple InteractIve report
By Vikram Chellappa, Mouri Tech Solutions
REQUIREMEN% -
Get the !lant and storage location from the user and to get the available materials in the particular
storage location and display in a report.
When the material number in the report is selected the material description and other complete details are
displayed in a new screen using interactive report.
STE!S FOLLOWED TO ACHEVE THE GOAL:
Go to SE38 ABA! Editor create a new program.

Code the logic in the ABA! Editor.
Check Activate- and Execute the code.

Type in the Required !arameters or select a value from F4 Help Screen.

Execute the project



The Report is displayed in the output Screen.

Select a record using the mouse double click.

A new screen shows the output based on the selected record achieving the interactive reporting.

REPJRT ZG_JJP.
INITIALIZATIJN.
TYPES : BEGIN JF TY_MARD,
MATNR TYPE MARD-MATNR,
WERKS TYPE MARD-WERKS,
LGJRT TYPE MARD-LGJRT,
END JF TY_MARD,
BEGIN JF TY_MARA,
MATNR TYPE MARA-MATNR,
ERSDA TYPE MARA-ERSDA,
ERNAM TYPE MARA-ERNAM,
MTART TYPE MARA-MTART,
MATKL TYPE MARA-MATKL,
END JF TY_MARA,
BEGIN JF TY_MAKT,
MATNR TYPE MAKT-MATNR,
SPRAS TYPE MAKT-SPRAS,
MAKTX TYPE MAKT-MAKTX,
END JF TY_MAKT,
BEGIN JF TY_FINAL,
MATNR TYPE MARA-MATNR,
ERSDA TYPE MARA-ERSDA,
ERNAM TYPE MARA-ERNAM,
MTART TYPE MARA-MTART,
MATKL TYPE MARA-MATKL,
WERKS TYPE MARD-WERKS,
LGJRT TYPE MARD-LGJRT,
SPRAS TYPE MAKT-SPRAS,
MAKTX TYPE MAKT-MAKTX,
END JF TY_FINAL.
***** THE INITIALIZATION PART CREATING WORKAREA AND INTERNAL TABLE*****
DATA : W_MARD TYPE TY_MARD,
I_MARD TYPE TABLE JF TY_MARD,
W_MARA TYPE TY_MARA,
I_MARA TYPE TABLE JF TY_MARA,
W_MAKT TYPE TY_MAKT,
I_MAKT TYPE TABLE JF TY_MAKT,
W_FINAL TYPE TY_FINAL,
I_FINAL TYPE TABLE JF TY_FINAL.
**************************START-OF-SELECTION.**************************
START-JF-SELECTIJN.
*************************GET INPUT FROM USER***************************
PARAMETER : PLANT TYPE MARD-WERKS,
STLJC TYPE MARD-LGJRT.
****SELECT DATA FROM DATABASE INTO INTERNAL TABLES***********************
****SELECT FROM MARD THE REQUIRED FIELDS FOR THE GIVEN INPUT*************
SELECT MATNR
WERKS
LGJRT
FRJM MARD
INTJ TABLE I_MARD
WHERE WERKS = PLANT AND LGJRT = STLJC.
*****CHECK IF RECORDS ARE FETCHED IF NO EXIT OUT OF THE PROGRAM********
IF SY-SUBRC < 0.
WRITE 'NJ RECJRDS'.
EXIT.
ELSE.
***IF RECORDS ARE FETCHED FROM FRIST TABLE*****************************
****FETCH RELATED RECORDS FROM NEXT TABLE******************************
SELECT MATNR
ERSDA
ERNAM
MTART
MATKL
FRJM MARA
INTJ TABLE I_MARA
FJR ALL ENTRIES IN I_MARD
WHERE MATNR = I_MARD-MATNR.
IF SY-SUBRC < 0.
WRITE 'NJ MASTER DATA'.
STJP.
ELSE.
SELECT MATNR SPRAS MAKTX
FRJM MAKT
INTJ TABLE I_MAKT
FJR ALL ENTRIES IN I_MARA
WHERE MATNR = I_MARA-MATNR AND SPRAS = 'E'.
ENDIF.
ENDIF.
*****READ FROM INTERNAL TABLE FOR OUTPUT ******************************
LJJP AT I_MARA INTJ W_MARA.
AT FIRST.
WRITE : SY-ULINE(100),
/1 SY-VLINE,
25 'EXAMPLE INTERACTIVE REPJRT',
100 SY-VLINE,
/ SY-ULINE(100), /1 SY-VLINE,
2 'MATERIAL NUMBER' ,
20 SY-VLINE,
22 'CREATIJN DATE',
40 SY-VLINE,
42 'USER NAME',
60 SY-VLINE,
62 'MATERIAL TYPE',
80 SY-VLINE,
82 'MATERIAL GRJUP',
100 SY-VLINE,
/ SY-ULINE(100).
ENDAT.
JN CHANGE JF W_MARA-MATNR.
READ TABLE I_MARD INTJ W_MARD WITH KEY MATNR = W_MARA-MATNR.
ENDJN.
WRITE :/1 SY-VLINE,
2 W_MARA-MATNR ,
20 SY-VLINE,
22 W_MARA-ERSDA,
40 SY-VLINE,
42 W_MARA-ERNAM,
60 SY-VLINE,
62 W_MARA-MTART,
80 SY-VLINE,
82 W_MARA-MATKL,
100 SY-VLINE.
HIDE W_MARA-MATNR.
CLEAR W_MARA-MATNR.
WRITE: / SY-ULINE(100).
ENDLJJP.
END-JF-SELECTIJN.
*************************************END-OF-SELECTION.
****MOVING VALUES IN TO FINAL INTERNAL TABLE **************************
LJJP AT I_MARA INTJ W_MARA.
JN CHANGE JF W_MARA-MATNR.
READ TABLE I_MAKT INTJ W_MAKT WITH KEY MATNR = W_MARA-MATNR.
READ TABLE I_MARD INTJ W_MARD WITH KEY MATNR = W_MARA-MATNR.
ENDJN.
W_FINAL-MATNR = W_MARA-MATNR.
W_FINAL-ERSDA = W_MARA-ERSDA.
W_FINAL-ERNAM = W_MARA-ERNAM.
W_FINAL-MTART = W_MARA-MTART.
W_FINAL-MATKL = W_MARA-MATKL.
W_FINAL-WERKS = W_MARD-WERKS.
W_FINAL-LGJRT = W_MARD-LGJRT.
W_FINAL-SPRAS = W_MAKT-SPRAS.
W_FINAL-MAKTX = W_MAKT-MAKTX.
APPEND W_FINAL TJ I_FINAL.
ENDLJJP.
********AT LINE-SELECTION EVENT TRIGERING INTERACTIVE REPORTING.*******
AT LINE-SELECTIJN.
CASE SY-LSIND.
WHEN 1.
**DISPLAY OUTPUT IN NEW SCREEN AT LINE SELECTION BY USER MOUSE CLICK **
WRITE: / W_MARA-MATNR CJLJR 2.
READ TABLE I_FINAL INTJ W_FINAL WITH KEY MATNR = W_MARA-MATNR SPRAS = 'EN'.
ULINE 1(200).
WRITE : /1 SY-VLINE,
75 'EXAMPLE INTERACTIVE REPJRT',
200 SY-VLINE,
SY-ULINE(200),
/1 SY-VLINE,
2 'MATERIAL NUMBER' ,
20 SY-VLINE,
22 'CREATIJN DATE',
40 SY-VLINE,
42 'USER NAME',
60 SY-VLINE,
62 'MATERIAL TYPE',
80 SY-VLINE,
82 'MATERIAL GRJUP',
100 SY-VLINE,
102 'PLANT NUMBER',
120 SY-VLINE,
122 'STJRAG LJCATIJN',
140 SY-VLINE,
142 'LANGUAGE',
160 SY-VLINE,
162 'DESCRIPTIJN',
200 SY-VLINE,
/ SY-ULINE(200).
WRITE :/1 SY-VLINE,
2 W_FINAL-MATNR ,
20 SY-VLINE,
22 W_FINAL-ERSDA,
40 SY-VLINE,
42 W_FINAL-ERNAM,
60 SY-VLINE,
62 W_FINAL-MTART,
80 SY-VLINE,
82 W_FINAL-MATKL,
100 SY-VLINE,
102 W_FINAL-WERKS,
120 SY-VLINE,
122 W_FINAL-LGJRT,
140 SY-VLINE,
142 W_FINAL-SPRAS,
160 SY-VLINE,
162 W_FINAL-MAKTX,
200 SY-VLINE,
/ SY-ULINE(200).
CLEAR W_MARA-MATNR.
ENDCASE.
--------------------------------------------------------------------------
Create namIc $electIon $creen
By Marcos Munhos, C!M Braxis
escription
This is a demo application to make a dynamic screen in a report.
This change the parameters according a radio button choice:

st
moment - Click on the radio button ocaI
n the block "Enter Parameters", we'll have 2 parameters.

The parameter in the block "Path" is named as ocaI Path and the match code will lead you to a
File Open Dialog.

2
nd
moment - Click in the radio button Server
n the Enter Parameters, we'll have just parameter.

The parameter in the block "Path" is now named as Server Path and the field will be disabled.
Step b Step Approach
Create a new report.

n the SEEC%ION SCREEN put all the fields, blocks and parameters necessary, notice that in the radio
button have the addiction USER-COMMAN to enable the event A% SEEC%ION-SCREEN OU%PU%.

Look that in the Iock 2 we have the both parameters p_IocaI and p_sever, at the same time.

At this time the report is something like this:

Event A% SEEC%ION-SCREEN OU%PU%
n this event you can manipulate all the objects that appears in the screen using OOP A% SCREEN
changing the value of the structure screen the way you want . See below:

All this characteristics in the structure are possible to be changed:


NAME, GRO&!, GRO&!2, GRO&!3, GRO&!4, REQ&RED, N!&T, O&T!&T, NTENSFED,
NVSBLE, LENGTH, ACTVE, DS!LAY_3D, VAL&E_HEL!, REQ&EST, VAL&ES_N_COMBO and
COLOR.
Below we have the full source code of our example.
REPJRT zdynamic_screen.
* Published at SAPTechnical.com****************************************
* External Tables *
************************************************************************
TABLES: kna1.
****************************************************
* Internal Tables *
************************************************************************
DATA: i_filetable TYPE filetable.
************************************************************************
* Screen Parameters *
************************************************************************
* Begin - Block 1
SELECTIJN-SCREEN BEGIN JF BLJCK b1 WITH FRAME TITLE text-001.
PARAMETERS: r_local RADIJBUTTJN GRJUP rad1 USER-CJMMAND flg, Local
r_server RADIJBUTTJN GRJUP rad1 DEFAULT 'X'. Server* Begin -
Block 2
SELECTIJN-SCREEN BEGIN JF BLJCK b2 WITH FRAME TITLE text-002.
PARAMETER: p_local LIKE rlgrap-filename DEFAULT 'C:\' JBLIGATJRY.
PARAMETER: p_server LIKE rlgrap-filename DEFAULT '/default' JBLIGATJRY.
* End - Block 2
SELECTIJN-SCREEN END JF BLJCK b2.
* Begin - Block 3
SELECTIJN-SCREEN BEGIN JF BLJCK b3 WITH FRAME TITLE text-003.
SELECT-JPTIJNS: s_kunnr FJR kna1-kunnr, Customer Number 1
s_land1 FJR kna1-land1. Country Key
* End - Block 3
SELECTIJN-SCREEN END JF BLJCK b3.
* End - Block 1
SELECTIJN-SCREEN END JF BLJCK b1.
************************************************************************
* At Selection Screen OUTPUT *
************************************************************************
AT SELECTIJN-SCREEN JUTPUT.
* Check what radiobutton is selected
* Local
IF r_local = 'X'.
LJJP AT SCREEN.
IF screen-name = 'P_LOCAL'. OR
screen-name = '%_P_LJCAL_%_APP_%-TEXT'.
screen-invisible = '0'.
screen-input = '1'.
MJDIFY SCREEN. ELSEIF screen-name = 'P_SERVER'. OR
screen-name = '%_P_SERVER_%_APP_%-TEXT'.
screen-invisible = '1'.
screen-input = '0'.
MJDIFY SCREEN.
ENDIF.
ENDLJJP.
* Server
ELSE. LJJP AT SCREEN.
IF screen-name = 'P_SERVER' JR
screen-name = '%_P_SERVER_%_APP_%-TEXT'.
screen-invisible = '0'.
screen-input = '0'.
MJDIFY SCREEN.
ELSEIF screen-name = 'P_LJCAL' JR
screen-name = '%_P_LJCAL_%_APP_%-TEXT' JR
screen-name = '%_S_KUNNR_%_APP_%-TEXT' JR
screen-name = '%_S_KUNNR_%_APP_%-JPTI_PUSH' JR
screen-name = 'S_KUNNR-LJW' JR
screen-name = '%_S_KUNNR_%_APP_%-TJ_TEXT' JR
screen-name = 'S_KUNNR-HIGH' JR
screen-name = '%_S_KUNNR_%_APP_%-VALU_PUSH'. .
screen-invisible = '1'.
screen-input = '0'.
MJDIFY SCREEN.
ENDIF.
ENDLJJP.
ENDIF.
************************************************************************
* At Selection Screen ON VALUE REQUEST *
************************************************************************
AT SELECTIJN-SCREEN JN VALUE-REQUEST FJR p_local.
PERFJRM filename_local CHANGING p_local.
************************************************************************
START-JF-SELECTIJN.
************************************************************************
* Forms *
************************************************************************
*&---------------------------------------------------------------------*
*& Form 1ilename_local
*&---------------------------------------------------------------------*
*&
FJRM filename_local CHANGING p_file TYPE rlgrap-filename.
DATA: vl_rc TYPE i,
vl_action TYPE i.
* Open the File Open Dialog
CALL METHJD cl_gui_frontend_services=file_open_dialog
EXPJRTING
file_filter = ''
initial_directory = 'C:\'
CHANGING
file_table = i_filetable
rc = vl_rc
user_action = vl_action
EXCEPTIJNS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
JTHERS = 5.
IF sy-subrc < 0 JR vl_rc < 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
IF vl_action EQ cl_gui_frontend_services=action_ok.
CLEAR p_file.
READ TABLE i_filetable INDEX 1 INTJ p_file.
ENDIF.
ENDIF.
ENDFJRM. 1ilename_local
------------------------------------------------------------------------
emo on $earch help exIt for the materIal
By Naveen Kumar Kusuma, OpenText Technologies
Search help exits are used to restrict the standard search help returned values according to users'
requirement.
Example:
Scenario: When &ser require only Material type as Finished goods and &ser2 require only Material type
as Raw material, for this scenario we can use search help exit.
Go to SE, select the search help radio button.
To restrict the values for Material by Material type search help name is: MATT_E
Click on change button.

For this create a function module, write the logic according to the requirement and place the function
module in marked location.
Function module structure definition: Create a parameters in changing and Tables tabs as follows.

Write the following code in the source code tab.

Code:
DATA : WA_TEMP LIKE RECJRD_TAB,
IT_TEMP LIKE RECJRD_TAB JCCURS 0.
IF CALLCJNTRJL-STEP = 'DISP'.
IF SY-UNAME = 'XXXXXX'.
LJJP AT RECJRD_TAB INTJ WA_TEMP WHERE STRING+3(4) = 'FERT'.
APPEND WA_TEMP TJ IT_TEMP.
CLEAR: WA_TEMP.
ENDLJJP.
CLEAR: RECJRD_TAB,.
RECJRD_TAB, = IT_TEMP,.
CLEAR: IT_TEMP,.
ELSEIF SY-UNAME = 'YYYYYY'.
LJJP AT RECJRD_TAB INTJ WA_TEMP WHERE STRING+3(4) = 'RJH'.
APPEND WA_TEMP TJ IT_TEMP.
CLEAR: WA_TEMP.
ENDLJJP.
CLEAR: RECJRD_TAB,.
RECJRD_TAB, = IT_TEMP,.
CLEAR: IT_TEMP,.
ENDIF.
ENDIF.
Save and activate it.
Then place the Function module above location in SE.
Testing:
Go to any Transaction which has material number.
Ex: ME2N. !ress F4 on Material Field.
User1 ResuIt

User2 ResuIt

Anda mungkin juga menyukai