2008 Oct 03 3:46 AM
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
2008 Oct 03 5:07 AM
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
2008 Oct 03 4:07 AM
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.
2008 Oct 03 4:29 AM
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.
2008 Oct 03 4:59 AM
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.
2008 Oct 03 5:03 AM
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
2008 Oct 03 5:12 AM
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.
2008 Oct 04 1:51 AM
2008 Oct 03 4:57 AM
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
2008 Oct 03 5:07 AM
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