Application Development and Automation 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: 
Read only

native sql EXEC - how to transfer abap range to IN operator

Eliramy
Explorer
0 Likes
4,530

Thanks if someone can give example .

Eliram.

1 ACCEPTED SOLUTION
Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,408

You may also map your range to a free selection format, then call FREE_SELECTIONS_RANGE_2_WHERE to convert it to a where string (concatenate returned records) that you pass to CL_SQL_STATEMENT->EXECUTE_QUERY (Look for ADBC - ABAP Database Connectivity in online Abap documentation)

Regards,

Raymond

Thanks if someone can give example .

Eliram.

7 REPLIES 7
Read only

Patrick_vN
Active Contributor
0 Likes
2,408

You can check  REPORT demo_sel_screen_tables_ranges in SAP for an example:

  DATA: s_carrid2 TYPE RANGE OF spfli-carrid,

       s_carrid2_wa LIKE LINE OF s_carrid2.

s_carrid2_wa-sign   = 'I'.

s_carrid2_wa-option = 'EQ'.

s_carrid2_wa-low    = 'AA'.

APPEND s_carrid2_wa TO s_carrid2.

SUBMIT demo_selection_screen_ldb_1 WITH carrid IN s_carrid2

        VIA SELECTION-SCREEN AND RETURN.

A selection table s_carrid is created with reference to column CARRID of database table SPFLI. The s_carrid-low and s_carrid-high fields have the same type as CARRID. The work area of the internal table s_carrid is filled and appended to the table. Program demo2 is called. If demo2 is linked to logical database F1S, its selections screen contains the fields of selection criterion CARRID from the logical database. These fields are filled with the contents of the internal table.

Of course, if you wish to use the range in a select statement, if would be something like this:

SELECT * FROM [dbase table] INTO TABLE [internal table] WHERE carrid in s_carrid2.

Note: replace the * with the fields you require from the dbase table

Read only

0 Likes
2,408

You didn't understand me .

I have asked about NATIVE SQL here's an example of my code .

How i transfer in where clause

Hkont in  S_HKONT -> abap range .

I don't succeed to transfer abap range to where clause .

    EXEC SQL.

OPEN dbcur for
SELECT /*+ FULL(B) */
bukrs
, hkont, gjahr, belnr, shkzg, buzei, budat, bldat,
monat
, blart, xblnr, dmbtr, sgtxt, ccbtc, vbund
FROM SAPSR3.BSAS B
WHERE mandt  = :sy-mandt
AND   bukrs  = :p_bukrs
AND   rfzei  = 000
AND   budat >= :p_budat

ENDEXEC.


DO.
EXEC SQL.
FETCH NEXT dbcur into :ls_bsis-bukrs,
:ls_bsis-hkont,
:ls_bsis-gjahr,
:ls_bsis-belnr,
:ls_bsis-shkzg,
:ls_bsis-buzei,
:ls_bsis-budat,
:ls_bsis-bldat,
:ls_bsis-monat,
:ls_bsis-blart,
:ls_bsis-xblnr,
:ls_bsis-dmbtr,
:ls_bsis-sgtxt,
:ls_bsis-ccbtc,
:ls_bsis-vbund.
ENDEXEC.

IF sy-subrc <> 0.
EXIT.
ENDIF.

APPEND ls_bsis TO lt_bsis.

ENDDO.

Read only

0 Likes
2,408

My mistake, apologies.

Might this thread help https://scn.sap.com/thread/1666042 ?

Not sure the IN operand works in native SQL, it looks like BETWEEN is used instead.

Read only

0 Likes
2,408

Check the F1 help on EXEC first.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,409

You may also map your range to a free selection format, then call FREE_SELECTIONS_RANGE_2_WHERE to convert it to a where string (concatenate returned records) that you pass to CL_SQL_STATEMENT->EXECUTE_QUERY (Look for ADBC - ABAP Database Connectivity in online Abap documentation)

Regards,

Raymond

Read only

0 Likes
2,408

Can you give me an example of code how to do this ?

Read only

0 Likes
2,408

Input parameter FIELD_RANGES of FREE_SELECTIONS_RANGE_2_WHERE is a small internal table deep structure

Hint: Just add an initial record (*) to the parameter work area, modify its TABLENAME value, add an initial record (*) to field FRANGE_T (an itab too) modify its FIELDNAME value and then loop at your select-option/range table, map fields to a RSDSSELOPT structure and append it to SELOPT_T table.

Regards,

Raymond

(*) use an APPEND INTIAL LINE TO itab ASSIGNING where you defined some FIELD-SYMBOLS of type RSDS_TRANGE and RSDS_FRANGE (Add a TYPE-POOLS rsds. in program global area/class properties)