1
votes

I have the following problem.

I need to write a script that reads a specific file, from the presentation layer, containing one numerical string per line, the contents of this file need to be entered into an internal table, and then the internal table needs to be inner joined, with table dfkkop to produce the equivalent lines that correspond to each numerical string in the internal table.

I recently read that a conventional inner join cannot be done between an internal table ("itab") and a database table, and instead I should use FOR ALL ENTRIES IN. The problem is that it doesn't seem to work. Here's the code:

TYPES:
  BEGIN OF type_dfkkop_vkont,
    vkont TYPE dfkkop-vkont,
  END OF type_dfkkop_vkont.

DATA: gt_dfkkop_file TYPE STANDARD TABLE OF type_dfkkop_vkont,
      wa_gt_dfkkop_file LIKE LINE OF gt_dfkkop_file,
      gt_dfkkop LIKE DFKKOP OCCURS 0 WITH HEADER LINE,
      wa_gt_dfkkop LIKE dfkkop,
DATA: gv_filename TYPE string,
      gv_filetype TYPE char10.

START-OF-SELECTION.
  PERFORM read_file.
  PERFORM process_data.


FORM read_file.
  gv_filename = 'C:\Users\p.doulgeridis\Desktop\data.txt'.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename            = gv_filename
      filetype            = 'ASC'
      has_field_separator = 'X'
    TABLES
     data_tab            = gt_dfkkop_file.

ENDFORM.

FORM process_data.

  SELECT *
    FROM dfkkop
    INTO CORRESPONDING FIELDS OF TABLE gt_dfkkop
    FOR ALL ENTRIES IN gt_dfkkop_file
    WHERE vkont = gt_dfkkop_file-vkont.

  IF gt_dfkkop_file IS NOT INITIAL.
    WRITE: / 'TABLE GT_DFKKOP_FILE IS NOT INITIAL'.
  ELSE.
    WRITE: / 'TABLE GT_DFKKOP_FILE IS INITIAL'.
  ENDIF.

  IF gt_dfkkop IS NOT INITIAL.
    WRITE: / 'TABLE GT_DFKKOP IS NOT INITIAL'.
  ELSE.
    WRITE: / 'TABLE GT_DFKKOP IS INITIAL'.
  ENDIF.

  LOOP AT gt_dfkkop_file INTO wa_gt_dfkkop_file.
    WRITE: / wa_gt_dfkkop_file-vkont.
  ENDLOOP.

  LOOP AT gt_dfkkop INTO wa_gt_dfkkop.
    WRITE: / wa_gt_dfkkop-vkont, wa_gt_dfkkop-opbel, wa_gt_dfkkop-OPUPW.
  ENDLOOP.

ENDFORM.

At the moment, I do not receive a syntax error, the program executes, but produces no output whatsoever. Could someone help me?

Edit 1: The output looks like this, it's like it doesn't find the values in the text file to query with, keep in mind the file I'm reading has around 11 lines worth of values, which already exist in table dfkkop so they should be producing a result, instead I get:

[blank11spaces]             4000000187   000

Exact output:

enter image description here

3
This question has been changed several times by the OP, so there are different answers, one for each fluctuating situation. Here is the summary: 1) The original code was using the wrong internal table after FOR ALL ENTRIES IN -> answers by Sergio and szako 2) The original code was fixed still no output -> comment by szako under his answer to say that "DFKKOP-VKONT field has alpha conversion" (the column is 12 characters in database and its values contain 2 leading zeroes, but ABAP doesn't display them) -> Ray posted it as an answer - Sandra Rossi

3 Answers

4
votes

In the for all entries part you have to refer to the internal table containing the key entries. Forget ENDSELECT also because you can move all entries into the internal table at once.

The proper syntax would be:

  SELECT *
    FROM dfkkop
    INTO CORRESPONDING FIELDS OF TABLE gt_dfkkop
    FOR ALL ENTRIES IN gt_dfkkop_file
    WHERE vkont = gt_dfkkop_file-vkont.

More about the command here. Btw, the most important part of this command is the following, keep this in mind:

Before using an internal table itab after FOR ALL ENTRIES, always check that the internal table is not initial. In an initial internal tables, all rows are read from the database regardless of any further conditions specified after WHERE. This is not usually the required behavior.

2
votes

The problem in your select is that you are using "FOR ALL ENTRIES IN gt_dfkkop" instead of "FOR ALL ENTRIES IN gt_dfkkop_file", besides, you can use INTO instead of SELECT - ENDSELECT, that will lead to the query szako has done.

If you deal with large volumes of data and you expect to find many contract account (VKONT) duplicates in gt_dfkkop_file you can increase performance moving vkont to another temporal table and use it instead of gt_dfkkop_file. Check allways that the table you use is not empty.

2
votes

szako seems to have answered this in the comment above:

The DFKKOP-VKONT field has alpha conversion. As I see the ids you have are 10 chars length. In the file do you have leading zeros? If not it will never find the corresponding records. Use input alpha-conversion method for the input values. – szako Jun 23 at 12:09