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

Cam someone help with below ABAP code

Former Member
1,504

Hi Friends,

I am new to ABAP coding and have written one code as below. But GL_Account column is not being updated not sure why.

Can someone please help

TYPES:

BEGIN OF ty_mapping,

cond_type TYPE c LENGTH 30,

gl_account TYPE c LENGTH 10,

country TYPE c LENGTH 10,

distr_chan TYPE c LENGTH 10,

END OF ty_mapping.

DATA: lt_avfmapping TYPE STANDARD TABLE OF ty_mapping,

ls_avfmapping TYPE ty_mapping.

SELECT cond_type

gl_account

country

distr_chan

FROM /bic/ac_afinval2

INTO TABLE lt_avfmapping

WHERE ( src_trdp = 'No' or src_trdp = 'NO' ) and country = 'CCE' .

IF sy-subrc = 0.

SORT lt_avfmapping BY cond_typeDISTR_CHAN ASCENDING.

DELETE ADJACENT DUPLICATES FROM lt_avfmapping

COMPARING cond_type.

ENDIF.

FIELD-SYMBOLS:

<fs_datapak> LIKE LINE OF RESULT_PACKAGE.

LOOP AT RESULT_PACKAGE ASSIGNING <fs_datapak>.

READ TABLE lt_avfmapping INTO ls_avfmapping WITH KEY

cond_type = <fs_datapak>-KNART

distr_chan = <fs_datapak>-DISTR_CHAN .

IF sy-subrc = 0.

<fs_datapak>-GL_ACCOUNT = ls_avfmapping-gl_account .

ENDIF.

ENDLOOP .

5 REPLIES 5
Read only

Abinathsiva
Active Contributor
1,371

Hi,

while using code in questions, use code button in order to view properly

Read only

michael_piesche
Active Contributor
1,371

When you debug your logic, are your tables filled with the information you expect? What happens in the loop when you are trying to set the gl_account?

So far you have not given enough information to help you out, one could only guess.

Read only

an10n
Explorer
0 Likes
1,371

From the information you've given, there could be multiple sources of the problem.

  1. Simply data missing in the tables
  2. Data in the column gl_account of the table "/bic/ac_afinval2" being 0
  3. There could be a problem with the types. You use the type "ty_mapping", which is clear, because it is explicitly defined in your code, but we dont know the type of fields of "/bic/ac_afinval2" (character legnths) and of "result_package". If the type of <fs_datapak>-KNART and cond_type don't match exactly, then the READ statement will not find any entry and exit with subrc = 4, therefore you will never get to your assignment "<fs_datapak>-gl_account = ls_avfmapping-gl_account."

What i would suggest is either you try to debug the program as @Michael Piersche suggested and see the types yourself or you post the exact types here, so someone could help.

As a sidenote - you don't use some nice new features available in abap since version 7.4, like new open sql syntax or inline declarations. You could look up the version of your system:

In the SAP GUI > under Menu: "System" > click on "Status ..." > in the section "SAP System data" > under "Product version" > click the magnifying glass > in the Tab "Installed Product Versions" look in the "Release" column for the Product "SAP NETWEAVER".

If the Version is >= 7.4, i could show you how to further simplify your code.

Read only

Sandra_Rossi
Active Contributor
0 Likes
1,371

Please enter a meaningful title (currently, it has the same meaning as none title). And use the CODE button to format the code (as S Abinath said).

Read only

Former Member
1,371

Hi,

Thanks for your replies. I am really sorry if i wasted you time but the issue was with one of the columns used in where clause. I rectified the data in that column and the same code worked.