SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Correct way of looping through bkpf-budat and bkpf-blart



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP
View previous topic :: View next topic  
Author Message
weelilin
Участник
Участник



Joined: 13 Jul 2009
Posts: 10

PostPosted: Thu Jul 16, 2009 12:00 pm    Post subject: Correct way of looping through bkpf-budat and bkpf-blart Reply with quote

Hi all, there seems to be something wrong with my date because it just take it the date and doc type that i keyed in in my option page.

e.g if i enter 01.01.2009, the print out will be that..although the date should be my posting date ( 20.06.2009)

I have tried putting my loop at different place inside these codes but it either look more wrong or just as wrong..

Clue??

Code:
START-OF-SELECTION.

SELECT * FROM bkpf INTO TABLE it_bkpf
WHERE budat in p_budat AND blart in p_blart.

SELECT * FROM ekpo INTO TABLE it_ekpo
WHERE ebeln in p_ebeln AND ebelp in p_ebelp.

SELECT * FROM bseg INTO TABLE it_bseg
WHERE belnr in p_belnr AND bukrs in p_bukrs AND gjahr in p_gjahr.

LOOP AT it_bkpf INTO it_bkpf.
ENDLOOP.
LOOP AT it_ekpo INTO it_ekpo.
LOOP AT it_bseg INTO it_bseg
WHERE EBELN = it_ekpo-EBELN
AND EBELP = it_ekpo-EBELP.


MOVE it_ekpo-txz01 TO it_bseg-sgtxt.
MODIFY it_bseg FROM it_bseg TRANSPORTING sgtxt.
WRITE:/ it_bseg-belnr, it_bseg-gjahr, it_bseg-sgtxt, it_ekpo-ebeln, it_ekpo-ebelp, it_bkpf-budat, it_bkpf-blart, it_bseg-hkont.
ENDLOOP.
ENDLOOP.

MODIFY bseg FROM TABLE it_bseg.
COMMIT WORK.

IF sy-subrc EQ 0.
WRITE:/3 'UPDATED SUCCESSFULLY WITH TEXT'.
ENDIF.
Back to top
View user's profile Send private message
vga
Мастер
Мастер


Age: 80
Joined: 04 Oct 2007
Posts: 1218
Location: Санкт-Петербург

PostPosted: Thu Jul 16, 2009 10:57 pm    Post subject: Reply with quote

Hello, suppose you need to move ENDLOOP statement from

Quote:
LOOP AT it_bkpf INTO it_bkpf.
ENDLOOP.

to
Quote:
t_bkpf-budat, it_bkpf-blart, it_bseg-hkont.
ENDLOOP.
ENDLOOP.
ENDLOOP.


but your сode is not a good style of abap programming. Crying or Very sad
Please, take advice of Удав in the near topic.
Back to top
View user's profile Send private message Blog Visit poster's website
weelilin
Участник
Участник



Joined: 13 Jul 2009
Posts: 10

PostPosted: Fri Jul 17, 2009 5:59 am    Post subject: Reply with quote

as in i shuld not update directly into the table or ?
Back to top
View user's profile Send private message
weelilin
Участник
Участник



Joined: 13 Jul 2009
Posts: 10

PostPosted: Fri Jul 17, 2009 6:37 am    Post subject: Reply with quote

when i p-ut my loop statement at the end, there will be a runtime error stating an endless loop...
Back to top
View user's profile Send private message
vga
Мастер
Мастер


Age: 80
Joined: 04 Oct 2007
Posts: 1218
Location: Санкт-Петербург

PostPosted: Fri Jul 17, 2009 9:39 am    Post subject: Reply with quote

weelilin wrote:
as in i shuld not update directly into the table or ?


Yes, direct update BSEG is a bad style. Also reading BKPF, BSEG, EKPO into internal tables without restrictions can lead to low memory dump.

But I corrected you example:

Code:
TABLES: bkpf, bseg, ekpo.

FIELD-SYMBOLS: <fs_bseg> TYPE bseg.

DATA: it_bkpf TYPE TABLE OF bkpf WITH HEADER LINE,
      it_bseg TYPE TABLE OF bseg WITH HEADER LINE,
      it_ekpo TYPE TABLE OF ekpo WITH HEADER LINE.

SELECT-OPTIONS:
           p_belnr FOR bseg-belnr OBLIGATORY,
           p_bukrs FOR bseg-bukrs OBLIGATORY,
           p_gjahr FOR bseg-gjahr OBLIGATORY,
           p_ebeln FOR ekpo-ebeln,
           p_ebelp FOR ekpo-ebelp,
           p_budat FOR bkpf-budat,
           p_blart FOR bkpf-blart.

SELECT * FROM bkpf INTO TABLE it_bkpf
  WHERE budat IN p_budat
    AND blart IN p_blart.

SELECT * FROM ekpo INTO TABLE it_ekpo
  WHERE ebeln IN p_ebeln
    AND ebelp IN p_ebelp.

SELECT * FROM bseg INTO TABLE it_bseg
  WHERE bukrs IN p_bukrs
    AND belnr IN p_belnr
    AND gjahr IN p_gjahr.

SORT it_bkpf BY bukrs belnr gjahr.
SORT it_ekpo BY ebeln ebelp.

LOOP AT it_bseg ASSIGNING <fs_bseg>.
  READ TABLE it_ekpo WITH KEY ebeln = it_bseg-ebeln
                              ebelp = it_bseg-ebelp
                     BINARY SEARCH.
  CHECK sy-subrc IS INITIAL.
  READ TABLE it_bkpf WITH KEY bukrs = it_bseg-bukrs
                              belnr = it_bseg-belnr
                              gjahr = it_bseg-gjahr
                     BINARY SEARCH.
  MOVE it_ekpo-txz01 TO <fs_bseg>-sgtxt.
  WRITE:/ <fs_bseg>-belnr, <fs_bseg>-gjahr, <fs_bseg>-sgtxt,
          it_ekpo-ebeln,  it_ekpo-ebelp,
          it_bkpf-budat, it_bkpf-blart, <fs_bseg>-hkont.
ENDLOOP.

MODIFY bseg FROM TABLE it_bseg.
COMMIT WORK.

IF sy-subrc EQ 0.
  WRITE:/3 'UPDATED SUCCESSFULLY WITH TEXT'.
ENDIF.
Back to top
View user's profile Send private message Blog Visit poster's website
weelilin
Участник
Участник



Joined: 13 Jul 2009
Posts: 10

PostPosted: Fri Jul 17, 2009 10:31 am    Post subject: Reply with quote

i manage to get it out..Thanks Cool
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.