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

READ TABLE

Former Member
0 Likes
1,021

I have the following question.

How can use the following sentence ABAP if have i want do

READ TABLE gt_bsid WITH KEY belnr = gt_bkpf-belnr and field2 = gt_bkpf-field2.

Regards

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
977

Hi,

Try like this....



CLEAR : lv_monat_condition.
CONCATENATE 'MONAT' ' IN ' '''' monat '''' INTO
lv_monat_condition.


IF NOT sociedad IS INITIAL.
CLEAR : lv_sociedad_condition.
CONCATENATE 'sociedad' ' = ' '''' sociedad '''' INTO
lv_sociedad_condition.
ENDIF.

IF NOT ejerc IS INITIAL.
CLEAR : lv_ejerc_condition.
CONCATENATE 'ejerc' ' = ' '''' ejerc '''' INTO
lv_ejerc_condition.
ENDIF.

IF NOT docum IS INITIAL.
CLEAR : lv_docum_condition.
CONCATENATE 'docum' ' = ' '''' docum '''' INTO
lv_docum_condition.
ENDIF.


IF NOT lv_monat_condition IS INITIAL.
CONCATENATE lv_monat_condition lv_condition
INTO lv_condition SEPARATED BY space.
ENDIF.

IF NOT lv_sociedad_condition IS INITIAL.
IF lv_condition IS INITIAL.
CONCATENATE lv_sociedad_condition lv_condition
INTO lv_condition SEPARATED BY space.
ELSE.
CONCATENATE lv_condition 'AND' lv_sociedad_condition
INTO lv_condition SEPARATED BY space.
ENDIF.

ENDIF.

IF NOT lv_docum_condition IS INITIAL.
IF lv_condition IS INITIAL.
CONCATENATE lv_docum_condition lv_condition
INTO lv_condition SEPARATED BY space.
ELSE.
CONCATENATE lv_condition 'AND' lv_docum_condition
INTO lv_condition SEPARATED BY space.
ENDIF.

ENDIF.


SELECT * FROM bkpf INTO CORRESPONDING FIELDS OF TABLE gt_bkpf WHERE lv_condition . " Dynamic where condition

Hope it will helps

8 REPLIES 8
Read only

Former Member
0 Likes
977

Hi Softtek MM,

1. Don't put 'AND' in between conditions.

2. GT_BSID and GT_BKPF should have a HEADER LINE.



  READ TABLE gt_bsid WITH KEY belnr  = gt_bkpf-belnr 
                              field2 = gt_bkpf-field2.

Regards,

R.Nagarajan.

Read only

0 Likes
977

Good Morning R.Nagarajan.,

I have the following abap code:

SELECT-OPTIONS monat FOR bkpf-monat.

SELECTION-SCREEN BEGIN OF BLOCK archivo WITH FRAME TITLE text-008.

PARAMETERS: sociedad LIKE bkpf-bukrs,

ejerc LIKE bkpf-gjahr,

docum LIKE bkpf-blart.

SELECTION-SCREEN END OF BLOCK archivo.

I want do a select at the table bkpf, having in count the parameter registers by the user , ie.

sociedad in blank.

ejerc in blank.

docum in blank.

Or sociedad with some valor and the other fields in blank.

How can do the select?

SELECT * FROM bkpf INTO CORRESPONDING FIELDS OF TABLE gt_bkpf WHERE monat IN monat.

But for the other fields how valide if is filled or not for do the select....

Regards.

Read only

0 Likes
977

Hi,

If you want to execute the including the parameters only if a value was provided then you can make the WHERE clause part dynamic as below.

Read only

0 Likes
977

Hi,

If you want to execute the including the parameters only if a value was provided then you can make the WHERE clause part dynamic as below.

DATA: gv_where TYPE string.

SELECT-OPTIONS monat FOR bkpf-monat.

SELECTION-SCREEN BEGIN OF BLOCK archivo WITH FRAME TITLE text-008.

PARAMETERS: sociedad LIKE bkpf-bukrs,

ejerc LIKE bkpf-gjahr,

docum LIKE bkpf-blart.

SELECTION-SCREEN END OF BLOCK archivo.

START-OF-SELECTION.

gv_where = 'monat IN monat'.

IF NOT sociedad IS INITIAL.

CONCATENATE gv_where 'AND bukrs = ' sociedad

INTO gv_where SEPARATED BY SPACE.

ENDIF.

IF NOT ejerc IS INITIAL.

CONCATENATE gv_where 'AND gjahr =' ejerc

INTO gv_where SEPARATED BY SPACE.

ENDIF.

IF NOT docum IS INITIAL.

CONCATENATE gv_where 'AND blart =' docum

INTO gv_where SEPARATED BY SPACE.

ENDIF.

SELECT *

FROM bkpf

INTO CORRESPONDING FIELDS OF TABLE gt_bkpf WHERE (gv_where).

Regards,

Gajendra

Edited by: Gajendra Bhatt on Oct 2, 2008 11:10 PM

Read only

0 Likes
977

Hi Softtek MM,

Try this.

SELECT * FROM bkpf  INTO CORRESPONDING FIELDS OF TABLE gt_bkpf 
              WHERE monat IN monat AND
                    bukrs = sociedad AND
                    gjahr = ejerc AND
                    blart = docum .

Regards,

R.Nagarajan.

Read only

0 Likes
977

Hi.

Thank you for all the responses.

Regards,

Read only

Ramprabhu_Sukum
Product and Topic Expert
Product and Topic Expert
0 Likes
977

Hi ,

Do you want to validate the parameters or do you want to validate the parameters.Since your directly referring the table fields , the validateion will be done automatically.

Thanks,

Ramprabhu

Read only

Former Member
0 Likes
978

Hi,

Try like this....



CLEAR : lv_monat_condition.
CONCATENATE 'MONAT' ' IN ' '''' monat '''' INTO
lv_monat_condition.


IF NOT sociedad IS INITIAL.
CLEAR : lv_sociedad_condition.
CONCATENATE 'sociedad' ' = ' '''' sociedad '''' INTO
lv_sociedad_condition.
ENDIF.

IF NOT ejerc IS INITIAL.
CLEAR : lv_ejerc_condition.
CONCATENATE 'ejerc' ' = ' '''' ejerc '''' INTO
lv_ejerc_condition.
ENDIF.

IF NOT docum IS INITIAL.
CLEAR : lv_docum_condition.
CONCATENATE 'docum' ' = ' '''' docum '''' INTO
lv_docum_condition.
ENDIF.


IF NOT lv_monat_condition IS INITIAL.
CONCATENATE lv_monat_condition lv_condition
INTO lv_condition SEPARATED BY space.
ENDIF.

IF NOT lv_sociedad_condition IS INITIAL.
IF lv_condition IS INITIAL.
CONCATENATE lv_sociedad_condition lv_condition
INTO lv_condition SEPARATED BY space.
ELSE.
CONCATENATE lv_condition 'AND' lv_sociedad_condition
INTO lv_condition SEPARATED BY space.
ENDIF.

ENDIF.

IF NOT lv_docum_condition IS INITIAL.
IF lv_condition IS INITIAL.
CONCATENATE lv_docum_condition lv_condition
INTO lv_condition SEPARATED BY space.
ELSE.
CONCATENATE lv_condition 'AND' lv_docum_condition
INTO lv_condition SEPARATED BY space.
ENDIF.

ENDIF.


SELECT * FROM bkpf INTO CORRESPONDING FIELDS OF TABLE gt_bkpf WHERE lv_condition . " Dynamic where condition

Hope it will helps