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: 

READ TABLE

Former Member
0 Kudos
133

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

Former Member
0 Kudos
89

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

Former Member
0 Kudos
89

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.

0 Kudos
89

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.

0 Kudos
89

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.

0 Kudos
89

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

0 Kudos
89

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.

0 Kudos
89

Hi.

Thank you for all the responses.

Regards,

Ramprabhu_Sukum
Product and Topic Expert
Product and Topic Expert
0 Kudos
89

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

Former Member
0 Kudos
90

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