Category Archives for "ABAP"

ABAP read table with OR condition in SAP

So is it possible to add an OR condition to the key values of the read statement? The simple answer is no, but you can replicate this functionality using one of two methods.

Method 1 - Using multiple ABAP READ statements within nested IF statements

The first method would be to use multiple READ statements to check each condition but nest these within IF statements.

i.e. Read condition 1
if no entry found read condition 2
if no entry found read condition 3 etc etc

Method 2 - Using an ABAP LOOP statement

The second method would be to use a LOOP statement with all the options within the where clause and simply EXIT on the first loop pass.

i.e.LOOP at itab where condition 1 or condition 2.
EXIT.
ENDLOOP.
If sy-subrc eq 0.
"Data found
endif.

data: IT_COMPONENT type standard table of SEOCOMPO,
WA_COMPONENT like line of IT_COMPONENT.
select *
from SEOCOMPO as A inner join SEOCOMPOTX as B
on B~CLSNAME = A~CLSNAME
and B~CMPNAME = A~CMPNAME
inner join SEOCOMPODF as C
on C~CLSNAME = A~CLSNAME
and C~CMPNAME = A~CMPNAME
into corresponding fields of table IT_COMPONENT
where A~CMPTYPE in (0,1,2)
and B~LANGU eq SY-LANGU.
sort IT_COMPONENT by clsname cmptype.
"READ solution
read table IT_COMPONENT transporting no fields
with key CLSNAME = WA_CLASS-CLSNAME
CMPTYPE = 0 binary search.
if SY-SUBRC eq 0.
"perform entry_found.
else.
read table IT_COMPONENT transporting no fields
with key CLSNAME = WA_CLASS-CLSNAME
CMPTYPE = 1 binary search.
if SY-SUBRC eq 0.
"perform entry_found.
else.
EXIT.
endif.
endif.
"loop solution
LOOP at IT_COMPONENT into WA_COMPONENT where  CLSNAME = WA_CLASS-CLSNAME
AND ( CMPTYPE = 0 or CMPTYPE = 1 ).
ENDLOOP.
if sy-subrc eq 0.
"at least one entry found
else.
EXIT.
endif.

ABAP report of pernrs and email output as PDF ABAP

Useful ABAP code example to demonstrate how to display an SAP ALV report and then email the output as a PDF document. The code covers the following SAP ABAP report functionality:

  • Email address input selection screen fields
  • Display ALV report using Objects cl_salv_table
  • Add custom ALV column header
  • Change colour of ALV rows based on user start year
  • Get ALV Spool from background execution
  • Convert Spool to PDF and send as Email
  • Submit an ABAP report in background
  • ABAP report submits itself in background to create spool
  • Pass parameter and select option to report submit
  • Delete SAP spool request

REPORT ZREP_EMAIL_ALV_SPOOL….

Click here for ABAP code and more info

View SAP Query ABAP program created

When working with SAP queries it is often useful to have a look at the ABAP code it generates. This could be to either use it as a basis for a new report or just to see what is going on. You can also use this information to assign a transaction code to your infoset query. Once you have the ABAP program associated you can assign a t-code in the same way you would assign any transaction code to an ABAP report.
I always used to do this by searching for an ABAP program/report containing the name of your query. This is done by simply adding an asterisk either side of your query name (i.e. *MYQUERY*), entering this into transaction SE38 or SE80 and using the F4 value help option. The name of your query will then appear in the hit list, it will be something like AQL4*======MYQUERY===.
A much better way would be to  view the name via SQ01 using menu option   Query->More functions->Display report name. You can also create the report using menu option Query->More functions->Generate program.
query-program-name

SAP Function Module tables parameter

Using the tables parameter is obsolete and SAP does not really support this any more. You can add a table type parameter to the changing or exporting section which should work fine but this method is not supported by some older versions of some extraction tools such as XtractIS.


Creating a TABLES parameter

fm_tables

Notice the LIKE option is not available from the drop down any more but you can still use it and ZMY_DATASTRUC must not contain a filed of type string otherwise you will get the FL389 error

Compare two ABAP objects using SE39 Split screen editor

Transaction SE39 is useful if you want edit two programs at the same time or if you just want to compare two ABAP objects on one screen. Once you have two objects loaded into the views you can turn compare mode on and it will highlight any differences, which you can step through one at a time.


Step 1 – Select two ABAP objects in SE39

First you simply need to execute t-code SE39 and choose the 2 objects you want to view/edit/compare i.e. I have created a copy of BAPI_EMPATTABS_GETDETAIL called ZBAPI_EMPATTABS_GETDETAIL and entered both of these into the selection screen.

se39-1


Step 2 – View two ABAP objects alongside each other
On the next screen you will see the two entered objects alongside each other in View/Change mode depending which button you pressed.

se39-2

 

Step 3 – Compare mode
In-order to compare the two objects simply click the “Compare On” button and any changes will be highlighted with a red and white not equals sign. As you can see when I copied this function module and changed the language it has slightly altered the signature lines so they arte highlighted as being different. The code its self remains the same so are not highlighted.

se39-3

Display URL in SAP ABAP report using class method

*&---------------------------------------------------------------------*
*& Report  ZDISPLAY_URL
*&
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT  Zdisplay_url. 

CALL METHOD CL_ABAP_BROWSER=>SHOW_URL
  EXPORTING
    URL          = 'http://www.se80.co.uk'
*    TITLE        =
*    SIZE         = CL_ABAP_BROWSER=>MEDIUM
*    MODAL        = ABAP_TRUE
*    PRINTING     = ABAP_FALSE
*    BUTTONS      = NAVIGATE_OFF
*    FORMAT       = CL_ABAP_BROWSER=>LANDSCAPE
*    POSITION     = CL_ABAP_BROWSER=>TOPLEFT
*    CONTAINER    =
*    CONTEXT_MENU = ABAP_FALSE
.

Payroll control record PA03

The payroll information displayed via transaction PA03 is stored within tables T569V, T549A and T549Q. They can also be retrieved using Function module PA03_PCR_READ

Another useful function module could be HR_MX_GET_PAYROLL_PERIOD which retrieves payroll period dates based on current date, irrespective of what is set in SAP transaction PA03.

CALL FUNCTION ’HR_MX_GET_PAYROLL_PERIOD’
EXPORTING
PAYROLL_AREA         = ld_abkrs
*   DATE                                = SY-DATUM
IMPORTING
*   PAYROLL_YEAR         =
*   PAYROLL_PERIOD     =
PERIOD_BEGIN              = ld_start
PERIOD_END                  = ld_end.