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

Values in internal table

Former Member
0 Likes
2,095

Hi all,

I am developing a report for Bank Deposit. I have a following selection screen

SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE text-001.

PARAMETERS: p_cocd  TYPE febko-bukrs OBLIGATORY.

SELECT-OPTIONS: s_hbkid FOR febko-hbkid,

                 s_hktid FOR febko-hktid,

                 s_emkey FOR febko-emkey OBLIGATORY,

                 s_euser FOR febko-euser OBLIGATORY,

                 s_azdat FOR febko-azdat OBLIGATORY.

SELECTION-SCREEN END OF BLOCK a.

and following data i am fetching from BKPF, FEBKO, FEBEP and FEBCL

SELECT bukrs

          bktxt

          budat

          usnam

          FROM bkpf INTO CORRESPONDING FIELDS OF TABLE it_bkpf

          WHERE bukrs = p_cocd.

   SORT it_bkpf BY bukrs.

   DELETE ADJACENT DUPLICATES FROM it_bkpf COMPARING bktxt.

   SELECT anwnd

          kukey

          emkey

          azdat

          bukrs

          hbkid

          hktid

          euser

          edate

          FROM febko INTO CORRESPONDING FIELDS OF TABLE it_febko

          FOR ALL ENTRIES IN it_bkpf

          WHERE ( bukrs = it_bkpf-bukrs

            AND  anwnd = '0002'

            AND emkey IN s_emkey

            AND euser IN s_euser

            AND azdat IN s_azdat )

            AND ( hbkid IN s_hbkid

            OR hktid IN s_hktid ).

   IF it_febko[] IS NOT INITIAL.

     SORT it_febko BY kukey.

     DELETE ADJACENT DUPLICATES FROM it_febko COMPARING kukey.

     SELECT kukey

            esnum

            budat

            gsber

            prctr

            chect

            gjahr

            valut

            vgman

            kwbtr

            nbbln

            FROM febep INTO CORRESPONDING FIELDS OF TABLE it_febep

            FOR ALL ENTRIES IN it_febko

            WHERE kukey = it_febko-kukey.

ENDIF.

     SORT it_febep BY kukey.

     DELETE ADJACENT DUPLICATES FROM it_febep COMPARING kukey.

     SELECT kukey

            esnum

            koart

            agkon

            FROM febcl INTO CORRESPONDING FIELDS OF TABLE it_febcl

            FOR ALL ENTRIES IN it_febep

            WHERE kukey = it_febep-kukey

              AND koart = 'D'

              AND esnum = it_febep-esnum.

Following is the loop...

DATA lv_text(25).

   LOOP AT it_febko INTO wa_febko.

     wa_final-emkey = wa_febko-emkey.

     wa_final-azdat = wa_febko-azdat.

     wa_final-bukrs = wa_febko-bukrs.

     wa_final-hbkid = wa_febko-hbkid.

     wa_final-hktid = wa_febko-hktid.

     wa_final-euser = wa_febko-euser.

     SORT it_febep BY kukey.

     READ TABLE it_febep INTO wa_febep WITH KEY kukey = wa_febko-kukey BINARY SEARCH.

     IF sy-subrc EQ 0.

       wa_final-budat = wa_febep-budat.

       wa_final-valut = wa_febep-valut.

       wa_final-kwbtr = wa_febep-kwbtr.

       wa_final-vgman = wa_febep-vgman.

       wa_final-gsber = wa_febep-gsber.

       wa_final-prctr = wa_febep-prctr.

       wa_final-chect = wa_febep-chect.

       CONCATENATE wa_febep-kukey wa_febep-esnum INTO lv_text.

       SELECT SINGLE belnr

                     INTO  wa_final-nbbln

                     FROM bkpf

                     WHERE bktxt  = lv_text.

     ENDIF.

     SORT it_bkpf BY bktxt.

     READ TABLE it_bkpf INTO wa_bkpf WITH KEY bktxt = lv_text BINARY SEARCH.

     IF sy-subrc EQ 0.

       wa_final-usnam = wa_bkpf-usnam.

     ENDIF.

     SORT it_febcl BY kukey.

     READ TABLE it_febcl INTO wa_febcl WITH KEY kukey = wa_febep-kukey BINARY SEARCH.

     IF sy-subrc EQ 0.

       wa_final-agkon = wa_febcl-agkon.

     ENDIF.

     CLEAR lv_text.

     APPEND wa_final TO it_final.

   ENDLOOP.

My Problem is IT_FEBKO is fetching only one record even if there are 3 records for given date by user.

Any suggestion please.

Regards,

PS

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,776

Hi Everyone,

Problem solved.

     " SORT it_febep BY kukey.

      DELETE ADJACENT DUPLICATES FROM it_febep COMPARING kukey. "

was the flaw. Removed it for FEBEP contained line items with unique key KUKEY and i was sorting internal table by the same key when internal table contained DOC NO as well.

Thank you all for your generous help.

Regards,

PS

12 REPLIES 12
Read only

Arun_Prabhu_K
Active Contributor
0 Likes
1,776

Purushottam,

     1) Re-check the select statement conditions which fetches the data into IT_FEBKO.

     Debugging helps you to understand the working of ABAP programs better. Make best use of it.

    

Regards.

Read only

0 Likes
1,776

Hi Arun,

I debugged it for almost coupe of hours it didnt work that is why i posted question here.

Thanks for your suggestion though .

Regards,

PS

Read only

former_member209120
Active Contributor
0 Likes
1,776

Hi Purushottam,

Modify you select statement like this and debug..

SELECT anwnd

          kukey

          emkey

          azdat

          bukrs

          hbkid

          hktid

          euser

          edate

          FROM febko INTO CORRESPONDING FIELDS OF TABLE it_febko

          FOR ALL ENTRIES IN it_bkpf

          WHERE  bukrs = it_bkpf-bukrs

            AND  anwnd = '0002'

            AND emkey IN s_emkey

            AND euser IN s_euser

            AND azdat IN s_azdat

            AND hbkid IN s_hbkid

            and   hktid IN s_hktid .

Read only

0 Likes
1,776

Hi Ramesh,

I tried that way, it wont work. I know FEBKO is a header table and FEBEP is item table but what concerns me is even for multiple document number in BKPF it is FETCHING only one record. Select query with BKPF has some flaws.

Regards,

PS

Read only

0 Likes
1,776

Check Structure you declared and selected for it_bkpf

if possible all structures like that

SELECT bukrs

          bktxt

          budat

          usnam

          FROM bkpf INTO CORRESPONDING FIELDS OF TABLE it_bkpf

          WHERE bukrs = p_cocd.

Read only

Former Member
0 Likes
1,776

Hi,

Many time sequence also play important role in data fetching use all key fields after select statement OR try with * for checking purpose.

SELECT

        ANWND

        ABSND

        AZIDT

        EMKEY

          kukey

          azdat

          bukrs

          hbkid

          hktid

          euser

          edate

Regards,

Read only

Former Member
0 Likes
1,776

Hi,

Before using for all entries, always check if the table you are referring to has entries hence add this check before your select.

Add the brackets only if you have a condition " if this or that". Assuming that it should be HBKID OR HTKID, you can add brackets for that.

Also make the order of the fields in the Select Statement and in the where condition is the same as that in the database table. For ex: make sure ANWND comes first, KUKEY comes 2nd,etc same as the order in the database table FEBKO. Similarly ANWND should come first in the where condition...and so on. Let us know if you need any more details

IF IT_BKPF[] IS NOT INITIAL.

 

SELECT anwnd 

          kukey

          emkey

          azdat

          bukrs

          hbkid

          hktid

          euser

          edate

          FROM febko INTO CORRESPONDING FIELDS OF TABLE it_febko

          FOR ALL ENTRIES IN it_bkpf

          WHERE bukrs = it_bkpf-bukrs

            AND  anwnd = '0002'

            AND emkey IN s_emkey

            AND euser IN s_euser

            AND azdat IN s_azdat

           AND ( hbkid IN s_hbkid

            OR hktid IN s_hktid ).

ENDIF.

Read only

Former Member
0 Likes
1,776

Hi Purushottam,

Declare the interal table for FEBKO with all primary  key fields from that table. This will solve your problem.

Regards,

Neelesh

Read only

Former Member
0 Likes
1,776

hi Purushottam,

Your below query is failing

   SELECT anwnd

          kukey

          emkey

          azdat

          bukrs

          hbkid

          hktid

          euser

          edate

          FROM febko INTO CORRESPONDING FIELDS OF TABLE it_febko

          FOR ALL ENTRIES IN it_bkpf

          WHERE ( bukrs = it_bkpf-bukrs

            AND  anwnd = '0002'

            AND emkey IN s_emkey

            AND euser IN s_euser

            AND azdat IN s_azdat )

            AND ( hbkid IN s_hbkid

            OR hktid IN s_hktid ).

I would request you to first check number of records in IT_BKPF. secondaly tally your condition in FEBKO table manually and check how many records are coming. Then fetch records from FEBKO based only on BKPF-BUKRS and ANWD as 0002. check how many records are fetched this time.

Next you filter the IT_FEBKO table based on select options (using delete ).

This process will help you understand the data that you are getting and probable flaw in code.

Please let me know if this helpw or still in doubt.

Regards,

DN.

Read only

Former Member
0 Likes
1,776

Hi Purushottam,

Modify your select statement as below and Check.

If it_bkpf[] is not initial.


SELECT anwnd

          kukey

          emkey

          azdat

          bukrs

          hbkid

          hktid

          euser

          edate

          FROM febko INTO CORRESPONDING FIELDS OF TABLE it_febko

          FOR ALL ENTRIES IN it_bkpf

          WHERE  bukrs = it_bkpf-bukrs

            AND  anwnd = '0002'

            AND emkey IN s_emkey

            AND euser IN s_euser

            AND azdat IN s_azdat

            AND ( hbkid IN s_hbkid

            OR   hktid IN s_hktid ).

endif.

Also declare structures with required fields and use them for typing internal tables, (E.g : Don't use BKPF structure to type IT_BKPF, when you required only some of the fields from that table), So that you can avoid "corresponding fields into" statement.

Read only

Former Member
0 Likes
1,776

Hi Purushottam,

The select query you are using does not have all keys for table FEBKO. You are using "for all entries" which will definitely not pick the duplicate entries.

Instead, use all the key fields

ANWND

ABSND

AZIDT

EMKEY

in your select query and then it should work fine.

Read only

Former Member
0 Likes
1,777

Hi Everyone,

Problem solved.

     " SORT it_febep BY kukey.

      DELETE ADJACENT DUPLICATES FROM it_febep COMPARING kukey. "

was the flaw. Removed it for FEBEP contained line items with unique key KUKEY and i was sorting internal table by the same key when internal table contained DOC NO as well.

Thank you all for your generous help.

Regards,

PS