Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Variables entered at runtime

Former Member
0 Kudos

Hi All

I want to extract the values which lie between two dates entered by the user at the run time. For the users to enter the dates, I am using the Select-Options clause.The code is like this...

SELECT-OPTIONS MY_DATE FOR SY-DATUM DEFAULT '19980101' TO '19981231'.

TABLES: PA0001, PA0006, PA0008.

DATA: BEGIN OF TEST_TBL OCCURS 100,

P_NAME LIKE P0001-UNAME,

P_SDATE LIKE P0006-BEGDA,

P_EDATE LIKE P0006-ENDDA,

P_STREET LIKE P0006-STRAS,

P_CITY LIKE P0006-ORT01,

P_ZIP LIKE P0006-PSTLZ,

P_WAGE_TYPE LIKE P0008-LGA01,

END OF TEST_TBL.

SELECT PA0001UNAME AS P_NAME PA0006STRAS AS P_STREET PA0006ORT01 AS P_CITY PA0006PSTLZ AS P_ZIP PA0008~LGA01 AS P_WAGE_TYPE

INTO CORRESPONDING FIELDS OF TABLE TEST_TBL

FROM ( PA0001 INNER JOIN PA0006 ON PA0001PERNR = PA0006PERNR

INNER JOIN PA0008 ON PA0001PERNR = PA0008PERNR )

WHERE MY_DATE BETWEEN PA0006BEGDA AND PA0006ENDDA.

LOOP AT TEST_TBL.

WRITE: /, TEST_TBL.

ENDLOOP.

Since the dates are entered at runtime, the complier fails to recognize the variable MY_DATE and gives an error.

Thanks in advance,

Gaurav

6 REPLIES 6

Former Member
0 Kudos

Hi,

try this logic:

SELECT PA0001UNAME AS P_NAME PA0006STRAS AS P_STREET PA0006ORT01 AS P_CITY PA0006PSTLZ AS P_ZIP PA0008~LGA01 AS P_WAGE_TYPE

INTO CORRESPONDING FIELDS OF TABLE TEST_TBL

FROM ( PA0001 INNER JOIN PA0006 ON PA0001PERNR = PA0006PERNR

INNER JOIN PA0008 ON PA0001PERNR = PA0008PERNR )

WHERE PA0006~BEGDA le my_date-low

AND PA0006~ENDDA ge my_date-high

0 Kudos

I think that this syntax would cover the bases a little better. Using select-options, the user doesn't have to use a positive range. Try this where statement.



where pa0006~begda in my_date
  and pa0006~endda in my_Date.

Regards,

Rich Heilman

Former Member
0 Kudos

hi dear

plz try this

SELECT PA0001UNAME AS P_NAME PA0006STRAS AS P_STREET PA0006ORT01 AS P_CITY PA0006PSTLZ AS P_ZIP PA0008~LGA01 AS P_WAGE_TYPE

INTO CORRESPONDING FIELDS OF TABLE TEST_TBL

FROM ( PA0001 INNER JOIN PA0006 ON PA0001PERNR = PA0006PERNR

INNER JOIN PA0008 ON PA0001PERNR = PA0008PERNR )

WHERE PA0006~BEGDA in MY_DATE

and PA0006~ENDDA in MY_DATE .

Rai

0 Kudos

Hello Rai,

I need to contact you. Can you please email me at sanghaonline-stuff@yahoo.com

Thank you.

0 Kudos

Hi Gaurav

I would recommend you to make the user enter date criteria via PARAMETERS, rather than select-options. This is the way SAP uses in standard, too.

You may have visual concerns to bring two parameter fields to one line in selection screens. Then you can use : (there might be something to edit since I did not try the following code at the system)

SELECTION-SCREEN BEGIN OF LINE .
SELECTION-SCREEN COMMENT 20(15) 'Begin Date' FIELD p_begda .
PARAMETERS p_begda TYPE begda .
SELECTION-SCREEN COMMENT 50(15) 'End Date' FIELD p_endda .
PARAMETERS p_endda TYPE endda .
SELECTION-SCREEN END OF LINE .

After defining your period's begin and end date you can select HR records from an infotype table using the where condition, for example:

SELECT ... FROM PAXXXX
       INTO TABLE gt_itab
       WHERE <other_conditions> AND
             begda LE p_endda AND
             endda GE p_begda .

Regards

*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>

Former Member
0 Kudos

Hi Gaurav,

Just a small tip here. When you are making the post it would be much easier for the readers if the code is properly formatted. For instance, in this case, you SELECT statement could have looked something like this -

SELECT PA0001~UNAME AS P_NAME 
       PA0006~STRAS AS P_STREET 
       PA0006~ORT01 AS P_CITY 
       PA0006~PSTLZ AS P_ZIP 
       PA0008~LGA01 AS P_WAGE_TYPE
  INTO CORRESPONDING FIELDS OF TABLE TEST_TBL
  FROM (   PA0001 INNER JOIN PA0006 
        ON PA0001~PERNR = PA0006~PERNR
           INNER JOIN PA0008 
        ON PA0001~PERNR = PA0008~PERNR )
  WHERE MY_DATE BETWEEN PA0006~BEGDA AND PA0006~ENDDA.

All you need to do is to format your code, select it and use the <b>code</b> button.

Regards,

Anand Mandalika.