Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Friday, April 18, 2008

Difference Between Select-Options & Ranges SAP ABAP INTERVIEW Questions

What are the difference between SELECT-OPTIONS & RANGES?


Here both SELECT-OPTIONS & RANGES works for the same purpose. They both are used for the range selection from selection screen. The main diff. between them is, while we use SELECT-OPTIONS system implicitly creates the select options internal table which contains the fields of SIGN,OPTION,LOW & HIGH. But in case of RANGES, this internal table should be defined explicitly.

Eg. to SELECT-OPTIONS :
-----------------------------------------

REPORT YARSELECT.
TABLES YTXLFA1.
SELECT-OPTIONS : VENDOR FOR YTXLFA1-LIFNR.
INITIALIZATION.
VENDOR-LOW = 1000. " It specifies the range starting value.
VENDOR-HIGH = 2000. " It specifies the range ending value.
VENDOR-OPTION = 'BT'. " specifies ranges value is in between.
VENDOR-SIGN = 'I'. "specifies both inclussive.

APPEND VENDOR.

- - - -
- - - -
SELECT LIFNR LAND1 NAME1 FROM LFA1 INTO TABLE ITAB
WHERE LIFNR IN VENDOR.

Eg. to RANGES:
-------------------------

REPORT YARRANGE.
TABLES YTXLFA1.
RANGES: VENDOR FOR YTXFLA1-LIFNR.

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

SELECT LIFNR LAND1 NAME1 FROM LFA1 INTO TABLE ITAB
WHERE LIFNR IN VENDOR.

Here with RANGES user has to design an internal table with fields -
SIGN,OPTION,LOW and HIGH EXPLICITLY.

--------------------------------------------------------------------------------------------------------->


Example:

select-options: bukrs for zstock-bukrs.

Should the user fill in 'ABFI' in BUKRS on the selection screen, BUKRS will look like this:

IEQABFI

This is because BUKRS is set as a table as follows:

begin of bukrs occurs 0,
SIGN(1) type c,
OPTION(2) type c,
LOW like bukrs,
HIGH like bukrs,
end of bukrs.

Now, when you create the following range, it will have the exact same fields set inside its table:

Ranges: bukrs for zstock-bukrs.

The difference is, because ranges doesn't show on the selection screen, you will have to fill it yourself, meaning you will have to fill bukrs-sign, bukrs-option, bukrs-low & bukrs-high all manually.

Some tips:
Sign is always I (for Include) or E (for Exclude)
Option can be a whole range, which includes:
EQ (Equal)
BT (Between))
CP (Contain Pattern)
So let's say you want to have the range check for all company codes not starting with AB, you will set your code as follow:

ranges: bukrs for zstock-bukrs.

bukrs-sign = 'E'. "Exclude
bukrs-option = 'CP'. "Pattern
bukrs-low = 'AB*'. "Low Value
bukrs-high = ''. "High Value
append bukrs.

Always remember to APPEND your range when you fill it, as the WHERE clause checks against the lines of the range table, not against the header line.

Hope this explains it well enough.

--------------------------------------------------------------------------------------------------------->


What does SIGN "I" & "E" mean?

The "I" stands for Include, and the "E" for Exclude.

The easiest way to learn how the range selections work is, create the following dummy program:

report dummy.
tables: mara.
select-options: matnr for mara-matnr.
start-of-selection.
loop at matnr.
write: / matnr-sign,
matnr-option,
matnr-low,
matnr-high.
endloop.

Run this program, and fill in a lot of junk into MATNR. Fill in some includes, some excludes, some ranges, etc., and you will soon realise how the system builds ranges (select-options). Once you know that, you can fill your own ranges quickly and efficiently.

Inner Join to retrieve the Material Valuation Class SAP ABAP INTERVIEW Questions

*
* Inner Join to retrieve the Material Valuation Class pointing to
* which General Ledger.
*
* Based on transaction OBYC - Inventory Posting - BSX
*
* If you use inner join to read data from several logically
* connected tables instead of nested Select statements.
* It will reduce your network load.
*
* Written by : SAP Basis, ABAP Programming and Other IMG Stuff
*
*
REPORT ZVALGL.

TABLES: MARA, "General Material Data
MAKT, "Material Descriptions
MBEW, "Material Valuation
SKAT, "G/L Account Master Record
T025T, "Valuation Class Descriptions
T030. "Standard Accounts Table

DATA: BEGIN OF WA,
BKLAS TYPE MBEW-BKLAS,
BKBEZ TYPE T025T-BKBEZ,
MTART TYPE MARA-MTART,
MATNR TYPE MARA-MATNR,
MAKTX TYPE MAKT-MAKTX,
END OF WA,
ITAB LIKE SORTED TABLE OF WA
WITH NON-UNIQUE KEY BKLAS MATNR.

SELECT-OPTIONS: PLANT FOR MBEW-BWKEY MEMORY ID PLT,
MATLTYPE FOR MARA-MTART MEMORY ID TYP,
MATERIAL FOR MBEW-MATNR MEMORY ID MAT,
CHARTACC FOR T030-KTOPL MEMORY ID KTO.

SELECT P~BKLAS
F~MATNR F~MTART
G~MAKTX
T~BKBEZ
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM ( ( ( ( MBEW AS P
INNER JOIN MARA AS F ON P~MATNR = F~MATNR )
INNER JOIN MAKT AS G ON P~MATNR = G~MATNR )
INNER JOIN T025T AS T ON P~BKLAS = T~BKLAS ) )
WHERE P~BWKEY IN PLANT
AND F~MTART IN MATLTYPE
AND P~MATNR IN MATERIAL
AND G~SPRAS = 'E'.

LOOP AT ITAB INTO WA.
CLEAR: T030, SKAT.
SELECT SINGLE * FROM T030 WHERE BKLAS = WA-BKLAS
AND KTOSL = 'BSX'.
SELECT SINGLE * FROM SKAT WHERE SAKNR = T030-KONTS
AND SPRAS = 'E'.
WRITE: / WA, T030-KONTS, SKAT-TXT20.
ENDLOOP.

How to used 3 tables for inner joins? SAP ABAP INTERVIEW Questions

Inner joins using 3 tables


Try this :-

SELECT stpo~stlnr stpo~idnrk mast~matnr mara~mtart stpo~menge
INTO CORRESPONDING FIELDS OF TABLE zmat1 FROM mast
JOIN stpo ON stpo~stlnr = mast~stlnr
JOIN mara ON mara~matnr = mast~matnr
WHERE stpo~stlty = 'M' "AND stpo~idnrk IN s_matnr
AND mast~werks = 1000.

Here s_matnr is a select-options on the selection-screen.

Or this.


Code:


Select single Vbrk~Bukrs Vbrk~Kunrg Vbrk~Vbeln
Vbrk~Fkdat Vbrk~Bstnk_Vf Vbrk~Zterm
Tvzbt~Vtext
Vbak~Vbeln Vbak~Bstdk
Likp~Vbeln Likp~lfdat Likp~Lfuhr
into w_vbrk
from vbrk
inner join Tvzbt on Tvzbt~Zterm = Vbrk~Zterm and
Tvzbt~Spras = sy-langu
Inner join Vbfa as SalesLnk
on SalesLnk~vbeln = pu_vbeln and
SalesLnk~vbtyp_v = c_order
inner join Vbak on Vbak~Vbeln = SalesLnk~Vbelv
Inner join Vbfa as DeliveryLnk
on DeliveryLnk~vbeln = pu_vbeln and
DeliveryLnk~vbtyp_v = c_Delivery
inner join Likp on Likp~Vbeln = DeliveryLnk~Vbelv
where vbrk~vbeln = pu_Vbeln.


This code locates sales, delivery and payment terms info from a billing document number.

or

Here, this one also works fine :

select zfpcd~cadivi zfpcd~proforma zfpcd~factura zfpcd~aniofactura
zfpcd~montousd zfpcd~montoap zfpcd~ebeln zfpcd~inco1
zfpcd~lifnr lfa1~name1 zcdvs~status zfpcd~conint
into it_lista
from zfpcd inner join zcdvs
on zfpcd~ebeln = zcdvs~ebeln
and zfpcd~proforma = zcdvs~proforma
and zfpcd~lifnr = zcdvs~lifnr
inner join lfa1
on zfpcd~lifnr = lfa1~lifnr
where zcdvs~status = '04'.

Protect Selection/Parameters SAP ABAP INTERVIEW Questions

An easy way of making a standard reports selection/parameters to be read-only/protected. (like an option NO-INPUT).

You can add a "Module Protect Output." module with code to the program, where it sets the screen-input = 0 as required, and add the line "Module Protect Output." to the PBO, and it works fine, until you re-generate the code and
this line is removed (the PBO PAI in SE51 screen 1000) as known, this code is also re-generated and any changes made will be ineffective.

If you tried using one of the PBO generated module names, it will says its does not exist, so if you generate it with the code, and run the program it will tell you "Module PBO_REPORT is already defined as a OUTPUT module".

The purpose: To calculate and set up the parameters in INITIALIZATION. You want to show them to the user, and use them in SELECTs, use them as Headings, but you want to stop the user from changing some of them.


The solution is as follows :


AT SELECTION-SCREEN OUTPUT.
PERFORM protect.
.
.
.
FORM protect.
LOOP at SCREEN
CASE screen-name.
WHEN 'UNAME' OR 'UNUMB' OR 'DESCR'. screen-input = 0.
WHEN 'XNAME' OR 'XNUMB' OR 'DESCX'. screen-input = 0.
ENDCASE.
ENDLOOP.
ENDFORM.

Difference Between Select Single and Select UpTo One Rows SAP ABAP INTERVIEW Questions

According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not using all the primary key fields.


select single is a construct designed to read database records with primary key. In the absence of the primary key, it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index.

The best way to find out is through sql trace or runtime analysis.


Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s) you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the second or the third record has the value you are looking for.


The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS.


The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique.


Mainly: to read data from


The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set.


Mainly: to check if entries exist.

Select statement with inner join is taking forever SAP ABAP INTERVIEW Questions

Following is the select stmt which is taking forever.

SELECT MKPF~BUDAT MKPF~CPUTM
MSEG~MATNR MSEG~WERKS MSEG~EBELN
MSEG~EBELP MSEG~ERFMG
INTO CORRESPONDING FIELDS OF TABLE
W_DTL_INVOICE
FROM MKPF INNER JOIN MSEG
ON MKPF~MBLNR = MSEG~MBLNR
AND MKPF~MJAHR = MSEG~MJAHR
WHERE MKPF~BUDAT > '20040721' AND
MSEG~BWART = '101' AND
MSEG~BUKRS = '1733'.

It does not have much records.
Can somebody let me know how to fine tune this statement.


I have gone through the same problem last year. This is the solution I made. My program spended more than an hour to select 5000 records from mkpf inner mseg(From a range of 100000 records) . Now it needs less than 15 seconds to perform the same task.

Try this changes

** in global data add these two hashed tables

data: begin of wa_mkpfmseg,
mblnr like mkpf-mblnr,
mjahr like mkpf-mjahr,
zeile like mseg-zeile,
bukrs like mseg-bukrs
bwart like mseg-bwart,
budat like mkpf-budat,
cputm like mkpf-cputm,
matnr like mseg-matnr,
werks like mseg-werks,
ebeln like mseg-ebeln,
ebelp like mseg-ebelp,
erfmg like mseg-erfmg,
end of wa_mkpfmseg.

data ht_mkpfmseg like hashed table of wa_mkpfmseg
with unique key mblnr mjahr zeile
with header line.

data: begin of wa_mkpfmsegSel,
budat like mkpf-budat,
cputm like mkpf-cputm,
matnr like mseg-matnr,
werks like mseg-werks,
ebeln like mseg-ebeln,
ebelp like mseg-ebelp,
erfmg like mseg-erfmg,
end of wa_mkpfmseg.


data ht_mkpfmsegSel like hashed table of wa_mkpfmsegSel
with unique key budat cputm matnr werks ebeln ebelp
with header line.

** change your select sentence to look like this:
select mkpf~mblnr
mkpf~mjahr
mseg~zeile
mseg~bukrs
mseg~bwart
MKPF~BUDAT MKPF~CPUTM
MSEG~MATNR MSEG~WERKS MSEG~EBELN
MSEG~EBELP MSEG~ERFMG
INTO TABLE ht_mkpfmseg
FROM MKPF INNER JOIN MSEG
ON mkpf~mandt = mseg~mandt
AND MKPF~MBLNR = MSEG~MBLNR
AND MKPF~MJAHR = MSEG~MJAHR
where mkpf~budat > '20040721'.

loop at ht_mkpfmseg.
check ht_mkpfmseg-bukrs = '1733' and ht_mkpfmseg-bwart = '101'
read table ht_mkpfmsegsel with table key
budat = ht_mkpfmseg-budat
cputm = ht_mkpfmseg-cputm

matnr = ht_mkpfmseg-matnr
werks = ht_mkpfmseg-werks

ebeln = ht_mkpfmseg-ebeln
ebelp = ht_mkpfmseg-ebelp
transporting erfmg.
if sy-subrc <> 0.
move-corresponding ht_mkpfmseg to ht_mkpfmsegsel.
insert table ht_mkpfmsegsel.
else.
ht_mkpfmsegSel-budat = ht_mkpfmseg-budat.
ht_mkpfmsegSel-cputm = ht_mkpfmseg-cputm.
ht_mkpfmsegSel-matnr = ht_mkpfmseg-matnr,
ht_mkpfmsegSel-werks = ht_mkpfmseg-werks.
ht_mkpfmsegSel-ebeln = ht_mkpfmseg-ebeln.
ht_mkpfmsegSel-ebelp = ht_mkpfmseg-ebelp.
add ht_mkpfmseg-erfmg to ht_mkpfmsegSel-erfmg.
modify table ht_mkpfmsegSel transporting erfmg.
endif.
endloop.
" at this point ht_mkpfmsegSel has the data collected that you want.
loop at ht_mkpfmsegSel.
.... Here put the code between your select ... endselect.
endloop.


This should run faster because of the next reasons:


1. you're not distracting the sql optimizer when it analizes the sql where clause. It makes use of the first index declared on mkpf (budat-mblnr)-


2. the data is selected into a hashed table which are the faster access tables provided by SAP from 4.0 up to 4.6c (I don't know about 4.7)


3. As the select isn't restricting bukrs and bwart (but there is a good reason on this: it's faster to read 100000 records into a hashed table and then filter the 80000 unwanted than to select the 20000 records via non index fields in the where clause. I tested it in my own programs).

How can we give dynamic table name in select statement? SAP ABAP INTERVIEW Questions

Dynamic Select Statement

check this code...

*-----

For dynamic table name....

REPORT demo_select_dynamic_database .

DATA wa TYPE scarr.
DATA name(10) TYPE c VALUE 'SCARR'.

SELECT *
INTO wa
FROM (name) CLIENT SPECIFIED
WHERE mandt = '000'.
WRITE: / wa-carrid, wa-carrname.
ENDSELECT.

*-----

For dynamic field list

REPORT demo_select_dynamic_columns .

DATA: itab TYPE STANDARD TABLE OF spfli,
wa LIKE LINE OF itab.
DATA: line(72) TYPE c,

list LIKE TABLE OF line(72).

line = ' CITYFROM CITYTO '.

APPEND line TO list.

SELECT DISTINCT (list)
INTO CORRESPONDING FIELDS OF TABLE itab
FROM spfli.

IF sy-subrc EQ 0.

LOOP AT itab INTO wa.
WRITE: / wa-cityfrom, wa-cityto.
ENDLOOP.

ENDIF.

Performance tuning for Data Selection Statement SAP ABAP INTERVIEW Questions

For all entries

The for all entries creates a where clause, where all the entries in the driver table are combined with OR. If the number of
entries in the driver table is larger than rsdb/max_blocking_factor, several similar SQL statements are executed to limit the
length of the WHERE clause.


The plus

  • Large amount of data
  • Mixing processing and reading of data
  • Fast internal reprocessing of data
  • Fast

The Minus
  • Difficult to program/understand
  • Memory could be critical (use FREE or PACKAGE size)

Some steps that might make FOR ALL ENTRIES more efficient:
  • Removing duplicates from the the driver table
  • Sorting the driver table
    If possible, convert the data in the driver table to ranges so a BETWEEN statement is used instead of and OR statement:
    FOR ALL ENTRIES IN i_tab
    WHERE mykey >= i_tab-low and
    mykey <= i_tab-high.


Nested selects


The plus:
  • Small amount of data
  • Mixing processing and reading of data
  • Easy to code - and understand

The minus:
  • Large amount of data
  • when mixed processing isn’t needed
  • Performance killer no. 1


Select using JOINS


The plus
  • Very large amount of data
  • Similar to Nested selects - when the accesses are planned by the programmer
  • In some cases the fastest
  • Not so memory critical

The minus
  • Very difficult to program/understand
  • Mixing processing and reading of data not possible


Use the selection criteria

SELECT * FROM SBOOK.                
CHECK: SBOOK-CARRID = 'LH' AND
SBOOK-CONNID = '0400'.
ENDSELECT.
SELECT * FROM SBOOK                  
WHERE CARRID = 'LH' AND
CONNID = '0400'.
ENDSELECT.


Use the aggregated functions

C4A = '000'.           
SELECT * FROM T100
WHERE SPRSL = 'D' AND
ARBGB = '00'.
CHECK: T100-MSGNR > C4A.
C4A = T100-MSGNR.
ENDSELECT.

SELECT MAX( MSGNR ) FROM T100 INTO C4A
WHERE SPRSL = 'D' AND
ARBGB = '00'.


Select with view

SELECT * FROM DD01L                 
WHERE DOMNAME LIKE 'CHAR%'
AND AS4LOCAL = 'A'.
SELECT SINGLE * FROM DD01T
WHERE DOMNAME = DD01L-DOMNAME
AND AS4LOCAL = 'A'
AND AS4VERS = DD01L-AS4VERS
AND DDLANGUAGE = SY-LANGU.
ENDSELECT.

SELECT * FROM DD01V
WHERE DOMNAME LIKE 'CHAR%'
AND DDLANGUAGE = SY-LANGU.
ENDSELECT.


Select with index support

SELECT * FROM T100         
WHERE ARBGB = '00'
AND MSGNR = '999'.
ENDSELECT.

SELECT * FROM T002.
SELECT * FROM T100
WHERE SPRSL = T002-SPRAS
AND ARBGB = '00'
AND MSGNR = '999'.
ENDSELECT.
ENDSELECT.


Select … Into table

REFRESH X006.              
SELECT * FROM T006 INTO X006.
APPEND X006.
ENDSELECT

SELECT * FROM T006 INTO TABLE X006.

Select with selection list

SELECT * FROM DD01L           
WHERE DOMNAME LIKE 'CHAR%'
AND AS4LOCAL = 'A'.
ENDSELECT

SELECT DOMNAME FROM DD01L
INTO DD01L-DOMNAME
WHERE DOMNAME LIKE 'CHAR%'
AND AS4LOCAL = 'A'.
ENDSELECT


Key access to multiple lines

LOOP AT TAB.       
CHECK TAB-K = KVAL.
" ...
ENDLOOP.

LOOP AT TAB WHERE K = KVAL.
" ...
ENDLOOP.


Copying internal tables

REFRESH TAB_DEST.           
LOOP AT TAB_SRC INTO TAB_DEST.
APPEND TAB_DEST.
ENDLOOP.

TAB_DEST[] = TAB_SRC[].


Modifying a set of lines

LOOP AT TAB.          
IF TAB-FLAG IS INITIAL.
TAB-FLAG = 'X'.
ENDIF.
MODIFY TAB.
ENDLOOP.

TAB-FLAG = 'X'.
MODIFY TAB TRANSPORTING FLAG
WHERE FLAG IS INITIAL.


Deleting a sequence of lines

DO 101 TIMES.            
DELETE TAB_DEST INDEX 450.
ENDDO.

DELETE TAB_DEST FROM 450 TO 550.

Linear search vs. binary

READ TABLE TAB WITH KEY K = 'X'.

READ TABLE TAB WITH KEY K = 'X' BINARY SEARCH.


Comparison of internal tables

DESCRIBE TABLE: TAB1 LINES L1,   
TAB2 LINES L2.

IF L1 <> L2.
TAB_DIFFERENT = 'X'.
ELSE.
TAB_DIFFERENT = SPACE.
LOOP AT TAB1.
READ TABLE TAB2 INDEX SY-TABIX.
IF TAB1 <> TAB2.
TAB_DIFFERENT = 'X'. EXIT.
ENDIF.
ENDLOOP.
ENDIF.

IF TAB_DIFFERENT = SPACE.
" ...
ENDIF.

IF TAB1[] = TAB2[].
" ...
ENDIF.


Modify selected components

LOOP AT TAB.        
TAB-DATE = SY-DATUM.
MODIFY TAB.
ENDLOOP.

WA-DATE = SY-DATUM.
LOOP AT TAB.
MODIFY TAB FROM WA TRANSPORTING DATE.
ENDLOOP.


Appending two internal tables

LOOP AT TAB_SRC.           
APPEND TAB_SRC TO TAB_DEST.
ENDLOOP

APPEND LINES OF TAB_SRC TO TAB_DEST.


Deleting a set of lines

LOOP AT TAB_DEST WHERE K = KVAL.
DELETE TAB_DEST.
ENDLOOP

DELETE TAB_DEST WHERE K = KVAL.

Tools available in SAP to pin-point a performance problem

    The runtime analysis (SE30)
    SQL Trace (ST05)
    Tips and Tricks tool 
    The performance database


Optimizing the load of the database


Using table buffering

Using buffered tables improves the performance considerably. Note that in some cases a stament can not be used with a buffered table, so when using these staments the buffer will be bypassed. These staments are:
  • Select DISTINCT
  • ORDER BY / GROUP BY / HAVING clause
  • Any WHERE clasuse that contains a subquery or IS NULL expression
  • JOIN s
  • A SELECT... FOR UPDATE
If you wnat to explicitly bypass the bufer, use the BYPASS BUFFER addition to the SELECT clause.


Use the ABAP SORT Clause Instead of ORDER BY

The ORDER BY clause is executed on the database server while the ABAP SORT statement is executed on the application server. The datbase server will usually be the bottleneck, so sometimes it is better to move thje sort from the datsbase server to the application server.

If you are not sorting by the primary key ( E.g. using the ORDER BY PRIMARY key statement) but are sorting by another key, it could be better to use the ABAP SORT stament to sort the data in an internal table. Note however that for very large result sets it might not be a feasible solution and you would want to let the datbase server sort it.


Avoid ther SELECT DISTINCT Statement

As with the ORDER BY clause it could be better to avoid using SELECT DISTINCT, if some of the fields are not part of an index. Instead use ABAP SORT + DELETE ADJACENT DUPLICATES on an internal table, to delete duplciate rows.

What's the purpose of using PACKAGE SIZE in select statement? SAP ABAP INTERVIEW Questions

Package size can be used if you for example only want to finish processing a limited amount of data at a time due to lack of memory.


The example below read 50 records at a time from VBAK into an internal table, and selects the corresponding entries from vbap into an internal table. Then the two internal tables can be processed, and the next 50 records from VBAk can be read. Remember to reinitialize tha tables before the next read.

REPORT z_test.

TYPES:
BEGIN OF t_vbak,
vbeln LIKE vbak-vbeln,
erdat LIKE vbak-erdat,
END OF t_vbak,

BEGIN OF t_vbap,
posnr LIKE vbap-posnr,
matnr LIKE vbap-matnr,
meins LIKE vbap-meins,
END OF t_vbap,

BEGIN OF t_report,
vbeln LIKE vbak-vbeln,
erdat LIKE vbak-erdat,
posnr LIKE vbap-posnr,
matnr LIKE vbap-matnr,
meins LIKE vbap-meins,
END OF t_report.

DATA:
li_vbak TYPE t_vbak OCCURS 0,
l_vbak TYPE t_vbak,
li_vbap TYPE t_vbap OCCURS 0,
l_vbap TYPE t_vbap,
li_report TYPE t_report OCCURS 0,
l_report TYPE t_report.

START-OF-SELECTION.
SELECT vbeln erdat
FROM vbak
INTO TABLE li_vbak PACKAGE SIZE 50.
SELECT posnr matnr meins
FROM vbap
INTO TABLE li_vbap
FOR ALL ENTRIES IN li_vbak
WHERE vbeln = li_vbak-vbeln.
IF sy-subrc = 0.
* Now you have the two internal tables li_vbak and li_vbap filled
* with data.
* Do something with the data - remember to reinitialize internal
* tables
ENDIF.
ENDSELECT.

*-- End of Program

Usage of 'for all entries' in Select Statement SAP ABAP INTERVIEW Questions

FORM data_retrieval.

DATA: ld_color(1) TYPE c.

DATA: BEGIN OF T_VBAP OCCURS 0,
VBELN LIKE VBAP-VBELN,
MATNR LIKE VBAP-MATNR,
POSNR LIKE VBAP-POSNR,
END OF T_VBAP.

DATA: BEGIN OF T_VBFA OCCURS 0,
VBELV LIKE VBFA-VBELV,
VBELN LIKE VBFA-VBELN,
VBTYP_N LIKE VBFA-VBTYP_N,

END OF T_VBFA.

DATA: BEGIN OF T_VBAK OCCURS 0,
VBELN LIKE VBAK-VBELN,
IHREZ LIKE VBAK-IHREZ,
END OF T_VBAK.

DATA: BEGIN OF T_KNA1 OCCURS 0,
KUNNR LIKE KNA1-KUNNR,
NAME1 LIKE KNA1-NAME1,
END OF T_KNA1.

DATA: BEGIN OF T_MAKT OCCURS 0,
MATNR LIKE MAKT-MATNR,
MAKTX LIKE MAKT-MAKTX,
END OF T_MAKT.

SELECT likp~vbeln likp~lifex likp~bldat likp~wadat likp~wadat_ist likp~kodat likp~lfart
likp~kunnr likp~vstel lips~posnv lips~lfimg lips~vrkme lips~lgmng lips~meins
lips~werks lips~lgort lips~charg lips~vbelv lips~posnr lips~matnr
lips~vbeln LIPS~VGBEL LIPS~VGPOS vbup~kosta vbup~wbsta vbup~posnr vbup~vbeln
* VBAK~IHREZ VBAK~VBELN VBAP~VBELN
INTO CORRESPONDING FIELDS OF TABLE it_itab
FROM ( likp
INNER JOIN lips
ON lips~vbeln = likp~vbeln
INNER JOIN vbup
ON vbup~posnr = lips~posnr
and VBUP~VBELN = LIPS~VBELN )
* left outer join VBAK
* on VBAK~VBELN = LIPS~VGBEL
* inner join VBAP
* on VBAP~VBELN = VBAK~VBELN )
WHERE likp~vbeln IN so_vbeln
AND likp~lifex IN so_lifex
AND likp~lfart IN so_lfart
AND likp~kunnr IN so_kunnr
AND likp~vstel IN so_vstel
AND likp~bldat IN so_bldat
AND likp~wadat_ist IN so_wadat
AND vbup~kosta IN so_kosta
AND vbup~wbsta IN so_wbsta
AND LIPS~LFIMG NE 0.

SELECT VBELN IHREZ INTO TABLE T_VBAK
FROM VBAK
FOR ALL ENTRIES IN IT_ITAB
WHERE VBELN = IT_ITAB-VGBEL.
* APPEND T_VBAK.
* ENDSELECT.

SELECT VBELN MATNR POSNR INTO TABLE T_VBAP
FROM VBAP
FOR ALL ENTRIES IN IT_ITAB
WHERE VBELN = IT_ITAB-VGBEL AND
MATNR = IT_ITAB-MATNR AND
POSNR = IT_ITAB-VGPOS.
* APPEND T_VBAP.
* ENDSELECT.

SELECT VBELV VBELN VBTYP_N INTO TABLE T_VBFA
FROM VBFA
FOR ALL ENTRIES IN IT_ITAB
WHERE VBELV = IT_ITAB-VBELN AND
VBTYP_N = 'M' .

SELECT KUNNR NAME1 INTO TABLE T_KNA1
FROM KNA1
FOR ALL ENTRIES IN IT_ITAB
WHERE KUNNR = IT_ITAB-KUNNR.
* APPEND T_KNA1.
* ENDSELECT.

SELECT MATNR MAKTX INTO TABLE T_MAKT
FROM MAKT
FOR ALL ENTRIES IN IT_ITAB
WHERE MATNR = IT_ITAB-MATNR.
* APPEND T_MAKT.
* ENDSELECT.


*Populate field with color attributes

LOOP AT it_itab INTO wa_ITAB.

* Populate color variable with colour properties

* Char 1 = C (This is a color property)

* Char 2 = 3 (Color codes: 1 - 7)

* Char 3 = Intensified on/off ( 1 or 0 )

* Char 4 = Inverse display on/off ( 1 or 0 )

* i.e. wa_ekko-line_color = 'C410'
REFRESH color.
colourize 'VBELN' 0. " .
WA_ITAB-farbe = color[].


ld_color = ld_color + 1.

* Only 7 colours so need to reset color value

IF ld_color = 3. "8

ld_color = 1.

ENDIF.

CONCATENATE 'C' ld_color '10' INTO wa_ITAB-line_color.
WA_ITAB-NAME1 = ''.
WA_ITAB-MAKTX = ''.
WA_ITAB-IHREZ = ''.
WA_ITAB-VBELV = ''.
READ TABLE T_KNA1 WITH KEY KUNNR = WA_ITAB-KUNNR.
IF SY-SUBRC = 0.
WA_ITAB-NAME1 = T_KNA1-NAME1.
ENDIF.
READ TABLE T_MAKT WITH KEY MATNR = WA_ITAB-MATNR.
IF SY-SUBRC = 0.
WA_ITAB-MAKTX = T_MAKT-MAKTX.
ENDIF.
READ TABLE T_VBAK WITH KEY VBELN = WA_ITAB-VGBEL.
IF SY-SUBRC = 0.
WA_ITAB-IHREZ = T_VBAK-IHREZ.
ENDIF.
READ TABLE T_VBFA WITH KEY VBELV = WA_ITAB-VBELN.
IF SY-SUBRC = 0.
WA_ITAB-VBELVA = T_VBFA-VBELN.
ENDIF.
* READ TABLE T_VBAP WITH KEY VBELN = WA_ITAB-VGBEL
* POSNR = WA_ITAB-VGPOS
* MATNR = WA_ITAB-MATNR.
* IF SY-SUBRC = 0.
* WA_ITAB-IHREZ = T_VBAK-IHREZ.
* ENDIF.



* wa_ekko-line_color = 'C410'.

MODIFY it_itab FROM wa_itab.

ENDLOOP.

ENDFORM. " data_retrieval

ABAP Self Test Q & A SAP ABAP INTERVIEW Questions

1) Authorization Objects

( this question has more than 1 answer )
a) Stored in User Master
b) Defines fields for a complex authority check
c) Grouped together in profiles
d) Covers up to 10 fields
e) Consists of up to 10 authorization objects


2) Authorization Checking

( this question has more than 1 answer )
a) performed with SELECT statement
b) performed with AUTHORITY-CHECK
c) determines if user has authority in master record
d) always refers to authorization profile
e) system admin defines which authorization checks are executed


3) Authorization

( this question has more than 1 answer )
a) contains value for field of an authorization object
b) defines fields for a complex authorization object
c) can be grouped together in profiles
d) always refer to a particular authorization
e) authorizations and profiles are stored in user master record


4) Using SM35 – in which case does the system check authorization:

( this question has more than 1 answer )
a) always
b) process / foreground
c) display errors only
d) process / background
e) system decides based on profile


5) Search Helps:

( this question has more than 1 answer )
a) called at POV
b) controls how fixed values are displayed when F4 is pressed
c) allow different views of info when help is required
d) object stored in data dictionary
e) field names starting with H_


6) Append Structures

( this question has more than 1 answer )
a) append to table without modifying table itself
b) can be assigned to several tables
c) same as substructure
d) use like any other structure
e) you must convert table once append is added


7) Check table

( this question has more than 1 answer )
a) value table assigned to a domain
b) internal table whose contents are used to check input values
c) table assigned to 1 or more fields if a FK (foreign key) table for checking input values
d) table for which a FK is defined
e) table to which a FK refers

8) Modify SAP objects:

( this question has more than 1 answer )
a) R/3 prevents modifications be user id DDIC and SAP*
b) Objects can be changed with registration
c) Register objects in OSS
d) Carry out modification without registration
e) Adjust modified object in upgrade


9) Activities required at upgrade when applying hot pack:

( this question has more than 1 answer )
a) adjust modified object
b) everything is automatic
c) release correction before update
d) abap dictionary tables, data elements and domains are adjusted during upgrade
e) abap dictionary objects not handled seperately


10) SELECT-OPTIONS COUNTRY FOR LFA1-LAND1:

What will internal table be?
a) LAND1
b) LFA1
c) COUNTRY
d) LFA1-LAND1

11) In program A function module F is called from function group G for the first time. Which one is correct:

a) coding of entire function group G is loaded in the roll area
b) global data from A can be accessed in F
c) A and F have common work areas for dictionary table
d) Function module F is called in a separate internal session
e) Function module F can not call any sessions


12) from transaction A you call transaction B with LEAVE TO TRANSACTION B:

a) internal system session opened for B
b) LEAVE can be used to return from B to A
c) Data from A can be accessed in B
d) A can pass data to B with export
e) A can pass data using SET


13) What is a SAP LUW:

a) a modularised unit in ABAP programs
b) all the updates for 1 SAP transaction
c) a logical grouping of database updates that should all be performed at the same time
d) the section of program code from setting a lock until it is released
e) all actions between first and last database update in transaction

14) Why do update functions have attributes of either START NOW (v1) or START DELAYED(V2):

a) define whether update task triggered immediately
b) combine synchronous and asynchronous updates
c) assign different priorities
d) take different speed of servers into account
e) enable reaction to termination n V1


15) Relationship between SAP transactions and database transactions:

a) each SAP corresponds to one database
b) update requests of one SAP transaction are distributed amongst several database transactions
c) one database group change request of several SAP
d) database transaction is an internal system representation of SAP transactions


Answers:

1) b, c, d
2) b, d
3) a, c
4) b, c, d
5) a, c, d
6) a, d
7) a, c, e
8) b, c, e
9) a, c, d
10) c
11) a
12) a, d, e
13) c
14) c
15) b

What is the difference between SMOD and CMOD? SAP ABAP INTERVIEW Questions

CMOD is the Project Management of SAP Enhancements (i.e., SMOD Enhancements). SMOD contains the actual enhancements and CMOD is the grouping of those SMOD enhancements.

User exits (Function module exits) are exits developed by SAP. The exit is implementerd as a call to a function module. The code for the function module is written by the developer. You are not writing the code directly in the function module, but in the include that is implemented in the function module.

The naming standard of function modules for function module exits is:
EXIT_<3>

The call to a functionmodule exit is implemented as:
CALL CUSTOMER.-FUNCTION <3>

For Example:

The program for transaction VA01 Create salesorder is SAPMV45A

1. If you search for CALL CUSTOMER-FUNCTION program SAPMV45A you will find ( Among other user exits):

CALL CUSTOMER-FUNCTION '003'
exporting
xvbak = vbak
xvbuk = vbuk
xkomk = tkomk
importing
lvf_subrc = lvf_subrc
tables
xvbfa = xvbfa
xvbap = xvbap
xvbup = xvbup.

The exit calls function module EXIT_SAPMV45A_003

2. How to find user exits

Display the program where you are searching for and exit and search for CALL CUSTOMER-EXIT

If you know the Exit name, go to transaction CMOD. Choose menu Utillities->SAP Enhancements.

Enter the exit name and press enter.

You will now come to a screen that shows the function module exits for the exit.

or use this ABAP program to search for user exits :-

Finding the user-exits of a SAP transaction Code

3. Using Project management of SAP Enhancements

You want to create a project to enhance transaction VA01

- Go to transaction CMOD
- Create a project called ZVA01
- Choose the Enhancement assign radio button and press the Change button
In the first column enter V45A0002 Predefine sold-to party in sales document . Note that an enhancement can only be used for 1 project. If the enhancement is allready in use, and error message will be displayed
- Press Save
- Press Components. You can now see that enhancement uses user exit EXIT_SAPMV45A_002.
- Double Click on the exit.
Now the function module is displayed. Double click on include ZXVVAU04 in the function module
Insert the following code into the include: E_KUNNR = '2155'.

Activate the include program. Go back to CMOD and activate the project.
Goto transaction VA01 and create a salesorder. Note that Sold-to-party now automatically is "2155"

Split String into two parts at delimiter SAP ABAP INTERVIEW Questions

*---------------------------------------------------------------------
* 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

String Handling in ABAP - Removing Unwanted Char SAP ABAP INTERVIEW Questions

I am importing data from a file and the string data has HTML tags in the description example Line Clearance, how I can programmatically strip the tags away and just leave the text?


The code for this String Handling



Line Clearance .



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.

System Fields for Details Lists SAP ABAP INTERVIEW Questions

After each user action on a list, the following ABAP system fields will be set in the corresponding event block:





come down
.
.
.



System Field

Information

sy-lsind

Index of the list created during the current event (basic list = 0)

sy-listi

Index of the list level from which the event was triggered

sy-lilli

Absolute number of the line from which the event was triggered

sy-lisel

Contents of the line from which the event was triggered

sy-curow

Position of the line in the window from which the event was triggered (counting starts with 1)

sy-cucol

Position of the column in the window from which the event was triggered (counting starts with 2)

sy-cpage

Page number of the first displayed page of the list from which the event was triggered

sy-staro

Number of the first line of the first page displayed of the list from which the event was triggered (counting starts with 1). This line may contain the page header.

sy-staco

Number of the first column displayed in the list from which the event was triggered (counting starts with 1)

sy-ucomm

Function code that triggered the event

sy-pfkey

Status of the list currently being displayed.


System Landscape: SAP ABAP INTERVIEW Questions

The system landscape contains all systems that were installed. The customer can choose any landscape according to the requirements.

If the customer is very big, one can implement four system landscapes. Mid size customers can go for two system landscape.


Now we will see different system landscapes:


Four System Landscape:

In this landscape, we will find four systems,

1) development system
2) test system
3) pre-production system
4) production system

In development system, we find three clients
100
140
180
100 can be used as configuration client. 140 can be used for development. 180 can be used for testing purpose in development system.

The Test system contains two clients
010
040
010 can be used for testing, where as 040can be used for training purposes.

The pre-production system is the one which behaves exactly as production system. It contains data similar to production system. We can test with similar production data.

Production system contains one client where the end users will be working with real time data supporting day to day business.



System Landscape1 SAP ABAP INTERVIEW Questions

Three system landscape, we will find each dedicated server for development, test and production systems. You can assume the clients like above.

Two system landscape, the development and test systems are combined into one system. One client can be used for development and another can be used for quality. In any landscape, production system will be installed on dedicated server.

One system landscape is not recommended, where all three systems can be installed in a single server.

Three system Landscape example




Table Maintenance Generator SAP ABAP INTERVIEW Questions

In this Post, we will discuss what is table maintenance generator?What is the use of it?

As all of you know, we can create database tables in SAP using transaction code
SE11. A table can be manipulated by a program or manually.

When creating table, you will find a check box 'Table maintenance allowed'. If we
check that option, we can manually enter entries using SE16 or table
maintenance generator screen.

SE16 is for data browser.

How to create table maintenance generator?
Go to SE11, give the table name and click on change. Then Go to utilities--> Table
maintenance generator.

In the table maintenance generator screen, we should give Authorization Group,
Function Group name (Function Group name can be same as table name),
Maintenance type can be one step or two step, usually we will create with one
step. we should give maintenance screen number. After clicking on create button,
a table maintenance generator will be created.

To check it go to SM30 . In SM30, we find display, Maintain options.

We can view the table contents by choosing Display and we can create table
entries by choosing Maintain.

Why we have to go for Table maintenance generator, when we can edit the table
by SE16 or SE11,

utilities->create entries?


Answer.

In the production system, end-users will not be having access to transaction codes like SE11 and SE16. Developers will not be having access to many transaction codes including the above two.

To view the contents of the database table, we will use SE16n in Production system. Please find out the difference between SE16 and SE16n.


All these authorizations will be maintained by BASIS team, by creating access
profiles.

So in order to edit or create the contents of a database table, we should go for
table maintenance generator.

In real time, authorizations will be maintained in production system. (even in development and Test systems to some extent).

There is an audit like Sarbanes-Oxley Act for American clients, where every thing will be audited by government agency.

To know more about SOX, use the links on the right hand side of this page.

TABStrips in ABAP SAP ABAP INTERVIEW Questions

*
* Different Selection Options separated by Tabstrips 1,2 and 3
*
* Written by : SAP Basis, ABAP Programming and Other IMG Stuff
*
*
REPORT ZTABSTRIPS LINE-SIZE 120
NO STANDARD PAGE HEADING.

TABLES: ekko, ekpo, eket, marc, t134h.

*---------------------------------------------------------------------*
* Tab Strips 1
*---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF SCREEN 101 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK vendor WITH FRAME TITLE text-t00.
SELECT-OPTIONS vendor FOR ekko-lifnr.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (10) text-m01.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP.
SELECT-OPTIONS vplant FOR ekko-reswk.
SELECTION-SCREEN END OF BLOCK vendor.
SELECTION-SCREEN END OF SCREEN 101.
*---------------------------------------------------------------------*
* Tab Strips 2
*---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF SCREEN 102 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK data1 WITH FRAME TITLE text-t02.
SELECT-OPTIONS: busarea FOR t134h-gsber,
plant FOR ekpo-werks,
puorg FOR ekko-ekorg.
SELECTION-SCREEN END OF BLOCK data1.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK data2 WITH FRAME TITLE text-t03.
SELECT-OPTIONS sched FOR ekko-ebeln.
SELECT-OPTIONS matl FOR ekpo-matnr.
SELECTION-SCREEN END OF BLOCK data2.
SELECTION-SCREEN END OF SCREEN 102.
*---------------------------------------------------------------------*
* Tab Strips 3
*---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF SCREEN 103 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK rype WITH FRAME TITLE text-t04.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS del RADIOBUTTON GROUP one.
SELECTION-SCREEN COMMENT 4(35) text-c05 FOR FIELD del.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS fix RADIOBUTTON GROUP one.
SELECTION-SCREEN COMMENT 4(35) text-c06 FOR FIELD fix.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK rype.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK interval WITH FRAME TITLE text-t05.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS mon RADIOBUTTON GROUP two.
SELECTION-SCREEN COMMENT 4(15) text-c01 FOR FIELD mon.
PARAMETERS evalmon TYPE spbup.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS wek RADIOBUTTON GROUP two.
SELECTION-SCREEN COMMENT 4(15) text-c02 FOR FIELD wek.
PARAMETERS evalweek TYPE sptag.
SELECTION-SCREEN COMMENT 35(30) text-i01.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK interval.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK type WITH FRAME TITLE text-t01.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS ext RADIOBUTTON GROUP thr.
SELECTION-SCREEN COMMENT 4(15) text-c08 FOR FIELD int.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS int RADIOBUTTON GROUP thr.
SELECTION-SCREEN COMMENT 4(15) text-c07 FOR FIELD ext.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK type.
SELECTION-SCREEN BEGIN OF BLOCK pre WITH FRAME TITLE text-t06.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS vn RADIOBUTTON GROUP slv.
SELECTION-SCREEN COMMENT 4(15) text-c09 FOR FIELD vn.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS bp RADIOBUTTON GROUP slv.
SELECTION-SCREEN COMMENT 4(17) text-c10 FOR FIELD bp.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK pre.
SELECTION-SCREEN END OF SCREEN 103.

SELECTION-SCREEN BEGIN OF TABBED BLOCK uno FOR 20 LINES.
SELECTION-SCREEN TAB (15) name1 USER-COMMAND ucomm1
DEFAULT SCREEN 101.
SELECTION-SCREEN TAB (17) name2 USER-COMMAND ucomm2
DEFAULT SCREEN 102.
SELECTION-SCREEN TAB (23) name3 USER-COMMAND ucomm3
DEFAULT SCREEN 103.
SELECTION-SCREEN END OF BLOCK uno.

INITIALIZATION.
name1 = text-n01.
name2 = text-n02.
name3 = text-n03.

ABAP Tips and Tricks SAP ABAP INTERVIEW Questions

Retrieving the deleted program

I recently deleted a custom program (which is already transported to production) accidentally and was wondering if there is any method of retrieving the program back. After some research, I found a way of getting back the program. Following are the steps in getting back the program:

1) Create a program with the same name as earlier (which is deleted)
2) Click on "Utilities" --> "Versions" --> "Version Management"
3) Select the version of your earlier program and click on display.
4) Your earlier program is displayed here.


Find out in what all Tables a specified field is available.

You can find out through transaction code SE15.

1) Give SE15 on command prompt.
2) Select ABAP Dictionary
3) Select "fields" folder
4) Click on table fields
5) Then you can enter the desired field name (In your case EKGRP)
6) Run OR press F8.

The system will list out all the tables which contain your desired field name.

or

1) using transactin Code SE11( ABAP Dictionary)
2) enter the Data table name where-in the respective field (EKGRP) is used eg; EKKO
3) Click the where -used list button
4) Check out the box(DB tables) Only .

There you can see entire list of tables containing the desired field.

Here the difficulty is that one should know at least the name of the one of the data tables which contain the desired field.


**********

Find the Table Name For a Field.

I know couple of ways to find the table name for a field.
like.
1. Part the cursor at the field and press F1 & F9.
2. se84 or se15
3. st05 (sql trace).
4. Setting Break point in ABAP.

If you will tell other methods it will be apreciate.

**********

*
* How to print Apostrophe using the write statement
* For e.g. You'll be there.
*
report zapostrophe message-id z1.

DATA: LINE(20).

CONCATENATE 'You''' 'll be there.' INTO LINE.

WRITE:/ LINE.

**********

Given a transaction code, how can I find the menu path?

In 4.6c, you can used tcode search_sap_menu to find the SAP MENU tcode.

Please note that there are no tcode available to find the path of the IMG transaction.

**********

How to un-encrypt SAP user password?

It is not possible to un-encrypt the SAP password, because a one-way encoding (with strong 1024 bit key) is used for this. The result is stored and each time one has entered the password the encoding result is checked.

**********

When you delete an entry from an internal table in ABAP, the system has to re-generate the index for all entries after your delete, slowing the report if you have many records to eliminate.

It is much quicker to do an insert of the correct records into a second table than to delete entries from the first. The reason for this is because the index is only generated for the newest element.

**********

If you want to protect a program against debugging, you just have to set the STATUS = S in the attributes view of the main program.

**********

BDC.
When You use a call transaction ,and populate the BDCDATA table.
Make sure you pass the "DATE FIELDS" of any transaction by formatting it as "XX/XX/YYYY" cos if you pick this data from database it will be of the format 20030505 or something like that. Make sure You pass this value as character field.
Same is true for the "Rate Fields". Make sure you pass them as "Character Fields" by formatting them.

**********

If you need to find out the Okcodes for BDC sessions, look for program RSBDCCUA and run it for any platform say 'WN' for windows or MC for Mac and it will generate list of function codes

**********

To save the contents of an internal table as a Microsoft Excel Worksheet when debugging code in SAP R/3 Enterprise:
1. Click on the "Table" button
2. Type in the name of your internal table in the "Internal table" field and hit Enter.
3. Hit CTRL + F11 or click on the "Save as Excel Worksheet" button.
4. Type in the record numbers that you want to save. (Ex. From Line: 1 To Line: 10) Hit Enter.
5. Save your file.

**********

Starts with a Z is homegrown program
You cannot be sure that anything which starts with a Z is a homegrown program.
SAP provide a number of correction programs, especially within the archiving area, which start with a Z.
For e.g. ZZSTOCKL from note 202345.

**********

Can line-size of abap report large than 255?

You can have line-size upto 1023.
Along with Report statement pass the line-size as 1023. Ex. Report xyz line-size 1023.

**********

How to find out the number of days between a given date, excluding Saturdays and Sundays and public holidays?

Try functions,
=> DATE_CONVERT_TO_FACTORYDATE
=> HR_HK_DIFF_BT_2_DATES

Tree type report in ABAP SAP ABAP INTERVIEW Questions

With Compliments from: Ravi

REPORT ZRJNTRIAL_TREE LINE-COUNT 65
LINE-SIZE 80
NO STANDARD PAGE
HEADING.
*********************************************************************
DATA: BEGIN OF ITEMS OCCURS 100,
ID(10),
PARENT_ID(10),
TEXT(20),
SYMBOL,
END OF ITEMS,
TABIX_STACK LIKE SY-TABIX OCCURS 10 WITH HEADER LINE,
ITEMS_SHOW LIKE ITEMS OCCURS 100 WITH HEADER LINE.
INCLUDE .
* append sample items (mixed order)
PERFORM APPEND_ITEM USING:
'1' '' 'Food',
'2' '' 'Drinks',
'12' '9' 'Jack Daniels',
'17' '11' 'Bosch',
'3' '' 'Tools',
'4' '1' 'Meat',
'16' '11' 'Metabo',
'5' '1' 'Chocolate',
'6' '2' 'Alcoholic',
'8' '4' 'Pork',
'10' '5' 'Milka',
'11' '3' 'Drills',
'13' '9' 'Jim Beam',
'7' '4' 'Beef',
'14' '2' 'Non-alcoholic',
'35' '31' 'Teran',
'9' '6' 'Whiskey',
'15' '14' 'Coca-cola',
'18' '6' 'Wine',
'28' '18' 'Croatia',
'33' '28' 'Slavonia',
'34' '28' 'Istria',
'29' '18' 'Hungary',
'30' '29' 'Tokaj',
'19' '33' 'Enjingi',
'20' '33' 'Zdjelarevic',
'22' '19' 'Riesling',
'23' '19' 'Chardonnay',
'24' '20' 'Riesling',
'32' '31' 'Malvazija',
'25' '20' 'Merlot',
'31' '34' 'Tomasevic'.

* show initial list (items with level 0 - parentless items)
LOOP AT ITEMS WHERE PARENT_ID = ''.
MOVE-CORRESPONDING ITEMS TO ITEMS_SHOW.
ITEMS_SHOW-SYMBOL = '+'.
APPEND ITEMS_SHOW.
ENDLOOP.
PERFORM PRINT_TREE TABLES ITEMS_SHOW.

* at line-selection - when the node is opened/closed or item double-clk
AT LINE-SELECTION.
READ TABLE ITEMS WITH KEY PARENT_ID = ITEMS_SHOW-ID. "see 'hide'
IF SY-SUBRC = 0. "item has children - expand or collapse
SY-LSIND = 0.
PERFORM EXPAND_COLLAPSE USING ITEMS_SHOW-ID.
PERFORM PRINT_TREE TABLES ITEMS_SHOW.
ELSE. "item has NO children - perform some action
READ TABLE ITEMS WITH KEY ID = ITEMS_SHOW-ID.
WRITE: 'Action performed on item "' NO-GAP, ITEMS-TEXT NO-GAP,
'", id.', ITEMS-ID.
ENDIF.

* form print_tree
FORM PRINT_TREE TABLES ITEMS STRUCTURE ITEMS.
DATA: V_TABIX LIKE SY-TABIX,
START_TABIX LIKE SY-TABIX,
V_LEVEL LIKE SY-TFILL,
V_OFFSET TYPE I,
V_ID LIKE ITEMS-ID,
V_PARENT_ID LIKE ITEMS-PARENT_ID,
V_PARENT_ID_FOR_VLINE LIKE ITEMS-PARENT_ID,
V_PREV_LEVEL TYPE I,
V_ITEMS_COUNT LIKE SY-TFILL,
V_VLINES_STRING(200).
CHECK NOT ITEMS[] IS INITIAL.
SORT ITEMS BY PARENT_ID ID.
READ TABLE ITEMS INDEX 1.
V_PARENT_ID = ITEMS-PARENT_ID.
START_TABIX = 1.
REFRESH TABIX_STACK.
DO.
LOOP AT ITEMS FROM START_TABIX.
V_TABIX = START_TABIX = SY-TABIX."remember current index
V_ID = ITEMS-ID.
V_PARENT_ID_FOR_VLINE = ITEMS-PARENT_ID.
* decrease level and exit loop if parent not the same as previous
IF ITEMS-PARENT_ID NE V_PARENT_ID.
PERFORM READ_FROM_STACK CHANGING START_TABIX. "level = NoOfRecs
READ TABLE ITEMS INDEX START_TABIX.
V_PARENT_ID = ITEMS-PARENT_ID.
ADD 1 TO START_TABIX. "next loop starts from parent index + 1
* clear vline
IF V_LEVEL > 1.
V_OFFSET = 2 + ( V_LEVEL - 2 ) * 3.
IF V_LEVEL = 1. V_OFFSET = 1. ENDIF.
V_VLINES_STRING+V_OFFSET = ' '.
ENDIF.
EXIT.
ENDIF.
V_PARENT_ID = ITEMS-PARENT_ID.
* write item
FORMAT COLOR OFF.
DESCRIBE TABLE TABIX_STACK LINES V_LEVEL."level is no of
StackRecs
WRITE: / V_VLINES_STRING.
V_OFFSET = V_LEVEL * 3.
IF V_LEVEL NE 0.
IF V_PREV_LEVEL < v_offset =" V_LEVEL" v_offset =" V_OFFSET" v_prev_level =" V_LEVEL." parent_id =" ITEMS-ID." subrc =" 0." start_tabix =" SY-TABIX." v_parent_id =" ITEMS-PARENT_ID." v_tabix =" V_TABIX" v_offset =" 2"> 0.
IF ITEMS-PARENT_ID = V_PARENT_ID_FOR_VLINE AND SY-SUBRC = 0.
V_VLINES_STRING+V_OFFSET = '|'.
ELSE.
V_VLINES_STRING+V_OFFSET = ' '.
ENDIF.
ENDIF.
EXIT.
ENDIF.
* at last - decrease level
AT LAST.
* clear vline
IF V_LEVEL > 1.
V_OFFSET = 2 + ( V_LEVEL - 2 ) * 3.
IF V_LEVEL = 1. V_OFFSET = 1. ENDIF.
V_VLINES_STRING+V_OFFSET = ' '.
ENDIF.
" next loop starts from parent index, not parent index + 1
" because of different parents level will decrease anyway
PERFORM READ_FROM_STACK CHANGING START_TABIX.
APPEND START_TABIX TO TABIX_STACK. "must return index to stack
ENDAT.
ENDLOOP.
DESCRIBE TABLE ITEMS.
IF START_TABIX > SY-TFILL OR V_ITEMS_COUNT >= SY-TFILL.
EXIT.
ENDIF.
ENDDO.
ENDFORM.

* form expand_collapse
FORM EXPAND_COLLAPSE USING VALUE(V_ID).
DATA: V_NO_MORE_ORPHANS,
ITEMS_TEMP LIKE ITEMS OCCURS 100 WITH HEADER LINE.
DELETE ITEMS_SHOW WHERE PARENT_ID = V_ID. "try to collapse
IF SY-SUBRC = 0. "succesfull first collapse
DO. "cascade collapse - delete 'orphans' that are left
REFRESH ITEMS_TEMP.
MOVE ITEMS_SHOW[] TO ITEMS_TEMP[].
SORT ITEMS_TEMP BY ID.
V_NO_MORE_ORPHANS = 'X'.
LOOP AT ITEMS_SHOW WHERE PARENT_ID NE ''.
READ TABLE ITEMS_TEMP WITH KEY ID = ITEMS_SHOW-PARENT_ID
BINARY SEARCH TRANSPORTING NO FIELDS.
IF SY-SUBRC NE 0. "no parent - it's an orphan
CLEAR V_NO_MORE_ORPHANS.
DELETE ITEMS_SHOW.
ENDIF.
ENDLOOP.
IF V_NO_MORE_ORPHANS = 'X'. EXIT. ENDIF.
ENDDO.
ITEMS_SHOW-SYMBOL = '+'.
MODIFY ITEMS_SHOW TRANSPORTING SYMBOL WHERE ID = V_ID.
ELSE. "unsuccessfull collapse - expand
ITEMS_SHOW-SYMBOL = '-'.
MODIFY ITEMS_SHOW TRANSPORTING SYMBOL WHERE ID = V_ID.
LOOP AT ITEMS WHERE PARENT_ID = V_ID. "show children
APPEND ITEMS TO ITEMS_SHOW.
ENDLOOP.
LOOP AT ITEMS_SHOW WHERE PARENT_ID = V_ID. "check grandchildren
READ TABLE ITEMS WITH KEY PARENT_ID = ITEMS_SHOW-ID.
IF SY-SUBRC = 0.
ITEMS_SHOW-SYMBOL = '+'.
ELSE.
ITEMS_SHOW-SYMBOL = ''.
ENDIF.
MODIFY ITEMS_SHOW.
ENDLOOP.
ENDIF.
ENDFORM.

* form append_item
FORM APPEND_ITEM USING VALUE(ID) VALUE(PARENT_ID) VALUE(TEXT).
ITEMS-ID = ID.
ITEMS-PARENT_ID = PARENT_ID.
ITEMS-TEXT = TEXT.
APPEND ITEMS.
ENDFORM.

* form read_from_stack
FORM READ_FROM_STACK CHANGING TABIX LIKE SY-TABIX.
DESCRIBE TABLE TABIX_STACK.
CHECK SY-TFILL NE 0.
READ TABLE TABIX_STACK INDEX SY-TFILL.
TABIX = TABIX_STACK.
DELETE TABIX_STACK INDEX SY-TFILL.
ENDFORM.

Explain Unicode-enabled ABAP program SAP ABAP INTERVIEW Questions

ABAP Development under Unicode


Prior to Unicode the length of a character was exactly one byte, allowing implicit typecasts or memory-layout oriented programming. With Unicode this situation has changed: One character is no longer one byte, so that additional specifications have to be added to define the unit of measure for implicit or explicit references to (the length of) characters.


Character-like data in ABAP are always represented with the UTF-16 - standard (also used in Java or other development tools like Microsoft's Visual Basic); but this format is not related to the encoding of the underlying database.


A Unicode-enabled ABAP program (UP) is a program in which all Unicode checks are effective. Such a program returns the same results in a non-Unicode system (NUS) as in a Unicode system (US). In order to perform the relevant syntax checks, you must activate the Unicode flag in the screens of the program and class attributes.


In a US, you can only execute programs for which the Unicode flag is set. In future, the Unicode flag must be set for all SAP programs to enable them to run on a US. If the Unicode flag is set for a program, the syntax is checked and the program executed according to the rules described in this document, regardless of whether the system is a US or a NUS. From now on, the Unicode flag must be set for all new programs and classes that are created.


If the Unicode flag is not set, a program can only be executed in an NUS. The syntactical and semantic changes described below do not apply to such programs. However, you can use all language extensions that have been introduced in the process of the conversion to Unicode.


As a result of the modifications and restrictions associated with the Unicode flag, programs are executed in both Unicode and non-Unicode systems with the same semantics to a large degree. In rare cases, however, differences may occur. Programs that are designed to run on both systems therefore need to be tested on both platforms.

Source Code Listing SAP ABAP INTERVIEW Questions

*----------------------------------------------------------------------*
* Report: ZKBPROGS *
*----------------------------------------------------------------------*
* Function : Up/Download ABAP reports complete with texts *
*----------------------------------------------------------------------*
* Change Log : *
* July 5, 1999 *
* - Combined existing programs that did the upload and download into*
* - one program. *
* - Changed format that the reports are saved in to be compatible *
* with Wolfgang Morgenthaler's upload/download program(YSTRASN00 *
* at www.antarcon.de). Major differences between this program and*
* Wolfgang's are:
* - this program does not update TRDIR with the *
* TRDIR entries that are in the program uploaded. Instead, *
* current users stats are used. *
* - this program allows selection of reports from a list or *
* a single report can be tuped in and uploaded *
* - this program also updates TADIR so that a development class*
* is assigned to the program *
* - this program checks to see if the program already has a *
* TRDIR entry, and if it does, warns the user *
* - this program will save/restore the program documenation too*
* *
* *
* *
*----------------------------------------------------------------------*
REPORT ZKBPROGS
NO STANDARD PAGE HEADING
LINE-SIZE 255.
*----------------------------------------------------------------------*
* Declare Database Objects *
*----------------------------------------------------------------------*
tables:
DOKIL,
TRDIR.
*----------------------------------------------------------------------*
* Constants*
CONSTANTS:
MC_TRDIR_IDENTIFIER(72) TYPE C VALUE '%&%& RDIR',
MC_REPORT_IDENTIFIER(72) TYPE C VALUE '%&%& REPO',
MC_TEXT_IDENTIFIER(72) TYPE C VALUE '%&%& TEXP',
MC_THEAD_IDENTIFIER(72) TYPE C VALUE '%&%& HEAD',
MC_DOC_IDENTIFIER(72) TYPE C VALUE '%&%& DOKL',
MC_TRDIR_SHORT(4) TYPE C VALUE 'RDIR',
MC_REPORT_SHORT(4) TYPE C VALUE 'REPO',
MC_TEXT_SHORT(4) TYPE C VALUE 'TEXP',
MC_THEAD_SHORT(4) TYPE C VALUE 'HEAD',
MC_DOC_SHORT(4) TYPE C VALUE 'DOKP'.
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* Declare Module level data structures *
*----------------------------------------------------------------------*
DATA: BEGIN OF MTAB_PROGRAM_SOURCE OCCURS 0,
LINE(72) TYPE C,
END OF MTAB_PROGRAM_SOURCE.
DATA: MTAB_PROGRAM_TRDIR LIKE TRDIR OCCURS 0 WITH HEADER LINE.
DATA: MTAB_PROGRAM_TEXTS LIKE TEXTPOOL OCCURS 0 WITH HEADER LINE.
DATA: MSTR_THEAD LIKE THEAD.
DATA: BEGIN OF MTAB_PROGRAM_FILE OCCURS 0,
LINE(275) TYPE C,
END OF MTAB_PROGRAM_FILE.
DATA: BEGIN OF MTAB_DIRECTORY OCCURS 0,
NAME LIKE TRDIR-NAME,
DESC(72) TYPE C,
SAVENAME LIKE RLGRAP-FILENAME,
END OF MTAB_DIRECTORY.
DATA: BEGIN OF MTAB_PROGRAM_DOCUMENTATION OCCURS 0,
LINE(255) TYPE C,
END OF MTAB_PROGRAM_DOCUMENTATION.
*----------------------------------------------------------------------*
* Selection Screen *
*----------------------------------------------------------------------*
*-- Options for upload/download of programs
SELECTION-SCREEN BEGIN OF BLOCK FRM_OPTIONS WITH FRAME TITLE TEXT-UDL.
PARAMETERS:
RB_DOWN RADIOBUTTON GROUP UDL DEFAULT 'X'. " Download reports
SELECTION-SCREEN BEGIN OF BLOCK FRM_TRDIR WITH FRAME TITLE TEXT-DIR.
SELECT-OPTIONS:
S_NAME FOR TRDIR-NAME, " Program Name
S_SUBC FOR TRDIR-SUBC " Program Type
DEFAULT 'F' OPTION EQ SIGN E," Exclude Functions by default
S_CNAM FOR TRDIR-CNAM " Created by
DEFAULT SY-UNAME,
S_UNAM FOR TRDIR-UNAM, " Last Changed by
S_CDAT FOR TRDIR-CDAT, " Creation date
S_UDAT FOR TRDIR-UDAT. " Last update date
SELECTION-SCREEN END OF BLOCK FRM_TRDIR.
*-- Options for uploading programs
PARAMETERS:
RB_UP RADIOBUTTON GROUP UDL. " Upload reports
SELECTION-SCREEN BEGIN OF BLOCK FRM_UPLOAD WITH FRAME TITLE TEXT-UPL.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(29) TEXT-SNG.
PARAMETERS:
RB_FILE RADIOBUTTON GROUP HOW DEFAULT 'X'.
SELECTION-SCREEN COMMENT 33(42) TEXT-FNA.
SELECTION-SCREEN END OF LINE.
PARAMETERS:
RB_LIST RADIOBUTTON GROUP HOW.
SELECTION-SCREEN END OF BLOCK FRM_UPLOAD.
SELECTION-SCREEN END OF BLOCK FRM_OPTIONS.
*-- Options for up/downloading programs
SELECTION-SCREEN BEGIN OF BLOCK FRM_FILEN WITH FRAME TITLE TEXT-FIL.
PARAMETERS:
RB_DOS RADIOBUTTON GROUP FIL DEFAULT 'X', " Save to local
RB_UNIX RADIOBUTTON GROUP FIL, " Save to UNIX
P_PATH LIKE RLGRAP-FILENAME " Path to save files to
DEFAULT 'c:\temp\'.
SELECTION-SCREEN END OF BLOCK FRM_FILEN.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_NAME-LOW.
CALL FUNCTION 'F4_PROGRAM'
EXPORTING
OBJECT = S_NAME-LOW
SUPPRESS_SELECTION = 'X'
IMPORTING
RESULT = S_NAME-LOW
EXCEPTIONS
OTHERS = 1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_NAME-HIGH.
CALL FUNCTION 'F4_PROGRAM'
EXPORTING
OBJECT = S_NAME-HIGH
SUPPRESS_SELECTION = 'X'
IMPORTING
RESULT = S_NAME-HIGH
EXCEPTIONS
OTHERS = 1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_UNAM-LOW.
PERFORM GET_NAME USING 'S_UNAM-LOW'
CHANGING S_UNAM-LOW.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_UNAM-HIGH.
PERFORM GET_NAME USING 'S_UNAM-HIGH'
CHANGING S_UNAM-HIGH.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_CNAM-LOW.
PERFORM GET_NAME USING 'S_CNAM-LOW'
CHANGING S_CNAM-LOW.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_CNAM-HIGH.
PERFORM GET_NAME USING 'S_CNAM-HIGH'
CHANGING S_CNAM-HIGH.
TOP-OF-PAGE.
IF RB_LIST = 'X'.
FORMAT COLOR COL_HEADING.
NEW-LINE.
WRITE: AT 3 TEXT-H01,
AT 15 TEXT-H03.
FORMAT COLOR OFF.
ENDIF.
AT LINE-SELECTION.
CHECK RB_LIST = 'X'. " only do in list mode
READ LINE SY-CUROW FIELD VALUE MTAB_DIRECTORY-SAVENAME.
*-- Read file into an internal table
PERFORM READ_REPORT_FROM_DISK TABLES MTAB_PROGRAM_FILE
USING MTAB_DIRECTORY-SAVENAME.
*-- Split table into TADIR entry, report lines, and report text
PERFORM SPLIT_INCOMING_FILE TABLES MTAB_PROGRAM_FILE
MTAB_PROGRAM_SOURCE
MTAB_PROGRAM_TEXTS
MTAB_PROGRAM_DOCUMENTATION
CHANGING TRDIR
MSTR_THEAD.
*-- Save all of the data
PERFORM INSERT_NEW_REPORT TABLES MTAB_PROGRAM_SOURCE
MTAB_PROGRAM_TEXTS
MTAB_PROGRAM_DOCUMENTATION
USING TRDIR
MSTR_THEAD.
*----------------------------------------------------------------------*
* Start of processing *
*----------------------------------------------------------------------*
START-OF-SELECTION.
FORMAT COLOR COL_NORMAL.
IF RB_DOWN = 'X'.
PERFORM DOWNLOAD_REPORTS.
ELSEIF RB_UP = 'X'.
PERFORM UPLOAD_REPORTS.
ENDIF.
END-OF-SELECTION.
IF RB_DOWN = 'X'.
CONCATENATE P_PATH
'directory.txt'
INTO P_PATH.
PERFORM SAVE_TABLE_TO_FILE TABLES MTAB_DIRECTORY
USING P_PATH.
ENDIF.
*---------------------------------------------------------------------*
* FORM UPLOAD_REPORTS *
*---------------------------------------------------------------------*
FORM UPLOAD_REPORTS.
*-- Can upload a reports entered in selection criteria or
*-- select from a list. List can be from index.txt in same directory
*-- (created by the download) or by reading the first line of each file
*-- in the directory.
IF RB_FILE = 'X'. " Upload single program from a file
*-- Read file into an internal table
PERFORM READ_REPORT_FROM_DISK TABLES MTAB_PROGRAM_FILE
USING P_PATH.
*-- Split table into TADIR entry, report lines, and report text
PERFORM SPLIT_INCOMING_FILE TABLES MTAB_PROGRAM_FILE
MTAB_PROGRAM_SOURCE
MTAB_PROGRAM_TEXTS
MTAB_PROGRAM_DOCUMENTATION
CHANGING TRDIR
MSTR_THEAD.
*-- Save all of the data
PERFORM INSERT_NEW_REPORT TABLES MTAB_PROGRAM_SOURCE
MTAB_PROGRAM_TEXTS
MTAB_PROGRAM_DOCUMENTATION
USING TRDIR
MSTR_THEAD.
ELSEIF RB_LIST = 'X'. " Show list for user to choose from
*-- get list of report names/descriptions from directory text
CONCATENATE P_PATH
'directory.txt'
INTO P_PATH.
PERFORM READ_REPORT_FROM_DISK TABLES MTAB_DIRECTORY
USING P_PATH.
SORT MTAB_DIRECTORY.
*-- Write out list of report names/descriptions
LOOP AT MTAB_DIRECTORY.
WRITE:
/ MTAB_DIRECTORY-NAME UNDER TEXT-H01,
MTAB_DIRECTORY-DESC UNDER TEXT-H03,
MTAB_DIRECTORY-SAVENAME.
ENDLOOP.
*-- Process user selections for reports to upload.
ENDIF.
ENDFORM. " upload_reports
*---------------------------------------------------------------------*
* FORM DOWNLOAD_REPORTS *
*---------------------------------------------------------------------*
* From the user selections, get all programs that meet the *
* criteria, and save them in ftab_program_directory. *
* Also save the report to disk. *
*---------------------------------------------------------------------*
FORM DOWNLOAD_REPORTS.
DATA:
LC_FULL_FILENAME LIKE RLGRAP-FILENAME.
*-- The table is put into an internal table because the program will
*-- abend if multiple transfers to a dataset occur within a SELECT/
*-- ENDSELCT (tested on 3.1H)
SELECT * FROM TRDIR
INTO TABLE MTAB_PROGRAM_TRDIR
WHERE NAME IN S_NAME
AND SUBC IN S_SUBC
AND CNAM IN S_CNAM
AND UNAM IN S_UNAM
AND CDAT IN S_CDAT
AND UDAT IN S_UDAT.
LOOP AT MTAB_PROGRAM_TRDIR.
*-- Clear out text and source code tables
CLEAR:
MTAB_PROGRAM_FILE,
MTAB_PROGRAM_SOURCE,
MTAB_PROGRAM_TEXTS,
MTAB_PROGRAM_DOCUMENTATION.
REFRESH:
MTAB_PROGRAM_FILE,
MTAB_PROGRAM_SOURCE,
MTAB_PROGRAM_TEXTS,
MTAB_PROGRAM_DOCUMENTATION.
*-- Get the report
READ REPORT MTAB_PROGRAM_TRDIR-NAME INTO MTAB_PROGRAM_SOURCE.
*-- Get the text for the report
READ TEXTPOOL MTAB_PROGRAM_TRDIR-NAME INTO MTAB_PROGRAM_TEXTS.
*-- Get the documentation for the report
CLEAR DOKIL.
SELECT * UP TO 1 ROWS FROM DOKIL
WHERE ID = 'RE'
AND OBJECT = MTAB_PROGRAM_TRDIR-NAME
AND LANGU = SY-LANGU
AND TYP = 'E'
ORDER BY VERSION DESCENDING.
ENDSELECT.
*-- Documentation exists for this object
IF SY-SUBRC = 0.
CALL FUNCTION 'DOCU_READ'
EXPORTING
ID = DOKIL-ID
LANGU = DOKIL-LANGU
OBJECT = DOKIL-OBJECT
TYP = DOKIL-TYP
VERSION = DOKIL-VERSION
IMPORTING
HEAD = MSTR_THEAD
TABLES
LINE = MTAB_PROGRAM_DOCUMENTATION
EXCEPTIONS
OTHERS = 1.
ENDIF.
*-- Put the report code and texts into a single file
*-- Put the identifier line in so that the start of the TRDIR line
*-- is marked
CONCATENATE MC_TRDIR_IDENTIFIER
MTAB_PROGRAM_TRDIR-NAME
INTO MTAB_PROGRAM_FILE-LINE.
APPEND MTAB_PROGRAM_FILE.
*-- Add the TRDIR line
MTAB_PROGRAM_FILE-LINE = MTAB_PROGRAM_TRDIR.
APPEND MTAB_PROGRAM_FILE.
*-- Put the identifier line in so that the start of the report code
*-- is marked
CONCATENATE MC_REPORT_IDENTIFIER
MTAB_PROGRAM_TRDIR-NAME
INTO MTAB_PROGRAM_FILE-LINE.
APPEND MTAB_PROGRAM_FILE.
*-- Add the report code
LOOP AT MTAB_PROGRAM_SOURCE.
MTAB_PROGRAM_FILE = MTAB_PROGRAM_SOURCE.
APPEND MTAB_PROGRAM_FILE.
ENDLOOP.
*-- Put the identifier line in so that the start of the report text
*-- is marked
CONCATENATE MC_TEXT_IDENTIFIER
MTAB_PROGRAM_TRDIR-NAME
INTO MTAB_PROGRAM_FILE-LINE.
APPEND MTAB_PROGRAM_FILE.
*-- Add the report texts
LOOP AT MTAB_PROGRAM_TEXTS.
MTAB_PROGRAM_FILE = MTAB_PROGRAM_TEXTS.
APPEND MTAB_PROGRAM_FILE.
ENDLOOP.
*-- Put the identifier line in so that the start of the THEAD record
*-- is marked
CONCATENATE MC_THEAD_IDENTIFIER
MTAB_PROGRAM_TRDIR-NAME
INTO MTAB_PROGRAM_FILE-LINE.
APPEND MTAB_PROGRAM_FILE.
MTAB_PROGRAM_FILE = MSTR_THEAD.
APPEND MTAB_PROGRAM_FILE.
*-- Put the identifier line in so that the start of the report
*-- documentation is marked
CONCATENATE MC_DOC_IDENTIFIER
MTAB_PROGRAM_TRDIR-NAME
INTO MTAB_PROGRAM_FILE-LINE.
APPEND MTAB_PROGRAM_FILE.
*-- Add the report documentation
LOOP AT MTAB_PROGRAM_DOCUMENTATION.
MTAB_PROGRAM_FILE = MTAB_PROGRAM_DOCUMENTATION.
APPEND MTAB_PROGRAM_FILE.
ENDLOOP.
*-- Make the fully pathed filename that report will be saved to
CONCATENATE P_PATH
MTAB_PROGRAM_TRDIR-NAME
'.txt'
INTO LC_FULL_FILENAME.
PERFORM SAVE_TABLE_TO_FILE TABLES MTAB_PROGRAM_FILE
USING LC_FULL_FILENAME.
*-- Write out message with Program Name/Description
READ TABLE MTAB_PROGRAM_TEXTS WITH KEY ID = 'R'.
IF SY-SUBRC = 0.
MTAB_DIRECTORY-NAME = MTAB_PROGRAM_TRDIR-NAME.
MTAB_DIRECTORY-DESC = MTAB_PROGRAM_TEXTS-ENTRY.
MTAB_DIRECTORY-SAVENAME = LC_FULL_FILENAME.
APPEND MTAB_DIRECTORY.
WRITE: / MTAB_PROGRAM_TRDIR-NAME,
MTAB_PROGRAM_TEXTS-ENTRY(65) COLOR COL_HEADING.
ELSE.
MTAB_DIRECTORY-NAME = MTAB_PROGRAM_TRDIR-NAME.
MTAB_DIRECTORY-DESC = 'No description available'.
MTAB_DIRECTORY-SAVENAME = LC_FULL_FILENAME.
APPEND MTAB_DIRECTORY.
WRITE: / MTAB_PROGRAM_TRDIR-NAME.
ENDIF.
ENDLOOP.
ENDFORM. " BUILD_PROGRAM_DIRECTORY
*---------------------------------------------------------------------*
* FORM SAVE_TABLE_TO_FILE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> FTAB_TABLE *
* --> F_FILENAME *
*---------------------------------------------------------------------*
FORM SAVE_TABLE_TO_FILE TABLES FTAB_TABLE
USING F_FILENAME.
IF RB_DOS = 'X'. " Save file to presentation server
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
FILENAME = F_FILENAME
FILETYPE = 'ASC'
TABLES
DATA_TAB = FTAB_TABLE
EXCEPTIONS
OTHERS = 4.
IF SY-SUBRC NE 0.
WRITE: / 'Error opening dataset' COLOR COL_NEGATIVE,
F_FILENAME COLOR COL_NEGATIVE.
ENDIF.
ELSE. " Save file to application server
OPEN DATASET F_FILENAME FOR OUTPUT IN TEXT MODE.
IF SY-SUBRC = 0.
LOOP AT FTAB_TABLE.
TRANSFER FTAB_TABLE TO F_FILENAME.
IF SY-SUBRC NE 0.
WRITE: / 'Error writing record to file;' COLOR COL_NEGATIVE,
F_FILENAME COLOR COL_NEGATIVE.
ENDIF.
ENDLOOP.
ELSE.
WRITE: / 'Error opening dataset' COLOR COL_NEGATIVE,
F_FILENAME COLOR COL_NEGATIVE.
ENDIF.
ENDIF. " End RB_DOS
ENDFORM. " SAVE_PROGRAM
*---------------------------------------------------------------------*
* FORM READ_REPORT_FROM_DISK *
*---------------------------------------------------------------------*
* Read report into internal table. Can read from local or *
* remote computer *
*---------------------------------------------------------------------*
FORM READ_REPORT_FROM_DISK TABLES FTAB_TABLE
USING F_FILENAME.
DATA:
LC_MESSAGE(128) TYPE C.
CLEAR FTAB_TABLE.
REFRESH FTAB_TABLE.
IF RB_DOS = 'X'.
TRANSLATE F_FILENAME USING '/\'. " correct slash for Dos PC file
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = F_FILENAME
FILETYPE = 'ASC'
TABLES
DATA_TAB = FTAB_TABLE
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TABLE_WIDTH = 4
INVALID_TYPE = 5
NO_BATCH = 6
UNKNOWN_ERROR = 7
OTHERS = 8.
IF SY-SUBRC >< 0.
WRITE: / 'Error reading file from local PC' COLOR COL_NEGATIVE.
ENDIF.
ELSEIF RB_UNIX = 'X'.
TRANSLATE F_FILENAME USING '\/'. " correct slash for unix
OPEN DATASET F_FILENAME FOR INPUT MESSAGE LC_MESSAGE IN TEXT MODE.
IF SY-SUBRC = 0.
DO.
READ DATASET F_FILENAME INTO FTAB_TABLE.
IF SY-SUBRC = 0.
APPEND FTAB_TABLE.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET F_FILENAME.
ELSE.
WRITE: / 'Error reading file from remote computer'
COLOR COL_NEGATIVE,
/ LC_MESSAGE,
/ F_FILENAME.
SY-SUBRC = 4.
ENDIF.
ENDIF.


ENDFORM. " READ_REPORT_FROM_DISK
*---------------------------------------------------------------------*
* FORM SPLIT_INCOMING_FILE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> FTAB_PROGRAM_FILE *
* --> FTAB_PROGRAM_SOURCE *
* --> ` *
* --> FTAB_PROGRAM_TEXTS *
*---------------------------------------------------------------------*
FORM SPLIT_INCOMING_FILE TABLES FTAB_PROGRAM_FILE
STRUCTURE MTAB_PROGRAM_FILE
FTAB_PROGRAM_SOURCE
STRUCTURE MTAB_PROGRAM_SOURCE
FTAB_PROGRAM_TEXTS
STRUCTURE MTAB_PROGRAM_TEXTS
FTAB_PROGRAM_DOCUMENTATION
STRUCTURE MTAB_PROGRAM_DOCUMENTATION
CHANGING FSTR_TRDIR
FSTR_THEAD.
DATA:
LC_DATATYPE(4) TYPE C, " Type of data, REPO, TEXP, RDIR
LC_PROGRAM_FILE LIKE MTAB_PROGRAM_FILE.
LOOP AT FTAB_PROGRAM_FILE.
LC_PROGRAM_FILE = FTAB_PROGRAM_FILE.
CASE LC_PROGRAM_FILE(9).
WHEN MC_TRDIR_IDENTIFIER.
LC_DATATYPE = MC_TRDIR_SHORT.
WHEN MC_REPORT_IDENTIFIER.
LC_DATATYPE = MC_REPORT_SHORT.
WHEN MC_TEXT_IDENTIFIER.
LC_DATATYPE = MC_TEXT_SHORT.
WHEN MC_DOC_IDENTIFIER.
LC_DATATYPE = MC_DOC_SHORT.
WHEN MC_THEAD_IDENTIFIER.
LC_DATATYPE = MC_THEAD_SHORT.
WHEN OTHERS. " Actual contents of report, trdir, or text
CASE LC_DATATYPE.
WHEN MC_TRDIR_SHORT.
FSTR_TRDIR = FTAB_PROGRAM_FILE.
WHEN MC_REPORT_SHORT.
FTAB_PROGRAM_SOURCE = FTAB_PROGRAM_FILE.
APPEND FTAB_PROGRAM_SOURCE.
WHEN MC_TEXT_SHORT.
FTAB_PROGRAM_TEXTS = FTAB_PROGRAM_FILE.
APPEND FTAB_PROGRAM_TEXTS.
WHEN MC_THEAD_SHORT.
FSTR_THEAD = FTAB_PROGRAM_FILE.
WHEN MC_DOC_SHORT.
FTAB_PROGRAM_DOCUMENTATION = FTAB_PROGRAM_FILE.
APPEND FTAB_PROGRAM_DOCUMENTATION.
ENDCASE.
ENDCASE.
ENDLOOP.
ENDFORM. " SPLIT_INCOMING_FILE
*---------------------------------------------------------------------*
* FORM INSERT_NEW_REPORT*
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> FTAB_PROGRAM_SOURCE *
* --> FTAB_PROGRAM_TEXTS *
* --> F_TRDIR *
*---------------------------------------------------------------------*
FORM INSERT_NEW_REPORT TABLES FTAB_PROGRAM_SOURCE
STRUCTURE MTAB_PROGRAM_SOURCE
FTAB_PROGRAM_TEXTS
STRUCTURE MTAB_PROGRAM_TEXTS
FTAB_PROGRAM_DOCUMENTATION
STRUCTURE MTAB_PROGRAM_DOCUMENTATION
USING FSTR_TRDIR LIKE TRDIR
FSTR_THEAD LIKE MSTR_THEAD.
DATA:
LC_OBJ_NAME LIKE E071-OBJ_NAME,
LC_LINE2(40) TYPE C,
LC_ANSWER(1) TYPE C.
*-- read trdir to see if the report already exists, if it does, prompt
*-- user to overwrite or abort.
SELECT SINGLE * FROM TRDIR WHERE NAME = FSTR_TRDIR-NAME.
IF SY-SUBRC = 0. " Already exists
CONCATENATE 'want to overwrite report'
FSTR_TRDIR-NAME
INTO LC_LINE2 SEPARATED BY SPACE.
CONCATENATE LC_LINE2
'?'
INTO LC_LINE2.
CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
EXPORTING
DEFAULTOPTION = 'N'
TEXTLINE1 = 'The selected report already exists, do you'
TEXTLINE2 = LC_LINE2
TITEL = 'Report already exists'
CANCEL_DISPLAY = SPACE
IMPORTING
ANSWER = LC_ANSWER
EXCEPTIONS
OTHERS = 1.
ELSE.
LC_ANSWER = 'J'.
ENDIF.
IF LC_ANSWER = 'J'.
*-- Create the TADIR entry. (TRDIR entry created by INSERT REPORT)
LC_OBJ_NAME = TRDIR-NAME.
CALL FUNCTION 'TR_TADIR_POPUP_ENTRY_E071'
EXPORTING
WI_E071_PGMID = 'R3TR'
WI_E071_OBJECT = 'PROG'
WI_E071_OBJ_NAME = LC_OBJ_NAME
WI_TADIR_DEVCLASS = '$TMP'
EXCEPTIONS
EXIT = 3
OTHERS = 4.
IF SY-SUBRC = 0.
*-- Create Report
INSERT REPORT FSTR_TRDIR-NAME FROM FTAB_PROGRAM_SOURCE.
*-- Create Texts
INSERT TEXTPOOL FSTR_TRDIR-NAME FROM FTAB_PROGRAM_TEXTS
LANGUAGE SY-LANGU.
*-- Save Documentation
CALL FUNCTION 'DOCU_UPDATE'
EXPORTING
HEAD = FSTR_THEAD
STATE = 'A'
TYP = 'E'
VERSION = '1'
TABLES
LINE = FTAB_PROGRAM_DOCUMENTATION
EXCEPTIONS
OTHERS = 1.
ELSE.
WRITE: / 'Error updating the TADIR entry' COLOR COL_NEGATIVE,
'Program' COLOR COL_NEGATIVE INTENSIFIED OFF,
FSTR_TRDIR-NAME, 'was not loaded into SAP.'
COLOR COL_NEGATIVE INTENSIFIED OFF.
ENDIF.
ELSE.
WRITE: / FSTR_TRDIR-NAME COLOR COL_NEGATIVE,
'was not uploaded into SAP. Action cancelled by user'
COLOR COL_NEGATIVE INTENSIFIED OFF.
ENDIF.
ENDFORM. " INSERT_NEW_REPORT
*---------------------------------------------------------------------*
* FORM GET_NAME *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> VALUE(F_FIELD) *
* --> F_NAME *
*---------------------------------------------------------------------*
FORM GET_NAME USING VALUE(F_FIELD)
CHANGING F_NAME.
DATA: LTAB_FIELDS LIKE DYNPREAD OCCURS 0 WITH HEADER LINE,
LC_PROG LIKE D020S-PROG,
LC_DNUM LIKE D020S-DNUM.
TRANSLATE F_FIELD TO UPPER CASE.
refresh ltab_fields.
LTAB_FIELDS-FIELDNAME = F_FIELD.
append ltab_fields.
LC_PROG = SY-REPID .
LC_DNUM = SY-DYNNR .
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
DYNAME = LC_PROG
DYNUMB = LC_DNUM
TABLES
dynpfields = ltab_fields
EXCEPTIONS
OTHERS = 01.
read table ltab_fields index 1.
IF SY-SUBRC EQ 0.
F_NAME = LTAB_FIELDS-FIELDVALUE.
refresh ltab_fields.
ENDIF.
CALL FUNCTION 'F4_USER'
EXPORTING
OBJECT = F_NAME
IMPORTING
RESULT = F_NAME.
ENDFORM. " GET_NAME.




Program Texts


DIR File Download Options (File Selection)



FIL File Options



FNA Enter filename below (under File Options)



H01 Prog Name



H03 Program Description



SNG Upload a single file



UDL Upload to SAP/Download from SAP



UPL File Upload Options



R Backup/Restore program source code with texts



P_PATH Path to save programs to



RB_DOS Files on local computer



RB_DOWN Download Programs



RB_FILE Upload a single file



RB_LIST Select program(s) from a list



RB_UNIX Files on remote computer



RB_UP Upload Programs to SAP



S_CDAT Date Created



S_CNAM Created by UserID



S_NAME Program Name



S_SUBC Program Type



S_UDAT Date Changed



S_UNAM Last Changed by UserID

Content

Recent Topics