on 09-11-2006 8:14 AM
Hi Guru's
I am enhancing a zfield in extract structure for 2lis_13_vditm. I have added the zfield in the append struture & activated it.
Zfield is populated from the table VBAP. I wanted to write an User Exit (EXIT_SAPLRSAP_001) to populate this zfield at CMOD.
As I am not well versed in ABAP,I would really appreciate if you can help me to write a code to populate this zfield from VBAP.
Thank you,
Neel
Hi,
Check for the sample code for 2LIS_13_VDITM.
For 2LIS_13_VDITM Billing item Data
TYPES: BEGIN OF ty_vbak,
vbeln TYPE vbeln_va,
vgbel TYPE vgbel,
END OF ty_vbak.
DATA: lx_vbak TYPE ty_vbak,
lt_vbak TYPE TABLE OF ty_vbak.
TYPES: BEGIN OF ty_vbrp,
vbeln TYPE vbeln_va,
vgbel TYPE vgbel,
END OF ty_vbrp.
DATA: lx_vbrp TYPE ty_vbrp,
lt_vbrp TYPE TABLE OF ty_vbrp.
DATA: lx_billitem TYPE mc13vd0itm.
DATA: lt_billitem TYPE TABLE OF mc13vd0itm .
DATA: lt_billitem_tmp TYPE TABLE OF mc13vd0itm .
For 2LIS_13_VDITM item data
WHEN '2LIS_13_VDITM'.
lt_billitem[] = c_t_data[].
lt_billitem_tmp[] = c_t_data[].
IF NOT lt_billitem_tmp[] IS INITIAL.
SORT lt_billitem_tmp BY aubel.
DELETE ADJACENT DUPLICATES FROM lt_billitem_tmp COMPARING aubel.
SELECT vbeln
vgbel
FROM vbak
INTO TABLE lt_vbak
FOR ALL ENTRIES IN lt_billitem_tmp
WHERE vbeln = lt_billitem_tmp-aubel
AND vgtyp = 'G'.
IF sy-subrc EQ 0.
SORT lt_vbak BY vbeln.
ENDIF.
ENDIF.
Populate the added fields
LOOP AT lt_billitem INTO lx_billitem.
l_index = sy-tabix.
MOVE lx_billitem-vbeln TO l_name.
Internal Text
CLEAR lt_line.
REFRESH lt_line.
CALL FUNCTION 'READ_TEXT'
EXPORTING
CLIENT = SY-MANDT
id = 'Z010'
language = sy-langu
name = l_name
object = 'VBBK'
ARCHIVE_HANDLE = 0
LOCAL_CAT = ' '
IMPORTING
HEADER =
TABLES
lines = lt_line
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF NOT lt_line[] IS INITIAL.
CLEAR lx_line.
READ TABLE lt_line INTO lx_line INDEX 1.
lx_billitem-zitext = lx_line-tdline.
ENDIF.
CLEAR lt_line.
REFRESH lt_line.
External Text
CALL FUNCTION 'READ_TEXT'
EXPORTING
CLIENT = SY-MANDT
id = 'Z011'
language = sy-langu
name = l_name
object = 'VBBK'
ARCHIVE_HANDLE = 0
LOCAL_CAT = ' '
IMPORTING
HEADER =
TABLES
lines = lt_line
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF NOT lt_line[] IS INITIAL.
CLEAR lx_line.
READ TABLE lt_line INTO lx_line INDEX 1.
lx_billitem-zetext = lx_line-tdline.
ENDIF.
CLEAR lx_vbak.
READ TABLE lt_vbak INTO lx_vbak
WITH KEY vbeln = lx_billitem-aubel.
IF sy-subrc EQ 0.
lx_billitem-zcontract = lx_vbak-vgbel.
ENDIF.
IF lx_billitem-aubel EQ lx_billitem-vgbel.
lx_billitem-vgbel = space.
ENDIF.
MODIFY lt_billitem FROM lx_billitem INDEX l_index.
ENDLOOP.
CLEAR c_t_data.
REFRESH c_t_data.
c_t_data[] = lt_billitem[].
Thanks,
Debasish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Sample code
*************************************
Data : wa_MC11V_0SCL like MC11V_0SCL,
l_tabix like sy-tabix.
tables : VBAP ,
VBAK.
Case i_datasource.
When '2LIS_11_V_SCL' .
Loop at c_t_data into wa_MC11V_0SCL.
l_tabix = sy-tabix.
select single KOKRS from VBAK into VBAK-KOKRS
where VBELN = wa_MC11V_0SCL-VBELN.
If sy-subrc = 0.
wa_MC11V_0SCL-ZZKOKRS = VBAK-KOKRS .
modify c_t_data from wa_MC11V_0SCL index l_tabix.
clear VBAK-KOKRS .
endif.
select single PRCTR from VBAP into VBAP-PRCTR
where VBELN = wa_MC11V_0SCL-VBELN
and POSNR = wa_MC11V_0SCL-POSNR.
If sy-subrc = 0.
wa_MC11V_0SCL-ZZPRCTR = VBAP-PRCTR .
modify c_t_data from wa_MC11V_0SCL index l_tabix.
clear VBAP-PRCTR .
endif.
Endloop.
When Others.
Exit.
EndCase.
*************************************
MOdify as per your need...
Regards,
San!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Neel,
it depend on your requirement.
if you want only single record and less fields ..then go for single select.
and
if you want to extract more data from datadase..then you go for internal table and select--endselect.
<b>Select Single</b> is more faster and more efficient.
I have seen many code..people use only single.
Select EndSelect generates a loop..so not that efficient.
Regards,
San!
Hi Neel,
The same code San has written could be written as below:
Sample code
*************************************
Data : wa_MC11V_0SCL like MC11V_0SCL,
l_tabix like sy-tabix.
Data:Begin of t_MC11V_0SCL occurs 0,
VBELN type VBELN,
KOKRS type kokrs,
end of t_MC11V_0SCL.
tables : VBAP ,
VBAK.
Case i_datasource.
When '2LIS_11_V_SCL' .
_______________________________________________________
select vbeln KOKRS from VBAK into table t_MC11V_0SCL
for all entries in c_t_data
where VBELN = c_t_data-VBELN.
if sy-subrc = 0.
sort t_MC11V_0SCL by vbeln.
endif.
________________________________________________________
Loop at c_t_data into wa_MC11V_0SCL.
l_tabix = sy-tabix.
_______________________________________________________
read t_MC11V_0SCL with key vbeln = wa_MC11V_0SCL-vbeln
binary search.
if sy-subrc = 0.
wa_MC11V_0SCL-kokrs = t_MC11V_0SCL-kokrs.
modify c_t_data from wa_MC11V_0SCL index l_tabix.
endif.
________________________________________________________
select single PRCTR from VBAP into VBAP-PRCTR
where VBELN = wa_MC11V_0SCL-VBELN
and POSNR = wa_MC11V_0SCL-POSNR.
If sy-subrc = 0.
wa_MC11V_0SCL-ZZPRCTR = VBAP-PRCTR .
modify c_t_data from wa_MC11V_0SCL index l_tabix.
clear VBAP-PRCTR .
endif.
Endloop.
When Others.
Exit.
EndCase.
*************************************
In this code, select single has been replaced by select for all entries and a read internal table statements. So, Database access is made only once instead of many hits to the database. This way, the communiccation time improves. You can replace the other select single also the same way. I just gave you an example here. Hope this helps.
Thanks and Regards
Subray Hegde
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.