Skip to Content
0

Data update with simple text file upload with ABAP

Jan 13, 2017 at 08:46 AM

209

avatar image
Former Member

Hello all,

I would like to amend some data (AFPO-ELIKZ ="final delivery" indicator) for a specific number of documents (field AFPO-AUFNR) by uploading a simple .txt file containing just the document numbers line by line.

The file will contain document numbers (7-digit) with a different length of the field values it's compared with (AFPO-AUFNR = 12-digit char field).

Now, what I'm struggling with: The data is loaded fine into the internal tables and seems to be processed through the structures, but it doesn't change the desired field value (AFPO-ELIKZ from '' to 'X'), selected by the document numbers values in the text file.

I guess there must be (a probably simple) flaw within the code you'll find below.

// I very new to ABAP and I hope my question is understandable and this is the right place for it. As there is hardly anyone else here with ABAP knowledge I'm kindly asking here.

Code starts below with "REPORT z_leupdt_elikz" (and I guess there are some lines which can be confidently omitted) and I'm very open to feedback:

SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L0S31 { font-style: italic; color: #808080; } .L0S32 { color: #3399FF; } .L0S33 { color: #4DA619; } .L0S52 { color: #0000FF; } .L0S55 { color: #800080; } .L0S70 { color: #808080; }

REPORT z_leupdt_elikz.

TABLES: afpo.

TYPES: BEGIN OF wa_doc,
docvalue(12) TYPE c,
END OF wa_doc.

TYPES: BEGIN OF ty_afpo,
aufnr TYPE afpo-aufnr,
elikz TYPE afpo-elikz,
END OF ty_afpo.

DATA: it_afpo TYPE TABLE OF ty_afpo,
wa_afpo LIKE LINE OF it_afpo.

DATA: it_doc TYPE TABLE OF wa_doc,
wa_doc LIKE LINE OF it_doc,

pa_type(10) TYPE c VALUE 'DAT'.

PARAMETERS: pa_name TYPE string DEFAULT 'C:\SAP'.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_name.

CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_filename = ' '
def_path = pa_name
mask = ',*.*,*.*.' " unbedingt erforderlich!
mode = 'S'
title = 'Dateiname'(031)
IMPORTING
filename = pa_name
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.

START-OF-SELECTION.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = pa_name
filetype = pa_type
TABLES
data_tab = it_doc
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10.


WRITE: / '<<Copied "delivery completed" indicator to Orders:>>',
/ '===================================================================================='.

LOOP AT it_doc INTO wa_doc.
DATA lv_aufnr TYPE afpo-aufnr.
UNPACK wa_doc TO lv_aufnr.

SELECT aufnr elikz FROM afpo INTO CORRESPONDING FIELDS OF TABLE it_afpo WHERE aufnr = lv_aufnr.

LOOP AT it_afpo INTO wa_afpo.
WRITE: / '| Doc.: ', wa_afpo-aufnr,
'| Del.Comp.: ', wa_afpo-elikz.

IF sy-subrc <> 0.
WRITE: / 'Error', wa_afpo-aufnr.
CONTINUE.
ENDIF.

IF wa_afpo-elikz <> 'X'.

UPDATE AFPO SET elikz = 'X' WHERE afpo~aufnr = wa_doc-docvalue.

IF sy-subrc = 0.
WRITE: 'updated'.
ENDIF.
ELSE.
WRITE: 'equal'.
ENDIF.
ENDLOOP.
ENDLOOP.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Jürgen L
Jan 13, 2017 at 10:08 AM
4

If you have basic ABAP skills then you should already be able to debug this bit of coding to know why the update does not happen.

It is just one line where you do the update, and in there you have a condition, so it it should be really easy to know if the condition was fulfilled or not and to compare the value from the condition with the value in your database, I bet it is not fulfilled because the number in your source file is without leading zeroes and you have not any conversion step added yourself in your tiny program to take care about this situation.

Also you are just looking for a 0 in sy-subrc to send a positive message, why not adding an "else" statement to also inform that you have not had any matching value?

You are actually doing a hard table update in a SAP standard table - this is not a desired way - you should call a SAP given BAPI to update tables consistent with the SAP design, you may want to read this blog: Production order : status DLV and indicator "Delivery completed to get some background information of production orders and its completion.

Share
10 |10000 characters needed characters left characters exceeded
Tomas Buryanek Jan 13, 2017 at 09:58 AM
1

Value in wa_doc-docvalue is probably in wrong format. For example you have value 123 but it is 000000000123 in AFPO table.

Use CONVERSION_EXIT_ALPHA_INPUT. You are doing similar thing with UNPACK TO lv_aufnr...

And instead of "docvalue(12) TYPE c" I would recommend use "AFPO-AUFNR type" for UPDATE.

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Jan 18, 2017 at 09:40 AM
0

@Jürgen: Thanks for correcting the tag. Was the very first time here and I haven't been really aware of it.

I tried debugging and it loaded the data fine, just the UPDATE step wasn't clear to me.

ELSE statement is included at the almost end and yes you are right, hard table update is not a good idea.

I'll dig through the link you shared, then I might find a more proper solution.

@Tomas: Thanks a lot for the CONVERSION_EXIT_ALPHA_INPUT recommendation, really useful.

But I'm still not sure what you meant with:

"And instead of "docvalue(12) TYPE c" I would recommend use "AFPO-AUFNR type" for UPDATE."

Problem Solution: (as usual simpler than I thought)

Not working:

UPDATE AFPO SET elikz = 'X' WHERE afpo~aufnr = wa_doc-docvalue.

Working:

UPDATE AFPO SET elikz = 'X' WHERE afpo~aufnr = lv_aufnr
Share
10 |10000 characters needed characters left characters exceeded