Friday, October 15, 2010
ABAP Programs : Using the events start-of-selection and end-of-selection
* Work area
TABLES BOOKINGS.
* Initial processing
START-OF-SELECTION.
WRITE / ‘Start’.
* Reading data
GET BOOKINGS.
WRITE: AT /3 BOOKINGS-FLDATE.
* Final processing
END-OF-SELECTION.
WRITE / ‘Finished’.
C program that uses the GUI automatization interface to implement automatic user login for sap
/* automation GUI interface to implement */
/* an automatic login feature. From release */
/* 3.1H SAP remouved it's similar function */
/* (slg_dll.exe, saplogin.exe), because of */
/* of security considerations. This program */
/* has a hardcoded password!! It would be */
/* adviseable to implement some encripting */
/* instead. */
#include
#include
#include "guilib.h"
int putt (char *strControlName);
int LogOff (HANDLE hHandle);
void main()
{
char Hostname[50];
char SystemID[5];
char Client[5];
char User[20];
char Passwd[20];
char Language[5];
HANDLE hHandle;
PIT_EVENT pEvt = 0;
strcpy (Hostname,"hostname");
strcpy (SystemID,"00");
strcpy (Client,"100");
strcpy (User,"UNAME");
strcpy (Passwd,"PASSWD");
strcpy (Language,"E");
hHandle = It_NewConnection(Hostname, SystemID, SAPGUI_FRONT);
It_Login (hHandle, Client, User, Passwd, Language );
while ( It_GetEvent(hHandle, &pEvt) )
{}
}
This ABAP rings the bell on any chosen pc, that has a sapgui connected to SAP
************************************************************************
* This program seds an audio alert to a specific user's frontend
* server. The program needs a pre-registered rfc program listening on
* every pc. The rfcexec can be started from the windows automatic
* startup like this:
* rfcexec -a100.100.100.100.rfcexec -ggatewayhostname -xsapgwXX
* ^ ^
* IP of the pc IP of the gateway host
************************************************************************
* Get the terminal, that belongs to the user
start-of-selection.
data: user value 'IMRE'.
DATA: OPCODE TYPE X VALUE 2.
DATA: BEGIN OF USR_TABL OCCURS 10.
INCLUDE STRUCTURE UINFO.
DATA: END OF USR_TABL.
CALL 'ThUsrInfo' ID 'OPCODE' FIELD OPCODE
ID 'TAB' FIELD USR_TABL-*SYS*.
* Get the corresponding IP address
data: arp_command(30) value '/usr/sbin/arp',
BEGIN OF TABL OCCURS 0,
LINE(200),
END OF TABL,
ip_address(100).
read table usr_tabl with key bname = 'IMRE'.
if sy-subrc <> 0. write: 'There is no such a user logged in'.
exit.endif.
arp_command+14 = usr_tabl-term.
CALL 'SYSTEM' ID 'COMMAND' FIELD arp_command
ID 'TAB' FIELD TABL-*SYS*.
read table tabl index 1.
shift tabl right up to ')'.
shift tabl right deleting trailing ')'.
shift tabl left up to '('.
shift tabl left deleting leading '('.
* Get the systems that has been registered on the gateway.
data: begin of connected_systems occurs 10.
include structure GWY_SYSTEm.
data: end of connected_systems.
call function 'GWY_READ_CONNECTED_SYSTEMS'
exporting
gwhost = 'optima'
gwserv = 'sapgw00'
tables
CONNECTED_SYSTEMS = CONNECTED_SYSTEMS.
* Get the registrated entry for the user's ip.
data: host_string(40).
loop at CONNECTED_SYSTEMS.
if CONNECTED_SYSTEMS-ADDR1 = tabl and
CONNECTED_SYSTEMS-SYSTYPE = 'REGISTER_TP'.
host_string = CONNECTED_SYSTEMS-tpname.
exit.
endif.
endloop.
if host_string is initial. write: 'No registered RFC server'.
exit.endif.
* Create a new destination in RFCDES
tables: rfcdes.
rfcdes-rfcdest = 'ZTTTT'.
rfcdes-rfctype = 'T'.
rfcdes-rfcoptions = 'H=%%RFCSERVER%%,N='.
rfcdes-rfcoptions+19 = host_string.
rfcdes-rfcoptions+59 = ','.
condense rfcdes-rfcoptions NO-GAPS.
modify rfcdes.
if sy-subrc <> 0. write: 'Unsuccessfull modification'.
exit. endif.
commit work.
* Call the alert with the new destination
DATA : BEGIN OF RET OCCURS 10,
TEXT(80),
END OF RET .
data: command(256) value
'sndrec32.exe /play /close c:/winnt/ringin.wav'.
CALL FUNCTION 'RFC_REMOTE_EXEC' DESTINATION 'ZTTTT'
EXPORTING
COMMAND = COMMAND
TABLES
PIPEDATA = RET.
* Delete the rfc destination
clear rfcdes.
select single * from rfcdes where rfcdest = 'ZTTTT'.
delete rfcdes.
if sy-subrc <> 0. write: 'Unsuccessfull delete'.
exit. endif.
commit work.
Method of displaying the hidden ABAPs of SAP - from the transport data files
************************************************************************
* The program reads a transport data file, and using some simple filters
* displays the contents. To see an abap source, first create a transport
* using se01 with an entry like: LIMU REPS SAPMSYST, then analyze it.
* This program does not handle data files bigger than 65535 bytes.
* I tested a slightly different version of this program as well, that
* changed some data in the data file, and imported it back - and it
* worked. But be careful with that, it can screw your system big time!
************************************************************************
* Get the filename
PARAMETERS: FILE(40) LOWER CASE OBLIGATORY
DEFAULT '/usr/sap/trans/data/R901111.ZZZ'.
* Find out the size of the transport file
DATA: L(132), F(50) VALUE '/tmp/azaz'.
DATA: FILT(56) VALUE 'ls -l'.
DATA: A, B(10) TYPE N.
FILT+6 = FILE.
OPEN DATASET F FOR OUTPUT IN TEXT MODE FILTER FILT.
CLOSE DATASET F.
OPEN DATASET F FOR INPUT IN TEXT MODE.
READ DATASET F INTO L.
IF SY-SUBRC <> 0. WRITE: / 'File does not exist'.EXIT. ENDIF.
DELETE DATASET F.
CONDENSE L.
SPLIT L AT ' ' INTO A A A A B A A A A.
IF B IS INITIAL OR B CN '0123456789 '.
WRITE: / 'File does not exist'.
ENDIF.
IF B > 65535.
WRITE: / 'File size is too big for this program'. EXIT.
ENDIF.
B = B - 11.
* Read an process the transport file
DATA: LL(65535) TYPE C.
DATA: I TYPE I, J TYPE I, K TYPE I.
DATA: X(11), Q(83), Y(3).
DATA: BEGIN OF STRUCC,
1(5), 2(1) TYPE X, 3(2), 4(3), 5(72),
END OF STRUCC.
OPEN DATASET FILE IN BINARY MODE FOR INPUT.
READ DATASET FILE INTO LL.
DO B TIMES.
I = SY-INDEX - 1.
X = LL+I.
IF X CP '+ ++++ +++'.
Y = X+2.
IF Y NA
' abcdefghijklmnopqrstxwz1234567890ABCDEFGHIJKLMNOPQRSTXWZ+=-/?*><'.
K = I - J.
Q = LL+J(K).
STRUCC = Q.
WRITE: / STRUCC-1, STRUCC-2, STRUCC-3, STRUCC-5.
J = I.
ENDIF.
ENDIF.
ENDDO.
abap program for Parallel processing: breaks a report to pieces and processes it parallel to reduce the run-time
************************************************************************
* This program implements parallel processing. Many time consuming
* report can be broken into equal pieces and run parallel, reducing
* the runtime (in this case searching for a string in the source code
* of a set of abaps). The main program (mother) creates CHILD_NU
* number of child programs(1-9),gives each of them a separate task, runs
* them parallel and then collects the end-result. The child program is
* actually embedded in the mother program, so the mother virtually
* gives birth of her children. A child that finished it's part, commits
* suicide: deletes itself at the end.
* Here is the result of a performonce test with 1-9 children processes
* for a light and a heavy task:
*
* children# light(Z* programs)(sec) heavy(R* programs)(sec)
* 1 51 664 100%
* 2 28 357
* 3 22 250
* 4 20 232
* 5 18 207 31%
* 6 19 209
* 7 18 219
* 8 21 202
* 9 20 211
*
* Conclusions:
* The performance starts to deteriorate when the children# exceeds a
* certain, task specific number (the children start to compete
* against each other for the same resources)
* The heavier the task - the more significant the performance gain.
************************************************************************
* The parent's data declaration
TABLES: TRDIR, TBTCO, INDX.
PARAMETERS: CHILD_NU TYPE I DEFAULT '3',
PATTERN(2) DEFAULT 'Z%'.
DATA: C,
CHILD(32) VALUE 'ZCHILD#',
JOBNAME(32),
ABAP_NAME(8).
DATA: BEGIN OF IV_TABLE OCCURS 10, "Table of intervals
LOW LIKE TRDIR-NAME,
HIGH LIKE TRDIR-NAME,
END OF IV_TABLE.
DATA: BEGIN OF ITAB OCCURS 500, "Table of program names
LINE(72),
END OF ITAB.
DATA: BEGIN OF CHILD_NAME_TAB OCCURS 10, "Table of the children's names
L(7), LL(23),
END OF CHILD_NAME_TAB.
DATA: BEGIN OF RESULT_TAB OCCURS 100, "The result of a single child
NAME LIKE TRDIR-NAME,
END OF RESULT_TAB.
DATA: BEGIN OF END_RESULT_TAB OCCURS 100, "The table of the end-results
NAME LIKE TRDIR-NAME,
END OF END_RESULT_TAB.
* Evenly distribute the work between the children
* With EXEC SQL it would be nicer, but less generic
DATA: INDEX TYPE I.
DATA: LINE_NUM TYPE I.
DATA: INTERVAL TYPE I.
DATA: BEGIN OF RANGE OCCURS 1000,
NAME LIKE TRDIR-NAME,
END OF RANGE.
* Timestamp
GET TIME. WRITE:/ SY-UZEIT. SKIP.
* Timestamp
SELECT * FROM TRDIR WHERE NAME LIKE PATTERN. "Fill up the range table
IF NOT TRDIR-NAME IS INITIAL.
RANGE = TRDIR-NAME.
APPEND RANGE.
ENDIF.
ENDSELECT.
SORT RANGE BY NAME.
DESCRIBE TABLE RANGE LINES LINE_NUM.
INTERVAL = LINE_NUM / CHILD_NU. "This will be the length of the
"working range of a single child
INDEX = 0.
DO. "Create the table of distinct ranges: 1 for each child
INDEX = INDEX + 1.
READ TABLE RANGE INDEX INDEX.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
IV_TABLE-LOW = RANGE-NAME.
INDEX = INDEX + INTERVAL.
READ TABLE RANGE INDEX INDEX.
IF SY-SUBRC <> 0.
INDEX = LINE_NUM.
READ TABLE RANGE INDEX INDEX.
IV_TABLE-HIGH = RANGE-NAME.
APPEND IV_TABLE.
EXIT.
ENDIF.
IV_TABLE-HIGH = RANGE-NAME.
APPEND IV_TABLE.
ENDDO.
* Create the children
DATA: NUM.
DO CHILD_NU TIMES. "Loop on the children
NUM = SY-INDEX. "The index of the child
CLEAR ITAB. REFRESH ITAB.
READ REPORT SY-REPID INTO ITAB.
LOOP AT ITAB.
C = ITAB+1(1).
IF C <> '@'. "Give birth of a child:
DELETE ITAB. "Filter it out from mamy's belly
ELSE.
SHIFT ITAB LEFT BY 2 PLACES.
MODIFY ITAB.
ENDIF.
ENDLOOP.
*
LOOP AT ITAB. "Give the child identity and a task to work on
REPLACE '#' WITH NUM INTO ITAB.
READ TABLE IV_TABLE INDEX NUM.
REPLACE '&' WITH IV_TABLE-LOW INTO ITAB.
IF SY-SUBRC = 0.MODIFY ITAB.CONTINUE.ENDIF.
REPLACE '$' WITH IV_TABLE-HIGH INTO ITAB.
MODIFY ITAB.
ENDLOOP.
*
CHILD+6(1) = NUM. "At last: create the child
INSERT REPORT CHILD FROM ITAB.
*
JOBNAME = CHILD. "Create a distinct job name to run the child in bg
JOBNAME+8(8) = SY-DATUM.
JOBNAME+16(8) = SY-UZEIT.
*
CHILD_NAME_TAB = JOBNAME. "Save the name of my wonderful child
APPEND CHILD_NAME_TAB.
*
PERFORM CREATE_A_CHILD_JOB. "Start the child
ENDDO.
* Wait for my children to complete their task and get the result
DO.
LOOP AT CHILD_NAME_TAB.
SELECT * FROM TBTCO WHERE JOBNAME = CHILD_NAME_TAB.
ENDSELECT.
IF TBTCO-STATUS = 'F' OR TBTCO-STATUS = 'A'.
REFRESH RESULT_TAB.
IMPORT RESULT_TAB FROM SHARED BUFFER INDX(ST) ID CHILD_NAME_TAB-L.
LOOP AT RESULT_TAB. "Merge the results in one single table
END_RESULT_TAB = RESULT_TAB.
APPEND END_RESULT_TAB.
ENDLOOP.
DELETE CHILD_NAME_TAB.
ENDIF.
ENDLOOP.
IF SY-SUBRC <> 0. EXIT. ENDIF.
ENDDO.
* Hooray, all the children are finished
LOOP AT END_RESULT_TAB.
WRITE: END_RESULT_TAB.
ENDLOOP.
* Timestamp
GET TIME. SKIP. WRITE:/ SY-UZEIT.
* Timestamp
* Schedule the child to run in background
FORM CREATE_A_CHILD_JOB.
DATA: JOBCOUNT LIKE TBTCJOB-JOBCOUNT.
ABAP_NAME = CHILD.
CALL FUNCTION 'JOB_OPEN'
EXPORTING
JOBNAME = JOBNAME
IMPORTING
JOBCOUNT = JOBCOUNT.
CALL FUNCTION 'JOB_SUBMIT'
EXPORTING
JOBNAME = JOBNAME
JOBCOUNT = JOBCOUNT
AUTHCKNAM = SY-UNAME
REPORT = ABAP_NAME.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
JOBNAME = JOBNAME
JOBCOUNT = JOBCOUNT
STRTIMMED = 'X'.
ENDFORM.
* Here is the child template in the mothers tummy:
*@program zchild#.
*@tables: trdir, indx.
*@data: begin of itab occurs 500,
*@ line(72),
*@end of itab.
*@data: begin of result_tab occurs 100,
*@ name like trdir-name,
*@end of result_tab.
*@data: string(20) value 'loadi'.
*@
*@select * from trdir where name between
*@'&'
*@and
*@'$'.
*@ read report trdir-name into itab.
*@ loop at itab.
*@ if itab-line cs string.
*@ write: trdir-name.
*@ result_tab = trdir-name.
*@ append result_tab.
*@ exit.
*@ endif.
*@ endloop.
*@endselect.
*@* Export the result to shared buffer
*@export result_tab to shared buffer INDX(ST) ID 'ZCHILD#'.
*@* The child commits a suicide after it has finished it's task
*@delete report 'ZCHILD#'.
Simple macro that prevents runnig more than one instance of the same ABAP the same time
ZCHK_MYSELF_RUNNING 001 *the one instance running the same time.
ZCHK_MYSELF_RUNNING 002 *Create this macro in TRMAC using SM31
ZCHK_MYSELF_RUNNING 003 *Insert the following single line in the
ZCHK_MYSELF_RUNNING 004 *program right after the REPORT state-
ZCHK_MYSELF_RUNNING 005 *ment: ZCHK_MYSELF_RUNNING SY-REPID.
ZCHK_MYSELF_RUNNING 010 DATA: PRG LIKE INDX-SRTFD. PRG = &1
ZCHK_MYSELF_RUNNING 011 CALL FUNCTION 'ENQUEUE_ESINDX' *
ZCHK_MYSELF_RUNNING 012 EXPORTING RELID = 'ZZ' *
ZCHK_MYSELF_RUNNING 013 SRTFD = PRG *
ZCHK_MYSELF_RUNNING 014 SRTF2 = 0 *
ZCHK_MYSELF_RUNNING 015 EXCEPTIONS FOREIGN_LOCK = 1 *
ZCHK_MYSELF_RUNNING 016 SYSTEM_FAILURE = 2
ZCHK_MYSELF_RUNNING 017 IF SY-SUBRC NE 0
ZCHK_MYSELF_RUNNING 018 WRITE: 'ERROR:',PRG,'is already running'
ZCHK_MYSELF_RUNNING 019 EXIT. ENDIF
abap Program to download/upload table data dynamically
This program allows the user to enter the table name and have the program download the data to a PC file.
Changing the radio button allows the user to upload the data to the specified table name.
Has function for append or clear/insert.
<>
*----------------------------------------------------------------------
* N Overton : Created ( T/Code ZTUD)
*
* Dynamic table export / import facility.
*
* Restrictions - Table definition MUST exist on target
* system for import.
* - Entire table is exported / imported
* - Must be WIN95/98 WIN-NT long filenames
*----------------------------------------------------------------------
* TEXTS
*
* List Header...: For SAP Table: &1............................
*
* Column Heading: | Function Status(48 spaces)# Records |
*
* Selection Texts: PATH Folder Path for file
* P_CLEAR Delete Existing Records
* P_EXP Export to PC File
* P_IMP Import from PC File
* TABNAME SAP table name
*
* Text Symbols: B00 Dynamic Import/Export of SAP data
* B01 SAP Table Name
* B02 Program Function
* B03 Folder For Data File
* B04 Existing Records Deletion Selection
* ER2 File not found. Please check.
* PGE Page
*----------------------------------------------------------------------
* This program once created will allow you to download or upload table
* data from any SAP table. It has the functionality to allow you to
* select whether data should be appended or original data cleaed before
* inserting new data.
* This is very useful when attempting to transfer data from one client
* to another
*----------------------------------------------------------------------
REPORT zsptud01 LINE-SIZE 80
LINE-COUNT 65
NO STANDARD PAGE HEADING.
TABLES: dd02l, dd03l.
* selection screen
SELECTION-SCREEN BEGIN OF BLOCK b00 WITH FRAME TITLE text-b00.
*
SELECTION-SCREEN BEGIN OF BLOCK b01 WITH FRAME TITLE text-b01.
PARAMETERS: tabname LIKE dd02l-tabname OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b01.
*
SELECTION-SCREEN BEGIN OF BLOCK b03 WITH FRAME TITLE text-b03.
PARAMETERS: path(30) TYPE c DEFAULT 'C:\SAPWorkdir'.
SELECTION-SCREEN END OF BLOCK b03.
*
SELECTION-SCREEN BEGIN OF BLOCK b04 WITH FRAME TITLE text-b04.
PARAMETERS: p_exp RADIOBUTTON GROUP radi,
p_imp RADIOBUTTON GROUP radi,
p_clear AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK b04.
SELECTION-SCREEN END OF BLOCK b00.
* data
DATA: q_return LIKE syst-subrc,
err_flag(1) TYPE c,
answer(1) TYPE c,
w_text1(62) TYPE c,
w_text2(40) TYPE c,
winfile(128) TYPE c,
w_system(40) TYPE c,
winsys(7) TYPE c,
zname(8) TYPE c,
w_line(80) TYPE c.
* internal tables
DATA : BEGIN OF textpool_tab OCCURS 0.
INCLUDE STRUCTURE textpool.
DATA : END OF textpool_tab.
* table for subroutine pool
DATA : itab(80) OCCURS 0.
* events
INITIALIZATION.
PERFORM check_system.
*
AT SELECTION-SCREEN ON tabname.
PERFORM check_table_exists.
*
START-OF-SELECTION.
PERFORM init_report_texts.
PERFORM request_confirmation.
*
END-OF-SELECTION.
IF answer = 'J'.
PERFORM execute_program_function.
ENDIF.
*
TOP-OF-PAGE.
PERFORM process_top_of_page.
* forms
*---------------------------------------------------------------------*
* FORM CHECK_TABLE_EXISTS *
*---------------------------------------------------------------------*
FORM check_table_exists.
SELECT SINGLE * FROM dd02l
INTO CORRESPONDING FIELDS OF dd02l
WHERE tabname = tabname.
CHECK syst-subrc NE 0.
MESSAGE e402(mo) WITH tabname.
ENDFORM.
*---------------------------------------------------------------------*
* FORM INIT_REPORT_TEXTS *
*---------------------------------------------------------------------*
FORM init_report_texts.
READ TEXTPOOL syst-repid
INTO textpool_tab LANGUAGE syst-langu.
LOOP AT textpool_tab
WHERE id EQ 'R' OR id EQ 'T'.
REPLACE '&1............................'
WITH tabname INTO textpool_tab-entry.
MODIFY textpool_tab.
ENDLOOP.
ENDFORM.
*---------------------------------------------------------------------*
* FORM REQUEST_CONFIRMATION *
*---------------------------------------------------------------------*
FORM request_confirmation.
* import selected, confirm action
IF p_imp = 'X'.
* build message text for popup
CONCATENATE 'Data for table'
tabname
'will be imported' INTO w_text1 SEPARATED BY space.
* check if delete existing selected, and change message text
IF p_clear = ' '.
w_text2 = 'and appended to the end of existing data'.
ELSE.
w_text2 = 'Existing Data will be deleted'.
ENDIF.
CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
EXPORTING
defaultoption = 'N'
textline1 = w_text1
textline2 = w_text2
titel = 'Confirm Import of Data'
cancel_display = ' '
IMPORTING
answer = answer
EXCEPTIONS
OTHERS = 1.
ELSE.
* export selected, set answer to yes so export can continue
answer = 'J'.
ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
* FORM EXECUTE_PROGRAM_FUNCTION *
*---------------------------------------------------------------------*
FORM execute_program_function.
PERFORM build_file_name.
CLEAR: q_return,err_flag.
IF p_imp = 'X'.
PERFORM check_file_exists.
CHECK err_flag = ' '.
PERFORM func_import.
ELSE.
PERFORM func_export.
ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
* FORM BUILD_FILE_NAME *
*---------------------------------------------------------------------*
FORM build_file_name.
MOVE path TO winfile.
WRITE '\' TO winfile+30.
WRITE tabname TO winfile+31.
WRITE '.TAB' TO winfile+61(4).
CONDENSE winfile NO-GAPS.
ENDFORM.
*---------------------------------------------------------------------*
* FORM CHECK_FILE_EXISTS *
*---------------------------------------------------------------------*
FORM check_file_exists.
CALL FUNCTION 'WS_QUERY'
EXPORTING
filename = winfile
query = 'FE'
IMPORTING
return = q_return
EXCEPTIONS
OTHERS = 1.
IF syst-subrc NE 0 OR q_return NE 1.
err_flag = 'X'.
ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
* FORM func_export *
*---------------------------------------------------------------------*
FORM func_export.
CLEAR itab. REFRESH itab.
APPEND 'PROGRAM SUBPOOL.' TO itab.
APPEND 'FORM DOWNLOAD.' TO itab.
APPEND 'DATA: BEGIN OF IT_TAB OCCURS 0.' TO itab.
CONCATENATE 'INCLUDE STRUCTURE'
tabname
'.' INTO w_line SEPARATED BY space.
APPEND w_line TO itab.
APPEND 'DATA: END OF IT_TAB.' TO itab.
CONCATENATE 'SELECT * FROM'
tabname
'INTO TABLE IT_TAB.' INTO w_line SEPARATED BY space.
APPEND w_line TO itab.
APPEND 'CALL FUNCTION ''WS_DOWNLOAD''' TO itab.
APPEND 'EXPORTING' TO itab.
CONCATENATE 'filename = ' ''''
winfile '''' INTO w_line SEPARATED BY space.
APPEND w_line TO itab.
APPEND 'filetype = ''DAT''' TO itab.
APPEND 'TABLES' TO itab.
APPEND 'DATA_TAB = IT_TAB.' TO itab.
APPEND 'DESCRIBE TABLE IT_TAB LINES sy-index.' TO itab.
APPEND 'FORMAT COLOR COL_NORMAL INTENSIFIED OFF.' TO itab.
APPEND 'WRITE: /1 syst-vline,' TO itab.
APPEND '''EXPORT'',' TO itab.
APPEND '15 ''data line(s) have been exported'',' TO itab.
APPEND '68 syst-index,' TO itab.
APPEND '80 syst-vline.' TO itab.
APPEND 'ULINE.' TO itab.
APPEND 'ENDFORM.' TO itab.
GENERATE SUBROUTINE POOL itab NAME zname.
PERFORM download IN PROGRAM (zname).
ENDFORM.
*---------------------------------------------------------------------*
* FORM func_import *
*---------------------------------------------------------------------*
FORM func_import.
CLEAR itab. REFRESH itab.
APPEND 'PROGRAM SUBPOOL.' TO itab.
APPEND 'FORM UPLOAD.' TO itab.
APPEND 'DATA: BEGIN OF IT_TAB OCCURS 0.' TO itab.
CONCATENATE 'INCLUDE STRUCTURE'
tabname
'.' INTO w_line SEPARATED BY space.
APPEND w_line TO itab.
APPEND 'DATA: END OF IT_TAB.' TO itab.
APPEND 'DATA: BEGIN OF IT_TAB2 OCCURS 0.' TO itab.
CONCATENATE 'INCLUDE STRUCTURE'
tabname
'.' INTO w_line SEPARATED BY space.
APPEND w_line TO itab.
APPEND 'DATA: END OF IT_TAB2.' TO itab.
APPEND 'CALL FUNCTION ''WS_UPLOAD''' TO itab.
APPEND 'EXPORTING' TO itab.
CONCATENATE 'filename = ' ''''
winfile '''' INTO w_line SEPARATED BY space.
APPEND w_line TO itab.
APPEND 'filetype = ''DAT''' TO itab.
APPEND 'TABLES' TO itab.
APPEND 'DATA_TAB = IT_TAB.' TO itab.
IF p_clear = 'X'.
CONCATENATE 'SELECT * FROM'
tabname
'INTO TABLE IT_TAB2.' INTO w_line SEPARATED BY space.
APPEND w_line TO itab.
APPEND 'LOOP AT IT_TAB2.' TO itab.
CONCATENATE 'DELETE'
tabname
'FROM IT_TAB2.' INTO w_line SEPARATED BY space.
APPEND w_line TO itab.
APPEND 'ENDLOOP.' TO itab.
APPEND 'COMMIT WORK.' TO itab.
ENDIF.
APPEND 'LOOP AT IT_TAB.' TO itab.
CONCATENATE 'MODIFY'
tabname
'FROM IT_TAB.' INTO w_line SEPARATED BY space.
APPEND w_line TO itab.
APPEND 'ENDLOOP.' TO itab.
APPEND 'DESCRIBE TABLE IT_TAB LINES sy-index.' TO itab.
APPEND 'FORMAT COLOR COL_NORMAL INTENSIFIED OFF.' TO itab.
APPEND 'WRITE: /1 syst-vline,' TO itab.
APPEND '''IMPORT'',' TO itab.
APPEND '15 ''data line(s) have been imported'',' TO itab.
APPEND '68 syst-index,' TO itab.
APPEND '80 syst-vline.' TO itab.
APPEND 'ULINE.' TO itab.
APPEND 'ENDFORM.' TO itab.
GENERATE SUBROUTINE POOL itab NAME zname.
PERFORM upload IN PROGRAM (zname).
ENDFORM.
*---------------------------------------------------------------------*
* Form CHECK_SYSTEM
* Check users workstation is running
* WINDOWS 95, or WINDOWS NT.
* OS/2 uses 8.3 file names which are no good for
* this application as filenames created are 30 char
* same as table name.
* You could change the logic to only use the first 8 chars
* of the table name for the filename, but you could possibly
* get problems if users had exported already with a table
* with the same first 8 chars.
* As an alternate method you could request the user to input
* the full path including filename and remove the logic to
* build the path using the table name.
*---------------------------------------------------------------------*
FORM check_system.
CALL FUNCTION 'WS_QUERY'
EXPORTING
query = 'WS'
IMPORTING
return = winsys.
IF winsys NE 'WN32_95'.
WRITE: 'Windows NT or Windows 95/98 is required'.
EXIT.
ENDIF.
ENDFORM. " CHECK_SYSTEM
*---------------------------------------------------------------------*
* FORM PROCESS_TOP_OF_PAGE *
*---------------------------------------------------------------------*
FORM process_top_of_page.
FORMAT COLOR COL_HEADING INTENSIFIED ON.
ULINE.
CONCATENATE syst-sysid
syst-saprl
syst-host INTO w_system SEPARATED BY space.
WRITE : AT /1(syst-linsz) w_system CENTERED.
WRITE : AT 1 syst-vline, syst-uname.
syst-linsz = syst-linsz - 11.
WRITE : AT syst-linsz syst-repid(008).
syst-linsz = syst-linsz + 11.
WRITE : AT syst-linsz syst-vline.
LOOP AT textpool_tab WHERE id EQ 'R'.
WRITE : AT /1(syst-linsz) textpool_tab-entry CENTERED.
ENDLOOP.
WRITE : AT 1 syst-vline, syst-datum.
syst-linsz = syst-linsz - 11.
WRITE : AT syst-linsz syst-tcode(004).
syst-linsz = syst-linsz + 11.
WRITE : AT syst-linsz syst-vline.
LOOP AT textpool_tab WHERE id EQ 'T'.
WRITE : AT /1(syst-linsz) textpool_tab-entry CENTERED.
ENDLOOP.
WRITE : AT 1 syst-vline, syst-uzeit.
syst-linsz = syst-linsz - 11.
WRITE : AT syst-linsz 'Page', syst-pagno.
syst-linsz = syst-linsz + 11.
WRITE : AT syst-linsz syst-vline.
ULINE.
FORMAT COLOR COL_HEADING INTENSIFIED OFF.
LOOP AT textpool_tab WHERE id EQ 'H'.
WRITE : AT /1(syst-linsz) textpool_tab-entry.
ENDLOOP.
ULINE.
ENDFORM.
Create/Modify/Delete records in any table from CSV file in sap
Allows to create, modify or delete records based on data coming from a CSV file. No other format than CSV is allowed. A check is done on field names to be sure every key field is present in source file. This file must contain header with fields names corresponding to the DDIC (fields names must be comma separated too). Some system fields can be updated too. Test run uses a true MODIFY / DELETE statement but is followed by a Rollback.
REPORT csv_upload LINE-SIZE 255.
* Data
DATA: it_dd03p TYPE TABLE OF dd03p,
is_dd03p TYPE dd03p.
DATA: it_rdata TYPE TABLE OF text1024,
is_rdata TYPE text1024.
DATA: it_fields TYPE TABLE OF fieldname.
DATA: it_file TYPE REF TO data,
is_file TYPE REF TO data.
DATA: w_error TYPE text132.
* Macros
DEFINE write_error.
concatenate 'Error: table'
p_table
&1
&2
into w_error
separated by space.
condense w_error.
write: / w_error.
stop.
END-OF-DEFINITION.
* Field symbols
FIELD-SYMBOLS:
TYPE ANY,
* Selection screen
SELECTION-SCREEN: BEGIN OF BLOCK b01 WITH FRAME TITLE text-b01.
PARAMETERS: p_file TYPE localfile DEFAULT 'C:\temp\' OBLIGATORY,
p_separ TYPE c DEFAULT ';' OBLIGATORY.
SELECTION-SCREEN: END OF BLOCK b01.
SELECTION-SCREEN: BEGIN OF BLOCK b02 WITH FRAME TITLE text-b02.
PARAMETERS: p_table TYPE tabname OBLIGATORY
MEMORY ID dtb
MATCHCODE OBJECT dd_dbtb_16.
SELECTION-SCREEN: END OF BLOCK b02.
SELECTION-SCREEN: BEGIN OF BLOCK b03 WITH FRAME TITLE text-b03.
PARAMETERS: p_create TYPE c AS CHECKBOX.
SELECTION-SCREEN: END OF BLOCK b03,
SKIP.
SELECTION-SCREEN: BEGIN OF BLOCK b04 WITH FRAME TITLE text-b04.
PARAMETERS: p_nodb RADIOBUTTON GROUP g1 DEFAULT 'X'
USER-COMMAND rg1,
p_save RADIOBUTTON GROUP g1,
p_dele RADIOBUTTON GROUP g1.
SELECTION-SCREEN: SKIP.
PARAMETERS: p_test TYPE c AS CHECKBOX,
p_list TYPE c AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN: END OF BLOCK b04.
* At selection screen
AT SELECTION-SCREEN.
IF sy-ucomm = 'RG1'.
IF p_nodb IS INITIAL.
p_test = 'X'.
ENDIF.
ENDIF.
* At selection screen
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
* Start of selection
START-OF-SELECTION.
PERFORM f_table_definition USING p_table.
PERFORM f_upload_data USING p_file.
PERFORM f_prepare_table USING p_table.
PERFORM f_process_data.
IF p_nodb IS INITIAL.
PERFORM f_modify_table.
ENDIF.
IF p_list = 'X'.
PERFORM f_list_records.
ENDIF.
* End of selection
END-OF-SELECTION.
*---------------------------------------------------------------------*
* FORM f_table_definition *
*---------------------------------------------------------------------*
* --> VALUE(IN_TABLE) *
*---------------------------------------------------------------------*
FORM f_table_definition USING value(in_table).
DATA: l_tname TYPE tabname,
l_state TYPE ddgotstate,
l_dd02v TYPE dd02v.
l_tname = in_table.
CALL FUNCTION 'DDIF_TABL_GET'
EXPORTING
name = l_tname
IMPORTING
gotstate = l_state
dd02v_wa = l_dd02v
TABLES
dd03p_tab = it_dd03p
EXCEPTIONS
illegal_input = 1
OTHERS = 2.
IF l_state NE 'A'.
write_error 'does not exist or is not active' space.
ENDIF.
IF l_dd02v-tabclass NE 'TRANSP' AND
l_dd02v-tabclass NE 'CLUSTER'.
write_error 'is type' l_dd02v-tabclass.
ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
* FORM f_prepare_table *
*---------------------------------------------------------------------*
* --> VALUE(IN_TABLE) *
*---------------------------------------------------------------------*
FORM f_prepare_table USING value(in_table).
DATA: l_tname TYPE tabname,
lt_ftab TYPE lvc_t_fcat.
l_tname = in_table.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = l_tname
CHANGING
ct_fieldcat = lt_ftab
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
WRITE: / 'Error while building field catalog'.
STOP.
ENDIF.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_ftab
IMPORTING
ep_table = it_file.
ASSIGN it_file->* TO
CREATE DATA is_file LIKE LINE OF
ASSIGN is_file->* TO .
ENDFORM.
*---------------------------------------------------------------------*
* FORM f_upload_data *
*---------------------------------------------------------------------*
* --> VALUE(IN_FILE) *
*---------------------------------------------------------------------*
FORM f_upload_data USING value(in_file).
DATA: l_file TYPE string,
l_ltext TYPE string.
DATA: l_lengt TYPE i,
l_field TYPE fieldname.
DATA: l_missk TYPE c.
l_file = in_file.
l_lengt = strlen( in_file ).
FORMAT INTENSIFIED ON.
WRITE: / 'Reading file', in_file(l_lengt).
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = l_file
filetype = 'ASC'
TABLES
data_tab = it_rdata
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
WRITE: /3 'Error uploading', l_file.
STOP.
ENDIF.
* File not empty
DESCRIBE TABLE it_rdata LINES sy-tmaxl.
IF sy-tmaxl = 0.
WRITE: /3 'File', l_file, 'is empty'.
STOP.
ELSE.
WRITE: '-', sy-tmaxl, 'rows read'.
ENDIF.
* File header on first row
READ TABLE it_rdata INTO is_rdata INDEX 1.
l_ltext = is_rdata.
WHILE l_ltext CS p_separ.
SPLIT l_ltext AT p_separ INTO l_field l_ltext.
APPEND l_field TO it_fields.
ENDWHILE.
IF sy-subrc = 0.
l_field = l_ltext.
APPEND l_field TO it_fields.
ENDIF.
* Check all key fields are present
SKIP.
FORMAT RESET.
FORMAT COLOR COL_HEADING.
WRITE: /3 'Key fields'.
FORMAT RESET.
LOOP AT it_dd03p INTO is_dd03p WHERE NOT keyflag IS initial.
WRITE: /3 is_dd03p-fieldname.
READ TABLE it_fields WITH KEY table_line = is_dd03p-fieldname
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
FORMAT COLOR COL_POSITIVE.
WRITE: 'ok'.
FORMAT RESET.
ELSEIF is_dd03p-datatype NE 'CLNT'.
FORMAT COLOR COL_NEGATIVE.
WRITE: 'error'.
FORMAT RESET.
l_missk = 'X'.
ENDIF.
ENDLOOP.
* Log other fields
SKIP.
FORMAT COLOR COL_HEADING.
WRITE: /3 'Other fields'.
FORMAT RESET.
LOOP AT it_dd03p INTO is_dd03p WHERE keyflag IS initial.
WRITE: /3 is_dd03p-fieldname.
READ TABLE it_fields WITH KEY table_line = is_dd03p-fieldname
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
WRITE: 'X'.
ENDIF.
ENDLOOP.
* Missing key field
IF l_missk = 'X'.
SKIP.
WRITE: /3 'Missing key fields - no further processing'.
STOP.
ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
* FORM f_process_data *
*---------------------------------------------------------------------*
FORM f_process_data.
DATA: l_ltext TYPE string,
l_stext TYPE text40,
l_field TYPE fieldname,
l_datat TYPE c.
LOOP AT it_rdata INTO is_rdata FROM 2.
l_ltext = is_rdata.
LOOP AT it_fields INTO l_field.
ASSIGN COMPONENT l_field OF STRUCTURE TO
IF sy-subrc = 0.
* Field value comes from file, determine conversion
DESCRIBE FIELD
CASE l_datat.
WHEN 'N'.
SPLIT l_ltext AT p_separ INTO l_stext l_ltext.
WRITE l_stext TO
OVERLAY
WHEN 'P'.
SPLIT l_ltext AT p_separ INTO l_stext l_ltext.
TRANSLATE l_stext USING ',.'.
WHEN 'F'.
SPLIT l_ltext AT p_separ INTO l_stext l_ltext.
TRANSLATE l_stext USING ',.'.
WHEN 'D'.
SPLIT l_ltext AT p_separ INTO l_stext l_ltext.
TRANSLATE l_stext USING '/.-.'.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
date_external = l_stext
IMPORTING
date_internal =
EXCEPTIONS
OTHERS = 1.
WHEN 'T'.
CALL FUNCTION 'CONVERT_TIME_INPUT'
EXPORTING
input = l_stext
IMPORTING
output =
EXCEPTIONS
OTHERS = 1.
WHEN OTHERS.
SPLIT l_ltext AT p_separ INTO
ENDCASE.
ELSE.
SHIFT l_ltext UP TO p_separ.
SHIFT l_ltext.
ENDIF.
ENDLOOP.
IF NOT IS INITIAL.
LOOP AT it_dd03p INTO is_dd03p WHERE datatype = 'CLNT'.
* This field is mandant
ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE
TO
ENDLOOP.
IF p_create = 'X'.
IF is_dd03p-rollname = 'ERDAT'.
ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE
TO
ENDIF.
IF is_dd03p-rollname = 'ERZET'.
ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE
TO
ENDIF.
IF is_dd03p-rollname = 'ERNAM'.
ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE
TO
ENDIF.
ENDIF.
IF is_dd03p-rollname = 'AEDAT'.
ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE
TO
ENDIF.
IF is_dd03p-rollname = 'AETIM'.
ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE
TO
ENDIF.
IF is_dd03p-rollname = 'AENAM'.
ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE
TO
ENDIF.
APPEND TO
ENDIF.
ENDLOOP.
ENDFORM.
*---------------------------------------------------------------------*
* FORM f_modify_table *
*---------------------------------------------------------------------*
FORM f_modify_table.
SKIP.
IF p_save = 'X'.
MODIFY (p_table) FROM TABLE
ELSEIF p_dele = 'X'.
DELETE (p_table) FROM TABLE
ELSE.
EXIT.
ENDIF.
IF sy-subrc EQ 0.
FORMAT COLOR COL_POSITIVE.
IF p_save = 'X'.
WRITE: /3 'Modify table OK'.
ELSE.
WRITE: /3 'Delete table OK'.
ENDIF.
FORMAT RESET.
IF p_test IS INITIAL.
COMMIT WORK.
ELSE.
ROLLBACK WORK.
WRITE: '- test only, no update'.
ENDIF.
ELSE.
FORMAT COLOR COL_NEGATIVE.
WRITE: /3 'Error while modifying table'.
FORMAT RESET.
ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
* FORM f_list_records *
*---------------------------------------------------------------------*
FORM f_list_records.
DATA: l_tleng TYPE i,
l_lasti TYPE i,
l_offst TYPE i.
* Output width
l_tleng = 1.
LOOP AT it_dd03p INTO is_dd03p.
l_tleng = l_tleng + is_dd03p-outputlen.
IF l_tleng LT sy-linsz.
l_lasti = sy-tabix.
l_tleng = l_tleng + 1.
ELSE.
l_tleng = l_tleng - is_dd03p-outputlen.
EXIT.
ENDIF.
ENDLOOP.
* Output header
SKIP.
FORMAT COLOR COL_HEADING.
WRITE: /3 'Contents'.
FORMAT RESET.
ULINE AT /3(l_tleng).
* Output records
LOOP AT
LOOP AT it_dd03p INTO is_dd03p FROM 1 TO l_lasti.
IF is_dd03p-position = 1.
WRITE: /3 sy-vline.
l_offst = 3.
ENDIF.
ASSIGN COMPONENT is_dd03p-fieldname OF STRUCTURE TO .
l_offst = l_offst + 1.
IF is_dd03p-decimals LE 2.
WRITE: AT l_offst .
ELSE.
WRITE: AT l_offst DECIMALS 3.
ENDIF.
l_offst = l_offst + is_dd03p-outputlen.
WRITE: AT l_offst sy-vline.
ENDLOOP.
ENDLOOP.
* Output end
ULINE AT /3(l_tleng).
ENDFORM.
Displaying Graphics using an ABAP Program
“I would like to explain about a simple report program to display graphics. The SAP Graphics can be used for various business purposes”.
In this article I am explaining about a simple Sales analysis on a yearly basis.
*&---------------------------------------------------------------------*
*& Report ZGRAPH_TEST
*&
*&---------------------------------------------------------------------*
REPORT ZGRAPH_TEST.
DATA: BEGIN OF TAB OCCURS 5,
CLASS(5) TYPE C,
VAL1(2) TYPE I,
VAL2(2) TYPE I,
VAL3(2) TYPE I,
END OF TAB.
DATA: BEGIN OF OPTTAB OCCURS 1,
C(20),
END OF OPTTAB.
MOVE: 'fan' TO TAB-CLASS,
12 TO TAB-VAL1, 8 TO TAB-VAL2, 15 TO TAB-VAL3.
APPEND TAB.
CLEAR TAB.
MOVE: 'cool' TO TAB-CLASS,
15 TO TAB-VAL1, 10 TO TAB-VAL2, 18 TO TAB-VAL3.
APPEND TAB.
CLEAR TAB.MOVE: 'DA' TO TAB-CLASS,
17 TO TAB-VAL1, 11 TO TAB-VAL2, 20 TO TAB-VAL3.
APPEND TAB.
CLEAR TAB.
OPTTAB = 'FIFRST = 3D'. APPEND OPTTAB. "// Grafik-Typ
OPTTAB = 'P3TYPE = TO'. APPEND OPTTAB. "// Objektart
OPTTAB = 'P3CTYP = RO'. APPEND OPTTAB. "// Farben der Objekte
OPTTAB = 'TISIZE = 2'. APPEND OPTTAB. "// Haupttitelgröße
OPTTAB = 'CLBACK = X'. APPEND OPTTAB. "// Background Color
CALL FUNCTION 'GRAPH_MATRIX_3D'
EXPORTING
COL1 = '1997'
COL2 = '1998'
COL3 = '1999'
DIM2 = 'Products'
DIM1 = 'Years'
TITL = 'Sales In Rs. Crores'
TABLES
DATA = TAB
OPTS = OPTTAB
EXCEPTIONS
OTHERS = 1.
LEAVE PROGRAM. Results :
Execute the report program for an output shown below.
Click on Overview for detailed view.
To display more detailed view.
ABAP Program: Output of Date Format
Suppose a date is given in the format 20050428 how to get the output in the format 28th Apr 2005.
FORM set_text_date.
DATA: month(9),
year(4),
date(2).
CASE p_frd+4(2).
WHEN '01'.
month = 'January'.
WHEN '02'.
month = 'February'.
WHEN '03'.
month = 'March'.
WHEN '04'.
month = 'April'.
WHEN '05'.
month = 'May'.
WHEN '06'.
month = 'June'.
WHEN '07'.
month = 'July'.
WHEN '08'.
month = 'August'.
WHEN '09'.
month = 'September'.
WHEN '10'.
month = 'October'.
WHEN '11'.
month = 'November'.
WHEN '12'.
month = 'December'.
WHEN OTHERS.
ENDCASE.
WRITE p_frd+0(4) TO year.
WRITE p_frd+6(2) TO date.
CONCATENATE month date ',' year INTO return_date SEPARATED BY space.
CONDENSE return_date.
ENDFORM.
ABAP Tips by : Kiran
Currently my date is getting printed in format 05262005.
I want the output as 26 May, 2005.
I have tried using Set date mask option but it is not picking up in the output.
Code:
This code yields as 12 march 2006.
DATA: ZTEMP(9).
CLEAR: ZTEMP, ZDD, ZMMM, ZYYYY.
CALL FUNCTION 'CONVERSION_EXIT_IDATE_OUTPUT'
EXPORTING
INPUT = IS_DLV_DELNOTE-HD_GEN-CREA_DATE
IMPORTING
OUTPUT = ZTEMP.
ZMMM = ZTEMP+0(3).
ZYYYY = ZTEMP+5(4).
Making a Java Editor in ABAP and compiling it
t have two reports:
zjavacreate
zjavamodify
ZJAVACREATE:
REPORT zjavacreate message-id zmsgnew.
*************************Creation of Internal table*******************
DATA: BEGIN OF ti_record OCCURS 200,
Line(250),
END OF ti_record.
DATA: BEGIN OF ti_rec OCCURS 200,
Line(250),
END OF ti_rec.
******************************Selection screen*************************
selection-screen begin of block b1 with frame .
Parameters create radiobutton group g1.
PARAMETERS: JavaName(30) lower case.
parameters modify radiobutton group g1.
selection-screen end of block b1.
*******************Calling the java program creation page***************
at selection-screen.
if CREATE = 'X'.
if javaname is not initial.
refresh ti_record[].
concatenate 'public class' javaname into ti_record-line separated by space.
concatenate ti_record-line '{' into ti_record-line separated by space.
Append ti_record.
ti_record-line = 'public static void main(String []args){'.
Append ti_record.
ti_record-line ='//enter ur code here'.
append ti_record.
ti_record-line ='}'.
Append ti_record.
ti_record-line ='}'.
Append ti_record.
EDITOR-CALL FOR ti_record .
else.
Message e001.
endif.
***************************Saving the java program*********************
data tfile type string.
concatenate 'D:\Programs\' javaname '.java' into tfile.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = tfile
FILETYPE = 'ASC'
TABLES
DATA_TAB = ti_record.
endif.
data new(15).
if MODIFY = 'X'.
new = 'ZJAVAMODIFY1'.
CALL TRANSACTION NEW.
endif.
*****************************************************************************************ZJAVAMODIFY:
REPORT zjavamodify.
***********************selection screen.*********************
selection-screen begin of block b1 with frame .
Parameters compile radiobutton group g1.
Parameters modify radiobutton group g1.
Parameters execute radiobutton group g1.
PARAMETER : FILE(100) lower case.
selection-screen end of block b1.
DATA: BEGIN OF TI_RECORD OCCURS 1,
LINE(200),
END OF TI_RECORD.
data: st1(30),st2(30).
AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILE.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
* DEF_FILENAME = ' '
DEF_PATH = '*.*'
* MASK = ' '
* MODE = ' '
* TITLE = ' '
IMPORTING
FILENAME = FILE
* RC =
.
End-of-selection.
********************************************************************
*****************************MODIFY*********************************
if modify = 'X'.
data: TXT_FILE1 TYPE STRING .
txt_file1 = file.
**************FM GUI_UPLOAD
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = txt_file1
TABLES
DATA_TAB = ti_recORD[].
**********End FM GUI_UPLOAD
EDITOR-CALL FOR ti_record .
**************FM GUI_UPLOAD
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = txt_file1
FILETYPE = 'ASC'
TABLES
DATA_TAB = ti_record.
**********End FM GUI_UPLOAD
endif.
********************end of modify********************
*******************BAT file for compilation n
execution.****************
if compile = 'X'.
DATA: begin of itab_bat_create occurs 0,
row(500) type c,
end of itab_bat_create.
data:comp_join1(250).
concatenate 'java' 'jCompiler' file into comp_join1
separated
by space.
itab_bat_create-row = 'c:'.
append itab_bat_create.
itab_bat_create-row = 'cd Documents and Settings\127740'.
append itab_bat_create.
itab_bat_create-row = comp_join1.
append itab_bat_create.
********FM GUI_DOWNLOAD
data: st type string.
st = 'C:\Documents and Settings\127740\compile_java.bat'.
call function 'GUI_DOWNLOAD'
EXPORTING
filename = st
filetype = 'ASC'
TABLES
data_tab = itab_bat_create[]
EXCEPTIONS
file_open_error = 1
file_write_error = 2
others = 3.
********end FM GUI_DOWNLOAD
*****FM dvsvas_doc_ws_execute_50
CALL FUNCTION 'DSVAS_DOC_WS_EXECUTE_50'
EXPORTING
PROGRAM = 'C:\Documents and Settings\127740\compile_java.bat'.
*****end FM dvsvas_doc_ws_execute_50
endif.
************************end of compile********************************
*********************************************************************
*************************************** output***********************
if execute = 'X'.
data: TXT_FILE3 TYPE STRING .
split File AT '.java' into: st1 st2 .
concatenate st1 'error.txt' into TXT_FILE3.
**************FM GUI_UPLOAD
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = txt_file3
TABLES
DATA_TAB = ti_recORD[].
**********End FM GUI_UPLOAD
if not ti_record[] is initial.
loop at ti_record.
write:/ ti_record.
endloop.
else.
data: TXT_FILE4 TYPE STRING .
split File AT '.java' into: st1 st2 .
concatenate st1 'output.txt' into TXT_FILE4.
**************FM GUI_UPLOAD
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = TXT_FILE4
TABLES
DATA_TAB = ti_recORD[].
**********End FM GUI_UPLOAD
loop at ti_record.
write:/ ti_record.
endloop.
endif.
endif.
************************end of
output****************************************
In ZJAVACREATE we have used the transaction new which is nothing but
the transaction code for zjavamodify. Program to Hide ABAP's Source Code and Protects it
************************************************************************
* This program hides any ABAP's source code and protects it with a
* password in this source code.
*
* After hiding, you can still run the abap (the load version is intact)
* but it cannot be displayed, edited, traced, transported or generated.
*
* If the ABAP is not hidden, the program hides it, if it is hidden, it
* unhide it.
* Remember to hide this program first!
************************************************************************
selection-screen begin of block block.
parameters: program(30) obligatory.
selection-screen begin of line.
selection-screen comment 1(8) pwd.
selection-screen position 35.
parameters: password(8) modif id aaa.
selection-screen end of line.
selection-screen end of block block.
*
data: message(60) type c.
*
at selection-screen output.
loop at screen.
if screen-group1 = 'AAA'.
screen-invisible = '1'.
modify screen.
endif.
endloop.
*
initialization.
pwd = 'Password'.
*
start-of-selection.
tables: trdir.
* User name and password check
if password <> 'ABCDEFG'.
write: / 'Wrong password'.
exit.
endif.
* SAP owned?
if not program cp 'Z*' and not program cp 'Y*'.
write: / 'Do not hide original SAP programs!'.
exit.
endif.
* Exists?
select single * from trdir where name = program.
if sy-subrc <> 0.
write: / 'Program does not exists!'.
exit.
endif.
* Does it have a current generated version?
data: f1 type d, f3 type d.
data: f2 type t, f4 type t.
EXEC SQL.
SELECT UDAT, UTIME, SDAT, STIME INTO :F1, :F2, :F3, :F4 FROM D010LINF
WHERE PROG = :PROGRAM
ENDEXEC.
if f1 < f1 =" f3" new_name ="">do 30 times.
i = sy-index - 1.
new_name+i(1) = '_'.
j = 0.
select * from trdir where name like new_name.
j = j + 1.
endselect.
if j = 1.
exit.
endif.
new_name = program.
enddo.
* Cannot generate appropriate program name
if j > 1.
write: / 'Cannot generate appropriate program name'.
exit.
endif.
* Check if it is already hidden
data: f5(30).
EXEC SQL.
SELECT PROG INTO :F5 FROM D010S WHERE PROG = :NEW_NAME
ENDEXEC.
if f5 is initial.
* There is no such hidden program, hide it
EXEC SQL.
UPDATE D010S SET PROG = :NEW_NAME WHERE PROG = :PROGRAM
ENDEXEC.
concatenate 'Program' :program 'was hidden.'
into message separated by space.
else.
* There is already a hidden program there, unhide it
EXEC SQL.
UPDATE D010S SET PROG = :PROGRAM WHERE PROG = :NEW_NAME
ENDEXEC.
concatenate 'Program' :program 'was restored.'
into message separated by space.
endif.
write message.
*** end of program
Program to Hide ABAP's Source Code and Protects it
report zsam_hide no standard page heading.
************************************************************************
* This program hides any ABAP's source code and protects it with a
* password in this source code.
*
* After hiding, you can still run the abap (the load version is intact)
* but it cannot be displayed, edited, traced, transported or generated.
*
* If the ABAP is not hidden, the program hides it, if it is hidden, it
* unhide it.
* Remember to hide this program first!
************************************************************************
selection-screen begin of block block.
parameters: program(30) obligatory.
selection-screen begin of line.
selection-screen comment 1(8) pwd.
selection-screen position 35.
parameters: password(8) modif id aaa.
selection-screen end of line.
selection-screen end of block block.
*
data: message(60) type c.
*
at selection-screen output.
loop at screen.
if screen-group1 = 'AAA'.
screen-invisible = '1'.
modify screen.
endif.
endloop.
*
initialization.
pwd = 'Password'.
*
start-of-selection.
tables: trdir.
* User name and password check
if password <> 'ABCDEFG'.
write: / 'Wrong password'.
exit.
endif.
* SAP owned?
if not program cp 'Z*' and not program cp 'Y*'.
write: / 'Do not hide original SAP programs!'.
exit.
endif.
* Exists?
select single * from trdir where name = program.
if sy-subrc <> 0.
write: / 'Program does not exists!'.
exit.
endif.
* Does it have a current generated version?
data: f1 type d, f3 type d.
data: f2 type t, f4 type t.
EXEC SQL.
SELECT UDAT, UTIME, SDAT, STIME INTO :F1, :F2, :F3, :F4 FROM D010LINF
WHERE PROG = :PROGRAM
ENDEXEC.
if f1 < f3 or ( f1 = f3 and f2 < f4 ).
write: / 'The program has no recent generated version!'.
exit.
endif.
* Compose a new program name
data: new_name(30), i type i, j type i.
new_name = program.
do 30 times.
i = sy-index - 1.
new_name+i(1) = '_'.
* Search for acceptable program name variations
j = 0.
select * from trdir where name like new_name.
j = j + 1.
endselect.
if j = 1.
exit.
endif.
new_name = program.
enddo.
* Cannot generate appropriate program name
if j > 1.
write: / 'Cannot generate appropriate program name'.
exit.
endif.
* Check if it is already hidden
data: f5(30).
EXEC SQL.
SELECT PROG INTO :F5 FROM D010S WHERE PROG = :NEW_NAME
ENDEXEC.
if f5 is initial.
* There is no such hidden program, hide it
EXEC SQL.
UPDATE D010S SET PROG = :NEW_NAME WHERE PROG = :PROGRAM
ENDEXEC.
concatenate 'Program' :program 'was hidden.'
into message separated by space.
else.
* There is already a hidden program there, unhide it
EXEC SQL.
UPDATE D010S SET PROG = :PROGRAM WHERE PROG = :NEW_NAME
ENDEXEC.
concatenate 'Program' :program 'was restored.'
into message separated by space.
endif.
write message.
*** end of program
Using Different Color in ABAP
*
REPORT ZCOLOR LINE-SIZE 90 NO STANDARD PAGE HEADING.
DATA: BEGIN OF TP OCCURS 10, ID, NR(8), TEXT(255), END OF TP.
DATA: LENGTH TYPE I VALUE 8, " Length of list
TESTSTRING(15) TYPE C VALUE '012345678901234',
WIDTH TYPE I. " Width of list
DATA: TXT_REPORT LIKE DOKHL-OBJECT.
START-OF-SELECTION.
PERFORM HEADING.
PERFORM OUTPUT_BODY.
FORM HEADING.
FORMAT INTENSIFIED OFF. " Remove any INTENSIFIED
ULINE AT (WIDTH). " Upper frame border
FORMAT COLOR COL_HEADING INTENSIFIED." Title color
WRITE: / SY-VLINE. " Left border
WRITE: 'No |Colour |intensified |intensified off|',
'inverse' NO-GAP.
WRITE: AT WIDTH SY-VLINE. " Right border
ULINE AT (WIDTH). " Line below titles
FORMAT COLOR OFF.
ENDFORM.
FORM OUTPUT_BODY.
DO LENGTH TIMES.
PERFORM WRITE_LINE USING SY-INDEX.
ENDDO.
ENDFORM.
FORM WRITE_LINE USING COUNT TYPE I.
DATA: HELP(14) TYPE C,
COUNT1 TYPE I.
COUNT1 = SY-INDEX - 1.
WRITE: / SY-VLINE NO-GAP.
WRITE: (4) COUNT1 COLOR COL_KEY INTENSIFIED NO-GAP.
WRITE: SY-VLINE NO-GAP.
CASE COUNT1.
WHEN '0'.
HELP = 'COL_BACKGROUND'.
WHEN '1'.
HELP = 'COL_HEADING'.
WHEN '2'.
HELP = 'COL_NORMAL'.
WHEN '3'.
HELP = 'COL_TOTAL'.
WHEN '4'.
HELP = 'COL_KEY'.
WHEN '5'.
HELP = 'COL_POSITIVE'.
WHEN '6'.
HELP = 'COL_NEGATIVE'.
WHEN '7'.
HELP = 'COL_GROUP'.
ENDCASE.
WRITE: HELP COLOR COL_KEY INTENSIFIED NO-GAP.
WRITE: SY-VLINE NO-GAP.
WRITE: TESTSTRING COLOR = COUNT1 INTENSIFIED NO-GAP.
WRITE: SY-VLINE NO-GAP.
WRITE: TESTSTRING COLOR = COUNT1 INTENSIFIED OFF NO-GAP.
WRITE: SY-VLINE NO-GAP.
WRITE: TESTSTRING COLOR = COUNT1 INVERSE NO-GAP.
WRITE AT WIDTH SY-VLINE NO-GAP.
ENDFORM.
*-- End of Program
Posted by RAJASEKHAR at 5:08 AM 0 comments
Labels: ABAP Programs
Using Fonts command in ABAP
How to change the font size of some of the character of SAP report without using scripts?
Be aware that the PRINT-CONTROL is not supported in SAP Enterprise 4.7
For your information, SAP cannot provide any support to error caused by print control command
(see
* Parameters for function below should be taken from your printer
* configuration in SAP - check SPAD transaction -
* standard print control
* print-control position 1 function: 'CI006', 'SF015'.
*
* Submitted by : SAP Basis, ABAP Programming and Other IMG Stuff
*
*
REPORT ZFONT NO STANDARD PAGE HEADING LINE-SIZE 80 LINE-COUNT 65.
* Start of print-control
NEW-PAGE PRINT ON.
PRINT-CONTROL FUNCTION 'SF000'.
WRITE: / 'This is CPI 20'.
SKIP.
PRINT-CONTROL FUNCTION 'SF020'.
WRITE: / 'This is CPI 6'.
SKIP.
PRINT-CONTROL FUNCTION 'SF008'.
WRITE: / 'This is CPI 12'.
* Depending on your SAP printer device, this may also work
PRINT-CONTROL FONT 1 LPI 6.
* you can try to change font and LPI numbers
WRITE: / 'font 1 lpi 6'.
PRINT-CONTROL FONT 2 LPI 6.
WRITE: / 'font 2 lpi 6'.
PRINT-CONTROL FONT 3 LPI 6.
WRITE: / 'font 3 lpi 6'.
* End of print-control
NEW-PAGE PRINT OFF.
*--- End of Program
Protect part of ABAP code from modifying
Is it possible to protect some parts of ABAP code in Z* programs from any modification?
Details... I made some templates for rapid ABAP-report design. When I want to create new report, I make copy of template and write some abap code in predefined places. A simplified example:
report z_my_report.
perform select_data.
perform output_data.
form select_data.
* Users can place code here
* >>>
* <<<
endform.
form output_data.
* Users can place code here
* >>>
* <<<
endform.
For complex reports it is important than user can write code ONLY in predefined places, not in other program logic. That's because I need to "lock" some parts of abap-code.
No direct answer for this.
One solutions is to put the sections of code in a separate include and use the editor lock in the attributes.
String Handling in ABAP - Removing Unwanted Char
I am importing data from a file and the string data has HTML tags in the description example
The code for this String Handling
REPORT zstring.
DATA : ipstr TYPE string.
DATA : opstr TYPE string.
DATA : len TYPE i VALUE 0.
DATA : ch TYPE char1.
DATA : num TYPE i VALUE 0. "No of Characters to be taken
DATA : pos TYPE char3. "Position of Char in the Input String
*Input string
ipstr = ''. Line Clearance
*Removing only ""
REPLACE ALL OCCURRENCES OF '' IN ipstr WITH ' '.
*Removing only "<"
REPLACE ALL OCCURRENCES OF '<' IN ipstr WITH ' '.
CONDENSE ipstr.
*Length of Input String
len = STRLEN( ipstr ).
DO len TIMES.
*Char by Char
ch = ipstr+pos(1).
pos = pos + 1.
*Scan each char in input String for ">"
FIND '>' IN ch IGNORING CASE.
IF sy-subrc = 0.
num = len - pos.
*Output String
opstr = ipstr+pos(num).
ENDIF.
ENDDO.
WRITE :/ opstr.
How to find out Total No of Pages of a Report Output in sap abap
I want to find out total no of pages of a report output. This no I have to print in TOP-OF-PAGE event.
Check this below code. You will get the clear idea.
REPORT YJAM_WA no standard page heading line-count 60(5).
data: v_totpage type i.
data: v_temp(3) type c.
Start-of-selection.
do 100 times.
write:/ sy-index.
enddo.
end-of-selection.
v_temp = v_totpage.
do v_totpage times.
read line 1 of page sy-index.
replace '@@@' in sy-lisel with v_temp.
modify line 1 of page sy-index.
enddo.
top-of-page.
write:/60 'page', sy-pagno, '/','@@@'.
v_totpage = sy-pagno.
Here is a sample:
* zlines number of lines in the table
* sy-srows number of lines in screen
* sy-cpage current page
* zpages total number of pages type i
* temp temporary number type f
describe table itab lines zlines.
temp = zlines / sy-srows.
zpages = trunc( temp ).
temp = frac( temp ).
if temp > 0.
zpages = zpages + 1.
endif.
* zpages is the number of pages
write: /'Page ',sy-cpage, ' of ', zpages.
Split String into two parts at delimiter in sap abap
*---------------------------------------------------------------------
* 29.04.2003 |Initial Author - | This program search for a delimiter
* |Amandeep Singh | and split it into two parts.
*---------------------------------------------------------------------
*
* Split String into two parts at delimeter
* Current delimeter is '/'.
*
REPORT ZSTRING.
DATA: LENGTH TYPE I,
REMAINING_LENGTH TYPE I ,
NEXT_POINTER TYPE I ,
FIRST_HALF(20) TYPE C ,
SECOND_HALF(20) TYPE C ,
TEMP TYPE I .
PARAMETER: WORD(35) TYPE C . "INPUT WORD
START-OF-SELECTION.
LENGTH = STRLEN( WORD ). "Length of the input String
SEARCH WORD FOR '/'.
IF SY-SUBRC = 0 .
IF SY-FDPOS > 0.
MOVE WORD+0(SY-FDPOS) TO FIRST_HALF.
ENDIF.
TEMP = SY-FDPOS + 1.
IF TEMP <> LENGTH.
NEXT_POINTER = SY-FDPOS + 1.
REMAINING_LENGTH = ( LENGTH - SY-FDPOS ) - 1.
MOVE WORD+NEXT_POINTER(REMAINING_LENGTH) TO SECOND_HALF.
ENDIF.
ENDIF.
WRITE:/'Input String:', WORD
.
WRITE:/'First Half:', FIRST_HALF.
WRITE:/'Second Half:', SECOND_HALF.
*-- End of Program
How to get the field descriptions of a table?
I need to get the associated data element descriptions of all the fields in a table. I think there's a way to do that using the SELECT statement.
Can you please give me in detail, the various steps and methods to find the corresponding SAP tables and fields for a particular transaction code, for example (CS03).
Do the following 2 steps. Then create your ABAP program accordingly with the SELECT statement.
1. From table DD03L, give your tablename and get all of its field names and corresponding data element names.
2. From table DD03T, get the description of each data element you have got in step 1.
Then Use Function Module DDIF_FIELDINFO_GET
The sample program will look like this:
REPORT ZTABLEFIELDNAME.OR
TABLES: DFIES,
X030L.
DATA: BEGIN OF INTTAB OCCURS 100.
INCLUDE STRUCTURE DFIES.
DATA: END OF INTTAB.
PARAMETERS: TABLENM TYPE DDOBJNAME DEFAULT 'MSEG',
FIELDNM TYPE DFIES-FIELDNAME DEFAULT 'MENGE'.
call function 'DDIF_FIELDINFO_GET'
exporting
tabname = TABLENM
FIELDNAME = FIELDNM
LANGU = SY-LANGU
* LFIELDNAME = ' '
* ALL_TYPES = ' '
* IMPORTING
* X030L_WA = WATAB
* DDOBJTYPE =
* DFIES_WA =
* LINES_DESCR =
TABLES
DFIES_TAB = INTTAB
* FIXED_VALUES =
EXCEPTIONS
NOT_FOUND = 1
INTERNAL_ERROR = 2
OTHERS = 3.
if sy-subrc <> 0.
WRITE:/ 'Field name not found'.
endif.
LOOP AT INTTAB.
WRITE:/ INTTAB-TABNAME, INTTAB-FIELDNAME, INTTAB-FIELDTEXT.
ENDLOOP.
*** End of Program
Step 1.
Run the transaction and click on System -> Status. Note the program name shown under the transaction code.
Step 2.
Run SE49 and enter the program name you identified in step 1 (SAPLCSDI) and then press enter.
This will identify the tables used, however, as you want to know the fields used as well then you may have to resort to looking at the actual code (get a developer involved if you're not one) using transaction SE80.
In this case the transaction CS03 is assigned to a screen with a function group so it's a slightly tricker process, hence the need for a developers service.
For all the tables, descriptions and fields you can refer to these tables:
DD02L : ALL SAP TABLE NAMES
DD02T : DESCRIPTION OF TABLE NAMES
DD03L : FIELDS IN A TABLE.
Automation Testing
- Manual and Automation testing Challenges
- What you need to know about BVT (Build Verification Testing)
- BVT types
- Learning basics of QTP automation tool and preparation of QTP interview questions
- QuickTest Pro - QTP Functional testing tool review
- Tips you should read before automating your testing work
- Choosing Automation tool for your organization