Application Development 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: 

Logical condition problem for Sales order from excel to bapi. Incorrect Display ALV

mavdleon
Explorer
0 Kudos

I'm a newbie programmer of ABAP, and I'm having some problems in my ALV (serves as log file). So i have this part of my Sales Order Massive Upload. It accepts Sales orders from excel to Bapi. I'm required to Log every SO in the Excel. The requirement is that for every the same PO Numbers, it must Generate the same SO Number. And everything must be log in my ALV Log file. My problem is that every time I append the Lines with the same PO number, the only line that will be displayed is the last line with same PO number.

e.g.

excel input:

SO TYPE | PO Number| Material | DIvision | District Channel |

xxx 11 zzzz mmmm yyyy

tttt 11 uuuu cccc dddd

nnn 12 iiii ooooo ppppp

ALV Display:

SO TYPE | PO Number| Material | DIvision | District Channel | Ret Message | SO NUmber|

tttt 11 uuuu cccc dddd adasdasdasd x <== the xxx line is missing

nnn 12 iiii ooooo ppppp asdasdadada y

Here's my Condition written in my program:

LOOP AT it_data ASSIGNING <fs_data>.

IF lv_po IS INITIAL.

lv_po = <fs_data>-po.

ENDIF.

IF <fs_data>-po = lv_po.

"move data to bapi parameters

Lv_ctr = lv_ctr + 1. "Counter is for every fields

ELSE.

"call bapi

"append entry to log file internal table

lv_po = <fs_data>-po.

"clear bapi parameters

"move data to bapi parameters.

Lv_ctr = lv_ctr + 1. "Counter is for every fields

ENDIF.

IF lv_ctr = lv_fields "lv_Fields is the total number of fields in my excel to internal table

"check if this is the last entry

"if yes, call bapi and append entry to log file internal table

ELSE.

"otherwise, continue

ENDIF.

ENDLOOP.

THanks guys!

1 ACCEPTED SOLUTION

former_member378318
Contributor
0 Kudos

John,

Rewrite your code using LOOP with the addition of the AT END OF, AT NEW, AT FIRST and AT LAST. This will allow you to check for changes in the PO number or any combination of fields. You will need to restructure your internal table so that the fields you want to check for change are at the start of the structure.

E.g

LOOP AT it_data ASSIGNING <fs_data>.
AT END OF po.

ENDAT.

AT LAST.

"check if this is the last entry
"if yes, call bapi and append entry to log file internal table

ENDAT.

3 REPLIES 3

SimoneMilesi
Active Contributor
0 Kudos

Please, try to format the code you are writing: i admit i cannot read it well.

How do you read your file? Instead of using flags to identify the moment to call BAPI, use AT NEW.. AT END...

former_member378318
Contributor
0 Kudos

John,

Rewrite your code using LOOP with the addition of the AT END OF, AT NEW, AT FIRST and AT LAST. This will allow you to check for changes in the PO number or any combination of fields. You will need to restructure your internal table so that the fields you want to check for change are at the start of the structure.

E.g

LOOP AT it_data ASSIGNING <fs_data>.
AT END OF po.

ENDAT.

AT LAST.

"check if this is the last entry
"if yes, call bapi and append entry to log file internal table

ENDAT.

former_member182550
Active Contributor
0 Kudos

Hi John,

As an aside, you mention that the ALV grid serves as a log file. SAP already provides this functionality via transactions SLG0, SLG1 and function modules in the SBAL Function group.

Regards

Rich