Sei sulla pagina 1di 8

JAVA TO SAP..

import com.sap.mw.jco.*;
import java.sql.*;

/*
This statement is to import predefied classes from JCO into java for SAP connections
*/
public class JavaToSap
{
public static void main(String argv[]) throws Exception
{
JCO.Client client = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:oradsn","scott","tiger");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from emp");
String argdata ="";
if(rs.next())
{
argdata = rs.getString("JOB");
}
con.close();

client = JCO.createClient( "800", "sapuser", "oracle","EN", "sap3","00" );


client.connect(); // connects from Java to SAP
System.out.println("java is connected to SAP");
JCO.MetaData input_md = new JCO.MetaData("INPUT");
input_md.addInfo("DTA", JCO.TYPE_CHAR, 255, 255 * 2 ,-1, 0, null, null, 0, null,
null);
JCO.ParameterList input = JCO.createParameterList(input_md);
input.setValue(argdata, "DTA");
JCO.MetaData output_md = new JCO.MetaData("OUTPUT");
output_md.addInfo("RET", JCO.TYPE_CHAR,
255, 255 * 2 ,-1, 0, null, null, 0, null, null);
JCO.ParameterList output = JCO.createParameterList
(output_md);

client.execute("ZJAVAFM", input, output);

System.out.println("Even FM is executed");

for (int i = 0; i < output.getFieldCount(); i++)


{
System.out.println("Name: " + output.getNa
me(i) + " Value: " + output.getString(i));
}
System.out.println("Java is connected to
SAP with Data Communications");

}catch(Exception e)
{
System.out.println("error due to "+e);
}
}
}

28th MARCH---SELECTION SCREENS

PARAMETERS :
BEGIN OF LINE - END OF LINE.
SELECTION-SCREEN SKIP .
SELECTION-SCREEN ULINE.
SELECTION-SCREEN COMMENT.
SELECTION-SCREEN PUSHBUTTON.

BEGIN OF BLOCK SYNTAX:

SELECTION-SCREEN BEGIN OF BLOCK <NAME> [WITH FRAME [TITLE


<VAR>]].
ABAP GUI.
SELECTION-SCREEN END OF BLOCK <NAME>.

EXAMPLE CODE FOR BEGIN -END OF BLOCK.

SELECTION-SCREEN BEGIN OF BLOCK AAA WITH FRAME TITLE T1.


PARAMETERS : A TYPE I.
PARAMETERS : B TYPE I.
SELECTION-SCREEN END OF BLOCK AAA.
INITIALIZATION.
T1 = 'DIMENSION FIELDS'.

AS BLOCK NAME IS REPRESENTED WITH <NAME>, INTERNALLY ASSIGNED


WITH TYPE C. SO IT CAN ACCEPT CHARCTER OR EVEN NUMBERS.
SELECTION-SCREEN BEGIN OF SCREEN -
END OF SCREEN.

SYNTAX:
SELECTION-SCREEN BEGIN OF SCREEN <NUM> [AS WINDOW [TITLE <T1>]].
ABAP GUI STATEMENTS.
SELECTION-SCREEN END OF SCREEN <NUM>.

THIS SYNTAX IS USED TO GENERATE OWN SCREEN IN ABAP. WHEN EVER A


SCREEN IS CREATED BY ABAPER, WE NEED TO CALL SCREENS MANUALLY
USING "CALL SELECTION-SCREEN" STATEMENT.

DEMO EXAMPLE FOR BEGIN OF SCREEN - END OF SCREEN.


SELECTION-SCREEN BEGIN OF SCREEN 100.
PARAMETERS : KUNNR LIKE KNA1-KUNNR,
LAND1 LIKE KNA1-LAND1,
NAME1 LIKE KNA1-NAME1,
ORT01 LIKE KNA1-ORT01.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN PUSHBUTTON /10(10) LB1 USER-COMMAND PB1..
SELECTION-SCREEN END OF SCREEN 100.
SELECTION-SCREEN BEGIN OF SCREEN 200.
PARAMETERS : MATNR LIKE MARA-MATNR,
MBRSH LIKE MARA-MBRSH,
MTART LIKE MARA-MTART,
MEINS LIKE MARA-MEINS.
SELECTION-SCREEN END OF SCREEN 200.
CALL SELECTION-SCREEN 100.
INITIALIZATION.
LB1 = 'CALL MATERIAL'.
AT SELECTION-SCREEN.
CASE SY-UCOMM.
WHEN 'PB1'.
CALL SELECTION-SCREEN 200.
ENDCASE.

NOTE : WHEN EVER WE PERFORM ACTION USING "AT SELECTION-SCREEN"


BY DEFAULT WE CAN'T INVOKE LPS SCREEN.

DEMO EXAMPLE FOR INVOKING LPS USING SELECTION SCREEN


PUSHBUTTONS.

SELECTION-SCREEN PUSHBUTTON /10(10) LB1


USER-COMMAND PB1.
SELECTION-SCREEN PUSHBUTTON 30(10) LB2 USER-COMMAND PB2.
SELECTION-SCREEN PUSHBUTTON 50(10) LB3 USER-COMMAND PB3.

INITIALIZATION.
LB1 = 'ACTION1'.
LB2 = 'ACTION2'.
LB3 = 'EXIT'.
AT SELECTION-SCREEN.
CASE SY-UCOMM.
WHEN 'PB1'.
LEAVE TO LIST-PROCESSING.
WRITE : 'ACTION IS ON FIRST PUSHBUTTON'.
WHEN 'PB2'.
LEAVE TO LIST-PROCESSING.
WRITE : 'ACTION IS ON SECOND PUSHBUTTON'.
WHEN 'PB3'.
LEAVE PROGRAM.
ENDCASE.

USE FOLLOWINGATIONS TO CREATE A MESSAGE CLASS.

SE91 -> NAME THE MESSAGE CLASS ( ZMYCLS) -> CLICK ON CREATE ->
OPENS AN INTERFCAE -> CLICK ON MESSAGES TABBUTTON -> SAVE THE
MESSAGE CLASS UNDER A PACKAGE -> OPENS MESSAGES EDITOR WITH
MESSAGE ID(INDEX) AS "000" TO "999", ENTER REQUIRED MESSAGE IN
REQUIRED MESSAGE NUMBER -> SAVE THE MESSAGE CLASS.

NOTE: WHEN EVER MESSAGE CLASS IS SAVED , BY DEFAULT IS ACTIVATED.

THESE MESSAGES CAN BE INVOKE FROM SE38 PROGRAMS USING


"MESSAGE" STATEMENT.

MESSAGE TYPES.
MESSAGE <TYP><MSG_NUM>(MSG_CLASS).

WHERE <TYP> INDICATES MESSAGE TYPES.


I : INFORMATION MESSAGE.
W : WARNING MESSAGE
E : ERROR MESSAGE.
S : STATUSBAR MESSAGE.

A : ABORT OPENS A DIALOGBOX AND TERMANIATES THE PROGRAM


EXECUTION.

X : TERMNIATE : Generates Runtime Error with ABAP Runtime Analysis screen and
current program will be terminated.
EXAMPLE CODE WITH MESSAGES.
SELECTION-SCREEN PUSHBUTTON /10(10) LB1
USER-COMMAND PB1.
SELECTION-SCREEN PUSHBUTTON 30(10) LB2 USER-COMMAND PB2.
SELECTION-SCREEN PUSHBUTTON 50(10) LB3 USER-COMMAND PB3.
INITIALIZATION.
LB1 = 'ACTION1'.
LB2 = 'ACTION2'.
LB3 = 'EXIT'.
AT SELECTION-SCREEN.
CASE SY-UCOMM.
WHEN 'PB1'.
MESSAGE S001(ZMYCLS).
WHEN 'PB2'.
LEAVE TO LIST-PROCESSING.
MESSAGE E002(ZMYCLS).
WHEN 'PB3'.
LEAVE PROGRAM.
ENDCASE.

1st APRIL---STRING FUNCTIONS

STRLEN
SHIFT
SPLIT
SEARCH
CONDENSE
CONCATENATE
TRANSLATE
OVERLAY

REPLACE
is the string function used to replace the existing word with new string.
syntax:
replace <s1> with <s2> into str [length <len>].

example code to replace a string data with another.

DATA : STR(50) VALUE 'SD related Billing'.


write : str color 5.
replace 'SD' with 'Sales and Distribution' into str.
write: / str color 7.

note: this string function can replace the data only for once.
SECOND EXAMPLE: REPLACING ALL SEARCHING CHARACTERS WITH
DESTINGATION STRING EVEN IF REPEATED MULTIPLE TIMES.

data : STR(30) VALUE 'INDIA IS GREAT'.


DATA : LEN TYPE I.
LEN = STRLEN( STR ).
DATA : CNT TYPE I.
DO LEN TIMES.
REPLACE 'I' WITH 'G' INTO STR.
IF SY-SUBRC = 0.
CNT = CNT + 1.
ENDIF.
ENDDO.
WRITE : STR.
WRITE :/ 'DATA IS REPLACED FOR ', CNT , 'TIMES'.

LENGTH OPTION IN REPLACE STRING FUNCTION.

LENGTH OPTION IN REPLACE FUNCTION IS USED TO CONSIDER THE


SEARCHING STRING LENGTH.

DATA : STR(30) VALUE 'INDIA IS GREAT'.


REPLACE 'IS' WITH 'WAS' INTO STR LENGTH 1.
WRITE : STR.

OUTPUT: WASNDIA IS GREAT

FAQ : WHAT IS OUTPUT OF FOLLOWING.

DATA : STR(30) VALUE 'INDIA IS GREAT'.


REPLACE 'IS' WITH 'WAS' INTO STR LENGTH 5.
WRITE : STR.

IF THE LENGTH IS MORE THAN SEARCHING STRING LENGTH, CONSIDER


ONLY STRING LENGTH, INSTEAD OF LENGTH SPECIFIED IN REPLACE
STATEMENT.

OUTPUT: INDIA WAS GREAT

FAQ : WHAT IS OUTPUT OF FOLLOWING.

DATA : STR(30) VALUE 'INDIA IS GREAT'.


REPLACE 'IS' WITH 'WAS' INTO STR LENGTH 0.
WRITE : STR.
WHEN EVER STRING LENGTH IS SPECIFIED AS "0" IN REPLACE STATEMENT,
IN THE DESTINATION STRING "TARGET" STRING WILL CONCATENATED AT
"0" INDEX POSITION (STARTING POSITION).

OUTPUT: WASINDIA IS GREAT.

OFFSET FUNCTIONALITY.

STR+<OFF_POS>[(WIDTH)].

+ IS THE OPTION IS USED TO SPECIFY OFFSET FUNCTIONALITY FOR THE


STRINGS, ALONG WITH THIS OPTION <OFF_POS> IS MANDATORY, WHERE
AS WIDTH IS OPTIONAL. IF WE DON'T SPECIFY WIDTH DEFAULT TAKES ALL
CHARACTERS.

DEMO EXAMPLE.

DATA : STR(20) VALUE 'INDIA IS GREAT'.


*WRITE : STR+6. "OUTPUT : IS GREAT
*WRITE : STR+6(2)." IS
*WRITE : STR+9. " GREAT
WRITE : STR+0(5). " INDIA

WRITE FOLLOWING STATEMENT IN VERTICAL FORMAT AS


"YASH TECHNOLOGIES" AS

EXAMPLE CODE.
SET BLANK LINES ON.
DATA : STR(30) VALUE 'YASH TECHNOLOGIES'.
DATA : LEN TYPE I.
DATA : A TYPE I.
LEN = STRLEN( STR ).

DO LEN TIMES.
WRITE :/ STR+A(1).
A = A + 1.
ENDDO.
COUNTING THE CHARACTER IS FOUND FOR NUMBER OF TIMES.
PARAMETERS : CH.
DATA : STR(30) VALUE 'INDIA IS GREAT IN ALL'.
DATA : LEN TYPE I , A TYPE I.
LEN = STRLEN( STR ) .
DATA : CNT TYPE I.
DO LEN TIMES.
IF CH = STR+A(1).
CNT = CNT + 1.
ENDIF.
A = A + 1.
ENDDO.
IF CNT > 0.
WRITE: 'CHARACTER ', CH, ' IS REPEATED IN SRING FOR ', CNT , 'TIMES'.
ELSE.
WRITE : 'DATA NOT FOUND'.
ENDIF.